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

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

Issue 49163004: cc: Reduce command buffer flushes related to creating texture ids. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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/test_web_graphics_context_3d.h ('k') | cc/trees/layer_tree_host_impl.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 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/test/test_web_graphics_context_3d.h" 5 #include "cc/test/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
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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 void TestWebGraphicsContext3D::SwapBuffersComplete() { 449 void TestWebGraphicsContext3D::SwapBuffersComplete() {
453 if (swap_buffers_callback_) 450 if (swap_buffers_callback_)
454 swap_buffers_callback_->onSwapBuffersComplete(); 451 swap_buffers_callback_->onSwapBuffersComplete();
455 } 452 }
456 453
457 void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target, 454 void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target,
458 WebKit::WebGLId buffer) { 455 WebKit::WebGLId buffer) {
459 bound_buffer_ = buffer; 456 bound_buffer_ = buffer;
460 if (!bound_buffer_) 457 if (!bound_buffer_)
461 return; 458 return;
462 unsigned context_id = buffer >> 17; 459 unsigned context_id = buffer >> 16;
463 unsigned buffer_id = buffer & 0x1ffff; 460 unsigned buffer_id = buffer & 0xffff;
464 base::AutoLock lock(namespace_->lock); 461 base::AutoLock lock(namespace_->lock);
465 DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id); 462 DCHECK(buffer_id);
463 DCHECK_LT(buffer_id, namespace_->next_buffer_id);
466 DCHECK_EQ(context_id, context_id_); 464 DCHECK_EQ(context_id, context_id_);
467 465
468 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; 466 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
469 if (buffers.count(bound_buffer_) == 0) 467 if (buffers.count(bound_buffer_) == 0)
470 buffers.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass()); 468 buffers.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass());
471 469
472 buffers.get(bound_buffer_)->target = target; 470 buffers.get(bound_buffer_)->target = target;
473 } 471 }
474 472
475 void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target, 473 void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 WebKit::WGC3Duint image_id = NextImageId(); 522 WebKit::WGC3Duint image_id = NextImageId();
525 base::AutoLock lock(namespace_->lock); 523 base::AutoLock lock(namespace_->lock);
526 base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images; 524 base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images;
527 images.set(image_id, make_scoped_ptr(new Image).Pass()); 525 images.set(image_id, make_scoped_ptr(new Image).Pass());
528 images.get(image_id)->pixels.reset(new uint8[width * height * 4]); 526 images.get(image_id)->pixels.reset(new uint8[width * height * 4]);
529 return image_id; 527 return image_id;
530 } 528 }
531 529
532 void TestWebGraphicsContext3D::destroyImageCHROMIUM( 530 void TestWebGraphicsContext3D::destroyImageCHROMIUM(
533 WebKit::WGC3Duint id) { 531 WebKit::WGC3Duint id) {
534 base::AutoLock lock(namespace_->lock); 532 RetireImageId(id);
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 } 533 }
540 534
541 void TestWebGraphicsContext3D::getImageParameterivCHROMIUM( 535 void TestWebGraphicsContext3D::getImageParameterivCHROMIUM(
542 WebKit::WGC3Duint image_id, 536 WebKit::WGC3Duint image_id,
543 WebKit::WGC3Denum pname, 537 WebKit::WGC3Denum pname,
544 WebKit::WGC3Dint* params) { 538 WebKit::WGC3Dint* params) {
545 base::AutoLock lock(namespace_->lock); 539 base::AutoLock lock(namespace_->lock);
546 DCHECK_GT(namespace_->images.count(image_id), 0u); 540 DCHECK_GT(namespace_->images.count(image_id), 0u);
547 DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname)); 541 DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname));
548 *params = 0; 542 *params = 0;
(...skipping 30 matching lines...) Expand all
579 } 573 }
580 574
581 WebGLId TestWebGraphicsContext3D::NextTextureId() { 575 WebGLId TestWebGraphicsContext3D::NextTextureId() {
582 base::AutoLock lock(namespace_->lock); 576 base::AutoLock lock(namespace_->lock);
583 WebGLId texture_id = namespace_->next_texture_id++; 577 WebGLId texture_id = namespace_->next_texture_id++;
584 DCHECK(texture_id < (1 << 16)); 578 DCHECK(texture_id < (1 << 16));
585 texture_id |= context_id_ << 16; 579 texture_id |= context_id_ << 16;
586 return texture_id; 580 return texture_id;
587 } 581 }
588 582
583 void TestWebGraphicsContext3D::RetireTextureId(WebGLId id) {
584 base::AutoLock lock(namespace_->lock);
585 unsigned context_id = id >> 16;
586 unsigned texture_id = id & 0xffff;
587 DCHECK(texture_id);
588 DCHECK_LT(texture_id, namespace_->next_texture_id);
589 DCHECK_EQ(context_id, context_id_);
590 }
591
589 WebGLId TestWebGraphicsContext3D::NextBufferId() { 592 WebGLId TestWebGraphicsContext3D::NextBufferId() {
590 base::AutoLock lock(namespace_->lock); 593 base::AutoLock lock(namespace_->lock);
591 WebGLId buffer_id = namespace_->next_buffer_id++; 594 WebGLId buffer_id = namespace_->next_buffer_id++;
592 DCHECK(buffer_id < (1 << 17)); 595 DCHECK(buffer_id < (1 << 16));
593 buffer_id |= context_id_ << 17; 596 buffer_id |= context_id_ << 16;
594 return buffer_id; 597 return buffer_id;
595 } 598 }
596 599
600 void TestWebGraphicsContext3D::RetireBufferId(WebGLId id) {
601 base::AutoLock lock(namespace_->lock);
602 unsigned context_id = id >> 16;
603 unsigned buffer_id = id & 0xffff;
604 DCHECK(buffer_id);
605 DCHECK_LT(buffer_id, namespace_->next_buffer_id);
606 DCHECK_EQ(context_id, context_id_);
607 }
608
597 WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() { 609 WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() {
598 base::AutoLock lock(namespace_->lock); 610 base::AutoLock lock(namespace_->lock);
599 WGC3Duint image_id = namespace_->next_image_id++; 611 WGC3Duint image_id = namespace_->next_image_id++;
600 DCHECK(image_id < (1 << 17)); 612 DCHECK(image_id < (1 << 16));
601 image_id |= context_id_ << 17; 613 image_id |= context_id_ << 16;
602 return image_id; 614 return image_id;
603 } 615 }
604 616
617 void TestWebGraphicsContext3D::RetireImageId(WebGLId id) {
618 base::AutoLock lock(namespace_->lock);
619 unsigned context_id = id >> 16;
620 unsigned image_id = id & 0xffff;
621 DCHECK(image_id);
622 DCHECK_LT(image_id, namespace_->next_image_id);
623 DCHECK_EQ(context_id, context_id_);
624 }
625
605 size_t TestWebGraphicsContext3D::GetTransferBufferMemoryUsedBytes() const { 626 size_t TestWebGraphicsContext3D::GetTransferBufferMemoryUsedBytes() const {
606 size_t total_bytes = 0; 627 size_t total_bytes = 0;
607 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers; 628 base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
608 base::ScopedPtrHashMap<unsigned, Buffer>::iterator it = buffers.begin(); 629 base::ScopedPtrHashMap<unsigned, Buffer>::iterator it = buffers.begin();
609 for (; it != buffers.end(); ++it) { 630 for (; it != buffers.end(); ++it) {
610 Buffer* buffer = it->second; 631 Buffer* buffer = it->second;
611 if (buffer->target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM) 632 if (buffer->target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM)
612 total_bytes += buffer->size; 633 total_bytes += buffer->size;
613 } 634 }
614 return total_bytes; 635 return total_bytes;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 677
657 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {} 678 TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {}
658 679
659 TestWebGraphicsContext3D::Buffer::~Buffer() {} 680 TestWebGraphicsContext3D::Buffer::~Buffer() {}
660 681
661 TestWebGraphicsContext3D::Image::Image() {} 682 TestWebGraphicsContext3D::Image::Image() {}
662 683
663 TestWebGraphicsContext3D::Image::~Image() {} 684 TestWebGraphicsContext3D::Image::~Image() {}
664 685
665 } // namespace cc 686 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_web_graphics_context_3d.h ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698