| 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 |
| 11 #include "SkImageGenerator.h" | 11 #include "SkImageGenerator.h" |
| 12 #include "SkMutex.h" | 12 #include "SkMutex.h" |
| 13 #include "SkTemplates.h" | 13 #include "SkTemplates.h" |
| 14 | 14 |
| 15 class GrContext; | 15 class GrContext; |
| 16 class GrTextureParams; | 16 class GrTextureParams; |
| 17 class GrUniqueKey; | |
| 18 class SkBitmap; | 17 class SkBitmap; |
| 19 class SkImage; | 18 class SkImage; |
| 20 | 19 |
| 21 /* | 20 /* |
| 22 * Internal class to manage caching the output of an ImageGenerator. | 21 * Internal class to manage caching the output of an ImageGenerator. |
| 23 */ | 22 */ |
| 24 class SkImageCacherator { | 23 class SkImageCacherator { |
| 25 public: | 24 public: |
| 26 // Takes ownership of the generator | 25 // Takes ownership of the generator |
| 27 static SkImageCacherator* NewFromGenerator(SkImageGenerator*, const SkIRect*
subset = nullptr); | 26 static SkImageCacherator* NewFromGenerator(SkImageGenerator*, const SkIRect*
subset = nullptr); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 54 * a ref to that data. If not, it returns null. | 53 * a ref to that data. If not, it returns null. |
| 55 */ | 54 */ |
| 56 SkData* refEncoded(); | 55 SkData* refEncoded(); |
| 57 | 56 |
| 58 private: | 57 private: |
| 59 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); | 58 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); |
| 60 | 59 |
| 61 bool generateBitmap(SkBitmap*); | 60 bool generateBitmap(SkBitmap*); |
| 62 bool tryLockAsBitmap(SkBitmap*, const SkImage*); | 61 bool tryLockAsBitmap(SkBitmap*, const SkImage*); |
| 63 #if SK_SUPPORT_GPU | 62 #if SK_SUPPORT_GPU |
| 64 // Returns the texture. If the cacherator is generating the texture and want
s to cache it, | 63 GrTexture* lockUnstretchedTexture(GrContext*, const SkImage* client); |
| 65 // it should use the passed in key (if the key is valid). | |
| 66 GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* cl
ient); | |
| 67 #endif | 64 #endif |
| 68 | 65 |
| 69 class ScopedGenerator { | 66 class ScopedGenerator { |
| 70 SkImageCacherator* fCacher; | 67 SkImageCacherator* fCacher; |
| 71 public: | 68 public: |
| 72 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { | 69 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { |
| 73 fCacher->fMutexForGenerator.acquire(); | 70 fCacher->fMutexForGenerator.acquire(); |
| 74 } | 71 } |
| 75 ~ScopedGenerator() { | 72 ~ScopedGenerator() { |
| 76 fCacher->fMutexForGenerator.release(); | 73 fCacher->fMutexForGenerator.release(); |
| 77 } | 74 } |
| 78 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } | 75 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } |
| 79 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } | 76 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } |
| 80 }; | 77 }; |
| 81 | 78 |
| 82 SkMutex fMutexForGenerator; | 79 SkMutex fMutexForGenerator; |
| 83 SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator; | 80 SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator; |
| 84 | 81 |
| 85 const SkImageInfo fInfo; | 82 const SkImageInfo fInfo; |
| 86 const SkIPoint fOrigin; | 83 const SkIPoint fOrigin; |
| 87 const uint32_t fUniqueID; | 84 const uint32_t fUniqueID; |
| 88 | 85 |
| 89 friend class Cacherator_GrTextureParamsAdjuster; | 86 friend class Cacherator_GrTextureMaker; |
| 90 }; | 87 }; |
| 91 | 88 |
| 92 #endif | 89 #endif |
| OLD | NEW |