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