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

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: Updated the extension documentation 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 image_factory_() {
no sievers 2013/05/10 01:21:51 nit: remove this
kaanb 2013/05/13 23:00:36 We're now passing the image_factory via the constr
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_tracker_.get() == NULL && image_factory_.get() != NULL)
181 gpu_memory_buffer_tracker_.reset(
182 new GpuMemoryBufferTrackerInProcess(image_factory_.get(), this));
reveman 2013/05/10 02:06:16 You can't make assumptions about single/multi-proc
kaanb 2013/05/13 23:00:36 Done.
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 (image_factory_.get() != NULL) {
2040 str += " ";
no sievers 2013/05/10 01:21:51 str += std::string(str.empty() ? "" : " ") + "GL_C
kaanb 2013/05/13 23:00:36 str.empty() is guaranteed to be false here, so I s
2041 str += "GL_CHROMIUM_map_image";
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 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after
3431 "[" << GetLogPrefix() << "] glUnmapBufferCHROMIUM(" << target << ")"); 3442 "[" << GetLogPrefix() << "] glUnmapBufferCHROMIUM(" << target << ")");
3432 GLuint buffer_id; 3443 GLuint buffer_id;
3433 if (!GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", &buffer_id)) { 3444 if (!GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", &buffer_id)) {
3434 SetGLError(GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target"); 3445 SetGLError(GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target");
3435 } 3446 }
3436 if (!buffer_id) { 3447 if (!buffer_id) {
3437 return false; 3448 return false;
3438 } 3449 }
3439 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id); 3450 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id);
3440 if (!buffer) { 3451 if (!buffer) {
3441 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "invalid buffer"); 3452 SetGLError(GL_INVALID_OPERATION, "glUnmapBufferCHROMIUM", "invalid buffer");
3442 return false; 3453 return false;
3443 } 3454 }
3444 if (!buffer->mapped()) { 3455 if (!buffer->mapped()) {
3445 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "not mapped"); 3456 SetGLError(GL_INVALID_OPERATION, "glUnmapBufferCHROMIUM", "not mapped");
3446 return false; 3457 return false;
3447 } 3458 }
3448 buffer->set_mapped(false); 3459 buffer->set_mapped(false);
3449 CheckGLError(); 3460 CheckGLError();
3450 return true; 3461 return true;
3451 } 3462 }
3452 3463
3453 void GLES2Implementation::AsyncTexImage2DCHROMIUM( 3464 void GLES2Implementation::AsyncTexImage2DCHROMIUM(
3454 GLenum target, GLint level, GLint internalformat, GLsizei width, 3465 GLenum target, GLint level, GLint internalformat, GLsizei width,
3455 GLsizei height, GLint border, GLenum format, GLenum type, 3466 GLsizei height, GLint border, GLenum format, GLenum type,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
3551 helper_->WaitAsyncTexImage2DCHROMIUM(target); 3562 helper_->WaitAsyncTexImage2DCHROMIUM(target);
3552 CheckGLError(); 3563 CheckGLError();
3553 } 3564 }
3554 3565
3555 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() { 3566 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() {
3556 GPU_CLIENT_SINGLE_THREAD_CHECK(); 3567 GPU_CLIENT_SINGLE_THREAD_CHECK();
3557 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM"); 3568 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM");
3558 return helper_->InsertSyncPointCHROMIUM(); 3569 return helper_->InsertSyncPointCHROMIUM();
3559 } 3570 }
3560 3571
3572 GLuint GLES2Implementation::CreateImageCHROMIUMHelper(GLsizei width,
3573 GLsizei height) {
3574 if (width <= 0) {
3575 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "width <= 0");
3576 return 0;
3577 }
3578
3579 if (height <= 0) {
3580 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "height <= 0");
3581 return 0;
3582 }
3583
3584 // Create new buffer.
3585 return gpu_memory_buffer_tracker_->CreateBuffer(width, height);
no sievers 2013/05/10 01:21:51 Could that fail? Should we set OUT_OF_MEMORY or so
kaanb 2013/05/13 23:00:36 Yes, it could fail, right now we DCHECK() in andro
3586 }
3587
3588 GLuint GLES2Implementation::CreateImageCHROMIUM(GLsizei width, GLsizei height) {
3589 GPU_CLIENT_SINGLE_THREAD_CHECK();
3590 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCreateImageCHROMIUM("
3591 << width << ", "
3592 << height << ")");
3593 GLuint image_id = CreateImageCHROMIUMHelper(width, height);
3594 CheckGLError();
3595 return image_id;
3596 }
3597
3598 void GLES2Implementation::DestroyImageCHROMIUMHelper(GLuint image_id) {
3599 GpuMemoryBuffer* gpu_buffer =
3600 gpu_memory_buffer_tracker_->GetBuffer(image_id);
3601 if (!gpu_buffer) {
3602 SetGLError(GL_INVALID_OPERATION, "glDestroyImageImageCHROMIUM",
3603 "invalid GPU memory buffer");
no sievers 2013/05/10 01:21:51 nit: "invalid image" here and below
kaanb 2013/05/13 23:00:36 Done.
3604 return;
3605 }
3606
3607 gpu_memory_buffer_tracker_->RemoveBuffer(image_id);
3608 }
3609
3610 void GLES2Implementation::DestroyImageCHROMIUM(GLuint image_id) {
3611 GPU_CLIENT_SINGLE_THREAD_CHECK();
3612 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glDestroyImageCHROMIUM("
3613 << image_id << ")");
3614 DestroyImageCHROMIUMHelper(image_id);
3615 CheckGLError();
3616 }
3617
3618 GLboolean GLES2Implementation::UnmapImageCHROMIUMHelper(GLuint image_id) {
3619 GpuMemoryBuffer* gpu_buffer =
3620 gpu_memory_buffer_tracker_->GetBuffer(image_id);
3621 if (!gpu_buffer) {
3622 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM",
3623 "invalid GPU memory buffer");
3624 return false;
3625 }
3626
3627 if (!gpu_buffer->IsMapped()) {
3628 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM",
3629 "not mapped");
3630 return false;
3631 }
3632 gpu_buffer->Unmap();
3633 return true;
3634 }
3635
3636 GLboolean GLES2Implementation::UnmapImageCHROMIUM(GLuint image_id) {
3637 GPU_CLIENT_SINGLE_THREAD_CHECK();
3638 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glUnmapImageCHROMIUM("
3639 << image_id << ")");
3640
3641 bool success = UnmapImageCHROMIUMHelper(image_id);
3642 CheckGLError();
3643 return success;
3644 }
3645
3646 void* GLES2Implementation::MapImageCHROMIUMHelper(GLuint image_id,
3647 GLenum access) {
3648 GpuMemoryBuffer* gpu_buffer =
3649 gpu_memory_buffer_tracker_->GetBuffer(image_id);
3650 if (!gpu_buffer) {
3651 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM",
3652 "invalid GPU memory buffer");
3653 return NULL;
3654 }
3655 GpuMemoryBuffer::AccessMode mode = GpuMemoryBuffer::READ_ONLY;
no sievers 2013/05/10 01:21:51 nit: no need to initialize
kaanb 2013/05/13 23:00:36 Done.
3656 switch(access) {
3657 case GL_WRITE_ONLY:
3658 mode = GpuMemoryBuffer::WRITE_ONLY;
3659 break;
3660 case GL_READ_ONLY:
3661 mode = GpuMemoryBuffer::READ_ONLY;
3662 break;
3663 // TODO(kaanb): should we add GL_READ_WRITE to gl2ext.h?
no sievers 2013/05/10 01:21:51 Yes, isn't readwrite what we need to raster into t
kaanb 2013/05/13 23:00:36 Done.
3664 default:
3665 SetGLError(GL_INVALID_ENUM, "glMapImageCHROMIUM",
3666 "invalid GPU access mode");
3667 return NULL;
3668 }
3669
3670 if (gpu_buffer->IsMapped()) {
3671 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM",
3672 "already mapped");
3673 return NULL;
3674 }
3675
3676 void* mapped_buffer = NULL;
3677 gpu_buffer->Map(mode, &mapped_buffer);
no sievers 2013/05/10 01:21:51 Can this fail and should we set a GL error if so?
kaanb 2013/05/13 23:00:36 From what I understand the documentation, the only
no sievers 2013/05/14 21:10:03 If it's something the client can do wrong, then it
3678 return mapped_buffer;
3679 }
3680
3681 void* GLES2Implementation::MapImageCHROMIUM(
3682 GLuint image_id, GLenum access) {
3683 GPU_CLIENT_SINGLE_THREAD_CHECK();
3684 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glMapImageCHROMIUM("
3685 << image_id << ", "
3686 << GLES2Util::GetStringEnum(access) << ")");
3687
3688 void* mapped = MapImageCHROMIUMHelper(image_id, access);
3689 CheckGLError();
3690 return mapped;
3691 }
3692
3693 void GLES2Implementation::GetImageParameterivCHROMIUMHelper(
3694 GLuint image_id, GLenum pname, GLint* params) {
3695 if (pname != GL_IMAGE_ROWBYTES) {
3696 SetGLError(GL_INVALID_ENUM, "glGetImageParameterivCHROMIUM",
3697 "invalid target");
no sievers 2013/05/10 01:21:51 nit: invalid parameter
kaanb 2013/05/13 23:00:36 Done.
3698 return;
3699 }
3700
3701 GpuMemoryBuffer* gpu_buffer =
3702 gpu_memory_buffer_tracker_->GetBuffer(image_id);
3703 if (!gpu_buffer) {
3704 SetGLError(GL_INVALID_OPERATION, "glGetImageParameterivCHROMIUM",
3705 "invalid GPU memory buffer");
3706 return;
3707 }
3708
3709 *params = gpu_buffer->GetStride();
3710 }
3711
3712 void GLES2Implementation::GetImageParameterivCHROMIUM(
3713 GLuint image_id, GLenum pname, GLint* params) {
3714 GPU_CLIENT_SINGLE_THREAD_CHECK();
3715 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params);
3716 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glMapImageCHROMIUM("
3717 << image_id << ", "
3718 << GLES2Util::GetStringBufferParameter(pname) << ", "
3719 << static_cast<const void*>(params) << ")");
3720 GetImageParameterivCHROMIUM(image_id, pname, params);
3721 CheckGLError();
3722 }
3723
3561 // Include the auto-generated part of this file. We split this because it means 3724 // Include the auto-generated part of this file. We split this because it means
3562 // we can easily edit the non-auto generated parts right here in this file 3725 // we can easily edit the non-auto generated parts right here in this file
3563 // instead of having to edit some template or the code generator. 3726 // instead of having to edit some template or the code generator.
3564 #include "../client/gles2_implementation_impl_autogen.h" 3727 #include "../client/gles2_implementation_impl_autogen.h"
3565 3728
3566 } // namespace gles2 3729 } // namespace gles2
3567 } // namespace gpu 3730 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698