15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "mojo/gles2/gles2_support_impl.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/lazy_instance.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "gpu/command_buffer/client/gles2_interface.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "mojo/gles2/gles2_context.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "mojo/public/gles2/gles2_interface.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "mojo/public/gles2/gles2_private.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace mojo { 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace gles2 { 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class GLES2ImplForCommandBuffer : public GLES2Interface { 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GLES2ImplForCommandBuffer() : gpu_interface_(NULL) {} 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void set_gpu_interface(gpu::gles2::GLES2Interface* gpu_interface) { 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gpu_interface_ = gpu_interface; 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gpu::gles2::GLES2Interface* gpu_interface() const { return gpu_interface_; } 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \ 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ReturnType Function PARAMETERS OVERRIDE { \ 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return gpu_interface_->Function ARGUMENTS; \ 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 314ad1aa43a48567659193a298fad74f55e00b3dd9Ben Murdoch#include "mojo/public/c/gles2/gles2_call_visitor_autogen.h" 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#undef VISIT_GL_CALL 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gpu::gles2::GLES2Interface* gpu_interface_; 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(GLES2ImplForCommandBuffer); 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::LazyInstance<GLES2ImplForCommandBuffer> g_gles2_interface = 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LAZY_INSTANCE_INITIALIZER; 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // anonymous namespace 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)GLES2SupportImpl::GLES2SupportImpl() : async_waiter_(NULL) {} 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)GLES2SupportImpl::~GLES2SupportImpl() {} 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// static 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void GLES2SupportImpl::Init() { GLES2Support::Init(new GLES2SupportImpl()); } 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 50f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)void GLES2SupportImpl::Initialize(const MojoAsyncWaiter* async_waiter) { 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(!async_waiter_); 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(async_waiter); 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) async_waiter_ = async_waiter; 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void GLES2SupportImpl::Terminate() { 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(async_waiter_); 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) async_waiter_ = NULL; 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)MojoGLES2Context GLES2SupportImpl::CreateContext( 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MessagePipeHandle handle, 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MojoGLES2ContextLost lost_callback, 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MojoGLES2DrawAnimationFrame animation_callback, 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void* closure) { 660de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles) ScopedMessagePipeHandle scoped_handle(handle); 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<GLES2Context> client(new GLES2Context(async_waiter_, 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_handle.Pass(), 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) lost_callback, 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) animation_callback, 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) closure)); 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!client->Initialize()) 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) client.reset(); 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return client.release(); 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void GLES2SupportImpl::DestroyContext(MojoGLES2Context context) { 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delete static_cast<GLES2Context*>(context); 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void GLES2SupportImpl::MakeCurrent(MojoGLES2Context context) { 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gpu::gles2::GLES2Interface* interface = NULL; 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (context) { 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GLES2Context* client = static_cast<GLES2Context*>(context); 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) interface = client->interface(); 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(interface); 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) g_gles2_interface.Get().set_gpu_interface(interface); 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void GLES2SupportImpl::SwapBuffers() { 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) g_gles2_interface.Get().gpu_interface()->SwapBuffers(); 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void GLES2SupportImpl::RequestAnimationFrames(MojoGLES2Context context) { 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static_cast<GLES2Context*>(context)->RequestAnimationFrames(); 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void GLES2SupportImpl::CancelAnimationFrames(MojoGLES2Context context) { 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static_cast<GLES2Context*>(context)->CancelAnimationFrames(); 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void* GLES2SupportImpl::GetGLES2Interface(MojoGLES2Context context) { 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return static_cast<GLES2Context*>(context)->interface(); 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void* GLES2SupportImpl::GetContextSupport(MojoGLES2Context context) { 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return static_cast<GLES2Context*>(context)->context_support(); 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)GLES2Interface* GLES2SupportImpl::GetGLES2InterfaceForCurrentContext() { 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return &g_gles2_interface.Get(); 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace gles2 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace mojo 117