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/services/gles2/gles2_impl.h" | 5 #include "mojo/services/gles2/gles2_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "gpu/command_buffer/client/gl_in_process_context.h" | 8 #include "gpu/command_buffer/client/gl_in_process_context.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace services { | 12 namespace services { |
13 | 13 |
14 GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client) | 14 GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client) |
15 : client_(client.Pass()) { | 15 : client_(client.Pass()) { |
16 client_.SetPeer(this); | 16 client_.SetPeer(this); |
17 } | 17 } |
18 | 18 |
19 GLES2Impl::~GLES2Impl() { | 19 GLES2Impl::~GLES2Impl() { |
20 } | 20 } |
21 | 21 |
22 void GLES2Impl::SwapBuffers() { | 22 void GLES2Impl::Destroy() { |
23 if (!gl_context_) | 23 gl_context_.reset(); |
24 return; | |
25 gl_context_->GetImplementation()->SwapBuffers(); | |
26 } | 24 } |
27 | 25 |
28 void GLES2Impl::CreateContext(gfx::AcceleratedWidget widget, | 26 void GLES2Impl::CreateContext(gfx::AcceleratedWidget widget, |
29 const gfx::Size& size) { | 27 const gfx::Size& size) { |
30 gpu::GLInProcessContextAttribs attribs; | 28 gpu::GLInProcessContextAttribs attribs; |
31 gl_context_.reset(gpu::GLInProcessContext::CreateContext( | 29 gl_context_.reset(gpu::GLInProcessContext::CreateContext( |
32 false, widget, size, false, attribs, gfx::PreferDiscreteGpu)); | 30 false, widget, size, false, attribs, gfx::PreferDiscreteGpu)); |
33 gl_context_->SetContextLostCallback(base::Bind( | 31 gl_context_->SetContextLostCallback(base::Bind( |
34 &GLES2Impl::OnGLContextLost, base::Unretained(this))); | 32 &GLES2Impl::OnGLContextLost, base::Unretained(this))); |
35 | 33 |
36 gpu::gles2::GLES2Interface* gl = gl_context_->GetImplementation(); | 34 gpu::gles2::GLES2Interface* gl = gl_context_->GetImplementation(); |
37 uint64_t encoded_gl = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(gl)); | 35 uint64_t encoded_gl = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(gl)); |
38 | 36 |
39 client_->DidCreateContext(encoded_gl, size.width(), size.height()); | 37 client_->DidCreateContext(encoded_gl, size.width(), size.height()); |
40 } | 38 } |
41 | 39 |
42 void GLES2Impl::OnGLContextLost() { | 40 void GLES2Impl::OnGLContextLost() { |
43 client_->ContextLost(); | 41 client_->ContextLost(); |
44 } | 42 } |
45 | 43 |
46 } // namespace services | 44 } // namespace services |
47 } // namespace mojo | 45 } // namespace mojo |
OLD | NEW |