Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / renderbuffer_manager.h
blobbe4cc0974e4d42e81343fda621ae73b45b09b03d
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 FeatureInfo;
21 class RenderbufferManager;
23 // Info about a Renderbuffer.
24 class GPU_EXPORT Renderbuffer
25 : public base::RefCounted<Renderbuffer> {
26 public:
27 Renderbuffer(RenderbufferManager* manager,
28 GLuint client_id,
29 GLuint service_id);
31 GLuint service_id() const {
32 return service_id_;
35 GLuint client_id() const {
36 return client_id_;
39 bool cleared() const {
40 return cleared_;
43 GLenum internal_format() const {
44 return internal_format_;
47 GLsizei samples() const {
48 return samples_;
51 GLsizei width() const {
52 return width_;
55 GLsizei height() const {
56 return height_;
59 bool IsDeleted() const {
60 return client_id_ == 0;
63 void MarkAsValid() {
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;
76 private:
77 friend class RenderbufferManager;
78 friend class base::RefCounted<Renderbuffer>;
80 ~Renderbuffer();
82 void set_cleared(bool cleared) {
83 cleared_ = cleared;
86 void SetInfo(
87 GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) {
88 samples_ = samples;
89 internal_format_ = internalformat;
90 width_ = width;
91 height_ = height;
92 cleared_ = false;
95 void MarkAsDeleted() {
96 client_id_ = 0;
99 // RenderbufferManager that owns this Renderbuffer.
100 RenderbufferManager* manager_;
102 // Client side renderbuffer id.
103 GLuint client_id_;
105 // Service side renderbuffer id.
106 GLuint service_id_;
108 // Whether this renderbuffer has been cleared
109 bool cleared_;
111 // Whether this renderbuffer has ever been bound.
112 bool has_been_bound_;
114 // Number of samples (for multi-sampled renderbuffers)
115 GLsizei samples_;
117 // Renderbuffer internalformat set through RenderbufferStorage().
118 GLenum internal_format_;
120 // Dimensions of renderbuffer.
121 GLsizei width_;
122 GLsizei height_;
125 // This class keeps track of the renderbuffers and whether or not they have
126 // been cleared.
127 class GPU_EXPORT RenderbufferManager {
128 public:
129 RenderbufferManager(MemoryTracker* memory_tracker,
130 GLint max_renderbuffer_size,
131 GLint max_samples,
132 FeatureInfo* feature_info);
133 ~RenderbufferManager();
135 GLint max_renderbuffer_size() const {
136 return max_renderbuffer_size_;
139 GLint max_samples() const {
140 return max_samples_;
143 bool HaveUnclearedRenderbuffers() const {
144 return num_uncleared_renderbuffers_ != 0;
147 void SetInfo(
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,
170 int height,
171 int samples,
172 int internal_format,
173 uint32* size) const;
174 GLenum InternalRenderbufferFormatToImplFormat(GLenum impl_format) const;
176 private:
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_;
185 GLint max_samples_;
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_;
195 bool have_context_;
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);
204 } // namespace gles2
205 } // namespace gpu
207 #endif // GPU_COMMAND_BUFFER_SERVICE_RENDERBUFFER_MANAGER_H_