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 30 matching lines...) Expand all Loading... |
41 | 41 |
42 /** | 42 /** |
43 * 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() |
44 * when it is done. Will return nullptr on failure. | 44 * when it is done. Will return nullptr on failure. |
45 * | 45 * |
46 * 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 |
47 * added to the cache on its behalf. | 47 * added to the cache on its behalf. |
48 * | 48 * |
49 * 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. |
50 */ | 50 */ |
51 GrTexture* lockAsTexture(GrContext*, const GrTextureParams&, const SkImage*
client, | 51 GrTexture* lockAsTexture(GrContext*, const GrTextureParams&, |
| 52 SkSourceGammaTreatment gammaTreatment, const SkImag
e* client, |
52 SkImage::CachingHint = SkImage::kAllow_CachingHint)
; | 53 SkImage::CachingHint = SkImage::kAllow_CachingHint)
; |
53 | 54 |
54 /** | 55 /** |
55 * If the underlying src naturally is represented by an encoded blob (in Sk
Data), this returns | 56 * If the underlying src naturally is represented by an encoded blob (in Sk
Data), this returns |
56 * a ref to that data. If not, it returns null. | 57 * a ref to that data. If not, it returns null. |
57 * | 58 * |
58 * If a GrContext is specified, then the caller is only interested in gpu-s
pecific encoded | 59 * If a GrContext is specified, then the caller is only interested in gpu-s
pecific encoded |
59 * formats, so others (e.g. PNG) can just return nullptr. | 60 * formats, so others (e.g. PNG) can just return nullptr. |
60 */ | 61 */ |
61 SkData* refEncoded(GrContext*); | 62 SkData* refEncoded(GrContext*); |
62 | 63 |
63 // Only return true if the generate has already been cached. | 64 // Only return true if the generate has already been cached. |
64 bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*); | 65 bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*); |
65 // Call the underlying generator directly | 66 // Call the underlying generator directly |
66 bool directGeneratePixels(const SkImageInfo& dstInfo, void* dstPixels, size_
t dstRB, | 67 bool directGeneratePixels(const SkImageInfo& dstInfo, void* dstPixels, size_
t dstRB, |
67 int srcX, int srcY); | 68 int srcX, int srcY); |
68 | 69 |
69 private: | 70 private: |
70 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); | 71 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); |
71 | 72 |
72 bool generateBitmap(SkBitmap*); | 73 bool generateBitmap(SkBitmap*); |
73 bool tryLockAsBitmap(SkBitmap*, const SkImage*, SkImage::CachingHint); | 74 bool tryLockAsBitmap(SkBitmap*, const SkImage*, SkImage::CachingHint); |
74 #if SK_SUPPORT_GPU | 75 #if SK_SUPPORT_GPU |
75 // Returns the texture. If the cacherator is generating the texture and want
s to cache it, | 76 // Returns the texture. If the cacherator is generating the texture and want
s to cache it, |
76 // it should use the passed in key (if the key is valid). | 77 // it should use the passed in key (if the key is valid). |
77 GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* cl
ient, | 78 GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* cl
ient, |
78 SkImage::CachingHint, bool willBeMipped); | 79 SkImage::CachingHint, bool willBeMipped, SkSourceGamm
aTreatment); |
79 #endif | 80 #endif |
80 | 81 |
81 class ScopedGenerator { | 82 class ScopedGenerator { |
82 SkImageCacherator* fCacher; | 83 SkImageCacherator* fCacher; |
83 public: | 84 public: |
84 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { | 85 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { |
85 fCacher->fMutexForGenerator.acquire(); | 86 fCacher->fMutexForGenerator.acquire(); |
86 } | 87 } |
87 ~ScopedGenerator() { | 88 ~ScopedGenerator() { |
88 fCacher->fMutexForGenerator.release(); | 89 fCacher->fMutexForGenerator.release(); |
89 } | 90 } |
90 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } | 91 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } |
91 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } | 92 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } |
92 }; | 93 }; |
93 | 94 |
94 SkMutex fMutexForGenerator; | 95 SkMutex fMutexForGenerator; |
95 SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator; | 96 SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator; |
96 | 97 |
97 const SkImageInfo fInfo; | 98 const SkImageInfo fInfo; |
98 const SkIPoint fOrigin; | 99 const SkIPoint fOrigin; |
99 const uint32_t fUniqueID; | 100 const uint32_t fUniqueID; |
100 | 101 |
101 friend class GrImageTextureMaker; | 102 friend class GrImageTextureMaker; |
102 }; | 103 }; |
103 | 104 |
104 #endif | 105 #endif |
OLD | NEW |