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 const int32_t kNone
= 0x3038; // EGL_NONE
19 base::LazyInstance
<base::ThreadLocalPointer
<gpu::gles2::GLES2Interface
> >::Leaky
22 void RunSignalSyncCallback(MojoGLES2SignalSyncPointCallback callback
,
30 MojoGLES2Context
MojoGLES2CreateContext(MojoHandle handle
,
31 const int32_t* attrib_list
,
32 MojoGLES2ContextLost lost_callback
,
34 const MojoAsyncWaiter
* async_waiter
) {
35 mojo::MessagePipeHandle
mph(handle
);
36 mojo::ScopedMessagePipeHandle
scoped_handle(mph
);
37 std::vector
<int32_t> attribs
;
39 for (int32_t const* p
= attrib_list
; *p
!= kNone
;) {
40 attribs
.push_back(*p
++);
41 attribs
.push_back(*p
++);
44 attribs
.push_back(kNone
);
45 scoped_ptr
<GLES2Context
> client(new GLES2Context(
46 attribs
, async_waiter
, scoped_handle
.Pass(), lost_callback
, closure
));
47 if (!client
->Initialize())
49 return client
.release();
52 void MojoGLES2DestroyContext(MojoGLES2Context context
) {
53 delete static_cast<GLES2Context
*>(context
);
56 void MojoGLES2MakeCurrent(MojoGLES2Context context
) {
57 gpu::gles2::GLES2Interface
* interface
= NULL
;
59 GLES2Context
* client
= static_cast<GLES2Context
*>(context
);
60 interface
= client
->interface();
63 g_gpu_interface
.Get().Set(interface
);
66 void MojoGLES2SwapBuffers() {
67 DCHECK(g_gpu_interface
.Get().Get());
68 g_gpu_interface
.Get().Get()->SwapBuffers();
71 void MojoGLES2SignalSyncPoint(
72 MojoGLES2Context context
,
74 MojoGLES2SignalSyncPointCallback callback
,
77 static_cast<GLES2Context
*>(context
)->context_support()->SignalSyncPoint(
78 sync_point
, base::Bind(&RunSignalSyncCallback
, callback
, closure
));
81 void* MojoGLES2GetGLES2Interface(MojoGLES2Context context
) {
82 return static_cast<GLES2Context
*>(context
)->interface();
85 void* MojoGLES2GetContextSupport(MojoGLES2Context context
) {
86 return static_cast<GLES2Context
*>(context
)->context_support();
89 #define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \
90 ReturnType GL_APIENTRY gl##Function PARAMETERS { \
91 DCHECK(g_gpu_interface.Get().Get()); \
92 return g_gpu_interface.Get().Get()->Function ARGUMENTS; \
94 #include "mojo/public/c/gles2/gles2_call_visitor_autogen.h"
95 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_copy_texture_autogen.h"
96 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_framebuffer_multisample_autogen.h"
97 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_image_autogen.h"
98 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_miscellaneous_autogen.h"
99 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_pixel_transfer_buffer_object_autogen.h"
100 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_sub_image_autogen.h"
101 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_sync_point_autogen.h"
102 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_texture_mailbox_autogen.h"
103 #include "mojo/public/c/gles2/gles2_call_visitor_occlusion_query_ext_autogen.h"