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_
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"
20 class RenderbufferManager
;
22 // Info about a Renderbuffer.
23 class GPU_EXPORT Renderbuffer
24 : public base::RefCounted
<Renderbuffer
> {
26 Renderbuffer(RenderbufferManager
* manager
,
30 GLuint
service_id() const {
34 GLuint
client_id() const {
38 bool cleared() const {
42 GLenum
internal_format() const {
43 return internal_format_
;
46 GLsizei
samples() const {
50 GLsizei
width() const {
54 GLsizei
height() const {
58 bool IsDeleted() const {
59 return client_id_
== 0;
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;
76 friend class RenderbufferManager
;
77 friend class base::RefCounted
<Renderbuffer
>;
81 void set_cleared(bool cleared
) {
86 GLsizei samples
, GLenum internalformat
, GLsizei width
, GLsizei height
) {
88 internal_format_
= internalformat
;
94 void MarkAsDeleted() {
98 // RenderbufferManager that owns this Renderbuffer.
99 RenderbufferManager
* manager_
;
101 // Client side renderbuffer id.
104 // Service side renderbuffer id.
107 // Whether this renderbuffer has been cleared
110 // Whether this renderbuffer has ever been bound.
111 bool has_been_bound_
;
113 // Number of samples (for multi-sampled renderbuffers)
116 // Renderbuffer internalformat set through RenderbufferStorage().
117 GLenum internal_format_
;
119 // Dimensions of renderbuffer.
124 // This class keeps track of the renderbuffers and whether or not they have
126 class GPU_EXPORT RenderbufferManager
{
128 RenderbufferManager(MemoryTracker
* memory_tracker
,
129 GLint max_renderbuffer_size
,
131 bool depth24_supported
);
132 ~RenderbufferManager();
134 GLint
max_renderbuffer_size() const {
135 return max_renderbuffer_size_
;
138 GLint
max_samples() const {
142 bool HaveUnclearedRenderbuffers() const {
143 return num_uncleared_renderbuffers_
!= 0;
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
,
173 GLenum
InternalRenderbufferFormatToImplFormat(GLenum impl_format
) const;
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_
;
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_
;
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
);
205 #endif // GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_