OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/public/c/gles2/gles2.h" | 5 #include "mojo/public/c/gles2/gles2.h" |
6 | 6 |
| 7 #include "base/lazy_instance.h" |
| 8 #include "base/threading/thread_local.h" |
7 #include "gpu/command_buffer/client/gles2_interface.h" | 9 #include "gpu/command_buffer/client/gles2_interface.h" |
8 #include "mojo/gles2/gles2_context.h" | 10 #include "mojo/gles2/gles2_context.h" |
9 | 11 |
10 using mojo::gles2::GLES2Context; | 12 using mojo::gles2::GLES2Context; |
11 | 13 |
12 namespace { | 14 namespace { |
13 | 15 |
14 const MojoAsyncWaiter* g_async_waiter = NULL; | 16 base::LazyInstance<base::ThreadLocalPointer<gpu::gles2::GLES2Interface> >::Leaky |
15 gpu::gles2::GLES2Interface* g_gpu_interface = NULL; | 17 g_gpu_interface; |
16 | 18 |
17 } // namespace | 19 } // namespace |
18 | 20 |
19 extern "C" { | 21 extern "C" { |
20 | 22 MojoGLES2Context MojoGLES2CreateContext(MojoHandle handle, |
21 void MojoGLES2Initialize(const MojoAsyncWaiter* async_waiter) { | 23 MojoGLES2ContextLost lost_callback, |
22 DCHECK(!g_async_waiter); | 24 void* closure, |
23 DCHECK(async_waiter); | 25 const MojoAsyncWaiter* async_waiter) { |
24 g_async_waiter = async_waiter; | |
25 } | |
26 | |
27 void MojoGLES2Terminate() { | |
28 DCHECK(g_async_waiter); | |
29 g_async_waiter = NULL; | |
30 } | |
31 | |
32 MojoGLES2Context MojoGLES2CreateContext( | |
33 MojoHandle handle, | |
34 MojoGLES2ContextLost lost_callback, | |
35 void* closure) { | |
36 mojo::MessagePipeHandle mph(handle); | 26 mojo::MessagePipeHandle mph(handle); |
37 mojo::ScopedMessagePipeHandle scoped_handle(mph); | 27 mojo::ScopedMessagePipeHandle scoped_handle(mph); |
38 scoped_ptr<GLES2Context> client(new GLES2Context(g_async_waiter, | 28 scoped_ptr<GLES2Context> client(new GLES2Context( |
39 scoped_handle.Pass(), | 29 async_waiter, scoped_handle.Pass(), lost_callback, closure)); |
40 lost_callback, | |
41 closure)); | |
42 if (!client->Initialize()) | 30 if (!client->Initialize()) |
43 client.reset(); | 31 client.reset(); |
44 return client.release(); | 32 return client.release(); |
45 } | 33 } |
46 | 34 |
47 void MojoGLES2DestroyContext(MojoGLES2Context context) { | 35 void MojoGLES2DestroyContext(MojoGLES2Context context) { |
48 delete static_cast<GLES2Context*>(context); | 36 delete static_cast<GLES2Context*>(context); |
49 } | 37 } |
50 | 38 |
51 void MojoGLES2MakeCurrent(MojoGLES2Context context) { | 39 void MojoGLES2MakeCurrent(MojoGLES2Context context) { |
52 gpu::gles2::GLES2Interface* interface = NULL; | 40 gpu::gles2::GLES2Interface* interface = NULL; |
53 if (context) { | 41 if (context) { |
54 GLES2Context* client = static_cast<GLES2Context*>(context); | 42 GLES2Context* client = static_cast<GLES2Context*>(context); |
55 interface = client->interface(); | 43 interface = client->interface(); |
56 DCHECK(interface); | 44 DCHECK(interface); |
57 } | 45 } |
58 g_gpu_interface = interface; | 46 g_gpu_interface.Get().Set(interface); |
59 } | 47 } |
60 | 48 |
61 void MojoGLES2SwapBuffers() { | 49 void MojoGLES2SwapBuffers() { |
62 assert(g_gpu_interface); | 50 DCHECK(g_gpu_interface.Get().Get()); |
63 g_gpu_interface->SwapBuffers(); | 51 g_gpu_interface.Get().Get()->SwapBuffers(); |
64 } | 52 } |
65 | 53 |
66 void* MojoGLES2GetGLES2Interface(MojoGLES2Context context) { | 54 void* MojoGLES2GetGLES2Interface(MojoGLES2Context context) { |
67 return static_cast<GLES2Context*>(context)->interface(); | 55 return static_cast<GLES2Context*>(context)->interface(); |
68 } | 56 } |
69 | 57 |
70 void* MojoGLES2GetContextSupport(MojoGLES2Context context) { | 58 void* MojoGLES2GetContextSupport(MojoGLES2Context context) { |
71 return static_cast<GLES2Context*>(context)->context_support(); | 59 return static_cast<GLES2Context*>(context)->context_support(); |
72 } | 60 } |
73 | 61 |
74 #define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \ | 62 #define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \ |
75 ReturnType gl##Function PARAMETERS { \ | 63 ReturnType gl##Function PARAMETERS { \ |
76 assert(g_gpu_interface); \ | 64 DCHECK(g_gpu_interface.Get().Get()); \ |
77 return g_gpu_interface->Function ARGUMENTS; \ | 65 return g_gpu_interface.Get().Get()->Function ARGUMENTS; \ |
78 } | 66 } |
79 #include "mojo/public/c/gles2/gles2_call_visitor_autogen.h" | 67 #include "mojo/public/c/gles2/gles2_call_visitor_autogen.h" |
80 #undef VISIT_GL_CALL | 68 #undef VISIT_GL_CALL |
81 | 69 |
82 } // extern "C" | 70 } // extern "C" |
OLD | NEW |