Clang roll script: fix error when GYP_DEFINES isn't defined
[chromium-blink-merge.git] / mojo / examples / aura_demo / demo_context_factory.cc
blob732a872bb6bf95991528070070242678e348b426
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/context_provider.h"
8 #include "cc/output/output_surface.h"
9 #include "mojo/examples/aura_demo/root_window_host_mojo.h"
10 #include "mojo/examples/compositor_app/gles2_client_impl.h"
11 #include "ui/compositor/reflector.h"
12 #include "ui/gl/gl_implementation.h"
13 #include "ui/gl/gl_surface.h"
14 #include "webkit/common/gpu/context_provider_in_process.h"
15 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h"
16 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
18 namespace mojo {
19 namespace examples {
21 namespace {
23 class MojoContextProvider : public cc::ContextProvider {
24 public:
25 explicit MojoContextProvider(GLES2ClientImpl* gles2_client_impl)
26 : gles2_client_impl_(gles2_client_impl) {}
28 // cc::ContextProvider implementation.
29 virtual bool BindToCurrentThread() OVERRIDE { return true; }
30 virtual gpu::gles2::GLES2Interface* ContextGL() OVERRIDE {
31 return gles2_client_impl_->Interface();
33 virtual gpu::ContextSupport* ContextSupport() OVERRIDE {
34 return gles2_client_impl_->Support();
36 virtual class GrContext* GrContext() OVERRIDE { return NULL; }
37 virtual Capabilities ContextCapabilities() OVERRIDE { return capabilities_; }
38 virtual bool IsContextLost() OVERRIDE {
39 return !gles2_client_impl_->Interface();
41 virtual void VerifyContexts() OVERRIDE {}
42 virtual bool DestroyedOnMainThread() OVERRIDE {
43 return !gles2_client_impl_->Interface();
45 virtual void SetLostContextCallback(
46 const LostContextCallback& lost_context_callback) OVERRIDE {}
47 virtual void SetMemoryPolicyChangedCallback(
48 const MemoryPolicyChangedCallback& memory_policy_changed_callback)
49 OVERRIDE {}
51 protected:
52 friend class base::RefCountedThreadSafe<MojoContextProvider>;
53 virtual ~MojoContextProvider() {}
55 private:
56 cc::ContextProvider::Capabilities capabilities_;
57 GLES2ClientImpl* gles2_client_impl_;
60 } // namespace
62 DemoContextFactory::DemoContextFactory(WindowTreeHostMojo* rwhm) : rwhm_(rwhm) {
65 DemoContextFactory::~DemoContextFactory() {
68 bool DemoContextFactory::Initialize() {
69 if (!gfx::GLSurface::InitializeOneOff() ||
70 gfx::GetGLImplementation() == gfx::kGLImplementationNone) {
71 LOG(ERROR) << "Could not load the GL bindings";
72 return false;
74 return true;
77 scoped_ptr<cc::OutputSurface> DemoContextFactory::CreateOutputSurface(
78 ui::Compositor* compositor, bool software_fallback) {
79 return make_scoped_ptr(
80 new cc::OutputSurface(new MojoContextProvider(rwhm_->gles2_client())));
83 scoped_refptr<ui::Reflector> DemoContextFactory::CreateReflector(
84 ui::Compositor* mirroed_compositor,
85 ui::Layer* mirroring_layer) {
86 return NULL;
89 void DemoContextFactory::RemoveReflector(
90 scoped_refptr<ui::Reflector> reflector) {
93 scoped_refptr<cc::ContextProvider>
94 DemoContextFactory::OffscreenCompositorContextProvider() {
95 if (!offscreen_compositor_contexts_.get() ||
96 !offscreen_compositor_contexts_->DestroyedOnMainThread()) {
97 offscreen_compositor_contexts_ =
98 webkit::gpu::ContextProviderInProcess::CreateOffscreen();
100 return offscreen_compositor_contexts_;
103 scoped_refptr<cc::ContextProvider>
104 DemoContextFactory::SharedMainThreadContextProvider() {
105 if (shared_main_thread_contexts_ &&
106 !shared_main_thread_contexts_->DestroyedOnMainThread())
107 return shared_main_thread_contexts_;
109 if (ui::Compositor::WasInitializedWithThread()) {
110 shared_main_thread_contexts_ =
111 webkit::gpu::ContextProviderInProcess::CreateOffscreen();
112 } else {
113 shared_main_thread_contexts_ =
114 static_cast<webkit::gpu::ContextProviderInProcess*>(
115 OffscreenCompositorContextProvider().get());
117 if (shared_main_thread_contexts_ &&
118 !shared_main_thread_contexts_->BindToCurrentThread())
119 shared_main_thread_contexts_ = NULL;
121 return shared_main_thread_contexts_;
124 void DemoContextFactory::RemoveCompositor(ui::Compositor* compositor) {
127 bool DemoContextFactory::DoesCreateTestContexts() { return false; }
129 } // namespace examples
130 } // namespace mojo