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(); } | 18 static bool bmp_is_alpha_only(const SkBitmap& bm) { return kAlpha_8_SkColorType
== bm.colorType(); } |
19 | 19 |
20 // SkImage's don't have a way of communicating whether they're alpha-only. So we
fallback to | 20 GrRawTextureAdjuster::GrRawTextureAdjuster(GrTexture* tex, const SkISize& size,
uint32_t uniqueID, |
21 // inspecting the texture. | 21 SkColorSpace* cs) |
22 static bool tex_image_is_alpha_only(const SkImage_Base& img) { | 22 : INHERITED(tex, SkIRect::MakeSize(size), GrPixelConfigIsAlphaOnly(tex->conf
ig())) |
23 return GrPixelConfigIsAlphaOnly(img.peekTexture()->config()); | 23 , fColorSpace(cs) |
24 } | 24 , fSize(size) |
| 25 , fUniqueID(uniqueID) |
| 26 {} |
25 | 27 |
26 GrImageTextureAdjuster::GrImageTextureAdjuster(const SkImage_Base* img) | 28 void GrRawTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* co
pyKey) { |
27 : INHERITED(img->peekTexture(), SkIRect::MakeWH(img->width(), img->height())
, | |
28 tex_image_is_alpha_only(*img)) | |
29 , fImageBase(img) {} | |
30 | |
31 void GrImageTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey*
copyKey) { | |
32 // By construction this texture adjuster always represents an entire SkImage
, so use the | |
33 // image's width and height for the key's rectangle. | |
34 GrUniqueKey baseKey; | 29 GrUniqueKey baseKey; |
35 GrMakeKeyFromImageID(&baseKey, fImageBase->uniqueID(), | 30 GrMakeKeyFromImageID(&baseKey, fUniqueID, SkIRect::MakeSize(fSize)); |
36 SkIRect::MakeWH(fImageBase->width(), fImageBase->height
())); | |
37 MakeCopyKeyFromOrigKey(baseKey, params, copyKey); | 31 MakeCopyKeyFromOrigKey(baseKey, params, copyKey); |
38 } | 32 } |
39 | 33 |
40 void GrImageTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) { | 34 void GrRawTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) { |
41 // We don't currently have a mechanism for notifications on Images! | 35 // We don't currently have a mechanism for notifications on Images! |
42 } | 36 } |
43 | 37 |
44 SkColorSpace* GrImageTextureAdjuster::getColorSpace() { | 38 SkColorSpace* GrRawTextureAdjuster::getColorSpace() { |
45 return fImageBase->onImageInfo().colorSpace(); | 39 return fColorSpace; |
| 40 } |
| 41 |
| 42 // By construction this texture adjuster always represents an entire SkImage, so
use the |
| 43 // image's width and height for the key's rectangle. |
| 44 GrImageTextureAdjuster::GrImageTextureAdjuster(const SkImage_Base* img) |
| 45 : GrRawTextureAdjuster(img->peekTexture(), img->dimensions(), img->uniqueID(
), |
| 46 img->onImageInfo().colorSpace()) |
| 47 { |
| 48 SkASSERT(img->peekTexture()); |
46 } | 49 } |
47 | 50 |
48 ////////////////////////////////////////////////////////////////////////////// | 51 ////////////////////////////////////////////////////////////////////////////// |
49 | 52 |
50 GrBitmapTextureMaker::GrBitmapTextureMaker(GrContext* context, const SkBitmap& b
itmap) | 53 GrBitmapTextureMaker::GrBitmapTextureMaker(GrContext* context, const SkBitmap& b
itmap) |
51 : INHERITED(context, bitmap.width(), bitmap.height(), bmp_is_alpha_only(bitm
ap)) | 54 : INHERITED(context, bitmap.width(), bitmap.height(), bmp_is_alpha_only(bitm
ap)) |
52 , fBitmap(bitmap) | 55 , fBitmap(bitmap) |
53 { | 56 { |
54 if (!bitmap.isVolatile()) { | 57 if (!bitmap.isVolatile()) { |
55 SkIPoint origin = bitmap.pixelRefOrigin(); | 58 SkIPoint origin = bitmap.pixelRefOrigin(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 130 |
128 void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { | 131 void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { |
129 if (fClient) { | 132 if (fClient) { |
130 as_IB(fClient)->notifyAddedToCache(); | 133 as_IB(fClient)->notifyAddedToCache(); |
131 } | 134 } |
132 } | 135 } |
133 | 136 |
134 SkColorSpace* GrImageTextureMaker::getColorSpace() { | 137 SkColorSpace* GrImageTextureMaker::getColorSpace() { |
135 return fCacher->info().colorSpace(); | 138 return fCacher->info().colorSpace(); |
136 } | 139 } |
OLD | NEW |