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 | 12 |
13 class GrContext; | 13 class GrContext; |
14 class SkBitmap; | 14 class SkBitmap; |
15 | 15 |
16 /* | 16 /* |
17 * Internal class to manage caching the output of an ImageGenerator. | 17 * Internal class to manage caching the output of an ImageGenerator. |
18 */ | 18 */ |
19 class SkImageCacherator { | 19 class SkImageCacherator { |
20 public: | 20 public: |
21 // Takes ownership of the generator | 21 // Takes ownership of the generator |
22 SkImageCacherator(SkImageGenerator* gen); | 22 static SkImageCacherator* NewFromGenerator(SkImageGenerator*); |
| 23 |
23 ~SkImageCacherator(); | 24 ~SkImageCacherator(); |
24 | 25 |
25 const SkImageInfo& info() const { return fGenerator->getInfo(); } | 26 const SkImageInfo& info() const { return fGenerator->getInfo(); } |
26 SkImageGenerator* generator() const { return fGenerator; } | 27 SkImageGenerator* generator() const { return fGenerator; } |
27 | 28 |
28 /** | 29 /** |
29 * 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 |
30 * false, the bitmap will be reset to empty. | 31 * false, the bitmap will be reset to empty. |
31 * | |
32 * The cached bitmap is valid until it goes out of scope. | |
33 */ | 32 */ |
34 bool lockAsBitmap(SkBitmap*); | 33 bool lockAsBitmap(SkBitmap*); |
35 | 34 |
36 /** | 35 /** |
37 * 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() |
38 * when it is done. Will return NULL on failure. | 37 * when it is done. Will return NULL on failure. |
39 * | 38 * |
40 * The cached texture is valid until it is unref'd. | 39 * The caller is responsible for calling texture->unref() when they are don
e. |
41 */ | 40 */ |
42 GrTexture* lockAsTexture(GrContext*, SkImageUsageType); | 41 GrTexture* lockAsTexture(GrContext*, SkImageUsageType); |
43 | 42 |
44 private: | 43 private: |
| 44 SkImageCacherator(SkImageGenerator* gen); |
| 45 |
45 bool tryLockAsBitmap(SkBitmap*); | 46 bool tryLockAsBitmap(SkBitmap*); |
46 GrTexture* tryLockAsTexture(GrContext*, SkImageUsageType); | 47 GrTexture* tryLockAsTexture(GrContext*, SkImageUsageType); |
47 | 48 |
48 SkImageGenerator* fGenerator; | 49 SkImageGenerator* fGenerator; |
49 }; | 50 }; |
50 | 51 |
51 #endif | 52 #endif |
OLD | NEW |