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 "SkCanvas.h" |
13 #include "SkGrPriv.h" | 14 #include "SkGrPriv.h" |
14 #include "SkImage_Base.h" | 15 #include "SkImage_Base.h" |
15 #include "SkImageCacherator.h" | 16 #include "SkImageCacherator.h" |
16 #include "SkPixelRef.h" | 17 #include "SkPixelRef.h" |
17 | 18 |
18 static bool bmp_is_alpha_only(const SkBitmap& bm) { return kAlpha_8_SkColorType
== bm.colorType(); } | 19 static bool bmp_is_alpha_only(const SkBitmap& bm) { return kAlpha_8_SkColorType
== bm.colorType(); } |
19 | 20 |
20 GrBitmapTextureAdjuster::GrBitmapTextureAdjuster(const SkBitmap* bmp) | 21 GrBitmapTextureAdjuster::GrBitmapTextureAdjuster(const SkBitmap* bmp) |
21 : INHERITED(bmp->getTexture(), | 22 : INHERITED(bmp->getTexture(), |
22 SkIRect::MakeWH(bmp->width(), bmp->height()), | 23 SkIRect::MakeWH(bmp->width(), bmp->height()), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 , fBitmap(bitmap) { | 75 , fBitmap(bitmap) { |
75 SkASSERT(!bitmap.getTexture()); | 76 SkASSERT(!bitmap.getTexture()); |
76 if (!bitmap.isVolatile()) { | 77 if (!bitmap.isVolatile()) { |
77 SkIPoint origin = bitmap.pixelRefOrigin(); | 78 SkIPoint origin = bitmap.pixelRefOrigin(); |
78 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(), | 79 SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(), |
79 bitmap.height()); | 80 bitmap.height()); |
80 GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGenerationID()
, subset); | 81 GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGenerationID()
, subset); |
81 } | 82 } |
82 } | 83 } |
83 | 84 |
84 GrTexture* GrBitmapTextureMaker::refOriginalTexture() { | 85 GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped) { |
85 GrTexture* tex; | 86 GrTexture* tex; |
86 | 87 |
87 if (fOriginalKey.isValid()) { | 88 if (fOriginalKey.isValid()) { |
88 tex = this->context()->textureProvider()->findAndRefTextureByUniqueKey(f
OriginalKey); | 89 tex = this->context()->textureProvider()->findAndRefTextureByUniqueKey(f
OriginalKey); |
89 if (tex) { | 90 if (tex) { |
90 return tex; | 91 return tex; |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 tex = GrUploadBitmapToTexture(this->context(), fBitmap); | 95 if (willBeMipped) { |
| 96 tex = GrGenerateMipMapsAndUploadToTexture(this->context(), fBitmap); |
| 97 } else { |
| 98 tex = GrUploadBitmapToTexture(this->context(), fBitmap); |
| 99 } |
95 if (tex && fOriginalKey.isValid()) { | 100 if (tex && fOriginalKey.isValid()) { |
96 tex->resourcePriv().setUniqueKey(fOriginalKey); | 101 tex->resourcePriv().setUniqueKey(fOriginalKey); |
97 GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef()); | 102 GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef()); |
98 } | 103 } |
99 return tex; | 104 return tex; |
100 } | 105 } |
101 | 106 |
102 void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey
* copyKey) { | 107 void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey
* copyKey) { |
103 if (fOriginalKey.isValid()) { | 108 if (fOriginalKey.isValid()) { |
104 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); | 109 MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); |
(...skipping 14 matching lines...) Expand all Loading... |
119 cacher_is_alpha_only(*cacher)) | 124 cacher_is_alpha_only(*cacher)) |
120 , fCacher(cacher) | 125 , fCacher(cacher) |
121 , fClient(client) | 126 , fClient(client) |
122 , fCachingHint(chint) { | 127 , fCachingHint(chint) { |
123 if (client) { | 128 if (client) { |
124 GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(), | 129 GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(), |
125 SkIRect::MakeWH(this->width(), this->height())); | 130 SkIRect::MakeWH(this->width(), this->height())); |
126 } | 131 } |
127 } | 132 } |
128 | 133 |
129 GrTexture* GrImageTextureMaker::refOriginalTexture() { | 134 GrTexture* GrImageTextureMaker::refOriginalTexture(bool willBeMipped) { |
130 return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCaching
Hint); | 135 return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCaching
Hint, willBeMipped); |
131 } | 136 } |
132 | 137 |
133 void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* pa
ramsCopyKey) { | 138 void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* pa
ramsCopyKey) { |
134 if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { | 139 if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { |
135 MakeCopyKeyFromOrigKey(fOriginalKey, stretch, paramsCopyKey); | 140 MakeCopyKeyFromOrigKey(fOriginalKey, stretch, paramsCopyKey); |
136 } | 141 } |
137 } | 142 } |
138 | 143 |
139 void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { | 144 void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { |
140 if (fClient) { | 145 if (fClient) { |
141 as_IB(fClient)->notifyAddedToCache(); | 146 as_IB(fClient)->notifyAddedToCache(); |
142 } | 147 } |
143 } | 148 } |
OLD | NEW |