| 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 "SkHistogramLogging.h" |
| 10 #include "SkImage_Base.h" | 11 #include "SkImage_Base.h" |
| 11 #include "SkImageCacherator.h" | 12 #include "SkImageCacherator.h" |
| 12 #include "SkMallocPixelRef.h" | 13 #include "SkMallocPixelRef.h" |
| 13 #include "SkNextID.h" | 14 #include "SkNextID.h" |
| 14 #include "SkPixelRef.h" | 15 #include "SkPixelRef.h" |
| 15 #include "SkResourceCache.h" | 16 #include "SkResourceCache.h" |
| 16 | 17 |
| 17 #if SK_SUPPORT_GPU | 18 #if SK_SUPPORT_GPU |
| 18 #include "GrContext.h" | 19 #include "GrContext.h" |
| 19 #include "GrGpuResourcePriv.h" | 20 #include "GrGpuResourcePriv.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 * We have a 5 ways to try to return a texture (in sorted order) | 234 * We have a 5 ways to try to return a texture (in sorted order) |
| 234 * | 235 * |
| 235 * 1. Check the cache for a pre-existing one | 236 * 1. Check the cache for a pre-existing one |
| 236 * 2. Ask the generator to natively create one | 237 * 2. Ask the generator to natively create one |
| 237 * 3. Ask the generator to return a compressed form that the GPU might support | 238 * 3. Ask the generator to return a compressed form that the GPU might support |
| 238 * 4. Ask the generator to return YUV planes, which the GPU can convert | 239 * 4. Ask the generator to return YUV planes, which the GPU can convert |
| 239 * 5. Ask the generator to return RGB(A) data, which the GPU can convert | 240 * 5. Ask the generator to return RGB(A) data, which the GPU can convert |
| 240 */ | 241 */ |
| 241 GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key
, | 242 GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key
, |
| 242 const SkImage* client, SkImage::Cachin
gHint chint) { | 243 const SkImage* client, SkImage::Cachin
gHint chint) { |
| 244 // Values representing the various texture lock paths we can take. Used for
logging the path |
| 245 // taken to a histogram. |
| 246 enum LockTexturePath { |
| 247 kPreExisting_LockTexturePath, |
| 248 kNative_LockTexturePath, |
| 249 kCompressed_LockTexturePath, |
| 250 kYUV_LockTexturePath, |
| 251 kRGBA_LockTexturePath, |
| 252 kFailure_LockTexturePath, |
| 253 }; |
| 254 |
| 255 const int kLockTexturePathCount = kFailure_LockTexturePath + 1; |
| 256 |
| 243 // 1. Check the cache for a pre-existing one | 257 // 1. Check the cache for a pre-existing one |
| 244 if (key.isValid()) { | 258 if (key.isValid()) { |
| 245 if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKe
y(key)) { | 259 if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKe
y(key)) { |
| 260 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kPreExisting_LockTexture
Path, |
| 261 kLockTexturePathCount); |
| 246 return tex; | 262 return tex; |
| 247 } | 263 } |
| 248 } | 264 } |
| 249 | 265 |
| 250 // 2. Ask the generator to natively create one | 266 // 2. Ask the generator to natively create one |
| 251 { | 267 { |
| 252 ScopedGenerator generator(this); | 268 ScopedGenerator generator(this); |
| 253 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width
(), fInfo.height()); | 269 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width
(), fInfo.height()); |
| 254 if (GrTexture* tex = generator->generateTexture(ctx, &subset)) { | 270 if (GrTexture* tex = generator->generateTexture(ctx, &subset)) { |
| 271 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath, |
| 272 kLockTexturePathCount); |
| 255 return set_key_and_return(tex, key); | 273 return set_key_and_return(tex, key); |
| 256 } | 274 } |
| 257 } | 275 } |
| 258 | 276 |
| 259 const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo); | 277 const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo); |
| 260 | 278 |
| 261 // 3. Ask the generator to return a compressed form that the GPU might suppo
rt | 279 // 3. Ask the generator to return a compressed form that the GPU might suppo
rt |
| 262 SkAutoTUnref<SkData> data(this->refEncoded(ctx)); | 280 SkAutoTUnref<SkData> data(this->refEncoded(ctx)); |
| 263 if (data) { | 281 if (data) { |
| 264 GrTexture* tex = load_compressed_into_texture(ctx, data, desc); | 282 GrTexture* tex = load_compressed_into_texture(ctx, data, desc); |
| 265 if (tex) { | 283 if (tex) { |
| 284 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kCompressed_LockTextureP
ath, |
| 285 kLockTexturePathCount); |
| 266 return set_key_and_return(tex, key); | 286 return set_key_and_return(tex, key); |
| 267 } | 287 } |
| 268 } | 288 } |
| 269 | 289 |
| 270 // 4. Ask the generator to return YUV planes, which the GPU can convert | 290 // 4. Ask the generator to return YUV planes, which the GPU can convert |
| 271 { | 291 { |
| 272 ScopedGenerator generator(this); | 292 ScopedGenerator generator(this); |
| 273 Generator_GrYUVProvider provider(generator); | 293 Generator_GrYUVProvider provider(generator); |
| 274 GrTexture* tex = provider.refAsTexture(ctx, desc, true); | 294 GrTexture* tex = provider.refAsTexture(ctx, desc, true); |
| 275 if (tex) { | 295 if (tex) { |
| 296 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath, |
| 297 kLockTexturePathCount); |
| 276 return set_key_and_return(tex, key); | 298 return set_key_and_return(tex, key); |
| 277 } | 299 } |
| 278 } | 300 } |
| 279 | 301 |
| 280 // 5. Ask the generator to return RGB(A) data, which the GPU can convert | 302 // 5. Ask the generator to return RGB(A) data, which the GPU can convert |
| 281 SkBitmap bitmap; | 303 SkBitmap bitmap; |
| 282 if (this->tryLockAsBitmap(&bitmap, client, chint)) { | 304 if (this->tryLockAsBitmap(&bitmap, client, chint)) { |
| 283 GrTexture* tex = GrUploadBitmapToTexture(ctx, bitmap); | 305 GrTexture* tex = GrUploadBitmapToTexture(ctx, bitmap); |
| 284 if (tex) { | 306 if (tex) { |
| 307 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath, |
| 308 kLockTexturePathCount); |
| 285 return set_key_and_return(tex, key); | 309 return set_key_and_return(tex, key); |
| 286 } | 310 } |
| 287 } | 311 } |
| 312 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kFailure_LockTexturePath, |
| 313 kLockTexturePathCount); |
| 288 return nullptr; | 314 return nullptr; |
| 289 } | 315 } |
| 290 | 316 |
| 291 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 317 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 292 | 318 |
| 293 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s& params, | 319 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s& params, |
| 294 const SkImage* client, SkImage::Cach
ingHint chint) { | 320 const SkImage* client, SkImage::Cach
ingHint chint) { |
| 295 if (!ctx) { | 321 if (!ctx) { |
| 296 return nullptr; | 322 return nullptr; |
| 297 } | 323 } |
| 298 | 324 |
| 299 return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(par
ams); | 325 return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(par
ams); |
| 300 } | 326 } |
| 301 | 327 |
| 302 #else | 328 #else |
| 303 | 329 |
| 304 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s&, | 330 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s&, |
| 305 const SkImage* client, SkImage::Cach
ingHint) { | 331 const SkImage* client, SkImage::Cach
ingHint) { |
| 306 return nullptr; | 332 return nullptr; |
| 307 } | 333 } |
| 308 | 334 |
| 309 #endif | 335 #endif |
| OLD | NEW |