aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-08-16 06:39:39 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-16 06:39:39 -0700
commitc68744880613c913d02f5941e86bb1d81a379936 (patch)
tree08c0ebd88c7d9883b99aed13e85bbe9e7a5a5965 /src/gpu
parentd707f2d1cf91505d45edc2d92a7faac788d0d99e (diff)
simplify GrTextureAdjuster given there is only one subclass
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrImageIDTextureAdjuster.cpp31
-rw-r--r--src/gpu/GrImageIDTextureAdjuster.h14
-rw-r--r--src/gpu/GrTextureParamsAdjuster.cpp27
-rw-r--r--src/gpu/GrTextureParamsAdjuster.h15
4 files changed, 37 insertions, 50 deletions
diff --git a/src/gpu/GrImageIDTextureAdjuster.cpp b/src/gpu/GrImageIDTextureAdjuster.cpp
index 989102e740..2bfa21c729 100644
--- a/src/gpu/GrImageIDTextureAdjuster.cpp
+++ b/src/gpu/GrImageIDTextureAdjuster.cpp
@@ -17,32 +17,13 @@
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());
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrImageIDTextureAdjuster.h b/src/gpu/GrImageIDTextureAdjuster.h
index 6092fcf7bd..327bf8fb5e 100644
--- a/src/gpu/GrImageIDTextureAdjuster.h
+++ b/src/gpu/GrImageIDTextureAdjuster.h
@@ -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
diff --git a/src/gpu/GrTextureParamsAdjuster.cpp b/src/gpu/GrTextureParamsAdjuster.cpp
index 4456980e85..20b77cb844 100644
--- a/src/gpu/GrTextureParamsAdjuster.cpp
+++ b/src/gpu/GrTextureParamsAdjuster.cpp
@@ -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();
diff --git a/src/gpu/GrTextureParamsAdjuster.h b/src/gpu/GrTextureParamsAdjuster.h
index 4377ae5af3..879c6605f8 100644
--- a/src/gpu/GrTextureParamsAdjuster.h
+++ b/src/gpu/GrTextureParamsAdjuster.h
@@ -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);