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 SkBitmap; | 16 class SkBitmap; |
| 17 class SkImage; |
17 | 18 |
18 /* | 19 /* |
19 * Internal class to manage caching the output of an ImageGenerator. | 20 * Internal class to manage caching the output of an ImageGenerator. |
20 */ | 21 */ |
21 class SkImageCacherator { | 22 class SkImageCacherator { |
22 public: | 23 public: |
23 // Takes ownership of the generator | 24 // Takes ownership of the generator |
24 static SkImageCacherator* NewFromGenerator(SkImageGenerator*, const SkIRect*
subset = nullptr); | 25 static SkImageCacherator* NewFromGenerator(SkImageGenerator*, const SkIRect*
subset = nullptr); |
25 | 26 |
26 const SkImageInfo& info() const { return fInfo; } | 27 const SkImageInfo& info() const { return fInfo; } |
27 uint32_t uniqueID() const { return fUniqueID; } | 28 uint32_t uniqueID() const { return fUniqueID; } |
28 | 29 |
29 /** | 30 /** |
30 * On success (true), bitmap will point to the pixels for this generator. I
f this returns | 31 * On success (true), bitmap will point to the pixels for this generator. I
f this returns |
31 * false, the bitmap will be reset to empty. | 32 * false, the bitmap will be reset to empty. |
| 33 * |
| 34 * If not NULL, the client will be notified (->notifyAddedToCache()) when r
esources are |
| 35 * added to the cache on its behalf. |
32 */ | 36 */ |
33 bool lockAsBitmap(SkBitmap*); | 37 bool lockAsBitmap(SkBitmap*, const SkImage* client); |
34 | 38 |
35 /** | 39 /** |
36 * Returns a ref() on the texture produced by this generator. The caller mu
st call unref() | 40 * Returns a ref() on the texture produced by this generator. The caller mu
st call unref() |
37 * when it is done. Will return nullptr on failure. | 41 * when it is done. Will return nullptr on failure. |
38 * | 42 * |
| 43 * If not NULL, the client will be notified (->notifyAddedToCache()) when r
esources are |
| 44 * added to the cache on its behalf. |
| 45 * |
39 * The caller is responsible for calling texture->unref() when they are don
e. | 46 * The caller is responsible for calling texture->unref() when they are don
e. |
40 */ | 47 */ |
41 GrTexture* lockAsTexture(GrContext*, SkImageUsageType); | 48 GrTexture* lockAsTexture(GrContext*, SkImageUsageType, const SkImage* client
); |
42 | 49 |
43 /** | 50 /** |
44 * If the underlying src naturally is represented by an encoded blob (in Sk
Data), this returns | 51 * If the underlying src naturally is represented by an encoded blob (in Sk
Data), this returns |
45 * a ref to that data. If not, it returns null. | 52 * a ref to that data. If not, it returns null. |
46 */ | 53 */ |
47 SkData* refEncoded(); | 54 SkData* refEncoded(); |
48 | 55 |
49 private: | 56 private: |
50 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); | 57 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); |
51 | 58 |
52 bool generateBitmap(SkBitmap*); | 59 bool generateBitmap(SkBitmap*); |
53 bool tryLockAsBitmap(SkBitmap*); | 60 bool tryLockAsBitmap(SkBitmap*, const SkImage*); |
54 | 61 |
55 class ScopedGenerator { | 62 class ScopedGenerator { |
56 SkImageCacherator* fCacher; | 63 SkImageCacherator* fCacher; |
57 public: | 64 public: |
58 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { | 65 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { |
59 fCacher->fMutexForGenerator.acquire(); | 66 fCacher->fMutexForGenerator.acquire(); |
60 } | 67 } |
61 ~ScopedGenerator() { | 68 ~ScopedGenerator() { |
62 fCacher->fMutexForGenerator.release(); | 69 fCacher->fMutexForGenerator.release(); |
63 } | 70 } |
64 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } | 71 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } |
65 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } | 72 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } |
66 }; | 73 }; |
67 | 74 |
68 SkMutex fMutexForGenerator; | 75 SkMutex fMutexForGenerator; |
69 SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator; | 76 SkAutoTDelete<SkImageGenerator> fNotThreadSafeGenerator; |
70 | 77 |
71 const SkImageInfo fInfo; | 78 const SkImageInfo fInfo; |
72 const SkIPoint fOrigin; | 79 const SkIPoint fOrigin; |
73 const uint32_t fUniqueID; | 80 const uint32_t fUniqueID; |
74 }; | 81 }; |
75 | 82 |
76 #endif | 83 #endif |
OLD | NEW |