Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / mojo / services / gles2 / gles2_impl.cc
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 <stdio.h>
8 #include "base/bind.h"
9 #include "gpu/command_buffer/client/gl_in_process_context.h"
10 #include "gpu/command_buffer/client/gles2_implementation.h"
11
12 namespace mojo {
13 namespace services {
14
15 GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client)
16     : client_(client.Pass(), this) {
17 }
18
19 GLES2Impl::~GLES2Impl() {
20 }
21
22 void GLES2Impl::RequestAnimationFrames() {
23   timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16),
24                this, &GLES2Impl::DrawAnimationFrame);
25 }
26
27 void GLES2Impl::CancelAnimationFrames() {
28   timer_.Stop();
29 }
30
31 void GLES2Impl::Destroy() {
32   gl_context_.reset();
33 }
34
35 void GLES2Impl::CreateContext(gfx::AcceleratedWidget widget,
36                               const gfx::Size& size) {
37   gpu::GLInProcessContextAttribs attribs;
38   gl_context_.reset(gpu::GLInProcessContext::CreateContext(
39       false, widget, size, false, attribs, gfx::PreferDiscreteGpu));
40   gl_context_->SetContextLostCallback(base::Bind(
41       &GLES2Impl::OnGLContextLost, base::Unretained(this)));
42
43   gpu::gles2::GLES2Interface* gl = gl_context_->GetImplementation();
44   uint64_t encoded_gl = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(gl));
45
46   client_->DidCreateContext(encoded_gl, size.width(), size.height());
47 }
48
49 void GLES2Impl::OnGLContextLost() {
50   client_->ContextLost();
51 }
52
53 void GLES2Impl::DrawAnimationFrame() {
54   client_->DrawAnimationFrame();
55 }
56
57 }  // namespace services
58 }  // namespace mojo