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 GrTextureProvider_DEFINED | 8 #ifndef GrTextureProvider_DEFINED |
9 #define GrTextureProvider_DEFINED | 9 #define GrTextureProvider_DEFINED |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 /** | 54 /** |
55 * Determines whether a texture is associated with the unique key. If the te
xture is found it | 55 * Determines whether a texture is associated with the unique key. If the te
xture is found it |
56 * will not be locked or returned. This call does not affect the priority of
the resource for | 56 * will not be locked or returned. This call does not affect the priority of
the resource for |
57 * deletion. | 57 * deletion. |
58 */ | 58 */ |
59 bool existsTextureWithUniqueKey(const GrUniqueKey& key) const { | 59 bool existsTextureWithUniqueKey(const GrUniqueKey& key) const { |
60 return this->existsResourceWithUniqueKey(key); | 60 return this->existsResourceWithUniqueKey(key); |
61 } | 61 } |
62 | 62 |
63 /** | 63 /** |
64 * Enum that determines how closely a returned scratch texture must match | 64 * Finds a texture that approximately matches the descriptor. Will be at lea
st as large in width |
65 * a provided GrSurfaceDesc. TODO: Remove this. createTexture() should be us
ed | 65 * and height as desc specifies. If desc specifies that the texture should b
e a render target |
66 * for exact match and refScratchTexture() should be replaced with createApp
roxTexture(). | 66 * then result will be a render target. Format and sample count will always
match the request. |
| 67 * The contents of the texture are undefined. The caller owns a ref on the r
eturned texture and |
| 68 * must balance with a call to unref. |
67 */ | 69 */ |
| 70 GrTexture* createApproxTexture(const GrSurfaceDesc&); |
| 71 |
| 72 /** Legacy function that no longer should be used. */ |
68 enum ScratchTexMatch { | 73 enum ScratchTexMatch { |
69 /** | |
70 * Finds a texture that exactly matches the descriptor. | |
71 */ | |
72 kExact_ScratchTexMatch, | 74 kExact_ScratchTexMatch, |
73 /** | |
74 * Finds a texture that approximately matches the descriptor. Will be | |
75 * at least as large in width and height as desc specifies. If desc | |
76 * specifies that texture is a render target then result will be a | |
77 * render target. If desc specifies a render target and doesn't set the | |
78 * no stencil flag then result will have a stencil. Format and aa level | |
79 * will always match. | |
80 */ | |
81 kApprox_ScratchTexMatch | 75 kApprox_ScratchTexMatch |
82 }; | 76 }; |
83 | 77 GrTexture* refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMatch matc
h) { |
84 /** | 78 if (kApprox_ScratchTexMatch == match) { |
85 * Returns a texture matching the desc. It's contents are unknown. The calle
r | 79 return this->createApproxTexture(desc); |
86 * owns a ref on the returned texture and must balance with a call to unref. | 80 } else { |
87 * It is guaranteed that the same texture will not be returned in subsequent | 81 return this->createTexture(desc, true); |
88 * calls until all refs to the texture are dropped. | 82 } |
89 * | 83 } |
90 * internalFlag is a temporary workaround until changes in the internal | |
91 * architecture are complete. Use the default value. | |
92 * | |
93 * TODO: Once internal flag can be removed, this should be replaced with | |
94 * createApproxTexture() and exact textures should be created with | |
95 * createTexture(). | |
96 */ | |
97 GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match, | |
98 bool internalFlag = false); | |
99 | 84 |
100 /////////////////////////////////////////////////////////////////////////// | 85 /////////////////////////////////////////////////////////////////////////// |
101 // Wrapped Backend Surfaces | 86 // Wrapped Backend Surfaces |
102 | 87 |
103 /** | 88 /** |
104 * Wraps an existing texture with a GrTexture object. | 89 * Wraps an existing texture with a GrTexture object. |
105 * | 90 * |
106 * OpenGL: if the object is a texture Gr may change its GL texture params | 91 * OpenGL: if the object is a texture Gr may change its GL texture params |
107 * when it is drawn. | 92 * when it is drawn. |
108 * | 93 * |
(...skipping 29 matching lines...) Expand all Loading... |
138 */ | 123 */ |
139 GrGpuResource* findAndRefResourceByUniqueKey(const GrUniqueKey&); | 124 GrGpuResource* findAndRefResourceByUniqueKey(const GrUniqueKey&); |
140 | 125 |
141 /** | 126 /** |
142 * Determines whether a resource is in the cache. If the resource is found i
t | 127 * Determines whether a resource is in the cache. If the resource is found i
t |
143 * will not be locked or returned. This call does not affect the priority of | 128 * will not be locked or returned. This call does not affect the priority of |
144 * the resource for deletion. | 129 * the resource for deletion. |
145 */ | 130 */ |
146 bool existsResourceWithUniqueKey(const GrUniqueKey& key) const; | 131 bool existsResourceWithUniqueKey(const GrUniqueKey& key) const; |
147 | 132 |
148 GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags); | 133 enum ScratchTextureFlags { |
| 134 kExact_ScratchTextureFlag = 0x1, |
| 135 kNoPendingIO_ScratchTextureFlag = 0x2, // (http://skbug.com/4156) |
| 136 kNoCreate_ScratchTextureFlag = 0x4, |
| 137 }; |
| 138 |
| 139 /** A common impl for GrTextureProvider and GrResourceProvider variants. */ |
| 140 GrTexture* internalCreateApproxTexture(const GrSurfaceDesc& desc, uint32_t s
cratchTextureFlags); |
| 141 |
| 142 GrTexture* refScratchTexture(const GrSurfaceDesc&, uint32_t scratchTextureFl
ags); |
149 | 143 |
150 void abandon() { | 144 void abandon() { |
151 fCache = NULL; | 145 fCache = NULL; |
152 fGpu = NULL; | 146 fGpu = NULL; |
153 } | 147 } |
154 | 148 |
155 GrResourceCache* cache() { return fCache; } | 149 GrResourceCache* cache() { return fCache; } |
156 const GrResourceCache* cache() const { return fCache; } | 150 const GrResourceCache* cache() const { return fCache; } |
157 | 151 |
158 GrGpu* gpu() { return fGpu; } | 152 GrGpu* gpu() { return fGpu; } |
159 const GrGpu* gpu() const { return fGpu; } | 153 const GrGpu* gpu() const { return fGpu; } |
160 | 154 |
161 bool isAbandoned() const { | 155 bool isAbandoned() const { |
162 SkASSERT(SkToBool(fGpu) == SkToBool(fCache)); | 156 SkASSERT(SkToBool(fGpu) == SkToBool(fCache)); |
163 return !SkToBool(fCache); | 157 return !SkToBool(fCache); |
164 } | 158 } |
165 | 159 |
166 private: | 160 private: |
167 GrResourceCache* fCache; | 161 GrResourceCache* fCache; |
168 GrGpu* fGpu; | 162 GrGpu* fGpu; |
169 }; | 163 }; |
170 | 164 |
171 #endif | 165 #endif |
OLD | NEW |