Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / mojo / examples / aura_demo / demo_context_factory.cc
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 "mojo/examples/aura_demo/demo_context_factory.h"
6
7 #include "cc/output/output_surface.h"
8 #include "mojo/examples/aura_demo/window_tree_host_mojo.h"
9 #include "mojo/examples/compositor_app/mojo_context_provider.h"
10 #include "ui/compositor/reflector.h"
11 #include "ui/gl/gl_implementation.h"
12 #include "ui/gl/gl_surface.h"
13 #include "webkit/common/gpu/context_provider_in_process.h"
14 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h"
15 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
16
17 namespace mojo {
18 namespace examples {
19
20 DemoContextFactory::DemoContextFactory(WindowTreeHostMojo* rwhm) : rwhm_(rwhm) {
21 }
22
23 DemoContextFactory::~DemoContextFactory() {
24 }
25
26 bool DemoContextFactory::Initialize() {
27   if (!gfx::GLSurface::InitializeOneOff() ||
28       gfx::GetGLImplementation() == gfx::kGLImplementationNone) {
29     LOG(ERROR) << "Could not load the GL bindings";
30     return false;
31   }
32   return true;
33 }
34
35 scoped_ptr<cc::OutputSurface> DemoContextFactory::CreateOutputSurface(
36     ui::Compositor* compositor, bool software_fallback) {
37   return make_scoped_ptr(new cc::OutputSurface(
38       new MojoContextProvider(rwhm_->TakeGLES2PipeHandle())));
39 }
40
41 scoped_refptr<ui::Reflector> DemoContextFactory::CreateReflector(
42     ui::Compositor* mirroed_compositor,
43     ui::Layer* mirroring_layer) {
44   return NULL;
45 }
46
47 void DemoContextFactory::RemoveReflector(
48     scoped_refptr<ui::Reflector> reflector) {
49 }
50
51 scoped_refptr<cc::ContextProvider>
52 DemoContextFactory::OffscreenCompositorContextProvider() {
53   if (!offscreen_compositor_contexts_.get() ||
54       !offscreen_compositor_contexts_->DestroyedOnMainThread()) {
55     offscreen_compositor_contexts_ =
56         webkit::gpu::ContextProviderInProcess::CreateOffscreen();
57   }
58   return offscreen_compositor_contexts_;
59 }
60
61 scoped_refptr<cc::ContextProvider>
62 DemoContextFactory::SharedMainThreadContextProvider() {
63   if (shared_main_thread_contexts_ &&
64       !shared_main_thread_contexts_->DestroyedOnMainThread())
65     return shared_main_thread_contexts_;
66
67   if (ui::Compositor::WasInitializedWithThread()) {
68     shared_main_thread_contexts_ =
69         webkit::gpu::ContextProviderInProcess::CreateOffscreen();
70   } else {
71     shared_main_thread_contexts_ =
72         static_cast<webkit::gpu::ContextProviderInProcess*>(
73             OffscreenCompositorContextProvider().get());
74   }
75   if (shared_main_thread_contexts_ &&
76       !shared_main_thread_contexts_->BindToCurrentThread())
77     shared_main_thread_contexts_ = NULL;
78
79   return shared_main_thread_contexts_;
80 }
81
82 void DemoContextFactory::RemoveCompositor(ui::Compositor* compositor) {
83 }
84
85 bool DemoContextFactory::DoesCreateTestContexts() { return false; }
86
87 }  // namespace examples
88 }  // namespace mojo
89