| 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 #ifndef SkImageCacherator_DEFINED | 8 #ifndef SkImageCacherator_DEFINED |
| 9 #define SkImageCacherator_DEFINED | 9 #define SkImageCacherator_DEFINED |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 const SkImageInfo& info() const { return fInfo; } | 29 const SkImageInfo& info() const { return fInfo; } |
| 30 uint32_t uniqueID() const { return fUniqueID; } | 30 uint32_t uniqueID() const { return fUniqueID; } |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * On success (true), bitmap will point to the pixels for this generator. I
f this returns | 33 * On success (true), bitmap will point to the pixels for this generator. I
f this returns |
| 34 * false, the bitmap will be reset to empty. | 34 * false, the bitmap will be reset to empty. |
| 35 * | 35 * |
| 36 * If not NULL, the client will be notified (->notifyAddedToCache()) when r
esources are | 36 * If not NULL, the client will be notified (->notifyAddedToCache()) when r
esources are |
| 37 * added to the cache on its behalf. | 37 * added to the cache on its behalf. |
| 38 */ | 38 */ |
| 39 bool lockAsBitmap(SkBitmap*, const SkImage* client); | 39 bool lockAsBitmap(SkBitmap*, const SkImage* client, |
| 40 SkImage::CachingHint = SkImage::kAllow_CachingHint); |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * Returns a ref() on the texture produced by this generator. The caller mu
st call unref() | 43 * Returns a ref() on the texture produced by this generator. The caller mu
st call unref() |
| 43 * when it is done. Will return nullptr on failure. | 44 * when it is done. Will return nullptr on failure. |
| 44 * | 45 * |
| 45 * If not NULL, the client will be notified (->notifyAddedToCache()) when r
esources are | 46 * If not NULL, the client will be notified (->notifyAddedToCache()) when r
esources are |
| 46 * added to the cache on its behalf. | 47 * added to the cache on its behalf. |
| 47 * | 48 * |
| 48 * The caller is responsible for calling texture->unref() when they are don
e. | 49 * The caller is responsible for calling texture->unref() when they are don
e. |
| 49 */ | 50 */ |
| 50 GrTexture* lockAsTexture(GrContext*, const GrTextureParams&, const SkImage*
client); | 51 GrTexture* lockAsTexture(GrContext*, const GrTextureParams&, const SkImage*
client, |
| 52 SkImage::CachingHint = SkImage::kAllow_CachingHint)
; |
| 51 | 53 |
| 52 /** | 54 /** |
| 53 * If the underlying src naturally is represented by an encoded blob (in Sk
Data), this returns | 55 * If the underlying src naturally is represented by an encoded blob (in Sk
Data), this returns |
| 54 * a ref to that data. If not, it returns null. | 56 * a ref to that data. If not, it returns null. |
| 55 */ | 57 */ |
| 56 SkData* refEncoded(); | 58 SkData* refEncoded(); |
| 57 | 59 |
| 58 private: | 60 private: |
| 59 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); | 61 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); |
| 60 | 62 |
| 61 bool generateBitmap(SkBitmap*); | 63 bool generateBitmap(SkBitmap*); |
| 62 bool tryLockAsBitmap(SkBitmap*, const SkImage*); | 64 bool tryLockAsBitmap(SkBitmap*, const SkImage*, SkImage::CachingHint); |
| 63 #if SK_SUPPORT_GPU | 65 #if SK_SUPPORT_GPU |
| 64 // Returns the texture. If the cacherator is generating the texture and want
s to cache it, | 66 // Returns the texture. If the cacherator is generating the texture and want
s to cache it, |
| 65 // it should use the passed in key (if the key is valid). | 67 // it should use the passed in key (if the key is valid). |
| 66 GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* cl
ient); | 68 GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* cl
ient, |
| 69 SkImage::CachingHint); |
| 67 #endif | 70 #endif |
| 68 | 71 |
| 69 class ScopedGenerator { | 72 class ScopedGenerator { |
| 70 SkImageCacherator* fCacher; | 73 SkImageCacherator* fCacher; |
| 71 public: | 74 public: |
| 72 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { | 75 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { |
| 73 fCacher->fMutexForGenerator.acquire(); | 76 fCacher->fMutexForGenerator.acquire(); |
| 74 } | 77 } |
| 75 ~ScopedGenerator() { | 78 ~ScopedGenerator() { |
| 76 fCacher->fMutexForGenerator.release(); | 79 fCacher->fMutexForGenerator.release(); |
| 77 } | 80 } |
| 78 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } | 81 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } |
| 79 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } | 82 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 SkMutex fMutexForGenerator; | 85 SkMutex fMutexForGenerator; |
| 83 SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator; | 86 SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator; |
| 84 | 87 |
| 85 const SkImageInfo fInfo; | 88 const SkImageInfo fInfo; |
| 86 const SkIPoint fOrigin; | 89 const SkIPoint fOrigin; |
| 87 const uint32_t fUniqueID; | 90 const uint32_t fUniqueID; |
| 88 | 91 |
| 89 friend class Cacherator_GrTextureMaker; | 92 friend class Cacherator_GrTextureMaker; |
| 90 }; | 93 }; |
| 91 | 94 |
| 92 #endif | 95 #endif |
| OLD | NEW |