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/public/c/gles2/gles2.h"
7 #include "base/lazy_instance.h"
8 #include "base/threading/thread_local.h"
9 #include "gpu/GLES2/gl2extchromium.h"
10 #include "gpu/command_buffer/client/gles2_interface.h"
11 #include "mojo/gles2/gles2_context.h"
13 using gles2::GLES2Context
;
17 base::LazyInstance
<base::ThreadLocalPointer
<gpu::gles2::GLES2Interface
> >::Leaky
20 void RunSignalSyncCallback(MojoGLES2SignalSyncPointCallback callback
,
28 MojoGLES2Context
MojoGLES2CreateContext(MojoHandle handle
,
29 MojoGLES2ContextLost lost_callback
,
31 const MojoAsyncWaiter
* async_waiter
) {
32 mojo::MessagePipeHandle
mph(handle
);
33 mojo::ScopedMessagePipeHandle
scoped_handle(mph
);
34 scoped_ptr
<GLES2Context
> client(new GLES2Context(
35 async_waiter
, scoped_handle
.Pass(), lost_callback
, closure
));
36 if (!client
->Initialize())
38 return client
.release();
41 void MojoGLES2DestroyContext(MojoGLES2Context context
) {
42 delete static_cast<GLES2Context
*>(context
);
45 void MojoGLES2MakeCurrent(MojoGLES2Context context
) {
46 gpu::gles2::GLES2Interface
* interface
= NULL
;
48 GLES2Context
* client
= static_cast<GLES2Context
*>(context
);
49 interface
= client
->interface();
52 g_gpu_interface
.Get().Set(interface
);
55 void MojoGLES2SwapBuffers() {
56 DCHECK(g_gpu_interface
.Get().Get());
57 g_gpu_interface
.Get().Get()->SwapBuffers();
60 void MojoGLES2SignalSyncPoint(
61 MojoGLES2Context context
,
63 MojoGLES2SignalSyncPointCallback callback
,
66 static_cast<GLES2Context
*>(context
)->context_support()->SignalSyncPoint(
67 sync_point
, base::Bind(&RunSignalSyncCallback
, callback
, closure
));
70 void* MojoGLES2GetGLES2Interface(MojoGLES2Context context
) {
71 return static_cast<GLES2Context
*>(context
)->interface();
74 void* MojoGLES2GetContextSupport(MojoGLES2Context context
) {
75 return static_cast<GLES2Context
*>(context
)->context_support();
78 #define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \
79 ReturnType GL_APIENTRY gl##Function PARAMETERS { \
80 DCHECK(g_gpu_interface.Get().Get()); \
81 return g_gpu_interface.Get().Get()->Function ARGUMENTS; \
83 #include "mojo/public/c/gles2/gles2_call_visitor_autogen.h"
84 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_copy_texture_autogen.h"
85 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_image_autogen.h"
86 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_miscellaneous_autogen.h"
87 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_pixel_transfer_buffer_object_autogen.h"
88 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_sub_image_autogen.h"
89 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_sync_point_autogen.h"
90 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_texture_mailbox_autogen.h"
91 #include "mojo/public/c/gles2/gles2_call_visitor_occlusion_query_ext_autogen.h"