OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ | 5 #ifndef CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ |
6 #define CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ | 6 #define CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/synchronization/lock.h" | |
15 #include "cc/base/scoped_ptr_hash_map.h" | 17 #include "cc/base/scoped_ptr_hash_map.h" |
16 #include "cc/debug/fake_web_graphics_context_3d.h" | 18 #include "cc/debug/fake_web_graphics_context_3d.h" |
17 #include "third_party/khronos/GLES2/gl2.h" | 19 #include "third_party/khronos/GLES2/gl2.h" |
18 | 20 |
19 namespace WebKit { struct WebGraphicsMemoryAllocation; } | 21 namespace WebKit { struct WebGraphicsMemoryAllocation; } |
20 | 22 |
21 namespace cc { | 23 namespace cc { |
22 | 24 |
23 class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D { | 25 class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D { |
24 public: | 26 public: |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 | 163 |
162 // When set, mapImageCHROMIUM and mapBufferCHROMIUM will return NULL after | 164 // When set, mapImageCHROMIUM and mapBufferCHROMIUM will return NULL after |
163 // this many times. | 165 // this many times. |
164 void set_times_map_image_chromium_succeeds(int times) { | 166 void set_times_map_image_chromium_succeeds(int times) { |
165 times_map_image_chromium_succeeds_ = times; | 167 times_map_image_chromium_succeeds_ = times; |
166 } | 168 } |
167 void set_times_map_buffer_chromium_succeeds(int times) { | 169 void set_times_map_buffer_chromium_succeeds(int times) { |
168 times_map_buffer_chromium_succeeds_ = times; | 170 times_map_buffer_chromium_succeeds_ = times; |
169 } | 171 } |
170 | 172 |
171 size_t NumTextures() const { return textures_.size(); } | 173 size_t NumTextures() const; |
172 WebKit::WebGLId TextureAt(int i) const { return textures_[i]; } | 174 WebKit::WebGLId TextureAt(int i) const; |
173 | 175 |
174 size_t NumUsedTextures() const { return used_textures_.size(); } | 176 size_t NumUsedTextures() const { return used_textures_.size(); } |
175 bool UsedTexture(int texture) const { | 177 bool UsedTexture(int texture) const { |
176 return ContainsKey(used_textures_, texture); | 178 return ContainsKey(used_textures_, texture); |
177 } | 179 } |
178 void ResetUsedTextures() { used_textures_.clear(); } | 180 void ResetUsedTextures() { used_textures_.clear(); } |
179 | 181 |
180 void set_support_swapbuffers_complete_callback(bool support) { | 182 void set_support_swapbuffers_complete_callback(bool support) { |
181 support_swapbuffers_complete_callback_ = support; | 183 support_swapbuffers_complete_callback_ = support; |
182 } | 184 } |
(...skipping 14 matching lines...) Expand all Loading... | |
197 static const WebKit::WebGLId kExternalTextureId; | 199 static const WebKit::WebGLId kExternalTextureId; |
198 virtual WebKit::WebGLId NextTextureId(); | 200 virtual WebKit::WebGLId NextTextureId(); |
199 | 201 |
200 virtual WebKit::WebGLId NextBufferId(); | 202 virtual WebKit::WebGLId NextBufferId(); |
201 | 203 |
202 virtual WebKit::WebGLId NextImageId(); | 204 virtual WebKit::WebGLId NextImageId(); |
203 | 205 |
204 void SetMemoryAllocation(WebKit::WebGraphicsMemoryAllocation allocation); | 206 void SetMemoryAllocation(WebKit::WebGraphicsMemoryAllocation allocation); |
205 | 207 |
206 protected: | 208 protected: |
209 struct Buffer { | |
210 Buffer(); | |
211 ~Buffer(); | |
212 | |
213 WebKit::WGC3Denum target; | |
214 scoped_ptr<uint8[]> pixels; | |
215 | |
216 private: | |
217 DISALLOW_COPY_AND_ASSIGN(Buffer); | |
218 }; | |
219 | |
220 struct Image { | |
221 Image(); | |
222 ~Image(); | |
223 | |
224 scoped_ptr<uint8[]> pixels; | |
225 | |
226 private: | |
227 DISALLOW_COPY_AND_ASSIGN(Image); | |
228 }; | |
229 | |
230 struct Namespace : public base::RefCountedThreadSafe<Namespace> { | |
231 Namespace(); | |
232 | |
233 // Protects all fields; | |
danakj
2013/07/16 03:26:11
nit: s/;/./
piman
2013/07/16 04:50:55
Done.
| |
234 base::Lock lock; | |
235 unsigned next_buffer_id; | |
236 unsigned next_image_id; | |
237 unsigned next_texture_id; | |
238 std::vector<WebKit::WebGLId> textures; | |
239 ScopedPtrHashMap<unsigned, Buffer> buffers; | |
240 ScopedPtrHashMap<unsigned, Image> images; | |
241 | |
242 private: | |
243 friend class base::RefCountedThreadSafe<Namespace>; | |
244 ~Namespace(); | |
245 DISALLOW_COPY_AND_ASSIGN(Namespace); | |
246 }; | |
247 | |
207 TestWebGraphicsContext3D(); | 248 TestWebGraphicsContext3D(); |
208 TestWebGraphicsContext3D( | 249 TestWebGraphicsContext3D( |
209 const WebKit::WebGraphicsContext3D::Attributes& attributes); | 250 const WebKit::WebGraphicsContext3D::Attributes& attributes); |
210 | 251 |
211 void CallAllSyncPointCallbacks(); | 252 void CallAllSyncPointCallbacks(); |
212 void SwapBuffersComplete(); | 253 void SwapBuffersComplete(); |
213 | 254 |
214 unsigned context_id_; | 255 unsigned context_id_; |
215 unsigned next_buffer_id_; | |
216 unsigned next_image_id_; | |
217 unsigned next_texture_id_; | |
218 Attributes attributes_; | 256 Attributes attributes_; |
219 bool support_swapbuffers_complete_callback_; | 257 bool support_swapbuffers_complete_callback_; |
220 bool have_extension_io_surface_; | 258 bool have_extension_io_surface_; |
221 bool have_extension_egl_image_; | 259 bool have_extension_egl_image_; |
222 int times_make_current_succeeds_; | 260 int times_make_current_succeeds_; |
223 int times_bind_texture_succeeds_; | 261 int times_bind_texture_succeeds_; |
224 int times_end_query_succeeds_; | 262 int times_end_query_succeeds_; |
225 bool context_lost_; | 263 bool context_lost_; |
226 int times_map_image_chromium_succeeds_; | 264 int times_map_image_chromium_succeeds_; |
227 int times_map_buffer_chromium_succeeds_; | 265 int times_map_buffer_chromium_succeeds_; |
228 WebGraphicsContextLostCallback* context_lost_callback_; | 266 WebGraphicsContextLostCallback* context_lost_callback_; |
229 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_; | 267 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_; |
230 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* | 268 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* |
231 memory_allocation_changed_callback_; | 269 memory_allocation_changed_callback_; |
232 std::vector<WebGraphicsSyncPointCallback*> sync_point_callbacks_; | 270 std::vector<WebGraphicsSyncPointCallback*> sync_point_callbacks_; |
233 std::vector<WebKit::WebGLId> textures_; | |
234 base::hash_set<WebKit::WebGLId> used_textures_; | 271 base::hash_set<WebKit::WebGLId> used_textures_; |
235 std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_; | 272 std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_; |
236 int max_texture_size_; | 273 int max_texture_size_; |
237 int width_; | 274 int width_; |
238 int height_; | 275 int height_; |
239 | 276 |
240 struct Buffer { | 277 unsigned bound_buffer_; |
241 Buffer(); | |
242 ~Buffer(); | |
243 | 278 |
244 WebKit::WGC3Denum target; | 279 scoped_refptr<Namespace> namespace_; |
245 scoped_ptr<uint8[]> pixels; | 280 static Namespace* shared_namespace_; |
246 | 281 |
247 private: | |
248 DISALLOW_COPY_AND_ASSIGN(Buffer); | |
249 }; | |
250 ScopedPtrHashMap<unsigned, Buffer> buffers_; | |
251 unsigned bound_buffer_; | |
252 struct Image { | |
253 Image(); | |
254 ~Image(); | |
255 | |
256 scoped_ptr<uint8[]> pixels; | |
257 | |
258 private: | |
259 DISALLOW_COPY_AND_ASSIGN(Image); | |
260 }; | |
261 ScopedPtrHashMap<unsigned, Image> images_; | |
262 base::WeakPtrFactory<TestWebGraphicsContext3D> weak_ptr_factory_; | 282 base::WeakPtrFactory<TestWebGraphicsContext3D> weak_ptr_factory_; |
263 }; | 283 }; |
264 | 284 |
265 } // namespace cc | 285 } // namespace cc |
266 | 286 |
267 #endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ | 287 #endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ |
OLD | NEW |