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 | 13 |
13 class GrContext; | 14 class GrContext; |
14 class SkBitmap; | 15 class SkBitmap; |
15 | 16 |
16 /* | 17 /* |
17 * Internal class to manage caching the output of an ImageGenerator. | 18 * Internal class to manage caching the output of an ImageGenerator. |
18 */ | 19 */ |
19 class SkImageCacherator { | 20 class SkImageCacherator { |
20 public: | 21 public: |
21 // Takes ownership of the generator | 22 // Takes ownership of the generator |
(...skipping 11 matching lines...) Expand all Loading... |
33 bool lockAsBitmap(SkBitmap*); | 34 bool lockAsBitmap(SkBitmap*); |
34 | 35 |
35 /** | 36 /** |
36 * Returns a ref() on the texture produced by this generator. The caller mu
st call unref() | 37 * 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. | 38 * when it is done. Will return NULL on failure. |
38 * | 39 * |
39 * The caller is responsible for calling texture->unref() when they are don
e. | 40 * The caller is responsible for calling texture->unref() when they are don
e. |
40 */ | 41 */ |
41 GrTexture* lockAsTexture(GrContext*, SkImageUsageType); | 42 GrTexture* lockAsTexture(GrContext*, SkImageUsageType); |
42 | 43 |
| 44 /** |
| 45 * If the underlying src naturally is represented by an encoded blob (in Sk
Data), this returns |
| 46 * a ref to that data. If not, it returns null. |
| 47 */ |
| 48 SkData* refEncoded(); |
| 49 |
43 private: | 50 private: |
44 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); | 51 SkImageCacherator(SkImageGenerator*, const SkImageInfo&, const SkIPoint&, ui
nt32_t uniqueID); |
45 | 52 |
| 53 bool generateBitmap(SkBitmap*); |
46 bool tryLockAsBitmap(SkBitmap*); | 54 bool tryLockAsBitmap(SkBitmap*); |
47 GrTexture* tryLockAsTexture(GrContext*, SkImageUsageType); | 55 GrTexture* tryLockAsTexture(GrContext*, SkImageUsageType); |
48 | 56 |
49 SkImageGenerator* fGenerator; | 57 class ScopedGenerator { |
| 58 SkImageCacherator* fCacher; |
| 59 public: |
| 60 ScopedGenerator(SkImageCacherator* cacher) : fCacher(cacher) { |
| 61 fCacher->fMutexForGenerator.acquire(); |
| 62 } |
| 63 ~ScopedGenerator() { |
| 64 fCacher->fMutexForGenerator.release(); |
| 65 } |
| 66 SkImageGenerator* operator->() const { return fCacher->fNotThreadSafeGen
erator; } |
| 67 operator SkImageGenerator*() const { return fCacher->fNotThreadSafeGener
ator; } |
| 68 }; |
| 69 |
| 70 SkMutex fMutexForGenerator; |
| 71 SkImageGenerator* fNotThreadSafeGenerator; |
50 const SkImageInfo fInfo; | 72 const SkImageInfo fInfo; |
51 const SkIPoint fOrigin; | 73 const SkIPoint fOrigin; |
52 const uint32_t fUniqueID; | 74 const uint32_t fUniqueID; |
53 }; | 75 }; |
54 | 76 |
55 #endif | 77 #endif |
OLD | NEW |