| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_DEBUG_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ | |
| 6 #define CC_DEBUG_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/containers/hash_tables.h" | |
| 12 #include "base/containers/scoped_ptr_hash_map.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "base/stl_util.h" | |
| 17 #include "base/synchronization/lock.h" | |
| 18 #include "cc/base/cc_export.h" | |
| 19 #include "cc/debug/fake_web_graphics_context_3d.h" | |
| 20 #include "cc/debug/ordered_texture_map.h" | |
| 21 #include "cc/debug/test_texture.h" | |
| 22 #include "cc/output/context_provider.h" | |
| 23 #include "third_party/khronos/GLES2/gl2.h" | |
| 24 | |
| 25 namespace cc { | |
| 26 class TestContextSupport; | |
| 27 | |
| 28 class CC_EXPORT TestWebGraphicsContext3D : public FakeWebGraphicsContext3D { | |
| 29 public: | |
| 30 static scoped_ptr<TestWebGraphicsContext3D> Create(); | |
| 31 | |
| 32 virtual ~TestWebGraphicsContext3D(); | |
| 33 | |
| 34 virtual bool makeContextCurrent(); | |
| 35 | |
| 36 virtual void reshapeWithScaleFactor( | |
| 37 int width, int height, float scale_factor); | |
| 38 | |
| 39 virtual bool isContextLost(); | |
| 40 virtual WebKit::WGC3Denum getGraphicsResetStatusARB(); | |
| 41 | |
| 42 virtual void attachShader(WebKit::WebGLId program, WebKit::WebGLId shader); | |
| 43 virtual void bindFramebuffer( | |
| 44 WebKit::WGC3Denum target, WebKit::WebGLId framebuffer); | |
| 45 virtual void bindRenderbuffer( | |
| 46 WebKit::WGC3Denum target, WebKit::WebGLId renderbuffer); | |
| 47 virtual void bindTexture( | |
| 48 WebKit::WGC3Denum target, | |
| 49 WebKit::WebGLId texture_id); | |
| 50 | |
| 51 virtual WebKit::WGC3Denum checkFramebufferStatus(WebKit::WGC3Denum target); | |
| 52 | |
| 53 virtual Attributes getContextAttributes(); | |
| 54 | |
| 55 virtual WebKit::WebString getString(WebKit::WGC3Denum name); | |
| 56 virtual WebKit::WGC3Dint getUniformLocation( | |
| 57 WebKit::WebGLId program, | |
| 58 const WebKit::WGC3Dchar* name); | |
| 59 virtual WebKit::WGC3Dsizeiptr getVertexAttribOffset( | |
| 60 WebKit::WGC3Duint index, | |
| 61 WebKit::WGC3Denum pname); | |
| 62 | |
| 63 virtual WebKit::WGC3Dboolean isBuffer(WebKit::WebGLId buffer); | |
| 64 virtual WebKit::WGC3Dboolean isEnabled(WebKit::WGC3Denum cap); | |
| 65 virtual WebKit::WGC3Dboolean isFramebuffer(WebKit::WebGLId framebuffer); | |
| 66 virtual WebKit::WGC3Dboolean isProgram(WebKit::WebGLId program); | |
| 67 virtual WebKit::WGC3Dboolean isRenderbuffer(WebKit::WebGLId renderbuffer); | |
| 68 virtual WebKit::WGC3Dboolean isShader(WebKit::WebGLId shader); | |
| 69 virtual WebKit::WGC3Dboolean isTexture(WebKit::WebGLId texture); | |
| 70 | |
| 71 virtual void useProgram(WebKit::WebGLId program); | |
| 72 | |
| 73 virtual void genBuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids); | |
| 74 virtual void genFramebuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids); | |
| 75 virtual void genRenderbuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids); | |
| 76 virtual void genTextures(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids); | |
| 77 | |
| 78 virtual void deleteBuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids); | |
| 79 virtual void deleteFramebuffers( | |
| 80 WebKit::WGC3Dsizei count, WebKit::WebGLId* ids); | |
| 81 virtual void deleteRenderbuffers( | |
| 82 WebKit::WGC3Dsizei count, WebKit::WebGLId* ids); | |
| 83 virtual void deleteTextures(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids); | |
| 84 | |
| 85 virtual WebKit::WebGLId createBuffer(); | |
| 86 virtual WebKit::WebGLId createFramebuffer(); | |
| 87 virtual WebKit::WebGLId createRenderbuffer(); | |
| 88 virtual WebKit::WebGLId createTexture(); | |
| 89 | |
| 90 virtual void deleteBuffer(WebKit::WebGLId id); | |
| 91 virtual void deleteFramebuffer(WebKit::WebGLId id); | |
| 92 virtual void deleteRenderbuffer(WebKit::WebGLId id); | |
| 93 virtual void deleteTexture(WebKit::WebGLId id); | |
| 94 | |
| 95 virtual WebKit::WebGLId createProgram(); | |
| 96 virtual WebKit::WebGLId createShader(WebKit::WGC3Denum); | |
| 97 virtual WebKit::WebGLId createExternalTexture(); | |
| 98 | |
| 99 virtual void deleteProgram(WebKit::WebGLId id); | |
| 100 virtual void deleteShader(WebKit::WebGLId id); | |
| 101 | |
| 102 virtual void endQueryEXT(WebKit::WGC3Denum target); | |
| 103 virtual void getQueryObjectuivEXT( | |
| 104 WebKit::WebGLId query, | |
| 105 WebKit::WGC3Denum pname, | |
| 106 WebKit::WGC3Duint* params); | |
| 107 | |
| 108 virtual void getIntegerv( | |
| 109 WebKit::WGC3Denum pname, | |
| 110 WebKit::WGC3Dint* value); | |
| 111 | |
| 112 virtual void genMailboxCHROMIUM(WebKit::WGC3Dbyte* mailbox); | |
| 113 virtual void produceTextureCHROMIUM(WebKit::WGC3Denum target, | |
| 114 const WebKit::WGC3Dbyte* mailbox) { } | |
| 115 virtual void consumeTextureCHROMIUM(WebKit::WGC3Denum target, | |
| 116 const WebKit::WGC3Dbyte* mailbox) { } | |
| 117 | |
| 118 virtual void setContextLostCallback( | |
| 119 WebGraphicsContextLostCallback* callback); | |
| 120 | |
| 121 virtual void loseContextCHROMIUM(WebKit::WGC3Denum current, | |
| 122 WebKit::WGC3Denum other); | |
| 123 | |
| 124 virtual void setSwapBuffersCompleteCallbackCHROMIUM( | |
| 125 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback); | |
| 126 | |
| 127 virtual void prepareTexture(); | |
| 128 virtual void finish(); | |
| 129 virtual void flush(); | |
| 130 | |
| 131 virtual void bindBuffer(WebKit::WGC3Denum target, WebKit::WebGLId buffer); | |
| 132 virtual void bufferData(WebKit::WGC3Denum target, | |
| 133 WebKit::WGC3Dsizeiptr size, | |
| 134 const void* data, | |
| 135 WebKit::WGC3Denum usage); | |
| 136 virtual void* mapBufferCHROMIUM(WebKit::WGC3Denum target, | |
| 137 WebKit::WGC3Denum access); | |
| 138 virtual WebKit::WGC3Dboolean unmapBufferCHROMIUM(WebKit::WGC3Denum target); | |
| 139 | |
| 140 virtual WebKit::WGC3Duint createImageCHROMIUM( | |
| 141 WebKit::WGC3Dsizei width, | |
| 142 WebKit::WGC3Dsizei height, | |
| 143 WebKit::WGC3Denum internalformat); | |
| 144 virtual void destroyImageCHROMIUM(WebKit::WGC3Duint image_id); | |
| 145 virtual void getImageParameterivCHROMIUM( | |
| 146 WebKit::WGC3Duint image_id, | |
| 147 WebKit::WGC3Denum pname, | |
| 148 WebKit::WGC3Dint* params); | |
| 149 virtual void* mapImageCHROMIUM( | |
| 150 WebKit::WGC3Duint image_id, | |
| 151 WebKit::WGC3Denum access); | |
| 152 virtual void unmapImageCHROMIUM(WebKit::WGC3Duint image_id); | |
| 153 | |
| 154 const ContextProvider::Capabilities& test_capabilities() const { | |
| 155 return test_capabilities_; | |
| 156 } | |
| 157 | |
| 158 // When set, MakeCurrent() will fail after this many times. | |
| 159 void set_times_make_current_succeeds(int times) { | |
| 160 times_make_current_succeeds_ = times; | |
| 161 } | |
| 162 void set_times_bind_texture_succeeds(int times) { | |
| 163 times_bind_texture_succeeds_ = times; | |
| 164 } | |
| 165 void set_times_end_query_succeeds(int times) { | |
| 166 times_end_query_succeeds_ = times; | |
| 167 } | |
| 168 void set_times_gen_mailbox_succeeds(int times) { | |
| 169 times_gen_mailbox_succeeds_ = times; | |
| 170 } | |
| 171 | |
| 172 // When set, mapImageCHROMIUM and mapBufferCHROMIUM will return NULL after | |
| 173 // this many times. | |
| 174 void set_times_map_image_chromium_succeeds(int times) { | |
| 175 times_map_image_chromium_succeeds_ = times; | |
| 176 } | |
| 177 void set_times_map_buffer_chromium_succeeds(int times) { | |
| 178 times_map_buffer_chromium_succeeds_ = times; | |
| 179 } | |
| 180 | |
| 181 size_t NumTextures() const; | |
| 182 WebKit::WebGLId TextureAt(int i) const; | |
| 183 | |
| 184 size_t NumUsedTextures() const { return used_textures_.size(); } | |
| 185 bool UsedTexture(int texture) const { | |
| 186 return ContainsKey(used_textures_, texture); | |
| 187 } | |
| 188 void ResetUsedTextures() { used_textures_.clear(); } | |
| 189 | |
| 190 void set_support_swapbuffers_complete_callback(bool support) { | |
| 191 test_capabilities_.swapbuffers_complete_callback = support; | |
| 192 } | |
| 193 void set_have_extension_io_surface(bool have) { | |
| 194 test_capabilities_.iosurface = have; | |
| 195 test_capabilities_.texture_rectangle = have; | |
| 196 } | |
| 197 void set_have_extension_egl_image(bool have) { | |
| 198 test_capabilities_.egl_image_external = have; | |
| 199 } | |
| 200 void set_have_post_sub_buffer(bool have) { | |
| 201 test_capabilities_.post_sub_buffer = have; | |
| 202 } | |
| 203 void set_have_discard_framebuffer(bool have) { | |
| 204 test_capabilities_.discard_framebuffer = have; | |
| 205 } | |
| 206 void set_support_compressed_texture_etc1(bool support) { | |
| 207 test_capabilities_.texture_format_etc1 = support; | |
| 208 } | |
| 209 | |
| 210 // When this context is lost, all contexts in its share group are also lost. | |
| 211 void add_share_group_context(WebKit::WebGraphicsContext3D* context3d) { | |
| 212 shared_contexts_.push_back(context3d); | |
| 213 } | |
| 214 | |
| 215 void set_max_texture_size(int size) { max_texture_size_ = size; } | |
| 216 | |
| 217 static const WebKit::WebGLId kExternalTextureId; | |
| 218 virtual WebKit::WebGLId NextTextureId(); | |
| 219 | |
| 220 virtual WebKit::WebGLId NextBufferId(); | |
| 221 | |
| 222 virtual WebKit::WebGLId NextImageId(); | |
| 223 | |
| 224 size_t GetTransferBufferMemoryUsedBytes() const; | |
| 225 void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes); | |
| 226 | |
| 227 void set_test_support(TestContextSupport* test_support) { | |
| 228 test_support_ = test_support; | |
| 229 } | |
| 230 | |
| 231 protected: | |
| 232 struct TextureTargets { | |
| 233 TextureTargets(); | |
| 234 ~TextureTargets(); | |
| 235 | |
| 236 void BindTexture(WebKit::WGC3Denum target, WebKit::WebGLId id); | |
| 237 void UnbindTexture(WebKit::WebGLId id); | |
| 238 | |
| 239 WebKit::WebGLId BoundTexture(WebKit::WGC3Denum target); | |
| 240 | |
| 241 private: | |
| 242 typedef base::hash_map<WebKit::WGC3Denum, WebKit::WebGLId> TargetTextureMap; | |
| 243 TargetTextureMap bound_textures_; | |
| 244 }; | |
| 245 | |
| 246 struct Buffer { | |
| 247 Buffer(); | |
| 248 ~Buffer(); | |
| 249 | |
| 250 WebKit::WGC3Denum target; | |
| 251 scoped_ptr<uint8[]> pixels; | |
| 252 size_t size; | |
| 253 | |
| 254 private: | |
| 255 DISALLOW_COPY_AND_ASSIGN(Buffer); | |
| 256 }; | |
| 257 | |
| 258 struct Image { | |
| 259 Image(); | |
| 260 ~Image(); | |
| 261 | |
| 262 scoped_ptr<uint8[]> pixels; | |
| 263 | |
| 264 private: | |
| 265 DISALLOW_COPY_AND_ASSIGN(Image); | |
| 266 }; | |
| 267 | |
| 268 struct Namespace : public base::RefCountedThreadSafe<Namespace> { | |
| 269 Namespace(); | |
| 270 | |
| 271 // Protects all fields. | |
| 272 base::Lock lock; | |
| 273 unsigned next_buffer_id; | |
| 274 unsigned next_image_id; | |
| 275 unsigned next_texture_id; | |
| 276 base::ScopedPtrHashMap<unsigned, Buffer> buffers; | |
| 277 base::ScopedPtrHashMap<unsigned, Image> images; | |
| 278 OrderedTextureMap textures; | |
| 279 | |
| 280 private: | |
| 281 friend class base::RefCountedThreadSafe<Namespace>; | |
| 282 ~Namespace(); | |
| 283 DISALLOW_COPY_AND_ASSIGN(Namespace); | |
| 284 }; | |
| 285 | |
| 286 TestWebGraphicsContext3D(); | |
| 287 | |
| 288 void CallAllSyncPointCallbacks(); | |
| 289 void SwapBuffersComplete(); | |
| 290 void CreateNamespace(); | |
| 291 WebKit::WebGLId BoundTextureId(WebKit::WGC3Denum target); | |
| 292 | |
| 293 unsigned context_id_; | |
| 294 Attributes attributes_; | |
| 295 ContextProvider::Capabilities test_capabilities_; | |
| 296 int times_make_current_succeeds_; | |
| 297 int times_bind_texture_succeeds_; | |
| 298 int times_end_query_succeeds_; | |
| 299 int times_gen_mailbox_succeeds_; | |
| 300 bool context_lost_; | |
| 301 int times_map_image_chromium_succeeds_; | |
| 302 int times_map_buffer_chromium_succeeds_; | |
| 303 WebGraphicsContextLostCallback* context_lost_callback_; | |
| 304 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_; | |
| 305 base::hash_set<WebKit::WebGLId> used_textures_; | |
| 306 std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_; | |
| 307 int max_texture_size_; | |
| 308 int width_; | |
| 309 int height_; | |
| 310 TestContextSupport* test_support_; | |
| 311 | |
| 312 unsigned bound_buffer_; | |
| 313 TextureTargets texture_targets_; | |
| 314 | |
| 315 scoped_refptr<Namespace> namespace_; | |
| 316 static Namespace* shared_namespace_; | |
| 317 | |
| 318 base::WeakPtrFactory<TestWebGraphicsContext3D> weak_ptr_factory_; | |
| 319 }; | |
| 320 | |
| 321 } // namespace cc | |
| 322 | |
| 323 #endif // CC_DEBUG_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ | |
| OLD | NEW |