Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: gpu/command_buffer/service/texture_manager.h

Issue 8341128: Defer clearing textures and renderbuffers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix one more unit test Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
7 7
8 #include <vector> 8 #include <vector>
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "gpu/command_buffer/service/gl_utils.h" 13 #include "gpu/command_buffer/service/gl_utils.h"
14 14
15 namespace gpu { 15 namespace gpu {
16 namespace gles2 { 16 namespace gles2 {
17 17
18 class FeatureInfo; 18 class FeatureInfo;
19 class GLES2Decoder;
19 20
20 // This class keeps track of the textures and their sizes so we can do NPOT and 21 // This class keeps track of the textures and their sizes so we can do NPOT and
21 // texture complete checking. 22 // texture complete checking.
22 // 23 //
23 // NOTE: To support shared resources an instance of this class will need to be 24 // NOTE: To support shared resources an instance of this class will need to be
24 // shared by multiple GLES2Decoders. 25 // shared by multiple GLES2Decoders.
25 class TextureManager { 26 class TextureManager {
26 public: 27 public:
27 // Info about Textures currently in the system. 28 // Info about Textures currently in the system.
28 class TextureInfo : public base::RefCounted<TextureInfo> { 29 class TextureInfo : public base::RefCounted<TextureInfo> {
29 public: 30 public:
30 typedef scoped_refptr<TextureInfo> Ref; 31 typedef scoped_refptr<TextureInfo> Ref;
31 32
32 explicit TextureInfo(GLuint service_id) 33 explicit TextureInfo(GLuint service_id)
33 : service_id_(service_id), 34 : service_id_(service_id),
34 deleted_(false), 35 deleted_(false),
36 cleared_(true),
37 num_uncleared_mips_(0),
35 target_(0), 38 target_(0),
36 min_filter_(GL_NEAREST_MIPMAP_LINEAR), 39 min_filter_(GL_NEAREST_MIPMAP_LINEAR),
37 mag_filter_(GL_LINEAR), 40 mag_filter_(GL_LINEAR),
38 wrap_s_(GL_REPEAT), 41 wrap_s_(GL_REPEAT),
39 wrap_t_(GL_REPEAT), 42 wrap_t_(GL_REPEAT),
40 max_level_set_(-1), 43 max_level_set_(-1),
41 texture_complete_(false), 44 texture_complete_(false),
42 cube_complete_(false), 45 cube_complete_(false),
43 npot_(false), 46 npot_(false),
44 has_been_bound_(false), 47 has_been_bound_(false),
(...skipping 11 matching lines...) Expand all
56 } 59 }
57 60
58 GLenum wrap_s() const { 61 GLenum wrap_s() const {
59 return wrap_s_; 62 return wrap_s_;
60 } 63 }
61 64
62 GLenum wrap_t() const { 65 GLenum wrap_t() const {
63 return wrap_t_; 66 return wrap_t_;
64 } 67 }
65 68
69 int num_uncleared_mips() const {
70 return num_uncleared_mips_;
71 }
72
66 // True if this texture meets all the GLES2 criteria for rendering. 73 // True if this texture meets all the GLES2 criteria for rendering.
67 // See section 3.8.2 of the GLES2 spec. 74 // See section 3.8.2 of the GLES2 spec.
68 bool CanRender(const FeatureInfo* feature_info) const; 75 bool CanRender(const FeatureInfo* feature_info) const;
69 76
70 bool CanRenderTo() const { 77 bool CanRenderTo() const {
71 return !stream_texture_ && target_ != GL_TEXTURE_EXTERNAL_OES; 78 return !stream_texture_ && target_ != GL_TEXTURE_EXTERNAL_OES;
72 } 79 }
73 80
74 // The service side OpenGL id of the texture. 81 // The service side OpenGL id of the texture.
75 GLuint service_id() const { 82 GLuint service_id() const {
(...skipping 18 matching lines...) Expand all
94 // same format, all the same dimensions and all width = height. 101 // same format, all the same dimensions and all width = height.
95 bool cube_complete() const { 102 bool cube_complete() const {
96 return cube_complete_; 103 return cube_complete_;
97 } 104 }
98 105
99 // Whether or not this texture is a non-power-of-two texture. 106 // Whether or not this texture is a non-power-of-two texture.
100 bool npot() const { 107 bool npot() const {
101 return npot_; 108 return npot_;
102 } 109 }
103 110
111 bool SafeToRenderFrom() const {
112 return cleared_;
113 }
114
104 // Returns true if mipmaps can be generated by GL. 115 // Returns true if mipmaps can be generated by GL.
105 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const; 116 bool CanGenerateMipmaps(const FeatureInfo* feature_info) const;
106 117
107 // Get the width and height for a particular level. Returns false if level 118 // Get the width and height for a particular level. Returns false if level
108 // does not exist. 119 // does not exist.
109 bool GetLevelSize( 120 bool GetLevelSize(
110 GLint face, GLint level, GLsizei* width, GLsizei* height) const; 121 GLint face, GLint level, GLsizei* width, GLsizei* height) const;
111 122
112 // Get the type of a level. Returns false if level does not exist. 123 // Get the type of a level. Returns false if level does not exist.
113 bool GetLevelType( 124 bool GetLevelType(
(...skipping 25 matching lines...) Expand all
139 150
140 bool IsAttachedToFramebuffer() const { 151 bool IsAttachedToFramebuffer() const {
141 return framebuffer_attachment_count_ != 0; 152 return framebuffer_attachment_count_ != 0;
142 } 153 }
143 154
144 void AttachToFramebuffer() { 155 void AttachToFramebuffer() {
145 ++framebuffer_attachment_count_; 156 ++framebuffer_attachment_count_;
146 } 157 }
147 158
148 void DetachFromFramebuffer() { 159 void DetachFromFramebuffer() {
149 DCHECK(framebuffer_attachment_count_ > 0); 160 DCHECK_GT(framebuffer_attachment_count_, 0);
150 --framebuffer_attachment_count_; 161 --framebuffer_attachment_count_;
151 } 162 }
152 163
153 void SetStreamTexture(bool stream_texture) { 164 void SetStreamTexture(bool stream_texture) {
154 stream_texture_ = stream_texture; 165 stream_texture_ = stream_texture;
155 } 166 }
156 167
157 int IsStreamTexture() { 168 int IsStreamTexture() {
158 return stream_texture_; 169 return stream_texture_;
159 } 170 }
160 171
172 // Whether a particular level/face is cleared.
173 bool IsLevelCleared(GLenum target, GLint level);
174
161 private: 175 private:
162 friend class TextureManager; 176 friend class TextureManager;
163 friend class base::RefCounted<TextureInfo>; 177 friend class base::RefCounted<TextureInfo>;
164 178
165 ~TextureInfo() { } 179 ~TextureInfo() { }
166 180
167 struct LevelInfo { 181 struct LevelInfo {
168 LevelInfo() 182 LevelInfo()
169 : valid(false), 183 : cleared(true),
184 target(0),
185 level(-1),
170 internal_format(0), 186 internal_format(0),
171 width(0), 187 width(0),
172 height(0), 188 height(0),
173 depth(0), 189 depth(0),
174 border(0), 190 border(0),
175 format(0), 191 format(0),
176 type(0) { 192 type(0) {
177 } 193 }
178 194
179 bool valid; 195 bool cleared;
196 GLenum target;
197 GLint level;
180 GLenum internal_format; 198 GLenum internal_format;
181 GLsizei width; 199 GLsizei width;
182 GLsizei height; 200 GLsizei height;
183 GLsizei depth; 201 GLsizei depth;
184 GLint border; 202 GLint border;
185 GLenum format; 203 GLenum format;
186 GLenum type; 204 GLenum type;
187 }; 205 };
188 206
189 // Set the info for a particular level. 207 // Set the info for a particular level.
190 void SetLevelInfo( 208 void SetLevelInfo(
191 const FeatureInfo* feature_info, 209 const FeatureInfo* feature_info,
192 GLenum target, 210 GLenum target,
193 GLint level, 211 GLint level,
194 GLenum internal_format, 212 GLenum internal_format,
195 GLsizei width, 213 GLsizei width,
196 GLsizei height, 214 GLsizei height,
197 GLsizei depth, 215 GLsizei depth,
198 GLint border, 216 GLint border,
199 GLenum format, 217 GLenum format,
200 GLenum type); 218 GLenum type,
219 bool cleared);
220
221 // Marks a particular level as cleared or uncleared.
222 void SetLevelCleared(GLenum target, GLint level);
223
224 // Updates the cleared flag for this texture by inspecting all the mips.
225 void UpdateCleared();
226
227 // Clears any renderable uncleared levels.
228 // Returns false if a GL error was generated.
229 bool ClearRenderableLevels(GLES2Decoder* decoder);
230
231 // Clears the level.
232 // Returns false if a GL error was generated.
233 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level);
201 234
202 // Sets a texture parameter. 235 // Sets a texture parameter.
203 // TODO(gman): Expand to SetParameteri,f,iv,fv 236 // TODO(gman): Expand to SetParameteri,f,iv,fv
204 // Returns false if param was INVALID_ENUN 237 // Returns false if param was INVALID_ENUN
205 bool SetParameter( 238 bool SetParameter(
206 const FeatureInfo* feature_info, GLenum pname, GLint param); 239 const FeatureInfo* feature_info, GLenum pname, GLint param);
207 240
208 // Makes each of the mip levels as though they were generated. 241 // Makes each of the mip levels as though they were generated.
209 bool MarkMipmapsGenerated(const FeatureInfo* feature_info); 242 bool MarkMipmapsGenerated(const FeatureInfo* feature_info);
210 243
(...skipping 18 matching lines...) Expand all
229 262
230 // Info about each face and level of texture. 263 // Info about each face and level of texture.
231 std::vector<std::vector<LevelInfo> > level_infos_; 264 std::vector<std::vector<LevelInfo> > level_infos_;
232 265
233 // The id of the texure 266 // The id of the texure
234 GLuint service_id_; 267 GLuint service_id_;
235 268
236 // Whether this texture has been deleted. 269 // Whether this texture has been deleted.
237 bool deleted_; 270 bool deleted_;
238 271
272 // Whether all renderable mips of this texture have been cleared.
273 bool cleared_;
274
275 int num_uncleared_mips_;
276
239 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. 277 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
240 GLenum target_; 278 GLenum target_;
241 279
242 // Texture parameters. 280 // Texture parameters.
243 GLenum min_filter_; 281 GLenum min_filter_;
244 GLenum mag_filter_; 282 GLenum mag_filter_;
245 GLenum wrap_s_; 283 GLenum wrap_s_;
246 GLenum wrap_t_; 284 GLenum wrap_t_;
247 285
248 // The maximum level that has been set. 286 // The maximum level that has been set.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 const FeatureInfo* feature_info, 364 const FeatureInfo* feature_info,
327 TextureInfo* info, 365 TextureInfo* info,
328 GLenum target, 366 GLenum target,
329 GLint level, 367 GLint level,
330 GLenum internal_format, 368 GLenum internal_format,
331 GLsizei width, 369 GLsizei width,
332 GLsizei height, 370 GLsizei height,
333 GLsizei depth, 371 GLsizei depth,
334 GLint border, 372 GLint border,
335 GLenum format, 373 GLenum format,
336 GLenum type); 374 GLenum type,
375 bool cleared);
376
377 // Sets a mip as cleared.
378 void SetLevelCleared(TextureInfo* info, GLenum target, GLint level);
337 379
338 // Sets a texture parameter of a TextureInfo 380 // Sets a texture parameter of a TextureInfo
339 // TODO(gman): Expand to SetParameteri,f,iv,fv 381 // TODO(gman): Expand to SetParameteri,f,iv,fv
340 bool SetParameter( 382 bool SetParameter(
341 const FeatureInfo* feature_info, 383 const FeatureInfo* feature_info,
342 TextureInfo* info, GLenum pname, GLint param); 384 TextureInfo* info, GLenum pname, GLint param);
343 385
344 // Makes each of the mip levels as though they were generated. 386 // Makes each of the mip levels as though they were generated.
345 // Returns false if that's not allowed for the given texture. 387 // Returns false if that's not allowed for the given texture.
346 bool MarkMipmapsGenerated( 388 bool MarkMipmapsGenerated(const FeatureInfo* feature_info, TextureInfo* info);
347 const FeatureInfo* feature_info, 389
348 TextureManager::TextureInfo* info); 390 // Clears any uncleared renderable levels.
391 bool ClearRenderableLevels(GLES2Decoder* decoder, TextureInfo* info);
392
393 // Clear a specific level.
394 bool ClearTextureLevel(
395 GLES2Decoder* decoder,TextureInfo* info, GLenum target, GLint level);
349 396
350 // Creates a new texture info. 397 // Creates a new texture info.
351 TextureInfo* CreateTextureInfo( 398 TextureInfo* CreateTextureInfo(
352 const FeatureInfo* feature_info, GLuint client_id, GLuint service_id); 399 const FeatureInfo* feature_info, GLuint client_id, GLuint service_id);
353 400
354 // Gets the texture info for the given texture. 401 // Gets the texture info for the given texture.
355 TextureInfo* GetTextureInfo(GLuint client_id); 402 TextureInfo* GetTextureInfo(GLuint client_id);
356 403
357 // Removes a texture info. 404 // Removes a texture info.
358 void RemoveTextureInfo(const FeatureInfo* feature_info, GLuint client_id); 405 void RemoveTextureInfo(const FeatureInfo* feature_info, GLuint client_id);
(...skipping 12 matching lines...) Expand all
371 default: 418 default:
372 NOTREACHED(); 419 NOTREACHED();
373 return NULL; 420 return NULL;
374 } 421 }
375 } 422 }
376 423
377 bool HaveUnrenderableTextures() const { 424 bool HaveUnrenderableTextures() const {
378 return num_unrenderable_textures_ > 0; 425 return num_unrenderable_textures_ > 0;
379 } 426 }
380 427
428 bool HaveUnsafeTextures() const {
429 return num_unsafe_textures_ > 0;
430 }
431
432 bool HaveUnclearedMips() const {
433 return num_uncleared_mips_ > 0;
434 }
435
381 GLuint black_texture_id(GLenum target) const { 436 GLuint black_texture_id(GLenum target) const {
382 switch (target) { 437 switch (target) {
383 case GL_SAMPLER_2D: 438 case GL_SAMPLER_2D:
384 return black_2d_texture_id_; 439 return black_2d_texture_id_;
385 case GL_SAMPLER_CUBE: 440 case GL_SAMPLER_CUBE:
386 return black_cube_texture_id_; 441 return black_cube_texture_id_;
387 case GL_SAMPLER_EXTERNAL_OES: 442 case GL_SAMPLER_EXTERNAL_OES:
388 return black_oes_external_texture_id_; 443 return black_oes_external_texture_id_;
389 default: 444 default:
390 NOTREACHED(); 445 NOTREACHED();
391 return 0; 446 return 0;
392 } 447 }
393 } 448 }
394 449
395 private: 450 private:
396 // Info for each texture in the system. 451 // Info for each texture in the system.
397 typedef base::hash_map<GLuint, TextureInfo::Ref> TextureInfoMap; 452 typedef base::hash_map<GLuint, TextureInfo::Ref> TextureInfoMap;
398 TextureInfoMap texture_infos_; 453 TextureInfoMap texture_infos_;
399 454
400 GLsizei max_texture_size_; 455 GLsizei max_texture_size_;
401 GLsizei max_cube_map_texture_size_; 456 GLsizei max_cube_map_texture_size_;
402 GLint max_levels_; 457 GLint max_levels_;
403 GLint max_cube_map_levels_; 458 GLint max_cube_map_levels_;
404 459
405 int num_unrenderable_textures_; 460 int num_unrenderable_textures_;
461 int num_unsafe_textures_;
462 int num_uncleared_mips_;
406 463
407 // Black (0,0,0,1) textures for when non-renderable textures are used. 464 // Black (0,0,0,1) textures for when non-renderable textures are used.
408 // NOTE: There is no corresponding TextureInfo for these textures. 465 // NOTE: There is no corresponding TextureInfo for these textures.
409 // TextureInfos are only for textures the client side can access. 466 // TextureInfos are only for textures the client side can access.
410 GLuint black_2d_texture_id_; 467 GLuint black_2d_texture_id_;
411 GLuint black_cube_texture_id_; 468 GLuint black_cube_texture_id_;
412 GLuint black_oes_external_texture_id_; 469 GLuint black_oes_external_texture_id_;
413 470
414 // The default textures for each target (texture name = 0) 471 // The default textures for each target (texture name = 0)
415 TextureInfo::Ref default_texture_2d_; 472 TextureInfo::Ref default_texture_2d_;
416 TextureInfo::Ref default_texture_cube_map_; 473 TextureInfo::Ref default_texture_cube_map_;
417 TextureInfo::Ref default_texture_external_oes_; 474 TextureInfo::Ref default_texture_external_oes_;
418 475
419 DISALLOW_COPY_AND_ASSIGN(TextureManager); 476 DISALLOW_COPY_AND_ASSIGN(TextureManager);
420 }; 477 };
421 478
422 } // namespace gles2 479 } // namespace gles2
423 } // namespace gpu 480 } // namespace gpu
424 481
425 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 482 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/renderbuffer_manager_unittest.cc ('k') | gpu/command_buffer/service/texture_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698