| 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 14 matching lines...) Expand all Loading... |
| 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 | 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 | 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 | 30 // can be somewhat expensive, and this call doesn't indicate to the generator th
at we're |
| 31 // only interested in GPU datas... | 31 // only interested in GPU datas... |
| 32 // see skbug.com/ 4971, 5128, ... | 32 // see skbug.com/ 4971, 5128, ... |
| 33 //#define SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR | 33 //#define SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR |
| 34 | 34 |
| 35 SkImageCacherator* SkImageCacherator::NewFromGenerator(SkImageGenerator* gen, | 35 SkImageCacherator::Validator::Validator(SkImageGenerator* gen, const SkIRect* su
bset) |
| 36 const SkIRect* subset) { | 36 // We are required to take ownership of gen, regardless of whether we instan
tiate a cacherator |
| 37 // or not. On instantiation, the client is responsible for transferring own
ership. |
| 38 : fGenerator(gen) { |
| 39 |
| 37 if (!gen) { | 40 if (!gen) { |
| 38 return nullptr; | 41 return; |
| 39 } | 42 } |
| 40 | 43 |
| 41 // We are required to take ownership of gen, regardless of if we return a ca
cherator or not | |
| 42 SkAutoTDelete<SkImageGenerator> genHolder(gen); | |
| 43 | |
| 44 const SkImageInfo& info = gen->getInfo(); | 44 const SkImageInfo& info = gen->getInfo(); |
| 45 if (info.isEmpty()) { | 45 if (info.isEmpty()) { |
| 46 return nullptr; | 46 fGenerator.reset(); |
| 47 return; |
| 47 } | 48 } |
| 48 | 49 |
| 49 uint32_t uniqueID = gen->uniqueID(); | 50 fUniqueID = gen->uniqueID(); |
| 50 const SkIRect bounds = SkIRect::MakeWH(info.width(), info.height()); | 51 const SkIRect bounds = SkIRect::MakeWH(info.width(), info.height()); |
| 51 if (subset) { | 52 if (subset) { |
| 52 if (!bounds.contains(*subset)) { | 53 if (!bounds.contains(*subset)) { |
| 53 return nullptr; | 54 fGenerator.reset(); |
| 55 return; |
| 54 } | 56 } |
| 55 if (*subset != bounds) { | 57 if (*subset != bounds) { |
| 56 // we need a different uniqueID since we really are a subset of the
raw generator | 58 // we need a different uniqueID since we really are a subset of the
raw generator |
| 57 uniqueID = SkNextID::ImageID(); | 59 fUniqueID = SkNextID::ImageID(); |
| 58 } | 60 } |
| 59 } else { | 61 } else { |
| 60 subset = &bounds; | 62 subset = &bounds; |
| 61 } | 63 } |
| 62 | 64 |
| 63 // Now that we know we can hand-off the generator (to be owned by the cacher
ator) we can | 65 fInfo = info.makeWH(subset->width(), subset->height()); |
| 64 // release our holder. (we DONT want to delete it here anymore) | 66 fOrigin = SkIPoint::Make(subset->x(), subset->y()); |
| 65 genHolder.release(); | |
| 66 | |
| 67 return new SkImageCacherator(gen, gen->getInfo().makeWH(subset->width(), sub
set->height()), | |
| 68 SkIPoint::Make(subset->x(), subset->y()), uniqu
eID); | |
| 69 } | 67 } |
| 70 | 68 |
| 71 SkImageCacherator::SkImageCacherator(SkImageGenerator* gen, const SkImageInfo& i
nfo, | 69 SkImageCacherator* SkImageCacherator::NewFromGenerator(SkImageGenerator* gen, |
| 72 const SkIPoint& origin, uint32_t uniqueID) | 70 const SkIRect* subset) { |
| 73 : fNotThreadSafeGenerator(gen) | 71 Validator validator(gen, subset); |
| 74 , fInfo(info) | 72 |
| 75 , fOrigin(origin) | 73 return validator ? new SkImageCacherator(&validator) : nullptr; |
| 76 , fUniqueID(uniqueID) | 74 } |
| 77 {} | 75 |
| 76 SkImageCacherator::SkImageCacherator(Validator* validator) |
| 77 : fNotThreadSafeGenerator(validator->fGenerator.release()) // we take owners
hip |
| 78 , fInfo(validator->fInfo) |
| 79 , fOrigin(validator->fOrigin) |
| 80 , fUniqueID(validator->fUniqueID) |
| 81 { |
| 82 SkASSERT(fNotThreadSafeGenerator); |
| 83 } |
| 78 | 84 |
| 79 SkData* SkImageCacherator::refEncoded(GrContext* ctx) { | 85 SkData* SkImageCacherator::refEncoded(GrContext* ctx) { |
| 80 ScopedGenerator generator(this); | 86 ScopedGenerator generator(this); |
| 81 return generator->refEncodedData(ctx); | 87 return generator->refEncodedData(ctx); |
| 82 } | 88 } |
| 83 | 89 |
| 84 static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) { | 90 static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) { |
| 85 SkASSERT(bitmap.getGenerationID() == expectedID); | 91 SkASSERT(bitmap.getGenerationID() == expectedID); |
| 86 SkASSERT(bitmap.isImmutable()); | 92 SkASSERT(bitmap.isImmutable()); |
| 87 SkASSERT(bitmap.getPixels()); | 93 SkASSERT(bitmap.getPixels()); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 353 |
| 348 #else | 354 #else |
| 349 | 355 |
| 350 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s&, | 356 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam
s&, |
| 351 SkSourceGammaTreatment gammaTreatmen
t, | 357 SkSourceGammaTreatment gammaTreatmen
t, |
| 352 const SkImage* client, SkImage::Cach
ingHint) { | 358 const SkImage* client, SkImage::Cach
ingHint) { |
| 353 return nullptr; | 359 return nullptr; |
| 354 } | 360 } |
| 355 | 361 |
| 356 #endif | 362 #endif |
| OLD | NEW |