OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 10 #include "base/logging.h" |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "gpu/command_buffer/service/gl_utils.h" | 13 #include "gpu/command_buffer/service/gl_utils.h" |
14 | 14 |
15 namespace gpu { | 15 namespace gpu { |
16 namespace gles2 { | 16 namespace gles2 { |
17 | 17 |
18 // This class keeps track of the buffers and their sizes so we can do | 18 // This class keeps track of the buffers and their sizes so we can do |
19 // bounds checking. | 19 // bounds checking. |
20 // | 20 // |
21 // NOTE: To support shared resources an instance of this class will need to be | 21 // NOTE: To support shared resources an instance of this class will need to be |
22 // shared by multiple GLES2Decoders. | 22 // shared by multiple GLES2Decoders. |
23 class BufferManager { | 23 class BufferManager { |
24 public: | 24 public: |
25 // Info about Buffers currently in the system. | 25 // Info about Buffers currently in the system. |
26 class BufferInfo : public base::RefCounted<BufferInfo> { | 26 class BufferInfo : public base::RefCounted<BufferInfo> { |
27 public: | 27 public: |
28 typedef scoped_refptr<BufferInfo> Ref; | 28 typedef scoped_refptr<BufferInfo> Ref; |
29 | 29 |
30 explicit BufferInfo(GLuint buffer_id) | 30 explicit BufferInfo(GLuint service_id) |
31 : buffer_id_(buffer_id), | 31 : service_id_(service_id), |
32 target_(0), | 32 target_(0), |
33 size_(0) { | 33 size_(0) { |
34 } | 34 } |
35 | 35 |
36 GLuint buffer_id() const { | 36 GLuint service_id() const { |
37 return buffer_id_; | 37 return service_id_; |
38 } | 38 } |
39 | 39 |
40 GLenum target() const { | 40 GLenum target() const { |
41 return target_; | 41 return target_; |
42 } | 42 } |
43 | 43 |
44 void set_target(GLenum target) { | 44 void set_target(GLenum target) { |
45 DCHECK_EQ(target_, 0u); // you can only set this once. | 45 DCHECK_EQ(target_, 0u); // you can only set this once. |
46 target_ = target; | 46 target_ = target; |
47 } | 47 } |
(...skipping 10 matching lines...) Expand all Loading... |
58 GLintptr offset, GLsizeiptr size, const GLvoid * data); | 58 GLintptr offset, GLsizeiptr size, const GLvoid * data); |
59 | 59 |
60 // Gets the maximum value in the buffer for the given range interpreted as | 60 // Gets the maximum value in the buffer for the given range interpreted as |
61 // the given type. Returns false if offset and count are out of range. | 61 // the given type. Returns false if offset and count are out of range. |
62 // offset is in bytes. | 62 // offset is in bytes. |
63 // count is in elements of type. | 63 // count is in elements of type. |
64 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type, | 64 bool GetMaxValueForRange(GLuint offset, GLsizei count, GLenum type, |
65 GLuint* max_value); | 65 GLuint* max_value); |
66 | 66 |
67 bool IsDeleted() { | 67 bool IsDeleted() { |
68 return buffer_id_ == 0; | 68 return service_id_ == 0; |
69 } | 69 } |
70 | 70 |
71 private: | 71 private: |
72 friend class BufferManager; | 72 friend class BufferManager; |
73 friend class base::RefCounted<BufferInfo>; | 73 friend class base::RefCounted<BufferInfo>; |
74 | 74 |
75 // Represents a range in a buffer. | 75 // Represents a range in a buffer. |
76 class Range { | 76 class Range { |
77 public: | 77 public: |
78 Range(GLuint offset, GLsizei count, GLenum type) | 78 Range(GLuint offset, GLsizei count, GLenum type) |
(...skipping 17 matching lines...) Expand all Loading... |
96 | 96 |
97 private: | 97 private: |
98 GLuint offset_; | 98 GLuint offset_; |
99 GLsizei count_; | 99 GLsizei count_; |
100 GLenum type_; | 100 GLenum type_; |
101 }; | 101 }; |
102 | 102 |
103 ~BufferInfo() { } | 103 ~BufferInfo() { } |
104 | 104 |
105 void MarkAsDeleted() { | 105 void MarkAsDeleted() { |
106 buffer_id_ = 0; | 106 service_id_ = 0; |
107 shadow_.reset(); | 107 shadow_.reset(); |
108 ClearCache(); | 108 ClearCache(); |
109 } | 109 } |
110 | 110 |
111 // Clears any cache of index ranges. | 111 // Clears any cache of index ranges. |
112 void ClearCache(); | 112 void ClearCache(); |
113 | 113 |
114 // Service side buffer id. | 114 // Service side buffer id. |
115 GLuint buffer_id_; | 115 GLuint service_id_; |
116 | 116 |
117 // The type of buffer. 0 = unset, GL_BUFFER_ARRAY = vertex data, | 117 // The type of buffer. 0 = unset, GL_BUFFER_ARRAY = vertex data, |
118 // GL_ELEMENT_BUFFER_ARRAY = index data. | 118 // GL_ELEMENT_BUFFER_ARRAY = index data. |
119 // Once set a buffer can not be used for something else. | 119 // Once set a buffer can not be used for something else. |
120 GLenum target_; | 120 GLenum target_; |
121 | 121 |
122 // Size of buffer. | 122 // Size of buffer. |
123 GLsizeiptr size_; | 123 GLsizeiptr size_; |
124 | 124 |
125 // A copy of the data in the buffer. This data is only kept if the target | 125 // A copy of the data in the buffer. This data is only kept if the target |
126 // is GL_ELEMENT_BUFFER_ARRAY | 126 // is GL_ELEMENT_BUFFER_ARRAY |
127 scoped_array<int8> shadow_; | 127 scoped_array<int8> shadow_; |
128 | 128 |
129 // A map of ranges to the highest value in that range of a certain type. | 129 // A map of ranges to the highest value in that range of a certain type. |
130 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap; | 130 typedef std::map<Range, GLuint, Range::Less> RangeToMaxValueMap; |
131 RangeToMaxValueMap range_set_; | 131 RangeToMaxValueMap range_set_; |
132 }; | 132 }; |
133 | 133 |
134 BufferManager() { } | 134 BufferManager() { } |
135 | 135 |
136 // Creates a BufferInfo for the given buffer. | 136 // Creates a BufferInfo for the given buffer. |
137 void CreateBufferInfo(GLuint buffer_id); | 137 void CreateBufferInfo(GLuint client_id, GLuint service_id); |
138 | 138 |
139 // Gets the buffer info for the given buffer. | 139 // Gets the buffer info for the given buffer. |
140 BufferInfo* GetBufferInfo(GLuint buffer_id); | 140 BufferInfo* GetBufferInfo(GLuint client_id); |
141 | 141 |
142 // Removes a buffer info for the given buffer. | 142 // Removes a buffer info for the given buffer. |
143 void RemoveBufferInfo(GLuint buffer_id); | 143 void RemoveBufferInfo(GLuint client_id); |
144 | 144 |
145 private: | 145 private: |
146 // Info for each buffer in the system. | 146 // Info for each buffer in the system. |
147 // TODO(gman): Choose a faster container. | 147 // TODO(gman): Choose a faster container. |
148 typedef std::map<GLuint, BufferInfo::Ref> BufferInfoMap; | 148 typedef std::map<GLuint, BufferInfo::Ref> BufferInfoMap; |
149 BufferInfoMap buffer_infos_; | 149 BufferInfoMap buffer_infos_; |
150 | 150 |
151 DISALLOW_COPY_AND_ASSIGN(BufferManager); | 151 DISALLOW_COPY_AND_ASSIGN(BufferManager); |
152 }; | 152 }; |
153 | 153 |
154 } // namespace gles2 | 154 } // namespace gles2 |
155 } // namespace gpu | 155 } // namespace gpu |
156 | 156 |
157 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ | 157 #endif // GPU_COMMAND_BUFFER_SERVICE_BUFFER_MANAGER_H_ |
158 | 158 |
159 | 159 |
OLD | NEW |