| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/examples/compositor_app/gles2_client_impl.h" | 5 #include "mojo/examples/compositor_app/gles2_client_impl.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "gpu/command_buffer/client/context_support.h" | 8 #include "gpu/command_buffer/client/context_support.h" |
| 9 #include "gpu/command_buffer/client/gles2_interface.h" | 9 #include "gpu/command_buffer/client/gles2_interface.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 namespace examples { | 12 namespace examples { |
| 13 | 13 |
| 14 GLES2ClientImpl::GLES2ClientImpl( | 14 GLES2ClientImpl::GLES2ClientImpl( |
| 15 ScopedMessagePipeHandle pipe, | 15 ScopedMessagePipeHandle pipe, |
| 16 const base::Callback<void(gfx::Size)>& context_created_callback) | 16 const base::Callback<void()>& context_created_callback) |
| 17 : context_created_callback_(context_created_callback) { | 17 : context_created_callback_(context_created_callback) { |
| 18 context_ = MojoGLES2CreateContext( | 18 context_ = MojoGLES2CreateContext( |
| 19 pipe.release().value(), | 19 pipe.release().value(), |
| 20 &DidCreateContextThunk, | 20 &DidCreateContextThunk, |
| 21 &ContextLostThunk, | 21 &ContextLostThunk, |
| 22 NULL, | 22 NULL, |
| 23 this); | 23 this); |
| 24 } | 24 } |
| 25 | 25 |
| 26 GLES2ClientImpl::~GLES2ClientImpl() { | 26 GLES2ClientImpl::~GLES2ClientImpl() { |
| 27 if (context_) | 27 if (context_) |
| 28 MojoGLES2DestroyContext(context_); | 28 MojoGLES2DestroyContext(context_); |
| 29 } | 29 } |
| 30 | 30 |
| 31 gpu::gles2::GLES2Interface* GLES2ClientImpl::Interface() const { | 31 gpu::gles2::GLES2Interface* GLES2ClientImpl::Interface() const { |
| 32 if (!context_) | 32 if (!context_) |
| 33 return NULL; | 33 return NULL; |
| 34 return static_cast<gpu::gles2::GLES2Interface*>( | 34 return static_cast<gpu::gles2::GLES2Interface*>( |
| 35 MojoGLES2GetGLES2Interface(context_)); | 35 MojoGLES2GetGLES2Interface(context_)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 gpu::ContextSupport* GLES2ClientImpl::Support() const { | 38 gpu::ContextSupport* GLES2ClientImpl::Support() const { |
| 39 if (!context_) | 39 if (!context_) |
| 40 return NULL; | 40 return NULL; |
| 41 return static_cast<gpu::ContextSupport*>( | 41 return static_cast<gpu::ContextSupport*>( |
| 42 MojoGLES2GetContextSupport(context_)); | 42 MojoGLES2GetContextSupport(context_)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void GLES2ClientImpl::DidCreateContext(uint32_t width, | 45 void GLES2ClientImpl::DidCreateContext() { |
| 46 uint32_t height) { | |
| 47 TRACE_EVENT0("compositor_app", "DidCreateContext"); | 46 TRACE_EVENT0("compositor_app", "DidCreateContext"); |
| 48 if (!context_created_callback_.is_null()) | 47 if (!context_created_callback_.is_null()) |
| 49 context_created_callback_.Run(gfx::Size(width, height)); | 48 context_created_callback_.Run(); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void GLES2ClientImpl::DidCreateContextThunk( | 51 void GLES2ClientImpl::DidCreateContextThunk(void* closure) { |
| 53 void* closure, | 52 static_cast<GLES2ClientImpl*>(closure)->DidCreateContext(); |
| 54 uint32_t width, | |
| 55 uint32_t height) { | |
| 56 static_cast<GLES2ClientImpl*>(closure)->DidCreateContext(width, height); | |
| 57 } | 53 } |
| 58 | 54 |
| 59 void GLES2ClientImpl::ContextLost() { | 55 void GLES2ClientImpl::ContextLost() { |
| 60 if (context_) { | 56 if (context_) { |
| 61 MojoGLES2DestroyContext(context_); | 57 MojoGLES2DestroyContext(context_); |
| 62 context_ = NULL; | 58 context_ = NULL; |
| 63 } | 59 } |
| 64 } | 60 } |
| 65 | 61 |
| 66 void GLES2ClientImpl::ContextLostThunk(void* closure) { | 62 void GLES2ClientImpl::ContextLostThunk(void* closure) { |
| 67 static_cast<GLES2ClientImpl*>(closure)->ContextLost(); | 63 static_cast<GLES2ClientImpl*>(closure)->ContextLost(); |
| 68 } | 64 } |
| 69 | 65 |
| 70 } // namespace examples | 66 } // namespace examples |
| 71 } // namespace mojo | 67 } // namespace mojo |
| OLD | NEW |