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>
diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp
index c8ccfbc..bd1264d 100644
--- a/src/core/SkPictureImageGenerator.cpp
+++ b/src/core/SkPictureImageGenerator.cpp
@@ -118,8 +118,9 @@
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
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 8617044..9dd1e5d 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -52,7 +52,7 @@
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 @@
}
#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 @@
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 @@
}
#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 @@
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());
diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h
index 0162850..9df11ab 100644
--- a/src/core/SkSpecialImage.h
+++ b/src/core/SkSpecialImage.h
@@ -148,7 +148,7 @@
* 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
/**
diff --git a/src/effects/imagefilters/SkAlphaThresholdFilter.cpp b/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
index 024b342..1ea348b 100644
--- a/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
+++ b/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
@@ -149,7 +149,7 @@
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();
diff --git a/src/effects/imagefilters/SkArithmeticImageFilter.cpp b/src/effects/imagefilters/SkArithmeticImageFilter.cpp
index 4ec1e71..180be8a 100644
--- a/src/effects/imagefilters/SkArithmeticImageFilter.cpp
+++ b/src/effects/imagefilters/SkArithmeticImageFilter.cpp
@@ -336,13 +336,13 @@
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();
}
diff --git a/src/effects/imagefilters/SkBlurImageFilter.cpp b/src/effects/imagefilters/SkBlurImageFilter.cpp
index bc5d52240..572ab13 100644
--- a/src/effects/imagefilters/SkBlurImageFilter.cpp
+++ b/src/effects/imagefilters/SkBlurImageFilter.cpp
@@ -643,7 +643,7 @@
auto context = ctx.getContext();
- GrSurfaceProxyView inputView = input->asSurfaceProxyViewRef(context);
+ GrSurfaceProxyView inputView = input->view(context);
if (!inputView.proxy()) {
return nullptr;
}
diff --git a/src/effects/imagefilters/SkDisplacementMapEffect.cpp b/src/effects/imagefilters/SkDisplacementMapEffect.cpp
index 15095ea..f921358 100644
--- a/src/effects/imagefilters/SkDisplacementMapEffect.cpp
+++ b/src/effects/imagefilters/SkDisplacementMapEffect.cpp
@@ -335,8 +335,8 @@
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;
}
diff --git a/src/effects/imagefilters/SkLightingImageFilter.cpp b/src/effects/imagefilters/SkLightingImageFilter.cpp
index f824146..7281d21 100644
--- a/src/effects/imagefilters/SkLightingImageFilter.cpp
+++ b/src/effects/imagefilters/SkLightingImageFilter.cpp
@@ -485,7 +485,7 @@
auto context = ctx.getContext();
- GrSurfaceProxyView inputView = input->asSurfaceProxyViewRef(context);
+ GrSurfaceProxyView inputView = input->view(context);
SkASSERT(inputView.asTextureProxy());
auto renderTargetContext = GrRenderTargetContext::Make(
diff --git a/src/effects/imagefilters/SkMagnifierImageFilter.cpp b/src/effects/imagefilters/SkMagnifierImageFilter.cpp
index 60f54bb..c06738d 100644
--- a/src/effects/imagefilters/SkMagnifierImageFilter.cpp
+++ b/src/effects/imagefilters/SkMagnifierImageFilter.cpp
@@ -122,7 +122,7 @@
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();
diff --git a/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp b/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp
index b3b6ba2..268ac53 100644
--- a/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/imagefilters/SkMatrixConvolutionImageFilter.cpp
@@ -419,7 +419,7 @@
// 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();
diff --git a/src/effects/imagefilters/SkMorphologyImageFilter.cpp b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
index 9433de2..c3cc510 100644
--- a/src/effects/imagefilters/SkMorphologyImageFilter.cpp
+++ b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
@@ -555,7 +555,7 @@
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();
diff --git a/src/effects/imagefilters/SkXfermodeImageFilter.cpp b/src/effects/imagefilters/SkXfermodeImageFilter.cpp
index f24fedf..5cbbdad 100644
--- a/src/effects/imagefilters/SkXfermodeImageFilter.cpp
+++ b/src/effects/imagefilters/SkXfermodeImageFilter.cpp
@@ -249,11 +249,11 @@
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;
diff --git a/src/gpu/GrImageTextureMaker.cpp b/src/gpu/GrImageTextureMaker.cpp
index 385e44a..2b6d87f 100644
--- a/src/gpu/GrImageTextureMaker.cpp
+++ b/src/gpu/GrImageTextureMaker.cpp
@@ -65,9 +65,13 @@
}
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 {};
+ }
}
}
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index fc135f6..e62c59d 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1020,7 +1020,7 @@
}
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 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());
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index ed50977..6b1a2fe 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -59,11 +59,11 @@
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;
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index eb24ab8..a5768d8 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -434,13 +434,12 @@
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);
}
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 75a830a..d153a18 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -36,11 +36,11 @@
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 {
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index ca716f1..c998de1 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -114,13 +114,14 @@
}
}
- 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 @@
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 @@
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 @@
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();
}
diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h
index 9c4cb58..950fb7c 100644
--- a/src/image/SkImage_GpuBase.h
+++ b/src/image/SkImage_GpuBase.h
@@ -34,8 +34,6 @@
return this->INHERITED::asTextureProxyRef(context);
}
- virtual const GrSurfaceProxyView& getSurfaceProxyView(GrRecordingContext* context) const = 0;
-
sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*, GrSamplerState,
SkScalar scaleAdjust[2]) const final;
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index eae0a33..8184384 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -174,7 +174,7 @@
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 @@
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;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/image/SkImage_GpuYUVA.h b/src/image/SkImage_GpuYUVA.h
index 27ad48c..8e2ab35 100644
--- a/src/image/SkImage_GpuYUVA.h
+++ b/src/image/SkImage_GpuYUVA.h
@@ -35,11 +35,7 @@
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 @@
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 {