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 |
312 RangeIdHandlerInterface* GLES2Implementation::GetRangeIdHandler( | 317 RangeIdHandlerInterface* GLES2Implementation::GetRangeIdHandler( |
313 int namespace_id) const { | 318 int namespace_id) const { |
314 return share_group_->GetRangeIdHandler(namespace_id); | 319 return share_group_->GetRangeIdHandler(namespace_id); |
315 } | 320 } |
316 | 321 |
317 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const { | 322 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const { |
318 if (namespace_id == id_namespaces::kQueries) | 323 if (namespace_id == id_namespaces::kQueries) |
319 return query_id_allocator_.get(); | 324 return query_id_allocator_.get(); |
320 NOTREACHED(); | 325 NOTREACHED(); |
321 return NULL; | 326 return NULL; |
322 } | 327 } |
323 | 328 |
| 329 void GLES2Implementation::OnGpuControlLostContext() { |
| 330 #if DCHECK_IS_ON() |
| 331 // This should never occur more than once. |
| 332 DCHECK(!lost_context_); |
| 333 lost_context_ = true; |
| 334 #endif |
| 335 if (!lost_context_callback_.is_null()) |
| 336 lost_context_callback_.Run(); |
| 337 } |
| 338 |
| 339 void GLES2Implementation::OnGpuControlErrorMessage(const char* message, |
| 340 int32_t id) { |
| 341 if (!error_message_callback_.is_null()) |
| 342 error_message_callback_.Run(message, id); |
| 343 } |
| 344 |
324 void* GLES2Implementation::GetResultBuffer() { | 345 void* GLES2Implementation::GetResultBuffer() { |
325 return transfer_buffer_->GetResultBuffer(); | 346 return transfer_buffer_->GetResultBuffer(); |
326 } | 347 } |
327 | 348 |
328 int32_t GLES2Implementation::GetResultShmId() { | 349 int32_t GLES2Implementation::GetResultShmId() { |
329 return transfer_buffer_->GetShmId(); | 350 return transfer_buffer_->GetShmId(); |
330 } | 351 } |
331 | 352 |
332 uint32_t GLES2Implementation::GetResultShmOffset() { | 353 uint32_t GLES2Implementation::GetResultShmOffset() { |
333 return transfer_buffer_->GetResultOffset(); | 354 return transfer_buffer_->GetResultOffset(); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 563 |
543 void GLES2Implementation::SetGLError( | 564 void GLES2Implementation::SetGLError( |
544 GLenum error, const char* function_name, const char* msg) { | 565 GLenum error, const char* function_name, const char* msg) { |
545 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] Client Synthesized Error: " | 566 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] Client Synthesized Error: " |
546 << GLES2Util::GetStringError(error) << ": " | 567 << GLES2Util::GetStringError(error) << ": " |
547 << function_name << ": " << msg); | 568 << function_name << ": " << msg); |
548 FailGLError(error); | 569 FailGLError(error); |
549 if (msg) { | 570 if (msg) { |
550 last_error_ = msg; | 571 last_error_ = msg; |
551 } | 572 } |
552 if (error_message_callback_) { | 573 if (!error_message_callback_.is_null()) { |
553 std::string temp(GLES2Util::GetStringError(error) + " : " + | 574 std::string temp(GLES2Util::GetStringError(error) + " : " + |
554 function_name + ": " + (msg ? msg : "")); | 575 function_name + ": " + (msg ? msg : "")); |
555 error_message_callback_->OnErrorMessage(temp.c_str(), 0); | 576 error_message_callback_.Run(temp.c_str(), 0); |
556 } | 577 } |
557 error_bits_ |= GLES2Util::GLErrorToErrorBit(error); | 578 error_bits_ |= GLES2Util::GLErrorToErrorBit(error); |
558 | 579 |
559 if (error == GL_OUT_OF_MEMORY && lose_context_when_out_of_memory_) { | 580 if (error == GL_OUT_OF_MEMORY && lose_context_when_out_of_memory_) { |
560 helper_->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 581 helper_->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
561 GL_UNKNOWN_CONTEXT_RESET_ARB); | 582 GL_UNKNOWN_CONTEXT_RESET_ARB); |
562 } | 583 } |
563 } | 584 } |
564 | 585 |
565 void GLES2Implementation::SetGLErrorInvalidEnum( | 586 void GLES2Implementation::SetGLErrorInvalidEnum( |
(...skipping 5245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5811 } | 5832 } |
5812 buffer->set_mapped(false); | 5833 buffer->set_mapped(false); |
5813 CheckGLError(); | 5834 CheckGLError(); |
5814 return true; | 5835 return true; |
5815 } | 5836 } |
5816 | 5837 |
5817 uint64_t GLES2Implementation::ShareGroupTracingGUID() const { | 5838 uint64_t GLES2Implementation::ShareGroupTracingGUID() const { |
5818 return share_group_->TracingGUID(); | 5839 return share_group_->TracingGUID(); |
5819 } | 5840 } |
5820 | 5841 |
| 5842 void GLES2Implementation::SetErrorMessageCallback( |
| 5843 const base::Callback<void(const char*, int32_t)>& callback) { |
| 5844 error_message_callback_ = callback; |
| 5845 } |
| 5846 |
| 5847 void GLES2Implementation::SetLostContextCallback( |
| 5848 const base::Closure& callback) { |
| 5849 lost_context_callback_ = callback; |
| 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 |