in_process_context_factory.cc revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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.
4
5#include "ui/compositor/test/in_process_context_factory.h"
6
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"
18
19namespace ui {
20
21InProcessContextFactory::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);
27#else
28  bool use_thread = false;
29#endif
30  if (use_thread) {
31    compositor_thread_.reset(new base::Thread("Browser Compositor"));
32    compositor_thread_->Start();
33  }
34}
35
36InProcessContextFactory::~InProcessContextFactory() {}
37
38scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface(
39    Compositor* compositor,
40    bool software_fallback) {
41  DCHECK(!software_fallback);
42  blink::WebGraphicsContext3D::Attributes attrs;
43  attrs.depth = false;
44  attrs.stencil = false;
45  attrs.antialias = false;
46  attrs.shareResources = true;
47  bool lose_context_when_out_of_memory = true;
48
49  using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
50  scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d(
51      WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
52          attrs, lose_context_when_out_of_memory, compositor->widget()));
53  CHECK(context3d);
54
55  using webkit::gpu::ContextProviderInProcess;
56  scoped_refptr<ContextProviderInProcess> context_provider =
57      ContextProviderInProcess::Create(context3d.Pass(), "UICompositor");
58
59  return make_scoped_ptr(new cc::OutputSurface(context_provider));
60}
61
62scoped_refptr<Reflector> InProcessContextFactory::CreateReflector(
63    Compositor* mirroed_compositor,
64    Layer* mirroring_layer) {
65  return new Reflector();
66}
67
68void InProcessContextFactory::RemoveReflector(
69    scoped_refptr<Reflector> reflector) {}
70
71scoped_refptr<cc::ContextProvider>
72InProcessContextFactory::SharedMainThreadContextProvider() {
73  if (shared_main_thread_contexts_ &&
74      !shared_main_thread_contexts_->DestroyedOnMainThread())
75    return shared_main_thread_contexts_;
76
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;
84
85  return shared_main_thread_contexts_;
86}
87
88void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {}
89
90bool InProcessContextFactory::DoesCreateTestContexts() { return false; }
91
92cc::SharedBitmapManager* InProcessContextFactory::GetSharedBitmapManager() {
93  return shared_bitmap_manager_.get();
94}
95
96base::MessageLoopProxy* InProcessContextFactory::GetCompositorMessageLoop() {
97  if (!compositor_thread_)
98    return NULL;
99  return compositor_thread_->message_loop_proxy();
100}
101
102}  // namespace ui
103