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

Side by Side Diff: cc/test/test_web_graphics_context_3d.h

Issue 18796008: Implement shareResources==true in TestWebGraphicsContext3D (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 5 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
« no previous file with comments | « cc/test/fake_output_surface.h ('k') | cc/test/test_web_graphics_context_3d.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:
25 static scoped_ptr<TestWebGraphicsContext3D> Create() { 27 static scoped_ptr<TestWebGraphicsContext3D> Create() {
26 return make_scoped_ptr(new TestWebGraphicsContext3D()); 28 return make_scoped_ptr(new TestWebGraphicsContext3D());
27 } 29 }
28 static scoped_ptr<TestWebGraphicsContext3D> Create( 30 static scoped_ptr<TestWebGraphicsContext3D> Create(
29 const WebKit::WebGraphicsContext3D::Attributes& attributes) { 31 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
30 return make_scoped_ptr(new TestWebGraphicsContext3D(attributes)); 32 return make_scoped_ptr(new TestWebGraphicsContext3D(attributes));
31 } 33 }
34 static scoped_ptr<TestWebGraphicsContext3D> CreateShared() {
35 WebKit::WebGraphicsContext3D::Attributes attrs;
36 attrs.shareResources = true;
danakj 2013/07/15 23:15:41 this defaults true, right? so won't Create() also
piman 2013/07/16 00:45:33 Done.
37 return Create(attrs);
38 }
32 virtual ~TestWebGraphicsContext3D(); 39 virtual ~TestWebGraphicsContext3D();
33 40
34 virtual bool makeContextCurrent(); 41 virtual bool makeContextCurrent();
35 42
36 virtual int width(); 43 virtual int width();
37 virtual int height(); 44 virtual int height();
38 45
39 virtual void reshapeWithScaleFactor( 46 virtual void reshapeWithScaleFactor(
40 int width, int height, float scale_factor); 47 int width, int height, float scale_factor);
41 48
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 168
162 // When set, mapImageCHROMIUM and mapBufferCHROMIUM will return NULL after 169 // When set, mapImageCHROMIUM and mapBufferCHROMIUM will return NULL after
163 // this many times. 170 // this many times.
164 void set_times_map_image_chromium_succeeds(int times) { 171 void set_times_map_image_chromium_succeeds(int times) {
165 times_map_image_chromium_succeeds_ = times; 172 times_map_image_chromium_succeeds_ = times;
166 } 173 }
167 void set_times_map_buffer_chromium_succeeds(int times) { 174 void set_times_map_buffer_chromium_succeeds(int times) {
168 times_map_buffer_chromium_succeeds_ = times; 175 times_map_buffer_chromium_succeeds_ = times;
169 } 176 }
170 177
171 size_t NumTextures() const { return textures_.size(); } 178 size_t NumTextures() const;
172 WebKit::WebGLId TextureAt(int i) const { return textures_[i]; } 179 WebKit::WebGLId TextureAt(int i) const;
173 180
174 size_t NumUsedTextures() const { return used_textures_.size(); } 181 size_t NumUsedTextures() const { return used_textures_.size(); }
175 bool UsedTexture(int texture) const { 182 bool UsedTexture(int texture) const {
176 return ContainsKey(used_textures_, texture); 183 return ContainsKey(used_textures_, texture);
177 } 184 }
178 void ResetUsedTextures() { used_textures_.clear(); } 185 void ResetUsedTextures() { used_textures_.clear(); }
179 186
180 void set_support_swapbuffers_complete_callback(bool support) { 187 void set_support_swapbuffers_complete_callback(bool support) {
181 support_swapbuffers_complete_callback_ = support; 188 support_swapbuffers_complete_callback_ = support;
182 } 189 }
(...skipping 14 matching lines...) Expand all
197 static const WebKit::WebGLId kExternalTextureId; 204 static const WebKit::WebGLId kExternalTextureId;
198 virtual WebKit::WebGLId NextTextureId(); 205 virtual WebKit::WebGLId NextTextureId();
199 206
200 virtual WebKit::WebGLId NextBufferId(); 207 virtual WebKit::WebGLId NextBufferId();
201 208
202 virtual WebKit::WebGLId NextImageId(); 209 virtual WebKit::WebGLId NextImageId();
203 210
204 void SetMemoryAllocation(WebKit::WebGraphicsMemoryAllocation allocation); 211 void SetMemoryAllocation(WebKit::WebGraphicsMemoryAllocation allocation);
205 212
206 protected: 213 protected:
214 struct Buffer {
215 Buffer();
216 ~Buffer();
217
218 WebKit::WGC3Denum target;
219 scoped_ptr<uint8[]> pixels;
220
221 private:
222 DISALLOW_COPY_AND_ASSIGN(Buffer);
223 };
224
225 struct Image {
226 Image();
227 ~Image();
228
229 scoped_ptr<uint8[]> pixels;
230
231 private:
232 DISALLOW_COPY_AND_ASSIGN(Image);
233 };
234
235 struct Namespace : public base::RefCountedThreadSafe<Namespace> {
236 Namespace();
237
238 // Protects all fields;
239 base::Lock lock;
240 unsigned next_buffer_id;
241 unsigned next_image_id;
242 unsigned next_texture_id;
243 std::vector<WebKit::WebGLId> textures;
244 ScopedPtrHashMap<unsigned, Buffer> buffers;
245 ScopedPtrHashMap<unsigned, Image> images;
246
247 private:
248 friend class base::RefCountedThreadSafe<Namespace>;
249 ~Namespace();
250 DISALLOW_COPY_AND_ASSIGN(Namespace);
251 };
252
207 TestWebGraphicsContext3D(); 253 TestWebGraphicsContext3D();
208 TestWebGraphicsContext3D( 254 TestWebGraphicsContext3D(
209 const WebKit::WebGraphicsContext3D::Attributes& attributes); 255 const WebKit::WebGraphicsContext3D::Attributes& attributes);
210 256
211 void CallAllSyncPointCallbacks(); 257 void CallAllSyncPointCallbacks();
212 void SwapBuffersComplete(); 258 void SwapBuffersComplete();
213 259
214 unsigned context_id_; 260 unsigned context_id_;
215 unsigned next_buffer_id_;
216 unsigned next_image_id_;
217 unsigned next_texture_id_;
218 Attributes attributes_; 261 Attributes attributes_;
219 bool support_swapbuffers_complete_callback_; 262 bool support_swapbuffers_complete_callback_;
220 bool have_extension_io_surface_; 263 bool have_extension_io_surface_;
221 bool have_extension_egl_image_; 264 bool have_extension_egl_image_;
222 int times_make_current_succeeds_; 265 int times_make_current_succeeds_;
223 int times_bind_texture_succeeds_; 266 int times_bind_texture_succeeds_;
224 int times_end_query_succeeds_; 267 int times_end_query_succeeds_;
225 bool context_lost_; 268 bool context_lost_;
226 int times_map_image_chromium_succeeds_; 269 int times_map_image_chromium_succeeds_;
227 int times_map_buffer_chromium_succeeds_; 270 int times_map_buffer_chromium_succeeds_;
228 WebGraphicsContextLostCallback* context_lost_callback_; 271 WebGraphicsContextLostCallback* context_lost_callback_;
229 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_; 272 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_;
230 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* 273 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM*
231 memory_allocation_changed_callback_; 274 memory_allocation_changed_callback_;
232 std::vector<WebGraphicsSyncPointCallback*> sync_point_callbacks_; 275 std::vector<WebGraphicsSyncPointCallback*> sync_point_callbacks_;
233 std::vector<WebKit::WebGLId> textures_;
234 base::hash_set<WebKit::WebGLId> used_textures_; 276 base::hash_set<WebKit::WebGLId> used_textures_;
235 std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_; 277 std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_;
236 int max_texture_size_; 278 int max_texture_size_;
237 int width_; 279 int width_;
238 int height_; 280 int height_;
239 281
240 struct Buffer { 282 unsigned bound_buffer_;
241 Buffer();
242 ~Buffer();
243 283
244 WebKit::WGC3Denum target; 284 scoped_refptr<Namespace> namespace_;
245 scoped_ptr<uint8[]> pixels; 285 static Namespace* shared_namespace_;
246 286
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_; 287 base::WeakPtrFactory<TestWebGraphicsContext3D> weak_ptr_factory_;
263 }; 288 };
264 289
265 } // namespace cc 290 } // namespace cc
266 291
267 #endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ 292 #endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_
OLDNEW
« no previous file with comments | « cc/test/fake_output_surface.h ('k') | cc/test/test_web_graphics_context_3d.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698