Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / gpu / command_buffer / service / renderbuffer_manager.h
blob71f830a559a45b87169c852aba2166769cb12bf6
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 RenderbufferManager;
22 // Info about a Renderbuffer.
23 class GPU_EXPORT Renderbuffer
24 : public base::RefCounted<Renderbuffer> {
25 public:
26 Renderbuffer(RenderbufferManager* manager,
27 GLuint client_id,
28 GLuint service_id);
30 GLuint service_id() const {
31 return service_id_;
34 GLuint client_id() const {
35 return client_id_;
38 bool cleared() const {
39 return cleared_;
42 GLenum internal_format() const {
43 return internal_format_;
46 GLsizei samples() const {
47 return samples_;
50 GLsizei width() const {
51 return width_;
54 GLsizei height() const {
55 return height_;
58 bool IsDeleted() const {
59 return client_id_ == 0;
62 void MarkAsValid() {
63 has_been_bound_ = true;
66 bool IsValid() const {
67 return has_been_bound_ && !IsDeleted();
70 size_t EstimatedSize();
72 size_t GetSignatureSize() const;
73 void AddToSignature(std::string* signature) const;
75 private:
76 friend class RenderbufferManager;
77 friend class base::RefCounted<Renderbuffer>;
79 ~Renderbuffer();
81 void set_cleared(bool cleared) {
82 cleared_ = cleared;
85 void SetInfo(
86 GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) {
87 samples_ = samples;
88 internal_format_ = internalformat;
89 width_ = width;
90 height_ = height;
91 cleared_ = false;
94 void MarkAsDeleted() {
95 client_id_ = 0;
98 // RenderbufferManager that owns this Renderbuffer.
99 RenderbufferManager* manager_;
101 // Client side renderbuffer id.
102 GLuint client_id_;
104 // Service side renderbuffer id.
105 GLuint service_id_;
107 // Whether this renderbuffer has been cleared
108 bool cleared_;
110 // Whether this renderbuffer has ever been bound.
111 bool has_been_bound_;
113 // Number of samples (for multi-sampled renderbuffers)
114 GLsizei samples_;
116 // Renderbuffer internalformat set through RenderbufferStorage().
117 GLenum internal_format_;
119 // Dimensions of renderbuffer.
120 GLsizei width_;
121 GLsizei height_;
124 // This class keeps track of the renderbuffers and whether or not they have
125 // been cleared.
126 class GPU_EXPORT RenderbufferManager {
127 public:
128 RenderbufferManager(MemoryTracker* memory_tracker,
129 GLint max_renderbuffer_size,
130 GLint max_samples,
131 bool depth24_supported);
132 ~RenderbufferManager();
134 GLint max_renderbuffer_size() const {
135 return max_renderbuffer_size_;
138 GLint max_samples() const {
139 return max_samples_;
142 bool HaveUnclearedRenderbuffers() const {
143 return num_uncleared_renderbuffers_ != 0;
146 void SetInfo(
147 Renderbuffer* renderbuffer,
148 GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
150 void SetCleared(Renderbuffer* renderbuffer, bool cleared);
152 // Must call before destruction.
153 void Destroy(bool have_context);
155 // Creates a Renderbuffer for the given renderbuffer ids.
156 void CreateRenderbuffer(GLuint client_id, GLuint service_id);
158 // Gets the renderbuffer for the given renderbuffer id.
159 Renderbuffer* GetRenderbuffer(GLuint client_id);
161 // Removes a renderbuffer for the given renderbuffer id.
162 void RemoveRenderbuffer(GLuint client_id);
164 size_t mem_represented() const {
165 return memory_tracker_->GetMemRepresented();
168 bool ComputeEstimatedRenderbufferSize(int width,
169 int height,
170 int samples,
171 int internal_format,
172 uint32* size) const;
173 GLenum InternalRenderbufferFormatToImplFormat(GLenum impl_format) const;
175 private:
176 friend class Renderbuffer;
178 void StartTracking(Renderbuffer* renderbuffer);
179 void StopTracking(Renderbuffer* renderbuffer);
181 scoped_ptr<MemoryTypeTracker> memory_tracker_;
183 GLint max_renderbuffer_size_;
184 GLint max_samples_;
185 bool depth24_supported_;
187 int num_uncleared_renderbuffers_;
189 // Counts the number of Renderbuffer allocated with 'this' as its manager.
190 // Allows to check no Renderbuffer will outlive this.
191 unsigned renderbuffer_count_;
193 bool have_context_;
195 // Info for each renderbuffer in the system.
196 typedef base::hash_map<GLuint, scoped_refptr<Renderbuffer> > RenderbufferMap;
197 RenderbufferMap renderbuffers_;
199 DISALLOW_COPY_AND_ASSIGN(RenderbufferManager);
202 } // namespace gles2
203 } // namespace gpu
205 #endif // GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_