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

Side by Side Diff: gpu/command_buffer/client/gles2_implementation.cc

Issue 8536045: Make command buffer free transfer buffer when switching tabs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 // A class to emulate GLES2 over command buffers. 5 // A class to emulate GLES2 over command buffers.
6 6
7 #include "../client/gles2_implementation.h" 7 #include "../client/gles2_implementation.h"
8 8
9 #include <set> 9 #include <set>
10 #include <queue> 10 #include <queue>
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 GLsizei array_buffer_offset_; 512 GLsizei array_buffer_offset_;
513 GLuint element_array_buffer_id_; 513 GLuint element_array_buffer_id_;
514 GLsizei element_array_buffer_size_; 514 GLsizei element_array_buffer_size_;
515 scoped_array<VertexAttribInfo> vertex_attrib_infos_; 515 scoped_array<VertexAttribInfo> vertex_attrib_infos_;
516 GLsizei collection_buffer_size_; 516 GLsizei collection_buffer_size_;
517 scoped_array<int8> collection_buffer_; 517 scoped_array<int8> collection_buffer_;
518 518
519 DISALLOW_COPY_AND_ASSIGN(ClientSideBufferHelper); 519 DISALLOW_COPY_AND_ASSIGN(ClientSideBufferHelper);
520 }; 520 };
521 521
522 AlignedRingBuffer::~AlignedRingBuffer() {
523 }
524
525 TransferBuffer::TransferBuffer(
526 CommandBufferHelper* helper,
527 int32 buffer_id,
528 void* buffer,
529 size_t buffer_size,
530 size_t result_size,
531 unsigned int alignment)
532 : helper_(helper),
533 buffer_size_(buffer_size),
534 result_size_(result_size),
535 alignment_(alignment) {
536 Setup(buffer_id, buffer);
537 }
538
539 TransferBuffer::~TransferBuffer() {
540 }
541
542 void TransferBuffer::Setup(int32 buffer_id, void* buffer) {
543 GPU_CHECK(!ring_buffer_.get());
544 ring_buffer_.reset(new AlignedRingBuffer(
545 alignment_,
546 buffer_id,
547 result_size_,
548 buffer_size_ - result_size_,
549 helper_,
550 static_cast<char*>(buffer) + result_size_));
551 buffer_id_ = buffer_id;
552 result_buffer_ = buffer;
553 result_shm_offset_ = 0;
554 }
555
556 void TransferBuffer::Free() {
557 if (buffer_id_) {
558 // TODO(gman): should we check the memory is unused?
559 helper_->command_buffer()->DestroyTransferBuffer(buffer_id_);
560 buffer_id_ = 0;
561 result_buffer_ = NULL;
562 result_shm_offset_ = 0;
563 ring_buffer_.reset();
564 }
565 }
566
567 void TransferBuffer::AllocateRingBuffer() {
568 if (!buffer_id_) {
569 int32 id = helper_->command_buffer()->CreateTransferBuffer(
570 buffer_size_, -1);
571 GPU_CHECK_NE(-1, id); // if it fails we're done.
572 gpu::Buffer shm = helper_->command_buffer()->GetTransferBuffer(id);
573 Setup(id, shm.ptr);
574 }
575 }
576
577 AlignedRingBuffer* TransferBuffer::GetBuffer() {
578 AllocateRingBuffer();
579 return ring_buffer_.get();
580 }
581
582 void* TransferBuffer::GetResultBuffer() {
583 AllocateRingBuffer();
584 GPU_CHECK(result_buffer_);
585 return result_buffer_;
586 }
587
588 int TransferBuffer::GetResultOffset() {
589 AllocateRingBuffer();
590 return result_shm_offset_;
591 }
592
593 int TransferBuffer::GetShmId() {
594 AllocateRingBuffer();
595 GPU_CHECK(buffer_id_);
596 return buffer_id_;
597 }
598
522 #if !defined(_MSC_VER) 599 #if !defined(_MSC_VER)
523 const size_t GLES2Implementation::kMaxSizeOfSimpleResult; 600 const size_t GLES2Implementation::kMaxSizeOfSimpleResult;
524 #endif 601 #endif
525 602
526 COMPILE_ASSERT(gpu::kInvalidResource == 0, 603 COMPILE_ASSERT(gpu::kInvalidResource == 0,
527 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); 604 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS);
528 605
529 GLES2Implementation::GLES2Implementation( 606 GLES2Implementation::GLES2Implementation(
530 GLES2CmdHelper* helper, 607 GLES2CmdHelper* helper,
531 size_t transfer_buffer_size, 608 size_t transfer_buffer_size,
532 void* transfer_buffer, 609 void* transfer_buffer,
533 int32 transfer_buffer_id, 610 int32 transfer_buffer_id,
534 bool share_resources, 611 bool share_resources,
535 bool bind_generates_resource) 612 bool bind_generates_resource)
536 : helper_(helper), 613 : helper_(helper),
537 transfer_buffer_( 614 transfer_buffer_(
538 kStartingOffset,
539 transfer_buffer_size - kStartingOffset,
540 helper, 615 helper,
541 static_cast<char*>(transfer_buffer) + kStartingOffset), 616 transfer_buffer_id,
542 transfer_buffer_id_(transfer_buffer_id), 617 transfer_buffer,
618 transfer_buffer_size,
619 GLES2Implementation::kStartingOffset,
620 GLES2Implementation::kAlignment),
543 angle_pack_reverse_row_order_status(kUnknownExtensionStatus), 621 angle_pack_reverse_row_order_status(kUnknownExtensionStatus),
544 pack_alignment_(4), 622 pack_alignment_(4),
545 unpack_alignment_(4), 623 unpack_alignment_(4),
546 unpack_flip_y_(false), 624 unpack_flip_y_(false),
547 pack_reverse_row_order_(false), 625 pack_reverse_row_order_(false),
548 active_texture_unit_(0), 626 active_texture_unit_(0),
549 bound_framebuffer_(0), 627 bound_framebuffer_(0),
550 bound_renderbuffer_(0), 628 bound_renderbuffer_(0),
551 bound_array_buffer_id_(0), 629 bound_array_buffer_id_(0),
552 bound_element_array_buffer_id_(0), 630 bound_element_array_buffer_id_(0),
553 client_side_array_id_(0), 631 client_side_array_id_(0),
554 client_side_element_array_id_(0), 632 client_side_element_array_id_(0),
555 error_bits_(0), 633 error_bits_(0),
556 debug_(false), 634 debug_(false),
557 sharing_resources_(share_resources), 635 sharing_resources_(share_resources),
558 bind_generates_resource_(bind_generates_resource) { 636 bind_generates_resource_(bind_generates_resource) {
559 GPU_CLIENT_LOG_CODE_BLOCK({ 637 GPU_CLIENT_LOG_CODE_BLOCK({
560 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( 638 debug_ = CommandLine::ForCurrentProcess()->HasSwitch(
561 switches::kEnableGPUClientLogging); 639 switches::kEnableGPUClientLogging);
562 }); 640 });
563 641
564 // Allocate space for simple GL results.
565 result_buffer_ = transfer_buffer;
566 result_shm_offset_ = 0;
567 memset(&reserved_ids_, 0, sizeof(reserved_ids_)); 642 memset(&reserved_ids_, 0, sizeof(reserved_ids_));
568 643
569 mapped_memory_.reset(new MappedMemoryManager(helper_)); 644 mapped_memory_.reset(new MappedMemoryManager(helper_));
570 SetSharedMemoryChunkSizeMultiple(1024 * 1024 * 2); 645 SetSharedMemoryChunkSizeMultiple(1024 * 1024 * 2);
571 646
572 if (share_resources) { 647 if (share_resources) {
573 if (!bind_generates_resource) { 648 if (!bind_generates_resource) {
574 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { 649 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) {
575 id_handlers_[i].reset(new StrictSharedIdHandler( 650 id_handlers_[i].reset(new StrictSharedIdHandler(
576 this, static_cast<id_namespaces::IdNamespaces>(i))); 651 this, static_cast<id_namespaces::IdNamespaces>(i)));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 713
639 void GLES2Implementation::SetSharedMemoryChunkSizeMultiple( 714 void GLES2Implementation::SetSharedMemoryChunkSizeMultiple(
640 unsigned int multiple) { 715 unsigned int multiple) {
641 mapped_memory_->set_chunk_size_multiple(multiple); 716 mapped_memory_->set_chunk_size_multiple(multiple);
642 } 717 }
643 718
644 void GLES2Implementation::FreeUnusedSharedMemory() { 719 void GLES2Implementation::FreeUnusedSharedMemory() {
645 mapped_memory_->FreeUnused(); 720 mapped_memory_->FreeUnused();
646 } 721 }
647 722
723 void GLES2Implementation::FreeEverything() {
724 Finish();
725 FreeUnusedSharedMemory();
726 transfer_buffer_.Free();
727 }
728
648 void GLES2Implementation::WaitForCmd() { 729 void GLES2Implementation::WaitForCmd() {
649 TRACE_EVENT0("gpu", "GLES2::WaitForCmd"); 730 TRACE_EVENT0("gpu", "GLES2::WaitForCmd");
650 helper_->CommandBufferHelper::Finish(); 731 helper_->CommandBufferHelper::Finish();
651 } 732 }
652 733
653 namespace { 734 namespace {
654 bool IsExtensionAvailable(GLES2Implementation* gles2, const char ext[]) { 735 bool IsExtensionAvailable(GLES2Implementation* gles2, const char ext[]) {
655 const char* extensions = reinterpret_cast<const char*>( 736 const char* extensions = reinterpret_cast<const char*>(
656 gles2->GetString(GL_EXTENSIONS)); 737 gles2->GetString(GL_EXTENSIONS));
657 int length = strlen(ext); 738 int length = strlen(ext);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 GPU_CLIENT_LOG("returned " << GLES2Util::GetStringError(err)); 772 GPU_CLIENT_LOG("returned " << GLES2Util::GetStringError(err));
692 return err; 773 return err;
693 } 774 }
694 775
695 GLenum GLES2Implementation::GetGLError() { 776 GLenum GLES2Implementation::GetGLError() {
696 TRACE_EVENT0("gpu", "GLES2::GetGLError"); 777 TRACE_EVENT0("gpu", "GLES2::GetGLError");
697 // Check the GL error first, then our wrapped error. 778 // Check the GL error first, then our wrapped error.
698 typedef gles2::GetError::Result Result; 779 typedef gles2::GetError::Result Result;
699 Result* result = GetResultAs<Result*>(); 780 Result* result = GetResultAs<Result*>();
700 *result = GL_NO_ERROR; 781 *result = GL_NO_ERROR;
701 helper_->GetError(result_shm_id(), result_shm_offset()); 782 helper_->GetError(GetResultShmId(), GetResultShmOffset());
702 WaitForCmd(); 783 WaitForCmd();
703 GLenum error = *result; 784 GLenum error = *result;
704 if (error == GL_NO_ERROR && error_bits_ != 0) { 785 if (error == GL_NO_ERROR && error_bits_ != 0) {
705 for (uint32 mask = 1; mask != 0; mask = mask << 1) { 786 for (uint32 mask = 1; mask != 0; mask = mask << 1) {
706 if ((error_bits_ & mask) != 0) { 787 if ((error_bits_ & mask) != 0) {
707 error = GLES2Util::GLErrorBitToGLError(mask); 788 error = GLES2Util::GLErrorBitToGLError(mask);
708 break; 789 break;
709 } 790 }
710 } 791 }
711 } 792 }
(...skipping 14 matching lines...) Expand all
726 error_bits_ |= GLES2Util::GLErrorToErrorBit(error); 807 error_bits_ |= GLES2Util::GLErrorToErrorBit(error);
727 } 808 }
728 809
729 void GLES2Implementation::GetBucketContents(uint32 bucket_id, 810 void GLES2Implementation::GetBucketContents(uint32 bucket_id,
730 std::vector<int8>* data) { 811 std::vector<int8>* data) {
731 TRACE_EVENT0("gpu", "GLES2::GetBucketContents"); 812 TRACE_EVENT0("gpu", "GLES2::GetBucketContents");
732 GPU_DCHECK(data); 813 GPU_DCHECK(data);
733 typedef cmd::GetBucketSize::Result Result; 814 typedef cmd::GetBucketSize::Result Result;
734 Result* result = GetResultAs<Result*>(); 815 Result* result = GetResultAs<Result*>();
735 *result = 0; 816 *result = 0;
736 helper_->GetBucketSize(bucket_id, result_shm_id(), result_shm_offset()); 817 helper_->GetBucketSize(bucket_id, GetResultShmId(), GetResultShmOffset());
737 WaitForCmd(); 818 WaitForCmd();
738 uint32 size = *result; 819 uint32 size = *result;
739 data->resize(size); 820 data->resize(size);
740 if (size > 0u) { 821 if (size > 0u) {
741 uint32 max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 822 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
823 uint32 max_size = transfer_buffer->GetLargestFreeOrPendingSize();
742 uint32 offset = 0; 824 uint32 offset = 0;
743 while (size) { 825 while (size) {
744 uint32 part_size = std::min(max_size, size); 826 uint32 part_size = std::min(max_size, size);
745 void* buffer = transfer_buffer_.Alloc(part_size); 827 void* buffer = transfer_buffer->Alloc(part_size);
746 helper_->GetBucketData( 828 helper_->GetBucketData(
747 bucket_id, offset, part_size, 829 bucket_id, offset, part_size,
748 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer)); 830 transfer_buffer->GetShmId(),
831 transfer_buffer->GetOffset(buffer));
749 WaitForCmd(); 832 WaitForCmd();
750 memcpy(&(*data)[offset], buffer, part_size); 833 memcpy(&(*data)[offset], buffer, part_size);
751 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 834 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
752 offset += part_size; 835 offset += part_size;
753 size -= part_size; 836 size -= part_size;
754 } 837 }
755 // Free the bucket. This is not required but it does free up the memory. 838 // Free the bucket. This is not required but it does free up the memory.
756 // and we don't have to wait for the result so from the client's perspective 839 // and we don't have to wait for the result so from the client's perspective
757 // it's cheap. 840 // it's cheap.
758 helper_->SetBucketSize(bucket_id, 0); 841 helper_->SetBucketSize(bucket_id, 0);
759 } 842 }
760 } 843 }
761 844
762 void GLES2Implementation::SetBucketContents( 845 void GLES2Implementation::SetBucketContents(
763 uint32 bucket_id, const void* data, size_t size) { 846 uint32 bucket_id, const void* data, size_t size) {
764 GPU_DCHECK(data); 847 GPU_DCHECK(data);
765 helper_->SetBucketSize(bucket_id, size); 848 helper_->SetBucketSize(bucket_id, size);
766 if (size > 0u) { 849 if (size > 0u) {
767 uint32 max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 850 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
851 uint32 max_size = transfer_buffer->GetLargestFreeOrPendingSize();
768 uint32 offset = 0; 852 uint32 offset = 0;
769 while (size) { 853 while (size) {
770 uint32 part_size = std::min(static_cast<size_t>(max_size), size); 854 uint32 part_size = std::min(static_cast<size_t>(max_size), size);
771 void* buffer = transfer_buffer_.Alloc(part_size); 855 void* buffer = transfer_buffer->Alloc(part_size);
772 memcpy(buffer, static_cast<const int8*>(data) + offset, part_size); 856 memcpy(buffer, static_cast<const int8*>(data) + offset, part_size);
773 helper_->SetBucketData( 857 helper_->SetBucketData(
774 bucket_id, offset, part_size, 858 bucket_id, offset, part_size,
775 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer)); 859 transfer_buffer->GetShmId(),
776 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 860 transfer_buffer->GetOffset(buffer));
861 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
777 offset += part_size; 862 offset += part_size;
778 size -= part_size; 863 size -= part_size;
779 } 864 }
780 } 865 }
781 } 866 }
782 867
783 void GLES2Implementation::SetBucketAsCString( 868 void GLES2Implementation::SetBucketAsCString(
784 uint32 bucket_id, const char* str) { 869 uint32 bucket_id, const char* str) {
785 // NOTE: strings are passed NULL terminated. That means the empty 870 // NOTE: strings are passed NULL terminated. That means the empty
786 // string will have a size of 1 and no-string will have a size of 0 871 // string will have a size of 1 and no-string will have a size of 0
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids) { 1100 GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids) {
1016 GPU_CLIENT_LOG("[" << this << "] glGenSharedIdsCHROMIUMTextures(" 1101 GPU_CLIENT_LOG("[" << this << "] glGenSharedIdsCHROMIUMTextures("
1017 << namespace_id << ", " << id_offset << ", " << n << ", " << 1102 << namespace_id << ", " << id_offset << ", " << n << ", " <<
1018 static_cast<void*>(ids) << ")"); 1103 static_cast<void*>(ids) << ")");
1019 GPU_CLIENT_LOG_CODE_BLOCK({ 1104 GPU_CLIENT_LOG_CODE_BLOCK({
1020 for (GLsizei i = 0; i < n; ++i) { 1105 for (GLsizei i = 0; i < n; ++i) {
1021 GPU_CLIENT_LOG(" " << i << ": " << ids[i]); 1106 GPU_CLIENT_LOG(" " << i << ": " << ids[i]);
1022 } 1107 }
1023 }); 1108 });
1024 TRACE_EVENT0("gpu", "GLES2::GenSharedIdsCHROMIUM"); 1109 TRACE_EVENT0("gpu", "GLES2::GenSharedIdsCHROMIUM");
1025 GLsizei max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 1110 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1111 GLsizei max_size = transfer_buffer->GetLargestFreeOrPendingSize();
1026 GLsizei max_num_per = max_size / sizeof(ids[0]); 1112 GLsizei max_num_per = max_size / sizeof(ids[0]);
1027 while (n) { 1113 while (n) {
1028 GLsizei num = std::min(n, max_num_per); 1114 GLsizei num = std::min(n, max_num_per);
1029 GLint* id_buffer = transfer_buffer_.AllocTyped<GLint>(num); 1115 GLint* id_buffer = transfer_buffer->AllocTyped<GLint>(num);
1030 helper_->GenSharedIdsCHROMIUM( 1116 helper_->GenSharedIdsCHROMIUM(
1031 namespace_id, id_offset, num, 1117 namespace_id, id_offset, num,
1032 transfer_buffer_id_, 1118 transfer_buffer->GetShmId(),
1033 transfer_buffer_.GetOffset(id_buffer)); 1119 transfer_buffer->GetOffset(id_buffer));
1034 WaitForCmd(); 1120 WaitForCmd();
1035 memcpy(ids, id_buffer, sizeof(*ids) * num); 1121 memcpy(ids, id_buffer, sizeof(*ids) * num);
1036 transfer_buffer_.FreePendingToken(id_buffer, helper_->InsertToken()); 1122 transfer_buffer->FreePendingToken(id_buffer, helper_->InsertToken());
1037 n -= num; 1123 n -= num;
1038 ids += num; 1124 ids += num;
1039 } 1125 }
1040 } 1126 }
1041 1127
1042 void GLES2Implementation::DeleteSharedIdsCHROMIUM( 1128 void GLES2Implementation::DeleteSharedIdsCHROMIUM(
1043 GLuint namespace_id, GLsizei n, const GLuint* ids) { 1129 GLuint namespace_id, GLsizei n, const GLuint* ids) {
1044 GPU_CLIENT_LOG("[" << this << "] glDeleteSharedIdsCHROMIUM(" 1130 GPU_CLIENT_LOG("[" << this << "] glDeleteSharedIdsCHROMIUM("
1045 << namespace_id << ", " << n << ", " 1131 << namespace_id << ", " << n << ", "
1046 << static_cast<const void*>(ids) << ")"); 1132 << static_cast<const void*>(ids) << ")");
1047 GPU_CLIENT_LOG_CODE_BLOCK({ 1133 GPU_CLIENT_LOG_CODE_BLOCK({
1048 for (GLsizei i = 0; i < n; ++i) { 1134 for (GLsizei i = 0; i < n; ++i) {
1049 GPU_CLIENT_LOG(" " << i << ": " << ids[i]); 1135 GPU_CLIENT_LOG(" " << i << ": " << ids[i]);
1050 } 1136 }
1051 }); 1137 });
1052 TRACE_EVENT0("gpu", "GLES2::DeleteSharedIdsCHROMIUM"); 1138 TRACE_EVENT0("gpu", "GLES2::DeleteSharedIdsCHROMIUM");
1053 GLsizei max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 1139 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1140 GLsizei max_size = transfer_buffer->GetLargestFreeOrPendingSize();
1054 GLsizei max_num_per = max_size / sizeof(ids[0]); 1141 GLsizei max_num_per = max_size / sizeof(ids[0]);
1055 while (n) { 1142 while (n) {
1056 GLsizei num = std::min(n, max_num_per); 1143 GLsizei num = std::min(n, max_num_per);
1057 GLint* id_buffer = transfer_buffer_.AllocTyped<GLint>(num); 1144 GLint* id_buffer = transfer_buffer->AllocTyped<GLint>(num);
1058 memcpy(id_buffer, ids, sizeof(*ids) * num); 1145 memcpy(id_buffer, ids, sizeof(*ids) * num);
1059 helper_->DeleteSharedIdsCHROMIUM( 1146 helper_->DeleteSharedIdsCHROMIUM(
1060 namespace_id, num, 1147 namespace_id, num,
1061 transfer_buffer_id_, 1148 transfer_buffer->GetShmId(),
1062 transfer_buffer_.GetOffset(id_buffer)); 1149 transfer_buffer->GetOffset(id_buffer));
1063 WaitForCmd(); 1150 WaitForCmd();
1064 transfer_buffer_.FreePendingToken(id_buffer, helper_->InsertToken()); 1151 transfer_buffer->FreePendingToken(id_buffer, helper_->InsertToken());
1065 n -= num; 1152 n -= num;
1066 ids += num; 1153 ids += num;
1067 } 1154 }
1068 } 1155 }
1069 1156
1070 void GLES2Implementation::RegisterSharedIdsCHROMIUM( 1157 void GLES2Implementation::RegisterSharedIdsCHROMIUM(
1071 GLuint namespace_id, GLsizei n, const GLuint* ids) { 1158 GLuint namespace_id, GLsizei n, const GLuint* ids) {
1072 GPU_CLIENT_LOG("[" << this << "] glRegisterSharedIdsCHROMIUM(" 1159 GPU_CLIENT_LOG("[" << this << "] glRegisterSharedIdsCHROMIUM("
1073 << namespace_id << ", " << n << ", " 1160 << namespace_id << ", " << n << ", "
1074 << static_cast<const void*>(ids) << ")"); 1161 << static_cast<const void*>(ids) << ")");
1075 GPU_CLIENT_LOG_CODE_BLOCK({ 1162 GPU_CLIENT_LOG_CODE_BLOCK({
1076 for (GLsizei i = 0; i < n; ++i) { 1163 for (GLsizei i = 0; i < n; ++i) {
1077 GPU_CLIENT_LOG(" " << i << ": " << ids[i]); 1164 GPU_CLIENT_LOG(" " << i << ": " << ids[i]);
1078 } 1165 }
1079 }); 1166 });
1080 TRACE_EVENT0("gpu", "GLES2::RegisterSharedIdsCHROMIUM"); 1167 TRACE_EVENT0("gpu", "GLES2::RegisterSharedIdsCHROMIUM");
1081 GLsizei max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 1168 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1169 GLsizei max_size = transfer_buffer->GetLargestFreeOrPendingSize();
1082 GLsizei max_num_per = max_size / sizeof(ids[0]); 1170 GLsizei max_num_per = max_size / sizeof(ids[0]);
1083 while (n) { 1171 while (n) {
1084 GLsizei num = std::min(n, max_num_per); 1172 GLsizei num = std::min(n, max_num_per);
1085 GLint* id_buffer = transfer_buffer_.AllocTyped<GLint>(n); 1173 GLint* id_buffer = transfer_buffer->AllocTyped<GLint>(n);
1086 memcpy(id_buffer, ids, sizeof(*ids) * n); 1174 memcpy(id_buffer, ids, sizeof(*ids) * n);
1087 helper_->RegisterSharedIdsCHROMIUM( 1175 helper_->RegisterSharedIdsCHROMIUM(
1088 namespace_id, n, 1176 namespace_id, n,
1089 transfer_buffer_id_, 1177 transfer_buffer->GetShmId(),
1090 transfer_buffer_.GetOffset(id_buffer)); 1178 transfer_buffer->GetOffset(id_buffer));
1091 WaitForCmd(); 1179 WaitForCmd();
1092 transfer_buffer_.FreePendingToken(id_buffer, helper_->InsertToken()); 1180 transfer_buffer->FreePendingToken(id_buffer, helper_->InsertToken());
1093 n -= num; 1181 n -= num;
1094 ids += num; 1182 ids += num;
1095 } 1183 }
1096 } 1184 }
1097 1185
1098 void GLES2Implementation::BindAttribLocation( 1186 void GLES2Implementation::BindAttribLocation(
1099 GLuint program, GLuint index, const char* name) { 1187 GLuint program, GLuint index, const char* name) {
1100 GPU_CLIENT_LOG("[" << this << "] glBindAttribLocation(" << program << ", " 1188 GPU_CLIENT_LOG("[" << this << "] glBindAttribLocation(" << program << ", "
1101 << index << ", " << name << ")"); 1189 << index << ", " << name << ")");
1102 SetBucketAsString(kResultBucketId, name); 1190 SetBucketAsString(kResultBucketId, name);
(...skipping 12 matching lines...) Expand all
1115 if (client_side_buffer_helper_->GetAttribPointer(index, pname, ptr)) { 1203 if (client_side_buffer_helper_->GetAttribPointer(index, pname, ptr)) {
1116 return; 1204 return;
1117 } 1205 }
1118 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) 1206 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
1119 1207
1120 TRACE_EVENT0("gpu", "GLES2::GetVertexAttribPointerv"); 1208 TRACE_EVENT0("gpu", "GLES2::GetVertexAttribPointerv");
1121 typedef gles2::GetVertexAttribPointerv::Result Result; 1209 typedef gles2::GetVertexAttribPointerv::Result Result;
1122 Result* result = GetResultAs<Result*>(); 1210 Result* result = GetResultAs<Result*>();
1123 result->SetNumResults(0); 1211 result->SetNumResults(0);
1124 helper_->GetVertexAttribPointerv( 1212 helper_->GetVertexAttribPointerv(
1125 index, pname, result_shm_id(), result_shm_offset()); 1213 index, pname, GetResultShmId(), GetResultShmOffset());
1126 WaitForCmd(); 1214 WaitForCmd();
1127 result->CopyResult(ptr); 1215 result->CopyResult(ptr);
1128 GPU_CLIENT_LOG_CODE_BLOCK({ 1216 GPU_CLIENT_LOG_CODE_BLOCK({
1129 for (int32 i = 0; i < result->GetNumResults(); ++i) { 1217 for (int32 i = 0; i < result->GetNumResults(); ++i) {
1130 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]); 1218 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]);
1131 } 1219 }
1132 }); 1220 });
1133 } 1221 }
1134 1222
1135 bool GLES2Implementation::DeleteProgramHelper(GLuint program) { 1223 bool GLES2Implementation::DeleteProgramHelper(GLuint program) {
(...skipping 20 matching lines...) Expand all
1156 return true; 1244 return true;
1157 } 1245 }
1158 1246
1159 GLint GLES2Implementation::GetAttribLocationHelper( 1247 GLint GLES2Implementation::GetAttribLocationHelper(
1160 GLuint program, const char* name) { 1248 GLuint program, const char* name) {
1161 typedef GetAttribLocationBucket::Result Result; 1249 typedef GetAttribLocationBucket::Result Result;
1162 Result* result = GetResultAs<Result*>(); 1250 Result* result = GetResultAs<Result*>();
1163 *result = -1; 1251 *result = -1;
1164 SetBucketAsCString(kResultBucketId, name); 1252 SetBucketAsCString(kResultBucketId, name);
1165 helper_->GetAttribLocationBucket( 1253 helper_->GetAttribLocationBucket(
1166 program, kResultBucketId, result_shm_id(), result_shm_offset()); 1254 program, kResultBucketId, GetResultShmId(), GetResultShmOffset());
1167 WaitForCmd(); 1255 WaitForCmd();
1168 helper_->SetBucketSize(kResultBucketId, 0); 1256 helper_->SetBucketSize(kResultBucketId, 0);
1169 return *result; 1257 return *result;
1170 } 1258 }
1171 1259
1172 GLint GLES2Implementation::GetAttribLocation( 1260 GLint GLES2Implementation::GetAttribLocation(
1173 GLuint program, const char* name) { 1261 GLuint program, const char* name) {
1174 GPU_CLIENT_LOG("[" << this << "] glGetAttribLocation(" << program 1262 GPU_CLIENT_LOG("[" << this << "] glGetAttribLocation(" << program
1175 << ", " << name << ")"); 1263 << ", " << name << ")");
1176 TRACE_EVENT0("gpu", "GLES2::GetAttribLocation"); 1264 TRACE_EVENT0("gpu", "GLES2::GetAttribLocation");
1177 GLint loc = program_info_manager_->GetAttribLocation(this, program, name); 1265 GLint loc = program_info_manager_->GetAttribLocation(this, program, name);
1178 GPU_CLIENT_LOG("returned " << loc); 1266 GPU_CLIENT_LOG("returned " << loc);
1179 return loc; 1267 return loc;
1180 } 1268 }
1181 1269
1182 GLint GLES2Implementation::GetUniformLocationHelper( 1270 GLint GLES2Implementation::GetUniformLocationHelper(
1183 GLuint program, const char* name) { 1271 GLuint program, const char* name) {
1184 typedef GetUniformLocationBucket::Result Result; 1272 typedef GetUniformLocationBucket::Result Result;
1185 Result* result = GetResultAs<Result*>(); 1273 Result* result = GetResultAs<Result*>();
1186 *result = -1; 1274 *result = -1;
1187 SetBucketAsCString(kResultBucketId, name); 1275 SetBucketAsCString(kResultBucketId, name);
1188 helper_->GetUniformLocationBucket(program, kResultBucketId, 1276 helper_->GetUniformLocationBucket(program, kResultBucketId,
1189 result_shm_id(), result_shm_offset()); 1277 GetResultShmId(), GetResultShmOffset());
1190 WaitForCmd(); 1278 WaitForCmd();
1191 helper_->SetBucketSize(kResultBucketId, 0); 1279 helper_->SetBucketSize(kResultBucketId, 0);
1192 return *result; 1280 return *result;
1193 } 1281 }
1194 1282
1195 GLint GLES2Implementation::GetUniformLocation( 1283 GLint GLES2Implementation::GetUniformLocation(
1196 GLuint program, const char* name) { 1284 GLuint program, const char* name) {
1197 GPU_CLIENT_LOG("[" << this << "] glGetUniformLocation(" << program 1285 GPU_CLIENT_LOG("[" << this << "] glGetUniformLocation(" << program
1198 << ", " << name << ")"); 1286 << ", " << name << ")");
1199 TRACE_EVENT0("gpu", "GLES2::GetUniformLocation"); 1287 TRACE_EVENT0("gpu", "GLES2::GetUniformLocation");
(...skipping 23 matching lines...) Expand all
1223 << length << ")"); 1311 << length << ")");
1224 if (n < 0) { 1312 if (n < 0) {
1225 SetGLError(GL_INVALID_VALUE, "glShaderBinary n < 0."); 1313 SetGLError(GL_INVALID_VALUE, "glShaderBinary n < 0.");
1226 return; 1314 return;
1227 } 1315 }
1228 if (length < 0) { 1316 if (length < 0) {
1229 SetGLError(GL_INVALID_VALUE, "glShaderBinary length < 0."); 1317 SetGLError(GL_INVALID_VALUE, "glShaderBinary length < 0.");
1230 return; 1318 return;
1231 } 1319 }
1232 GLsizei shader_id_size = n * sizeof(*shaders); 1320 GLsizei shader_id_size = n * sizeof(*shaders);
1233 int8* buffer = transfer_buffer_.AllocTyped<int8>(shader_id_size + length); 1321 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1322 int8* buffer = transfer_buffer->AllocTyped<int8>(shader_id_size + length);
1234 void* shader_ids = buffer; 1323 void* shader_ids = buffer;
1235 void* shader_data = buffer + shader_id_size; 1324 void* shader_data = buffer + shader_id_size;
1236 memcpy(shader_ids, shaders, shader_id_size); 1325 memcpy(shader_ids, shaders, shader_id_size);
1237 memcpy(shader_data, binary, length); 1326 memcpy(shader_data, binary, length);
1238 helper_->ShaderBinary( 1327 helper_->ShaderBinary(
1239 n, 1328 n,
1240 transfer_buffer_id_, transfer_buffer_.GetOffset(shader_ids), 1329 transfer_buffer->GetShmId(),
1330 transfer_buffer->GetOffset(shader_ids),
1241 binaryformat, 1331 binaryformat,
1242 transfer_buffer_id_, transfer_buffer_.GetOffset(shader_data), 1332 transfer_buffer->GetShmId(),
1333 transfer_buffer->GetOffset(shader_data),
1243 length); 1334 length);
1244 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 1335 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
1245 } 1336 }
1246 1337
1247 void GLES2Implementation::PixelStorei(GLenum pname, GLint param) { 1338 void GLES2Implementation::PixelStorei(GLenum pname, GLint param) {
1248 GPU_CLIENT_LOG("[" << this << "] glPixelStorei(" 1339 GPU_CLIENT_LOG("[" << this << "] glPixelStorei("
1249 << GLES2Util::GetStringPixelStore(pname) << ", " 1340 << GLES2Util::GetStringPixelStore(pname) << ", "
1250 << param << ")"); 1341 << param << ")");
1251 switch (pname) { 1342 switch (pname) {
1252 case GL_PACK_ALIGNMENT: 1343 case GL_PACK_ALIGNMENT:
1253 pack_alignment_ = param; 1344 pack_alignment_ = param;
1254 break; 1345 break;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 uint32 total_size = 1; 1418 uint32 total_size = 1;
1328 for (GLsizei ii = 0; ii < count; ++ii) { 1419 for (GLsizei ii = 0; ii < count; ++ii) {
1329 if (source[ii]) { 1420 if (source[ii]) {
1330 total_size += (length && length[ii] >= 0) ? 1421 total_size += (length && length[ii] >= 0) ?
1331 static_cast<size_t>(length[ii]) : strlen(source[ii]); 1422 static_cast<size_t>(length[ii]) : strlen(source[ii]);
1332 } 1423 }
1333 } 1424 }
1334 1425
1335 // Concatenate all the strings in to a bucket on the service. 1426 // Concatenate all the strings in to a bucket on the service.
1336 helper_->SetBucketSize(kResultBucketId, total_size); 1427 helper_->SetBucketSize(kResultBucketId, total_size);
1337 uint32 max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 1428 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1429 uint32 max_size = transfer_buffer->GetLargestFreeOrPendingSize();
1338 uint32 offset = 0; 1430 uint32 offset = 0;
1339 for (GLsizei ii = 0; ii <= count; ++ii) { 1431 for (GLsizei ii = 0; ii <= count; ++ii) {
1340 const char* src = ii < count ? source[ii] : ""; 1432 const char* src = ii < count ? source[ii] : "";
1341 if (src) { 1433 if (src) {
1342 uint32 size = ii < count ? 1434 uint32 size = ii < count ?
1343 (length ? static_cast<size_t>(length[ii]) : strlen(src)) : 1; 1435 (length ? static_cast<size_t>(length[ii]) : strlen(src)) : 1;
1344 while (size) { 1436 while (size) {
1345 uint32 part_size = std::min(size, max_size); 1437 uint32 part_size = std::min(size, max_size);
1346 void* buffer = transfer_buffer_.Alloc(part_size); 1438 void* buffer = transfer_buffer->Alloc(part_size);
1347 memcpy(buffer, src, part_size); 1439 memcpy(buffer, src, part_size);
1348 helper_->SetBucketData(kResultBucketId, offset, part_size, 1440 helper_->SetBucketData(kResultBucketId, offset, part_size,
1349 transfer_buffer_id_, 1441 transfer_buffer->GetShmId(),
1350 transfer_buffer_.GetOffset(buffer)); 1442 transfer_buffer->GetOffset(buffer));
1351 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 1443 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
1352 offset += part_size; 1444 offset += part_size;
1353 src += part_size; 1445 src += part_size;
1354 size -= part_size; 1446 size -= part_size;
1355 } 1447 }
1356 } 1448 }
1357 } 1449 }
1358 1450
1359 GPU_DCHECK_EQ(total_size, offset); 1451 GPU_DCHECK_EQ(total_size, offset);
1360 1452
1361 helper_->ShaderSourceBucket(shader, kResultBucketId); 1453 helper_->ShaderSourceBucket(shader, kResultBucketId);
1362 helper_->SetBucketSize(kResultBucketId, 0); 1454 helper_->SetBucketSize(kResultBucketId, 0);
1363 } 1455 }
1364 1456
1365 void GLES2Implementation::BufferData( 1457 void GLES2Implementation::BufferData(
1366 GLenum target, GLsizeiptr size, const void* data, GLenum usage) { 1458 GLenum target, GLsizeiptr size, const void* data, GLenum usage) {
1367 GPU_CLIENT_LOG("[" << this << "] glBufferData(" 1459 GPU_CLIENT_LOG("[" << this << "] glBufferData("
1368 << GLES2Util::GetStringBufferTarget(target) << ", " 1460 << GLES2Util::GetStringBufferTarget(target) << ", "
1369 << size << ", " 1461 << size << ", "
1370 << static_cast<const void*>(data) << ", " 1462 << static_cast<const void*>(data) << ", "
1371 << GLES2Util::GetStringBufferUsage(usage) << ")"); 1463 << GLES2Util::GetStringBufferUsage(usage) << ")");
1372 GLsizeiptr max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 1464 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1465 GLsizeiptr max_size = transfer_buffer->GetLargestFreeOrPendingSize();
1373 if (size > max_size || !data) { 1466 if (size > max_size || !data) {
1374 helper_->BufferData(target, size, 0, 0, usage); 1467 helper_->BufferData(target, size, 0, 0, usage);
1375 if (data != NULL) { 1468 if (data != NULL) {
1376 BufferSubData(target, 0, size, data); 1469 BufferSubData(target, 0, size, data);
1377 } 1470 }
1378 return; 1471 return;
1379 } 1472 }
1380 1473
1381 void* buffer = transfer_buffer_.Alloc(size); 1474 void* buffer = transfer_buffer->Alloc(size);
1382 memcpy(buffer, data, size); 1475 memcpy(buffer, data, size);
1383 helper_->BufferData( 1476 helper_->BufferData(
1384 target, 1477 target,
1385 size, 1478 size,
1386 transfer_buffer_id_, 1479 transfer_buffer->GetShmId(),
1387 transfer_buffer_.GetOffset(buffer), 1480 transfer_buffer->GetOffset(buffer),
1388 usage); 1481 usage);
1389 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 1482 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
1390 } 1483 }
1391 1484
1392 void GLES2Implementation::BufferSubData( 1485 void GLES2Implementation::BufferSubData(
1393 GLenum target, GLintptr offset, GLsizeiptr size, const void* data) { 1486 GLenum target, GLintptr offset, GLsizeiptr size, const void* data) {
1394 GPU_CLIENT_LOG("[" << this << "] glBufferSubData(" 1487 GPU_CLIENT_LOG("[" << this << "] glBufferSubData("
1395 << GLES2Util::GetStringBufferTarget(target) << ", " 1488 << GLES2Util::GetStringBufferTarget(target) << ", "
1396 << offset << ", " << size << ", " 1489 << offset << ", " << size << ", "
1397 << static_cast<const void*>(data) << ")"); 1490 << static_cast<const void*>(data) << ")");
1398 if (size == 0) { 1491 if (size == 0) {
1399 return; 1492 return;
1400 } 1493 }
1401 1494
1402 if (size < 0) { 1495 if (size < 0) {
1403 SetGLError(GL_INVALID_VALUE, "glBufferSubData: size < 0"); 1496 SetGLError(GL_INVALID_VALUE, "glBufferSubData: size < 0");
1404 return; 1497 return;
1405 } 1498 }
1406 1499
1407 const int8* source = static_cast<const int8*>(data); 1500 const int8* source = static_cast<const int8*>(data);
1408 GLsizeiptr max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 1501 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1502 GLsizeiptr max_size = transfer_buffer->GetLargestFreeOrPendingSize();
1409 while (size) { 1503 while (size) {
1410 GLsizeiptr part_size = std::min(size, max_size); 1504 GLsizeiptr part_size = std::min(size, max_size);
1411 void* buffer = transfer_buffer_.Alloc(part_size); 1505 void* buffer = transfer_buffer->Alloc(part_size);
1412 memcpy(buffer, source, part_size); 1506 memcpy(buffer, source, part_size);
1413 helper_->BufferSubData(target, offset, part_size, 1507 helper_->BufferSubData(target, offset, part_size,
1414 transfer_buffer_id_, 1508 transfer_buffer->GetShmId(),
1415 transfer_buffer_.GetOffset(buffer)); 1509 transfer_buffer->GetOffset(buffer));
1416 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 1510 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
1417 offset += part_size; 1511 offset += part_size;
1418 source += part_size; 1512 source += part_size;
1419 size -= part_size; 1513 size -= part_size;
1420 } 1514 }
1421 } 1515 }
1422 1516
1423 void GLES2Implementation::CompressedTexImage2D( 1517 void GLES2Implementation::CompressedTexImage2D(
1424 GLenum target, GLint level, GLenum internalformat, GLsizei width, 1518 GLenum target, GLint level, GLenum internalformat, GLsizei width,
1425 GLsizei height, GLint border, GLsizei image_size, const void* data) { 1519 GLsizei height, GLint border, GLsizei image_size, const void* data) {
1426 GPU_CLIENT_LOG("[" << this << "] glCompressedTexImage2D(" 1520 GPU_CLIENT_LOG("[" << this << "] glCompressedTexImage2D("
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 return; 1620 return;
1527 } 1621 }
1528 uint32 size; 1622 uint32 size;
1529 if (!GLES2Util::ComputeImageDataSize( 1623 if (!GLES2Util::ComputeImageDataSize(
1530 width, height, format, type, unpack_alignment_, &size)) { 1624 width, height, format, type, unpack_alignment_, &size)) {
1531 SetGLError(GL_INVALID_VALUE, "glTexImage2D: image size too large"); 1625 SetGLError(GL_INVALID_VALUE, "glTexImage2D: image size too large");
1532 return; 1626 return;
1533 } 1627 }
1534 1628
1535 // Check if we can send it all at once. 1629 // Check if we can send it all at once.
1536 unsigned int max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 1630 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1631 unsigned int max_size = transfer_buffer->GetLargestFreeOrPendingSize();
1537 if (size > max_size || !pixels) { 1632 if (size > max_size || !pixels) {
1538 // No, so send it using TexSubImage2D. 1633 // No, so send it using TexSubImage2D.
1539 helper_->TexImage2D( 1634 helper_->TexImage2D(
1540 target, level, internalformat, width, height, border, format, type, 1635 target, level, internalformat, width, height, border, format, type,
1541 0, 0); 1636 0, 0);
1542 if (pixels) { 1637 if (pixels) {
1543 TexSubImage2DImpl( 1638 TexSubImage2DImpl(
1544 target, level, 0, 0, width, height, format, type, pixels, GL_TRUE); 1639 target, level, 0, 0, width, height, format, type, pixels, GL_TRUE);
1545 } 1640 }
1546 return; 1641 return;
1547 } 1642 }
1548 1643
1549 void* buffer = transfer_buffer_.Alloc(size); 1644 void* buffer = transfer_buffer->Alloc(size);
1550 bool copy_success = true; 1645 bool copy_success = true;
1551 if (unpack_flip_y_) { 1646 if (unpack_flip_y_) {
1552 copy_success = CopyRectToBufferFlipped( 1647 copy_success = CopyRectToBufferFlipped(
1553 pixels, width, height, format, type, buffer); 1648 pixels, width, height, format, type, buffer);
1554 } else { 1649 } else {
1555 memcpy(buffer, pixels, size); 1650 memcpy(buffer, pixels, size);
1556 } 1651 }
1557 1652
1558 if (copy_success) { 1653 if (copy_success) {
1559 helper_->TexImage2D( 1654 helper_->TexImage2D(
1560 target, level, internalformat, width, height, border, format, type, 1655 target, level, internalformat, width, height, border, format, type,
1561 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer)); 1656 transfer_buffer->GetShmId(), transfer_buffer->GetOffset(buffer));
1562 } 1657 }
1563 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 1658 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
1564 } 1659 }
1565 1660
1566 void GLES2Implementation::TexSubImage2D( 1661 void GLES2Implementation::TexSubImage2D(
1567 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, 1662 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
1568 GLsizei height, GLenum format, GLenum type, const void* pixels) { 1663 GLsizei height, GLenum format, GLenum type, const void* pixels) {
1569 GPU_CLIENT_LOG("[" << this << "] glTexSubImage2D(" 1664 GPU_CLIENT_LOG("[" << this << "] glTexSubImage2D("
1570 << GLES2Util::GetStringTextureTarget(target) << ", " 1665 << GLES2Util::GetStringTextureTarget(target) << ", "
1571 << level << ", " 1666 << level << ", "
1572 << xoffset << ", " << yoffset << ", " 1667 << xoffset << ", " << yoffset << ", "
1573 << width << ", " << height << ", " 1668 << width << ", " << height << ", "
(...skipping 10 matching lines...) Expand all
1584 GLsizei height, GLenum format, GLenum type, const void* pixels, 1679 GLsizei height, GLenum format, GLenum type, const void* pixels,
1585 GLboolean internal) { 1680 GLboolean internal) {
1586 if (level < 0 || height < 0 || width < 0) { 1681 if (level < 0 || height < 0 || width < 0) {
1587 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D dimension < 0"); 1682 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D dimension < 0");
1588 return; 1683 return;
1589 } 1684 }
1590 if (height == 0 || width == 0) { 1685 if (height == 0 || width == 0) {
1591 return; 1686 return;
1592 } 1687 }
1593 const int8* source = static_cast<const int8*>(pixels); 1688 const int8* source = static_cast<const int8*>(pixels);
1594 GLsizeiptr max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 1689 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1690 GLsizeiptr max_size = transfer_buffer->GetLargestFreeOrPendingSize();
1595 uint32 temp_size; 1691 uint32 temp_size;
1596 if (!GLES2Util::ComputeImageDataSize( 1692 if (!GLES2Util::ComputeImageDataSize(
1597 width, 1, format, type, unpack_alignment_, &temp_size)) { 1693 width, 1, format, type, unpack_alignment_, &temp_size)) {
1598 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large"); 1694 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large");
1599 return; 1695 return;
1600 } 1696 }
1601 GLsizeiptr unpadded_row_size = temp_size; 1697 GLsizeiptr unpadded_row_size = temp_size;
1602 if (!GLES2Util::ComputeImageDataSize( 1698 if (!GLES2Util::ComputeImageDataSize(
1603 width, 2, format, type, unpack_alignment_, &temp_size)) { 1699 width, 2, format, type, unpack_alignment_, &temp_size)) {
1604 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large"); 1700 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large");
1605 return; 1701 return;
1606 } 1702 }
1607 GLsizeiptr padded_row_size = temp_size - unpadded_row_size; 1703 GLsizeiptr padded_row_size = temp_size - unpadded_row_size;
1608 if (padded_row_size < 0 || unpadded_row_size < 0) { 1704 if (padded_row_size < 0 || unpadded_row_size < 0) {
1609 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large"); 1705 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: size to large");
1610 return; 1706 return;
1611 } 1707 }
1612 1708
1613 GLint original_yoffset = yoffset; 1709 GLint original_yoffset = yoffset;
1614 if (padded_row_size <= max_size) { 1710 if (padded_row_size <= max_size) {
1615 // Transfer by rows. 1711 // Transfer by rows.
1616 GLint max_rows = max_size / std::max(padded_row_size, 1712 GLint max_rows = max_size / std::max(padded_row_size,
1617 static_cast<GLsizeiptr>(1)); 1713 static_cast<GLsizeiptr>(1));
1618 while (height) { 1714 while (height) {
1619 GLint num_rows = std::min(height, max_rows); 1715 GLint num_rows = std::min(height, max_rows);
1620 GLsizeiptr part_size = 1716 GLsizeiptr part_size =
1621 (num_rows - 1) * padded_row_size + unpadded_row_size; 1717 (num_rows - 1) * padded_row_size + unpadded_row_size;
1622 void* buffer = transfer_buffer_.Alloc(part_size); 1718 void* buffer = transfer_buffer->Alloc(part_size);
1623 GLint y; 1719 GLint y;
1624 if (unpack_flip_y_) { 1720 if (unpack_flip_y_) {
1625 CopyRectToBufferFlipped( 1721 CopyRectToBufferFlipped(
1626 source, width, num_rows, format, type, buffer); 1722 source, width, num_rows, format, type, buffer);
1627 // GPU_DCHECK(copy_success); // can't check this because bot fails! 1723 // GPU_DCHECK(copy_success); // can't check this because bot fails!
1628 y = original_yoffset + height - num_rows; 1724 y = original_yoffset + height - num_rows;
1629 } else { 1725 } else {
1630 memcpy(buffer, source, part_size); 1726 memcpy(buffer, source, part_size);
1631 y = yoffset; 1727 y = yoffset;
1632 } 1728 }
1633 helper_->TexSubImage2D( 1729 helper_->TexSubImage2D(
1634 target, level, xoffset, y, width, num_rows, format, type, 1730 target, level, xoffset, y, width, num_rows, format, type,
1635 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), internal); 1731 transfer_buffer->GetShmId(),
1636 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 1732 transfer_buffer->GetOffset(buffer), internal);
1733 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
1637 yoffset += num_rows; 1734 yoffset += num_rows;
1638 source += num_rows * padded_row_size; 1735 source += num_rows * padded_row_size;
1639 height -= num_rows; 1736 height -= num_rows;
1640 } 1737 }
1641 } else { 1738 } else {
1642 // Transfer by sub rows. Because GL has no maximum texture dimensions. 1739 // Transfer by sub rows. Because GL has no maximum texture dimensions.
1643 uint32 temp; 1740 uint32 temp;
1644 GLES2Util::ComputeImageDataSize( 1741 GLES2Util::ComputeImageDataSize(
1645 1, 1, format, type, unpack_alignment_, &temp); 1742 1, 1, format, type, unpack_alignment_, &temp);
1646 GLsizeiptr element_size = temp; 1743 GLsizeiptr element_size = temp;
1647 max_size -= max_size % element_size; 1744 max_size -= max_size % element_size;
1648 GLint max_sub_row_pixels = max_size / element_size; 1745 GLint max_sub_row_pixels = max_size / element_size;
1649 for (; height; --height) { 1746 for (; height; --height) {
1650 GLint temp_width = width; 1747 GLint temp_width = width;
1651 GLint temp_xoffset = xoffset; 1748 GLint temp_xoffset = xoffset;
1652 const int8* row_source = source; 1749 const int8* row_source = source;
1653 while (temp_width) { 1750 while (temp_width) {
1654 GLint num_pixels = std::min(width, max_sub_row_pixels); 1751 GLint num_pixels = std::min(width, max_sub_row_pixels);
1655 GLsizeiptr part_size = num_pixels * element_size; 1752 GLsizeiptr part_size = num_pixels * element_size;
1656 void* buffer = transfer_buffer_.Alloc(part_size); 1753 void* buffer = transfer_buffer->Alloc(part_size);
1657 memcpy(buffer, row_source, part_size); 1754 memcpy(buffer, row_source, part_size);
1658 GLint y = unpack_flip_y_ ? (original_yoffset + height - 1) : yoffset; 1755 GLint y = unpack_flip_y_ ? (original_yoffset + height - 1) : yoffset;
1659 helper_->TexSubImage2D( 1756 helper_->TexSubImage2D(
1660 target, level, temp_xoffset, y, num_pixels, 1, format, type, 1757 target, level, temp_xoffset, y, num_pixels, 1, format, type,
1661 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), internal); 1758 transfer_buffer->GetShmId(),
1662 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 1759 transfer_buffer->GetOffset(buffer), internal);
1760 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
1663 row_source += part_size; 1761 row_source += part_size;
1664 temp_xoffset += num_pixels; 1762 temp_xoffset += num_pixels;
1665 temp_width -= num_pixels; 1763 temp_width -= num_pixels;
1666 } 1764 }
1667 ++yoffset; 1765 ++yoffset;
1668 source += padded_row_size; 1766 source += padded_row_size;
1669 } 1767 }
1670 } 1768 }
1671 } 1769 }
1672 1770
1673 bool GLES2Implementation::GetActiveAttribHelper( 1771 bool GLES2Implementation::GetActiveAttribHelper(
1674 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, 1772 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size,
1675 GLenum* type, char* name) { 1773 GLenum* type, char* name) {
1676 // Clear the bucket so if the command fails nothing will be in it. 1774 // Clear the bucket so if the command fails nothing will be in it.
1677 helper_->SetBucketSize(kResultBucketId, 0); 1775 helper_->SetBucketSize(kResultBucketId, 0);
1678 typedef gles2::GetActiveAttrib::Result Result; 1776 typedef gles2::GetActiveAttrib::Result Result;
1679 Result* result = static_cast<Result*>(result_buffer_); 1777 Result* result = GetResultAs<Result*>();
1680 // Set as failed so if the command fails we'll recover. 1778 // Set as failed so if the command fails we'll recover.
1681 result->success = false; 1779 result->success = false;
1682 helper_->GetActiveAttrib(program, index, kResultBucketId, 1780 helper_->GetActiveAttrib(program, index, kResultBucketId,
1683 result_shm_id(), result_shm_offset()); 1781 GetResultShmId(), GetResultShmOffset());
1684 WaitForCmd(); 1782 WaitForCmd();
1685 if (result->success) { 1783 if (result->success) {
1686 if (size) { 1784 if (size) {
1687 *size = result->size; 1785 *size = result->size;
1688 } 1786 }
1689 if (type) { 1787 if (type) {
1690 *type = result->type; 1788 *type = result->type;
1691 } 1789 }
1692 if (length || name) { 1790 if (length || name) {
1693 std::vector<int8> str; 1791 std::vector<int8> str;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 } 1833 }
1736 } 1834 }
1737 } 1835 }
1738 1836
1739 bool GLES2Implementation::GetActiveUniformHelper( 1837 bool GLES2Implementation::GetActiveUniformHelper(
1740 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, 1838 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size,
1741 GLenum* type, char* name) { 1839 GLenum* type, char* name) {
1742 // Clear the bucket so if the command fails nothing will be in it. 1840 // Clear the bucket so if the command fails nothing will be in it.
1743 helper_->SetBucketSize(kResultBucketId, 0); 1841 helper_->SetBucketSize(kResultBucketId, 0);
1744 typedef gles2::GetActiveUniform::Result Result; 1842 typedef gles2::GetActiveUniform::Result Result;
1745 Result* result = static_cast<Result*>(result_buffer_); 1843 Result* result = GetResultAs<Result*>();
1746 // Set as failed so if the command fails we'll recover. 1844 // Set as failed so if the command fails we'll recover.
1747 result->success = false; 1845 result->success = false;
1748 helper_->GetActiveUniform(program, index, kResultBucketId, 1846 helper_->GetActiveUniform(program, index, kResultBucketId,
1749 result_shm_id(), result_shm_offset()); 1847 GetResultShmId(), GetResultShmOffset());
1750 WaitForCmd(); 1848 WaitForCmd();
1751 if (result->success) { 1849 if (result->success) {
1752 if (size) { 1850 if (size) {
1753 *size = result->size; 1851 *size = result->size;
1754 } 1852 }
1755 if (type) { 1853 if (type) {
1756 *type = result->type; 1854 *type = result->type;
1757 } 1855 }
1758 if (length || name) { 1856 if (length || name) {
1759 std::vector<int8> str; 1857 std::vector<int8> str;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 << program << ", " << maxcount << ", " 1906 << program << ", " << maxcount << ", "
1809 << static_cast<const void*>(count) << ", " 1907 << static_cast<const void*>(count) << ", "
1810 << static_cast<const void*>(shaders) << ", "); 1908 << static_cast<const void*>(shaders) << ", ");
1811 if (maxcount < 0) { 1909 if (maxcount < 0) {
1812 SetGLError(GL_INVALID_VALUE, "glGetAttachedShaders: maxcount < 0"); 1910 SetGLError(GL_INVALID_VALUE, "glGetAttachedShaders: maxcount < 0");
1813 return; 1911 return;
1814 } 1912 }
1815 TRACE_EVENT0("gpu", "GLES2::GetAttachedShaders"); 1913 TRACE_EVENT0("gpu", "GLES2::GetAttachedShaders");
1816 typedef gles2::GetAttachedShaders::Result Result; 1914 typedef gles2::GetAttachedShaders::Result Result;
1817 uint32 size = Result::ComputeSize(maxcount); 1915 uint32 size = Result::ComputeSize(maxcount);
1818 Result* result = transfer_buffer_.AllocTyped<Result>(size); 1916 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
1917 Result* result = transfer_buffer->AllocTyped<Result>(size);
1819 result->SetNumResults(0); 1918 result->SetNumResults(0);
1820 helper_->GetAttachedShaders( 1919 helper_->GetAttachedShaders(
1821 program, 1920 program,
1822 transfer_buffer_id_, 1921 transfer_buffer->GetShmId(),
1823 transfer_buffer_.GetOffset(result), 1922 transfer_buffer->GetOffset(result),
1824 size); 1923 size);
1825 int32 token = helper_->InsertToken(); 1924 int32 token = helper_->InsertToken();
1826 WaitForCmd(); 1925 WaitForCmd();
1827 if (count) { 1926 if (count) {
1828 *count = result->GetNumResults(); 1927 *count = result->GetNumResults();
1829 } 1928 }
1830 result->CopyResult(shaders); 1929 result->CopyResult(shaders);
1831 GPU_CLIENT_LOG_CODE_BLOCK({ 1930 GPU_CLIENT_LOG_CODE_BLOCK({
1832 for (int32 i = 0; i < result->GetNumResults(); ++i) { 1931 for (int32 i = 0; i < result->GetNumResults(); ++i) {
1833 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]); 1932 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]);
1834 } 1933 }
1835 }); 1934 });
1836 transfer_buffer_.FreePendingToken(result, token); 1935 transfer_buffer->FreePendingToken(result, token);
1837 } 1936 }
1838 1937
1839 void GLES2Implementation::GetShaderPrecisionFormat( 1938 void GLES2Implementation::GetShaderPrecisionFormat(
1840 GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) { 1939 GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) {
1841 GPU_CLIENT_LOG("[" << this << "] glGetShaderPrecisionFormat(" 1940 GPU_CLIENT_LOG("[" << this << "] glGetShaderPrecisionFormat("
1842 << GLES2Util::GetStringShaderType(shadertype) << ", " 1941 << GLES2Util::GetStringShaderType(shadertype) << ", "
1843 << GLES2Util::GetStringShaderPrecision(precisiontype) << ", " 1942 << GLES2Util::GetStringShaderPrecision(precisiontype) << ", "
1844 << static_cast<const void*>(range) << ", " 1943 << static_cast<const void*>(range) << ", "
1845 << static_cast<const void*>(precision) << ", "); 1944 << static_cast<const void*>(precision) << ", ");
1846 TRACE_EVENT0("gpu", "GLES2::GetShaderPrecisionFormat"); 1945 TRACE_EVENT0("gpu", "GLES2::GetShaderPrecisionFormat");
1847 typedef gles2::GetShaderPrecisionFormat::Result Result; 1946 typedef gles2::GetShaderPrecisionFormat::Result Result;
1848 Result* result = static_cast<Result*>(result_buffer_); 1947 Result* result = GetResultAs<Result*>();
1849 result->success = false; 1948 result->success = false;
1850 helper_->GetShaderPrecisionFormat( 1949 helper_->GetShaderPrecisionFormat(
1851 shadertype, precisiontype, result_shm_id(), result_shm_offset()); 1950 shadertype, precisiontype, GetResultShmId(), GetResultShmOffset());
1852 WaitForCmd(); 1951 WaitForCmd();
1853 if (result->success) { 1952 if (result->success) {
1854 if (range) { 1953 if (range) {
1855 range[0] = result->min_range; 1954 range[0] = result->min_range;
1856 range[1] = result->max_range; 1955 range[1] = result->max_range;
1857 GPU_CLIENT_LOG(" min_range: " << range[0]); 1956 GPU_CLIENT_LOG(" min_range: " << range[0]);
1858 GPU_CLIENT_LOG(" min_range: " << range[1]); 1957 GPU_CLIENT_LOG(" min_range: " << range[1]);
1859 } 1958 }
1860 if (precision) { 1959 if (precision) {
1861 precision[0] = result->precision; 1960 precision[0] = result->precision;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 return reinterpret_cast<const GLubyte*>(result); 2009 return reinterpret_cast<const GLubyte*>(result);
1911 } 2010 }
1912 2011
1913 void GLES2Implementation::GetUniformfv( 2012 void GLES2Implementation::GetUniformfv(
1914 GLuint program, GLint location, GLfloat* params) { 2013 GLuint program, GLint location, GLfloat* params) {
1915 GPU_CLIENT_LOG("[" << this << "] glGetUniformfv(" 2014 GPU_CLIENT_LOG("[" << this << "] glGetUniformfv("
1916 << program << ", " << location << ", " 2015 << program << ", " << location << ", "
1917 << static_cast<const void*>(params) << ")"); 2016 << static_cast<const void*>(params) << ")");
1918 TRACE_EVENT0("gpu", "GLES2::GetUniformfv"); 2017 TRACE_EVENT0("gpu", "GLES2::GetUniformfv");
1919 typedef gles2::GetUniformfv::Result Result; 2018 typedef gles2::GetUniformfv::Result Result;
1920 Result* result = static_cast<Result*>(result_buffer_); 2019 Result* result = GetResultAs<Result*>();
1921 result->SetNumResults(0); 2020 result->SetNumResults(0);
1922 helper_->GetUniformfv( 2021 helper_->GetUniformfv(
1923 program, location, result_shm_id(), result_shm_offset()); 2022 program, location, GetResultShmId(), GetResultShmOffset());
1924 WaitForCmd(); 2023 WaitForCmd();
1925 result->CopyResult(params); 2024 result->CopyResult(params);
1926 GPU_CLIENT_LOG_CODE_BLOCK({ 2025 GPU_CLIENT_LOG_CODE_BLOCK({
1927 for (int32 i = 0; i < result->GetNumResults(); ++i) { 2026 for (int32 i = 0; i < result->GetNumResults(); ++i) {
1928 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]); 2027 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]);
1929 } 2028 }
1930 }); 2029 });
1931 } 2030 }
1932 2031
1933 void GLES2Implementation::GetUniformiv( 2032 void GLES2Implementation::GetUniformiv(
1934 GLuint program, GLint location, GLint* params) { 2033 GLuint program, GLint location, GLint* params) {
1935 GPU_CLIENT_LOG("[" << this << "] glGetUniformiv(" 2034 GPU_CLIENT_LOG("[" << this << "] glGetUniformiv("
1936 << program << ", " << location << ", " 2035 << program << ", " << location << ", "
1937 << static_cast<const void*>(params) << ")"); 2036 << static_cast<const void*>(params) << ")");
1938 TRACE_EVENT0("gpu", "GLES2::GetUniformiv"); 2037 TRACE_EVENT0("gpu", "GLES2::GetUniformiv");
1939 typedef gles2::GetUniformiv::Result Result; 2038 typedef gles2::GetUniformiv::Result Result;
1940 Result* result = static_cast<Result*>(result_buffer_); 2039 Result* result = GetResultAs<Result*>();
1941 result->SetNumResults(0); 2040 result->SetNumResults(0);
1942 helper_->GetUniformiv( 2041 helper_->GetUniformiv(
1943 program, location, result_shm_id(), result_shm_offset()); 2042 program, location, GetResultShmId(), GetResultShmOffset());
1944 WaitForCmd(); 2043 WaitForCmd();
1945 static_cast<gles2::GetUniformfv::Result*>(result_buffer_)->CopyResult(params); 2044 GetResultAs<gles2::GetUniformfv::Result*>()->CopyResult(params);
1946 GPU_CLIENT_LOG_CODE_BLOCK({ 2045 GPU_CLIENT_LOG_CODE_BLOCK({
1947 for (int32 i = 0; i < result->GetNumResults(); ++i) { 2046 for (int32 i = 0; i < result->GetNumResults(); ++i) {
1948 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]); 2047 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]);
1949 } 2048 }
1950 }); 2049 });
1951 } 2050 }
1952 2051
1953 void GLES2Implementation::ReadPixels( 2052 void GLES2Implementation::ReadPixels(
1954 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, 2053 GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format,
1955 GLenum type, void* pixels) { 2054 GLenum type, void* pixels) {
(...skipping 12 matching lines...) Expand all
1968 } 2067 }
1969 2068
1970 // glReadPixel pads the size of each row of pixels by an amount specified by 2069 // glReadPixel pads the size of each row of pixels by an amount specified by
1971 // glPixelStorei. So, we have to take that into account both in the fact that 2070 // glPixelStorei. So, we have to take that into account both in the fact that
1972 // the pixels returned from the ReadPixel command will include that padding 2071 // the pixels returned from the ReadPixel command will include that padding
1973 // and that when we copy the results to the user's buffer we need to not 2072 // and that when we copy the results to the user's buffer we need to not
1974 // write those padding bytes but leave them as they are. 2073 // write those padding bytes but leave them as they are.
1975 2074
1976 TRACE_EVENT0("gpu", "GLES2::ReadPixels"); 2075 TRACE_EVENT0("gpu", "GLES2::ReadPixels");
1977 typedef gles2::ReadPixels::Result Result; 2076 typedef gles2::ReadPixels::Result Result;
1978 Result* result = static_cast<Result*>(result_buffer_); 2077 Result* result = GetResultAs<Result*>();
1979 int8* dest = reinterpret_cast<int8*>(pixels); 2078 int8* dest = reinterpret_cast<int8*>(pixels);
1980 GLsizeiptr max_size = transfer_buffer_.GetLargestFreeOrPendingSize(); 2079 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
2080 GLsizeiptr max_size = transfer_buffer->GetLargestFreeOrPendingSize();
1981 uint32 temp_size; 2081 uint32 temp_size;
1982 if (!GLES2Util::ComputeImageDataSize( 2082 if (!GLES2Util::ComputeImageDataSize(
1983 width, 1, format, type, pack_alignment_, &temp_size)) { 2083 width, 1, format, type, pack_alignment_, &temp_size)) {
1984 SetGLError(GL_INVALID_VALUE, "glReadPixels: size too large."); 2084 SetGLError(GL_INVALID_VALUE, "glReadPixels: size too large.");
1985 return; 2085 return;
1986 } 2086 }
1987 GLsizeiptr unpadded_row_size = temp_size; 2087 GLsizeiptr unpadded_row_size = temp_size;
1988 if (!GLES2Util::ComputeImageDataSize( 2088 if (!GLES2Util::ComputeImageDataSize(
1989 width, 2, format, type, pack_alignment_, &temp_size)) { 2089 width, 2, format, type, pack_alignment_, &temp_size)) {
1990 SetGLError(GL_INVALID_VALUE, "glReadPixels: size too large."); 2090 SetGLError(GL_INVALID_VALUE, "glReadPixels: size too large.");
(...skipping 10 matching lines...) Expand all
2001 // The max rows we can transfer. 2101 // The max rows we can transfer.
2002 GLint max_rows = max_size / std::max(padded_row_size, 2102 GLint max_rows = max_size / std::max(padded_row_size,
2003 static_cast<GLsizeiptr>(1)); 2103 static_cast<GLsizeiptr>(1));
2004 while (height) { 2104 while (height) {
2005 // Compute how many rows to transfer. 2105 // Compute how many rows to transfer.
2006 GLint num_rows = std::min(height, max_rows); 2106 GLint num_rows = std::min(height, max_rows);
2007 // Compute how much space those rows will take. The last row will not 2107 // Compute how much space those rows will take. The last row will not
2008 // include padding. 2108 // include padding.
2009 GLsizeiptr part_size = 2109 GLsizeiptr part_size =
2010 unpadded_row_size + padded_row_size * (num_rows - 1); 2110 unpadded_row_size + padded_row_size * (num_rows - 1);
2011 void* buffer = transfer_buffer_.Alloc(part_size); 2111 void* buffer = transfer_buffer->Alloc(part_size);
2012 *result = 0; // mark as failed. 2112 *result = 0; // mark as failed.
2013 helper_->ReadPixels( 2113 helper_->ReadPixels(
2014 xoffset, yoffset, width, num_rows, format, type, 2114 xoffset, yoffset, width, num_rows, format, type,
2015 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), 2115 transfer_buffer->GetShmId(), transfer_buffer->GetOffset(buffer),
2016 result_shm_id(), result_shm_offset()); 2116 GetResultShmId(), GetResultShmOffset());
2017 WaitForCmd(); 2117 WaitForCmd();
2018 if (*result != 0) { 2118 if (*result != 0) {
2019 // when doing a y-flip we have to iterate through top-to-bottom chunks 2119 // when doing a y-flip we have to iterate through top-to-bottom chunks
2020 // of the dst. The service side handles reversing the rows within a 2120 // of the dst. The service side handles reversing the rows within a
2021 // chunk. 2121 // chunk.
2022 int8* rows_dst; 2122 int8* rows_dst;
2023 if (pack_reverse_row_order_) { 2123 if (pack_reverse_row_order_) {
2024 rows_dst = dest + (height - num_rows) * padded_row_size; 2124 rows_dst = dest + (height - num_rows) * padded_row_size;
2025 } else { 2125 } else {
2026 rows_dst = dest; 2126 rows_dst = dest;
2027 } 2127 }
2028 // We have to copy 1 row at a time to avoid writing pad bytes. 2128 // We have to copy 1 row at a time to avoid writing pad bytes.
2029 const int8* src = static_cast<const int8*>(buffer); 2129 const int8* src = static_cast<const int8*>(buffer);
2030 for (GLint yy = 0; yy < num_rows; ++yy) { 2130 for (GLint yy = 0; yy < num_rows; ++yy) {
2031 memcpy(rows_dst, src, unpadded_row_size); 2131 memcpy(rows_dst, src, unpadded_row_size);
2032 rows_dst += padded_row_size; 2132 rows_dst += padded_row_size;
2033 src += padded_row_size; 2133 src += padded_row_size;
2034 } 2134 }
2035 if (!pack_reverse_row_order_) { 2135 if (!pack_reverse_row_order_) {
2036 dest = rows_dst; 2136 dest = rows_dst;
2037 } 2137 }
2038 } 2138 }
2039 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 2139 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
2040 // If it was not marked as successful exit. 2140 // If it was not marked as successful exit.
2041 if (*result == 0) { 2141 if (*result == 0) {
2042 return; 2142 return;
2043 } 2143 }
2044 yoffset += num_rows; 2144 yoffset += num_rows;
2045 height -= num_rows; 2145 height -= num_rows;
2046 } 2146 }
2047 } else { 2147 } else {
2048 // Transfer by sub rows. Because GL has no maximum texture dimensions. 2148 // Transfer by sub rows. Because GL has no maximum texture dimensions.
2049 GLES2Util::ComputeImageDataSize( 2149 GLES2Util::ComputeImageDataSize(
2050 1, 1, format, type, pack_alignment_, &temp_size); 2150 1, 1, format, type, pack_alignment_, &temp_size);
2051 GLsizeiptr element_size = temp_size; 2151 GLsizeiptr element_size = temp_size;
2052 max_size -= max_size % element_size; 2152 max_size -= max_size % element_size;
2053 GLint max_sub_row_pixels = max_size / element_size; 2153 GLint max_sub_row_pixels = max_size / element_size;
2054 if (pack_reverse_row_order_) { 2154 if (pack_reverse_row_order_) {
2055 // start at the last row when flipping y. 2155 // start at the last row when flipping y.
2056 dest = dest + (height - 1) * padded_row_size; 2156 dest = dest + (height - 1) * padded_row_size;
2057 } 2157 }
2058 for (; height; --height) { 2158 for (; height; --height) {
2059 GLint temp_width = width; 2159 GLint temp_width = width;
2060 GLint temp_xoffset = xoffset; 2160 GLint temp_xoffset = xoffset;
2061 int8* row_dest = dest; 2161 int8* row_dest = dest;
2062 while (temp_width) { 2162 while (temp_width) {
2063 GLint num_pixels = std::min(width, max_sub_row_pixels); 2163 GLint num_pixels = std::min(width, max_sub_row_pixels);
2064 GLsizeiptr part_size = num_pixels * element_size; 2164 GLsizeiptr part_size = num_pixels * element_size;
2065 void* buffer = transfer_buffer_.Alloc(part_size); 2165 void* buffer = transfer_buffer->Alloc(part_size);
2066 *result = 0; // mark as failed. 2166 *result = 0; // mark as failed.
2067 helper_->ReadPixels( 2167 helper_->ReadPixels(
2068 temp_xoffset, yoffset, temp_width, 1, format, type, 2168 temp_xoffset, yoffset, temp_width, 1, format, type,
2069 transfer_buffer_id_, transfer_buffer_.GetOffset(buffer), 2169 transfer_buffer->GetShmId(),
2070 result_shm_id(), result_shm_offset()); 2170 transfer_buffer->GetOffset(buffer),
2171 GetResultShmId(), GetResultShmOffset());
2071 WaitForCmd(); 2172 WaitForCmd();
2072 if (*result != 0) { 2173 if (*result != 0) {
2073 memcpy(row_dest, buffer, part_size); 2174 memcpy(row_dest, buffer, part_size);
2074 } 2175 }
2075 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 2176 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
2076 // If it was not marked as successful exit. 2177 // If it was not marked as successful exit.
2077 if (*result == 0) { 2178 if (*result == 0) {
2078 return; 2179 return;
2079 } 2180 }
2080 row_dest += part_size; 2181 row_dest += part_size;
2081 temp_xoffset += num_pixels; 2182 temp_xoffset += num_pixels;
2082 temp_width -= num_pixels; 2183 temp_width -= num_pixels;
2083 } 2184 }
2084 ++yoffset; 2185 ++yoffset;
2085 dest += pack_reverse_row_order_ ? -padded_row_size : padded_row_size; 2186 dest += pack_reverse_row_order_ ? -padded_row_size : padded_row_size;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2353 if (GetVertexAttribHelper(index, pname, &value)) { 2454 if (GetVertexAttribHelper(index, pname, &value)) {
2354 *params = static_cast<float>(value); 2455 *params = static_cast<float>(value);
2355 return; 2456 return;
2356 } 2457 }
2357 #endif 2458 #endif
2358 TRACE_EVENT0("gpu", "GLES2::GetVertexAttribfv"); 2459 TRACE_EVENT0("gpu", "GLES2::GetVertexAttribfv");
2359 typedef GetVertexAttribfv::Result Result; 2460 typedef GetVertexAttribfv::Result Result;
2360 Result* result = GetResultAs<Result*>(); 2461 Result* result = GetResultAs<Result*>();
2361 result->SetNumResults(0); 2462 result->SetNumResults(0);
2362 helper_->GetVertexAttribfv( 2463 helper_->GetVertexAttribfv(
2363 index, pname, result_shm_id(), result_shm_offset()); 2464 index, pname, GetResultShmId(), GetResultShmOffset());
2364 WaitForCmd(); 2465 WaitForCmd();
2365 result->CopyResult(params); 2466 result->CopyResult(params);
2366 GPU_CLIENT_LOG_CODE_BLOCK({ 2467 GPU_CLIENT_LOG_CODE_BLOCK({
2367 for (int32 i = 0; i < result->GetNumResults(); ++i) { 2468 for (int32 i = 0; i < result->GetNumResults(); ++i) {
2368 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]); 2469 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]);
2369 } 2470 }
2370 }); 2471 });
2371 } 2472 }
2372 2473
2373 void GLES2Implementation::GetVertexAttribiv( 2474 void GLES2Implementation::GetVertexAttribiv(
2374 GLuint index, GLenum pname, GLint* params) { 2475 GLuint index, GLenum pname, GLint* params) {
2375 GPU_CLIENT_LOG("[" << this << "] glGetVertexAttribiv(" 2476 GPU_CLIENT_LOG("[" << this << "] glGetVertexAttribiv("
2376 << index << ", " 2477 << index << ", "
2377 << GLES2Util::GetStringVertexAttribute(pname) << ", " 2478 << GLES2Util::GetStringVertexAttribute(pname) << ", "
2378 << static_cast<const void*>(params) << ")"); 2479 << static_cast<const void*>(params) << ")");
2379 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) 2480 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
2380 uint32 value = 0; 2481 uint32 value = 0;
2381 if (GetVertexAttribHelper(index, pname, &value)) { 2482 if (GetVertexAttribHelper(index, pname, &value)) {
2382 *params = value; 2483 *params = value;
2383 return; 2484 return;
2384 } 2485 }
2385 #endif 2486 #endif
2386 TRACE_EVENT0("gpu", "GLES2::GetVertexAttribiv"); 2487 TRACE_EVENT0("gpu", "GLES2::GetVertexAttribiv");
2387 typedef GetVertexAttribiv::Result Result; 2488 typedef GetVertexAttribiv::Result Result;
2388 Result* result = GetResultAs<Result*>(); 2489 Result* result = GetResultAs<Result*>();
2389 result->SetNumResults(0); 2490 result->SetNumResults(0);
2390 helper_->GetVertexAttribiv( 2491 helper_->GetVertexAttribiv(
2391 index, pname, result_shm_id(), result_shm_offset()); 2492 index, pname, GetResultShmId(), GetResultShmOffset());
2392 WaitForCmd(); 2493 WaitForCmd();
2393 result->CopyResult(params); 2494 result->CopyResult(params);
2394 GPU_CLIENT_LOG_CODE_BLOCK({ 2495 GPU_CLIENT_LOG_CODE_BLOCK({
2395 for (int32 i = 0; i < result->GetNumResults(); ++i) { 2496 for (int32 i = 0; i < result->GetNumResults(); ++i) {
2396 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]); 2497 GPU_CLIENT_LOG(" " << i << ": " << result->GetData()[i]);
2397 } 2498 }
2398 }); 2499 });
2399 } 2500 }
2400 2501
2401 GLboolean GLES2Implementation::EnableFeatureCHROMIUM( 2502 GLboolean GLES2Implementation::EnableFeatureCHROMIUM(
2402 const char* feature) { 2503 const char* feature) {
2403 GPU_CLIENT_LOG("[" << this << "] glEnableFeatureCHROMIUM(" 2504 GPU_CLIENT_LOG("[" << this << "] glEnableFeatureCHROMIUM("
2404 << feature << ")"); 2505 << feature << ")");
2405 TRACE_EVENT0("gpu", "GLES2::EnableFeatureCHROMIUM"); 2506 TRACE_EVENT0("gpu", "GLES2::EnableFeatureCHROMIUM");
2406 typedef EnableFeatureCHROMIUM::Result Result; 2507 typedef EnableFeatureCHROMIUM::Result Result;
2407 Result* result = GetResultAs<Result*>(); 2508 Result* result = GetResultAs<Result*>();
2408 *result = 0; 2509 *result = 0;
2409 SetBucketAsCString(kResultBucketId, feature); 2510 SetBucketAsCString(kResultBucketId, feature);
2410 helper_->EnableFeatureCHROMIUM( 2511 helper_->EnableFeatureCHROMIUM(
2411 kResultBucketId, result_shm_id(), result_shm_offset()); 2512 kResultBucketId, GetResultShmId(), GetResultShmOffset());
2412 WaitForCmd(); 2513 WaitForCmd();
2413 helper_->SetBucketSize(kResultBucketId, 0); 2514 helper_->SetBucketSize(kResultBucketId, 0);
2414 GPU_CLIENT_LOG(" returned " << GLES2Util::GetStringBool(*result)); 2515 GPU_CLIENT_LOG(" returned " << GLES2Util::GetStringBool(*result));
2415 return *result; 2516 return *result;
2416 } 2517 }
2417 2518
2418 void* GLES2Implementation::MapBufferSubDataCHROMIUM( 2519 void* GLES2Implementation::MapBufferSubDataCHROMIUM(
2419 GLuint target, GLintptr offset, GLsizeiptr size, GLenum access) { 2520 GLuint target, GLintptr offset, GLsizeiptr size, GLenum access) {
2420 GPU_CLIENT_LOG("[" << this << "] glMapBufferSubDataCHROMIUM(" 2521 GPU_CLIENT_LOG("[" << this << "] glMapBufferSubDataCHROMIUM("
2421 << target << ", " << offset << ", " << size << ", " 2522 << target << ", " << offset << ", " << size << ", "
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2619 } 2720 }
2620 for (int ii = 0; ii < num_results; ++ii) { 2721 for (int ii = 0; ii < num_results; ++ii) {
2621 if (results[ii] != 0) { 2722 if (results[ii] != 0) {
2622 SetGLError(GL_INVALID_VALUE, 2723 SetGLError(GL_INVALID_VALUE,
2623 "glGetMultipleIntegervCHROMIUM: results not set to zero."); 2724 "glGetMultipleIntegervCHROMIUM: results not set to zero.");
2624 return; 2725 return;
2625 } 2726 }
2626 } 2727 }
2627 uint32 size_needed = 2728 uint32 size_needed =
2628 count * sizeof(pnames[0]) + num_results * sizeof(results[0]); 2729 count * sizeof(pnames[0]) + num_results * sizeof(results[0]);
2629 void* buffer = transfer_buffer_.Alloc(size_needed); 2730 AlignedRingBuffer* transfer_buffer = transfer_buffer_.GetBuffer();
2731 void* buffer = transfer_buffer->Alloc(size_needed);
2630 GLenum* pnames_buffer = static_cast<GLenum*>(buffer); 2732 GLenum* pnames_buffer = static_cast<GLenum*>(buffer);
2631 void* results_buffer = pnames_buffer + count; 2733 void* results_buffer = pnames_buffer + count;
2632 memcpy(pnames_buffer, pnames, count * sizeof(GLenum)); 2734 memcpy(pnames_buffer, pnames, count * sizeof(GLenum));
2633 memset(results_buffer, 0, num_results * sizeof(GLint)); 2735 memset(results_buffer, 0, num_results * sizeof(GLint));
2634 helper_->GetMultipleIntegervCHROMIUM( 2736 helper_->GetMultipleIntegervCHROMIUM(
2635 transfer_buffer_id_, transfer_buffer_.GetOffset(pnames_buffer), 2737 transfer_buffer->GetShmId(),
2738 transfer_buffer->GetOffset(pnames_buffer),
2636 count, 2739 count,
2637 transfer_buffer_id_, transfer_buffer_.GetOffset(results_buffer), 2740 transfer_buffer->GetShmId(),
2741 transfer_buffer->GetOffset(results_buffer),
2638 size); 2742 size);
2639 WaitForCmd(); 2743 WaitForCmd();
2640 memcpy(results, results_buffer, size); 2744 memcpy(results, results_buffer, size);
2641 // TODO(gman): We should be able to free without a token. 2745 // TODO(gman): We should be able to free without a token.
2642 transfer_buffer_.FreePendingToken(buffer, helper_->InsertToken()); 2746 transfer_buffer->FreePendingToken(buffer, helper_->InsertToken());
2643 GPU_CLIENT_LOG(" returned"); 2747 GPU_CLIENT_LOG(" returned");
2644 GPU_CLIENT_LOG_CODE_BLOCK({ 2748 GPU_CLIENT_LOG_CODE_BLOCK({
2645 for (int i = 0; i < num_results; ++i) { 2749 for (int i = 0; i < num_results; ++i) {
2646 GPU_CLIENT_LOG(" " << i << ": " << (results[i])); 2750 GPU_CLIENT_LOG(" " << i << ": " << (results[i]));
2647 } 2751 }
2648 }); 2752 });
2649 } 2753 }
2650 2754
2651 void GLES2Implementation::GetProgramInfoCHROMIUMHelper( 2755 void GLES2Implementation::GetProgramInfoCHROMIUMHelper(
2652 GLuint program, std::vector<int8>* result) { 2756 GLuint program, std::vector<int8>* result) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 2793
2690 GLuint GLES2Implementation::CreateStreamTextureCHROMIUM(GLuint texture) { 2794 GLuint GLES2Implementation::CreateStreamTextureCHROMIUM(GLuint texture) {
2691 GPU_CLIENT_LOG("[" << this << "] CreateStreamTextureCHROMIUM(" 2795 GPU_CLIENT_LOG("[" << this << "] CreateStreamTextureCHROMIUM("
2692 << texture << ")"); 2796 << texture << ")");
2693 TRACE_EVENT0("gpu", "GLES2::CreateStreamTextureCHROMIUM"); 2797 TRACE_EVENT0("gpu", "GLES2::CreateStreamTextureCHROMIUM");
2694 typedef CreateStreamTextureCHROMIUM::Result Result; 2798 typedef CreateStreamTextureCHROMIUM::Result Result;
2695 Result* result = GetResultAs<Result*>(); 2799 Result* result = GetResultAs<Result*>();
2696 *result = GL_ZERO; 2800 *result = GL_ZERO;
2697 2801
2698 helper_->CreateStreamTextureCHROMIUM(texture, 2802 helper_->CreateStreamTextureCHROMIUM(texture,
2699 result_shm_id(), 2803 GetResultShmId(),
2700 result_shm_offset()); 2804 GetResultShmOffset());
2701 WaitForCmd(); 2805 WaitForCmd();
2702 2806
2703 return *result; 2807 return *result;
2704 } 2808 }
2705 2809
2706 void GLES2Implementation::DestroyStreamTextureCHROMIUM(GLuint texture) { 2810 void GLES2Implementation::DestroyStreamTextureCHROMIUM(GLuint texture) {
2707 GPU_CLIENT_LOG("[" << this << "] DestroyStreamTextureCHROMIUM(" 2811 GPU_CLIENT_LOG("[" << this << "] DestroyStreamTextureCHROMIUM("
2708 << texture << ")"); 2812 << texture << ")");
2709 TRACE_EVENT0("gpu", "GLES2::DestroyStreamTextureCHROMIUM"); 2813 TRACE_EVENT0("gpu", "GLES2::DestroyStreamTextureCHROMIUM");
2710 helper_->DestroyStreamTextureCHROMIUM(texture); 2814 helper_->DestroyStreamTextureCHROMIUM(texture);
(...skipping 10 matching lines...) Expand all
2721 helper_->PostSubBufferCHROMIUM(x, y, width, height); 2825 helper_->PostSubBufferCHROMIUM(x, y, width, height);
2722 helper_->CommandBufferHelper::Flush(); 2826 helper_->CommandBufferHelper::Flush();
2723 if (swap_buffers_tokens_.size() > kMaxSwapBuffers + 1) { 2827 if (swap_buffers_tokens_.size() > kMaxSwapBuffers + 1) {
2724 helper_->WaitForToken(swap_buffers_tokens_.front()); 2828 helper_->WaitForToken(swap_buffers_tokens_.front());
2725 swap_buffers_tokens_.pop(); 2829 swap_buffers_tokens_.pop();
2726 } 2830 }
2727 } 2831 }
2728 2832
2729 } // namespace gles2 2833 } // namespace gles2
2730 } // namespace gpu 2834 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.h ('k') | gpu/command_buffer/client/gles2_implementation_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698