OLD | NEW |
(Empty) | |
| 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/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" |
| 17 |
| 18 namespace mojo { |
| 19 namespace examples { |
| 20 |
| 21 namespace { |
| 22 |
| 23 class MojoContextProvider : public cc::ContextProvider { |
| 24 public: |
| 25 explicit MojoContextProvider(GLES2ClientImpl* gles2_client_impl) |
| 26 : gles2_client_impl_(gles2_client_impl) {} |
| 27 |
| 28 // cc::ContextProvider implementation. |
| 29 virtual bool BindToCurrentThread() OVERRIDE { return true; } |
| 30 virtual blink::WebGraphicsContext3D* Context3d() OVERRIDE { return NULL; } |
| 31 virtual gpu::gles2::GLES2Interface* ContextGL() OVERRIDE { |
| 32 return gles2_client_impl_->Interface(); |
| 33 } |
| 34 virtual gpu::ContextSupport* ContextSupport() OVERRIDE { |
| 35 return gles2_client_impl_->Support(); |
| 36 } |
| 37 virtual class GrContext* GrContext() OVERRIDE { return NULL; } |
| 38 virtual void MakeGrContextCurrent() OVERRIDE {} |
| 39 virtual Capabilities ContextCapabilities() OVERRIDE { return capabilities_; } |
| 40 virtual bool IsContextLost() OVERRIDE { |
| 41 return !gles2_client_impl_->Interface(); |
| 42 } |
| 43 virtual void VerifyContexts() OVERRIDE {} |
| 44 virtual bool DestroyedOnMainThread() OVERRIDE { |
| 45 return !gles2_client_impl_->Interface(); |
| 46 } |
| 47 virtual void SetLostContextCallback( |
| 48 const LostContextCallback& lost_context_callback) OVERRIDE {} |
| 49 virtual void SetMemoryPolicyChangedCallback( |
| 50 const MemoryPolicyChangedCallback& memory_policy_changed_callback) |
| 51 OVERRIDE {} |
| 52 |
| 53 protected: |
| 54 friend class base::RefCountedThreadSafe<MojoContextProvider>; |
| 55 virtual ~MojoContextProvider() {} |
| 56 |
| 57 private: |
| 58 cc::ContextProvider::Capabilities capabilities_; |
| 59 GLES2ClientImpl* gles2_client_impl_; |
| 60 }; |
| 61 |
| 62 } // namespace |
| 63 |
| 64 DemoContextFactory::DemoContextFactory(RootWindowHostMojo* rwhm) : rwhm_(rwhm) { |
| 65 } |
| 66 |
| 67 DemoContextFactory::~DemoContextFactory() { |
| 68 } |
| 69 |
| 70 bool DemoContextFactory::Initialize() { |
| 71 if (!gfx::GLSurface::InitializeOneOff() || |
| 72 gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
| 73 LOG(ERROR) << "Could not load the GL bindings"; |
| 74 return false; |
| 75 } |
| 76 return true; |
| 77 } |
| 78 |
| 79 scoped_ptr<cc::OutputSurface> DemoContextFactory::CreateOutputSurface( |
| 80 ui::Compositor* compositor, bool software_fallback) { |
| 81 return make_scoped_ptr( |
| 82 new cc::OutputSurface(new MojoContextProvider(rwhm_->gles2_client()))); |
| 83 } |
| 84 |
| 85 scoped_refptr<ui::Reflector> DemoContextFactory::CreateReflector( |
| 86 ui::Compositor* mirroed_compositor, |
| 87 ui::Layer* mirroring_layer) { |
| 88 return NULL; |
| 89 } |
| 90 |
| 91 void DemoContextFactory::RemoveReflector( |
| 92 scoped_refptr<ui::Reflector> reflector) { |
| 93 } |
| 94 |
| 95 scoped_refptr<cc::ContextProvider> |
| 96 DemoContextFactory::OffscreenCompositorContextProvider() { |
| 97 if (!offscreen_compositor_contexts_.get() || |
| 98 !offscreen_compositor_contexts_->DestroyedOnMainThread()) { |
| 99 offscreen_compositor_contexts_ = |
| 100 webkit::gpu::ContextProviderInProcess::CreateOffscreen(); |
| 101 } |
| 102 return offscreen_compositor_contexts_; |
| 103 } |
| 104 |
| 105 scoped_refptr<cc::ContextProvider> |
| 106 DemoContextFactory::SharedMainThreadContextProvider() { |
| 107 if (shared_main_thread_contexts_ && |
| 108 !shared_main_thread_contexts_->DestroyedOnMainThread()) |
| 109 return shared_main_thread_contexts_; |
| 110 |
| 111 if (ui::Compositor::WasInitializedWithThread()) { |
| 112 shared_main_thread_contexts_ = |
| 113 webkit::gpu::ContextProviderInProcess::CreateOffscreen(); |
| 114 } else { |
| 115 shared_main_thread_contexts_ = |
| 116 static_cast<webkit::gpu::ContextProviderInProcess*>( |
| 117 OffscreenCompositorContextProvider().get()); |
| 118 } |
| 119 if (shared_main_thread_contexts_ && |
| 120 !shared_main_thread_contexts_->BindToCurrentThread()) |
| 121 shared_main_thread_contexts_ = NULL; |
| 122 |
| 123 return shared_main_thread_contexts_; |
| 124 } |
| 125 |
| 126 void DemoContextFactory::RemoveCompositor(ui::Compositor* compositor) { |
| 127 } |
| 128 |
| 129 bool DemoContextFactory::DoesCreateTestContexts() { return false; } |
| 130 |
| 131 } // namespace examples |
| 132 } // namespace mojo |
| 133 |
OLD | NEW |