| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "platform/graphics/gpu/SharedGpuContext.h" | 5 #include "platform/graphics/gpu/SharedGpuContext.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_interface.h" | 7 #include "gpu/command_buffer/client/gles2_interface.h" |
| 8 #include "gpu/command_buffer/common/capabilities.h" | 8 #include "gpu/command_buffer/common/capabilities.h" |
| 9 #include "platform/CrossThreadFunctional.h" | 9 #include "platform/CrossThreadFunctional.h" |
| 10 #include "platform/WaitableEvent.h" | 10 #include "platform/WaitableEvent.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 SharedGpuContext::SharedGpuContext() : context_id_(kNoSharedContext) { | 24 SharedGpuContext::SharedGpuContext() : context_id_(kNoSharedContext) { |
| 25 CreateContextProviderIfNeeded(); | 25 CreateContextProviderIfNeeded(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void SharedGpuContext::CreateContextProviderOnMainThread( | 28 void SharedGpuContext::CreateContextProviderOnMainThread( |
| 29 WaitableEvent* waitable_event) { | 29 WaitableEvent* waitable_event) { |
| 30 DCHECK(IsMainThread()); | 30 DCHECK(IsMainThread()); |
| 31 Platform::ContextAttributes context_attributes; | 31 Platform::ContextAttributes context_attributes; |
| 32 context_attributes.web_gl_version = 1; // GLES2 | 32 context_attributes.web_gl_version = 1; // GLES2 |
| 33 Platform::GraphicsInfo graphics_info; | 33 Platform::GraphicsInfo graphics_info; |
| 34 context_provider_ = | 34 context_provider_ = WTF::WrapUnique( |
| 35 Platform::Current()->CreateOffscreenGraphicsContext3DProvider( | 35 Platform::Current()->CreateOffscreenGraphicsContext3DProvider( |
| 36 context_attributes, WebURL(), nullptr, &graphics_info); | 36 context_attributes, WebURL(), nullptr, &graphics_info)); |
| 37 if (waitable_event) | 37 if (waitable_event) |
| 38 waitable_event->Signal(); | 38 waitable_event->Signal(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void SharedGpuContext::CreateContextProviderIfNeeded() { | 41 void SharedGpuContext::CreateContextProviderIfNeeded() { |
| 42 if (context_provider_ && | 42 if (context_provider_ && |
| 43 context_provider_->ContextGL()->GetGraphicsResetStatusKHR() == | 43 context_provider_->ContextGL()->GetGraphicsResetStatusKHR() == |
| 44 GL_NO_ERROR) | 44 GL_NO_ERROR) |
| 45 return; | 45 return; |
| 46 | 46 |
| 47 std::unique_ptr<WebGraphicsContext3DProvider> old_context_provider = | 47 std::unique_ptr<WebGraphicsContext3DProvider> old_context_provider = |
| 48 std::move(context_provider_); | 48 std::move(context_provider_); |
| 49 if (context_provider_factory_) { | 49 if (context_provider_factory_) { |
| 50 // This path should only be used in unit tests | 50 // This path should only be used in unit tests |
| 51 context_provider_ = context_provider_factory_(); | 51 context_provider_ = context_provider_factory_(); |
| 52 } else if (IsMainThread()) { | 52 } else if (IsMainThread()) { |
| 53 context_provider_ = blink::Platform::Current() | 53 context_provider_ = |
| 54 ->CreateSharedOffscreenGraphicsContext3DProvider(); | 54 WTF::WrapUnique(blink::Platform::Current() |
| 55 ->CreateSharedOffscreenGraphicsContext3DProvider()); |
| 55 } else { | 56 } else { |
| 56 // This synchronous round-trip to the main thread is the reason why | 57 // This synchronous round-trip to the main thread is the reason why |
| 57 // SharedGpuContext encasulates the context provider: so we only have to do | 58 // SharedGpuContext encasulates the context provider: so we only have to do |
| 58 // this once per thread. | 59 // this once per thread. |
| 59 WaitableEvent waitable_event; | 60 WaitableEvent waitable_event; |
| 60 RefPtr<WebTaskRunner> task_runner = | 61 RefPtr<WebTaskRunner> task_runner = |
| 61 Platform::Current()->MainThread()->GetWebTaskRunner(); | 62 Platform::Current()->MainThread()->GetWebTaskRunner(); |
| 62 task_runner->PostTask( | 63 task_runner->PostTask( |
| 63 BLINK_FROM_HERE, | 64 BLINK_FROM_HERE, |
| 64 CrossThreadBind(&SharedGpuContext::CreateContextProviderOnMainThread, | 65 CrossThreadBind(&SharedGpuContext::CreateContextProviderOnMainThread, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 130 |
| 130 bool SharedGpuContext::AllowSoftwareToAcceleratedCanvasUpgrade() { | 131 bool SharedGpuContext::AllowSoftwareToAcceleratedCanvasUpgrade() { |
| 131 if (!IsValid()) | 132 if (!IsValid()) |
| 132 return kNoSharedContext; | 133 return kNoSharedContext; |
| 133 SharedGpuContext* this_ptr = GetInstanceForCurrentThread(); | 134 SharedGpuContext* this_ptr = GetInstanceForCurrentThread(); |
| 134 return this_ptr->context_provider_->GetCapabilities() | 135 return this_ptr->context_provider_->GetCapabilities() |
| 135 .software_to_accelerated_canvas_upgrade; | 136 .software_to_accelerated_canvas_upgrade; |
| 136 } | 137 } |
| 137 | 138 |
| 138 } // blink | 139 } // blink |
| OLD | NEW |