• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/gles2/gles2_support_impl.h"
6 
7 #include "base/lazy_instance.h"
8 #include "gpu/command_buffer/client/gles2_interface.h"
9 #include "mojo/gles2/gles2_context.h"
10 #include "mojo/public/gles2/gles2_interface.h"
11 #include "mojo/public/gles2/gles2_private.h"
12 
13 namespace mojo {
14 namespace gles2 {
15 
16 namespace {
17 
18 class GLES2ImplForCommandBuffer : public GLES2Interface {
19  public:
GLES2ImplForCommandBuffer()20   GLES2ImplForCommandBuffer() : gpu_interface_(NULL) {}
21 
set_gpu_interface(gpu::gles2::GLES2Interface * gpu_interface)22   void set_gpu_interface(gpu::gles2::GLES2Interface* gpu_interface) {
23     gpu_interface_ = gpu_interface;
24   }
gpu_interface() const25   gpu::gles2::GLES2Interface* gpu_interface() const { return gpu_interface_; }
26 
27 #define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \
28   virtual ReturnType Function PARAMETERS OVERRIDE {                \
29     return gpu_interface_->Function ARGUMENTS;                     \
30   }
31 #include "mojo/public/c/gles2/gles2_call_visitor_autogen.h"
32 #undef VISIT_GL_CALL
33 
34  private:
35   gpu::gles2::GLES2Interface* gpu_interface_;
36   DISALLOW_COPY_AND_ASSIGN(GLES2ImplForCommandBuffer);
37 };
38 
39 base::LazyInstance<GLES2ImplForCommandBuffer> g_gles2_interface =
40     LAZY_INSTANCE_INITIALIZER;
41 
42 }  // anonymous namespace
43 
GLES2SupportImpl()44 GLES2SupportImpl::GLES2SupportImpl() : async_waiter_(NULL) {}
~GLES2SupportImpl()45 GLES2SupportImpl::~GLES2SupportImpl() {}
46 
47 // static
Init()48 void GLES2SupportImpl::Init() { GLES2Support::Init(new GLES2SupportImpl()); }
49 
Initialize(const MojoAsyncWaiter * async_waiter)50 void GLES2SupportImpl::Initialize(const MojoAsyncWaiter* async_waiter) {
51   DCHECK(!async_waiter_);
52   DCHECK(async_waiter);
53   async_waiter_ = async_waiter;
54 }
55 
Terminate()56 void GLES2SupportImpl::Terminate() {
57   DCHECK(async_waiter_);
58   async_waiter_ = NULL;
59 }
60 
CreateContext(MessagePipeHandle handle,MojoGLES2ContextLost lost_callback,MojoGLES2DrawAnimationFrame animation_callback,void * closure)61 MojoGLES2Context GLES2SupportImpl::CreateContext(
62     MessagePipeHandle handle,
63     MojoGLES2ContextLost lost_callback,
64     MojoGLES2DrawAnimationFrame animation_callback,
65     void* closure) {
66   ScopedMessagePipeHandle scoped_handle(handle);
67   scoped_ptr<GLES2Context> client(new GLES2Context(async_waiter_,
68                                                    scoped_handle.Pass(),
69                                                    lost_callback,
70                                                    animation_callback,
71                                                    closure));
72   if (!client->Initialize())
73     client.reset();
74   return client.release();
75 }
76 
DestroyContext(MojoGLES2Context context)77 void GLES2SupportImpl::DestroyContext(MojoGLES2Context context) {
78   delete static_cast<GLES2Context*>(context);
79 }
80 
MakeCurrent(MojoGLES2Context context)81 void GLES2SupportImpl::MakeCurrent(MojoGLES2Context context) {
82   gpu::gles2::GLES2Interface* interface = NULL;
83   if (context) {
84     GLES2Context* client = static_cast<GLES2Context*>(context);
85     interface = client->interface();
86     DCHECK(interface);
87   }
88   g_gles2_interface.Get().set_gpu_interface(interface);
89 }
90 
SwapBuffers()91 void GLES2SupportImpl::SwapBuffers() {
92   g_gles2_interface.Get().gpu_interface()->SwapBuffers();
93 }
94 
RequestAnimationFrames(MojoGLES2Context context)95 void GLES2SupportImpl::RequestAnimationFrames(MojoGLES2Context context) {
96   static_cast<GLES2Context*>(context)->RequestAnimationFrames();
97 }
98 
CancelAnimationFrames(MojoGLES2Context context)99 void GLES2SupportImpl::CancelAnimationFrames(MojoGLES2Context context) {
100   static_cast<GLES2Context*>(context)->CancelAnimationFrames();
101 }
102 
GetGLES2Interface(MojoGLES2Context context)103 void* GLES2SupportImpl::GetGLES2Interface(MojoGLES2Context context) {
104   return static_cast<GLES2Context*>(context)->interface();
105 }
106 
GetContextSupport(MojoGLES2Context context)107 void* GLES2SupportImpl::GetContextSupport(MojoGLES2Context context) {
108   return static_cast<GLES2Context*>(context)->context_support();
109 }
110 
GetGLES2InterfaceForCurrentContext()111 GLES2Interface* GLES2SupportImpl::GetGLES2InterfaceForCurrentContext() {
112   return &g_gles2_interface.Get();
113 }
114 
115 }  // namespace gles2
116 }  // namespace mojo
117