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

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

Issue 11516014: Track managed memory usage in the command buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve against HEAD Created 8 years 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) 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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "gpu/command_buffer/service/feature_info.h" 14 #include "gpu/command_buffer/service/feature_info.h"
15 #include "gpu/command_buffer/service/gl_utils.h" 15 #include "gpu/command_buffer/service/gl_utils.h"
16 #include "gpu/command_buffer/service/memory_tracking.h"
16 #include "gpu/gpu_export.h" 17 #include "gpu/gpu_export.h"
17 #include "ui/gl/gl_image.h" 18 #include "ui/gl/gl_image.h"
18 19
19 namespace gpu { 20 namespace gpu {
20 namespace gles2 { 21 namespace gles2 {
21 22
22 class GLES2Decoder; 23 class GLES2Decoder;
23 class Display; 24 class Display;
24 class TextureDefinition; 25 class TextureDefinition;
25 class MemoryTracker;
26 class MemoryTypeTracker;
27 26
28 // This class keeps track of the textures and their sizes so we can do NPOT and 27 // This class keeps track of the textures and their sizes so we can do NPOT and
29 // texture complete checking. 28 // texture complete checking.
30 // 29 //
31 // NOTE: To support shared resources an instance of this class will need to be 30 // NOTE: To support shared resources an instance of this class will need to be
32 // shared by multiple GLES2Decoders. 31 // shared by multiple GLES2Decoders.
33 class GPU_EXPORT TextureManager { 32 class GPU_EXPORT TextureManager {
34 public: 33 public:
35 enum DefaultAndBlackTextures { 34 enum DefaultAndBlackTextures {
36 kTexture2D, 35 kTexture2D,
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP. 304 // The target. 0 if unset, otherwise GL_TEXTURE_2D or GL_TEXTURE_CUBE_MAP.
306 GLenum target_; 305 GLenum target_;
307 306
308 // Texture parameters. 307 // Texture parameters.
309 GLenum min_filter_; 308 GLenum min_filter_;
310 GLenum mag_filter_; 309 GLenum mag_filter_;
311 GLenum wrap_s_; 310 GLenum wrap_s_;
312 GLenum wrap_t_; 311 GLenum wrap_t_;
313 GLenum usage_; 312 GLenum usage_;
314 313
314 // The accounting pool towards which the memory for this allocation should
315 // be charged. This will be rolled into a new GLenum texture parameter in
316 // a separate change.
317 MemoryTracker::Pool tracking_pool_;
318
315 // The maximum level that has been set. 319 // The maximum level that has been set.
316 GLint max_level_set_; 320 GLint max_level_set_;
317 321
318 // Whether or not this texture is "texture complete" 322 // Whether or not this texture is "texture complete"
319 bool texture_complete_; 323 bool texture_complete_;
320 324
321 // Whether or not this texture is "cube complete" 325 // Whether or not this texture is "cube complete"
322 bool cube_complete_; 326 bool cube_complete_;
323 327
324 // Whether or not this texture is non-power-of-two 328 // Whether or not this texture is non-power-of-two
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 case GL_SAMPLER_EXTERNAL_OES: 504 case GL_SAMPLER_EXTERNAL_OES:
501 return black_texture_ids_[kExternalOES]; 505 return black_texture_ids_[kExternalOES];
502 case GL_SAMPLER_2D_RECT_ARB: 506 case GL_SAMPLER_2D_RECT_ARB:
503 return black_texture_ids_[kRectangleARB]; 507 return black_texture_ids_[kRectangleARB];
504 default: 508 default:
505 NOTREACHED(); 509 NOTREACHED();
506 return 0; 510 return 0;
507 } 511 }
508 } 512 }
509 513
510 uint32 mem_represented() const { 514 size_t mem_represented() const {
511 return mem_represented_; 515 return
516 memory_tracker_managed_->GetMemRepresented() +
517 memory_tracker_unmanaged_->GetMemRepresented();
512 } 518 }
513 519
514 void SetLevelImage( 520 void SetLevelImage(
515 TextureInfo* info, 521 TextureInfo* info,
516 GLenum target, 522 GLenum target,
517 GLint level, 523 GLint level,
518 gfx::GLImage* image); 524 gfx::GLImage* image);
519 525
520 void AddToSignature( 526 void AddToSignature(
521 TextureInfo* info, 527 TextureInfo* info,
522 GLenum target, 528 GLenum target,
523 GLint level, 529 GLint level,
524 std::string* signature) const; 530 std::string* signature) const;
525 531
526 private: 532 private:
527 // Helper for Initialize(). 533 // Helper for Initialize().
528 TextureInfo::Ref CreateDefaultAndBlackTextures( 534 TextureInfo::Ref CreateDefaultAndBlackTextures(
529 GLenum target, 535 GLenum target,
530 GLuint* black_texture); 536 GLuint* black_texture);
531 537
532 void UpdateMemRepresented();
533
534 void StartTracking(TextureInfo* info); 538 void StartTracking(TextureInfo* info);
535 void StopTracking(TextureInfo* info); 539 void StopTracking(TextureInfo* info);
536 540
537 scoped_ptr<MemoryTypeTracker> texture_memory_tracker_; 541 MemoryTypeTracker* GetMemTracker(MemoryTracker::Pool tracking_pool);
542 scoped_ptr<MemoryTypeTracker> memory_tracker_managed_;
543 scoped_ptr<MemoryTypeTracker> memory_tracker_unmanaged_;
538 544
539 FeatureInfo::Ref feature_info_; 545 FeatureInfo::Ref feature_info_;
540 546
541 // Info for each texture in the system. 547 // Info for each texture in the system.
542 typedef base::hash_map<GLuint, TextureInfo::Ref> TextureInfoMap; 548 typedef base::hash_map<GLuint, TextureInfo::Ref> TextureInfoMap;
543 TextureInfoMap texture_infos_; 549 TextureInfoMap texture_infos_;
544 550
545 GLsizei max_texture_size_; 551 GLsizei max_texture_size_;
546 GLsizei max_cube_map_texture_size_; 552 GLsizei max_cube_map_texture_size_;
547 GLint max_levels_; 553 GLint max_levels_;
548 GLint max_cube_map_levels_; 554 GLint max_cube_map_levels_;
549 555
550 int num_unrenderable_textures_; 556 int num_unrenderable_textures_;
551 int num_unsafe_textures_; 557 int num_unsafe_textures_;
552 int num_uncleared_mips_; 558 int num_uncleared_mips_;
553 559
554 // Counts the number of TextureInfo allocated with 'this' as its manager. 560 // Counts the number of TextureInfo allocated with 'this' as its manager.
555 // Allows to check no TextureInfo will outlive this. 561 // Allows to check no TextureInfo will outlive this.
556 unsigned int texture_info_count_; 562 unsigned int texture_info_count_;
557 563
558 uint32 mem_represented_;
559
560 bool have_context_; 564 bool have_context_;
561 565
562 // Black (0,0,0,1) textures for when non-renderable textures are used. 566 // Black (0,0,0,1) textures for when non-renderable textures are used.
563 // NOTE: There is no corresponding TextureInfo for these textures. 567 // NOTE: There is no corresponding TextureInfo for these textures.
564 // TextureInfos are only for textures the client side can access. 568 // TextureInfos are only for textures the client side can access.
565 GLuint black_texture_ids_[kNumDefaultTextures]; 569 GLuint black_texture_ids_[kNumDefaultTextures];
566 570
567 // The default textures for each target (texture name = 0) 571 // The default textures for each target (texture name = 0)
568 TextureInfo::Ref default_textures_[kNumDefaultTextures]; 572 TextureInfo::Ref default_textures_[kNumDefaultTextures];
569 573
570 DISALLOW_COPY_AND_ASSIGN(TextureManager); 574 DISALLOW_COPY_AND_ASSIGN(TextureManager);
571 }; 575 };
572 576
573 } // namespace gles2 577 } // namespace gles2
574 } // namespace gpu 578 } // namespace gpu
575 579
576 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_ 580 #endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698