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 GrTextureMaker_DEFINED | 8 #ifndef GrTextureMaker_DEFINED |
9 #define GrTextureMaker_DEFINED | 9 #define GrTextureMaker_DEFINED |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 GrTextureParamsAdjuster(int width, int height) : fWidth(width), fHeight(heig
ht) {} | 36 GrTextureParamsAdjuster(int width, int height) : fWidth(width), fHeight(heig
ht) {} |
37 virtual ~GrTextureParamsAdjuster() {} | 37 virtual ~GrTextureParamsAdjuster() {} |
38 | 38 |
39 int width() const { return fWidth; } | 39 int width() const { return fWidth; } |
40 int height() const { return fHeight; } | 40 int height() const { return fHeight; } |
41 | 41 |
42 /** Returns a texture that is safe for use with the params */ | 42 /** Returns a texture that is safe for use with the params */ |
43 GrTexture* refTextureForParams(GrContext*, const GrTextureParams&); | 43 GrTexture* refTextureForParams(GrContext*, const GrTextureParams&); |
44 | 44 |
45 protected: | 45 protected: |
46 /** If the original is a inherently texture that can be returned for "free"
then return it | |
47 without ref'ing it. Otherwise, return null. */ | |
48 virtual GrTexture* peekOriginalTexture() = 0; | |
49 | |
50 /** | 46 /** |
51 * Return the maker's "original" texture. It is the responsibility of the m
aker | 47 * Return the maker's "original" texture. It is the responsibility of the m
aker |
52 * to make this efficient ... if the texture is being generated, the maker
must handle | 48 * to make this efficient ... if the texture is being generated, the maker
must handle |
53 * caching it (if desired). | 49 * caching it (if desired). |
54 */ | 50 */ |
55 virtual GrTexture* refOriginalTexture(GrContext*) = 0; | 51 virtual GrTexture* refOriginalTexture(GrContext*) = 0; |
56 | 52 |
57 /** | 53 /** |
58 * If we need to copy the maker's original texture, the maker is asked to r
eturn a key | 54 * If we need to copy the maker's original texture, the maker is asked to r
eturn a key |
59 * that identifies its original + the CopyParms parameter. If the maker doe
s not want to cache | 55 * that identifies its original + the CopyParms parameter. If the maker doe
s not want to cache |
60 * the stretched version (e.g. the maker is volatile), this should simply r
eturn without | 56 * the stretched version (e.g. the maker is volatile), this should simply r
eturn without |
61 * initializing the copyKey. | 57 * initializing the copyKey. |
62 */ | 58 */ |
63 virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey) = 0; | 59 virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey) = 0; |
64 | 60 |
65 /** | 61 /** |
66 * Return a new (uncached) texture that is the stretch of the maker's origi
nal. | 62 * Return a new (uncached) texture that is the stretch of the maker's origi
nal. |
67 * | 63 * |
68 * The base-class handles general logic for this, and only needs access to
the following | 64 * The base-class handles general logic for this, and only needs access to
the following |
69 * methods: | 65 * method: |
70 * - onRefOriginalTexture() | 66 * - refOriginalTexture() |
71 * - onGetROBitmap() | |
72 * | 67 * |
73 * Subclass may override this if they can handle creating the texture more
directly than | 68 * Subclass may override this if they can handle creating the texture more
directly than |
74 * by copying. | 69 * by copying. |
75 */ | 70 */ |
76 virtual GrTexture* generateTextureForParams(GrContext*, const CopyParams&); | 71 virtual GrTexture* generateTextureForParams(GrContext*, const CopyParams&); |
77 | 72 |
78 /** | 73 /** |
79 * If a stretched version of the texture is generated, it may be cached (as
suming that | 74 * If a stretched version of the texture is generated, it may be cached (as
suming that |
80 * onMakeParamsKey() returns true). In that case, the maker is notified in
case it | 75 * onMakeParamsKey() returns true). In that case, the maker is notified in
case it |
81 * wants to note that for when the maker is destroyed. | 76 * wants to note that for when the maker is destroyed. |
82 */ | 77 */ |
83 virtual void didCacheCopy(const GrUniqueKey& copyKey) = 0; | 78 virtual void didCacheCopy(const GrUniqueKey& copyKey) = 0; |
84 | 79 |
85 /** | |
86 * Some GPUs are unreliable w/ very small texture sizes. If we run into tha
t case, this | |
87 * method will be called (in service of onGenerateParamsTexture) to return
a raster version | |
88 * of the original texture. | |
89 */ | |
90 virtual bool getROBitmap(SkBitmap*) = 0; | |
91 | |
92 /** Helper for creating a key for a copy from an original key. */ | 80 /** Helper for creating a key for a copy from an original key. */ |
93 static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey, | 81 static void MakeCopyKeyFromOrigKey(const GrUniqueKey& origKey, |
94 const CopyParams& copyParams, | 82 const CopyParams& copyParams, |
95 GrUniqueKey* copyKey) { | 83 GrUniqueKey* copyKey) { |
96 SkASSERT(!copyKey->isValid()); | 84 SkASSERT(!copyKey->isValid()); |
97 if (origKey.isValid()) { | 85 if (origKey.isValid()) { |
98 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDoma
in(); | 86 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDoma
in(); |
99 GrUniqueKey::Builder builder(copyKey, origKey, kDomain, 3); | 87 GrUniqueKey::Builder builder(copyKey, origKey, kDomain, 3); |
100 builder[0] = copyParams.fFilter; | 88 builder[0] = copyParams.fFilter; |
101 builder[1] = copyParams.fWidth; | 89 builder[1] = copyParams.fWidth; |
102 builder[2] = copyParams.fHeight; | 90 builder[2] = copyParams.fHeight; |
103 } | 91 } |
104 } | 92 } |
105 | 93 |
106 private: | 94 private: |
107 const int fWidth; | 95 const int fWidth; |
108 const int fHeight; | 96 const int fHeight; |
109 }; | 97 }; |
110 | 98 |
111 #endif | 99 #endif |
OLD | NEW |