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 GrTextureProvider_DEFINED | |
9 #define GrTextureProvider_DEFINED | |
10 | |
11 #include "GrTexture.h" | |
12 | |
robertphillips
2015/04/30 20:43:44
do we need this pre-decl ?
bsalomon
2015/04/30 20:58:39
Done.
| |
13 class GrResourceProvider; | |
14 | |
15 class SK_API GrTextureProvider { | |
16 public: | |
17 /////////////////////////////////////////////////////////////////////////// | |
18 // Textures | |
19 | |
20 /** | |
21 * Creates a new texture in the resource cache and returns it. The caller ow ns a | |
22 * ref on the returned texture which must be balanced by a call to unref. | |
23 * | |
24 * @param desc Description of the texture properties. | |
25 * @param budgeted Does the texture count against the resource cache budget ? | |
26 * @param srcData Pointer to the pixel values (optional). | |
27 * @param rowBytes The number of bytes between rows of the texture. Zero | |
28 * implies tightly packed rows. For compressed pixel config s, this | |
29 * field is ignored. | |
30 */ | |
31 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, const voi d* srcData, | |
32 size_t rowBytes); | |
33 | |
34 /** Shortcut for creating a texture with no initial data to upload. */ | |
35 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted) { | |
36 return this->createTexture(desc, budgeted, NULL, 0); | |
37 } | |
38 | |
39 /** Assigns a unique key to the texture. The texture will be findable via th is key using | |
40 findTextureByUniqueKey(). If an existing texture has this key, it's key will be removed. */ | |
41 void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) { | |
42 this->assignUniqueKeyToResource(key, texture); | |
43 } | |
44 | |
45 /** Finds a texture by unique key. If the texture is found it is ref'ed and returned. */ | |
46 GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key) { | |
47 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); | |
48 if (resource) { | |
49 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); | |
50 SkASSERT(texture); | |
51 return texture; | |
52 } | |
53 return NULL; | |
54 } | |
55 | |
56 /** | |
57 * Determines whether a texture is associated with the unique key. If the te xture is found it | |
58 * will not be locked or returned. This call does not affect the priority of the resource for | |
59 * deletion. | |
60 */ | |
61 bool existsTextureWithUniqueKey(const GrUniqueKey& key) const { | |
62 return this->existsResourceWithUniqueKey(key); | |
63 } | |
64 | |
65 /** | |
66 * Enum that determines how closely a returned scratch texture must match | |
67 * a provided GrSurfaceDesc. TODO: Remove this. createTexture() should be us ed | |
68 * for exact match and refScratchTexture() should be replaced with createApp roxTexture(). | |
69 */ | |
70 enum ScratchTexMatch { | |
71 /** | |
72 * Finds a texture that exactly matches the descriptor. | |
73 */ | |
74 kExact_ScratchTexMatch, | |
75 /** | |
76 * Finds a texture that approximately matches the descriptor. Will be | |
77 * at least as large in width and height as desc specifies. If desc | |
78 * specifies that texture is a render target then result will be a | |
79 * render target. If desc specifies a render target and doesn't set the | |
80 * no stencil flag then result will have a stencil. Format and aa level | |
81 * will always match. | |
82 */ | |
83 kApprox_ScratchTexMatch | |
84 }; | |
85 | |
86 /** | |
87 * Returns a texture matching the desc. It's contents are unknown. The calle r | |
88 * owns a ref on the returned texture and must balance with a call to unref. | |
89 * It is guaranteed that the same texture will not be returned in subsequent | |
90 * calls until all refs to the texture are dropped. | |
91 * | |
92 * internalFlag is a temporary workaround until changes in the internal | |
93 * architecture are complete. Use the default value. | |
94 * | |
95 * TODO: Once internal flag can be removed, this should be replaced with | |
96 * createApproxTexture() and exact textures should be created with | |
97 * createTexture(). | |
98 */ | |
99 GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match, | |
100 bool internalFlag = false); | |
101 | |
102 /////////////////////////////////////////////////////////////////////////// | |
103 // Wrapped Backend Surfaces | |
104 | |
105 /** | |
106 * Wraps an existing texture with a GrTexture object. | |
107 * | |
108 * OpenGL: if the object is a texture Gr may change its GL texture params | |
109 * when it is drawn. | |
110 * | |
111 * @param desc description of the object to create. | |
112 * | |
113 * @return GrTexture object or NULL on failure. | |
114 */ | |
115 GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc); | |
116 | |
117 /** | |
118 * Wraps an existing render target with a GrRenderTarget object. It is | |
119 * similar to wrapBackendTexture but can be used to draw into surfaces | |
120 * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that | |
121 * the client will resolve to a texture). | |
122 * | |
123 * @param desc description of the object to create. | |
124 * | |
125 * @return GrTexture object or NULL on failure. | |
126 */ | |
127 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& de sc); | |
128 | |
129 protected: | |
130 GrTextureProvider(GrGpu* gpu, GrResourceCache* cache) : fCache(cache), fGpu( gpu) {} | |
131 | |
132 /** | |
133 * Assigns a unique key to a resource. If the key is associated with another resource that | |
134 * association is removed and replaced by this resource. | |
135 */ | |
136 void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*); | |
137 | |
138 /** | |
139 * Finds a resource in the cache, based on the specified key. This is intend ed for use in | |
140 * conjunction with addResourceToCache(). The return value will be NULL if n ot found. The | |
141 * caller must balance with a call to unref(). | |
142 */ | |
143 GrGpuResource* findAndRefResourceByUniqueKey(const GrUniqueKey&); | |
144 | |
145 /** | |
146 * Determines whether a resource is in the cache. If the resource is found i t | |
147 * will not be locked or returned. This call does not affect the priority of | |
148 * the resource for deletion. | |
149 */ | |
150 bool existsResourceWithUniqueKey(const GrUniqueKey& key) const; | |
151 | |
152 GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags); | |
153 | |
154 void abandon() { | |
155 fCache = NULL; | |
156 fGpu = NULL; | |
157 } | |
158 | |
159 private: | |
160 | |
161 bool isAbandoned() const { | |
162 SkASSERT(SkToBool(fGpu) == SkToBool(fCache)); | |
163 return !SkToBool(fCache); | |
164 } | |
165 | |
166 GrResourceCache* fCache; | |
167 GrGpu* fGpu; | |
168 }; | |
169 | |
170 #endif | |
OLD | NEW |