OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef GrTextureMaker_DEFINED | |
9 #define GrTextureMaker_DEFINED | |
10 | |
11 #include "SkGrPriv.h" | |
12 | |
13 class GrContext; | |
14 class GrTexture; | |
15 class GrTextureParams; | |
16 class GrUniqueKey; | |
17 class SkBitmap; | |
18 | |
19 class GrTextureMaker { | |
20 public: | |
21 GrTextureMaker(int width, int height) : fWidth(width), fHeight(height) {} | |
22 virtual ~GrTextureMaker() {} | |
23 | |
24 int width() const { return fWidth; } | |
25 int height() const { return fHeight; } | |
26 | |
27 GrTexture* refCachedTexture(GrContext*, const GrTextureParams&); | |
28 | |
29 protected: | |
30 /** | |
31 * Return the maker's "original" unstretched texture. It is the responsibil
ity of the maker | |
32 * to make this efficient ... if the texture is being generated, the maker
must handle | |
33 * caching it. | |
34 */ | |
35 virtual GrTexture* onRefUnstretchedTexture(GrContext*) = 0; | |
36 | |
37 /** | |
38 * If we need to stretch the maker's original texture, the maker is asked t
o return a key | |
39 * that identifies its origianl + the stretch parameter. If the maker does
not want to cache | |
40 * the stretched version (e.g. the maker is volatile), this should ignore t
he key parameter | |
41 * and return false. | |
42 */ | |
43 virtual bool onMakeStretchedKey(const SkGrStretch&, GrUniqueKey* stretchedKe
y) = 0; | |
44 | |
45 /** | |
46 * Return a new (uncached) texture that is the stretch of the maker's origi
nal. | |
47 * | |
48 * The base-class handles general logic for this, and only needs access to
the following | |
49 * methods: | |
50 * - onRefUnstretchedTexture() | |
51 * - onGetROBitmap() | |
52 * | |
53 * Subclass may override this if they can handle stretching more efficientl
y. | |
54 */ | |
55 virtual GrTexture* onGenerateStretchedTexture(GrContext*, const SkGrStretch&
); | |
56 | |
57 /** | |
58 * If a stretched version of the texture is generated, it may be cached (as
suming that | |
59 * onMakeStretchedKey() returns true). In that case, the maker is notified
in case it | |
60 * wants to note that for when the maker is destroyed. | |
61 */ | |
62 virtual void onNotifyStretchCached(const GrUniqueKey& stretchedKey) = 0; | |
63 | |
64 /** | |
65 * Some GPUs are unreliable w/ very small texture sizes. If we run into tha
t case, this | |
66 * method will be called (in service of onGenerateStretchedTexture) to retu
rn a raster version | |
67 * of the original texture. | |
68 */ | |
69 virtual bool onGetROBitmap(SkBitmap*) = 0; | |
70 | |
71 private: | |
72 const int fWidth; | |
73 const int fHeight; | |
74 }; | |
75 | |
76 #endif | |
OLD | NEW |