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