OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "android_webview/browser/deferred_gpu_command_service.h" | 5 #include "android_webview/browser/deferred_gpu_command_service.h" |
6 | 6 |
7 #include "android_webview/browser/gl_view_renderer_manager.h" | 7 #include "android_webview/browser/gl_view_renderer_manager.h" |
8 #include "android_webview/browser/shared_renderer_state.h" | 8 #include "android_webview/browser/shared_renderer_state.h" |
9 #include "base/bind.h" | |
9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
12 #include "content/public/browser/android/synchronous_compositor.h" | 13 #include "content/public/browser/android/synchronous_compositor.h" |
14 #include "gpu/blink/webgraphicscontext3d_impl.h" | |
15 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" | |
16 #include "gpu/command_buffer/client/gl_in_process_context.h" | |
17 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | |
13 #include "gpu/command_buffer/service/shader_translator_cache.h" | 18 #include "gpu/command_buffer/service/shader_translator_cache.h" |
19 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | |
20 #include "webkit/common/gpu/context_provider_in_process.h" | |
14 | 21 |
15 namespace android_webview { | 22 namespace android_webview { |
16 | 23 |
17 namespace { | 24 namespace { |
25 | |
18 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > | 26 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > |
19 g_service = LAZY_INSTANCE_INITIALIZER; | 27 g_service = LAZY_INSTANCE_INITIALIZER; |
28 | |
29 content::SynchronousCompositor::ContextHolder GetContextHolder( | |
30 bool need_share_group_with_parent, | |
tfarina
2015/02/24 17:02:34
What I do with this?
boliu
2015/02/24 21:52:57
If true, pass g_service as the first parameter to
tfarina
2015/02/24 22:10:12
Done.
| |
31 const blink::WebGraphicsContext3D::Attributes& attributes, | |
32 bool is_offscreen, | |
33 const gpu::GLInProcessContextSharedMemoryLimits& mem_limits) { | |
34 content::SynchronousCompositor::ContextHolder holder; | |
35 | |
36 gpu::gles2::ContextCreationAttribHelper in_process_attribs; | |
37 gpu_blink::WebGraphicsContext3DImpl::ConvertAttributes(attributes, | |
38 &in_process_attribs); | |
39 in_process_attribs.lose_context_when_out_of_memory = true; | |
40 | |
41 scoped_ptr<gpu::GLInProcessContext> context(gpu::GLInProcessContext::Create( | |
42 NULL /* service */, | |
43 NULL /* surface */, | |
44 is_offscreen, | |
45 gfx::kNullAcceleratedWidget, | |
46 gfx::Size(1, 1), | |
47 NULL /* share_context */, | |
48 attributes.shareResources, | |
49 in_process_attribs, | |
50 gfx::PreferDiscreteGpu, | |
51 mem_limits, | |
52 nullptr, | |
53 nullptr)); | |
54 | |
55 holder.context_provider = webkit::gpu::ContextProviderInProcess::Create( | |
56 gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext( | |
57 context.Pass(), attributes), std::string()); | |
58 | |
59 holder.context = context.get(); | |
boliu
2015/02/24 21:52:57
You already called context.Pass() 2 lines above, s
tfarina
2015/02/24 22:10:12
Done.
| |
60 return holder; | |
61 } | |
62 | |
20 } // namespace | 63 } // namespace |
21 | 64 |
22 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl; | 65 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl; |
23 | 66 |
24 // static | 67 // static |
25 bool ScopedAllowGL::IsAllowed() { | 68 bool ScopedAllowGL::IsAllowed() { |
26 return allow_gl.Get().Get(); | 69 return allow_gl.Get().Get(); |
27 } | 70 } |
28 | 71 |
29 ScopedAllowGL::ScopedAllowGL() { | 72 ScopedAllowGL::ScopedAllowGL() { |
(...skipping 13 matching lines...) Expand all Loading... | |
43 if (service->IdleQueueSize()) { | 86 if (service->IdleQueueSize()) { |
44 service->RequestProcessGL(); | 87 service->RequestProcessGL(); |
45 } | 88 } |
46 } | 89 } |
47 } | 90 } |
48 | 91 |
49 // static | 92 // static |
50 void DeferredGpuCommandService::SetInstance() { | 93 void DeferredGpuCommandService::SetInstance() { |
51 if (!g_service.Get().get()) { | 94 if (!g_service.Get().get()) { |
52 g_service.Get() = new DeferredGpuCommandService; | 95 g_service.Get() = new DeferredGpuCommandService; |
53 content::SynchronousCompositor::SetGpuService(g_service.Get()); | 96 content::SynchronousCompositor::SetCreateContextCallback( |
97 base::Bind(&GetContextHolder)); | |
54 } | 98 } |
55 } | 99 } |
56 | 100 |
57 // static | 101 // static |
58 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { | 102 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { |
59 DCHECK(g_service.Get().get()); | 103 DCHECK(g_service.Get().get()); |
60 return g_service.Get().get(); | 104 return g_service.Get().get(); |
61 } | 105 } |
62 | 106 |
63 DeferredGpuCommandService::DeferredGpuCommandService() {} | 107 DeferredGpuCommandService::DeferredGpuCommandService() {} |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 | 220 |
177 void DeferredGpuCommandService::AddRef() const { | 221 void DeferredGpuCommandService::AddRef() const { |
178 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); | 222 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); |
179 } | 223 } |
180 | 224 |
181 void DeferredGpuCommandService::Release() const { | 225 void DeferredGpuCommandService::Release() const { |
182 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); | 226 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); |
183 } | 227 } |
184 | 228 |
185 } // namespace android_webview | 229 } // namespace android_webview |
OLD | NEW |