Chromium Code Reviews| 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 "SkImageCacherator.h" | 10 #include "SkImageCacherator.h" |
| 11 #include "SkMallocPixelRef.h" | 11 #include "SkMallocPixelRef.h" |
| 12 #include "SkNextID.h" | 12 #include "SkNextID.h" |
| 13 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
| 14 | 14 |
| 15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
| 16 #include "GrContext.h" | 16 #include "GrContext.h" |
| 17 #include "GrGpuResourcePriv.h" | 17 #include "GrGpuResourcePriv.h" |
| 18 #include "GrResourceKey.h" | 18 #include "GrResourceKey.h" |
| 19 #include "GrTextureAccess.h" | 19 #include "GrTextureAccess.h" |
| 20 #include "GrYUVProvider.h" | 20 #include "GrYUVProvider.h" |
| 21 #include "SkGr.h" | 21 #include "SkGr.h" |
| 22 #include "SkGrPriv.h" | 22 #include "SkGrPriv.h" |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 SkImageCacherator* SkImageCacherator::NewFromGenerator(SkImageGenerator* gen, | 25 SkImageCacherator* SkImageCacherator::NewFromGenerator(SkImageGenerator* gen, |
| 26 const SkIRect* subset) { | 26 const SkIRect* subset) { |
| 27 if (!gen) { | 27 if (!gen) { |
| 28 return nullptr; | 28 return nullptr; |
| 29 } | 29 } |
| 30 | |
| 31 // We are required to take ownership of gen, regardless of if we return a ca cherator or not | |
| 32 SkAutoTDelete<SkImageGenerator> genHolder(gen); | |
| 33 | |
| 30 const SkImageInfo& info = gen->getInfo(); | 34 const SkImageInfo& info = gen->getInfo(); |
| 31 if (info.isEmpty()) { | 35 if (info.isEmpty()) { |
| 32 return nullptr; | 36 return nullptr; |
| 33 } | 37 } |
| 34 | 38 |
| 35 uint32_t uniqueID = gen->uniqueID(); | 39 uint32_t uniqueID = gen->uniqueID(); |
| 36 const SkIRect bounds = SkIRect::MakeWH(info.width(), info.height()); | 40 const SkIRect bounds = SkIRect::MakeWH(info.width(), info.height()); |
| 37 if (subset) { | 41 if (subset) { |
| 38 if (!bounds.contains(*subset)) { | 42 if (!bounds.contains(*subset)) { |
| 39 return nullptr; | 43 return nullptr; |
| 40 } | 44 } |
| 41 if (*subset != bounds) { | 45 if (*subset != bounds) { |
| 42 // we need a different uniqueID since we really are a subset of the raw generator | 46 // we need a different uniqueID since we really are a subset of the raw generator |
| 43 uniqueID = SkNextID::ImageID(); | 47 uniqueID = SkNextID::ImageID(); |
| 44 } | 48 } |
| 45 } else { | 49 } else { |
| 46 subset = &bounds; | 50 subset = &bounds; |
| 47 } | 51 } |
| 48 | 52 |
| 53 // Now that we know we can hand-off the generator (to be owned by the cacher ator) we can | |
| 54 // release our holder. (we DONT want to delete it here anymore) | |
|
tomhudson
2015/09/14 16:58:16
Nit: two words "any more" unless you're Edgar Alle
| |
| 55 genHolder.detach(); | |
| 56 | |
| 49 return new SkImageCacherator(gen, gen->getInfo().makeWH(subset->width(), sub set->height()), | 57 return new SkImageCacherator(gen, gen->getInfo().makeWH(subset->width(), sub set->height()), |
| 50 SkIPoint::Make(subset->x(), subset->y()), uniqu eID); | 58 SkIPoint::Make(subset->x(), subset->y()), uniqu eID); |
| 51 } | 59 } |
| 52 | 60 |
| 53 SkImageCacherator::SkImageCacherator(SkImageGenerator* gen, const SkImageInfo& i nfo, | 61 SkImageCacherator::SkImageCacherator(SkImageGenerator* gen, const SkImageInfo& i nfo, |
| 54 const SkIPoint& origin, uint32_t uniqueID) | 62 const SkIPoint& origin, uint32_t uniqueID) |
| 55 : fNotThreadSafeGenerator(gen) | 63 : fNotThreadSafeGenerator(gen) |
| 56 , fInfo(info) | 64 , fInfo(info) |
| 57 , fOrigin(origin) | 65 , fOrigin(origin) |
| 58 , fUniqueID(uniqueID) | 66 , fUniqueID(uniqueID) |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 // 5. Ask the generator to return RGB(A) data, which the GPU can convert | 265 // 5. Ask the generator to return RGB(A) data, which the GPU can convert |
| 258 SkBitmap bitmap; | 266 SkBitmap bitmap; |
| 259 if (this->generateBitmap(&bitmap)) { | 267 if (this->generateBitmap(&bitmap)) { |
| 260 return GrRefCachedBitmapTexture(ctx, bitmap, usage); | 268 return GrRefCachedBitmapTexture(ctx, bitmap, usage); |
| 261 } | 269 } |
| 262 #endif | 270 #endif |
| 263 | 271 |
| 264 return nullptr; | 272 return nullptr; |
| 265 } | 273 } |
| 266 | 274 |
| OLD | NEW |