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 |
385 DISALLOW_COPY_AND_ASSIGN(Texture); | 371 DISALLOW_COPY_AND_ASSIGN(Texture); |
386 }; | 372 }; |
387 | 373 |
388 // This class represents a texture in a client context group. It's mostly 1:1 | 374 // This class represents a texture in a client context group. It's mostly 1:1 |
389 // with a client id, though it can outlive the client id if it's still bound to | 375 // with a client id, though it can outlive the client id if it's still bound to |
390 // a FBO or another context when destroyed. | 376 // a FBO or another context when destroyed. |
391 // Multiple TextureRef can point to the same texture with cross-context sharing. | 377 // Multiple TextureRef can point to the same texture with cross-context sharing. |
392 // | |
393 // Note: for stream textures, the TextureRef that created the stream texture is | |
394 // set as the "owner" of the stream texture, i.e. it will call | |
395 // DestroyStreamTexture on destruction. This is because the StreamTextureManager | |
396 // isn't generally shared between ContextGroups, so ownership can't be at the | |
397 // Texture level. We also can't have multiple StreamTexture on the same service | |
398 // id, so there can be only one owner. | |
399 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> { | 378 class GPU_EXPORT TextureRef : public base::RefCounted<TextureRef> { |
400 public: | 379 public: |
401 TextureRef(TextureManager* manager, GLuint client_id, Texture* texture); | 380 TextureRef(TextureManager* manager, GLuint client_id, Texture* texture); |
402 static scoped_refptr<TextureRef> Create(TextureManager* manager, | 381 static scoped_refptr<TextureRef> Create(TextureManager* manager, |
403 GLuint client_id, | 382 GLuint client_id, |
404 GLuint service_id); | 383 GLuint service_id); |
405 const Texture* texture() const { return texture_; } | 384 const Texture* texture() const { return texture_; } |
406 Texture* texture() { return texture_; } | 385 Texture* texture() { return texture_; } |
407 GLuint client_id() const { return client_id_; } | 386 GLuint client_id() const { return client_id_; } |
408 GLuint service_id() const { return texture_->service_id(); } | 387 GLuint service_id() const { return texture_->service_id(); } |
409 | 388 |
410 private: | 389 private: |
411 friend class base::RefCounted<TextureRef>; | 390 friend class base::RefCounted<TextureRef>; |
412 friend class Texture; | 391 friend class Texture; |
413 friend class TextureManager; | 392 friend class TextureManager; |
414 | 393 |
415 ~TextureRef(); | 394 ~TextureRef(); |
416 const TextureManager* manager() const { return manager_; } | 395 const TextureManager* manager() const { return manager_; } |
417 TextureManager* manager() { return manager_; } | 396 TextureManager* manager() { return manager_; } |
418 void reset_client_id() { client_id_ = 0; } | 397 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 | 398 |
424 TextureManager* manager_; | 399 TextureManager* manager_; |
425 Texture* texture_; | 400 Texture* texture_; |
426 GLuint client_id_; | 401 GLuint client_id_; |
427 bool is_stream_texture_owner_; | |
428 | 402 |
429 DISALLOW_COPY_AND_ASSIGN(TextureRef); | 403 DISALLOW_COPY_AND_ASSIGN(TextureRef); |
430 }; | 404 }; |
431 | 405 |
432 // This class keeps track of the textures and their sizes so we can do NPOT and | 406 // This class keeps track of the textures and their sizes so we can do NPOT and |
433 // texture complete checking. | 407 // texture complete checking. |
434 // | 408 // |
435 // NOTE: To support shared resources an instance of this class will need to be | 409 // NOTE: To support shared resources an instance of this class will need to be |
436 // shared by multiple GLES2Decoders. | 410 // shared by multiple GLES2Decoders. |
437 class GPU_EXPORT TextureManager { | 411 class GPU_EXPORT TextureManager { |
(...skipping 24 matching lines...) Expand all Loading... |
462 TextureManager(MemoryTracker* memory_tracker, | 436 TextureManager(MemoryTracker* memory_tracker, |
463 FeatureInfo* feature_info, | 437 FeatureInfo* feature_info, |
464 GLsizei max_texture_size, | 438 GLsizei max_texture_size, |
465 GLsizei max_cube_map_texture_size); | 439 GLsizei max_cube_map_texture_size); |
466 ~TextureManager(); | 440 ~TextureManager(); |
467 | 441 |
468 void set_framebuffer_manager(FramebufferManager* manager) { | 442 void set_framebuffer_manager(FramebufferManager* manager) { |
469 framebuffer_manager_ = manager; | 443 framebuffer_manager_ = manager; |
470 } | 444 } |
471 | 445 |
472 void set_stream_texture_manager(StreamTextureManager* manager) { | |
473 stream_texture_manager_ = manager; | |
474 } | |
475 | |
476 // Init the texture manager. | 446 // Init the texture manager. |
477 bool Initialize(); | 447 bool Initialize(); |
478 | 448 |
479 // Must call before destruction. | 449 // Must call before destruction. |
480 void Destroy(bool have_context); | 450 void Destroy(bool have_context); |
481 | 451 |
482 // Returns the maximum number of levels. | 452 // Returns the maximum number of levels. |
483 GLint MaxLevelsForTarget(GLenum target) const { | 453 GLint MaxLevelsForTarget(GLenum target) const { |
484 switch (target) { | 454 switch (target) { |
485 case GL_TEXTURE_2D: | 455 case GL_TEXTURE_2D: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 493 } |
524 | 494 |
525 // Sets the Texture's target | 495 // Sets the Texture's target |
526 // Parameters: | 496 // Parameters: |
527 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP | 497 // target: GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP |
528 // max_levels: The maximum levels this type of target can have. | 498 // max_levels: The maximum levels this type of target can have. |
529 void SetTarget( | 499 void SetTarget( |
530 TextureRef* ref, | 500 TextureRef* ref, |
531 GLenum target); | 501 GLenum target); |
532 | 502 |
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. | 503 // Set the info for a particular level in a TexureInfo. |
541 void SetLevelInfo( | 504 void SetLevelInfo( |
542 TextureRef* ref, | 505 TextureRef* ref, |
543 GLenum target, | 506 GLenum target, |
544 GLint level, | 507 GLint level, |
545 GLenum internal_format, | 508 GLenum internal_format, |
546 GLsizei width, | 509 GLsizei width, |
547 GLsizei height, | 510 GLsizei height, |
548 GLsizei depth, | 511 GLsizei depth, |
549 GLint border, | 512 GLint border, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 Texture::CanRenderCondition new_condition); | 652 Texture::CanRenderCondition new_condition); |
690 void IncFramebufferStateChangeCount(); | 653 void IncFramebufferStateChangeCount(); |
691 | 654 |
692 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); | 655 MemoryTypeTracker* GetMemTracker(GLenum texture_pool); |
693 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; | 656 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_; |
694 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; | 657 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_; |
695 | 658 |
696 scoped_refptr<FeatureInfo> feature_info_; | 659 scoped_refptr<FeatureInfo> feature_info_; |
697 | 660 |
698 FramebufferManager* framebuffer_manager_; | 661 FramebufferManager* framebuffer_manager_; |
699 StreamTextureManager* stream_texture_manager_; | |
700 | 662 |
701 // Info for each texture in the system. | 663 // Info for each texture in the system. |
702 typedef base::hash_map<GLuint, scoped_refptr<TextureRef> > TextureMap; | 664 typedef base::hash_map<GLuint, scoped_refptr<TextureRef> > TextureMap; |
703 TextureMap textures_; | 665 TextureMap textures_; |
704 | 666 |
705 GLsizei max_texture_size_; | 667 GLsizei max_texture_size_; |
706 GLsizei max_cube_map_texture_size_; | 668 GLsizei max_cube_map_texture_size_; |
707 GLint max_levels_; | 669 GLint max_levels_; |
708 GLint max_cube_map_levels_; | 670 GLint max_cube_map_levels_; |
709 | 671 |
(...skipping 17 matching lines...) Expand all Loading... |
727 | 689 |
728 ObserverList<DestructionObserver> destruction_observers_; | 690 ObserverList<DestructionObserver> destruction_observers_; |
729 | 691 |
730 DISALLOW_COPY_AND_ASSIGN(TextureManager); | 692 DISALLOW_COPY_AND_ASSIGN(TextureManager); |
731 }; | 693 }; |
732 | 694 |
733 } // namespace gles2 | 695 } // namespace gles2 |
734 } // namespace gpu | 696 } // namespace gpu |
735 | 697 |
736 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ | 698 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ |
OLD | NEW |