simplify GrTextureAdjuster given there is only one subclass
authorreed <reed@google.com>
Tue, 16 Aug 2016 13:39:39 +0000 (06:39 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 16 Aug 2016 13:39:39 +0000 (06:39 -0700)
Intended as a pre-cl for https://codereview.chromium.org/2241353002#

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2242373002

Review-Url: https://codereview.chromium.org/2242373002

src/gpu/GrImageIDTextureAdjuster.cpp
src/gpu/GrImageIDTextureAdjuster.h
src/gpu/GrTextureParamsAdjuster.cpp
src/gpu/GrTextureParamsAdjuster.h

index 989102e..2bfa21c 100644 (file)
 
 static bool bmp_is_alpha_only(const SkBitmap& bm) { return kAlpha_8_SkColorType == bm.colorType(); }
 
-// SkImage's don't have a way of communicating whether they're alpha-only. So we fallback to
-// inspecting the texture.
-static bool tex_image_is_alpha_only(const SkImage_Base& img) {
-    return GrPixelConfigIsAlphaOnly(img.peekTexture()->config());
-}
-
+// By construction this texture adjuster always represents an entire SkImage, so use the
+// image's dimensions for the key's rectangle.
 GrImageTextureAdjuster::GrImageTextureAdjuster(const SkImage_Base* img)
-    : INHERITED(img->peekTexture(), SkIRect::MakeWH(img->width(), img->height()),
-                tex_image_is_alpha_only(*img))
-    , fImageBase(img) {}
-
-void GrImageTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) {
-    // By construction this texture adjuster always represents an entire SkImage, so use the
-    // image's width and height for the key's rectangle.
-    GrUniqueKey baseKey;
-    GrMakeKeyFromImageID(&baseKey, fImageBase->uniqueID(),
-                         SkIRect::MakeWH(fImageBase->width(), fImageBase->height()));
-    MakeCopyKeyFromOrigKey(baseKey, params, copyKey);
-}
-
-void GrImageTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) {
-    // We don't currently have a mechanism for notifications on Images!
-}
-
-SkColorSpace* GrImageTextureAdjuster::getColorSpace() {
-    return fImageBase->onImageInfo().colorSpace();
+    : GrTextureAdjuster(img->peekTexture(), SkIRect::MakeSize(img->dimensions()), img->uniqueID(),
+                        img->onImageInfo().colorSpace())
+{
+    SkASSERT(img->peekTexture());
 }
 
 //////////////////////////////////////////////////////////////////////////////
index 6092fcf..327bf8f 100644 (file)
@@ -15,23 +15,9 @@ class SkBitmap;
 class SkImage_Base;
 class SkImageCacherator;
 
-/** Implementation for texture-backed SkImages. The image must stay in scope and unmodified while
-    this object exists. */
 class GrImageTextureAdjuster : public GrTextureAdjuster {
 public:
     explicit GrImageTextureAdjuster(const SkImage_Base* img);
-
-protected:
-    SkColorSpace* getColorSpace() override;
-
-private:
-    void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override;
-
-    void didCacheCopy(const GrUniqueKey& copyKey) override;
-
-    const SkImage_Base* fImageBase;
-
-    typedef GrTextureAdjuster INHERITED;
 };
 
 /** This class manages the conversion of SW-backed bitmaps to GrTextures. If the input bitmap is
index 4456980..20b77cb 100644 (file)
@@ -112,11 +112,14 @@ static GrTexture* copy_on_gpu(GrTexture* inputTexture, const SkIRect* subset,
     return copyDC->asTexture().release();
 }
 
-GrTextureAdjuster::GrTextureAdjuster(GrTexture* original,
-                                     const SkIRect& contentArea,
-                                     bool isAlphaOnly)
-    : INHERITED(contentArea.width(), contentArea.height(), isAlphaOnly)
-    , fOriginal(original) {
+GrTextureAdjuster::GrTextureAdjuster(GrTexture* original, const SkIRect& contentArea,
+                                     uint32_t uniqueID, SkColorSpace* cs)
+    : INHERITED(contentArea.width(), contentArea.height(),
+                GrPixelConfigIsAlphaOnly(original->config()))
+    , fOriginal(original)
+    , fColorSpace(cs)
+    , fUniqueID(uniqueID)
+{
     SkASSERT(SkIRect::MakeWH(original->width(), original->height()).contains(contentArea));
     if (contentArea.fLeft > 0 || contentArea.fTop > 0 ||
         contentArea.fRight < original->width() || contentArea.fBottom < original->height()) {
@@ -124,6 +127,20 @@ GrTextureAdjuster::GrTextureAdjuster(GrTexture* original,
     }
 }
 
+void GrTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) {
+    GrUniqueKey baseKey;
+    GrMakeKeyFromImageID(&baseKey, fUniqueID, SkIRect::MakeWH(this->width(), this->height()));
+    MakeCopyKeyFromOrigKey(baseKey, params, copyKey);
+}
+
+void GrTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) {
+    // We don't currently have a mechanism for notifications on Images!
+}
+
+SkColorSpace* GrTextureAdjuster::getColorSpace() {
+    return fColorSpace;
+}
+
 GrTexture* GrTextureAdjuster::refCopy(const CopyParams& copyParams) {
     GrTexture* texture = this->originalTexture();
     GrContext* context = texture->getContext();
index 4377ae5..879c660 100644 (file)
@@ -142,13 +142,14 @@ public:
                                 SkColorSpace* dstColorSpace,
                                 SkSourceGammaTreatment) override;
 
-protected:
-    /** The whole texture is content. */
-    explicit GrTextureAdjuster(GrTexture* original, bool isAlphaOnly)
-        : INHERITED(original->width(), original->height(), isAlphaOnly)
-        , fOriginal(original) {}
+    // We do not ref the texture nor the colorspace, so the caller must keep them in scope while
+    // this Adjuster is alive.
+    GrTextureAdjuster(GrTexture*, const SkIRect& area, uint32_t uniqueID, SkColorSpace*);
 
-    GrTextureAdjuster(GrTexture* original, const SkIRect& contentArea, bool isAlphaOnly);
+protected:
+    SkColorSpace* getColorSpace() override;
+    void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override;
+    void didCacheCopy(const GrUniqueKey& copyKey) override;
 
     GrTexture* originalTexture() const { return fOriginal; }
 
@@ -158,6 +159,8 @@ protected:
 private:
     SkTLazy<SkIRect>    fContentArea;
     GrTexture*          fOriginal;
+    SkColorSpace*       fColorSpace;
+    uint32_t            fUniqueID;
 
     GrTexture* refCopy(const CopyParams &copyParams);