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 void AddToSignature(std::string
* signature
) const;
75 friend class RenderbufferManager
;
76 friend class base::RefCounted
<Renderbuffer
>;
80 void set_cleared(bool cleared
) {
85 GLsizei samples
, GLenum internalformat
, GLsizei width
, GLsizei height
) {
87 internal_format_
= internalformat
;
93 void MarkAsDeleted() {
97 // RenderbufferManager that owns this Renderbuffer.
98 RenderbufferManager
* manager_
;
100 // Client side renderbuffer id.
103 // Service side renderbuffer id.
106 // Whether this renderbuffer has been cleared
109 // Whether this renderbuffer has ever been bound.
110 bool has_been_bound_
;
112 // Number of samples (for multi-sampled renderbuffers)
115 // Renderbuffer internalformat set through RenderbufferStorage().
116 GLenum internal_format_
;
118 // Dimensions of renderbuffer.
123 // This class keeps track of the renderbuffers and whether or not they have
125 class GPU_EXPORT RenderbufferManager
{
127 RenderbufferManager(MemoryTracker
* memory_tracker
,
128 GLint max_renderbuffer_size
,
130 bool depth24_supported
);
131 ~RenderbufferManager();
133 GLint
max_renderbuffer_size() const {
134 return max_renderbuffer_size_
;
137 GLint
max_samples() const {
141 bool HaveUnclearedRenderbuffers() const {
142 return num_uncleared_renderbuffers_
!= 0;
146 Renderbuffer
* renderbuffer
,
147 GLsizei samples
, GLenum internalformat
, GLsizei width
, GLsizei height
);
149 void SetCleared(Renderbuffer
* renderbuffer
, bool cleared
);
151 // Must call before destruction.
152 void Destroy(bool have_context
);
154 // Creates a Renderbuffer for the given renderbuffer ids.
155 void CreateRenderbuffer(GLuint client_id
, GLuint service_id
);
157 // Gets the renderbuffer for the given renderbuffer id.
158 Renderbuffer
* GetRenderbuffer(GLuint client_id
);
160 // Removes a renderbuffer for the given renderbuffer id.
161 void RemoveRenderbuffer(GLuint client_id
);
163 size_t mem_represented() const {
164 return memory_tracker_
->GetMemRepresented();
167 bool ComputeEstimatedRenderbufferSize(int width
,
172 GLenum
InternalRenderbufferFormatToImplFormat(GLenum impl_format
) const;
175 friend class Renderbuffer
;
177 void StartTracking(Renderbuffer
* renderbuffer
);
178 void StopTracking(Renderbuffer
* renderbuffer
);
180 scoped_ptr
<MemoryTypeTracker
> memory_tracker_
;
182 GLint max_renderbuffer_size_
;
184 bool depth24_supported_
;
186 int num_uncleared_renderbuffers_
;
188 // Counts the number of Renderbuffer allocated with 'this' as its manager.
189 // Allows to check no Renderbuffer will outlive this.
190 unsigned renderbuffer_count_
;
194 // Info for each renderbuffer in the system.
195 typedef base::hash_map
<GLuint
, scoped_refptr
<Renderbuffer
> > RenderbufferMap
;
196 RenderbufferMap renderbuffers_
;
198 DISALLOW_COPY_AND_ASSIGN(RenderbufferManager
);
204 #endif // GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_