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