| 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" |
| 11 #include "SkImageCacherator.h" | 11 #include "SkImageCacherator.h" |
| 12 #include "SkMallocPixelRef.h" | 12 #include "SkMallocPixelRef.h" |
| 13 #include "SkNextID.h" | 13 #include "SkNextID.h" |
| 14 #include "SkPixelRef.h" | 14 #include "SkPixelRef.h" |
| 15 #include "SkResourceCache.h" | 15 #include "SkResourceCache.h" |
| 16 | 16 |
| 17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
| 18 #include "GrContext.h" | 18 #include "GrContext.h" |
| 19 #include "GrGpuResourcePriv.h" | 19 #include "GrGpuResourcePriv.h" |
| 20 #include "GrImageIDTextureAdjuster.h" | 20 #include "GrImageIDTextureAdjuster.h" |
| 21 #include "GrResourceKey.h" | 21 #include "GrResourceKey.h" |
| 22 #include "GrTextureParams.h" | 22 #include "GrTextureParams.h" |
| 23 #include "GrYUVProvider.h" | 23 #include "GrYUVProvider.h" |
| 24 #include "SkGr.h" | 24 #include "SkGr.h" |
| 25 #include "SkGrPriv.h" | 25 #include "SkGrPriv.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 // Until we actually have codecs/etc. that can contain/support a GPU texture for
mat |
| 29 // skip this step, since for some generators, returning their encoded data as a
SkData |
| 30 // can be somewhat expensive, and this call doesn't indicate to the generator th
at we're |
| 31 // only interested in GPU datas... |
| 32 // see skbug.com/ 4971, 5128, ... |
| 33 //#define SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR |
| 34 |
| 28 SkImageCacherator* SkImageCacherator::NewFromGenerator(SkImageGenerator* gen, | 35 SkImageCacherator* SkImageCacherator::NewFromGenerator(SkImageGenerator* gen, |
| 29 const SkIRect* subset) { | 36 const SkIRect* subset) { |
| 30 if (!gen) { | 37 if (!gen) { |
| 31 return nullptr; | 38 return nullptr; |
| 32 } | 39 } |
| 33 | 40 |
| 34 // We are required to take ownership of gen, regardless of if we return a ca
cherator or not | 41 // We are required to take ownership of gen, regardless of if we return a ca
cherator or not |
| 35 SkAutoTDelete<SkImageGenerator> genHolder(gen); | 42 SkAutoTDelete<SkImageGenerator> genHolder(gen); |
| 36 | 43 |
| 37 const SkImageInfo& info = gen->getInfo(); | 44 const SkImageInfo& info = gen->getInfo(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 return check_output_bitmap(*bitmap, fUniqueID); | 195 return check_output_bitmap(*bitmap, fUniqueID); |
| 189 #else | 196 #else |
| 190 return false; | 197 return false; |
| 191 #endif | 198 #endif |
| 192 } | 199 } |
| 193 | 200 |
| 194 ////////////////////////////////////////////////////////////////////////////////
////////////////// | 201 ////////////////////////////////////////////////////////////////////////////////
////////////////// |
| 195 | 202 |
| 196 #if SK_SUPPORT_GPU | 203 #if SK_SUPPORT_GPU |
| 197 | 204 |
| 205 #ifdef SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR |
| 198 static GrTexture* load_compressed_into_texture(GrContext* ctx, SkData* data, GrS
urfaceDesc desc) { | 206 static GrTexture* load_compressed_into_texture(GrContext* ctx, SkData* data, GrS
urfaceDesc desc) { |
| 199 const void* rawStart; | 207 const void* rawStart; |
| 200 GrPixelConfig config = GrIsCompressedTextureDataSupported(ctx, data, desc.fW
idth, desc.fHeight, | 208 GrPixelConfig config = GrIsCompressedTextureDataSupported(ctx, data, desc.fW
idth, desc.fHeight, |
| 201 &rawStart); | 209 &rawStart); |
| 202 if (kUnknown_GrPixelConfig == config) { | 210 if (kUnknown_GrPixelConfig == config) { |
| 203 return nullptr; | 211 return nullptr; |
| 204 } | 212 } |
| 205 | 213 |
| 206 desc.fConfig = config; | 214 desc.fConfig = config; |
| 207 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, rawStar
t, 0); | 215 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, rawStar
t, 0); |
| 208 } | 216 } |
| 217 #endif |
| 209 | 218 |
| 210 class Generator_GrYUVProvider : public GrYUVProvider { | 219 class Generator_GrYUVProvider : public GrYUVProvider { |
| 211 SkImageGenerator* fGen; | 220 SkImageGenerator* fGen; |
| 212 | 221 |
| 213 public: | 222 public: |
| 214 Generator_GrYUVProvider(SkImageGenerator* gen) : fGen(gen) {} | 223 Generator_GrYUVProvider(SkImageGenerator* gen) : fGen(gen) {} |
| 215 | 224 |
| 216 uint32_t onGetID() override { return fGen->uniqueID(); } | 225 uint32_t onGetID() override { return fGen->uniqueID(); } |
| 217 bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const
override { | 226 bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const
override { |
| 218 return fGen->queryYUV8(sizeInfo, colorSpace); | 227 return fGen->queryYUV8(sizeInfo, colorSpace); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width
(), fInfo.height()); | 278 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width
(), fInfo.height()); |
| 270 if (GrTexture* tex = generator->generateTexture(ctx, &subset)) { | 279 if (GrTexture* tex = generator->generateTexture(ctx, &subset)) { |
| 271 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath, | 280 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath, |
| 272 kLockTexturePathCount); | 281 kLockTexturePathCount); |
| 273 return set_key_and_return(tex, key); | 282 return set_key_and_return(tex, key); |
| 274 } | 283 } |
| 275 } | 284 } |
| 276 | 285 |
| 277 const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo, *ctx->caps()); | 286 const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo, *ctx->caps()); |
| 278 | 287 |
| 288 #ifdef SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR |
| 279 // 3. Ask the generator to return a compressed form that the GPU might suppo
rt | 289 // 3. Ask the generator to return a compressed form that the GPU might suppo
rt |
| 280 SkAutoTUnref<SkData> data(this->refEncoded(ctx)); | 290 SkAutoTUnref<SkData> data(this->refEncoded(ctx)); |
| 281 if (data) { | 291 if (data) { |
| 282 GrTexture* tex = load_compressed_into_texture(ctx, data, desc); | 292 GrTexture* tex = load_compressed_into_texture(ctx, data, desc); |
| 283 if (tex) { | 293 if (tex) { |
| 284 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kCompressed_LockTextureP
ath, | 294 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kCompressed_LockTextureP
ath, |
| 285 kLockTexturePathCount); | 295 kLockTexturePathCount); |
| 286 return set_key_and_return(tex, key); | 296 return set_key_and_return(tex, key); |
| 287 } | 297 } |
| 288 } | 298 } |
| 299 #endif |
| 289 | 300 |
| 290 // 4. Ask the generator to return YUV planes, which the GPU can convert | 301 // 4. Ask the generator to return YUV planes, which the GPU can convert |
| 291 { | 302 { |
| 292 ScopedGenerator generator(this); | 303 ScopedGenerator generator(this); |
| 293 Generator_GrYUVProvider provider(generator); | 304 Generator_GrYUVProvider provider(generator); |
| 294 sk_sp<GrTexture> tex = provider.refAsTexture(ctx, desc, true); | 305 sk_sp<GrTexture> tex = provider.refAsTexture(ctx, desc, true); |
| 295 if (tex) { | 306 if (tex) { |
| 296 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath, | 307 SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath, |
| 297 kLockTexturePathCount); | 308 kLockTexturePathCount); |
| 298 return set_key_and_return(tex.release(), key); | 309 return set_key_and_return(tex.release(), key); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 343 } |
| 333 | 344 |
| 334 #else | 345 #else |
| 335 | 346 |
| 336 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s&, | 347 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s&, |
| 337 const SkImage* client, SkImage::Cach
ingHint) { | 348 const SkImage* client, SkImage::Cach
ingHint) { |
| 338 return nullptr; | 349 return nullptr; |
| 339 } | 350 } |
| 340 | 351 |
| 341 #endif | 352 #endif |
| OLD | NEW |