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