e9312ad22f8af1bee9c9e876e5d920bd03678b42
[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     // If the compositor was initialized with its own thread then we would need
56     // to leak the context provider when we shutdown to avoid destroying the
57     // contexts on the wrong thread.
58     DCHECK(!ui::Compositor::WasInitializedWithThread());
59     offscreen_compositor_contexts_ =
60         webkit::gpu::ContextProviderInProcess::CreateOffscreen();
61   }
62   return offscreen_compositor_contexts_;
63 }
64
65 scoped_refptr<cc::ContextProvider>
66 DemoContextFactory::SharedMainThreadContextProvider() {
67   if (!shared_main_thread_contexts_ ||
68       shared_main_thread_contexts_->DestroyedOnMainThread()) {
69     shared_main_thread_contexts_ =
70         webkit::gpu::ContextProviderInProcess::CreateOffscreen();
71     if (shared_main_thread_contexts_ &&
72         !shared_main_thread_contexts_->BindToCurrentThread())
73       shared_main_thread_contexts_ = NULL;
74   }
75   return shared_main_thread_contexts_;
76 }
77
78 void DemoContextFactory::RemoveCompositor(ui::Compositor* compositor) {
79 }
80
81 bool DemoContextFactory::DoesCreateTestContexts() { return false; }
82
83 }  // namespace examples
84 }  // namespace mojo
85