OLD | NEW |
---|---|
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.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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 GLES2Implementation::SingleThreadChecker::~SingleThreadChecker() { | 74 GLES2Implementation::SingleThreadChecker::~SingleThreadChecker() { |
72 --gles2_implementation_->use_count_; | 75 --gles2_implementation_->use_count_; |
73 GPU_CHECK_EQ(0, gles2_implementation_->use_count_); | 76 GPU_CHECK_EQ(0, gles2_implementation_->use_count_); |
74 } | 77 } |
75 | 78 |
76 GLES2Implementation::GLES2Implementation( | 79 GLES2Implementation::GLES2Implementation( |
77 GLES2CmdHelper* helper, | 80 GLES2CmdHelper* helper, |
78 ShareGroup* share_group, | 81 ShareGroup* share_group, |
79 TransferBufferInterface* transfer_buffer, | 82 TransferBufferInterface* transfer_buffer, |
80 bool share_resources, | 83 bool share_resources, |
81 bool bind_generates_resource) | 84 bool bind_generates_resource, |
85 ImageFactory* image_factory) | |
82 : helper_(helper), | 86 : helper_(helper), |
83 transfer_buffer_(transfer_buffer), | 87 transfer_buffer_(transfer_buffer), |
84 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus), | 88 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus), |
85 chromium_framebuffer_multisample_(kUnknownExtensionStatus), | 89 chromium_framebuffer_multisample_(kUnknownExtensionStatus), |
86 pack_alignment_(4), | 90 pack_alignment_(4), |
87 unpack_alignment_(4), | 91 unpack_alignment_(4), |
88 unpack_flip_y_(false), | 92 unpack_flip_y_(false), |
89 unpack_row_length_(0), | 93 unpack_row_length_(0), |
90 unpack_skip_rows_(0), | 94 unpack_skip_rows_(0), |
91 unpack_skip_pixels_(0), | 95 unpack_skip_pixels_(0), |
92 pack_reverse_row_order_(false), | 96 pack_reverse_row_order_(false), |
93 active_texture_unit_(0), | 97 active_texture_unit_(0), |
94 bound_framebuffer_(0), | 98 bound_framebuffer_(0), |
95 bound_read_framebuffer_(0), | 99 bound_read_framebuffer_(0), |
96 bound_renderbuffer_(0), | 100 bound_renderbuffer_(0), |
97 current_program_(0), | 101 current_program_(0), |
98 bound_array_buffer_id_(0), | 102 bound_array_buffer_id_(0), |
99 bound_pixel_pack_transfer_buffer_id_(0), | 103 bound_pixel_pack_transfer_buffer_id_(0), |
100 bound_pixel_unpack_transfer_buffer_id_(0), | 104 bound_pixel_unpack_transfer_buffer_id_(0), |
101 error_bits_(0), | 105 error_bits_(0), |
102 debug_(false), | 106 debug_(false), |
103 use_count_(0), | 107 use_count_(0), |
104 current_query_(NULL), | 108 current_query_(NULL), |
105 error_message_callback_(NULL) { | 109 error_message_callback_(NULL), |
110 image_factory_(image_factory) { | |
106 GPU_DCHECK(helper); | 111 GPU_DCHECK(helper); |
107 GPU_DCHECK(transfer_buffer); | 112 GPU_DCHECK(transfer_buffer); |
108 | 113 |
109 char temp[128]; | 114 char temp[128]; |
110 sprintf(temp, "%p", static_cast<void*>(this)); | 115 sprintf(temp, "%p", static_cast<void*>(this)); |
111 this_in_hex_ = std::string(temp); | 116 this_in_hex_ = std::string(temp); |
112 | 117 |
113 GPU_CLIENT_LOG_CODE_BLOCK({ | 118 GPU_CLIENT_LOG_CODE_BLOCK({ |
114 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( | 119 debug_ = CommandLine::ForCurrentProcess()->HasSwitch( |
115 switches::kEnableGPUClientLogging); | 120 switches::kEnableGPUClientLogging); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 static_state_.int_state.num_compressed_texture_formats); | 171 static_state_.int_state.num_compressed_texture_formats); |
167 util_.set_num_shader_binary_formats( | 172 util_.set_num_shader_binary_formats( |
168 static_state_.int_state.num_shader_binary_formats); | 173 static_state_.int_state.num_shader_binary_formats); |
169 | 174 |
170 texture_units_.reset( | 175 texture_units_.reset( |
171 new TextureUnit[ | 176 new TextureUnit[ |
172 static_state_.int_state.max_combined_texture_image_units]); | 177 static_state_.int_state.max_combined_texture_image_units]); |
173 | 178 |
174 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); | 179 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); |
175 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); | 180 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); |
181 gpu_memory_buffer_tracker_.reset(new GpuMemoryBufferTracker(image_factory_)); | |
176 | 182 |
177 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) | 183 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) |
178 GetIdHandler(id_namespaces::kBuffers)->MakeIds( | 184 GetIdHandler(id_namespaces::kBuffers)->MakeIds( |
179 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); | 185 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); |
180 #endif | 186 #endif |
181 | 187 |
182 vertex_array_object_manager_.reset(new VertexArrayObjectManager( | 188 vertex_array_object_manager_.reset(new VertexArrayObjectManager( |
183 static_state_.int_state.max_vertex_attribs, | 189 static_state_.int_state.max_vertex_attribs, |
184 reserved_ids_[0], | 190 reserved_ids_[0], |
185 reserved_ids_[1])); | 191 reserved_ids_[1])); |
(...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2022 std::string str; | 2028 std::string str; |
2023 if (GetBucketAsString(kResultBucketId, &str)) { | 2029 if (GetBucketAsString(kResultBucketId, &str)) { |
2024 // Adds extensions implemented on client side only. | 2030 // Adds extensions implemented on client side only. |
2025 switch (name) { | 2031 switch (name) { |
2026 case GL_EXTENSIONS: | 2032 case GL_EXTENSIONS: |
2027 str += std::string(str.empty() ? "" : " ") + | 2033 str += std::string(str.empty() ? "" : " ") + |
2028 "GL_CHROMIUM_flipy " | 2034 "GL_CHROMIUM_flipy " |
2029 "GL_CHROMIUM_map_sub " | 2035 "GL_CHROMIUM_map_sub " |
2030 "GL_CHROMIUM_shallow_flush " | 2036 "GL_CHROMIUM_shallow_flush " |
2031 "GL_EXT_unpack_subimage"; | 2037 "GL_EXT_unpack_subimage"; |
2038 if (image_factory_ != NULL) { | |
2039 // The first space character is intentional. | |
2040 str += " GL_CHROMIUM_map_image"; | |
2041 } | |
2032 break; | 2042 break; |
2033 default: | 2043 default: |
2034 break; | 2044 break; |
2035 } | 2045 } |
2036 | 2046 |
2037 // Because of WebGL the extensions can change. We have to cache each unique | 2047 // 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 | 2048 // result since we don't know when the client will stop referring to a |
2039 // previous one it queries. | 2049 // previous one it queries. |
2040 GLStringMap::iterator it = gl_strings_.find(name); | 2050 GLStringMap::iterator it = gl_strings_.find(name); |
2041 if (it == gl_strings_.end()) { | 2051 if (it == gl_strings_.end()) { |
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3431 "[" << GetLogPrefix() << "] glUnmapBufferCHROMIUM(" << target << ")"); | 3441 "[" << GetLogPrefix() << "] glUnmapBufferCHROMIUM(" << target << ")"); |
3432 GLuint buffer_id; | 3442 GLuint buffer_id; |
3433 if (!GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", &buffer_id)) { | 3443 if (!GetBoundPixelTransferBuffer(target, "glMapBufferCHROMIUM", &buffer_id)) { |
3434 SetGLError(GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target"); | 3444 SetGLError(GL_INVALID_ENUM, "glUnmapBufferCHROMIUM", "invalid target"); |
3435 } | 3445 } |
3436 if (!buffer_id) { | 3446 if (!buffer_id) { |
3437 return false; | 3447 return false; |
3438 } | 3448 } |
3439 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id); | 3449 BufferTracker::Buffer* buffer = buffer_tracker_->GetBuffer(buffer_id); |
3440 if (!buffer) { | 3450 if (!buffer) { |
3441 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "invalid buffer"); | 3451 SetGLError(GL_INVALID_OPERATION, "glUnmapBufferCHROMIUM", "invalid buffer"); |
3442 return false; | 3452 return false; |
3443 } | 3453 } |
3444 if (!buffer->mapped()) { | 3454 if (!buffer->mapped()) { |
3445 SetGLError(GL_INVALID_OPERATION, "glMapBufferCHROMIUM", "not mapped"); | 3455 SetGLError(GL_INVALID_OPERATION, "glUnmapBufferCHROMIUM", "not mapped"); |
3446 return false; | 3456 return false; |
3447 } | 3457 } |
3448 buffer->set_mapped(false); | 3458 buffer->set_mapped(false); |
3449 CheckGLError(); | 3459 CheckGLError(); |
3450 return true; | 3460 return true; |
3451 } | 3461 } |
3452 | 3462 |
3453 void GLES2Implementation::AsyncTexImage2DCHROMIUM( | 3463 void GLES2Implementation::AsyncTexImage2DCHROMIUM( |
3454 GLenum target, GLint level, GLint internalformat, GLsizei width, | 3464 GLenum target, GLint level, GLint internalformat, GLsizei width, |
3455 GLsizei height, GLint border, GLenum format, GLenum type, | 3465 GLsizei height, GLint border, GLenum format, GLenum type, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3551 helper_->WaitAsyncTexImage2DCHROMIUM(target); | 3561 helper_->WaitAsyncTexImage2DCHROMIUM(target); |
3552 CheckGLError(); | 3562 CheckGLError(); |
3553 } | 3563 } |
3554 | 3564 |
3555 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() { | 3565 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() { |
3556 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 3566 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
3557 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM"); | 3567 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM"); |
3558 return helper_->InsertSyncPointCHROMIUM(); | 3568 return helper_->InsertSyncPointCHROMIUM(); |
3559 } | 3569 } |
3560 | 3570 |
3571 GLuint GLES2Implementation::CreateImageCHROMIUMHelper( | |
3572 GLsizei width, GLsizei height, GLenum internalformat) { | |
3573 if (width <= 0) { | |
3574 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "width <= 0"); | |
3575 return 0; | |
3576 } | |
3577 | |
3578 if (height <= 0) { | |
3579 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "height <= 0"); | |
3580 return 0; | |
3581 } | |
3582 // Flush the command stream to make sure all pending commands | |
3583 // that may refer to the image_id are executed on the service side. | |
3584 helper_->CommandBufferHelper::Flush(); | |
3585 | |
3586 // Create new buffer. | |
3587 return gpu_memory_buffer_tracker_->CreateBuffer( | |
3588 width, height, internalformat); | |
3589 } | |
3590 | |
3591 GLuint GLES2Implementation::CreateImageCHROMIUM( | |
3592 GLsizei width, GLsizei height, GLenum internalformat) { | |
3593 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
3594 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCreateImageCHROMIUM(" | |
3595 << width << ", " | |
3596 << height << ", " | |
3597 << GLES2Util::GetStringTextureInternalFormat(internalformat) << ")"); | |
3598 GLuint image_id = CreateImageCHROMIUMHelper(width, height, internalformat); | |
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, "glDestroyImageCHROMIUM", | |
3608 "invalid image"); | |
3609 return; | |
3610 } | |
3611 | |
3612 // Flush the command stream to make sure all pending commands | |
3613 // that may refer to the image_id are executed on the service side. | |
3614 helper_->CommandBufferHelper::Flush(); | |
3615 gpu_memory_buffer_tracker_->RemoveBuffer(image_id); | |
3616 } | |
3617 | |
3618 void GLES2Implementation::DestroyImageCHROMIUM(GLuint image_id) { | |
3619 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
3620 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glDestroyImageCHROMIUM(" | |
3621 << image_id << ")"); | |
3622 DestroyImageCHROMIUMHelper(image_id); | |
3623 CheckGLError(); | |
3624 } | |
3625 | |
3626 void GLES2Implementation::UnmapImageCHROMIUMHelper(GLuint image_id) { | |
3627 GpuMemoryBuffer* gpu_buffer = | |
3628 gpu_memory_buffer_tracker_->GetBuffer(image_id); | |
3629 if (!gpu_buffer) { | |
3630 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM", "invalid image"); | |
3631 return; | |
3632 } | |
3633 | |
3634 if (!gpu_buffer->IsMapped()) { | |
3635 SetGLError(GL_INVALID_OPERATION, "glUnmapImageCHROMIUM", "not mapped"); | |
3636 return; | |
3637 } | |
3638 gpu_buffer->Unmap(); | |
3639 } | |
3640 | |
3641 void GLES2Implementation::UnmapImageCHROMIUM(GLuint image_id) { | |
3642 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
3643 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glUnmapImageCHROMIUM(" | |
3644 << image_id << ")"); | |
3645 | |
3646 UnmapImageCHROMIUMHelper(image_id); | |
3647 CheckGLError(); | |
3648 } | |
3649 | |
3650 void* GLES2Implementation::MapImageCHROMIUMHelper(GLuint image_id, | |
3651 GLenum access) { | |
3652 GpuMemoryBuffer* gpu_buffer = | |
3653 gpu_memory_buffer_tracker_->GetBuffer(image_id); | |
3654 if (!gpu_buffer) { | |
3655 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM", "invalid image"); | |
3656 return NULL; | |
3657 } | |
3658 GpuMemoryBuffer::AccessMode mode; | |
3659 switch(access) { | |
3660 case GL_WRITE_ONLY: | |
3661 mode = GpuMemoryBuffer::WRITE_ONLY; | |
3662 break; | |
3663 case GL_READ_ONLY: | |
3664 mode = GpuMemoryBuffer::READ_ONLY; | |
3665 break; | |
3666 case GL_READ_WRITE: | |
3667 mode = GpuMemoryBuffer::READ_OR_WRITE; | |
reveman
2013/05/14 01:21:04
Can we call this GpuMemoryBuffer::READ_WRITE inste
kaanb
2013/05/14 18:12:11
Done.
| |
3668 break; | |
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", "already mapped"); | |
3677 return NULL; | |
3678 } | |
3679 | |
3680 void* mapped_buffer = NULL; | |
3681 gpu_buffer->Map(mode, &mapped_buffer); | |
3682 return mapped_buffer; | |
3683 } | |
3684 | |
3685 void* GLES2Implementation::MapImageCHROMIUM( | |
3686 GLuint image_id, GLenum access) { | |
3687 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
3688 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glMapImageCHROMIUM(" | |
3689 << image_id << ", " | |
3690 << GLES2Util::GetStringEnum(access) << ")"); | |
3691 | |
3692 void* mapped = MapImageCHROMIUMHelper(image_id, access); | |
3693 CheckGLError(); | |
3694 return mapped; | |
3695 } | |
3696 | |
3697 void GLES2Implementation::GetImageParameterivCHROMIUMHelper( | |
3698 GLuint image_id, GLenum pname, GLint* params) { | |
3699 if (pname != GL_IMAGE_ROWBYTES_CHROMIUM) { | |
3700 SetGLError(GL_INVALID_ENUM, "glGetImageParameterivCHROMIUM", | |
3701 "invalid parameter"); | |
3702 return; | |
3703 } | |
3704 | |
3705 GpuMemoryBuffer* gpu_buffer = | |
3706 gpu_memory_buffer_tracker_->GetBuffer(image_id); | |
3707 if (!gpu_buffer) { | |
3708 SetGLError(GL_INVALID_OPERATION, "glGetImageParameterivCHROMIUM", | |
3709 "invalid image"); | |
3710 return; | |
3711 } | |
3712 | |
3713 *params = gpu_buffer->GetStride(); | |
3714 } | |
3715 | |
3716 void GLES2Implementation::GetImageParameterivCHROMIUM( | |
3717 GLuint image_id, GLenum pname, GLint* params) { | |
3718 GPU_CLIENT_SINGLE_THREAD_CHECK(); | |
3719 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); | |
3720 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glMapImageCHROMIUM(" | |
3721 << image_id << ", " | |
3722 << GLES2Util::GetStringBufferParameter(pname) << ", " | |
3723 << static_cast<const void*>(params) << ")"); | |
3724 GetImageParameterivCHROMIUM(image_id, pname, params); | |
3725 CheckGLError(); | |
3726 } | |
3727 | |
3561 // Include the auto-generated part of this file. We split this because it means | 3728 // 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 | 3729 // 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. | 3730 // instead of having to edit some template or the code generator. |
3564 #include "../client/gles2_implementation_impl_autogen.h" | 3731 #include "../client/gles2_implementation_impl_autogen.h" |
3565 | 3732 |
3566 } // namespace gles2 | 3733 } // namespace gles2 |
3567 } // namespace gpu | 3734 } // namespace gpu |
OLD | NEW |