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.
5 #include "mojo/examples/aura_demo/demo_context_factory.h"
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"
20 DemoContextFactory::DemoContextFactory(WindowTreeHostMojo* rwhm) : rwhm_(rwhm) {
23 DemoContextFactory::~DemoContextFactory() {
26 bool DemoContextFactory::Initialize() {
27 if (!gfx::GLSurface::InitializeOneOff() ||
28 gfx::GetGLImplementation() == gfx::kGLImplementationNone) {
29 LOG(ERROR) << "Could not load the GL bindings";
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())));
41 scoped_refptr<ui::Reflector> DemoContextFactory::CreateReflector(
42 ui::Compositor* mirroed_compositor,
43 ui::Layer* mirroring_layer) {
47 void DemoContextFactory::RemoveReflector(
48 scoped_refptr<ui::Reflector> reflector) {
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();
58 return offscreen_compositor_contexts_;
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_;
67 if (ui::Compositor::WasInitializedWithThread()) {
68 shared_main_thread_contexts_ =
69 webkit::gpu::ContextProviderInProcess::CreateOffscreen();
71 shared_main_thread_contexts_ =
72 static_cast<webkit::gpu::ContextProviderInProcess*>(
73 OffscreenCompositorContextProvider().get());
75 if (shared_main_thread_contexts_ &&
76 !shared_main_thread_contexts_->BindToCurrentThread())
77 shared_main_thread_contexts_ = NULL;
79 return shared_main_thread_contexts_;
82 void DemoContextFactory::RemoveCompositor(ui::Compositor* compositor) {
85 bool DemoContextFactory::DoesCreateTestContexts() { return false; }
87 } // namespace examples