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

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

Issue 12494005: Use client side arrays for GL_STREAM_DRAW attributes (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;
22 24
23 // Info about Buffers currently in the system. 25 // Info about Buffers currently in the system.
24 class GPU_EXPORT Buffer : public base::RefCounted<Buffer> { 26 class GPU_EXPORT Buffer : public base::RefCounted<Buffer> {
25 public: 27 public:
26 Buffer(BufferManager* manager, GLuint service_id); 28 Buffer(BufferManager* manager, GLuint service_id);
27 29
28 GLuint service_id() const { 30 GLuint service_id() const {
29 return service_id_; 31 return service_id_;
30 } 32 }
31 33
34 GLenum target() const {
35 return target_;
36 }
37
32 GLsizeiptr size() const { 38 GLsizeiptr size() const {
33 return size_; 39 return size_;
34 } 40 }
35 41
36 GLenum usage() const { 42 GLenum usage() const {
37 return usage_; 43 return usage_;
38 } 44 }
39 45
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
45 // Gets the maximum value in the buffer for the given range interpreted as 46 // Gets the maximum value in the buffer for the given range interpreted as
46 // the given type. Returns false if offset and count are out of range. 47 // the given type. Returns false if offset and count are out of range.
47 // offset is in bytes. 48 // offset is in bytes.
48 // count is in elements of type. 49 // count is in elements of type.
49 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type, 50 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type,
50 GLuint* max_value); 51 GLuint* max_value);
51 52
52 // Returns a pointer to shadowed data. 53 // Returns a pointer to shadowed data.
53 const void* GetRange(GLintptr offset, GLsizeiptr size) const; 54 const void* GetRange(GLintptr offset, GLsizeiptr size) const;
54 55
55 bool IsDeleted() const { 56 bool IsDeleted() const {
56 return deleted_; 57 return deleted_;
57 } 58 }
58 59
59 bool IsValid() const { 60 bool IsValid() const {
60 return target() && !IsDeleted(); 61 return target() && !IsDeleted();
61 } 62 }
62 63
64 bool IsClientSideArray() const {
65 return is_client_side_array_;
66 }
67
63 private: 68 private:
64 friend class BufferManager; 69 friend class BufferManager;
65 friend class BufferManagerTestBase; 70 friend class BufferManagerTestBase;
66 friend class base::RefCounted<Buffer>; 71 friend class base::RefCounted<Buffer>;
67 72
68 // Represents a range in a buffer. 73 // Represents a range in a buffer.
69 class Range { 74 class Range {
70 public: 75 public:
71 Range(GLuint offset, GLsizei count, GLenum type) 76 Range(GLuint offset, GLsizei count, GLenum type)
72 : offset_(offset), 77 : offset_(offset),
(...skipping 15 matching lines...) Expand all
88 }; 93 };
89 94
90 private: 95 private:
91 GLuint offset_; 96 GLuint offset_;
92 GLsizei count_; 97 GLsizei count_;
93 GLenum type_; 98 GLenum type_;
94 }; 99 };
95 100
96 ~Buffer(); 101 ~Buffer();
97 102
98 GLenum target() const {
99 return target_;
100 }
101
102 void set_target(GLenum target) { 103 void set_target(GLenum target) {
103 DCHECK_EQ(target_, 0u); // you can only set this once. 104 DCHECK_EQ(target_, 0u); // you can only set this once.
104 target_ = target; 105 target_ = target;
105 } 106 }
106 107
107 bool shadowed() const { 108 bool shadowed() const {
108 return shadowed_; 109 return shadowed_;
109 } 110 }
110 111
111 void MarkAsDeleted() { 112 void MarkAsDeleted() {
112 deleted_ = true; 113 deleted_ = true;
113 } 114 }
114 115
115 void SetInfo(GLsizeiptr size, GLenum usage, bool shadow); 116 // Sets the size, usage and initial data of a buffer.
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);
116 126
117 // Clears any cache of index ranges. 127 // Clears any cache of index ranges.
118 void ClearCache(); 128 void ClearCache();
119 129
120 // Check if an offset, size range is valid for the current buffer. 130 // Check if an offset, size range is valid for the current buffer.
121 bool CheckRange(GLintptr offset, GLsizeiptr size) const; 131 bool CheckRange(GLintptr offset, GLsizeiptr size) const;
122 132
123 // The manager that owns this Buffer. 133 // The manager that owns this Buffer.
124 BufferManager* manager_; 134 BufferManager* manager_;
125 135
(...skipping 10 matching lines...) Expand all
136 146
137 // Size of buffer. 147 // Size of buffer.
138 GLsizeiptr size_; 148 GLsizeiptr size_;
139 149
140 // Usage of buffer. 150 // Usage of buffer.
141 GLenum usage_; 151 GLenum usage_;
142 152
143 // Whether or not the data is shadowed. 153 // Whether or not the data is shadowed.
144 bool shadowed_; 154 bool shadowed_;
145 155
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
146 // A copy of the data in the buffer. This data is only kept if the target 160 // A copy of the data in the buffer. This data is only kept if the target
147 // is backed_ = true. 161 // is backed_ = true.
148 scoped_array<int8> shadow_; 162 scoped_array<int8> shadow_;
149 163
150 // A map of ranges to the highest value in that range of a certain type. 164 // A map of ranges to the highest value in that range of a certain type.
151 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap; 165 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap;
152 RangeToMaxValueMap range_set_; 166 RangeToMaxValueMap range_set_;
153 }; 167 };
154 168
155 // This class keeps track of the buffers and their sizes so we can do 169 // This class keeps track of the buffers and their sizes so we can do
156 // bounds checking. 170 // bounds checking.
157 // 171 //
158 // NOTE: To support shared resources an instance of this class will need to be 172 // NOTE: To support shared resources an instance of this class will need to be
159 // shared by multiple GLES2Decoders. 173 // shared by multiple GLES2Decoders.
160 class GPU_EXPORT BufferManager { 174 class GPU_EXPORT BufferManager {
161 public: 175 public:
162 BufferManager(MemoryTracker* memory_tracker); 176 BufferManager(MemoryTracker* memory_tracker, FeatureInfo* feature_info);
163 ~BufferManager(); 177 ~BufferManager();
164 178
165 // Must call before destruction. 179 // Must call before destruction.
166 void Destroy(bool have_context); 180 void Destroy(bool have_context);
167 181
168 // Creates a Buffer for the given buffer. 182 // Creates a Buffer for the given buffer.
169 void CreateBuffer(GLuint client_id, GLuint service_id); 183 void CreateBuffer(GLuint client_id, GLuint service_id);
170 184
171 // Gets the buffer info for the given buffer. 185 // Gets the buffer info for the given buffer.
172 Buffer* GetBuffer(GLuint client_id); 186 Buffer* GetBuffer(GLuint client_id);
173 187
174 // Removes a buffer info for the given buffer. 188 // Removes a buffer info for the given buffer.
175 void RemoveBuffer(GLuint client_id); 189 void RemoveBuffer(GLuint client_id);
176 190
177 // Gets a client id for a given service id. 191 // Gets a client id for a given service id.
178 bool GetClientId(GLuint service_id, GLuint* client_id) const; 192 bool GetClientId(GLuint service_id, GLuint* client_id) const;
179 193
180 // Sets the size and usage of a buffer. 194 // Does a glBufferData and updates the approprate accounting. Currently
181 void SetInfo(Buffer* info, GLsizeiptr size, GLenum usage); 195 // assume the values have already been validated.
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);
182 210
183 // Sets the target of a buffer. Returns false if the target can not be set. 211 // Sets the target of a buffer. Returns false if the target can not be set.
184 bool SetTarget(Buffer* info, GLenum target); 212 bool SetTarget(Buffer* info, GLenum target);
185 213
186 void set_allow_buffers_on_multiple_targets(bool allow) { 214 void set_allow_buffers_on_multiple_targets(bool allow) {
187 allow_buffers_on_multiple_targets_ = allow; 215 allow_buffers_on_multiple_targets_ = allow;
188 } 216 }
189 217
190 size_t mem_represented() const { 218 size_t mem_represented() const {
191 return memory_tracker_->GetMemRepresented(); 219 return memory_tracker_->GetMemRepresented();
192 } 220 }
193 221
222 // Tell's for a given usage if this would be a client side array.
223 bool IsUsageClientSideArray(GLenum usage);
224
194 private: 225 private:
195 friend class Buffer; 226 friend class Buffer;
196 void StartTracking(Buffer* info); 227 void StartTracking(Buffer* info);
197 void StopTracking(Buffer* info); 228 void StopTracking(Buffer* info);
198 229
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
199 scoped_ptr<MemoryTypeTracker> memory_tracker_; 234 scoped_ptr<MemoryTypeTracker> memory_tracker_;
235 scoped_refptr<FeatureInfo> feature_info_;
200 236
201 // Info for each buffer in the system. 237 // Info for each buffer in the system.
202 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferInfoMap; 238 typedef base::hash_map<GLuint, scoped_refptr<Buffer> > BufferInfoMap;
203 BufferInfoMap buffer_infos_; 239 BufferInfoMap buffer_infos_;
204 240
205 // Whether or not buffers can be bound to multiple targets. 241 // Whether or not buffers can be bound to multiple targets.
206 bool allow_buffers_on_multiple_targets_; 242 bool allow_buffers_on_multiple_targets_;
207 243
208 // Counts the number of Buffer allocated with 'this' as its manager. 244 // Counts the number of Buffer allocated with 'this' as its manager.
209 // Allows to check no Buffer will outlive this. 245 // Allows to check no Buffer will outlive this.
210 unsigned int buffer_info_count_; 246 unsigned int buffer_info_count_;
211 247
212 bool have_context_; 248 bool have_context_;
249 bool use_client_side_arrays_for_stream_buffers_;
213 250
214 DISALLOW_COPY_AND_ASSIGN(BufferManager); 251 DISALLOW_COPY_AND_ASSIGN(BufferManager);
215 }; 252 };
216 253
217 } // namespace gles2 254 } // namespace gles2
218 } // namespace gpu 255 } // namespace gpu
219 256
220 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ 257 #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