| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrImageIDTextureAdjuster.h" | 8 #include "GrImageIDTextureAdjuster.h" |
| 9 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| 11 #include "GrGpuResourcePriv.h" | 11 #include "GrGpuResourcePriv.h" |
| 12 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 13 #include "SkGrPriv.h" | 13 #include "SkGrPriv.h" |
| 14 #include "SkImage_Base.h" | 14 #include "SkImage_Base.h" |
| 15 #include "SkImageCacherator.h" | 15 #include "SkImageCacherator.h" |
| 16 #include "SkPixelRef.h" | 16 #include "SkPixelRef.h" |
| 17 | 17 |
| 18 static bool bmp_is_alpha_only(const SkBitmap& bm) { return kAlpha_8_SkColorType
== bm.colorType(); } |
| 19 |
| 18 GrBitmapTextureAdjuster::GrBitmapTextureAdjuster(const SkBitmap* bmp) | 20 GrBitmapTextureAdjuster::GrBitmapTextureAdjuster(const SkBitmap* bmp) |
| 19 : INHERITED(bmp->getTexture(), SkIRect::MakeWH(bmp->width(), bmp->height())) | 21 : INHERITED(bmp->getTexture(), |
| 22 SkIRect::MakeWH(bmp->width(), bmp->height()), |
| 23 bmp_is_alpha_only(*bmp)) |
| 20 , fBmp(bmp) {} | 24 , fBmp(bmp) {} |
| 21 | 25 |
| 22 void GrBitmapTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey*
copyKey) { | 26 void GrBitmapTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey*
copyKey) { |
| 23 if (fBmp->isVolatile()) { | 27 if (fBmp->isVolatile()) { |
| 24 return; | 28 return; |
| 25 } | 29 } |
| 26 // The content area must represent the whole bitmap. Texture-backed bitmaps
don't support | 30 // The content area must represent the whole bitmap. Texture-backed bitmaps
don't support |
| 27 // extractSubset(). Therefore, either the bitmap and the texture are the sam
e size or the | 31 // extractSubset(). Therefore, either the bitmap and the texture are the sam
e size or the |
| 28 // content's dimensions are the bitmap's dimensions which is pinned to the u
pper left | 32 // content's dimensions are the bitmap's dimensions which is pinned to the u
pper left |
| 29 // of the texture. | 33 // of the texture. |
| 30 GrUniqueKey baseKey; | 34 GrUniqueKey baseKey; |
| 31 GrMakeKeyFromImageID(&baseKey, fBmp->getGenerationID(), | 35 GrMakeKeyFromImageID(&baseKey, fBmp->getGenerationID(), |
| 32 SkIRect::MakeWH(fBmp->width(), fBmp->height())); | 36 SkIRect::MakeWH(fBmp->width(), fBmp->height())); |
| 33 MakeCopyKeyFromOrigKey(baseKey, params, copyKey); | 37 MakeCopyKeyFromOrigKey(baseKey, params, copyKey); |
| 34 } | 38 } |
| 35 | 39 |
| 36 void GrBitmapTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) { | 40 void GrBitmapTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) { |
| 37 GrInstallBitmapUniqueKeyInvalidator(copyKey, fBmp->pixelRef()); | 41 GrInstallBitmapUniqueKeyInvalidator(copyKey, fBmp->pixelRef()); |
| 38 } | 42 } |
| 39 | 43 |
| 40 ////////////////////////////////////////////////////////////////////////////// | 44 ////////////////////////////////////////////////////////////////////////////// |
| 41 | 45 |
| 46 // SkImage's don't have a way of communicating whether they're alpha-only. So we
fallback to |
| 47 // inspecting the texture. |
| 48 static bool tex_image_is_alpha_only(const SkImage_Base& img) { |
| 49 return GrPixelConfigIsAlphaOnly(img.peekTexture()->config()); |
| 50 } |
| 51 |
| 42 GrImageTextureAdjuster::GrImageTextureAdjuster(const SkImage_Base* img) | 52 GrImageTextureAdjuster::GrImageTextureAdjuster(const SkImage_Base* img) |
| 43 : INHERITED(img->peekTexture(), SkIRect::MakeWH(img->width(), img->height())
) | 53 : INHERITED(img->peekTexture(), SkIRect::MakeWH(img->width(), img->height())
, |
| 54 tex_image_is_alpha_only(*img)) |
| 44 , fImageBase(img) {} | 55 , fImageBase(img) {} |
| 45 | 56 |
| 46 void GrImageTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey*
copyKey) { | 57 void GrImageTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey*
copyKey) { |
| 47 // By construction this texture adjuster always represents an entire SkImage
, so use the | 58 // By construction this texture adjuster always represents an entire SkImage
, so use the |
| 48 // image's width and height for the key's rectangle. | 59 // image's width and height for the key's rectangle. |
| 49 GrUniqueKey baseKey; | 60 GrUniqueKey baseKey; |
| 50 GrMakeKeyFromImageID(&baseKey, fImageBase->uniqueID(), | 61 GrMakeKeyFromImageID(&baseKey, fImageBase->uniqueID(), |
| 51 SkIRect::MakeWH(fImageBase->width(), fImageBase->height
())); | 62 SkIRect::MakeWH(fImageBase->width(), fImageBase->height
())); |
| 52 MakeCopyKeyFromOrigKey(baseKey, params, copyKey); | 63 MakeCopyKeyFromOrigKey(baseKey, params, copyKey); |
| 53 } | 64 } |
| 54 | 65 |
| 55 void GrImageTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) { | 66 void GrImageTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) { |
| 56 // We don't currently have a mechanism for notifications on Images! | 67 // We don't currently have a mechanism for notifications on Images! |
| 57 } | 68 } |
| 58 | 69 |
| 59 ////////////////////////////////////////////////////////////////////////////// | 70 ////////////////////////////////////////////////////////////////////////////// |
| 60 | 71 |
| 61 GrBitmapTextureMaker::GrBitmapTextureMaker(GrContext* context, const SkBitmap& b
itmap) | 72 GrBitmapTextureMaker::GrBitmapTextureMaker(GrContext* context, const SkBitmap& b
itmap) |
| 62 : INHERITED(context, bitmap.width(), bitmap.height()) | 73 : INHERITED(context, bitmap.width(), bitmap.height(), bmp_is_alpha_only(bitm
ap)) |
| 63 , fBitmap(bitmap) { | 74 , fBitmap(bitmap) { |
| 64 SkASSERT(!bitmap.getTexture()); | 75 SkASSERT(!bitmap.getTexture()); |
| 65 if (!bitmap.isVolatile()) { | 76 if (!bitmap.isVolatile()) { |
| 66 SkIPoint origin = bitmap.pixelRefOrigin(); | 77 SkIPoint origin = bitmap.pixelRefOrigin(); |
| 67 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(), | 78 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(), |
| 68 bitmap.height()); | 79 bitmap.height()); |
| 69 GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGenerationID()
, subset); | 80 GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGenerationID()
, subset); |
| 70 } | 81 } |
| 71 } | 82 } |
| 72 | 83 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 92 if (fOriginalKey.isValid()) { | 103 if (fOriginalKey.isValid()) { |
| 93 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); | 104 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); |
| 94 } | 105 } |
| 95 } | 106 } |
| 96 | 107 |
| 97 void GrBitmapTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { | 108 void GrBitmapTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { |
| 98 GrInstallBitmapUniqueKeyInvalidator(copyKey, fBitmap.pixelRef()); | 109 GrInstallBitmapUniqueKeyInvalidator(copyKey, fBitmap.pixelRef()); |
| 99 } | 110 } |
| 100 | 111 |
| 101 ////////////////////////////////////////////////////////////////////////////// | 112 ////////////////////////////////////////////////////////////////////////////// |
| 102 | 113 static bool cacher_is_alpha_only(const SkImageCacherator& cacher) { |
| 114 return kAlpha_8_SkColorType == cacher.info().colorType(); |
| 115 } |
| 103 GrImageTextureMaker::GrImageTextureMaker(GrContext* context, SkImageCacherator*
cacher, | 116 GrImageTextureMaker::GrImageTextureMaker(GrContext* context, SkImageCacherator*
cacher, |
| 104 const SkImage* client, SkImage::Caching
Hint chint) | 117 const SkImage* client, SkImage::Caching
Hint chint) |
| 105 : INHERITED(context, cacher->info().width(), cacher->info().height()) | 118 : INHERITED(context, cacher->info().width(), cacher->info().height(), |
| 119 cacher_is_alpha_only(*cacher)) |
| 106 , fCacher(cacher) | 120 , fCacher(cacher) |
| 107 , fClient(client) | 121 , fClient(client) |
| 108 , fCachingHint(chint) { | 122 , fCachingHint(chint) { |
| 109 if (client) { | 123 if (client) { |
| 110 GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(), | 124 GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(), |
| 111 SkIRect::MakeWH(this->width(), this->height())); | 125 SkIRect::MakeWH(this->width(), this->height())); |
| 112 } | 126 } |
| 113 } | 127 } |
| 114 | 128 |
| 115 GrTexture* GrImageTextureMaker::refOriginalTexture() { | 129 GrTexture* GrImageTextureMaker::refOriginalTexture() { |
| 116 return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCaching
Hint); | 130 return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCaching
Hint); |
| 117 } | 131 } |
| 118 | 132 |
| 119 void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* pa
ramsCopyKey) { | 133 void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* pa
ramsCopyKey) { |
| 120 if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { | 134 if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { |
| 121 MakeCopyKeyFromOrigKey(fOriginalKey, stretch, paramsCopyKey); | 135 MakeCopyKeyFromOrigKey(fOriginalKey, stretch, paramsCopyKey); |
| 122 } | 136 } |
| 123 } | 137 } |
| 124 | 138 |
| 125 void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { | 139 void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { |
| 126 if (fClient) { | 140 if (fClient) { |
| 127 as_IB(fClient)->notifyAddedToCache(); | 141 as_IB(fClient)->notifyAddedToCache(); |
| 128 } | 142 } |
| 129 } | 143 } |
| OLD | NEW |