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 #if GR_GL_PER_GL_FUNC_CALLBACK | |
jamesr
2014/01/16 19:31:07
i've seen this #if guard in multiple places, but i
alokp
2014/01/16 22:00:47
Good point. It will be better to remove this guard
| |
86 TestInProcessContextProvider* context_provider = | |
87 reinterpret_cast<TestInProcessContextProvider*>(interface->fCallbackData); | |
88 | |
109 // Make sure the gles2 library is initialized first on exactly one thread. | 89 // Make sure the gles2 library is initialized first on exactly one thread. |
110 g_gles2_initializer.Get(); | 90 g_gles2_initializer.Get(); |
91 gles2::SetGLContext(context_provider->ContextGL()); | |
92 #endif // GR_GL_PER_GL_FUNC_CALLBACK | |
93 } | |
111 | 94 |
112 gles2::SetGLContext(context_->GetImplementation()); | 95 class GrContext* TestInProcessContextProvider::GrContext() { |
96 if (gr_context_) | |
97 return gr_context_.get(); | |
98 | |
99 skia::RefPtr<GrGLInterface> interface = | |
100 skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding()); | |
101 #if GR_GL_PER_GL_FUNC_CALLBACK | |
102 interface->fCallback = BindGrContextCallback; | |
103 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this); | |
104 #endif // GR_GL_PER_GL_FUNC_CALLBACK | |
105 | |
106 gr_context_ = skia::AdoptRef(GrContext::Create( | |
107 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); | |
108 | |
109 return gr_context_.get(); | |
113 } | 110 } |
114 | 111 |
115 ContextProvider::Capabilities | 112 ContextProvider::Capabilities |
116 TestInProcessContextProvider::ContextCapabilities() { | 113 TestInProcessContextProvider::ContextCapabilities() { |
117 return ContextProvider::Capabilities(); | 114 return ContextProvider::Capabilities(); |
118 } | 115 } |
119 | 116 |
120 bool TestInProcessContextProvider::IsContextLost() { return false; } | 117 bool TestInProcessContextProvider::IsContextLost() { return false; } |
121 | 118 |
122 void TestInProcessContextProvider::VerifyContexts() {} | 119 void TestInProcessContextProvider::VerifyContexts() {} |
123 | 120 |
124 bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; } | 121 bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; } |
125 | 122 |
126 void TestInProcessContextProvider::SetLostContextCallback( | 123 void TestInProcessContextProvider::SetLostContextCallback( |
127 const LostContextCallback& lost_context_callback) {} | 124 const LostContextCallback& lost_context_callback) {} |
128 | 125 |
129 void TestInProcessContextProvider::SetMemoryPolicyChangedCallback( | 126 void TestInProcessContextProvider::SetMemoryPolicyChangedCallback( |
130 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {} | 127 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {} |
131 | 128 |
132 } // namespace cc | 129 } // namespace cc |
OLD | NEW |