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 <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 #if defined(OS_NACL) | 154 #if defined(OS_NACL) |
155 0), | 155 0), |
156 #else | 156 #else |
157 // Do not use more than 5% of extra shared memory, and do not | 157 // Do not use more than 5% of extra shared memory, and do not |
158 // use any extra for memory contrained devices (<=1GB). | 158 // use any extra for memory contrained devices (<=1GB). |
159 base::SysInfo::AmountOfPhysicalMemory() > 1024 * 1024 * 1024 | 159 base::SysInfo::AmountOfPhysicalMemory() > 1024 * 1024 * 1024 |
160 ? base::saturated_cast<uint32_t>( | 160 ? base::saturated_cast<uint32_t>( |
161 base::SysInfo::AmountOfPhysicalMemory() / 20) | 161 base::SysInfo::AmountOfPhysicalMemory() / 20) |
162 : 0), | 162 : 0), |
163 #endif | 163 #endif |
164 error_message_callback_(NULL), | |
165 current_trace_stack_(0), | 164 current_trace_stack_(0), |
166 gpu_control_(gpu_control), | 165 gpu_control_(gpu_control), |
167 capabilities_(gpu_control->GetCapabilities()), | 166 capabilities_(gpu_control->GetCapabilities()), |
168 aggressively_free_resources_(false), | 167 aggressively_free_resources_(false), |
169 cached_extension_string_(nullptr), | 168 cached_extension_string_(nullptr), |
170 weak_ptr_factory_(this) { | 169 weak_ptr_factory_(this) { |
171 DCHECK(helper); | 170 DCHECK(helper); |
172 DCHECK(transfer_buffer); | 171 DCHECK(transfer_buffer); |
173 DCHECK(gpu_control); | 172 DCHECK(gpu_control); |
174 | 173 |
(...skipping 19 matching lines...) Expand all Loading... |
194 bool GLES2Implementation::Initialize( | 193 bool GLES2Implementation::Initialize( |
195 unsigned int starting_transfer_buffer_size, | 194 unsigned int starting_transfer_buffer_size, |
196 unsigned int min_transfer_buffer_size, | 195 unsigned int min_transfer_buffer_size, |
197 unsigned int max_transfer_buffer_size, | 196 unsigned int max_transfer_buffer_size, |
198 unsigned int mapped_memory_limit) { | 197 unsigned int mapped_memory_limit) { |
199 TRACE_EVENT0("gpu", "GLES2Implementation::Initialize"); | 198 TRACE_EVENT0("gpu", "GLES2Implementation::Initialize"); |
200 DCHECK_GE(starting_transfer_buffer_size, min_transfer_buffer_size); | 199 DCHECK_GE(starting_transfer_buffer_size, min_transfer_buffer_size); |
201 DCHECK_LE(starting_transfer_buffer_size, max_transfer_buffer_size); | 200 DCHECK_LE(starting_transfer_buffer_size, max_transfer_buffer_size); |
202 DCHECK_GE(min_transfer_buffer_size, kStartingOffset); | 201 DCHECK_GE(min_transfer_buffer_size, kStartingOffset); |
203 | 202 |
| 203 gpu_control_->SetGpuControlClient(this); |
| 204 |
204 if (!transfer_buffer_->Initialize( | 205 if (!transfer_buffer_->Initialize( |
205 starting_transfer_buffer_size, | 206 starting_transfer_buffer_size, |
206 kStartingOffset, | 207 kStartingOffset, |
207 min_transfer_buffer_size, | 208 min_transfer_buffer_size, |
208 max_transfer_buffer_size, | 209 max_transfer_buffer_size, |
209 kAlignment, | 210 kAlignment, |
210 kSizeToFlush)) { | 211 kSizeToFlush)) { |
211 return false; | 212 return false; |
212 } | 213 } |
213 | 214 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 // called but not the UnmapBuffer() pair. | 293 // called but not the UnmapBuffer() pair. |
293 ClearMappedBufferRangeMap(); | 294 ClearMappedBufferRangeMap(); |
294 | 295 |
295 // Release any per-context data in share group. | 296 // Release any per-context data in share group. |
296 share_group_->FreeContext(this); | 297 share_group_->FreeContext(this); |
297 | 298 |
298 buffer_tracker_.reset(); | 299 buffer_tracker_.reset(); |
299 | 300 |
300 // Make sure the commands make it the service. | 301 // Make sure the commands make it the service. |
301 WaitForCmd(); | 302 WaitForCmd(); |
| 303 |
| 304 // The gpu_control_ outlives this class, so clear the client on it before we |
| 305 // self-destruct. |
| 306 gpu_control_->SetGpuControlClient(nullptr); |
302 } | 307 } |
303 | 308 |
304 GLES2CmdHelper* GLES2Implementation::helper() const { | 309 GLES2CmdHelper* GLES2Implementation::helper() const { |
305 return helper_; | 310 return helper_; |
306 } | 311 } |
307 | 312 |
308 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { | 313 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { |
309 return share_group_->GetIdHandler(namespace_id); | 314 return share_group_->GetIdHandler(namespace_id); |
310 } | 315 } |
311 | 316 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 547 |
543 void GLES2Implementation::SetGLError( | 548 void GLES2Implementation::SetGLError( |
544 GLenum error, const char* function_name, const char* msg) { | 549 GLenum error, const char* function_name, const char* msg) { |
545 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] Client Synthesized Error: " | 550 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] Client Synthesized Error: " |
546 << GLES2Util::GetStringError(error) << ": " | 551 << GLES2Util::GetStringError(error) << ": " |
547 << function_name << ": " << msg); | 552 << function_name << ": " << msg); |
548 FailGLError(error); | 553 FailGLError(error); |
549 if (msg) { | 554 if (msg) { |
550 last_error_ = msg; | 555 last_error_ = msg; |
551 } | 556 } |
552 if (error_message_callback_) { | 557 if (!error_message_callback_.is_null()) { |
553 std::string temp(GLES2Util::GetStringError(error) + " : " + | 558 std::string temp(GLES2Util::GetStringError(error) + " : " + |
554 function_name + ": " + (msg ? msg : "")); | 559 function_name + ": " + (msg ? msg : "")); |
555 error_message_callback_->OnErrorMessage(temp.c_str(), 0); | 560 error_message_callback_.Run(temp.c_str(), 0); |
556 } | 561 } |
557 error_bits_ |= GLES2Util::GLErrorToErrorBit(error); | 562 error_bits_ |= GLES2Util::GLErrorToErrorBit(error); |
558 | 563 |
559 if (error == GL_OUT_OF_MEMORY && lose_context_when_out_of_memory_) { | 564 if (error == GL_OUT_OF_MEMORY && lose_context_when_out_of_memory_) { |
560 helper_->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 565 helper_->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
561 GL_UNKNOWN_CONTEXT_RESET_ARB); | 566 GL_UNKNOWN_CONTEXT_RESET_ARB); |
562 } | 567 } |
563 } | 568 } |
564 | 569 |
565 void GLES2Implementation::SetGLErrorInvalidEnum( | 570 void GLES2Implementation::SetGLErrorInvalidEnum( |
(...skipping 5245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5811 } | 5816 } |
5812 buffer->set_mapped(false); | 5817 buffer->set_mapped(false); |
5813 CheckGLError(); | 5818 CheckGLError(); |
5814 return true; | 5819 return true; |
5815 } | 5820 } |
5816 | 5821 |
5817 uint64_t GLES2Implementation::ShareGroupTracingGUID() const { | 5822 uint64_t GLES2Implementation::ShareGroupTracingGUID() const { |
5818 return share_group_->TracingGUID(); | 5823 return share_group_->TracingGUID(); |
5819 } | 5824 } |
5820 | 5825 |
| 5826 void GLES2Implementation::SetErrorMessageCallback( |
| 5827 const base::Callback<void(const char*, int32_t)>& callback) { |
| 5828 error_message_callback_ = callback; |
| 5829 } |
| 5830 |
| 5831 void GLES2Implementation::SetLostContextCallback( |
| 5832 const base::Closure& callback) { |
| 5833 lost_context_callback_ = callback; |
| 5834 } |
| 5835 |
| 5836 void GLES2Implementation::OnGpuControlLostContext() { |
| 5837 #if DCHECK_IS_ON() |
| 5838 // This should never occur more than once. |
| 5839 DCHECK(!lost_context_); |
| 5840 lost_context_ = true; |
| 5841 #endif |
| 5842 if (!lost_context_callback_.is_null()) |
| 5843 lost_context_callback_.Run(); |
| 5844 } |
| 5845 |
| 5846 void GLES2Implementation::OnGpuControlErrorMessage(const char* message, |
| 5847 int32_t id) { |
| 5848 if (!error_message_callback_.is_null()) |
| 5849 error_message_callback_.Run(message, id); |
| 5850 } |
| 5851 |
5821 GLuint64 GLES2Implementation::InsertFenceSyncCHROMIUM() { | 5852 GLuint64 GLES2Implementation::InsertFenceSyncCHROMIUM() { |
5822 const uint64_t release = gpu_control_->GenerateFenceSyncRelease(); | 5853 const uint64_t release = gpu_control_->GenerateFenceSyncRelease(); |
5823 helper_->InsertFenceSyncCHROMIUM(release); | 5854 helper_->InsertFenceSyncCHROMIUM(release); |
5824 return release; | 5855 return release; |
5825 } | 5856 } |
5826 | 5857 |
5827 void GLES2Implementation::GenSyncTokenCHROMIUM(GLuint64 fence_sync, | 5858 void GLES2Implementation::GenSyncTokenCHROMIUM(GLuint64 fence_sync, |
5828 GLbyte* sync_token) { | 5859 GLbyte* sync_token) { |
5829 if (!sync_token) { | 5860 if (!sync_token) { |
5830 SetGLError(GL_INVALID_VALUE, "glGenSyncTokenCHROMIUM", "empty sync_token"); | 5861 SetGLError(GL_INVALID_VALUE, "glGenSyncTokenCHROMIUM", "empty sync_token"); |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6846 cached_extensions_.clear(); | 6877 cached_extensions_.clear(); |
6847 } | 6878 } |
6848 | 6879 |
6849 // Include the auto-generated part of this file. We split this because it means | 6880 // Include the auto-generated part of this file. We split this because it means |
6850 // we can easily edit the non-auto generated parts right here in this file | 6881 // we can easily edit the non-auto generated parts right here in this file |
6851 // instead of having to edit some template or the code generator. | 6882 // instead of having to edit some template or the code generator. |
6852 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 6883 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
6853 | 6884 |
6854 } // namespace gles2 | 6885 } // namespace gles2 |
6855 } // namespace gpu | 6886 } // namespace gpu |
OLD | NEW |