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());
}
//////////////////////////////////////////////////////////////////////////////
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
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()) {
}
}
+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();
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; }
private:
SkTLazy<SkIRect> fContentArea;
GrTexture* fOriginal;
+ SkColorSpace* fColorSpace;
+ uint32_t fUniqueID;
GrTexture* refCopy(const CopyParams ©Params);