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/PlatformExport.h" |
5 #include "wtf/ThreadSpecific.h" | 6 #include "wtf/ThreadSpecific.h" |
6 | 7 |
7 #include <memory> | 8 #include <memory> |
8 | 9 |
9 namespace gpu { namespace gles2 { class GLES2Interface; } } | 10 namespace gpu { namespace gles2 { class GLES2Interface; } } |
10 class GrContext; | 11 class GrContext; |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 class WaitableEvent; | 15 class WaitableEvent; |
15 class WebGraphicsContext3DProvider; | 16 class WebGraphicsContext3DProvider; |
16 | 17 |
17 // SharedGpuContext provides access to a thread-specific GPU context | 18 // SharedGpuContext provides access to a thread-specific GPU context |
18 // that is shared by many callsites throughout the thread. | 19 // that is shared by many callsites throughout the thread. |
19 // When on the main thread, provides access to the same context as | 20 // When on the main thread, provides access to the same context as |
20 // Platform::createSharedOffscreenGraphicsContext3DProvider | 21 // Platform::createSharedOffscreenGraphicsContext3DProvider |
21 class SharedGpuContext { | 22 class PLATFORM_EXPORT SharedGpuContext { |
22 public: | 23 public: |
23 // The contextId is incremented each time a new underlying context | 24 // The contextId is incremented each time a new underlying context |
24 // is created. For example, when the context is lost, then restored. | 25 // is created. For example, when the context is lost, then restored. |
25 // User code can rely on this Id to determine whether long-lived | 26 // User code can rely on this Id to determine whether long-lived |
26 // gpu resources are still alive in the current context. | 27 // gpu resources are still alive in the current context. |
27 static unsigned contextId(); | 28 static unsigned contextId(); |
28 static gpu::gles2::GLES2Interface* gl(); | 29 static gpu::gles2::GLES2Interface* gl(); // May re-create context if context
was lost |
29 static GrContext* gr(); | 30 static GrContext* gr(); // May re-create context if context was lost |
30 static bool isValid(); | 31 static bool isValid(); // May re-create context if context was lost |
31 static bool restore(); | 32 static bool isValidWithoutRestoring(); |
| 33 typedef std::function<std::unique_ptr<WebGraphicsContext3DProvider>()> Conte
xtProviderFactory; |
| 34 static void setContextProviderFactoryForTesting(ContextProviderFactory); |
32 | 35 |
33 enum { | 36 enum { |
34 kNoSharedContext = 0, | 37 kNoSharedContext = 0, |
35 }; | 38 }; |
36 | 39 |
37 private: | 40 private: |
38 static SharedGpuContext* getInstanceForCurrentThread(); | 41 static SharedGpuContext* getInstanceForCurrentThread(); |
39 | 42 |
40 SharedGpuContext(); | 43 SharedGpuContext(); |
41 void createContextProviderOnMainThread(WaitableEvent*); | 44 void createContextProviderOnMainThread(WaitableEvent*); |
42 void createContextProvider(); | 45 void createContextProviderIfNeeded(); |
43 | 46 |
| 47 ContextProviderFactory m_contextProviderFactory = nullptr; |
44 std::unique_ptr<WebGraphicsContext3DProvider> m_contextProvider; | 48 std::unique_ptr<WebGraphicsContext3DProvider> m_contextProvider; |
45 unsigned m_contextId; | 49 unsigned m_contextId; |
46 friend class WTF::ThreadSpecific<SharedGpuContext>; | 50 friend class WTF::ThreadSpecific<SharedGpuContext>; |
47 }; | 51 }; |
48 | 52 |
49 } // blink | 53 } // blink |
OLD | NEW |