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. |
| 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(); |
| 254 void CreateNamespace(); |
213 | 255 |
214 unsigned context_id_; | 256 unsigned context_id_; |
215 unsigned next_buffer_id_; | |
216 unsigned next_image_id_; | |
217 unsigned next_texture_id_; | |
218 Attributes attributes_; | 257 Attributes attributes_; |
219 bool support_swapbuffers_complete_callback_; | 258 bool support_swapbuffers_complete_callback_; |
220 bool have_extension_io_surface_; | 259 bool have_extension_io_surface_; |
221 bool have_extension_egl_image_; | 260 bool have_extension_egl_image_; |
222 int times_make_current_succeeds_; | 261 int times_make_current_succeeds_; |
223 int times_bind_texture_succeeds_; | 262 int times_bind_texture_succeeds_; |
224 int times_end_query_succeeds_; | 263 int times_end_query_succeeds_; |
225 bool context_lost_; | 264 bool context_lost_; |
226 int times_map_image_chromium_succeeds_; | 265 int times_map_image_chromium_succeeds_; |
227 int times_map_buffer_chromium_succeeds_; | 266 int times_map_buffer_chromium_succeeds_; |
228 WebGraphicsContextLostCallback* context_lost_callback_; | 267 WebGraphicsContextLostCallback* context_lost_callback_; |
229 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_; | 268 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_; |
230 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* | 269 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* |
231 memory_allocation_changed_callback_; | 270 memory_allocation_changed_callback_; |
232 std::vector<WebGraphicsSyncPointCallback*> sync_point_callbacks_; | 271 std::vector<WebGraphicsSyncPointCallback*> sync_point_callbacks_; |
233 std::vector<WebKit::WebGLId> textures_; | |
234 base::hash_set<WebKit::WebGLId> used_textures_; | 272 base::hash_set<WebKit::WebGLId> used_textures_; |
235 std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_; | 273 std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_; |
236 int max_texture_size_; | 274 int max_texture_size_; |
237 int width_; | 275 int width_; |
238 int height_; | 276 int height_; |
239 | 277 |
240 struct Buffer { | 278 unsigned bound_buffer_; |
241 Buffer(); | |
242 ~Buffer(); | |
243 | 279 |
244 WebKit::WGC3Denum target; | 280 scoped_refptr<Namespace> namespace_; |
245 scoped_ptr<uint8[]> pixels; | 281 static Namespace* shared_namespace_; |
246 | 282 |
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_; | 283 base::WeakPtrFactory<TestWebGraphicsContext3D> weak_ptr_factory_; |
263 }; | 284 }; |
264 | 285 |
265 } // namespace cc | 286 } // namespace cc |
266 | 287 |
267 #endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ | 288 #endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ |
OLD | NEW |