| 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 <stdint.h> | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/threading/thread_local.h" | |
| 11 #include "components/mus/public/cpp/gles2_context.h" | |
| 12 #include "gpu/GLES2/gl2extchromium.h" | |
| 13 #include "gpu/command_buffer/client/gles2_interface.h" | |
| 14 // Even though this isn't used here, we need to include it to get the symbols to | |
| 15 // be exported in component build. | |
| 16 #include "mojo/public/c/gles2/chromium_extension.h" | |
| 17 #include "mojo/public/c/gles2/gles2.h" | |
| 18 | |
| 19 using mus::GLES2Context; | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 const int32_t kNone = 0x3038; // EGL_NONE | |
| 24 | |
| 25 base::LazyInstance<base::ThreadLocalPointer<gpu::gles2::GLES2Interface> >::Leaky | |
| 26 g_gpu_interface; | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 extern "C" { | |
| 31 MojoGLES2Context MojoGLES2CreateContext(MojoHandle handle, | |
| 32 const int32_t* attrib_list, | |
| 33 MojoGLES2ContextLost lost_callback, | |
| 34 void* closure) { | |
| 35 mojo::MessagePipeHandle mph(handle); | |
| 36 mojo::ScopedMessagePipeHandle scoped_handle(mph); | |
| 37 std::vector<int32_t> attribs; | |
| 38 if (attrib_list) { | |
| 39 for (int32_t const* p = attrib_list; *p != kNone;) { | |
| 40 attribs.push_back(*p++); | |
| 41 attribs.push_back(*p++); | |
| 42 } | |
| 43 } | |
| 44 attribs.push_back(kNone); | |
| 45 std::unique_ptr<GLES2Context> client(new GLES2Context( | |
| 46 attribs, std::move(scoped_handle), lost_callback, closure)); | |
| 47 if (!client->Initialize()) | |
| 48 client.reset(); | |
| 49 return client.release(); | |
| 50 } | |
| 51 | |
| 52 void MojoGLES2DestroyContext(MojoGLES2Context context) { | |
| 53 delete static_cast<GLES2Context*>(context); | |
| 54 } | |
| 55 | |
| 56 void MojoGLES2MakeCurrent(MojoGLES2Context context) { | |
| 57 gpu::gles2::GLES2Interface* interface = NULL; | |
| 58 if (context) { | |
| 59 GLES2Context* client = static_cast<GLES2Context*>(context); | |
| 60 interface = client->interface(); | |
| 61 DCHECK(interface); | |
| 62 } | |
| 63 g_gpu_interface.Get().Set(interface); | |
| 64 } | |
| 65 | |
| 66 void MojoGLES2SwapBuffers() { | |
| 67 DCHECK(g_gpu_interface.Get().Get()); | |
| 68 g_gpu_interface.Get().Get()->SwapBuffers(); | |
| 69 } | |
| 70 | |
| 71 void* MojoGLES2GetGLES2Interface(MojoGLES2Context context) { | |
| 72 return static_cast<GLES2Context*>(context)->interface(); | |
| 73 } | |
| 74 | |
| 75 void* MojoGLES2GetContextSupport(MojoGLES2Context context) { | |
| 76 return static_cast<GLES2Context*>(context)->context_support(); | |
| 77 } | |
| 78 | |
| 79 #define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \ | |
| 80 ReturnType GL_APIENTRY gl##Function PARAMETERS { \ | |
| 81 DCHECK(g_gpu_interface.Get().Get()); \ | |
| 82 return g_gpu_interface.Get().Get()->Function ARGUMENTS; \ | |
| 83 } | |
| 84 #include "mojo/public/c/gles2/gles2_call_visitor_autogen.h" | |
| 85 #include "mojo/public/c/gles2/gles2_call_visitor_chromium_extension_autogen.h" | |
| 86 #undef VISIT_GL_CALL | |
| 87 | |
| 88 } // extern "C" | |
| OLD | NEW |