| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "cc/debug/test_web_graphics_context_3d.h" | 5 #include "cc/debug/test_web_graphics_context_3d.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 for (int i = 0; i < count; ++i) { | 209 for (int i = 0; i < count; ++i) { |
| 210 ids[i] = NextTextureId(); | 210 ids[i] = NextTextureId(); |
| 211 DCHECK_NE(ids[i], kExternalTextureId); | 211 DCHECK_NE(ids[i], kExternalTextureId); |
| 212 } | 212 } |
| 213 base::AutoLock lock(namespace_->lock); | 213 base::AutoLock lock(namespace_->lock); |
| 214 for (int i = 0; i < count; ++i) | 214 for (int i = 0; i < count; ++i) |
| 215 namespace_->textures.Append(ids[i], new TestTexture()); | 215 namespace_->textures.Append(ids[i], new TestTexture()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void TestWebGraphicsContext3D::deleteBuffers(WGC3Dsizei count, WebGLId* ids) { | 218 void TestWebGraphicsContext3D::deleteBuffers(WGC3Dsizei count, WebGLId* ids) { |
| 219 base::AutoLock lock(namespace_->lock); | 219 for (int i = 0; i < count; ++i) |
| 220 for (int i = 0; i < count; ++i) { | 220 RetireBufferId(ids[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 } | 221 } |
| 227 | 222 |
| 228 void TestWebGraphicsContext3D::deleteFramebuffers( | 223 void TestWebGraphicsContext3D::deleteFramebuffers( |
| 229 WGC3Dsizei count, WebGLId* ids) { | 224 WGC3Dsizei count, WebGLId* ids) { |
| 230 for (int i = 0; i < count; ++i) | 225 for (int i = 0; i < count; ++i) |
| 231 DCHECK_EQ(kFramebufferId | context_id_ << 16, ids[i]); | 226 DCHECK_EQ(kFramebufferId | context_id_ << 16, ids[i]); |
| 232 } | 227 } |
| 233 | 228 |
| 234 void TestWebGraphicsContext3D::deleteRenderbuffers( | 229 void TestWebGraphicsContext3D::deleteRenderbuffers( |
| 235 WGC3Dsizei count, WebGLId* ids) { | 230 WGC3Dsizei count, WebGLId* ids) { |
| 236 for (int i = 0; i < count; ++i) | 231 for (int i = 0; i < count; ++i) |
| 237 DCHECK_EQ(kRenderbufferId | context_id_ << 16, ids[i]); | 232 DCHECK_EQ(kRenderbufferId | context_id_ << 16, ids[i]); |
| 238 } | 233 } |
| 239 | 234 |
| 240 void TestWebGraphicsContext3D::deleteTextures(WGC3Dsizei count, WebGLId* ids) { | 235 void TestWebGraphicsContext3D::deleteTextures(WGC3Dsizei count, WebGLId* ids) { |
| 236 for (int i = 0; i < count; ++i) |
| 237 RetireTextureId(ids[i]); |
| 241 base::AutoLock lock(namespace_->lock); | 238 base::AutoLock lock(namespace_->lock); |
| 242 for (int i = 0; i < count; ++i) { | 239 for (int i = 0; i < count; ++i) { |
| 243 namespace_->textures.Remove(ids[i]); | 240 namespace_->textures.Remove(ids[i]); |
| 244 texture_targets_.UnbindTexture(ids[i]); | 241 texture_targets_.UnbindTexture(ids[i]); |
| 245 } | 242 } |
| 246 } | 243 } |
| 247 | 244 |
| 248 WebGLId TestWebGraphicsContext3D::createBuffer() { | 245 WebGLId TestWebGraphicsContext3D::createBuffer() { |
| 249 WebGLId id; | 246 WebGLId id; |
| 250 genBuffers(1, &id); | 247 genBuffers(1, &id); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 void TestWebGraphicsContext3D::SwapBuffersComplete() { | 461 void TestWebGraphicsContext3D::SwapBuffersComplete() { |
| 465 if (swap_buffers_callback_) | 462 if (swap_buffers_callback_) |
| 466 swap_buffers_callback_->onSwapBuffersComplete(); | 463 swap_buffers_callback_->onSwapBuffersComplete(); |
| 467 } | 464 } |
| 468 | 465 |
| 469 void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target, | 466 void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target, |
| 470 WebKit::WebGLId buffer) { | 467 WebKit::WebGLId buffer) { |
| 471 bound_buffer_ = buffer; | 468 bound_buffer_ = buffer; |
| 472 if (!bound_buffer_) | 469 if (!bound_buffer_) |
| 473 return; | 470 return; |
| 474 unsigned context_id = buffer >> 17; | 471 unsigned context_id = buffer >> 16; |
| 475 unsigned buffer_id = buffer & 0x1ffff; | 472 unsigned buffer_id = buffer & 0xffff; |
| 476 base::AutoLock lock(namespace_->lock); | 473 base::AutoLock lock(namespace_->lock); |
| 477 DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id); | 474 DCHECK(buffer_id); |
| 475 DCHECK_LT(buffer_id, namespace_->next_buffer_id); |
| 478 DCHECK_EQ(context_id, context_id_); | 476 DCHECK_EQ(context_id, context_id_); |
| 479 | 477 |
| 480 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; | 478 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; |
| 481 if (buffers.count(bound_buffer_) == 0) | 479 if (buffers.count(bound_buffer_) == 0) |
| 482 buffers.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass()); | 480 buffers.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass()); |
| 483 | 481 |
| 484 buffers.get(bound_buffer_)->target = target; | 482 buffers.get(bound_buffer_)->target = target; |
| 485 } | 483 } |
| 486 | 484 |
| 487 void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target, | 485 void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 WebKit::WGC3Duint image_id = NextImageId(); | 534 WebKit::WGC3Duint image_id = NextImageId(); |
| 537 base::AutoLock lock(namespace_->lock); | 535 base::AutoLock lock(namespace_->lock); |
| 538 base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images; | 536 base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images; |
| 539 images.set(image_id, make_scoped_ptr(new Image).Pass()); | 537 images.set(image_id, make_scoped_ptr(new Image).Pass()); |
| 540 images.get(image_id)->pixels.reset(new uint8[width * height * 4]); | 538 images.get(image_id)->pixels.reset(new uint8[width * height * 4]); |
| 541 return image_id; | 539 return image_id; |
| 542 } | 540 } |
| 543 | 541 |
| 544 void TestWebGraphicsContext3D::destroyImageCHROMIUM( | 542 void TestWebGraphicsContext3D::destroyImageCHROMIUM( |
| 545 WebKit::WGC3Duint id) { | 543 WebKit::WGC3Duint id) { |
| 546 base::AutoLock lock(namespace_->lock); | 544 RetireImageId(id); |
| 547 unsigned context_id = id >> 17; | |
| 548 unsigned image_id = id & 0x1ffff; | |
| 549 DCHECK(image_id && image_id < namespace_->next_image_id); | |
| 550 DCHECK_EQ(context_id, context_id_); | |
| 551 } | 545 } |
| 552 | 546 |
| 553 void TestWebGraphicsContext3D::getImageParameterivCHROMIUM( | 547 void TestWebGraphicsContext3D::getImageParameterivCHROMIUM( |
| 554 WebKit::WGC3Duint image_id, | 548 WebKit::WGC3Duint image_id, |
| 555 WebKit::WGC3Denum pname, | 549 WebKit::WGC3Denum pname, |
| 556 WebKit::WGC3Dint* params) { | 550 WebKit::WGC3Dint* params) { |
| 557 base::AutoLock lock(namespace_->lock); | 551 base::AutoLock lock(namespace_->lock); |
| 558 DCHECK_GT(namespace_->images.count(image_id), 0u); | 552 DCHECK_GT(namespace_->images.count(image_id), 0u); |
| 559 DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname)); | 553 DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname)); |
| 560 *params = 0; | 554 *params = 0; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 591 } | 585 } |
| 592 | 586 |
| 593 WebGLId TestWebGraphicsContext3D::NextTextureId() { | 587 WebGLId TestWebGraphicsContext3D::NextTextureId() { |
| 594 base::AutoLock lock(namespace_->lock); | 588 base::AutoLock lock(namespace_->lock); |
| 595 WebGLId texture_id = namespace_->next_texture_id++; | 589 WebGLId texture_id = namespace_->next_texture_id++; |
| 596 DCHECK(texture_id < (1 << 16)); | 590 DCHECK(texture_id < (1 << 16)); |
| 597 texture_id |= context_id_ << 16; | 591 texture_id |= context_id_ << 16; |
| 598 return texture_id; | 592 return texture_id; |
| 599 } | 593 } |
| 600 | 594 |
| 595 void TestWebGraphicsContext3D::RetireTextureId(WebGLId id) { |
| 596 base::AutoLock lock(namespace_->lock); |
| 597 unsigned context_id = id >> 16; |
| 598 unsigned texture_id = id & 0xffff; |
| 599 DCHECK(texture_id); |
| 600 DCHECK_LT(texture_id, namespace_->next_texture_id); |
| 601 DCHECK_EQ(context_id, context_id_); |
| 602 } |
| 603 |
| 601 WebGLId TestWebGraphicsContext3D::NextBufferId() { | 604 WebGLId TestWebGraphicsContext3D::NextBufferId() { |
| 602 base::AutoLock lock(namespace_->lock); | 605 base::AutoLock lock(namespace_->lock); |
| 603 WebGLId buffer_id = namespace_->next_buffer_id++; | 606 WebGLId buffer_id = namespace_->next_buffer_id++; |
| 604 DCHECK(buffer_id < (1 << 17)); | 607 DCHECK(buffer_id < (1 << 16)); |
| 605 buffer_id |= context_id_ << 17; | 608 buffer_id |= context_id_ << 16; |
| 606 return buffer_id; | 609 return buffer_id; |
| 607 } | 610 } |
| 608 | 611 |
| 612 void TestWebGraphicsContext3D::RetireBufferId(WebGLId id) { |
| 613 base::AutoLock lock(namespace_->lock); |
| 614 unsigned context_id = id >> 16; |
| 615 unsigned buffer_id = id & 0xffff; |
| 616 DCHECK(buffer_id); |
| 617 DCHECK_LT(buffer_id, namespace_->next_buffer_id); |
| 618 DCHECK_EQ(context_id, context_id_); |
| 619 } |
| 620 |
| 609 WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() { | 621 WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() { |
| 610 base::AutoLock lock(namespace_->lock); | 622 base::AutoLock lock(namespace_->lock); |
| 611 WGC3Duint image_id = namespace_->next_image_id++; | 623 WGC3Duint image_id = namespace_->next_image_id++; |
| 612 DCHECK(image_id < (1 << 17)); | 624 DCHECK(image_id < (1 << 16)); |
| 613 image_id |= context_id_ << 17; | 625 image_id |= context_id_ << 16; |
| 614 return image_id; | 626 return image_id; |
| 615 } | 627 } |
| 616 | 628 |
| 629 void TestWebGraphicsContext3D::RetireImageId(WebGLId id) { |
| 630 base::AutoLock lock(namespace_->lock); |
| 631 unsigned context_id = id >> 16; |
| 632 unsigned image_id = id & 0xffff; |
| 633 DCHECK(image_id); |
| 634 DCHECK_LT(image_id, namespace_->next_image_id); |
| 635 DCHECK_EQ(context_id, context_id_); |
| 636 } |
| 637 |
| 617 size_t TestWebGraphicsContext3D::GetTransferBufferMemoryUsedBytes() const { | 638 size_t TestWebGraphicsContext3D::GetTransferBufferMemoryUsedBytes() const { |
| 618 size_t total_bytes = 0; | 639 size_t total_bytes = 0; |
| 619 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; | 640 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; |
| 620 base::ScopedPtrHashMap<unsigned, Buffer>::iterator it = buffers.begin(); | 641 base::ScopedPtrHashMap<unsigned, Buffer>::iterator it = buffers.begin(); |
| 621 for (; it != buffers.end(); ++it) { | 642 for (; it != buffers.end(); ++it) { |
| 622 Buffer* buffer = it->second; | 643 Buffer* buffer = it->second; |
| 623 if (buffer->target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) | 644 if (buffer->target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) |
| 624 total_bytes += buffer->size; | 645 total_bytes += buffer->size; |
| 625 } | 646 } |
| 626 return total_bytes; | 647 return total_bytes; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 | 689 |
| 669 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {} | 690 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {} |
| 670 | 691 |
| 671 TestWebGraphicsContext3D::Buffer::~Buffer() {} | 692 TestWebGraphicsContext3D::Buffer::~Buffer() {} |
| 672 | 693 |
| 673 TestWebGraphicsContext3D::Image::Image() {} | 694 TestWebGraphicsContext3D::Image::Image() {} |
| 674 | 695 |
| 675 TestWebGraphicsContext3D::Image::~Image() {} | 696 TestWebGraphicsContext3D::Image::~Image() {} |
| 676 | 697 |
| 677 } // namespace cc | 698 } // namespace cc |
| OLD | NEW |