OLD | NEW |
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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 explicit TextureInfo(GLuint service_id) | 33 explicit TextureInfo(GLuint service_id) |
34 : service_id_(service_id), | 34 : service_id_(service_id), |
35 deleted_(false), | 35 deleted_(false), |
36 cleared_(true), | 36 cleared_(true), |
37 num_uncleared_mips_(0), | 37 num_uncleared_mips_(0), |
38 target_(0), | 38 target_(0), |
39 min_filter_(GL_NEAREST_MIPMAP_LINEAR), | 39 min_filter_(GL_NEAREST_MIPMAP_LINEAR), |
40 mag_filter_(GL_LINEAR), | 40 mag_filter_(GL_LINEAR), |
41 wrap_s_(GL_REPEAT), | 41 wrap_s_(GL_REPEAT), |
42 wrap_t_(GL_REPEAT), | 42 wrap_t_(GL_REPEAT), |
| 43 usage_(GL_NONE), |
43 max_level_set_(-1), | 44 max_level_set_(-1), |
44 texture_complete_(false), | 45 texture_complete_(false), |
45 cube_complete_(false), | 46 cube_complete_(false), |
46 npot_(false), | 47 npot_(false), |
47 has_been_bound_(false), | 48 has_been_bound_(false), |
48 framebuffer_attachment_count_(0), | 49 framebuffer_attachment_count_(0), |
49 owned_(true), | 50 owned_(true), |
50 stream_texture_(false) { | 51 stream_texture_(false), |
| 52 immutable_(false) { |
51 } | 53 } |
52 | 54 |
53 GLenum min_filter() const { | 55 GLenum min_filter() const { |
54 return min_filter_; | 56 return min_filter_; |
55 } | 57 } |
56 | 58 |
57 GLenum mag_filter() const { | 59 GLenum mag_filter() const { |
58 return mag_filter_; | 60 return mag_filter_; |
59 } | 61 } |
60 | 62 |
61 GLenum wrap_s() const { | 63 GLenum wrap_s() const { |
62 return wrap_s_; | 64 return wrap_s_; |
63 } | 65 } |
64 | 66 |
65 GLenum wrap_t() const { | 67 GLenum wrap_t() const { |
66 return wrap_t_; | 68 return wrap_t_; |
67 } | 69 } |
68 | 70 |
| 71 GLenum usage() const { |
| 72 return usage_; |
| 73 } |
| 74 |
69 int num_uncleared_mips() const { | 75 int num_uncleared_mips() const { |
70 return num_uncleared_mips_; | 76 return num_uncleared_mips_; |
71 } | 77 } |
72 | 78 |
73 // True if this texture meets all the GLES2 criteria for rendering. | 79 // True if this texture meets all the GLES2 criteria for rendering. |
74 // See section 3.8.2 of the GLES2 spec. | 80 // See section 3.8.2 of the GLES2 spec. |
75 bool CanRender(const FeatureInfo* feature_info) const; | 81 bool CanRender(const FeatureInfo* feature_info) const; |
76 | 82 |
77 bool CanRenderTo() const { | 83 bool CanRenderTo() const { |
78 return !stream_texture_ && target_ != GL_TEXTURE_EXTERNAL_OES; | 84 return !stream_texture_ && target_ != GL_TEXTURE_EXTERNAL_OES; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 168 } |
163 | 169 |
164 void SetStreamTexture(bool stream_texture) { | 170 void SetStreamTexture(bool stream_texture) { |
165 stream_texture_ = stream_texture; | 171 stream_texture_ = stream_texture; |
166 } | 172 } |
167 | 173 |
168 int IsStreamTexture() { | 174 int IsStreamTexture() { |
169 return stream_texture_; | 175 return stream_texture_; |
170 } | 176 } |
171 | 177 |
| 178 void SetImmutable(bool immutable) { |
| 179 DCHECK(!immutable_); |
| 180 immutable_ = immutable; |
| 181 } |
| 182 |
| 183 bool IsImmutable() { |
| 184 return immutable_; |
| 185 } |
| 186 |
172 // Whether a particular level/face is cleared. | 187 // Whether a particular level/face is cleared. |
173 bool IsLevelCleared(GLenum target, GLint level); | 188 bool IsLevelCleared(GLenum target, GLint level); |
174 | 189 |
175 private: | 190 private: |
176 friend class TextureManager; | 191 friend class TextureManager; |
177 friend class base::RefCounted<TextureInfo>; | 192 friend class base::RefCounted<TextureInfo>; |
178 | 193 |
179 ~TextureInfo() { } | 194 ~TextureInfo() { } |
180 | 195 |
181 struct LevelInfo { | 196 struct LevelInfo { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // Returns false if a GL error was generated. | 247 // Returns false if a GL error was generated. |
233 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level); | 248 bool ClearLevel(GLES2Decoder* decoder, GLenum target, GLint level); |
234 | 249 |
235 // Sets a texture parameter. | 250 // Sets a texture parameter. |
236 // TODO(gman): Expand to SetParameteri,f,iv,fv | 251 // TODO(gman): Expand to SetParameteri,f,iv,fv |
237 // Returns false if param was INVALID_ENUN | 252 // Returns false if param was INVALID_ENUN |
238 bool SetParameter( | 253 bool SetParameter( |
239 const FeatureInfo* feature_info, GLenum pname, GLint param); | 254 const FeatureInfo* feature_info, GLenum pname, GLint param); |
240 | 255 |
241 // Makes each of the mip levels as though they were generated. | 256 // Makes each of the mip levels as though they were generated. |
242 bool MarkMipmapsGenerated(const FeatureInfo* feature_info); | 257 bool MarkMipmapsGenerated(const FeatureInfo* feature_info, bool cleared); |
243 | 258 |
244 void MarkAsDeleted() { | 259 void MarkAsDeleted() { |
245 service_id_ = 0; | 260 service_id_ = 0; |
246 deleted_ = true; | 261 deleted_ = true; |
247 } | 262 } |
248 | 263 |
249 bool NeedsMips() const { | 264 bool NeedsMips() const { |
250 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; | 265 return min_filter_ != GL_NEAREST && min_filter_ != GL_LINEAR; |
251 } | 266 } |
252 | 267 |
(...skipping 22 matching lines...) Expand all Loading... |
275 int num_uncleared_mips_; | 290 int num_uncleared_mips_; |
276 | 291 |
277 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. | 292 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. |
278 GLenum target_; | 293 GLenum target_; |
279 | 294 |
280 // Texture parameters. | 295 // Texture parameters. |
281 GLenum min_filter_; | 296 GLenum min_filter_; |
282 GLenum mag_filter_; | 297 GLenum mag_filter_; |
283 GLenum wrap_s_; | 298 GLenum wrap_s_; |
284 GLenum wrap_t_; | 299 GLenum wrap_t_; |
| 300 GLenum usage_; |
285 | 301 |
286 // The maximum level that has been set. | 302 // The maximum level that has been set. |
287 GLint max_level_set_; | 303 GLint max_level_set_; |
288 | 304 |
289 // Whether or not this texture is "texture complete" | 305 // Whether or not this texture is "texture complete" |
290 bool texture_complete_; | 306 bool texture_complete_; |
291 | 307 |
292 // Whether or not this texture is "cube complete" | 308 // Whether or not this texture is "cube complete" |
293 bool cube_complete_; | 309 bool cube_complete_; |
294 | 310 |
295 // Whether or not this texture is non-power-of-two | 311 // Whether or not this texture is non-power-of-two |
296 bool npot_; | 312 bool npot_; |
297 | 313 |
298 // Whether this texture has ever been bound. | 314 // Whether this texture has ever been bound. |
299 bool has_been_bound_; | 315 bool has_been_bound_; |
300 | 316 |
301 // The number of framebuffers this texture is attached to. | 317 // The number of framebuffers this texture is attached to. |
302 int framebuffer_attachment_count_; | 318 int framebuffer_attachment_count_; |
303 | 319 |
304 // Whether the associated context group owns this texture and should delete | 320 // Whether the associated context group owns this texture and should delete |
305 // it. | 321 // it. |
306 bool owned_; | 322 bool owned_; |
307 | 323 |
308 // Whether this is a special streaming texture. | 324 // Whether this is a special streaming texture. |
309 bool stream_texture_; | 325 bool stream_texture_; |
310 | 326 |
| 327 // Whether the texture is immutable and no further changes to the format |
| 328 // or dimensions of the texture object can be made. |
| 329 bool immutable_; |
| 330 |
311 DISALLOW_COPY_AND_ASSIGN(TextureInfo); | 331 DISALLOW_COPY_AND_ASSIGN(TextureInfo); |
312 }; | 332 }; |
313 | 333 |
314 TextureManager(GLsizei max_texture_size, | 334 TextureManager(GLsizei max_texture_size, |
315 GLsizei max_cube_map_texture_size); | 335 GLsizei max_cube_map_texture_size); |
316 ~TextureManager(); | 336 ~TextureManager(); |
317 | 337 |
318 // Init the texture manager. | 338 // Init the texture manager. |
319 bool Initialize(const FeatureInfo* feature_info); | 339 bool Initialize(const FeatureInfo* feature_info); |
320 | 340 |
(...skipping 16 matching lines...) Expand all Loading... |
337 GLsizei MaxSizeForTarget(GLenum target) const { | 357 GLsizei MaxSizeForTarget(GLenum target) const { |
338 switch (target) { | 358 switch (target) { |
339 case GL_TEXTURE_2D: | 359 case GL_TEXTURE_2D: |
340 case GL_TEXTURE_EXTERNAL_OES: | 360 case GL_TEXTURE_EXTERNAL_OES: |
341 return max_texture_size_; | 361 return max_texture_size_; |
342 default: | 362 default: |
343 return max_cube_map_texture_size_; | 363 return max_cube_map_texture_size_; |
344 } | 364 } |
345 } | 365 } |
346 | 366 |
| 367 // Returns the maxium number of levels a texture of the given size can have. |
| 368 static GLsizei ComputeMipMapCount( |
| 369 GLsizei width, GLsizei height, GLsizei depth); |
| 370 |
347 // Checks if a dimensions are valid for a given target. | 371 // Checks if a dimensions are valid for a given target. |
348 bool ValidForTarget( | 372 bool ValidForTarget( |
349 const FeatureInfo* feature_info, | 373 const FeatureInfo* feature_info, |
350 GLenum target, GLint level, | 374 GLenum target, GLint level, |
351 GLsizei width, GLsizei height, GLsizei depth); | 375 GLsizei width, GLsizei height, GLsizei depth); |
352 | 376 |
353 // Sets the TextureInfo's target | 377 // Sets the TextureInfo's target |
354 // Parameters: | 378 // Parameters: |
355 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 379 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
356 // max_levels: The maximum levels this type of target can have. | 380 // max_levels: The maximum levels this type of target can have. |
(...skipping 21 matching lines...) Expand all Loading... |
378 void SetLevelCleared(TextureInfo* info, GLenum target, GLint level); | 402 void SetLevelCleared(TextureInfo* info, GLenum target, GLint level); |
379 | 403 |
380 // Sets a texture parameter of a TextureInfo | 404 // Sets a texture parameter of a TextureInfo |
381 // TODO(gman): Expand to SetParameteri,f,iv,fv | 405 // TODO(gman): Expand to SetParameteri,f,iv,fv |
382 bool SetParameter( | 406 bool SetParameter( |
383 const FeatureInfo* feature_info, | 407 const FeatureInfo* feature_info, |
384 TextureInfo* info, GLenum pname, GLint param); | 408 TextureInfo* info, GLenum pname, GLint param); |
385 | 409 |
386 // Makes each of the mip levels as though they were generated. | 410 // Makes each of the mip levels as though they were generated. |
387 // Returns false if that's not allowed for the given texture. | 411 // Returns false if that's not allowed for the given texture. |
388 bool MarkMipmapsGenerated(const FeatureInfo* feature_info, TextureInfo* info); | 412 bool MarkMipmapsGenerated(const FeatureInfo* feature_info, TextureInfo* info, |
| 413 bool cleared); |
389 | 414 |
390 // Clears any uncleared renderable levels. | 415 // Clears any uncleared renderable levels. |
391 bool ClearRenderableLevels(GLES2Decoder* decoder, TextureInfo* info); | 416 bool ClearRenderableLevels(GLES2Decoder* decoder, TextureInfo* info); |
392 | 417 |
393 // Clear a specific level. | 418 // Clear a specific level. |
394 bool ClearTextureLevel( | 419 bool ClearTextureLevel( |
395 GLES2Decoder* decoder,TextureInfo* info, GLenum target, GLint level); | 420 GLES2Decoder* decoder,TextureInfo* info, GLenum target, GLint level); |
396 | 421 |
397 // Creates a new texture info. | 422 // Creates a new texture info. |
398 TextureInfo* CreateTextureInfo( | 423 TextureInfo* CreateTextureInfo( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 TextureInfo::Ref default_texture_external_oes_; | 510 TextureInfo::Ref default_texture_external_oes_; |
486 TextureInfo::Ref default_texture_rectangle_arb_; | 511 TextureInfo::Ref default_texture_rectangle_arb_; |
487 | 512 |
488 DISALLOW_COPY_AND_ASSIGN(TextureManager); | 513 DISALLOW_COPY_AND_ASSIGN(TextureManager); |
489 }; | 514 }; |
490 | 515 |
491 } // namespace gles2 | 516 } // namespace gles2 |
492 } // namespace gpu | 517 } // namespace gpu |
493 | 518 |
494 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 519 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
OLD | NEW |