Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / mojo / gles2 / gles2_context.cc
1 // Copyright 2014 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/gles2/gles2_context.h"
6
7 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
8 #include "gpu/command_buffer/client/gles2_implementation.h"
9 #include "gpu/command_buffer/client/transfer_buffer.h"
10 #include "mojo/public/gles2/gles2.h"
11 #include "mojo/public/system/core_cpp.h"
12
13 namespace mojo {
14 namespace gles2 {
15
16 namespace {
17 const size_t kDefaultCommandBufferSize = 1024 * 1024;
18 const size_t kDefaultStartTransferBufferSize = 1 * 1024 * 1024;
19 const size_t kDefaultMinTransferBufferSize = 1 * 256 * 1024;
20 const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024;
21 }
22
23 GLES2Context::GLES2Context(MojoAsyncWaiter* async_waiter,
24                            ScopedCommandBufferHandle command_buffer_handle,
25                            MojoGLES2ContextLost lost_callback,
26                            MojoGLES2DrawAnimationFrame animation_callback,
27                            void* closure)
28     : command_buffer_(this, async_waiter, command_buffer_handle.Pass()),
29       lost_callback_(lost_callback),
30       animation_callback_(animation_callback),
31       closure_(closure) {}
32
33 GLES2Context::~GLES2Context() {}
34
35 bool GLES2Context::Initialize() {
36   if (!command_buffer_.Initialize())
37     return false;
38   gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(&command_buffer_));
39   if (!gles2_helper_->Initialize(kDefaultCommandBufferSize))
40     return false;
41   gles2_helper_->SetAutomaticFlushes(false);
42   transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get()));
43   implementation_.reset(
44       new gpu::gles2::GLES2Implementation(gles2_helper_.get(),
45                                           NULL,
46                                           transfer_buffer_.get(),
47                                           true,
48                                           true,
49                                           &command_buffer_));
50   return implementation_->Initialize(kDefaultStartTransferBufferSize,
51                                      kDefaultMinTransferBufferSize,
52                                      kDefaultMaxTransferBufferSize,
53                                      gpu::gles2::GLES2Implementation::kNoLimit);
54 }
55
56 void GLES2Context::RequestAnimationFrames() {
57   command_buffer_.RequestAnimationFrames();
58 }
59
60 void GLES2Context::CancelAnimationFrames() {
61   command_buffer_.CancelAnimationFrames();
62 }
63
64 void GLES2Context::ContextLost() { lost_callback_(closure_); }
65
66 void GLES2Context::DrawAnimationFrame() { animation_callback_(closure_); }
67
68 }  // namespace gles2
69 }  // namespace mojo