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"
21 class RenderbufferManager
;
23 // Info about a Renderbuffer.
24 class GPU_EXPORT Renderbuffer
25 : public base::RefCounted
<Renderbuffer
> {
27 Renderbuffer(RenderbufferManager
* manager
,
31 GLuint
service_id() const {
35 GLuint
client_id() const {
39 bool cleared() const {
43 GLenum
internal_format() const {
44 return internal_format_
;
47 GLsizei
samples() const {
51 GLsizei
width() const {
55 GLsizei
height() const {
59 bool IsDeleted() const {
60 return client_id_
== 0;
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;
77 friend class RenderbufferManager
;
78 friend class base::RefCounted
<Renderbuffer
>;
82 void set_cleared(bool cleared
) {
87 GLsizei samples
, GLenum internalformat
, GLsizei width
, GLsizei height
) {
89 internal_format_
= internalformat
;
95 void MarkAsDeleted() {
99 // RenderbufferManager that owns this Renderbuffer.
100 RenderbufferManager
* manager_
;
102 // Client side renderbuffer id.
105 // Service side renderbuffer id.
108 // Whether this renderbuffer has been cleared
111 // Whether this renderbuffer has ever been bound.
112 bool has_been_bound_
;
114 // Number of samples (for multi-sampled renderbuffers)
117 // Renderbuffer internalformat set through RenderbufferStorage().
118 GLenum internal_format_
;
120 // Dimensions of renderbuffer.
125 // This class keeps track of the renderbuffers and whether or not they have
127 class GPU_EXPORT RenderbufferManager
{
129 RenderbufferManager(MemoryTracker
* memory_tracker
,
130 GLint max_renderbuffer_size
,
132 FeatureInfo
* feature_info
);
133 ~RenderbufferManager();
135 GLint
max_renderbuffer_size() const {
136 return max_renderbuffer_size_
;
139 GLint
max_samples() const {
143 bool HaveUnclearedRenderbuffers() const {
144 return num_uncleared_renderbuffers_
!= 0;
148 Renderbuffer
* renderbuffer
,
149 GLsizei samples
, GLenum internalformat
, GLsizei width
, GLsizei height
);
151 void SetCleared(Renderbuffer
* renderbuffer
, bool cleared
);
153 // Must call before destruction.
154 void Destroy(bool have_context
);
156 // Creates a Renderbuffer for the given renderbuffer ids.
157 void CreateRenderbuffer(GLuint client_id
, GLuint service_id
);
159 // Gets the renderbuffer for the given renderbuffer id.
160 Renderbuffer
* GetRenderbuffer(GLuint client_id
);
162 // Removes a renderbuffer for the given renderbuffer id.
163 void RemoveRenderbuffer(GLuint client_id
);
165 size_t mem_represented() const {
166 return memory_tracker_
->GetMemRepresented();
169 bool ComputeEstimatedRenderbufferSize(int width
,
174 GLenum
InternalRenderbufferFormatToImplFormat(GLenum impl_format
) const;
177 friend class Renderbuffer
;
179 void StartTracking(Renderbuffer
* renderbuffer
);
180 void StopTracking(Renderbuffer
* renderbuffer
);
182 scoped_ptr
<MemoryTypeTracker
> memory_tracker_
;
184 GLint max_renderbuffer_size_
;
187 scoped_refptr
<FeatureInfo
> feature_info_
;
189 int num_uncleared_renderbuffers_
;
191 // Counts the number of Renderbuffer allocated with 'this' as its manager.
192 // Allows to check no Renderbuffer will outlive this.
193 unsigned renderbuffer_count_
;
197 // Info for each renderbuffer in the system.
198 typedef base::hash_map
<GLuint
, scoped_refptr
<Renderbuffer
> > RenderbufferMap
;
199 RenderbufferMap renderbuffers_
;
201 DISALLOW_COPY_AND_ASSIGN(RenderbufferManager
);
207 #endif // GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_