| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" | 17 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
| 18 #include "gpu/command_buffer/service/gl_utils.h" | 18 #include "gpu/command_buffer/service/gl_utils.h" |
| 19 #include "gpu/command_buffer/service/memory_tracking.h" | 19 #include "gpu/command_buffer/service/memory_tracking.h" |
| 20 #include "gpu/gpu_export.h" | 20 #include "gpu/gpu_export.h" |
| 21 #include "ui/gl/gl_image.h" | 21 #include "ui/gl/gl_image.h" |
| 22 | 22 |
| 23 namespace gpu { | 23 namespace gpu { |
| 24 | 24 |
| 25 class StreamTextureManager; | |
| 26 | |
| 27 namespace gles2 { | 25 namespace gles2 { |
| 28 | 26 |
| 29 class GLES2Decoder; | 27 class GLES2Decoder; |
| 30 class Display; | 28 class Display; |
| 31 class ErrorState; | 29 class ErrorState; |
| 32 class FeatureInfo; | 30 class FeatureInfo; |
| 33 class FramebufferManager; | 31 class FramebufferManager; |
| 34 class MailboxManager; | 32 class MailboxManager; |
| 35 class TextureManager; | 33 class TextureManager; |
| 36 class TextureRef; | 34 class TextureRef; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 66 |
| 69 int num_uncleared_mips() const { | 67 int num_uncleared_mips() const { |
| 70 return num_uncleared_mips_; | 68 return num_uncleared_mips_; |
| 71 } | 69 } |
| 72 | 70 |
| 73 uint32 estimated_size() const { | 71 uint32 estimated_size() const { |
| 74 return estimated_size_; | 72 return estimated_size_; |
| 75 } | 73 } |
| 76 | 74 |
| 77 bool CanRenderTo() const { | 75 bool CanRenderTo() const { |
| 78 return !stream_texture_ && target_ != GL_TEXTURE_EXTERNAL_OES; | 76 return target_ != GL_TEXTURE_EXTERNAL_OES; |
| 79 } | 77 } |
| 80 | 78 |
| 81 // The service side OpenGL id of the texture. | 79 // The service side OpenGL id of the texture. |
| 82 GLuint service_id() const { | 80 GLuint service_id() const { |
| 83 return service_id_; | 81 return service_id_; |
| 84 } | 82 } |
| 85 | 83 |
| 86 void SetServiceId(GLuint service_id) { | 84 void SetServiceId(GLuint service_id) { |
| 87 DCHECK(service_id); | 85 DCHECK(service_id); |
| 88 service_id_ = service_id; | 86 service_id_ = service_id; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 132 |
| 135 void AttachToFramebuffer() { | 133 void AttachToFramebuffer() { |
| 136 ++framebuffer_attachment_count_; | 134 ++framebuffer_attachment_count_; |
| 137 } | 135 } |
| 138 | 136 |
| 139 void DetachFromFramebuffer() { | 137 void DetachFromFramebuffer() { |
| 140 DCHECK_GT(framebuffer_attachment_count_, 0); | 138 DCHECK_GT(framebuffer_attachment_count_, 0); |
| 141 --framebuffer_attachment_count_; | 139 --framebuffer_attachment_count_; |
| 142 } | 140 } |
| 143 | 141 |
| 144 bool IsStreamTexture() const { | |
| 145 return stream_texture_; | |
| 146 } | |
| 147 | |
| 148 void SetImmutable(bool immutable) { | 142 void SetImmutable(bool immutable) { |
| 149 immutable_ = immutable; | 143 immutable_ = immutable; |
| 150 } | 144 } |
| 151 | 145 |
| 152 bool IsImmutable() const { | 146 bool IsImmutable() const { |
| 153 return immutable_; | 147 return immutable_; |
| 154 } | 148 } |
| 155 | 149 |
| 156 // Whether a particular level/face is cleared. | 150 // Whether a particular level/face is cleared. |
| 157 bool IsLevelCleared(GLenum target, GLint level) const; | 151 bool IsLevelCleared(GLenum target, GLint level) const; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // same format, all the same dimensions and all width = height. | 223 // same format, all the same dimensions and all width = height. |
| 230 bool cube_complete() const { | 224 bool cube_complete() const { |
| 231 return cube_complete_; | 225 return cube_complete_; |
| 232 } | 226 } |
| 233 | 227 |
| 234 // Whether or not this texture is a non-power-of-two texture. | 228 // Whether or not this texture is a non-power-of-two texture. |
| 235 bool npot() const { | 229 bool npot() const { |
| 236 return npot_; | 230 return npot_; |
| 237 } | 231 } |
| 238 | 232 |
| 239 void SetStreamTexture(bool stream_texture) { | |
| 240 stream_texture_ = stream_texture; | |
| 241 UpdateCanRenderCondition(); | |
| 242 } | |
| 243 | |
| 244 // Marks a particular level as cleared or uncleared. | 233 // Marks a particular level as cleared or uncleared. |
| 245 void SetLevelCleared(GLenum target, GLint level, bool cleared); | 234 void SetLevelCleared(GLenum target, GLint level, bool cleared); |
| 246 | 235 |
| 247 // Updates the cleared flag for this texture by inspecting all the mips. | 236 // Updates the cleared flag for this texture by inspecting all the mips. |
| 248 void UpdateCleared(); | 237 void UpdateCleared(); |
| 249 | 238 |
| 250 // Clears any renderable uncleared levels. | 239 // Clears any renderable uncleared levels. |
| 251 // Returns false if a GL error was generated. | 240 // Returns false if a GL error was generated. |
| 252 bool ClearRenderableLevels(GLES2Decoder* decoder); | 241 bool ClearRenderableLevels(GLES2Decoder* decoder); |
| 253 | 242 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 351 |
| 363 // Whether or not this texture is non-power-of-two | 352 // Whether or not this texture is non-power-of-two |
| 364 bool npot_; | 353 bool npot_; |
| 365 | 354 |
| 366 // Whether this texture has ever been bound. | 355 // Whether this texture has ever been bound. |
| 367 bool has_been_bound_; | 356 bool has_been_bound_; |
| 368 | 357 |
| 369 // The number of framebuffers this texture is attached to. | 358 // The number of framebuffers this texture is attached to. |
| 370 int framebuffer_attachment_count_; | 359 int framebuffer_attachment_count_; |
| 371 | 360 |
| 372 // Whether this is a special streaming texture. | |
| 373 bool stream_texture_; | |
| 374 | |
| 375 // Whether the texture is immutable and no further changes to the format | 361 // Whether the texture is immutable and no further changes to the format |
| 376 // or dimensions of the texture object can be made. | 362 // or dimensions of the texture object can be made. |
| 377 bool immutable_; | 363 bool immutable_; |
| 378 | 364 |
| 379 // Size in bytes this texture is assumed to take in memory. | 365 // Size in bytes this texture is assumed to take in memory. |
| 380 uint32 estimated_size_; | 366 uint32 estimated_size_; |
| 381 | 367 |
| 382 // Cache of the computed CanRenderCondition flag. | 368 // Cache of the computed CanRenderCondition flag. |
| 383 CanRenderCondition can_render_condition_; | 369 CanRenderCondition can_render_condition_; |
| 384 | 370 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 409 | 395 |
| 410 private: | 396 private: |
| 411 friend class base::RefCounted<TextureRef>; | 397 friend class base::RefCounted<TextureRef>; |
| 412 friend class Texture; | 398 friend class Texture; |
| 413 friend class TextureManager; | 399 friend class TextureManager; |
| 414 | 400 |
| 415 ~TextureRef(); | 401 ~TextureRef(); |
| 416 const TextureManager* manager() const { return manager_; } | 402 const TextureManager* manager() const { return manager_; } |
| 417 TextureManager* manager() { return manager_; } | 403 TextureManager* manager() { return manager_; } |
| 418 void reset_client_id() { client_id_ = 0; } | 404 void reset_client_id() { client_id_ = 0; } |
| 419 void set_is_stream_texture_owner(bool owner) { | |
| 420 is_stream_texture_owner_ = owner; | |
| 421 } | |
| 422 bool is_stream_texture_owner() const { return is_stream_texture_owner_; } | |
| 423 | 405 |
| 424 TextureManager* manager_; | 406 TextureManager* manager_; |
| 425 Texture* texture_; | 407 Texture* texture_; |
| 426 GLuint client_id_; | 408 GLuint client_id_; |
| 427 bool is_stream_texture_owner_; | |
| 428 | 409 |
| 429 DISALLOW_COPY_AND_ASSIGN(TextureRef); | 410 DISALLOW_COPY_AND_ASSIGN(TextureRef); |
| 430 }; | 411 }; |
| 431 | 412 |
| 432 // This class keeps track of the textures and their sizes so we can do NPOT and | 413 // This class keeps track of the textures and their sizes so we can do NPOT and |
| 433 // texture complete checking. | 414 // texture complete checking. |
| 434 // | 415 // |
| 435 // NOTE: To support shared resources an instance of this class will need to be | 416 // NOTE: To support shared resources an instance of this class will need to be |
| 436 // shared by multiple GLES2Decoders. | 417 // shared by multiple GLES2Decoders. |
| 437 class GPU_EXPORT TextureManager { | 418 class GPU_EXPORT TextureManager { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 462 TextureManager(MemoryTracker* memory_tracker, | 443 TextureManager(MemoryTracker* memory_tracker, |
| 463 FeatureInfo* feature_info, | 444 FeatureInfo* feature_info, |
| 464 GLsizei max_texture_size, | 445 GLsizei max_texture_size, |
| 465 GLsizei max_cube_map_texture_size); | 446 GLsizei max_cube_map_texture_size); |
| 466 ~TextureManager(); | 447 ~TextureManager(); |
| 467 | 448 |
| 468 void set_framebuffer_manager(FramebufferManager* manager) { | 449 void set_framebuffer_manager(FramebufferManager* manager) { |
| 469 framebuffer_manager_ = manager; | 450 framebuffer_manager_ = manager; |
| 470 } | 451 } |
| 471 | 452 |
| 472 void set_stream_texture_manager(StreamTextureManager* manager) { | |
| 473 stream_texture_manager_ = manager; | |
| 474 } | |
| 475 | |
| 476 // Init the texture manager. | 453 // Init the texture manager. |
| 477 bool Initialize(); | 454 bool Initialize(); |
| 478 | 455 |
| 479 // Must call before destruction. | 456 // Must call before destruction. |
| 480 void Destroy(bool have_context); | 457 void Destroy(bool have_context); |
| 481 | 458 |
| 482 // Returns the maximum number of levels. | 459 // Returns the maximum number of levels. |
| 483 GLint MaxLevelsForTarget(GLenum target) const { | 460 GLint MaxLevelsForTarget(GLenum target) const { |
| 484 switch (target) { | 461 switch (target) { |
| 485 case GL_TEXTURE_2D: | 462 case GL_TEXTURE_2D: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 } | 500 } |
| 524 | 501 |
| 525 // Sets the Texture's target | 502 // Sets the Texture's target |
| 526 // Parameters: | 503 // Parameters: |
| 527 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 504 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
| 528 // max_levels: The maximum levels this type of target can have. | 505 // max_levels: The maximum levels this type of target can have. |
| 529 void SetTarget( | 506 void SetTarget( |
| 530 TextureRef* ref, | 507 TextureRef* ref, |
| 531 GLenum target); | 508 GLenum target); |
| 532 | 509 |
| 533 // Marks a texture as a stream texture, and the ref as the stream texture | |
| 534 // owner. | |
| 535 void SetStreamTexture(TextureRef* ref, bool stream_texture); | |
| 536 | |
| 537 // Whether the TextureRef is the stream texture owner. | |
| 538 bool IsStreamTextureOwner(TextureRef* ref); | |
| 539 | |
| 540 // Set the info for a particular level in a TexureInfo. | 510 // Set the info for a particular level in a TexureInfo. |
| 541 void SetLevelInfo( | 511 void SetLevelInfo( |
| 542 TextureRef* ref, | 512 TextureRef* ref, |
| 543 GLenum target, | 513 GLenum target, |
| 544 GLint level, | 514 GLint level, |
| 545 GLenum internal_format, | 515 GLenum internal_format, |
| 546 GLsizei width, | 516 GLsizei width, |
| 547 GLsizei height, | 517 GLsizei height, |
| 548 GLsizei depth, | 518 GLsizei depth, |
| 549 GLint border, | 519 GLint border, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 Texture::CanRenderCondition new_condition); | 659 Texture::CanRenderCondition new_condition); |
| 690 void IncFramebufferStateChangeCount(); | 660 void IncFramebufferStateChangeCount(); |
| 691 | 661 |
| 692 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); | 662 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); |
| 693 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; | 663 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; |
| 694 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; | 664 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; |
| 695 | 665 |
| 696 scoped_refptr<FeatureInfo> feature_info_; | 666 scoped_refptr<FeatureInfo> feature_info_; |
| 697 | 667 |
| 698 FramebufferManager* framebuffer_manager_; | 668 FramebufferManager* framebuffer_manager_; |
| 699 StreamTextureManager* stream_texture_manager_; | |
| 700 | 669 |
| 701 // Info for each texture in the system. | 670 // Info for each texture in the system. |
| 702 typedef base::hash_map<GLuint, scoped_refptr<TextureRef> > TextureMap; | 671 typedef base::hash_map<GLuint, scoped_refptr<TextureRef> > TextureMap; |
| 703 TextureMap textures_; | 672 TextureMap textures_; |
| 704 | 673 |
| 705 GLsizei max_texture_size_; | 674 GLsizei max_texture_size_; |
| 706 GLsizei max_cube_map_texture_size_; | 675 GLsizei max_cube_map_texture_size_; |
| 707 GLint max_levels_; | 676 GLint max_levels_; |
| 708 GLint max_cube_map_levels_; | 677 GLint max_cube_map_levels_; |
| 709 | 678 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 727 | 696 |
| 728 ObserverList<DestructionObserver> destruction_observers_; | 697 ObserverList<DestructionObserver> destruction_observers_; |
| 729 | 698 |
| 730 DISALLOW_COPY_AND_ASSIGN(TextureManager); | 699 DISALLOW_COPY_AND_ASSIGN(TextureManager); |
| 731 }; | 700 }; |
| 732 | 701 |
| 733 } // namespace gles2 | 702 } // namespace gles2 |
| 734 } // namespace gpu | 703 } // namespace gpu |
| 735 | 704 |
| 736 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 705 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
| OLD | NEW |