| 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 #include "cc/debug/test_web_graphics_context_3d.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "base/lazy_instance.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "cc/debug/test_context_support.h" | |
| 15 #include "gpu/GLES2/gl2extchromium.h" | |
| 16 #include "third_party/khronos/GLES2/gl2ext.h" | |
| 17 | |
| 18 using WebKit::WGC3Dboolean; | |
| 19 using WebKit::WGC3Dchar; | |
| 20 using WebKit::WGC3Denum; | |
| 21 using WebKit::WGC3Dint; | |
| 22 using WebKit::WGC3Dsizei; | |
| 23 using WebKit::WGC3Dsizeiptr; | |
| 24 using WebKit::WGC3Duint; | |
| 25 using WebKit::WebGLId; | |
| 26 using WebKit::WebGraphicsContext3D; | |
| 27 | |
| 28 namespace cc { | |
| 29 | |
| 30 static const WebGLId kFramebufferId = 1; | |
| 31 static const WebGLId kProgramId = 2; | |
| 32 static const WebGLId kRenderbufferId = 3; | |
| 33 static const WebGLId kShaderId = 4; | |
| 34 | |
| 35 static unsigned s_context_id = 1; | |
| 36 | |
| 37 const WebGLId TestWebGraphicsContext3D::kExternalTextureId = 1337; | |
| 38 | |
| 39 static base::LazyInstance<base::Lock>::Leaky | |
| 40 g_shared_namespace_lock = LAZY_INSTANCE_INITIALIZER; | |
| 41 | |
| 42 TestWebGraphicsContext3D::Namespace* | |
| 43 TestWebGraphicsContext3D::shared_namespace_ = NULL; | |
| 44 | |
| 45 TestWebGraphicsContext3D::Namespace::Namespace() | |
| 46 : next_buffer_id(1), | |
| 47 next_image_id(1), | |
| 48 next_texture_id(1) { | |
| 49 } | |
| 50 | |
| 51 TestWebGraphicsContext3D::Namespace::~Namespace() { | |
| 52 g_shared_namespace_lock.Get().AssertAcquired(); | |
| 53 if (shared_namespace_ == this) | |
| 54 shared_namespace_ = NULL; | |
| 55 } | |
| 56 | |
| 57 // static | |
| 58 scoped_ptr<TestWebGraphicsContext3D> TestWebGraphicsContext3D::Create() { | |
| 59 return make_scoped_ptr(new TestWebGraphicsContext3D()); | |
| 60 } | |
| 61 | |
| 62 TestWebGraphicsContext3D::TestWebGraphicsContext3D() | |
| 63 : FakeWebGraphicsContext3D(), | |
| 64 context_id_(s_context_id++), | |
| 65 times_make_current_succeeds_(-1), | |
| 66 times_bind_texture_succeeds_(-1), | |
| 67 times_end_query_succeeds_(-1), | |
| 68 times_gen_mailbox_succeeds_(-1), | |
| 69 context_lost_(false), | |
| 70 times_map_image_chromium_succeeds_(-1), | |
| 71 times_map_buffer_chromium_succeeds_(-1), | |
| 72 context_lost_callback_(NULL), | |
| 73 swap_buffers_callback_(NULL), | |
| 74 max_texture_size_(2048), | |
| 75 width_(0), | |
| 76 height_(0), | |
| 77 test_support_(NULL), | |
| 78 bound_buffer_(0), | |
| 79 weak_ptr_factory_(this) { | |
| 80 CreateNamespace(); | |
| 81 test_capabilities_.swapbuffers_complete_callback = true; | |
| 82 } | |
| 83 | |
| 84 TestWebGraphicsContext3D::~TestWebGraphicsContext3D() { | |
| 85 base::AutoLock lock(g_shared_namespace_lock.Get()); | |
| 86 namespace_ = NULL; | |
| 87 } | |
| 88 | |
| 89 void TestWebGraphicsContext3D::CreateNamespace() { | |
| 90 if (attributes_.shareResources) { | |
| 91 base::AutoLock lock(g_shared_namespace_lock.Get()); | |
| 92 if (shared_namespace_) { | |
| 93 namespace_ = shared_namespace_; | |
| 94 } else { | |
| 95 namespace_ = new Namespace; | |
| 96 shared_namespace_ = namespace_.get(); | |
| 97 } | |
| 98 } else { | |
| 99 namespace_ = new Namespace; | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 bool TestWebGraphicsContext3D::makeContextCurrent() { | |
| 104 if (times_make_current_succeeds_ >= 0) { | |
| 105 if (!times_make_current_succeeds_) { | |
| 106 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
| 107 GL_INNOCENT_CONTEXT_RESET_ARB); | |
| 108 } | |
| 109 --times_make_current_succeeds_; | |
| 110 } | |
| 111 return !context_lost_; | |
| 112 } | |
| 113 | |
| 114 void TestWebGraphicsContext3D::reshapeWithScaleFactor( | |
| 115 int width, int height, float scale_factor) { | |
| 116 width_ = width; | |
| 117 height_ = height; | |
| 118 } | |
| 119 | |
| 120 bool TestWebGraphicsContext3D::isContextLost() { | |
| 121 return context_lost_; | |
| 122 } | |
| 123 | |
| 124 WGC3Denum TestWebGraphicsContext3D::getGraphicsResetStatusARB() { | |
| 125 return context_lost_ ? GL_UNKNOWN_CONTEXT_RESET_ARB : GL_NO_ERROR; | |
| 126 } | |
| 127 | |
| 128 WGC3Denum TestWebGraphicsContext3D::checkFramebufferStatus( | |
| 129 WGC3Denum target) { | |
| 130 if (context_lost_) | |
| 131 return GL_FRAMEBUFFER_UNDEFINED_OES; | |
| 132 return GL_FRAMEBUFFER_COMPLETE; | |
| 133 } | |
| 134 | |
| 135 WebGraphicsContext3D::Attributes | |
| 136 TestWebGraphicsContext3D::getContextAttributes() { | |
| 137 return attributes_; | |
| 138 } | |
| 139 | |
| 140 WebKit::WebString TestWebGraphicsContext3D::getString(WGC3Denum name) { | |
| 141 return WebKit::WebString(); | |
| 142 } | |
| 143 | |
| 144 WGC3Dint TestWebGraphicsContext3D::getUniformLocation( | |
| 145 WebGLId program, | |
| 146 const WGC3Dchar* name) { | |
| 147 return 0; | |
| 148 } | |
| 149 | |
| 150 WGC3Dsizeiptr TestWebGraphicsContext3D::getVertexAttribOffset( | |
| 151 WGC3Duint index, | |
| 152 WGC3Denum pname) { | |
| 153 return 0; | |
| 154 } | |
| 155 | |
| 156 WGC3Dboolean TestWebGraphicsContext3D::isBuffer( | |
| 157 WebGLId buffer) { | |
| 158 return false; | |
| 159 } | |
| 160 | |
| 161 WGC3Dboolean TestWebGraphicsContext3D::isEnabled( | |
| 162 WGC3Denum cap) { | |
| 163 return false; | |
| 164 } | |
| 165 | |
| 166 WGC3Dboolean TestWebGraphicsContext3D::isFramebuffer( | |
| 167 WebGLId framebuffer) { | |
| 168 return false; | |
| 169 } | |
| 170 | |
| 171 WGC3Dboolean TestWebGraphicsContext3D::isProgram( | |
| 172 WebGLId program) { | |
| 173 return false; | |
| 174 } | |
| 175 | |
| 176 WGC3Dboolean TestWebGraphicsContext3D::isRenderbuffer( | |
| 177 WebGLId renderbuffer) { | |
| 178 return false; | |
| 179 } | |
| 180 | |
| 181 WGC3Dboolean TestWebGraphicsContext3D::isShader( | |
| 182 WebGLId shader) { | |
| 183 return false; | |
| 184 } | |
| 185 | |
| 186 WGC3Dboolean TestWebGraphicsContext3D::isTexture( | |
| 187 WebGLId texture) { | |
| 188 return false; | |
| 189 } | |
| 190 | |
| 191 void TestWebGraphicsContext3D::genBuffers(WGC3Dsizei count, WebGLId* ids) { | |
| 192 for (int i = 0; i < count; ++i) | |
| 193 ids[i] = NextBufferId(); | |
| 194 } | |
| 195 | |
| 196 void TestWebGraphicsContext3D::genFramebuffers( | |
| 197 WGC3Dsizei count, WebGLId* ids) { | |
| 198 for (int i = 0; i < count; ++i) | |
| 199 ids[i] = kFramebufferId | context_id_ << 16; | |
| 200 } | |
| 201 | |
| 202 void TestWebGraphicsContext3D::genRenderbuffers( | |
| 203 WGC3Dsizei count, WebGLId* ids) { | |
| 204 for (int i = 0; i < count; ++i) | |
| 205 ids[i] = kRenderbufferId | context_id_ << 16; | |
| 206 } | |
| 207 | |
| 208 void TestWebGraphicsContext3D::genTextures(WGC3Dsizei count, WebGLId* ids) { | |
| 209 for (int i = 0; i < count; ++i) { | |
| 210 ids[i] = NextTextureId(); | |
| 211 DCHECK_NE(ids[i], kExternalTextureId); | |
| 212 } | |
| 213 base::AutoLock lock(namespace_->lock); | |
| 214 for (int i = 0; i < count; ++i) | |
| 215 namespace_->textures.Append(ids[i], new TestTexture()); | |
| 216 } | |
| 217 | |
| 218 void TestWebGraphicsContext3D::deleteBuffers(WGC3Dsizei count, WebGLId* ids) { | |
| 219 base::AutoLock lock(namespace_->lock); | |
| 220 for (int i = 0; i < count; ++i) { | |
| 221 unsigned context_id = ids[i] >> 17; | |
| 222 unsigned buffer_id = ids[i] & 0x1ffff; | |
| 223 DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id); | |
| 224 DCHECK_EQ(context_id, context_id_); | |
| 225 } | |
| 226 } | |
| 227 | |
| 228 void TestWebGraphicsContext3D::deleteFramebuffers( | |
| 229 WGC3Dsizei count, WebGLId* ids) { | |
| 230 for (int i = 0; i < count; ++i) | |
| 231 DCHECK_EQ(kFramebufferId | context_id_ << 16, ids[i]); | |
| 232 } | |
| 233 | |
| 234 void TestWebGraphicsContext3D::deleteRenderbuffers( | |
| 235 WGC3Dsizei count, WebGLId* ids) { | |
| 236 for (int i = 0; i < count; ++i) | |
| 237 DCHECK_EQ(kRenderbufferId | context_id_ << 16, ids[i]); | |
| 238 } | |
| 239 | |
| 240 void TestWebGraphicsContext3D::deleteTextures(WGC3Dsizei count, WebGLId* ids) { | |
| 241 base::AutoLock lock(namespace_->lock); | |
| 242 for (int i = 0; i < count; ++i) { | |
| 243 namespace_->textures.Remove(ids[i]); | |
| 244 texture_targets_.UnbindTexture(ids[i]); | |
| 245 } | |
| 246 } | |
| 247 | |
| 248 WebGLId TestWebGraphicsContext3D::createBuffer() { | |
| 249 WebGLId id; | |
| 250 genBuffers(1, &id); | |
| 251 return id; | |
| 252 } | |
| 253 | |
| 254 WebGLId TestWebGraphicsContext3D::createFramebuffer() { | |
| 255 WebGLId id; | |
| 256 genFramebuffers(1, &id); | |
| 257 return id; | |
| 258 } | |
| 259 | |
| 260 WebGLId TestWebGraphicsContext3D::createRenderbuffer() { | |
| 261 WebGLId id; | |
| 262 genRenderbuffers(1, &id); | |
| 263 return id; | |
| 264 } | |
| 265 | |
| 266 WebGLId TestWebGraphicsContext3D::createTexture() { | |
| 267 WebGLId id; | |
| 268 genTextures(1, &id); | |
| 269 return id; | |
| 270 } | |
| 271 | |
| 272 void TestWebGraphicsContext3D::deleteBuffer(WebGLId id) { | |
| 273 deleteBuffers(1, &id); | |
| 274 } | |
| 275 | |
| 276 void TestWebGraphicsContext3D::deleteFramebuffer(WebGLId id) { | |
| 277 deleteFramebuffers(1, &id); | |
| 278 } | |
| 279 | |
| 280 void TestWebGraphicsContext3D::deleteRenderbuffer(WebGLId id) { | |
| 281 deleteRenderbuffers(1, &id); | |
| 282 } | |
| 283 | |
| 284 void TestWebGraphicsContext3D::deleteTexture(WebGLId id) { | |
| 285 deleteTextures(1, &id); | |
| 286 } | |
| 287 | |
| 288 WebGLId TestWebGraphicsContext3D::createProgram() { | |
| 289 return kProgramId | context_id_ << 16; | |
| 290 } | |
| 291 | |
| 292 WebGLId TestWebGraphicsContext3D::createShader(WGC3Denum) { | |
| 293 return kShaderId | context_id_ << 16; | |
| 294 } | |
| 295 | |
| 296 WebGLId TestWebGraphicsContext3D::createExternalTexture() { | |
| 297 base::AutoLock lock(namespace_->lock); | |
| 298 namespace_->textures.Append(kExternalTextureId, new TestTexture()); | |
| 299 return kExternalTextureId; | |
| 300 } | |
| 301 | |
| 302 void TestWebGraphicsContext3D::deleteProgram(WebGLId id) { | |
| 303 DCHECK_EQ(kProgramId | context_id_ << 16, id); | |
| 304 } | |
| 305 | |
| 306 void TestWebGraphicsContext3D::deleteShader(WebGLId id) { | |
| 307 DCHECK_EQ(kShaderId | context_id_ << 16, id); | |
| 308 } | |
| 309 | |
| 310 void TestWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) { | |
| 311 DCHECK_EQ(kProgramId | context_id_ << 16, program); | |
| 312 DCHECK_EQ(kShaderId | context_id_ << 16, shader); | |
| 313 } | |
| 314 | |
| 315 void TestWebGraphicsContext3D::useProgram(WebGLId program) { | |
| 316 if (!program) | |
| 317 return; | |
| 318 DCHECK_EQ(kProgramId | context_id_ << 16, program); | |
| 319 } | |
| 320 | |
| 321 void TestWebGraphicsContext3D::bindFramebuffer( | |
| 322 WGC3Denum target, WebGLId framebuffer) { | |
| 323 if (!framebuffer) | |
| 324 return; | |
| 325 DCHECK_EQ(kFramebufferId | context_id_ << 16, framebuffer); | |
| 326 } | |
| 327 | |
| 328 void TestWebGraphicsContext3D::bindRenderbuffer( | |
| 329 WGC3Denum target, WebGLId renderbuffer) { | |
| 330 if (!renderbuffer) | |
| 331 return; | |
| 332 DCHECK_EQ(kRenderbufferId | context_id_ << 16, renderbuffer); | |
| 333 } | |
| 334 | |
| 335 void TestWebGraphicsContext3D::bindTexture( | |
| 336 WGC3Denum target, WebGLId texture_id) { | |
| 337 if (times_bind_texture_succeeds_ >= 0) { | |
| 338 if (!times_bind_texture_succeeds_) { | |
| 339 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
| 340 GL_INNOCENT_CONTEXT_RESET_ARB); | |
| 341 } | |
| 342 --times_bind_texture_succeeds_; | |
| 343 } | |
| 344 | |
| 345 if (!texture_id) | |
| 346 return; | |
| 347 base::AutoLock lock(namespace_->lock); | |
| 348 DCHECK(namespace_->textures.ContainsId(texture_id)); | |
| 349 texture_targets_.BindTexture(target, texture_id); | |
| 350 used_textures_.insert(texture_id); | |
| 351 } | |
| 352 | |
| 353 WebKit::WebGLId TestWebGraphicsContext3D::BoundTextureId( | |
| 354 WebKit::WGC3Denum target) { | |
| 355 return texture_targets_.BoundTexture(target); | |
| 356 } | |
| 357 | |
| 358 void TestWebGraphicsContext3D::endQueryEXT(WGC3Denum target) { | |
| 359 if (times_end_query_succeeds_ >= 0) { | |
| 360 if (!times_end_query_succeeds_) { | |
| 361 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
| 362 GL_INNOCENT_CONTEXT_RESET_ARB); | |
| 363 } | |
| 364 --times_end_query_succeeds_; | |
| 365 } | |
| 366 } | |
| 367 | |
| 368 void TestWebGraphicsContext3D::getQueryObjectuivEXT( | |
| 369 WebGLId query, | |
| 370 WGC3Denum pname, | |
| 371 WGC3Duint* params) { | |
| 372 // If the context is lost, behave as if result is available. | |
| 373 if (pname == GL_QUERY_RESULT_AVAILABLE_EXT) | |
| 374 *params = 1; | |
| 375 } | |
| 376 | |
| 377 void TestWebGraphicsContext3D::getIntegerv( | |
| 378 WGC3Denum pname, | |
| 379 WebKit::WGC3Dint* value) { | |
| 380 if (pname == GL_MAX_TEXTURE_SIZE) | |
| 381 *value = max_texture_size_; | |
| 382 else if (pname == GL_ACTIVE_TEXTURE) | |
| 383 *value = GL_TEXTURE0; | |
| 384 } | |
| 385 | |
| 386 void TestWebGraphicsContext3D::genMailboxCHROMIUM(WebKit::WGC3Dbyte* mailbox) { | |
| 387 if (times_gen_mailbox_succeeds_ >= 0) { | |
| 388 if (!times_gen_mailbox_succeeds_) { | |
| 389 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
| 390 GL_INNOCENT_CONTEXT_RESET_ARB); | |
| 391 } | |
| 392 --times_gen_mailbox_succeeds_; | |
| 393 } | |
| 394 if (context_lost_) { | |
| 395 memset(mailbox, 0, 64); | |
| 396 return; | |
| 397 } | |
| 398 | |
| 399 static char mailbox_name1 = '1'; | |
| 400 static char mailbox_name2 = '1'; | |
| 401 mailbox[0] = mailbox_name1; | |
| 402 mailbox[1] = mailbox_name2; | |
| 403 mailbox[2] = '\0'; | |
| 404 if (++mailbox_name1 == 0) { | |
| 405 mailbox_name1 = '1'; | |
| 406 ++mailbox_name2; | |
| 407 } | |
| 408 } | |
| 409 | |
| 410 void TestWebGraphicsContext3D::setContextLostCallback( | |
| 411 WebGraphicsContextLostCallback* callback) { | |
| 412 context_lost_callback_ = callback; | |
| 413 } | |
| 414 | |
| 415 void TestWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current, | |
| 416 WGC3Denum other) { | |
| 417 if (context_lost_) | |
| 418 return; | |
| 419 context_lost_ = true; | |
| 420 if (context_lost_callback_) | |
| 421 context_lost_callback_->onContextLost(); | |
| 422 | |
| 423 for (size_t i = 0; i < shared_contexts_.size(); ++i) | |
| 424 shared_contexts_[i]->loseContextCHROMIUM(current, other); | |
| 425 shared_contexts_.clear(); | |
| 426 } | |
| 427 | |
| 428 void TestWebGraphicsContext3D::setSwapBuffersCompleteCallbackCHROMIUM( | |
| 429 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback) { | |
| 430 if (test_capabilities_.swapbuffers_complete_callback) | |
| 431 swap_buffers_callback_ = callback; | |
| 432 } | |
| 433 | |
| 434 void TestWebGraphicsContext3D::prepareTexture() { | |
| 435 // TODO(jamesr): This should implemented as ContextSupport::SwapBuffers(). | |
| 436 if (swap_buffers_callback_) { | |
| 437 base::MessageLoop::current()->PostTask( | |
| 438 FROM_HERE, base::Bind(&TestWebGraphicsContext3D::SwapBuffersComplete, | |
| 439 weak_ptr_factory_.GetWeakPtr())); | |
| 440 } | |
| 441 test_support_->CallAllSyncPointCallbacks(); | |
| 442 } | |
| 443 | |
| 444 void TestWebGraphicsContext3D::finish() { | |
| 445 test_support_->CallAllSyncPointCallbacks(); | |
| 446 } | |
| 447 | |
| 448 void TestWebGraphicsContext3D::flush() { | |
| 449 test_support_->CallAllSyncPointCallbacks(); | |
| 450 } | |
| 451 | |
| 452 void TestWebGraphicsContext3D::SwapBuffersComplete() { | |
| 453 if (swap_buffers_callback_) | |
| 454 swap_buffers_callback_->onSwapBuffersComplete(); | |
| 455 } | |
| 456 | |
| 457 void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target, | |
| 458 WebKit::WebGLId buffer) { | |
| 459 bound_buffer_ = buffer; | |
| 460 if (!bound_buffer_) | |
| 461 return; | |
| 462 unsigned context_id = buffer >> 17; | |
| 463 unsigned buffer_id = buffer & 0x1ffff; | |
| 464 base::AutoLock lock(namespace_->lock); | |
| 465 DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id); | |
| 466 DCHECK_EQ(context_id, context_id_); | |
| 467 | |
| 468 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; | |
| 469 if (buffers.count(bound_buffer_) == 0) | |
| 470 buffers.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass()); | |
| 471 | |
| 472 buffers.get(bound_buffer_)->target = target; | |
| 473 } | |
| 474 | |
| 475 void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target, | |
| 476 WebKit::WGC3Dsizeiptr size, | |
| 477 const void* data, | |
| 478 WebKit::WGC3Denum usage) { | |
| 479 base::AutoLock lock(namespace_->lock); | |
| 480 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; | |
| 481 DCHECK_GT(buffers.count(bound_buffer_), 0u); | |
| 482 DCHECK_EQ(target, buffers.get(bound_buffer_)->target); | |
| 483 Buffer* buffer = buffers.get(bound_buffer_); | |
| 484 if (context_lost_) { | |
| 485 buffer->pixels.reset(); | |
| 486 return; | |
| 487 } | |
| 488 | |
| 489 buffer->pixels.reset(new uint8[size]); | |
| 490 buffer->size = size; | |
| 491 if (data != NULL) | |
| 492 memcpy(buffer->pixels.get(), data, size); | |
| 493 } | |
| 494 | |
| 495 void* TestWebGraphicsContext3D::mapBufferCHROMIUM(WebKit::WGC3Denum target, | |
| 496 WebKit::WGC3Denum access) { | |
| 497 base::AutoLock lock(namespace_->lock); | |
| 498 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; | |
| 499 DCHECK_GT(buffers.count(bound_buffer_), 0u); | |
| 500 DCHECK_EQ(target, buffers.get(bound_buffer_)->target); | |
| 501 if (times_map_buffer_chromium_succeeds_ >= 0) { | |
| 502 if (!times_map_buffer_chromium_succeeds_) { | |
| 503 return NULL; | |
| 504 } | |
| 505 --times_map_buffer_chromium_succeeds_; | |
| 506 } | |
| 507 return buffers.get(bound_buffer_)->pixels.get(); | |
| 508 } | |
| 509 | |
| 510 WebKit::WGC3Dboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM( | |
| 511 WebKit::WGC3Denum target) { | |
| 512 base::AutoLock lock(namespace_->lock); | |
| 513 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; | |
| 514 DCHECK_GT(buffers.count(bound_buffer_), 0u); | |
| 515 DCHECK_EQ(target, buffers.get(bound_buffer_)->target); | |
| 516 buffers.get(bound_buffer_)->pixels.reset(); | |
| 517 return true; | |
| 518 } | |
| 519 | |
| 520 WebKit::WGC3Duint TestWebGraphicsContext3D::createImageCHROMIUM( | |
| 521 WebKit::WGC3Dsizei width, WebKit::WGC3Dsizei height, | |
| 522 WebKit::WGC3Denum internalformat) { | |
| 523 DCHECK_EQ(GL_RGBA8_OES, static_cast<int>(internalformat)); | |
| 524 WebKit::WGC3Duint image_id = NextImageId(); | |
| 525 base::AutoLock lock(namespace_->lock); | |
| 526 base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images; | |
| 527 images.set(image_id, make_scoped_ptr(new Image).Pass()); | |
| 528 images.get(image_id)->pixels.reset(new uint8[width * height * 4]); | |
| 529 return image_id; | |
| 530 } | |
| 531 | |
| 532 void TestWebGraphicsContext3D::destroyImageCHROMIUM( | |
| 533 WebKit::WGC3Duint id) { | |
| 534 base::AutoLock lock(namespace_->lock); | |
| 535 unsigned context_id = id >> 17; | |
| 536 unsigned image_id = id & 0x1ffff; | |
| 537 DCHECK(image_id && image_id < namespace_->next_image_id); | |
| 538 DCHECK_EQ(context_id, context_id_); | |
| 539 } | |
| 540 | |
| 541 void TestWebGraphicsContext3D::getImageParameterivCHROMIUM( | |
| 542 WebKit::WGC3Duint image_id, | |
| 543 WebKit::WGC3Denum pname, | |
| 544 WebKit::WGC3Dint* params) { | |
| 545 base::AutoLock lock(namespace_->lock); | |
| 546 DCHECK_GT(namespace_->images.count(image_id), 0u); | |
| 547 DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname)); | |
| 548 *params = 0; | |
| 549 } | |
| 550 | |
| 551 void* TestWebGraphicsContext3D::mapImageCHROMIUM(WebKit::WGC3Duint image_id, | |
| 552 WebKit::WGC3Denum access) { | |
| 553 base::AutoLock lock(namespace_->lock); | |
| 554 base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images; | |
| 555 DCHECK_GT(images.count(image_id), 0u); | |
| 556 if (times_map_image_chromium_succeeds_ >= 0) { | |
| 557 if (!times_map_image_chromium_succeeds_) { | |
| 558 return NULL; | |
| 559 } | |
| 560 --times_map_image_chromium_succeeds_; | |
| 561 } | |
| 562 return images.get(image_id)->pixels.get(); | |
| 563 } | |
| 564 | |
| 565 void TestWebGraphicsContext3D::unmapImageCHROMIUM( | |
| 566 WebKit::WGC3Duint image_id) { | |
| 567 base::AutoLock lock(namespace_->lock); | |
| 568 DCHECK_GT(namespace_->images.count(image_id), 0u); | |
| 569 } | |
| 570 | |
| 571 size_t TestWebGraphicsContext3D::NumTextures() const { | |
| 572 base::AutoLock lock(namespace_->lock); | |
| 573 return namespace_->textures.Size(); | |
| 574 } | |
| 575 | |
| 576 WebKit::WebGLId TestWebGraphicsContext3D::TextureAt(int i) const { | |
| 577 base::AutoLock lock(namespace_->lock); | |
| 578 return namespace_->textures.IdAt(i); | |
| 579 } | |
| 580 | |
| 581 WebGLId TestWebGraphicsContext3D::NextTextureId() { | |
| 582 base::AutoLock lock(namespace_->lock); | |
| 583 WebGLId texture_id = namespace_->next_texture_id++; | |
| 584 DCHECK(texture_id < (1 << 16)); | |
| 585 texture_id |= context_id_ << 16; | |
| 586 return texture_id; | |
| 587 } | |
| 588 | |
| 589 WebGLId TestWebGraphicsContext3D::NextBufferId() { | |
| 590 base::AutoLock lock(namespace_->lock); | |
| 591 WebGLId buffer_id = namespace_->next_buffer_id++; | |
| 592 DCHECK(buffer_id < (1 << 17)); | |
| 593 buffer_id |= context_id_ << 17; | |
| 594 return buffer_id; | |
| 595 } | |
| 596 | |
| 597 WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() { | |
| 598 base::AutoLock lock(namespace_->lock); | |
| 599 WGC3Duint image_id = namespace_->next_image_id++; | |
| 600 DCHECK(image_id < (1 << 17)); | |
| 601 image_id |= context_id_ << 17; | |
| 602 return image_id; | |
| 603 } | |
| 604 | |
| 605 size_t TestWebGraphicsContext3D::GetTransferBufferMemoryUsedBytes() const { | |
| 606 size_t total_bytes = 0; | |
| 607 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; | |
| 608 base::ScopedPtrHashMap<unsigned, Buffer>::iterator it = buffers.begin(); | |
| 609 for (; it != buffers.end(); ++it) { | |
| 610 Buffer* buffer = it->second; | |
| 611 if (buffer->target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) | |
| 612 total_bytes += buffer->size; | |
| 613 } | |
| 614 return total_bytes; | |
| 615 } | |
| 616 | |
| 617 void TestWebGraphicsContext3D::SetMaxTransferBufferUsageBytes( | |
| 618 size_t max_transfer_buffer_usage_bytes) { | |
| 619 test_capabilities_.max_transfer_buffer_usage_bytes = | |
| 620 max_transfer_buffer_usage_bytes; | |
| 621 } | |
| 622 | |
| 623 TestWebGraphicsContext3D::TextureTargets::TextureTargets() { | |
| 624 // Initialize default bindings. | |
| 625 bound_textures_[GL_TEXTURE_2D] = 0; | |
| 626 bound_textures_[GL_TEXTURE_EXTERNAL_OES] = 0; | |
| 627 bound_textures_[GL_TEXTURE_RECTANGLE_ARB] = 0; | |
| 628 } | |
| 629 | |
| 630 TestWebGraphicsContext3D::TextureTargets::~TextureTargets() {} | |
| 631 | |
| 632 void TestWebGraphicsContext3D::TextureTargets::BindTexture( | |
| 633 WebKit::WGC3Denum target, | |
| 634 WebKit::WebGLId id) { | |
| 635 // Make sure this is a supported target by seeing if it was bound to before. | |
| 636 DCHECK(bound_textures_.find(target) != bound_textures_.end()); | |
| 637 bound_textures_[target] = id; | |
| 638 } | |
| 639 | |
| 640 void TestWebGraphicsContext3D::TextureTargets::UnbindTexture( | |
| 641 WebKit::WebGLId id) { | |
| 642 // Bind zero to any targets that the id is bound to. | |
| 643 for (TargetTextureMap::iterator it = bound_textures_.begin(); | |
| 644 it != bound_textures_.end(); | |
| 645 it++) { | |
| 646 if (it->second == id) | |
| 647 it->second = 0; | |
| 648 } | |
| 649 } | |
| 650 | |
| 651 WebKit::WebGLId TestWebGraphicsContext3D::TextureTargets::BoundTexture( | |
| 652 WebKit::WGC3Denum target) { | |
| 653 DCHECK(bound_textures_.find(target) != bound_textures_.end()); | |
| 654 return bound_textures_[target]; | |
| 655 } | |
| 656 | |
| 657 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {} | |
| 658 | |
| 659 TestWebGraphicsContext3D::Buffer::~Buffer() {} | |
| 660 | |
| 661 TestWebGraphicsContext3D::Image::Image() {} | |
| 662 | |
| 663 TestWebGraphicsContext3D::Image::~Image() {} | |
| 664 | |
| 665 } // namespace cc | |
| OLD | NEW |