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 running tests, ensure that main() is calling "
25 << "gfx::GLSurface::InitializeOneOffForTests()";
27 #if defined(OS_CHROMEOS)
28 bool use_thread
= !CommandLine::ForCurrentProcess()->HasSwitch(
29 switches::kUIDisableThreadedCompositing
);
31 bool use_thread
= false;
34 compositor_thread_
.reset(new base::Thread("Browser Compositor"));
35 compositor_thread_
->Start();
39 InProcessContextFactory::~InProcessContextFactory() {}
41 scoped_ptr
<cc::OutputSurface
> InProcessContextFactory::CreateOutputSurface(
42 Compositor
* compositor
,
43 bool software_fallback
) {
44 DCHECK(!software_fallback
);
45 blink::WebGraphicsContext3D::Attributes attrs
;
47 attrs
.stencil
= false;
48 attrs
.antialias
= false;
49 attrs
.shareResources
= true;
50 bool lose_context_when_out_of_memory
= true;
52 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl
;
53 scoped_ptr
<WebGraphicsContext3DInProcessCommandBufferImpl
> context3d(
54 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
55 attrs
, lose_context_when_out_of_memory
, compositor
->widget()));
58 using webkit::gpu::ContextProviderInProcess
;
59 scoped_refptr
<ContextProviderInProcess
> context_provider
=
60 ContextProviderInProcess::Create(context3d
.Pass(), "UICompositor");
62 return make_scoped_ptr(new cc::OutputSurface(context_provider
));
65 scoped_refptr
<Reflector
> InProcessContextFactory::CreateReflector(
66 Compositor
* mirroed_compositor
,
67 Layer
* mirroring_layer
) {
68 return new Reflector();
71 void InProcessContextFactory::RemoveReflector(
72 scoped_refptr
<Reflector
> reflector
) {}
74 scoped_refptr
<cc::ContextProvider
>
75 InProcessContextFactory::SharedMainThreadContextProvider() {
76 if (shared_main_thread_contexts_
.get() &&
77 !shared_main_thread_contexts_
->DestroyedOnMainThread())
78 return shared_main_thread_contexts_
;
80 bool lose_context_when_out_of_memory
= false;
81 shared_main_thread_contexts_
=
82 webkit::gpu::ContextProviderInProcess::CreateOffscreen(
83 lose_context_when_out_of_memory
);
84 if (shared_main_thread_contexts_
.get() &&
85 !shared_main_thread_contexts_
->BindToCurrentThread())
86 shared_main_thread_contexts_
= NULL
;
88 return shared_main_thread_contexts_
;
91 void InProcessContextFactory::RemoveCompositor(Compositor
* compositor
) {}
93 bool InProcessContextFactory::DoesCreateTestContexts() { return false; }
95 cc::SharedBitmapManager
* InProcessContextFactory::GetSharedBitmapManager() {
96 return shared_bitmap_manager_
.get();
99 base::MessageLoopProxy
* InProcessContextFactory::GetCompositorMessageLoop() {
100 if (!compositor_thread_
)
102 return compositor_thread_
->message_loop_proxy().get();