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
128 : public base::trace_event::MemoryDumpProvider
{
130 RenderbufferManager(MemoryTracker
* memory_tracker
,
131 GLint max_renderbuffer_size
,
133 FeatureInfo
* feature_info
);
134 ~RenderbufferManager() override
;
136 GLint
max_renderbuffer_size() const {
137 return max_renderbuffer_size_
;
140 GLint
max_samples() const {
144 bool HaveUnclearedRenderbuffers() const {
145 return num_uncleared_renderbuffers_
!= 0;
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
,
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
;
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_
;
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_
;
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
);
213 #endif // GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_