| 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/public/bindings/gles2_client/gles2_client_impl.h" | 5 #include "mojo/public/bindings/gles2_client/gles2_client_impl.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 | 8 |
| 9 #include "gpu/command_buffer/client/gles2_lib.h" | 9 #include "gpu/command_buffer/client/gles2_lib.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 bool g_gles2_initialized = false; | 14 bool g_gles2_initialized = false; |
| 15 | 15 |
| 16 } // namespace | 16 } // namespace |
| 17 | 17 |
| 18 GLES2Delegate::~GLES2Delegate() { | 18 GLES2Delegate::~GLES2Delegate() { |
| 19 } | 19 } |
| 20 | 20 |
| 21 void GLES2Delegate::DidCreateContext( | 21 void GLES2Delegate::DidCreateContext( |
| 22 GLES2* gl, uint32_t width, uint32_t height) { | 22 GLES2ClientImpl* gl, uint32_t width, uint32_t height) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 void GLES2Delegate::ContextLost(GLES2* gl) { | 25 void GLES2Delegate::ContextLost(GLES2ClientImpl* gl) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 GLES2ClientImpl::GLES2ClientImpl(GLES2Delegate* delegate, | 28 GLES2ClientImpl::GLES2ClientImpl(GLES2Delegate* delegate, |
| 29 ScopedMessagePipeHandle gl) | 29 ScopedMessagePipeHandle gl) |
| 30 : delegate_(delegate), | 30 : delegate_(delegate), |
| 31 gl_(gl.Pass()) { | 31 gl_(gl.Pass()) { |
| 32 assert(g_gles2_initialized); | 32 assert(g_gles2_initialized); |
| 33 gl_.SetPeer(this); | 33 gl_.SetPeer(this); |
| 34 } | 34 } |
| 35 | 35 |
| 36 GLES2ClientImpl::~GLES2ClientImpl() { | 36 GLES2ClientImpl::~GLES2ClientImpl() { |
| 37 gl_->Destroy(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void GLES2ClientImpl::Initialize() { | 40 void GLES2ClientImpl::Initialize() { |
| 40 assert(!g_gles2_initialized); | 41 assert(!g_gles2_initialized); |
| 41 gles2::Initialize(); | 42 gles2::Initialize(); |
| 42 g_gles2_initialized = true; | 43 g_gles2_initialized = true; |
| 43 } | 44 } |
| 44 | 45 |
| 45 void GLES2ClientImpl::Terminate() { | 46 void GLES2ClientImpl::Terminate() { |
| 46 assert(g_gles2_initialized); | 47 assert(g_gles2_initialized); |
| 47 gles2::Terminate(); | 48 gles2::Terminate(); |
| 48 g_gles2_initialized = false; | 49 g_gles2_initialized = false; |
| 49 } | 50 } |
| 50 | 51 |
| 52 void GLES2ClientImpl::SwapBuffers() { |
| 53 gles2::GetGLContext()->SwapBuffers(); |
| 54 } |
| 55 |
| 51 void GLES2ClientImpl::DidCreateContext( | 56 void GLES2ClientImpl::DidCreateContext( |
| 52 uint64_t encoded, uint32_t width, uint32_t height) { | 57 uint64_t encoded, uint32_t width, uint32_t height) { |
| 53 // Ack, Hans! It's the giant hack. | 58 // Ack, Hans! It's the giant hack. |
| 54 // TODO(abarth): Replace this hack with something more disciplined. Most | 59 // TODO(abarth): Replace this hack with something more disciplined. Most |
| 55 // likley, we should receive a MojoHandle that we use to wire up the | 60 // likley, we should receive a MojoHandle that we use to wire up the |
| 56 // client side of an out-of-process command buffer. Given that we're | 61 // client side of an out-of-process command buffer. Given that we're |
| 57 // still in-process, we just reinterpret_cast the value into a GL interface. | 62 // still in-process, we just reinterpret_cast the value into a GL interface. |
| 58 gpu::gles2::GLES2Interface* gl_interface = | 63 gpu::gles2::GLES2Interface* gl_interface = |
| 59 reinterpret_cast<gpu::gles2::GLES2Interface*>( | 64 reinterpret_cast<gpu::gles2::GLES2Interface*>( |
| 60 static_cast<uintptr_t>(encoded)); | 65 static_cast<uintptr_t>(encoded)); |
| 61 gles2::SetGLContext(gl_interface); | 66 gles2::SetGLContext(gl_interface); |
| 62 | 67 |
| 63 delegate_->DidCreateContext(gl(), width, height); | 68 delegate_->DidCreateContext(this, width, height); |
| 64 } | 69 } |
| 65 | 70 |
| 66 void GLES2ClientImpl::ContextLost() { | 71 void GLES2ClientImpl::ContextLost() { |
| 67 delegate_->ContextLost(gl()); | 72 delegate_->ContextLost(this); |
| 68 } | 73 } |
| 69 | 74 |
| 70 } // mojo | 75 } // mojo |
| OLD | NEW |