OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/test/test_in_process_context_provider.h" | 5 #include "cc/test/test_in_process_context_provider.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "gpu/GLES2/gl2extchromium.h" | 8 #include "gpu/GLES2/gl2extchromium.h" |
9 #include "gpu/command_buffer/client/gl_in_process_context.h" | 9 #include "gpu/command_buffer/client/gl_in_process_context.h" |
10 #include "gpu/command_buffer/client/gles2_implementation.h" | 10 #include "gpu/command_buffer/client/gles2_implementation.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 bool TestInProcessContextProvider::BindToCurrentThread() { return true; } | 56 bool TestInProcessContextProvider::BindToCurrentThread() { return true; } |
57 | 57 |
58 gpu::gles2::GLES2Interface* TestInProcessContextProvider::ContextGL() { | 58 gpu::gles2::GLES2Interface* TestInProcessContextProvider::ContextGL() { |
59 return context_->GetImplementation(); | 59 return context_->GetImplementation(); |
60 } | 60 } |
61 | 61 |
62 gpu::ContextSupport* TestInProcessContextProvider::ContextSupport() { | 62 gpu::ContextSupport* TestInProcessContextProvider::ContextSupport() { |
63 return context_->GetImplementation(); | 63 return context_->GetImplementation(); |
64 } | 64 } |
65 | 65 |
66 static void BindGrContextCallback(const GrGLInterface* interface) { | |
67 #if GR_GL_PER_GL_FUNC_CALLBACK | |
68 reinterpret_cast<TestInProcessContextProvider*>(interface->fCallbackData) | |
69 ->MakeGrContextCurrent(); | |
70 #endif // GR_GL_PER_GL_FUNC_CALLBACK | |
71 } | |
72 | |
73 class GrContext* TestInProcessContextProvider::GrContext() { | |
74 if (gr_context_) | |
75 return gr_context_.get(); | |
76 | |
77 skia::RefPtr<GrGLInterface> interface = | |
78 skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding()); | |
79 #if GR_GL_PER_GL_FUNC_CALLBACK | |
80 interface->fCallback = BindGrContextCallback; | |
81 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this); | |
82 #endif // GR_GL_PER_GL_FUNC_CALLBACK | |
83 | |
84 gr_context_ = skia::AdoptRef(GrContext::Create( | |
85 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); | |
86 | |
87 return gr_context_.get(); | |
88 } | |
89 | |
90 namespace { | 66 namespace { |
91 | 67 |
92 // Singleton used to initialize and terminate the gles2 library. | 68 // Singleton used to initialize and terminate the gles2 library. |
93 class GLES2Initializer { | 69 class GLES2Initializer { |
94 public: | 70 public: |
95 GLES2Initializer() { ::gles2::Initialize(); } | 71 GLES2Initializer() { ::gles2::Initialize(); } |
96 | 72 |
97 ~GLES2Initializer() { ::gles2::Terminate(); } | 73 ~GLES2Initializer() { ::gles2::Terminate(); } |
98 | 74 |
99 private: | 75 private: |
100 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); | 76 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); |
101 }; | 77 }; |
102 | 78 |
103 static base::LazyInstance<GLES2Initializer> g_gles2_initializer = | 79 static base::LazyInstance<GLES2Initializer> g_gles2_initializer = |
104 LAZY_INSTANCE_INITIALIZER; | 80 LAZY_INSTANCE_INITIALIZER; |
105 | 81 |
106 } // namespace | 82 } // namespace |
107 | 83 |
108 void TestInProcessContextProvider::MakeGrContextCurrent() { | 84 static void BindGrContextCallback(const GrGLInterface* interface) { |
| 85 TestInProcessContextProvider* context_provider = |
| 86 reinterpret_cast<TestInProcessContextProvider*>(interface->fCallbackData); |
| 87 |
109 // Make sure the gles2 library is initialized first on exactly one thread. | 88 // Make sure the gles2 library is initialized first on exactly one thread. |
110 g_gles2_initializer.Get(); | 89 g_gles2_initializer.Get(); |
| 90 gles2::SetGLContext(context_provider->ContextGL()); |
| 91 } |
111 | 92 |
112 gles2::SetGLContext(context_->GetImplementation()); | 93 class GrContext* TestInProcessContextProvider::GrContext() { |
| 94 if (gr_context_) |
| 95 return gr_context_.get(); |
| 96 |
| 97 skia::RefPtr<GrGLInterface> interface = |
| 98 skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding()); |
| 99 interface->fCallback = BindGrContextCallback; |
| 100 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this); |
| 101 |
| 102 gr_context_ = skia::AdoptRef(GrContext::Create( |
| 103 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); |
| 104 |
| 105 return gr_context_.get(); |
113 } | 106 } |
114 | 107 |
115 ContextProvider::Capabilities | 108 ContextProvider::Capabilities |
116 TestInProcessContextProvider::ContextCapabilities() { | 109 TestInProcessContextProvider::ContextCapabilities() { |
117 return ContextProvider::Capabilities(); | 110 return ContextProvider::Capabilities(); |
118 } | 111 } |
119 | 112 |
120 bool TestInProcessContextProvider::IsContextLost() { return false; } | 113 bool TestInProcessContextProvider::IsContextLost() { return false; } |
121 | 114 |
122 void TestInProcessContextProvider::VerifyContexts() {} | 115 void TestInProcessContextProvider::VerifyContexts() {} |
123 | 116 |
124 bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; } | 117 bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; } |
125 | 118 |
126 void TestInProcessContextProvider::SetLostContextCallback( | 119 void TestInProcessContextProvider::SetLostContextCallback( |
127 const LostContextCallback& lost_context_callback) {} | 120 const LostContextCallback& lost_context_callback) {} |
128 | 121 |
129 void TestInProcessContextProvider::SetMemoryPolicyChangedCallback( | 122 void TestInProcessContextProvider::SetMemoryPolicyChangedCallback( |
130 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {} | 123 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {} |
131 | 124 |
132 } // namespace cc | 125 } // namespace cc |
OLD | NEW |