Upstream version 7.35.144.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     // 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     bool lose_context_when_out_of_memory = true;
60     offscreen_compositor_contexts_ =
61         webkit::gpu::ContextProviderInProcess::CreateOffscreen(
62             lose_context_when_out_of_memory);
63   }
64   return offscreen_compositor_contexts_;
65 }
66
67 scoped_refptr<cc::ContextProvider>
68 DemoContextFactory::SharedMainThreadContextProvider() {
69   if (!shared_main_thread_contexts_ ||
70       shared_main_thread_contexts_->DestroyedOnMainThread()) {
71     bool lose_context_when_out_of_memory = false;
72     shared_main_thread_contexts_ =
73         webkit::gpu::ContextProviderInProcess::CreateOffscreen(
74             lose_context_when_out_of_memory);
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