| 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 "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> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 CHECK_EQ(0, gles2_implementation_->use_count_); | 76 CHECK_EQ(0, gles2_implementation_->use_count_); |
| 77 ++gles2_implementation_->use_count_; | 77 ++gles2_implementation_->use_count_; |
| 78 } | 78 } |
| 79 | 79 |
| 80 GLES2Implementation::SingleThreadChecker::~SingleThreadChecker() { | 80 GLES2Implementation::SingleThreadChecker::~SingleThreadChecker() { |
| 81 --gles2_implementation_->use_count_; | 81 --gles2_implementation_->use_count_; |
| 82 CHECK_EQ(0, gles2_implementation_->use_count_); | 82 CHECK_EQ(0, gles2_implementation_->use_count_); |
| 83 } | 83 } |
| 84 | 84 |
| 85 GLES2Implementation::GLES2Implementation( | 85 GLES2Implementation::GLES2Implementation( |
| 86 GLES2CmdHelper* helper, | 86 GLES2CmdHelper* helper, |
| 87 ShareGroup* share_group, | 87 ShareGroup* share_group, |
| 88 TransferBufferInterface* transfer_buffer, | 88 TransferBufferInterface* transfer_buffer, |
| 89 bool bind_generates_resource, | 89 bool bind_generates_resource, |
| 90 bool lose_context_when_out_of_memory, | 90 GpuControl* gpu_control) |
| 91 GpuControl* gpu_control) | |
| 92 : helper_(helper), | 91 : helper_(helper), |
| 93 transfer_buffer_(transfer_buffer), | 92 transfer_buffer_(transfer_buffer), |
| 94 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus), | 93 angle_pack_reverse_row_order_status_(kUnknownExtensionStatus), |
| 95 chromium_framebuffer_multisample_(kUnknownExtensionStatus), | 94 chromium_framebuffer_multisample_(kUnknownExtensionStatus), |
| 96 pack_alignment_(4), | 95 pack_alignment_(4), |
| 97 unpack_alignment_(4), | 96 unpack_alignment_(4), |
| 98 unpack_flip_y_(false), | 97 unpack_flip_y_(false), |
| 99 unpack_row_length_(0), | 98 unpack_row_length_(0), |
| 100 unpack_skip_rows_(0), | 99 unpack_skip_rows_(0), |
| 101 unpack_skip_pixels_(0), | 100 unpack_skip_pixels_(0), |
| 102 pack_reverse_row_order_(false), | 101 pack_reverse_row_order_(false), |
| 103 active_texture_unit_(0), | 102 active_texture_unit_(0), |
| 104 bound_framebuffer_(0), | 103 bound_framebuffer_(0), |
| 105 bound_read_framebuffer_(0), | 104 bound_read_framebuffer_(0), |
| 106 bound_renderbuffer_(0), | 105 bound_renderbuffer_(0), |
| 107 current_program_(0), | 106 current_program_(0), |
| 108 bound_array_buffer_id_(0), | 107 bound_array_buffer_id_(0), |
| 109 bound_pixel_pack_transfer_buffer_id_(0), | 108 bound_pixel_pack_transfer_buffer_id_(0), |
| 110 bound_pixel_unpack_transfer_buffer_id_(0), | 109 bound_pixel_unpack_transfer_buffer_id_(0), |
| 111 async_upload_token_(0), | 110 async_upload_token_(0), |
| 112 async_upload_sync_(NULL), | 111 async_upload_sync_(NULL), |
| 113 async_upload_sync_shm_id_(0), | 112 async_upload_sync_shm_id_(0), |
| 114 async_upload_sync_shm_offset_(0), | 113 async_upload_sync_shm_offset_(0), |
| 115 error_bits_(0), | 114 error_bits_(0), |
| 116 debug_(false), | 115 debug_(false), |
| 117 lose_context_when_out_of_memory_(lose_context_when_out_of_memory), | |
| 118 use_count_(0), | 116 use_count_(0), |
| 119 error_message_callback_(NULL), | 117 error_message_callback_(NULL), |
| 120 gpu_control_(gpu_control), | 118 gpu_control_(gpu_control), |
| 121 capabilities_(gpu_control->GetCapabilities()), | 119 capabilities_(gpu_control->GetCapabilities()), |
| 122 weak_ptr_factory_(this) { | 120 weak_ptr_factory_(this) { |
| 123 DCHECK(helper); | 121 DCHECK(helper); |
| 124 DCHECK(transfer_buffer); | 122 DCHECK(transfer_buffer); |
| 125 DCHECK(gpu_control); | 123 DCHECK(gpu_control); |
| 126 | 124 |
| 127 std::stringstream ss; | 125 std::stringstream ss; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 FailGLError(error); | 497 FailGLError(error); |
| 500 if (msg) { | 498 if (msg) { |
| 501 last_error_ = msg; | 499 last_error_ = msg; |
| 502 } | 500 } |
| 503 if (error_message_callback_) { | 501 if (error_message_callback_) { |
| 504 std::string temp(GLES2Util::GetStringError(error) + " : " + | 502 std::string temp(GLES2Util::GetStringError(error) + " : " + |
| 505 function_name + ": " + (msg ? msg : "")); | 503 function_name + ": " + (msg ? msg : "")); |
| 506 error_message_callback_->OnErrorMessage(temp.c_str(), 0); | 504 error_message_callback_->OnErrorMessage(temp.c_str(), 0); |
| 507 } | 505 } |
| 508 error_bits_ |= GLES2Util::GLErrorToErrorBit(error); | 506 error_bits_ |= GLES2Util::GLErrorToErrorBit(error); |
| 509 | |
| 510 if (error == GL_OUT_OF_MEMORY && lose_context_when_out_of_memory_) { | |
| 511 helper_->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
| 512 GL_UNKNOWN_CONTEXT_RESET_ARB); | |
| 513 } | |
| 514 } | 507 } |
| 515 | 508 |
| 516 void GLES2Implementation::SetGLErrorInvalidEnum( | 509 void GLES2Implementation::SetGLErrorInvalidEnum( |
| 517 const char* function_name, GLenum value, const char* label) { | 510 const char* function_name, GLenum value, const char* label) { |
| 518 SetGLError(GL_INVALID_ENUM, function_name, | 511 SetGLError(GL_INVALID_ENUM, function_name, |
| 519 (std::string(label) + " was " + | 512 (std::string(label) + " was " + |
| 520 GLES2Util::GetStringEnum(value)).c_str()); | 513 GLES2Util::GetStringEnum(value)).c_str()); |
| 521 } | 514 } |
| 522 | 515 |
| 523 bool GLES2Implementation::GetBucketContents(uint32 bucket_id, | 516 bool GLES2Implementation::GetBucketContents(uint32 bucket_id, |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 } | 884 } |
| 892 | 885 |
| 893 void GLES2Implementation::ShallowFinishCHROMIUM() { | 886 void GLES2Implementation::ShallowFinishCHROMIUM() { |
| 894 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 887 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 895 TRACE_EVENT0("gpu", "GLES2::ShallowFinishCHROMIUM"); | 888 TRACE_EVENT0("gpu", "GLES2::ShallowFinishCHROMIUM"); |
| 896 // Flush our command buffer (tell the service to execute up to the flush cmd | 889 // Flush our command buffer (tell the service to execute up to the flush cmd |
| 897 // and don't return until it completes). | 890 // and don't return until it completes). |
| 898 helper_->CommandBufferHelper::Finish(); | 891 helper_->CommandBufferHelper::Finish(); |
| 899 } | 892 } |
| 900 | 893 |
| 894 bool GLES2Implementation::MustBeContextLost() { |
| 895 bool context_lost = helper_->IsContextLost(); |
| 896 if (!context_lost) { |
| 897 WaitForCmd(); |
| 898 context_lost = helper_->IsContextLost(); |
| 899 } |
| 900 CHECK(context_lost); |
| 901 return context_lost; |
| 902 } |
| 903 |
| 901 void GLES2Implementation::FinishHelper() { | 904 void GLES2Implementation::FinishHelper() { |
| 902 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glFinish()"); | 905 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glFinish()"); |
| 903 TRACE_EVENT0("gpu", "GLES2::Finish"); | 906 TRACE_EVENT0("gpu", "GLES2::Finish"); |
| 904 // Insert the cmd to call glFinish | 907 // Insert the cmd to call glFinish |
| 905 helper_->Finish(); | 908 helper_->Finish(); |
| 906 // Finish our command buffer | 909 // Finish our command buffer |
| 907 // (tell the service to execute up to the Finish cmd and wait for it to | 910 // (tell the service to execute up to the Finish cmd and wait for it to |
| 908 // execute.) | 911 // execute.) |
| 909 helper_->CommandBufferHelper::Finish(); | 912 helper_->CommandBufferHelper::Finish(); |
| 910 } | 913 } |
| (...skipping 2409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3320 return; | 3323 return; |
| 3321 } | 3324 } |
| 3322 | 3325 |
| 3323 // TODO(gman) if id not GENned INV_OPERATION | 3326 // TODO(gman) if id not GENned INV_OPERATION |
| 3324 | 3327 |
| 3325 // if id does not have an object | 3328 // if id does not have an object |
| 3326 QueryTracker::Query* query = query_tracker_->GetQuery(id); | 3329 QueryTracker::Query* query = query_tracker_->GetQuery(id); |
| 3327 if (!query) { | 3330 if (!query) { |
| 3328 query = query_tracker_->CreateQuery(id, target); | 3331 query = query_tracker_->CreateQuery(id, target); |
| 3329 if (!query) { | 3332 if (!query) { |
| 3330 SetGLError(GL_OUT_OF_MEMORY, | 3333 MustBeContextLost(); |
| 3331 "glBeginQueryEXT", | |
| 3332 "transfer buffer allocation failed"); | |
| 3333 return; | 3334 return; |
| 3334 } | 3335 } |
| 3335 } else if (query->target() != target) { | 3336 } else if (query->target() != target) { |
| 3336 SetGLError( | 3337 SetGLError( |
| 3337 GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); | 3338 GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); |
| 3338 return; | 3339 return; |
| 3339 } | 3340 } |
| 3340 | 3341 |
| 3341 current_queries_[target] = query; | 3342 current_queries_[target] = query; |
| 3342 | 3343 |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4056 CheckGLError(); | 4057 CheckGLError(); |
| 4057 } | 4058 } |
| 4058 | 4059 |
| 4059 // Include the auto-generated part of this file. We split this because it means | 4060 // Include the auto-generated part of this file. We split this because it means |
| 4060 // we can easily edit the non-auto generated parts right here in this file | 4061 // we can easily edit the non-auto generated parts right here in this file |
| 4061 // instead of having to edit some template or the code generator. | 4062 // instead of having to edit some template or the code generator. |
| 4062 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 4063 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
| 4063 | 4064 |
| 4064 } // namespace gles2 | 4065 } // namespace gles2 |
| 4065 } // namespace gpu | 4066 } // namespace gpu |
| OLD | NEW |