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 "platform/CrossThreadFunctional.h" | 8 #include "platform/CrossThreadFunctional.h" |
9 #include "platform/WaitableEvent.h" | 9 #include "platform/WaitableEvent.h" |
10 #include "platform/WebTaskRunner.h" | 10 #include "platform/WebTaskRunner.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 SharedGpuContext::SharedGpuContext() : m_contextId(kNoSharedContext) { | 23 SharedGpuContext::SharedGpuContext() : m_contextId(kNoSharedContext) { |
24 createContextProviderIfNeeded(); | 24 createContextProviderIfNeeded(); |
25 } | 25 } |
26 | 26 |
27 void SharedGpuContext::createContextProviderOnMainThread( | 27 void SharedGpuContext::createContextProviderOnMainThread( |
28 WaitableEvent* waitableEvent) { | 28 WaitableEvent* waitableEvent) { |
29 DCHECK(isMainThread()); | 29 DCHECK(isMainThread()); |
30 Platform::ContextAttributes contextAttributes; | 30 Platform::ContextAttributes contextAttributes; |
31 contextAttributes.webGLVersion = 1; // GLES2 | 31 contextAttributes.webGLVersion = 1; // GLES2 |
32 Platform::GraphicsInfo graphicsInfo; | 32 Platform::GraphicsInfo graphicsInfo; |
33 m_contextProvider = | 33 m_contextProvider = WTF::wrapUnique( |
34 wrapUnique(Platform::current()->createOffscreenGraphicsContext3DProvider( | 34 Platform::current()->createOffscreenGraphicsContext3DProvider( |
35 contextAttributes, WebURL(), nullptr, &graphicsInfo)); | 35 contextAttributes, WebURL(), nullptr, &graphicsInfo)); |
36 if (waitableEvent) | 36 if (waitableEvent) |
37 waitableEvent->signal(); | 37 waitableEvent->signal(); |
38 } | 38 } |
39 | 39 |
40 void SharedGpuContext::createContextProviderIfNeeded() { | 40 void SharedGpuContext::createContextProviderIfNeeded() { |
41 if (m_contextProvider && | 41 if (m_contextProvider && |
42 m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() == | 42 m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() == |
43 GL_NO_ERROR) | 43 GL_NO_ERROR) |
44 return; | 44 return; |
45 | 45 |
46 std::unique_ptr<WebGraphicsContext3DProvider> oldContextProvider = | 46 std::unique_ptr<WebGraphicsContext3DProvider> oldContextProvider = |
47 std::move(m_contextProvider); | 47 std::move(m_contextProvider); |
48 if (m_contextProviderFactory) { | 48 if (m_contextProviderFactory) { |
49 // This path should only be used in unit tests | 49 // This path should only be used in unit tests |
50 m_contextProvider = m_contextProviderFactory(); | 50 m_contextProvider = m_contextProviderFactory(); |
51 } else if (isMainThread()) { | 51 } else if (isMainThread()) { |
52 m_contextProvider = | 52 m_contextProvider = |
53 wrapUnique(blink::Platform::current() | 53 WTF::wrapUnique(blink::Platform::current() |
54 ->createSharedOffscreenGraphicsContext3DProvider()); | 54 ->createSharedOffscreenGraphicsContext3DProvider()); |
55 } else { | 55 } else { |
56 // This synchronous round-trip to the main thread is the reason why | 56 // This synchronous round-trip to the main thread is the reason why |
57 // SharedGpuContext encasulates the context provider: so we only have to do | 57 // SharedGpuContext encasulates the context provider: so we only have to do |
58 // this once per thread. | 58 // this once per thread. |
59 WaitableEvent waitableEvent; | 59 WaitableEvent waitableEvent; |
60 WebTaskRunner* taskRunner = | 60 WebTaskRunner* taskRunner = |
61 Platform::current()->mainThread()->getWebTaskRunner(); | 61 Platform::current()->mainThread()->getWebTaskRunner(); |
62 taskRunner->postTask( | 62 taskRunner->postTask( |
63 BLINK_FROM_HERE, | 63 BLINK_FROM_HERE, |
64 crossThreadBind(&SharedGpuContext::createContextProviderOnMainThread, | 64 crossThreadBind(&SharedGpuContext::createContextProviderOnMainThread, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 bool SharedGpuContext::isValidWithoutRestoring() { | 122 bool SharedGpuContext::isValidWithoutRestoring() { |
123 SharedGpuContext* thisPtr = getInstanceForCurrentThread(); | 123 SharedGpuContext* thisPtr = getInstanceForCurrentThread(); |
124 if (!thisPtr->m_contextProvider) | 124 if (!thisPtr->m_contextProvider) |
125 return false; | 125 return false; |
126 return thisPtr->m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() == | 126 return thisPtr->m_contextProvider->contextGL()->GetGraphicsResetStatusKHR() == |
127 GL_NO_ERROR; | 127 GL_NO_ERROR; |
128 } | 128 } |
129 | 129 |
130 } // blink | 130 } // blink |
OLD | NEW |