in_process_context_factory.cc revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
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 "cc/output/output_surface.h"
8#include "ui/compositor/reflector.h"
9#include "ui/gl/gl_implementation.h"
10#include "ui/gl/gl_surface.h"
11#include "webkit/common/gpu/context_provider_in_process.h"
12#include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h"
13#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
14
15namespace ui {
16
17InProcessContextFactory::InProcessContextFactory() {
18  DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone);
19}
20
21InProcessContextFactory::~InProcessContextFactory() {}
22
23scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface(
24    Compositor* compositor,
25    bool software_fallback) {
26  DCHECK(!software_fallback);
27  blink::WebGraphicsContext3D::Attributes attrs;
28  attrs.depth = false;
29  attrs.stencil = false;
30  attrs.antialias = false;
31  attrs.shareResources = true;
32  bool lose_context_when_out_of_memory = true;
33
34  using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
35  scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d(
36      WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
37          attrs, lose_context_when_out_of_memory, compositor->widget()));
38  CHECK(context3d);
39
40  using webkit::gpu::ContextProviderInProcess;
41  scoped_refptr<ContextProviderInProcess> context_provider =
42      ContextProviderInProcess::Create(context3d.Pass(), "UICompositor");
43
44  return make_scoped_ptr(new cc::OutputSurface(context_provider));
45}
46
47scoped_refptr<Reflector> InProcessContextFactory::CreateReflector(
48    Compositor* mirroed_compositor,
49    Layer* mirroring_layer) {
50  return new Reflector();
51}
52
53void InProcessContextFactory::RemoveReflector(
54    scoped_refptr<Reflector> reflector) {}
55
56scoped_refptr<cc::ContextProvider>
57InProcessContextFactory::OffscreenCompositorContextProvider() {
58  if (!offscreen_compositor_contexts_.get() ||
59      !offscreen_compositor_contexts_->DestroyedOnMainThread()) {
60    bool lose_context_when_out_of_memory = true;
61    offscreen_compositor_contexts_ =
62        webkit::gpu::ContextProviderInProcess::CreateOffscreen(
63            lose_context_when_out_of_memory);
64  }
65  return offscreen_compositor_contexts_;
66}
67
68scoped_refptr<cc::ContextProvider>
69InProcessContextFactory::SharedMainThreadContextProvider() {
70  if (shared_main_thread_contexts_ &&
71      !shared_main_thread_contexts_->DestroyedOnMainThread())
72    return shared_main_thread_contexts_;
73
74  if (ui::Compositor::WasInitializedWithThread()) {
75    bool lose_context_when_out_of_memory = false;
76    shared_main_thread_contexts_ =
77        webkit::gpu::ContextProviderInProcess::CreateOffscreen(
78            lose_context_when_out_of_memory);
79  } else {
80    shared_main_thread_contexts_ =
81        static_cast<webkit::gpu::ContextProviderInProcess*>(
82            OffscreenCompositorContextProvider().get());
83  }
84  if (shared_main_thread_contexts_ &&
85      !shared_main_thread_contexts_->BindToCurrentThread())
86    shared_main_thread_contexts_ = NULL;
87
88  return shared_main_thread_contexts_;
89}
90
91void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {}
92
93bool InProcessContextFactory::DoesCreateTestContexts() { return false; }
94
95}  // namespace ui
96