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

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

Issue 20017005: gpu: Refactor GpuMemoryBuffer framework for multi-process support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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 "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/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 "gpu/command_buffer/client/buffer_tracker.h" 18 #include "gpu/command_buffer/client/buffer_tracker.h"
19 #include "gpu/command_buffer/client/gpu_memory_buffer.h"
20 #include "gpu/command_buffer/client/gpu_memory_buffer_tracker.h" 19 #include "gpu/command_buffer/client/gpu_memory_buffer_tracker.h"
21 #include "gpu/command_buffer/client/mapped_memory.h" 20 #include "gpu/command_buffer/client/mapped_memory.h"
22 #include "gpu/command_buffer/client/program_info_manager.h" 21 #include "gpu/command_buffer/client/program_info_manager.h"
23 #include "gpu/command_buffer/client/query_tracker.h" 22 #include "gpu/command_buffer/client/query_tracker.h"
24 #include "gpu/command_buffer/client/transfer_buffer.h" 23 #include "gpu/command_buffer/client/transfer_buffer.h"
25 #include "gpu/command_buffer/client/vertex_array_object_manager.h" 24 #include "gpu/command_buffer/client/vertex_array_object_manager.h"
26 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 25 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
27 #include "gpu/command_buffer/common/trace_event.h" 26 #include "gpu/command_buffer/common/trace_event.h"
27 #include "ui/gfx/gpu_memory_buffer.h"
28 28
29 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) 29 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
30 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS 30 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS
31 #endif 31 #endif
32 32
33 #if defined(GPU_CLIENT_DEBUG) 33 #if defined(GPU_CLIENT_DEBUG)
34 #include "ui/gl/gl_switches.h" 34 #include "ui/gl/gl_switches.h"
35 #include "base/command_line.h" 35 #include "base/command_line.h"
36 #endif 36 #endif
37 37
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 GLES2Implementation::SingleThreadChecker::~SingleThreadChecker() { 79 GLES2Implementation::SingleThreadChecker::~SingleThreadChecker() {
80 --gles2_implementation_->use_count_; 80 --gles2_implementation_->use_count_;
81 GPU_CHECK_EQ(0, gles2_implementation_->use_count_); 81 GPU_CHECK_EQ(0, gles2_implementation_->use_count_);
82 } 82 }
83 83
84 GLES2Implementation::GLES2Implementation( 84 GLES2Implementation::GLES2Implementation(
85 GLES2CmdHelper* helper, 85 GLES2CmdHelper* helper,
86 ShareGroup* share_group, 86 ShareGroup* share_group,
87 TransferBufferInterface* transfer_buffer, 87 TransferBufferInterface* transfer_buffer,
88 bool share_resources, 88 bool share_resources,
89 bool bind_generates_resource, 89 bool bind_generates_resource)
90 ImageFactory* image_factory)
91 : helper_(helper), 90 : helper_(helper),
92 transfer_buffer_(transfer_buffer), 91 transfer_buffer_(transfer_buffer),
93 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus), 92 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus),
94 chromium_framebuffer_multisample_(kUnknownExtensionStatus), 93 chromium_framebuffer_multisample_(kUnknownExtensionStatus),
95 pack_alignment_(4), 94 pack_alignment_(4),
96 unpack_alignment_(4), 95 unpack_alignment_(4),
97 unpack_flip_y_(false), 96 unpack_flip_y_(false),
98 unpack_row_length_(0), 97 unpack_row_length_(0),
99 unpack_skip_rows_(0), 98 unpack_skip_rows_(0),
100 unpack_skip_pixels_(0), 99 unpack_skip_pixels_(0),
101 pack_reverse_row_order_(false), 100 pack_reverse_row_order_(false),
102 active_texture_unit_(0), 101 active_texture_unit_(0),
103 bound_framebuffer_(0), 102 bound_framebuffer_(0),
104 bound_read_framebuffer_(0), 103 bound_read_framebuffer_(0),
105 bound_renderbuffer_(0), 104 bound_renderbuffer_(0),
106 current_program_(0), 105 current_program_(0),
107 bound_array_buffer_id_(0), 106 bound_array_buffer_id_(0),
108 bound_pixel_pack_transfer_buffer_id_(0), 107 bound_pixel_pack_transfer_buffer_id_(0),
109 bound_pixel_unpack_transfer_buffer_id_(0), 108 bound_pixel_unpack_transfer_buffer_id_(0),
110 error_bits_(0), 109 error_bits_(0),
111 debug_(false), 110 debug_(false),
112 use_count_(0), 111 use_count_(0),
113 current_query_(NULL), 112 current_query_(NULL),
114 error_message_callback_(NULL), 113 error_message_callback_(NULL) {
115 image_factory_(image_factory) {
116 GPU_DCHECK(helper); 114 GPU_DCHECK(helper);
117 GPU_DCHECK(transfer_buffer); 115 GPU_DCHECK(transfer_buffer);
118 116
119 char temp[128]; 117 char temp[128];
120 sprintf(temp, "%p", static_cast<void*>(this)); 118 sprintf(temp, "%p", static_cast<void*>(this));
121 this_in_hex_ = std::string(temp); 119 this_in_hex_ = std::string(temp);
122 120
123 GPU_CLIENT_LOG_CODE_BLOCK({ 121 GPU_CLIENT_LOG_CODE_BLOCK({
124 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( 122 debug_ = CommandLine::ForCurrentProcess()->HasSwitch(
125 switches::kEnableGPUClientLogging); 123 switches::kEnableGPUClientLogging);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 static_state_.int_state.num_compressed_texture_formats); 157 static_state_.int_state.num_compressed_texture_formats);
160 util_.set_num_shader_binary_formats( 158 util_.set_num_shader_binary_formats(
161 static_state_.int_state.num_shader_binary_formats); 159 static_state_.int_state.num_shader_binary_formats);
162 160
163 texture_units_.reset( 161 texture_units_.reset(
164 new TextureUnit[ 162 new TextureUnit[
165 static_state_.int_state.max_combined_texture_image_units]); 163 static_state_.int_state.max_combined_texture_image_units]);
166 164
167 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); 165 query_tracker_.reset(new QueryTracker(mapped_memory_.get()));
168 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); 166 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get()));
169 gpu_memory_buffer_tracker_.reset(new GpuMemoryBufferTracker(image_factory_)); 167 gpu_memory_buffer_tracker_.reset(new GpuMemoryBufferTracker(helper_));
170 168
171 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) 169 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
172 GetIdHandler(id_namespaces::kBuffers)->MakeIds( 170 GetIdHandler(id_namespaces::kBuffers)->MakeIds(
173 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); 171 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]);
174 #endif 172 #endif
175 173
176 vertex_array_object_manager_.reset(new VertexArrayObjectManager( 174 vertex_array_object_manager_.reset(new VertexArrayObjectManager(
177 static_state_.int_state.max_vertex_attribs, 175 static_state_.int_state.max_vertex_attribs,
178 reserved_ids_[0], 176 reserved_ids_[0],
179 reserved_ids_[1])); 177 reserved_ids_[1]));
(...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 // Clears the bucket so if the command fails nothing will be in it. 2083 // Clears the bucket so if the command fails nothing will be in it.
2086 helper_->SetBucketSize(kResultBucketId, 0); 2084 helper_->SetBucketSize(kResultBucketId, 0);
2087 helper_->GetString(name, kResultBucketId); 2085 helper_->GetString(name, kResultBucketId);
2088 std::string str; 2086 std::string str;
2089 if (GetBucketAsString(kResultBucketId, &str)) { 2087 if (GetBucketAsString(kResultBucketId, &str)) {
2090 // Adds extensions implemented on client side only. 2088 // Adds extensions implemented on client side only.
2091 switch (name) { 2089 switch (name) {
2092 case GL_EXTENSIONS: 2090 case GL_EXTENSIONS:
2093 str += std::string(str.empty() ? "" : " ") + 2091 str += std::string(str.empty() ? "" : " ") +
2094 "GL_CHROMIUM_flipy " 2092 "GL_CHROMIUM_flipy "
2093 "GL_CHROMIUM_map_image "
2095 "GL_CHROMIUM_map_sub " 2094 "GL_CHROMIUM_map_sub "
2096 "GL_CHROMIUM_shallow_flush " 2095 "GL_CHROMIUM_shallow_flush "
2097 "GL_EXT_unpack_subimage"; 2096 "GL_EXT_unpack_subimage";
2098 if (image_factory_ != NULL) {
2099 // The first space character is intentional.
2100 str += " GL_CHROMIUM_map_image";
2101 }
2102 break; 2097 break;
2103 default: 2098 default:
2104 break; 2099 break;
2105 } 2100 }
2106 2101
2107 // Because of WebGL the extensions can change. We have to cache each unique 2102 // Because of WebGL the extensions can change. We have to cache each unique
2108 // result since we don't know when the client will stop referring to a 2103 // result since we don't know when the client will stop referring to a
2109 // previous one it queries. 2104 // previous one it queries.
2110 GLStringMap::iterator it = gl_strings_.find(name); 2105 GLStringMap::iterator it = gl_strings_.find(name);
2111 if (it == gl_strings_.end()) { 2106 if (it == gl_strings_.end()) {
(...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCreateImageCHROMIUM(" 3693 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCreateImageCHROMIUM("
3699 << width << ", " 3694 << width << ", "
3700 << height << ", " 3695 << height << ", "
3701 << GLES2Util::GetStringTextureInternalFormat(internalformat) << ")"); 3696 << GLES2Util::GetStringTextureInternalFormat(internalformat) << ")");
3702 GLuint image_id = CreateImageCHROMIUMHelper(width, height, internalformat); 3697 GLuint image_id = CreateImageCHROMIUMHelper(width, height, internalformat);
3703 CheckGLError(); 3698 CheckGLError();
3704 return image_id; 3699 return image_id;
3705 } 3700 }
3706 3701
3707 void GLES2Implementation::DestroyImageCHROMIUMHelper(GLuint image_id) { 3702 void GLES2Implementation::DestroyImageCHROMIUMHelper(GLuint image_id) {
3708 GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer(image_id); 3703 gfx::GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer(
3704 image_id);
3709 if (!gpu_buffer) { 3705 if (!gpu_buffer) {
3710 SetGLError(GL_INVALID_OPERATION, "glDestroyImageCHROMIUM", "invalid image"); 3706 SetGLError(GL_INVALID_OPERATION, "glDestroyImageCHROMIUM", "invalid image");
3711 return; 3707 return;
3712 } 3708 }
3713 3709
3714 // Flush the command stream to make sure all pending commands 3710 // Flush the command stream to make sure all pending commands
3715 // that may refer to the image_id are executed on the service side. 3711 // that may refer to the image_id are executed on the service side.
3716 helper_->CommandBufferHelper::Flush(); 3712 helper_->CommandBufferHelper::Flush();
3717 gpu_memory_buffer_tracker_->RemoveBuffer(image_id); 3713 gpu_memory_buffer_tracker_->RemoveBuffer(image_id);
3718 } 3714 }
3719 3715
3720 void GLES2Implementation::DestroyImageCHROMIUM(GLuint image_id) { 3716 void GLES2Implementation::DestroyImageCHROMIUM(GLuint image_id) {
3721 GPU_CLIENT_SINGLE_THREAD_CHECK(); 3717 GPU_CLIENT_SINGLE_THREAD_CHECK();
3722 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glDestroyImageCHROMIUM(" 3718 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glDestroyImageCHROMIUM("
3723 << image_id << ")"); 3719 << image_id << ")");
3724 DestroyImageCHROMIUMHelper(image_id); 3720 DestroyImageCHROMIUMHelper(image_id);
3725 CheckGLError(); 3721 CheckGLError();
3726 } 3722 }
3727 3723
3728 void GLES2Implementation::UnmapImageCHROMIUMHelper(GLuint image_id) { 3724 void GLES2Implementation::UnmapImageCHROMIUMHelper(GLuint image_id) {
3729 GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer(image_id); 3725 gfx::GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer(
3726 image_id);
3730 if (!gpu_buffer) { 3727 if (!gpu_buffer) {
3731 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM", "invalid image"); 3728 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM", "invalid image");
3732 return; 3729 return;
3733 } 3730 }
3734 3731
3735 if (!gpu_buffer->IsMapped()) { 3732 if (!gpu_buffer->IsMapped()) {
3736 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM", "not mapped"); 3733 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM", "not mapped");
3737 return; 3734 return;
3738 } 3735 }
3739 gpu_buffer->Unmap(); 3736 gpu_buffer->Unmap();
3740 } 3737 }
3741 3738
3742 void GLES2Implementation::UnmapImageCHROMIUM(GLuint image_id) { 3739 void GLES2Implementation::UnmapImageCHROMIUM(GLuint image_id) {
3743 GPU_CLIENT_SINGLE_THREAD_CHECK(); 3740 GPU_CLIENT_SINGLE_THREAD_CHECK();
3744 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glUnmapImageCHROMIUM(" 3741 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glUnmapImageCHROMIUM("
3745 << image_id << ")"); 3742 << image_id << ")");
3746 3743
3747 UnmapImageCHROMIUMHelper(image_id); 3744 UnmapImageCHROMIUMHelper(image_id);
3748 CheckGLError(); 3745 CheckGLError();
3749 } 3746 }
3750 3747
3751 void* GLES2Implementation::MapImageCHROMIUMHelper(GLuint image_id, 3748 void* GLES2Implementation::MapImageCHROMIUMHelper(GLuint image_id,
3752 GLenum access) { 3749 GLenum access) {
3753 GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer(image_id); 3750 gfx::GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer(
3751 image_id);
3754 if (!gpu_buffer) { 3752 if (!gpu_buffer) {
3755 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM", "invalid image"); 3753 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM", "invalid image");
3756 return NULL; 3754 return NULL;
3757 } 3755 }
3758 GpuMemoryBuffer::AccessMode mode; 3756 gfx::GpuMemoryBuffer::AccessMode mode;
3759 switch(access) { 3757 switch(access) {
3760 case GL_WRITE_ONLY: 3758 case GL_WRITE_ONLY:
3761 mode = GpuMemoryBuffer::WRITE_ONLY; 3759 mode = gfx::GpuMemoryBuffer::WRITE_ONLY;
3762 break; 3760 break;
3763 case GL_READ_ONLY: 3761 case GL_READ_ONLY:
3764 mode = GpuMemoryBuffer::READ_ONLY; 3762 mode = gfx::GpuMemoryBuffer::READ_ONLY;
3765 break; 3763 break;
3766 case GL_READ_WRITE: 3764 case GL_READ_WRITE:
3767 mode = GpuMemoryBuffer::READ_WRITE; 3765 mode = gfx::GpuMemoryBuffer::READ_WRITE;
3768 break; 3766 break;
3769 default: 3767 default:
3770 SetGLError(GL_INVALID_ENUM, "glMapImageCHROMIUM", 3768 SetGLError(GL_INVALID_ENUM, "glMapImageCHROMIUM",
3771 "invalid GPU access mode"); 3769 "invalid GPU access mode");
3772 return NULL; 3770 return NULL;
3773 } 3771 }
3774 3772
3775 if (gpu_buffer->IsMapped()) { 3773 if (gpu_buffer->IsMapped()) {
3776 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM", "already mapped"); 3774 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM", "already mapped");
3777 return NULL; 3775 return NULL;
(...skipping 17 matching lines...) Expand all
3795 } 3793 }
3796 3794
3797 void GLES2Implementation::GetImageParameterivCHROMIUMHelper( 3795 void GLES2Implementation::GetImageParameterivCHROMIUMHelper(
3798 GLuint image_id, GLenum pname, GLint* params) { 3796 GLuint image_id, GLenum pname, GLint* params) {
3799 if (pname != GL_IMAGE_ROWBYTES_CHROMIUM) { 3797 if (pname != GL_IMAGE_ROWBYTES_CHROMIUM) {
3800 SetGLError(GL_INVALID_ENUM, "glGetImageParameterivCHROMIUM", 3798 SetGLError(GL_INVALID_ENUM, "glGetImageParameterivCHROMIUM",
3801 "invalid parameter"); 3799 "invalid parameter");
3802 return; 3800 return;
3803 } 3801 }
3804 3802
3805 GpuMemoryBuffer* gpu_buffer = 3803 gfx::GpuMemoryBuffer* gpu_buffer =
3806 gpu_memory_buffer_tracker_->GetBuffer(image_id); 3804 gpu_memory_buffer_tracker_->GetBuffer(image_id);
3807 if (!gpu_buffer) { 3805 if (!gpu_buffer) {
3808 SetGLError(GL_INVALID_OPERATION, "glGetImageParameterivCHROMIUM", 3806 SetGLError(GL_INVALID_OPERATION, "glGetImageParameterivCHROMIUM",
3809 "invalid image"); 3807 "invalid image");
3810 return; 3808 return;
3811 } 3809 }
3812 3810
3813 *params = gpu_buffer->GetStride(); 3811 *params = gpu_buffer->GetStride();
3814 } 3812 }
3815 3813
3816 void GLES2Implementation::GetImageParameterivCHROMIUM( 3814 void GLES2Implementation::GetImageParameterivCHROMIUM(
3817 GLuint image_id, GLenum pname, GLint* params) { 3815 GLuint image_id, GLenum pname, GLint* params) {
3818 GPU_CLIENT_SINGLE_THREAD_CHECK(); 3816 GPU_CLIENT_SINGLE_THREAD_CHECK();
3819 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); 3817 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params);
3820 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glImageParameterivCHROMIUM(" 3818 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glImageParameterivCHROMIUM("
3821 << image_id << ", " 3819 << image_id << ", "
3822 << GLES2Util::GetStringBufferParameter(pname) << ", " 3820 << GLES2Util::GetStringBufferParameter(pname) << ", "
3823 << static_cast<const void*>(params) << ")"); 3821 << static_cast<const void*>(params) << ")");
3824 GetImageParameterivCHROMIUMHelper(image_id, pname, params); 3822 GetImageParameterivCHROMIUMHelper(image_id, pname, params);
3825 CheckGLError(); 3823 CheckGLError();
3826 } 3824 }
3827 3825
3828 // Include the auto-generated part of this file. We split this because it means 3826 // Include the auto-generated part of this file. We split this because it means
3829 // we can easily edit the non-auto generated parts right here in this file 3827 // we can easily edit the non-auto generated parts right here in this file
3830 // instead of having to edit some template or the code generator. 3828 // instead of having to edit some template or the code generator.
3831 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" 3829 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h"
3832 3830
3833 } // namespace gles2 3831 } // namespace gles2
3834 } // namespace gpu 3832 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698