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" |
| 11 #include "GrGpuResourcePriv.h" |
10 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
11 #include "SkGrPriv.h" | 13 #include "SkGrPriv.h" |
12 #include "SkImage_Base.h" | 14 #include "SkImage_Base.h" |
13 | 15 #include "SkPixelRef.h" |
14 | 16 |
15 GrBitmapTextureAdjuster::GrBitmapTextureAdjuster(const SkBitmap* bmp) | 17 GrBitmapTextureAdjuster::GrBitmapTextureAdjuster(const SkBitmap* bmp) |
16 : INHERITED(bmp->getTexture(), SkIRect::MakeWH(bmp->width(), bmp->height())) | 18 : INHERITED(bmp->getTexture(), SkIRect::MakeWH(bmp->width(), bmp->height())) |
17 , fBmp(bmp) {} | 19 , fBmp(bmp) {} |
18 | 20 |
19 void GrBitmapTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey*
copyKey) { | 21 void GrBitmapTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey*
copyKey) { |
20 if (fBmp->isVolatile()) { | 22 if (fBmp->isVolatile()) { |
21 return; | 23 return; |
22 } | 24 } |
23 // The content area must represent the whole bitmap. Texture-backed bitmaps
don't support | 25 // The content area must represent the whole bitmap. Texture-backed bitmaps
don't support |
(...skipping 21 matching lines...) Expand all Loading... |
45 // image's width and height for the key's rectangle. | 47 // image's width and height for the key's rectangle. |
46 GrUniqueKey baseKey; | 48 GrUniqueKey baseKey; |
47 GrMakeKeyFromImageID(&baseKey, fImageBase->uniqueID(), | 49 GrMakeKeyFromImageID(&baseKey, fImageBase->uniqueID(), |
48 SkIRect::MakeWH(fImageBase->width(), fImageBase->height
())); | 50 SkIRect::MakeWH(fImageBase->width(), fImageBase->height
())); |
49 MakeCopyKeyFromOrigKey(baseKey, params, copyKey); | 51 MakeCopyKeyFromOrigKey(baseKey, params, copyKey); |
50 } | 52 } |
51 | 53 |
52 void GrImageTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) { | 54 void GrImageTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) { |
53 // We don't currently have a mechanism for notifications on Images! | 55 // We don't currently have a mechanism for notifications on Images! |
54 } | 56 } |
| 57 |
| 58 ////////////////////////////////////////////////////////////////////////////// |
| 59 |
| 60 GrBitmapTextureMaker::GrBitmapTextureMaker(GrContext* context, const SkBitmap& b
itmap) |
| 61 : INHERITED(context, bitmap.width(), bitmap.height()) |
| 62 , fBitmap(bitmap) { |
| 63 SkASSERT(!bitmap.getTexture()); |
| 64 if (!bitmap.isVolatile()) { |
| 65 SkIPoint origin = bitmap.pixelRefOrigin(); |
| 66 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(), |
| 67 bitmap.height()); |
| 68 GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGenerationID()
, subset); |
| 69 } |
| 70 } |
| 71 |
| 72 GrTexture* GrBitmapTextureMaker::refOriginalTexture() { |
| 73 GrTexture* tex; |
| 74 |
| 75 if (fOriginalKey.isValid()) { |
| 76 tex = this->context()->textureProvider()->findAndRefTextureByUniqueKey(f
OriginalKey); |
| 77 if (tex) { |
| 78 return tex; |
| 79 } |
| 80 } |
| 81 |
| 82 tex = GrUploadBitmapToTexture(this->context(), fBitmap); |
| 83 if (tex && fOriginalKey.isValid()) { |
| 84 tex->resourcePriv().setUniqueKey(fOriginalKey); |
| 85 GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef()); |
| 86 } |
| 87 return tex; |
| 88 } |
| 89 |
| 90 void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey
* copyKey) { |
| 91 if (fOriginalKey.isValid()) { |
| 92 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); |
| 93 } |
| 94 } |
| 95 |
| 96 void GrBitmapTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { |
| 97 GrInstallBitmapUniqueKeyInvalidator(copyKey, fBitmap.pixelRef()); |
| 98 } |
OLD | NEW |