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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
10 #include "SkImage_Base.h" | 10 #include "SkImage_Base.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], | 200 bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
201 SkYUVColorSpace* space) override { | 201 SkYUVColorSpace* space) override { |
202 return fGen->getYUV8Planes(sizes, planes, rowBytes, space); | 202 return fGen->getYUV8Planes(sizes, planes, rowBytes, space); |
203 } | 203 } |
204 }; | 204 }; |
205 | 205 |
206 static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { | 206 static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { |
207 tex->resourcePriv().setUniqueKey(key); | 207 tex->resourcePriv().setUniqueKey(key); |
208 return tex; | 208 return tex; |
209 } | 209 } |
210 #endif | |
211 | 210 |
212 /* | 211 /* |
213 * We have a 5 ways to try to return a texture (in sorted order) | 212 * We have a 5 ways to try to return a texture (in sorted order) |
214 * | 213 * |
215 * 1. Check the cache for a pre-existing one | 214 * 1. Check the cache for a pre-existing one |
216 * 2. Ask the genreator to natively create one | 215 * 2. Ask the genreator to natively create one |
217 * 3. Ask the generator to return a compressed form that the GPU might support | 216 * 3. Ask the generator to return a compressed form that the GPU might support |
218 * 4. Ask the generator to return YUV planes, which the GPU can convert | 217 * 4. Ask the generator to return YUV planes, which the GPU can convert |
219 * 5. Ask the generator to return RGB(A) data, which the GPU can convert | 218 * 5. Ask the generator to return RGB(A) data, which the GPU can convert |
220 */ | 219 */ |
221 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa
ge, | 220 GrTexture* SkImageCacherator::lockUnstretchedTexture(GrContext* ctx, SkImageUsag
eType usage, |
222 const SkImage* client) { | 221 const SkImage* client) { |
223 #if SK_SUPPORT_GPU | |
224 if (!ctx) { | |
225 return nullptr; | |
226 } | |
227 | |
228 // textures (at least the texture-key) only support 16bit dimensions, so abo
rt early | 222 // textures (at least the texture-key) only support 16bit dimensions, so abo
rt early |
229 // if we're too big. | 223 // if we're too big. |
230 if (fInfo.width() > 0xFFFF || fInfo.height() > 0xFFFF) { | 224 if (fInfo.width() > 0xFFFF || fInfo.height() > 0xFFFF) { |
231 return nullptr; | 225 return nullptr; |
232 } | 226 } |
233 | 227 |
234 GrUniqueKey key; | 228 GrUniqueKey key; |
235 GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.h
eight()), | 229 GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.h
eight()), |
236 *ctx->caps(), usage); | 230 *ctx->caps(), usage); |
237 | 231 |
(...skipping 30 matching lines...) Expand all Loading... |
268 if (tex) { | 262 if (tex) { |
269 return set_key_and_return(tex, key); | 263 return set_key_and_return(tex, key); |
270 } | 264 } |
271 } | 265 } |
272 | 266 |
273 // 5. Ask the generator to return RGB(A) data, which the GPU can convert | 267 // 5. Ask the generator to return RGB(A) data, which the GPU can convert |
274 SkBitmap bitmap; | 268 SkBitmap bitmap; |
275 if (this->tryLockAsBitmap(&bitmap, client)) { | 269 if (this->tryLockAsBitmap(&bitmap, client)) { |
276 return GrRefCachedBitmapTexture(ctx, bitmap, usage); | 270 return GrRefCachedBitmapTexture(ctx, bitmap, usage); |
277 } | 271 } |
278 #endif | |
279 | |
280 return nullptr; | 272 return nullptr; |
281 } | 273 } |
282 | 274 |
| 275 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 276 |
| 277 #include "GrTextureMaker.h" |
| 278 |
| 279 class Cacherator_GrTextureMaker : public GrTextureMaker { |
| 280 public: |
| 281 Cacherator_GrTextureMaker(SkImageCacherator* cacher, SkImageUsageType usage, |
| 282 const SkImage* client, const GrUniqueKey& unstretc
hedKey) |
| 283 : INHERITED(cacher->info().width(), cacher->info().height()) |
| 284 , fCacher(cacher) |
| 285 , fUsage(usage) |
| 286 , fClient(client) |
| 287 , fUnstretchedKey(unstretchedKey) |
| 288 {} |
| 289 |
| 290 protected: |
| 291 // TODO: consider overriding this, for the case where the underlying generat
or might be |
| 292 // able to efficiently produce a "stretched" texture natively (e.g. pi
cture-backed) |
| 293 // GrTexture* onGenerateStretchedTexture(GrContext*, const SkGrStretch&) over
ride; |
| 294 |
| 295 GrTexture* onRefUnstretchedTexture(GrContext* ctx) override { |
| 296 return fCacher->lockUnstretchedTexture(ctx, fUsage, fClient); |
| 297 } |
| 298 |
| 299 bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKe
y) override { |
| 300 return GrMakeStretchedKey(fUnstretchedKey, stretch, stretchedKey); |
| 301 } |
| 302 |
| 303 void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override { |
| 304 if (fClient) { |
| 305 as_IB(fClient)->notifyAddedToCache(); |
| 306 } |
| 307 } |
| 308 |
| 309 bool onGetROBitmap(SkBitmap* bitmap) override { |
| 310 return fCacher->lockAsBitmap(bitmap, fClient); |
| 311 } |
| 312 |
| 313 private: |
| 314 SkImageCacherator* fCacher; |
| 315 const SkImageUsageType fUsage; |
| 316 const SkImage* fClient; |
| 317 const GrUniqueKey fUnstretchedKey; |
| 318 |
| 319 typedef GrTextureMaker INHERITED; |
| 320 }; |
| 321 |
| 322 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa
ge, |
| 323 const SkImage* client) { |
| 324 if (!ctx) { |
| 325 return nullptr; |
| 326 } |
| 327 |
| 328 GrUniqueKey key; |
| 329 GrMakeKeyFromImageID(&key, this->uniqueID(), |
| 330 SkIRect::MakeWH(this->info().width(), this->info().heig
ht()), |
| 331 *ctx->caps(), usage); |
| 332 |
| 333 return Cacherator_GrTextureMaker(this, usage, client, key).refCachedTexture(
ctx, usage); |
| 334 } |
| 335 |
| 336 #else |
| 337 |
| 338 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa
ge, |
| 339 const SkImage* client) { |
| 340 return nullptr; |
| 341 } |
| 342 |
| 343 #endif |
OLD | NEW |