OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/test/in_process_context_provider.h" | 5 #include "ui/compositor/test/in_process_context_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "cc/output/managed_memory_policy.h" | 13 #include "cc/output/managed_memory_policy.h" |
14 #include "gpu/command_buffer/client/gl_in_process_context.h" | 14 #include "gpu/command_buffer/client/gl_in_process_context.h" |
15 #include "gpu/command_buffer/client/gles2_implementation.h" | 15 #include "gpu/command_buffer/client/gles2_implementation.h" |
16 #include "gpu/command_buffer/client/gles2_lib.h" | 16 #include "gpu/command_buffer/client/gles2_lib.h" |
17 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 17 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
18 #include "third_party/skia/include/gpu/GrContext.h" | 18 #include "third_party/skia/include/gpu/GrContext.h" |
19 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 19 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 | 22 |
23 namespace { | |
24 | |
25 // Singleton used to initialize and terminate the gles2 library. | |
26 class GLES2Initializer { | |
27 public: | |
28 GLES2Initializer() { gles2::Initialize(); } | |
29 | |
30 ~GLES2Initializer() { gles2::Terminate(); } | |
31 | |
32 private: | |
33 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); | |
34 }; | |
35 | |
36 base::LazyInstance<GLES2Initializer> g_gles2_initializer = | |
37 LAZY_INSTANCE_INITIALIZER; | |
38 | |
39 } // namespace | |
40 | |
41 // static | 23 // static |
42 scoped_refptr<InProcessContextProvider> InProcessContextProvider::Create( | 24 scoped_refptr<InProcessContextProvider> InProcessContextProvider::Create( |
43 const gpu::gles2::ContextCreationAttribHelper& attribs, | 25 const gpu::gles2::ContextCreationAttribHelper& attribs, |
44 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
45 gpu::ImageFactory* image_factory, | 27 gpu::ImageFactory* image_factory, |
46 gfx::AcceleratedWidget window, | 28 gfx::AcceleratedWidget window, |
47 const std::string& debug_name) { | 29 const std::string& debug_name) { |
48 return new InProcessContextProvider( | 30 return new InProcessContextProvider( |
49 attribs, gpu_memory_buffer_manager, image_factory, window, debug_name); | 31 attribs, gpu_memory_buffer_manager, image_factory, window, debug_name); |
50 } | 32 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 119 |
138 return context_->GetImplementation(); | 120 return context_->GetImplementation(); |
139 } | 121 } |
140 | 122 |
141 gpu::ContextSupport* InProcessContextProvider::ContextSupport() { | 123 gpu::ContextSupport* InProcessContextProvider::ContextSupport() { |
142 DCHECK(context_thread_checker_.CalledOnValidThread()); | 124 DCHECK(context_thread_checker_.CalledOnValidThread()); |
143 | 125 |
144 return context_->GetImplementation(); | 126 return context_->GetImplementation(); |
145 } | 127 } |
146 | 128 |
147 static void BindGrContextCallback(const GrGLInterface* interface) { | |
148 cc::ContextProvider* context_provider = | |
149 reinterpret_cast<InProcessContextProvider*>(interface->fCallbackData); | |
150 | |
151 gles2::SetGLContext(context_provider->ContextGL()); | |
152 } | |
153 | |
154 class GrContext* InProcessContextProvider::GrContext() { | 129 class GrContext* InProcessContextProvider::GrContext() { |
155 DCHECK(context_thread_checker_.CalledOnValidThread()); | 130 DCHECK(context_thread_checker_.CalledOnValidThread()); |
156 | 131 |
157 if (gr_context_) | 132 if (gr_context_) |
158 return gr_context_.get(); | 133 return gr_context_.get(); |
159 | 134 |
160 // The GrGLInterface factory will make GL calls using the C GLES2 interface. | |
161 // Make sure the gles2 library is initialized first on exactly one thread. | |
162 g_gles2_initializer.Get(); | |
163 gles2::SetGLContext(ContextGL()); | |
164 | |
165 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(new GrGLInterface); | 135 skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(new GrGLInterface); |
166 skia_bindings::InitCommandBufferSkiaGLBinding(interface.get()); | 136 skia_bindings::InitGLES2InterfaceBindings(interface.get(), ContextGL()); |
167 interface->fCallback = BindGrContextCallback; | |
168 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this); | |
169 | 137 |
170 gr_context_ = skia::AdoptRef(GrContext::Create( | 138 gr_context_ = skia::AdoptRef(GrContext::Create( |
171 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); | 139 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); |
172 | 140 |
173 return gr_context_.get(); | 141 return gr_context_.get(); |
174 } | 142 } |
175 | 143 |
176 void InProcessContextProvider::InvalidateGrContext(uint32_t state) { | 144 void InProcessContextProvider::InvalidateGrContext(uint32_t state) { |
177 DCHECK(context_thread_checker_.CalledOnValidThread()); | 145 DCHECK(context_thread_checker_.CalledOnValidThread()); |
178 | 146 |
(...skipping 25 matching lines...) Expand all Loading... |
204 | 172 |
205 void InProcessContextProvider::OnLostContext() { | 173 void InProcessContextProvider::OnLostContext() { |
206 DCHECK(context_thread_checker_.CalledOnValidThread()); | 174 DCHECK(context_thread_checker_.CalledOnValidThread()); |
207 if (!lost_context_callback_.is_null()) | 175 if (!lost_context_callback_.is_null()) |
208 base::ResetAndReturn(&lost_context_callback_).Run(); | 176 base::ResetAndReturn(&lost_context_callback_).Run(); |
209 if (gr_context_) | 177 if (gr_context_) |
210 gr_context_->abandonContext(); | 178 gr_context_->abandonContext(); |
211 } | 179 } |
212 | 180 |
213 } // namespace ui | 181 } // namespace ui |
OLD | NEW |