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

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

Issue 14456004: GPU client side changes for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Rollback decoder changes Created 7 years, 7 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
11 #include <queue> 11 #include <queue>
12 #include <set> 12 #include <set>
13 #include <limits> 13 #include <limits>
14 #include <stdio.h> 14 #include <stdio.h>
15 #include <string.h> 15 #include <string.h>
16 #include <GLES2/gl2ext.h> 16 #include <GLES2/gl2ext.h>
17 #include <GLES2/gl2extchromium.h> 17 #include <GLES2/gl2extchromium.h>
18 #include "../client/buffer_tracker.h" 18 #include "../client/buffer_tracker.h"
19 #include "../client/gpu_memory_buffer.h"
20 #include "../client/gpu_memory_buffer_factory.h"
21 #include "../client/gpu_memory_buffer_tracker_in_process.h"
19 #include "../client/mapped_memory.h" 22 #include "../client/mapped_memory.h"
20 #include "../client/program_info_manager.h" 23 #include "../client/program_info_manager.h"
21 #include "../client/query_tracker.h" 24 #include "../client/query_tracker.h"
22 #include "../client/transfer_buffer.h" 25 #include "../client/transfer_buffer.h"
23 #include "../client/vertex_array_object_manager.h" 26 #include "../client/vertex_array_object_manager.h"
24 #include "../common/gles2_cmd_utils.h" 27 #include "../common/gles2_cmd_utils.h"
25 #include "../common/trace_event.h" 28 #include "../common/trace_event.h"
26 29
27 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) 30 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
28 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS 31 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 bound_read_framebuffer_(0), 98 bound_read_framebuffer_(0),
96 bound_renderbuffer_(0), 99 bound_renderbuffer_(0),
97 current_program_(0), 100 current_program_(0),
98 bound_array_buffer_id_(0), 101 bound_array_buffer_id_(0),
99 bound_pixel_pack_transfer_buffer_id_(0), 102 bound_pixel_pack_transfer_buffer_id_(0),
100 bound_pixel_unpack_transfer_buffer_id_(0), 103 bound_pixel_unpack_transfer_buffer_id_(0),
101 error_bits_(0), 104 error_bits_(0),
102 debug_(false), 105 debug_(false),
103 use_count_(0), 106 use_count_(0),
104 current_query_(NULL), 107 current_query_(NULL),
105 error_message_callback_(NULL) { 108 error_message_callback_(NULL),
109 gpu_memory_buffer_factory_() {
106 GPU_DCHECK(helper); 110 GPU_DCHECK(helper);
107 GPU_DCHECK(transfer_buffer); 111 GPU_DCHECK(transfer_buffer);
108 112
109 char temp[128]; 113 char temp[128];
110 sprintf(temp, "%p", static_cast<void*>(this)); 114 sprintf(temp, "%p", static_cast<void*>(this));
111 this_in_hex_ = std::string(temp); 115 this_in_hex_ = std::string(temp);
112 116
113 GPU_CLIENT_LOG_CODE_BLOCK({ 117 GPU_CLIENT_LOG_CODE_BLOCK({
114 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( 118 debug_ = CommandLine::ForCurrentProcess()->HasSwitch(
115 switches::kEnableGPUClientLogging); 119 switches::kEnableGPUClientLogging);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 static_state_.int_state.num_compressed_texture_formats); 170 static_state_.int_state.num_compressed_texture_formats);
167 util_.set_num_shader_binary_formats( 171 util_.set_num_shader_binary_formats(
168 static_state_.int_state.num_shader_binary_formats); 172 static_state_.int_state.num_shader_binary_formats);
169 173
170 texture_units_.reset( 174 texture_units_.reset(
171 new TextureUnit[ 175 new TextureUnit[
172 static_state_.int_state.max_combined_texture_image_units]); 176 static_state_.int_state.max_combined_texture_image_units]);
173 177
174 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); 178 query_tracker_.reset(new QueryTracker(mapped_memory_.get()));
175 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); 179 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get()));
180 if (gpu_memory_buffer_factory_.get() != NULL)
181 gpu_memory_buffer_tracker_.reset(
182 new GpuMemoryBufferTrackerInProcess(gpu_memory_buffer_factory_.get()));
176 183
177 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) 184 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
178 GetIdHandler(id_namespaces::kBuffers)->MakeIds( 185 GetIdHandler(id_namespaces::kBuffers)->MakeIds(
179 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); 186 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]);
180 #endif 187 #endif
181 188
182 vertex_array_object_manager_.reset(new VertexArrayObjectManager( 189 vertex_array_object_manager_.reset(new VertexArrayObjectManager(
183 static_state_.int_state.max_vertex_attribs, 190 static_state_.int_state.max_vertex_attribs,
184 reserved_ids_[0], 191 reserved_ids_[0],
185 reserved_ids_[1])); 192 reserved_ids_[1]));
(...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 std::string str; 2029 std::string str;
2023 if (GetBucketAsString(kResultBucketId, &str)) { 2030 if (GetBucketAsString(kResultBucketId, &str)) {
2024 // Adds extensions implemented on client side only. 2031 // Adds extensions implemented on client side only.
2025 switch (name) { 2032 switch (name) {
2026 case GL_EXTENSIONS: 2033 case GL_EXTENSIONS:
2027 str += std::string(str.empty() ? "" : " ") + 2034 str += std::string(str.empty() ? "" : " ") +
2028 "GL_CHROMIUM_flipy " 2035 "GL_CHROMIUM_flipy "
2029 "GL_CHROMIUM_map_sub " 2036 "GL_CHROMIUM_map_sub "
2030 "GL_CHROMIUM_shallow_flush " 2037 "GL_CHROMIUM_shallow_flush "
2031 "GL_EXT_unpack_subimage"; 2038 "GL_EXT_unpack_subimage";
2039 if (gpu_memory_buffer_factory_.get() != NULL) {
2040 str += " ";
2041 str += "GL_CHROMIUM_gpu_memory_buffer";
2042 }
2032 break; 2043 break;
2033 default: 2044 default:
2034 break; 2045 break;
2035 } 2046 }
2036 2047
2037 // Because of WebGL the extensions can change. We have to cache each unique 2048 // Because of WebGL the extensions can change. We have to cache each unique
2038 // result since we don't know when the client will stop referring to a 2049 // result since we don't know when the client will stop referring to a
2039 // previous one it queries. 2050 // previous one it queries.
2040 GLStringMap::iterator it = gl_strings_.find(name); 2051 GLStringMap::iterator it = gl_strings_.find(name);
2041 if (it == gl_strings_.end()) { 2052 if (it == gl_strings_.end()) {
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after
3432 "[" << GetLogPrefix() << "] glUnmapBufferCHROMIUM(" << target << ")"); 3443 "[" << GetLogPrefix() << "] glUnmapBufferCHROMIUM(" << target << ")");
3433 GLuint buffer_id; 3444 GLuint buffer_id;
3434 if (!GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", &buffer_id)) { 3445 if (!GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", &buffer_id)) {
3435 SetGLError(GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target"); 3446 SetGLError(GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target");
3436 } 3447 }
3437 if (!buffer_id) { 3448 if (!buffer_id) {
3438 return false; 3449 return false;
3439 } 3450 }
3440 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id); 3451 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id);
3441 if (!buffer) { 3452 if (!buffer) {
3442 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "invalid buffer"); 3453 SetGLError(GL_INVALID_OPERATION, "glUnmapBufferCHROMIUM", "invalid buffer");
3443 return false; 3454 return false;
3444 } 3455 }
3445 if (!buffer->mapped()) { 3456 if (!buffer->mapped()) {
3446 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "not mapped"); 3457 SetGLError(GL_INVALID_OPERATION, "glUnmapBufferCHROMIUM", "not mapped");
3447 return false; 3458 return false;
3448 } 3459 }
3449 buffer->set_mapped(false); 3460 buffer->set_mapped(false);
3450 CheckGLError(); 3461 CheckGLError();
3451 return true; 3462 return true;
3452 } 3463 }
3453 3464
3454 void GLES2Implementation::AsyncTexImage2DCHROMIUM( 3465 void GLES2Implementation::AsyncTexImage2DCHROMIUM(
3455 GLenum target, GLint level, GLint internalformat, GLsizei width, 3466 GLenum target, GLint level, GLint internalformat, GLsizei width,
3456 GLsizei height, GLint border, GLenum format, GLenum type, 3467 GLsizei height, GLint border, GLenum format, GLenum type,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3556 helper_->WaitAsyncTexImage2DCHROMIUM(target); 3567 helper_->WaitAsyncTexImage2DCHROMIUM(target);
3557 CheckGLError(); 3568 CheckGLError();
3558 } 3569 }
3559 3570
3560 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() { 3571 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() {
3561 GPU_CLIENT_SINGLE_THREAD_CHECK(); 3572 GPU_CLIENT_SINGLE_THREAD_CHECK();
3562 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM"); 3573 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM");
3563 return helper_->InsertSyncPointCHROMIUM(); 3574 return helper_->InsertSyncPointCHROMIUM();
3564 } 3575 }
3565 3576
3577 GLuint GLES2Implementation::CreateImageCHROMIUMHelper(GLsizei width,
3578 GLsizei height) {
3579 if (width <= 0) {
3580 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "width <= 0");
3581 return 0;
3582 }
3583
3584 if (height <= 0) {
3585 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "height <= 0");
3586 return 0;
3587 }
3588
3589 // Create new buffer.
3590 return gpu_memory_buffer_tracker_->CreateBuffer(width, height);
3591 }
3592
3593 GLuint GLES2Implementation::CreateImageCHROMIUM(GLsizei width, GLsizei height) {
3594 GPU_CLIENT_SINGLE_THREAD_CHECK();
3595 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCreateImageCHROMIUM("
3596 << width << ", "
3597 << height << ")");
3598 GLuint image_id = CreateImageCHROMIUMHelper(width, height);
3599 CheckGLError();
3600 return image_id;
3601 }
3602
3603 void GLES2Implementation::DestroyImageCHROMIUMHelper(GLuint image_id) {
3604 GpuMemoryBuffer* gpu_buffer =
3605 gpu_memory_buffer_tracker_->GetBuffer(image_id);
3606 if (!gpu_buffer) {
3607 SetGLError(GL_INVALID_OPERATION, "glDestroyImageImageCHROMIUM",
3608 "invalid GPU memory buffer");
3609 return;
3610 }
3611
3612 gpu_memory_buffer_tracker_->RemoveBuffer(image_id);
3613 }
3614
3615 void GLES2Implementation::DestroyImageCHROMIUM(GLuint image_id) {
3616 GPU_CLIENT_SINGLE_THREAD_CHECK();
3617 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glDestroyImageCHROMIUM("
3618 << image_id << ")");
3619 DestroyImageCHROMIUMHelper(image_id);
3620 CheckGLError();
3621 }
3622
3623 GLboolean GLES2Implementation::UnmapImageCHROMIUMHelper(GLuint image_id) {
3624 GpuMemoryBuffer* gpu_buffer =
3625 gpu_memory_buffer_tracker_->GetBuffer(image_id);
3626 if (!gpu_buffer) {
3627 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM",
3628 "invalid GPU memory buffer");
3629 return false;
3630 }
3631
3632 if (!gpu_buffer->IsMapped()) {
3633 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM",
3634 "not mapped");
3635 return false;
3636 }
3637 gpu_buffer->Unmap();
3638 return true;
3639 }
3640
3641 GLboolean GLES2Implementation::UnmapImageCHROMIUM(GLuint image_id) {
3642 GPU_CLIENT_SINGLE_THREAD_CHECK();
3643 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glUnmapImageCHROMIUM("
3644 << image_id << ")");
3645
3646 bool success = UnmapImageCHROMIUMHelper(image_id);
3647 CheckGLError();
3648 return success;
3649 }
3650
3651 void* GLES2Implementation::MapImageCHROMIUMHelper(GLuint image_id,
3652 GLenum access) {
3653 GpuMemoryBuffer* gpu_buffer =
3654 gpu_memory_buffer_tracker_->GetBuffer(image_id);
3655 if (!gpu_buffer) {
3656 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM",
3657 "invalid GPU memory buffer");
3658 return NULL;
3659 }
3660 GpuMemoryBuffer::AccessMode mode = GpuMemoryBuffer::READ_ONLY;
3661 switch(access) {
3662 case GL_WRITE_ONLY:
3663 mode = GpuMemoryBuffer::WRITE_ONLY;
3664 break;
3665 case GL_READ_ONLY:
3666 mode = GpuMemoryBuffer::READ_ONLY;
3667 break;
3668 // TODO(kaanb): should we add GL_READ_WRITE to gl2ext.h?
3669 default:
3670 SetGLError(GL_INVALID_ENUM, "glMapImageCHROMIUM",
3671 "invalid GPU access mode");
3672 return NULL;
3673 }
3674
3675 if (gpu_buffer->IsMapped()) {
3676 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM",
3677 "already mapped");
3678 return NULL;
3679 }
3680
3681 void* mapped_buffer = NULL;
3682 gpu_buffer->Map(mode, &mapped_buffer);
3683 return mapped_buffer;
3684 }
3685
3686 void* GLES2Implementation::MapImageCHROMIUM(
3687 GLuint image_id, GLenum access) {
3688 GPU_CLIENT_SINGLE_THREAD_CHECK();
3689 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glMapImageCHROMIUM("
3690 << image_id << ", "
3691 << GLES2Util::GetStringEnum(access) << ")");
3692
3693 void* mapped = MapImageCHROMIUMHelper(image_id, access);
3694 CheckGLError();
3695 return mapped;
3696 }
3697
3698 void GLES2Implementation::GetImageParameterivCHROMIUMHelper(
3699 GLuint image_id, GLenum pname, GLint* params) {
3700 if (pname != GL_IMAGE_ROWBYTES) {
3701 SetGLError(GL_INVALID_ENUM, "glGetImageParameterivCHROMIUM",
3702 "invalid target");
3703 return;
3704 }
3705
3706 GpuMemoryBuffer* gpu_buffer =
3707 gpu_memory_buffer_tracker_->GetBuffer(image_id);
3708 if (!gpu_buffer) {
3709 SetGLError(GL_INVALID_OPERATION, "glGetImageParameterivCHROMIUM",
3710 "invalid GPU memory buffer");
3711 return;
3712 }
3713
3714 *params = gpu_buffer->GetStride();
3715 }
3716
3717 void GLES2Implementation::GetImageParameterivCHROMIUM(
3718 GLuint image_id, GLenum pname, GLint* params) {
3719 GPU_CLIENT_SINGLE_THREAD_CHECK();
3720 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params);
3721 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glMapImageCHROMIUM("
3722 << image_id << ", "
3723 << GLES2Util::GetStringBufferParameter(pname) << ", "
3724 << static_cast<const void*>(params) << ")");
3725 GetImageParameterivCHROMIUM(image_id, pname, params);
3726 CheckGLError();
3727 }
3728
3566 // Include the auto-generated part of this file. We split this because it means 3729 // Include the auto-generated part of this file. We split this because it means
3567 // we can easily edit the non-auto generated parts right here in this file 3730 // we can easily edit the non-auto generated parts right here in this file
3568 // instead of having to edit some template or the code generator. 3731 // instead of having to edit some template or the code generator.
3569 #include "../client/gles2_implementation_impl_autogen.h" 3732 #include "../client/gles2_implementation_impl_autogen.h"
3570 3733
3571 } // namespace gles2 3734 } // namespace gles2
3572 } // namespace gpu 3735 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698