Rename view getters in various image subclasses.

This also changes the SkImage_Base header to return a const& view and
then removes the equivalent version in SkImage_GpuBase.

Bug: skia:9556
Change-Id: Ica096693a22c0fc590786058c055fb28387c80a1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/268624
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Auto-Submit: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2020-02-05 10:37:27 -05:00 committed by Skia Commit-Bot
parent d3a32c5425
commit 37c127f558
24 changed files with 79 additions and 75 deletions

View File

@ -176,7 +176,10 @@ public:
surface->getCanvas()->translate(-100, -100);
surface->getCanvas()->drawPicture(pic);
sk_sp<SkImage> image(surface->makeImageSnapshot());
fView = as_IB(image)->asSurfaceProxyViewRef(fCtx.get());
const GrSurfaceProxyView* view = as_IB(image)->view(fCtx.get());
if (view) {
fView = *view;
}
}
}
protected:

View File

@ -118,8 +118,9 @@ GrSurfaceProxyView SkPictureImageGenerator::onGenerateTexture(
if (!image) {
return {};
}
GrSurfaceProxyView view = as_IB(image)->asSurfaceProxyViewRef(ctx);
SkASSERT(!willNeedMipMaps || GrMipMapped::kYes == view.asTextureProxy()->mipMapped());
return view;
const GrSurfaceProxyView* view = as_IB(image)->view(ctx);
SkASSERT(view);
SkASSERT(!willNeedMipMaps || GrMipMapped::kYes == view->asTextureProxy()->mipMapped());
return *view;
}
#endif

View File

@ -52,7 +52,7 @@ public:
virtual SkColorSpace* onGetColorSpace() const = 0;
#if SK_SUPPORT_GPU
virtual GrSurfaceProxyView onAsSurfaceProxyViewRef(GrRecordingContext* context) const = 0;
virtual GrSurfaceProxyView onView(GrRecordingContext* context) const = 0;
#endif
// This subset is relative to the backing store's coordinate frame, it has already been mapped
@ -155,8 +155,8 @@ SkColorSpace* SkSpecialImage::getColorSpace() const {
}
#if SK_SUPPORT_GPU
GrSurfaceProxyView SkSpecialImage::asSurfaceProxyViewRef(GrRecordingContext* context) const {
return as_SIB(this)->onAsSurfaceProxyViewRef(context);
GrSurfaceProxyView SkSpecialImage::view(GrRecordingContext* context) const {
return as_SIB(this)->onView(context);
}
#endif
@ -207,13 +207,12 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(GrRecordingContext* context,
SkASSERT(rect_fits(subset, image->width(), image->height()));
#if SK_SUPPORT_GPU
GrSurfaceProxyView view = as_IB(image)->asSurfaceProxyViewRef(context);
if (view.proxy()) {
if (const GrSurfaceProxyView* view = as_IB(image)->view(context)) {
if (!as_IB(image)->context()->priv().matches(context)) {
return nullptr;
}
return MakeDeferredFromGpu(context, subset, image->uniqueID(), std::move(view),
return MakeDeferredFromGpu(context, subset, image->uniqueID(), *view,
SkColorTypeToGrColorType(image->colorType()),
image->refColorSpace(), props);
} else
@ -262,7 +261,7 @@ public:
}
#if SK_SUPPORT_GPU
GrSurfaceProxyView onAsSurfaceProxyViewRef(GrRecordingContext* context) const override {
GrSurfaceProxyView onView(GrRecordingContext* context) const override {
if (context) {
return GrMakeCachedBitmapProxyView(context, fBitmap);
}
@ -424,9 +423,7 @@ public:
GrRecordingContext* onGetContext() const override { return fContext; }
GrSurfaceProxyView onAsSurfaceProxyViewRef(GrRecordingContext* context) const override {
return fView;
}
GrSurfaceProxyView onView(GrRecordingContext* context) const override { return fView; }
bool onGetROPixels(SkBitmap* dst) const override {
const auto desc = SkBitmapCacheDesc::Make(this->uniqueID(), this->subset());

View File

@ -148,7 +148,7 @@ public:
* coordinates must be mapped from the content rect (e.g. relative to 'subset()') to the proxy's
* space (offset by subset().topLeft()).
*/
GrSurfaceProxyView asSurfaceProxyViewRef(GrRecordingContext*) const;
GrSurfaceProxyView view(GrRecordingContext*) const;
#endif
/**

View File

@ -149,7 +149,7 @@ sk_sp<SkSpecialImage> SkAlphaThresholdFilterImpl::onFilterImage(const Context& c
if (ctx.gpuBacked()) {
auto context = ctx.getContext();
GrSurfaceProxyView inputView = (input->asSurfaceProxyViewRef(context));
GrSurfaceProxyView inputView = (input->view(context));
SkASSERT(inputView.asTextureProxy());
const GrProtected isProtected = inputView.proxy()->isProtected();

View File

@ -336,13 +336,13 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU(
GrProtected isProtected = GrProtected::kNo;
if (background) {
backgroundView = background->asSurfaceProxyViewRef(context);
backgroundView = background->view(context);
SkASSERT(backgroundView.proxy());
isProtected = backgroundView.proxy()->isProtected();
}
if (foreground) {
foregroundView = foreground->asSurfaceProxyViewRef(context);
foregroundView = foreground->view(context);
SkASSERT(foregroundView.proxy());
isProtected = foregroundView.proxy()->isProtected();
}

View File

@ -643,7 +643,7 @@ sk_sp<SkSpecialImage> SkBlurImageFilterImpl::gpuFilter(
auto context = ctx.getContext();
GrSurfaceProxyView inputView = input->asSurfaceProxyViewRef(context);
GrSurfaceProxyView inputView = input->view(context);
if (!inputView.proxy()) {
return nullptr;
}

View File

@ -335,8 +335,8 @@ sk_sp<SkSpecialImage> SkDisplacementMapEffectImpl::onFilterImage(const Context&
if (ctx.gpuBacked()) {
auto context = ctx.getContext();
GrSurfaceProxyView colorView = color->asSurfaceProxyViewRef(context);
GrSurfaceProxyView displView = displ->asSurfaceProxyViewRef(context);
GrSurfaceProxyView colorView = color->view(context);
GrSurfaceProxyView displView = displ->view(context);
if (!colorView.proxy() || !displView.proxy()) {
return nullptr;
}

View File

@ -485,7 +485,7 @@ sk_sp<SkSpecialImage> SkLightingImageFilterInternal::filterImageGPU(
auto context = ctx.getContext();
GrSurfaceProxyView inputView = input->asSurfaceProxyViewRef(context);
GrSurfaceProxyView inputView = input->view(context);
SkASSERT(inputView.asTextureProxy());
auto renderTargetContext = GrRenderTargetContext::Make(

View File

@ -122,7 +122,7 @@ sk_sp<SkSpecialImage> SkMagnifierImageFilterImpl::onFilterImage(const Context& c
if (ctx.gpuBacked()) {
auto context = ctx.getContext();
GrSurfaceProxyView inputView = input->asSurfaceProxyViewRef(context);
GrSurfaceProxyView inputView = input->view(context);
SkASSERT(inputView.asTextureProxy());
const auto isProtected = inputView.proxy()->isProtected();

View File

@ -419,7 +419,7 @@ sk_sp<SkSpecialImage> SkMatrixConvolutionImageFilterImpl::onFilterImage(const Co
// fall-back, which saves us from having to do the xform during the filter itself.
input = ImageToColorSpace(input.get(), ctx.colorType(), ctx.colorSpace());
GrSurfaceProxyView inputView = input->asSurfaceProxyViewRef(context);
GrSurfaceProxyView inputView = input->view(context);
SkASSERT(inputView.asTextureProxy());
const auto isProtected = inputView.proxy()->isProtected();

View File

@ -555,7 +555,7 @@ static void apply_morphology_pass(GrRenderTargetContext* renderTargetContext,
static sk_sp<SkSpecialImage> apply_morphology(
GrRecordingContext* context, SkSpecialImage* input, const SkIRect& rect,
MorphType morphType, SkISize radius, const SkImageFilter_Base::Context& ctx) {
GrSurfaceProxyView srcView = input->asSurfaceProxyViewRef(context);
GrSurfaceProxyView srcView = input->view(context);
SkAlphaType srcAlphaType = input->alphaType();
SkASSERT(srcView.asTextureProxy());
sk_sp<SkColorSpace> colorSpace = ctx.refColorSpace();

View File

@ -249,11 +249,11 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilterImpl::filterImageGPU(
GrSurfaceProxyView backgroundView, foregroundView;
if (background) {
backgroundView = background->asSurfaceProxyViewRef(context);
backgroundView = background->view(context);
}
if (foreground) {
foregroundView = foreground->asSurfaceProxyViewRef(context);
foregroundView = foreground->view(context);
}
GrPaint paint;

View File

@ -65,9 +65,13 @@ GrSurfaceProxyView GrYUVAImageTextureMaker::refOriginalTextureProxyView(
}
if (willBeMipped) {
return fImage->asMippedTextureProxyViewRef(this->context());
return fImage->refMippedView(this->context());
} else {
return fImage->asSurfaceProxyViewRef(this->context());
if (const GrSurfaceProxyView* view = fImage->view(this->context())) {
return *view;
} else {
return {};
}
}
}

View File

@ -1020,7 +1020,7 @@ void SkGpuDevice::drawSpecial(SkSpecialImage* special, int left, int top, const
}
SkASSERT(result->isTextureBacked());
GrSurfaceProxyView view = result->asSurfaceProxyViewRef(this->context());
GrSurfaceProxyView view = result->view(this->context());
if (!view.proxy()) {
return;
}
@ -1211,12 +1211,13 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) {
sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) {
SkPixmap pm;
if (image->isTextureBacked()) {
auto view = as_IB(image)->asSurfaceProxyViewRef(this->context());
const GrSurfaceProxyView* view = as_IB(image)->view(this->context());
SkASSERT(view);
return SkSpecialImage::MakeDeferredFromGpu(fContext.get(),
SkIRect::MakeWH(image->width(), image->height()),
image->uniqueID(),
std::move(view),
*view,
SkColorTypeToGrColorType(image->colorType()),
image->refColorSpace(),
&this->surfaceProps());

View File

@ -59,11 +59,11 @@ public:
virtual GrTextureProxy* peekProxy() const { return nullptr; }
virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*) const { return nullptr; }
// This returns a copy of the GrSurfaceProxyView which essentially refs the contained
// GrSurfaceProxy. Callers should check if the proxy of the returned view is null.
virtual GrSurfaceProxyView asSurfaceProxyViewRef(GrRecordingContext*) const {
return GrSurfaceProxyView();
}
// If it exists, this returns a pointer to the GrSurfaceProxyView of image. The caller does not
// own the returned view and must copy it if they want to gain a ref to the internal proxy.
// If the returned view is not null, then it is guaranteed to have a valid proxy. Additionally
// this call will flatten a SkImage_GpuYUV to a single texture.
virtual const GrSurfaceProxyView* view(GrRecordingContext*) const { return nullptr; }
virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*, GrSamplerState,
SkScalar scaleAdjust[2]) const = 0;

View File

@ -434,13 +434,12 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, GrMipMapped mipMapp
return nullptr;
}
GrSurfaceProxyView view = as_IB(this)->asSurfaceProxyViewRef(context);
SkASSERT(view.asTextureProxy());
if (GrMipMapped::kNo == mipMapped || view.asTextureProxy()->mipMapped() == mipMapped) {
const GrSurfaceProxyView* view = as_IB(this)->view(context);
SkASSERT(view && view->asTextureProxy());
if (GrMipMapped::kNo == mipMapped || view->asTextureProxy()->mipMapped() == mipMapped) {
return sk_ref_sp(const_cast<SkImage*>(this));
}
GrTextureAdjuster adjuster(context, std::move(view), this->imageInfo().colorInfo(),
this->uniqueID());
GrTextureAdjuster adjuster(context, *view, this->imageInfo().colorInfo(), this->uniqueID());
return create_image_from_producer(context, &adjuster, this->uniqueID(), mipMapped);
}

View File

@ -36,11 +36,11 @@ public:
return fView.asTextureProxyRef();
}
GrSurfaceProxyView asSurfaceProxyViewRef(GrRecordingContext* context) const override {
return fView;
}
const GrSurfaceProxyView& getSurfaceProxyView(GrRecordingContext* context) const override {
return fView;
const GrSurfaceProxyView* view(GrRecordingContext* context) const override {
if (!fView.proxy()) {
return nullptr;
}
return &fView;
}
bool onIsTextureBacked() const override {

View File

@ -114,13 +114,14 @@ bool SkImage_GpuBase::getROPixels(SkBitmap* dst, CachingHint chint) const {
}
}
GrSurfaceProxyView view = this->asSurfaceProxyViewRef(direct);
const GrSurfaceProxyView* view = this->view(direct);
SkASSERT(view);
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(fContext->priv().caps(),
this->colorType(),
view.proxy()->backendFormat());
view->proxy()->backendFormat());
auto sContext = GrSurfaceContext::Make(direct, std::move(view), grColorType,
this->alphaType(), this->refColorSpace());
auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
this->refColorSpace());
if (!sContext) {
return false;
}
@ -142,15 +143,15 @@ sk_sp<SkImage> SkImage_GpuBase::onMakeSubset(GrRecordingContext* context,
return nullptr;
}
const GrSurfaceProxyView& view = this->getSurfaceProxyView(context);
SkASSERT(view.proxy());
const GrSurfaceProxyView* view = this->view(context);
SkASSERT(view && view->proxy());
GrColorType grColorType = SkColorTypeToGrColorType(this->colorType());
GrSurfaceProxyView copyView =
GrSurfaceProxy::Copy(context, view.proxy(), view.origin(), grColorType,
GrSurfaceProxy::Copy(context, view->proxy(), view->origin(), grColorType,
GrMipMapped::kNo, subset, SkBackingFit::kExact,
view.proxy()->isBudgeted());
view->proxy()->isBudgeted());
if (!copyView.proxy()) {
return nullptr;
@ -173,13 +174,14 @@ bool SkImage_GpuBase::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels,
return false;
}
GrSurfaceProxyView view = this->asSurfaceProxyViewRef(direct);
const GrSurfaceProxyView* view = this->view(direct);
SkASSERT(view);
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(fContext->priv().caps(),
this->colorType(),
view.proxy()->backendFormat());
view->proxy()->backendFormat());
auto sContext = GrSurfaceContext::Make(direct, std::move(view), grColorType,
this->alphaType(), this->refColorSpace());
auto sContext = GrSurfaceContext::Make(direct, *view, grColorType, this->alphaType(),
this->refColorSpace());
if (!sContext) {
return false;
}
@ -195,8 +197,8 @@ sk_sp<GrTextureProxy> SkImage_GpuBase::asTextureProxyRef(GrRecordingContext* con
return nullptr;
}
GrTextureAdjuster adjuster(fContext.get(), this->asSurfaceProxyViewRef(context),
this->imageInfo().colorInfo(), this->uniqueID());
GrTextureAdjuster adjuster(fContext.get(), *this->view(context), this->imageInfo().colorInfo(),
this->uniqueID());
return adjuster.viewForParams(params, scaleAdjust).asTextureProxyRef();
}

View File

@ -34,8 +34,6 @@ public:
return this->INHERITED::asTextureProxyRef(context);
}
virtual const GrSurfaceProxyView& getSurfaceProxyView(GrRecordingContext* context) const = 0;
sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*, GrSamplerState,
SkScalar scaleAdjust[2]) const final;

View File

@ -174,7 +174,7 @@ sk_sp<GrTextureProxy> SkImage_GpuYUVA::asTextureProxyRef(GrRecordingContext* con
return fRGBView.asTextureProxyRef();
}
GrSurfaceProxyView SkImage_GpuYUVA::asMippedTextureProxyViewRef(GrRecordingContext* context) const {
GrSurfaceProxyView SkImage_GpuYUVA::refMippedView(GrRecordingContext* context) const {
// if invalid or already has miplevels
this->flattenToRGB(context);
if (!fRGBView.proxy() || GrMipMapped::kYes == fRGBView.asTextureProxy()->mipMapped()) {
@ -194,9 +194,12 @@ GrSurfaceProxyView SkImage_GpuYUVA::asMippedTextureProxyViewRef(GrRecordingConte
return {};
}
GrSurfaceProxyView SkImage_GpuYUVA::asSurfaceProxyViewRef(GrRecordingContext* context) const {
const GrSurfaceProxyView* SkImage_GpuYUVA::view(GrRecordingContext* context) const {
this->flattenToRGB(context);
return fRGBView;
if (!fRGBView.proxy()) {
return nullptr;
}
return &fRGBView;
}
//////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -35,11 +35,7 @@ public:
GrTextureProxy* peekProxy() const override;
sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*) const override;
GrSurfaceProxyView asSurfaceProxyViewRef(GrRecordingContext* context) const override;
const GrSurfaceProxyView& getSurfaceProxyView(GrRecordingContext* context) const override {
this->flattenToRGB(context);
return fRGBView;
}
const GrSurfaceProxyView* view(GrRecordingContext* context) const override;
bool onIsTextureBacked() const override {
SkASSERT(fProxies[0] || fRGBView.proxy());
@ -56,7 +52,7 @@ public:
bool setupMipmapsForPlanes(GrRecordingContext*) const;
// Returns a ref-ed texture proxy view with miplevels
GrSurfaceProxyView asMippedTextureProxyViewRef(GrRecordingContext*) const;
GrSurfaceProxyView refMippedView(GrRecordingContext*) const;
#if GR_TEST_UTILS
bool testingOnly_IsFlattened() const {

View File

@ -71,9 +71,9 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
REPORTER_ASSERT(reporter, isGPUBacked == img->isTextureBacked());
//--------------
// Test asSurfaceProxyViewRef - as long as there is a context this should succeed
// Test view - as long as there is a context this should succeed
if (context) {
GrSurfaceProxyView view = img->asSurfaceProxyViewRef(context);
GrSurfaceProxyView view = img->view(context);
REPORTER_ASSERT(reporter, view.asTextureProxy());
}

View File

@ -782,7 +782,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
auto makeImageSurfaceContext = [context](SkSurface* surface) {
sk_sp<SkImage> i(surface->makeImageSnapshot());
SkImage_Gpu* gpuImage = (SkImage_Gpu*)as_IB(i);
return GrSurfaceContext::Make(context, gpuImage->asSurfaceProxyViewRef(context),
return GrSurfaceContext::Make(context, *gpuImage->view(context),
SkColorTypeToGrColorType(i->colorType()), kPremul_SkAlphaType,
gpuImage->refColorSpace());
};