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" | |
13 #include "SkTemplates.h" | 12 #include "SkTemplates.h" |
14 | 13 |
15 class GrContext; | 14 class GrContext; |
16 class GrTextureParams; | 15 class GrTextureParams; |
17 class GrUniqueKey; | 16 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); |
28 | 27 |
| 28 ~SkImageCacherator(); |
| 29 |
29 const SkImageInfo& info() const { return fInfo; } | 30 const SkImageInfo& info() const { return fInfo; } |
30 uint32_t uniqueID() const { return fUniqueID; } | 31 uint32_t uniqueID() const { return fUniqueID; } |
31 | 32 |
32 /** | 33 /** |
33 * On success (true), bitmap will point to the pixels for this generator. I
f this returns | 34 * 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. | 35 * false, the bitmap will be reset to empty. |
35 * | 36 * |
36 * If not NULL, the client will be notified (->notifyAddedToCache()) when r
esources are | 37 * If not NULL, the client will be notified (->notifyAddedToCache()) when r
esources are |
37 * added to the cache on its behalf. | 38 * added to the cache on its behalf. |
38 */ | 39 */ |
(...skipping 22 matching lines...) Expand all Loading... |
61 */ | 62 */ |
62 SkData* refEncoded(GrContext*); | 63 SkData* refEncoded(GrContext*); |
63 | 64 |
64 // Only return true if the generate has already been cached. | 65 // Only return true if the generate has already been cached. |
65 bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*); | 66 bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*); |
66 // Call the underlying generator directly | 67 // Call the underlying generator directly |
67 bool directGeneratePixels(const SkImageInfo& dstInfo, void* dstPixels, size_
t dstRB, | 68 bool directGeneratePixels(const SkImageInfo& dstInfo, void* dstPixels, size_
t dstRB, |
68 int srcX, int srcY); | 69 int srcX, int srcY); |
69 | 70 |
70 private: | 71 private: |
| 72 class SharedGenerator; |
| 73 class ScopedGenerator; |
| 74 |
71 struct Validator { | 75 struct Validator { |
72 Validator(SkImageGenerator*, const SkIRect* subset); | 76 Validator(SkImageGenerator*, const SkIRect* subset); |
| 77 ~Validator(); |
73 | 78 |
74 operator bool() const { return fGenerator.get(); } | 79 operator bool() const { return fSharedGenerator.get(); } |
75 | 80 |
76 std::unique_ptr<SkImageGenerator> fGenerator; | 81 sk_sp<SharedGenerator> fSharedGenerator; |
77 SkImageInfo fInfo; | 82 SkImageInfo fInfo; |
78 SkIPoint fOrigin; | 83 SkIPoint fOrigin; |
79 uint32_t fUniqueID; | 84 uint32_t fUniqueID; |
80 }; | 85 }; |
81 | 86 |
82 SkImageCacherator(Validator*); | 87 SkImageCacherator(Validator*); |
83 | 88 |
84 bool generateBitmap(SkBitmap*); | 89 bool generateBitmap(SkBitmap*); |
85 bool tryLockAsBitmap(SkBitmap*, const SkImage*, SkImage::CachingHint); | 90 bool tryLockAsBitmap(SkBitmap*, const SkImage*, SkImage::CachingHint); |
86 #if SK_SUPPORT_GPU | 91 #if SK_SUPPORT_GPU |
87 // Returns the texture. If the cacherator is generating the texture and want
s to cache it, | 92 // Returns the texture. If the cacherator is generating the texture and want
s to cache it, |
88 // it should use the passed in key (if the key is valid). | 93 // it should use the passed in key (if the key is valid). |
89 GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* cl
ient, | 94 GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* cl
ient, |
90 SkImage::CachingHint, bool willBeMipped, SkSourceGamm
aTreatment); | 95 SkImage::CachingHint, bool willBeMipped, SkSourceGamm
aTreatment); |
91 #endif | 96 #endif |
92 | 97 |
93 class ScopedGenerator { | 98 sk_sp<SharedGenerator> fSharedGenerator; |
94 SkImageCacherator* fCacher; | 99 const SkImageInfo fInfo; |
95 public: | 100 const SkIPoint fOrigin; |
96 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { | 101 const uint32_t fUniqueID; |
97 fCacher->fMutexForGenerator.acquire(); | |
98 } | |
99 ~ScopedGenerator() { | |
100 fCacher->fMutexForGenerator.release(); | |
101 } | |
102 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } | |
103 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } | |
104 }; | |
105 | |
106 SkMutex fMutexForGenerator; | |
107 SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator; | |
108 | |
109 const SkImageInfo fInfo; | |
110 const SkIPoint fOrigin; | |
111 const uint32_t fUniqueID; | |
112 | 102 |
113 friend class GrImageTextureMaker; | 103 friend class GrImageTextureMaker; |
114 friend class SkImage; | 104 friend class SkImage; |
115 friend class SkImage_Generator; | 105 friend class SkImage_Generator; |
116 }; | 106 }; |
117 | 107 |
118 #endif | 108 #endif |
OLD | NEW |