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
3 // found in the LICENSE file.
5 #include "ui/compositor/test/in_process_context_factory.h"
7 #include "base/command_line.h"
8 #include "base/threading/thread.h"
9 #include "cc/output/output_surface.h"
10 #include "cc/test/test_shared_bitmap_manager.h"
11 #include "ui/compositor/compositor_switches.h"
12 #include "ui/compositor/reflector.h"
13 #include "ui/gl/gl_implementation.h"
14 #include "ui/gl/gl_surface.h"
15 #include "webkit/common/gpu/context_provider_in_process.h"
16 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h"
17 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
21 InProcessContextFactory::InProcessContextFactory()
22 : shared_bitmap_manager_(new cc::TestSharedBitmapManager()) {
23 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone
);
24 #if defined(OS_CHROMEOS)
25 bool use_thread
= !CommandLine::ForCurrentProcess()->HasSwitch(
26 switches::kUIDisableThreadedCompositing
);
28 bool use_thread
= false;
31 compositor_thread_
.reset(new base::Thread("Browser Compositor"));
32 compositor_thread_
->Start();
36 InProcessContextFactory::~InProcessContextFactory() {}
38 scoped_ptr
<cc::OutputSurface
> InProcessContextFactory::CreateOutputSurface(
39 Compositor
* compositor
,
40 bool software_fallback
) {
41 DCHECK(!software_fallback
);
42 blink::WebGraphicsContext3D::Attributes attrs
;
44 attrs
.stencil
= false;
45 attrs
.antialias
= false;
46 attrs
.shareResources
= true;
47 bool lose_context_when_out_of_memory
= true;
49 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl
;
50 scoped_ptr
<WebGraphicsContext3DInProcessCommandBufferImpl
> context3d(
51 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
52 attrs
, lose_context_when_out_of_memory
, compositor
->widget()));
55 using webkit::gpu::ContextProviderInProcess
;
56 scoped_refptr
<ContextProviderInProcess
> context_provider
=
57 ContextProviderInProcess::Create(context3d
.Pass(), "UICompositor");
59 return make_scoped_ptr(new cc::OutputSurface(context_provider
));
62 scoped_refptr
<Reflector
> InProcessContextFactory::CreateReflector(
63 Compositor
* mirroed_compositor
,
64 Layer
* mirroring_layer
) {
65 return new Reflector();
68 void InProcessContextFactory::RemoveReflector(
69 scoped_refptr
<Reflector
> reflector
) {}
71 scoped_refptr
<cc::ContextProvider
>
72 InProcessContextFactory::SharedMainThreadContextProvider() {
73 if (shared_main_thread_contexts_
&&
74 !shared_main_thread_contexts_
->DestroyedOnMainThread())
75 return shared_main_thread_contexts_
;
77 bool lose_context_when_out_of_memory
= false;
78 shared_main_thread_contexts_
=
79 webkit::gpu::ContextProviderInProcess::CreateOffscreen(
80 lose_context_when_out_of_memory
);
81 if (shared_main_thread_contexts_
&&
82 !shared_main_thread_contexts_
->BindToCurrentThread())
83 shared_main_thread_contexts_
= NULL
;
85 return shared_main_thread_contexts_
;
88 void InProcessContextFactory::RemoveCompositor(Compositor
* compositor
) {}
90 bool InProcessContextFactory::DoesCreateTestContexts() { return false; }
92 cc::SharedBitmapManager
* InProcessContextFactory::GetSharedBitmapManager() {
93 return shared_bitmap_manager_
.get();
96 base::MessageLoopProxy
* InProcessContextFactory::GetCompositorMessageLoop() {
97 if (!compositor_thread_
)
99 return compositor_thread_
->message_loop_proxy();