Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: gpu/command_buffer/service/buffer_manager.h

Issue 12544006: Revert 186416 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "gpu/command_buffer/service/gl_utils.h" 14 #include "gpu/command_buffer/service/gl_utils.h"
15 #include "gpu/command_buffer/service/memory_tracking.h" 15 #include "gpu/command_buffer/service/memory_tracking.h"
16 #include "gpu/gpu_export.h" 16 #include "gpu/gpu_export.h"
17 17
18 namespace gpu { 18 namespace gpu {
19 namespace gles2 { 19 namespace gles2 {
20 20
21 class BufferManager; 21 class BufferManager;
22 class FeatureInfo;
23 class GLES2Decoder;
24 22
25 // Info about Buffers currently in the system. 23 // Info about Buffers currently in the system.
26 class GPU_EXPORT Buffer : public base::RefCounted<Buffer> { 24 class GPU_EXPORT Buffer : public base::RefCounted<Buffer> {
27 public: 25 public:
28 Buffer(BufferManager* manager, GLuint service_id); 26 Buffer(BufferManager* manager, GLuint service_id);
29 27
30 GLuint service_id() const { 28 GLuint service_id() const {
31 return service_id_; 29 return service_id_;
32 } 30 }
33 31
34 GLenum target() const {
35 return target_;
36 }
37
38 GLsizeiptr size() const { 32 GLsizeiptr size() const {
39 return size_; 33 return size_;
40 } 34 }
41 35
42 GLenum usage() const { 36 GLenum usage() const {
43 return usage_; 37 return usage_;
44 } 38 }
45 39
40 // Sets a range of data for this buffer. Returns false if the offset or size
41 // is out of range.
42 bool SetRange(
43 GLintptr offset, GLsizeiptr size, const GLvoid * data);
44
46 // Gets the maximum value in the buffer for the given range interpreted as 45 // Gets the maximum value in the buffer for the given range interpreted as
47 // the given type. Returns false if offset and count are out of range. 46 // the given type. Returns false if offset and count are out of range.
48 // offset is in bytes. 47 // offset is in bytes.
49 // count is in elements of type. 48 // count is in elements of type.
50 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type, 49 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type,
51 GLuint* max_value); 50 GLuint* max_value);
52 51
53 // Returns a pointer to shadowed data. 52 // Returns a pointer to shadowed data.
54 const void* GetRange(GLintptr offset, GLsizeiptr size) const; 53 const void* GetRange(GLintptr offset, GLsizeiptr size) const;
55 54
56 bool IsDeleted() const { 55 bool IsDeleted() const {
57 return deleted_; 56 return deleted_;
58 } 57 }
59 58
60 bool IsValid() const { 59 bool IsValid() const {
61 return target() && !IsDeleted(); 60 return target() && !IsDeleted();
62 } 61 }
63 62
64 bool IsClientSideArray() const {
65 return is_client_side_array_;
66 }
67
68 private: 63 private:
69 friend class BufferManager; 64 friend class BufferManager;
70 friend class BufferManagerTestBase; 65 friend class BufferManagerTestBase;
71 friend class base::RefCounted<Buffer>; 66 friend class base::RefCounted<Buffer>;
72 67
73 // Represents a range in a buffer. 68 // Represents a range in a buffer.
74 class Range { 69 class Range {
75 public: 70 public:
76 Range(GLuint offset, GLsizei count, GLenum type) 71 Range(GLuint offset, GLsizei count, GLenum type)
77 : offset_(offset), 72 : offset_(offset),
(...skipping 15 matching lines...) Expand all
93 }; 88 };
94 89
95 private: 90 private:
96 GLuint offset_; 91 GLuint offset_;
97 GLsizei count_; 92 GLsizei count_;
98 GLenum type_; 93 GLenum type_;
99 }; 94 };
100 95
101 ~Buffer(); 96 ~Buffer();
102 97
98 GLenum target() const {
99 return target_;
100 }
101
103 void set_target(GLenum target) { 102 void set_target(GLenum target) {
104 DCHECK_EQ(target_, 0u); // you can only set this once. 103 DCHECK_EQ(target_, 0u); // you can only set this once.
105 target_ = target; 104 target_ = target;
106 } 105 }
107 106
108 bool shadowed() const { 107 bool shadowed() const {
109 return shadowed_; 108 return shadowed_;
110 } 109 }
111 110
112 void MarkAsDeleted() { 111 void MarkAsDeleted() {
113 deleted_ = true; 112 deleted_ = true;
114 } 113 }
115 114
116 // Sets the size, usage and initial data of a buffer. 115 void SetInfo(GLsizeiptr size, GLenum usage, bool shadow);
117 // If shadow is true then if data is NULL buffer will be initialized to 0.
118 void SetInfo(
119 GLsizeiptr size, GLenum usage, bool shadow, const GLvoid* data,
120 bool is_client_side_array);
121
122 // Sets a range of data for this buffer. Returns false if the offset or size
123 // is out of range.
124 bool SetRange(
125 GLintptr offset, GLsizeiptr size, const GLvoid * data);
126 116
127 // Clears any cache of index ranges. 117 // Clears any cache of index ranges.
128 void ClearCache(); 118 void ClearCache();
129 119
130 // Check if an offset, size range is valid for the current buffer. 120 // Check if an offset, size range is valid for the current buffer.
131 bool CheckRange(GLintptr offset, GLsizeiptr size) const; 121 bool CheckRange(GLintptr offset, GLsizeiptr size) const;
132 122
133 // The manager that owns this Buffer. 123 // The manager that owns this Buffer.
134 BufferManager* manager_; 124 BufferManager* manager_;
135 125
(...skipping 10 matching lines...) Expand all
146 136
147 // Size of buffer. 137 // Size of buffer.
148 GLsizeiptr size_; 138 GLsizeiptr size_;
149 139
150 // Usage of buffer. 140 // Usage of buffer.
151 GLenum usage_; 141 GLenum usage_;
152 142
153 // Whether or not the data is shadowed. 143 // Whether or not the data is shadowed.
154 bool shadowed_; 144 bool shadowed_;
155 145
156 // Whether or not this Buffer is not uploaded to the GPU but just
157 // sitting in local memory.
158 bool is_client_side_array_;
159
160 // A copy of the data in the buffer. This data is only kept if the target 146 // A copy of the data in the buffer. This data is only kept if the target
161 // is backed_ = true. 147 // is backed_ = true.
162 scoped_array<int8> shadow_; 148 scoped_array<int8> shadow_;
163 149
164 // A map of ranges to the highest value in that range of a certain type. 150 // A map of ranges to the highest value in that range of a certain type.
165 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap; 151 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap;
166 RangeToMaxValueMap range_set_; 152 RangeToMaxValueMap range_set_;
167 }; 153 };
168 154
169 // This class keeps track of the buffers and their sizes so we can do 155 // This class keeps track of the buffers and their sizes so we can do
170 // bounds checking. 156 // bounds checking.
171 // 157 //
172 // NOTE: To support shared resources an instance of this class will need to be 158 // NOTE: To support shared resources an instance of this class will need to be
173 // shared by multiple GLES2Decoders. 159 // shared by multiple GLES2Decoders.
174 class GPU_EXPORT BufferManager { 160 class GPU_EXPORT BufferManager {
175 public: 161 public:
176 BufferManager(MemoryTracker* memory_tracker, FeatureInfo* feature_info); 162 BufferManager(MemoryTracker* memory_tracker);
177 ~BufferManager(); 163 ~BufferManager();
178 164
179 // Must call before destruction. 165 // Must call before destruction.
180 void Destroy(bool have_context); 166 void Destroy(bool have_context);
181 167
182 // Creates a Buffer for the given buffer. 168 // Creates a Buffer for the given buffer.
183 void CreateBuffer(GLuint client_id, GLuint service_id); 169 void CreateBuffer(GLuint client_id, GLuint service_id);
184 170
185 // Gets the buffer info for the given buffer. 171 // Gets the buffer info for the given buffer.
186 Buffer* GetBuffer(GLuint client_id); 172 Buffer* GetBuffer(GLuint client_id);
187 173
188 // Removes a buffer info for the given buffer. 174 // Removes a buffer info for the given buffer.
189 void RemoveBuffer(GLuint client_id); 175 void RemoveBuffer(GLuint client_id);
190 176
191 // Gets a client id for a given service id. 177 // Gets a client id for a given service id.
192 bool GetClientId(GLuint service_id, GLuint* client_id) const; 178 bool GetClientId(GLuint service_id, GLuint* client_id) const;
193 179
194 // Does a glBufferData and updates the approprate accounting. Currently 180 // Sets the size and usage of a buffer.
195 // assume the values have already been validated. 181 void SetInfo(Buffer* info, GLsizeiptr size, GLenum usage);
196 void DoBufferData(
197 GLES2Decoder* decoder,
198 Buffer* buffer,
199 GLsizeiptr size,
200 GLenum usage,
201 const GLvoid* data);
202
203 // Does a glBufferSubData and updates the approrate accounting.
204 void DoBufferSubData(
205 GLES2Decoder* decoder,
206 Buffer* buffer,
207 GLintptr offset,
208 GLsizeiptr size,
209 const GLvoid* data);
210 182
211 // Sets the target of a buffer. Returns false if the target can not be set. 183 // Sets the target of a buffer. Returns false if the target can not be set.
212 bool SetTarget(Buffer* info, GLenum target); 184 bool SetTarget(Buffer* info, GLenum target);
213 185
214 void set_allow_buffers_on_multiple_targets(bool allow) { 186 void set_allow_buffers_on_multiple_targets(bool allow) {
215 allow_buffers_on_multiple_targets_ = allow; 187 allow_buffers_on_multiple_targets_ = allow;
216 } 188 }
217 189
218 size_t mem_represented() const { 190 size_t mem_represented() const {
219 return memory_tracker_->GetMemRepresented(); 191 return memory_tracker_->GetMemRepresented();
220 } 192 }
221 193
222 // Tell's for a given usage if this would be a client side array.
223 bool IsUsageClientSideArray(GLenum usage);
224
225 private: 194 private:
226 friend class Buffer; 195 friend class Buffer;
227 void StartTracking(Buffer* info); 196 void StartTracking(Buffer* info);
228 void StopTracking(Buffer* info); 197 void StopTracking(Buffer* info);
229 198
230 // Sets the size, usage and initial data of a buffer.
231 // If data is NULL buffer will be initialized to 0 if shadowed.
232 void SetInfo(Buffer* info, GLsizeiptr size, GLenum usage, const GLvoid* data);
233
234 scoped_ptr<MemoryTypeTracker> memory_tracker_; 199 scoped_ptr<MemoryTypeTracker> memory_tracker_;
235 scoped_refptr<FeatureInfo> feature_info_;
236 200
237 // Info for each buffer in the system. 201 // Info for each buffer in the system.
238 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferInfoMap; 202 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferInfoMap;
239 BufferInfoMap buffer_infos_; 203 BufferInfoMap buffer_infos_;
240 204
241 // Whether or not buffers can be bound to multiple targets. 205 // Whether or not buffers can be bound to multiple targets.
242 bool allow_buffers_on_multiple_targets_; 206 bool allow_buffers_on_multiple_targets_;
243 207
244 // Counts the number of Buffer allocated with 'this' as its manager. 208 // Counts the number of Buffer allocated with 'this' as its manager.
245 // Allows to check no Buffer will outlive this. 209 // Allows to check no Buffer will outlive this.
246 unsigned int buffer_info_count_; 210 unsigned int buffer_info_count_;
247 211
248 bool have_context_; 212 bool have_context_;
249 bool use_client_side_arrays_for_stream_buffers_;
250 213
251 DISALLOW_COPY_AND_ASSIGN(BufferManager); 214 DISALLOW_COPY_AND_ASSIGN(BufferManager);
252 }; 215 };
253 216
254 } // namespace gles2 217 } // namespace gles2
255 } // namespace gpu 218 } // namespace gpu
256 219
257 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ 220 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h ('k') | gpu/command_buffer/service/buffer_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698