Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / service / renderbuffer_manager.h
blob72b0aaeddf55986bd6d17d40e09d0292e35b9d49
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
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_
8 #include <string>
9 #include "base/basictypes.h"
10 #include "base/containers/hash_tables.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "gpu/command_buffer/service/gl_utils.h"
14 #include "gpu/command_buffer/service/memory_tracking.h"
15 #include "gpu/gpu_export.h"
17 namespace gpu {
18 namespace gles2 {
20 class FeatureInfo;
21 class RenderbufferManager;
23 // Info about a Renderbuffer.
24 class GPU_EXPORT Renderbuffer
25 : public base::RefCounted<Renderbuffer> {
26 public:
27 Renderbuffer(RenderbufferManager* manager,
28 GLuint client_id,
29 GLuint service_id);
31 GLuint service_id() const {
32 return service_id_;
35 GLuint client_id() const {
36 return client_id_;
39 bool cleared() const {
40 return cleared_;
43 GLenum internal_format() const {
44 return internal_format_;
47 GLsizei samples() const {
48 return samples_;
51 GLsizei width() const {
52 return width_;
55 GLsizei height() const {
56 return height_;
59 bool IsDeleted() const {
60 return client_id_ == 0;
63 void MarkAsValid() {
64 has_been_bound_ = true;
67 bool IsValid() const {
68 return has_been_bound_ && !IsDeleted();
71 size_t EstimatedSize();
73 size_t GetSignatureSize() const;
74 void AddToSignature(std::string* signature) const;
76 private:
77 friend class RenderbufferManager;
78 friend class base::RefCounted<Renderbuffer>;
80 ~Renderbuffer();
82 void set_cleared(bool cleared) {
83 cleared_ = cleared;
86 void SetInfo(
87 GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) {
88 samples_ = samples;
89 internal_format_ = internalformat;
90 width_ = width;
91 height_ = height;
92 cleared_ = false;
95 void MarkAsDeleted() {
96 client_id_ = 0;
99 // RenderbufferManager that owns this Renderbuffer.
100 RenderbufferManager* manager_;
102 // Client side renderbuffer id.
103 GLuint client_id_;
105 // Service side renderbuffer id.
106 GLuint service_id_;
108 // Whether this renderbuffer has been cleared
109 bool cleared_;
111 // Whether this renderbuffer has ever been bound.
112 bool has_been_bound_;
114 // Number of samples (for multi-sampled renderbuffers)
115 GLsizei samples_;
117 // Renderbuffer internalformat set through RenderbufferStorage().
118 GLenum internal_format_;
120 // Dimensions of renderbuffer.
121 GLsizei width_;
122 GLsizei height_;
125 // This class keeps track of the renderbuffers and whether or not they have
126 // been cleared.
127 class GPU_EXPORT RenderbufferManager
128 : public base::trace_event::MemoryDumpProvider {
129 public:
130 RenderbufferManager(MemoryTracker* memory_tracker,
131 GLint max_renderbuffer_size,
132 GLint max_samples,
133 FeatureInfo* feature_info);
134 ~RenderbufferManager() override;
136 GLint max_renderbuffer_size() const {
137 return max_renderbuffer_size_;
140 GLint max_samples() const {
141 return max_samples_;
144 bool HaveUnclearedRenderbuffers() const {
145 return num_uncleared_renderbuffers_ != 0;
148 void SetInfo(
149 Renderbuffer* renderbuffer,
150 GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
152 void SetCleared(Renderbuffer* renderbuffer, bool cleared);
154 // Must call before destruction.
155 void Destroy(bool have_context);
157 // Creates a Renderbuffer for the given renderbuffer ids.
158 void CreateRenderbuffer(GLuint client_id, GLuint service_id);
160 // Gets the renderbuffer for the given renderbuffer id.
161 Renderbuffer* GetRenderbuffer(GLuint client_id);
163 // Removes a renderbuffer for the given renderbuffer id.
164 void RemoveRenderbuffer(GLuint client_id);
166 size_t mem_represented() const {
167 return memory_type_tracker_->GetMemRepresented();
170 bool ComputeEstimatedRenderbufferSize(int width,
171 int height,
172 int samples,
173 int internal_format,
174 uint32* size) const;
175 GLenum InternalRenderbufferFormatToImplFormat(GLenum impl_format) const;
177 // base::trace_event::MemoryDumpProvider implementation.
178 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
179 base::trace_event::ProcessMemoryDump* pmd) override;
181 private:
182 friend class Renderbuffer;
184 void StartTracking(Renderbuffer* renderbuffer);
185 void StopTracking(Renderbuffer* renderbuffer);
187 scoped_ptr<MemoryTypeTracker> memory_type_tracker_;
188 MemoryTracker* memory_tracker_;
190 GLint max_renderbuffer_size_;
191 GLint max_samples_;
193 scoped_refptr<FeatureInfo> feature_info_;
195 int num_uncleared_renderbuffers_;
197 // Counts the number of Renderbuffer allocated with 'this' as its manager.
198 // Allows to check no Renderbuffer will outlive this.
199 unsigned renderbuffer_count_;
201 bool have_context_;
203 // Info for each renderbuffer in the system.
204 typedef base::hash_map<GLuint, scoped_refptr<Renderbuffer> > RenderbufferMap;
205 RenderbufferMap renderbuffers_;
207 DISALLOW_COPY_AND_ASSIGN(RenderbufferManager);
210 } // namespace gles2
211 } // namespace gpu
213 #endif // GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_