Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / mojo / gles2 / gles2_context.cc
blob5574840129cf686667ca7355d347ecdf58626e83
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.
5 #include "mojo/gles2/gles2_context.h"
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/c/gles2/gles2.h"
11 #include "mojo/public/cpp/system/core.h"
13 namespace gles2 {
15 namespace {
16 const size_t kDefaultCommandBufferSize = 1024 * 1024;
17 const size_t kDefaultStartTransferBufferSize = 1 * 1024 * 1024;
18 const size_t kDefaultMinTransferBufferSize = 1 * 256 * 1024;
19 const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024;
22 GLES2Context::GLES2Context(const std::vector<int32_t>& attribs,
23 const MojoAsyncWaiter* async_waiter,
24 mojo::ScopedMessagePipeHandle command_buffer_handle,
25 MojoGLES2ContextLost lost_callback,
26 void* closure)
27 : command_buffer_(this, attribs, async_waiter,
28 command_buffer_handle.Pass()),
29 lost_callback_(lost_callback),
30 closure_(closure) {
33 GLES2Context::~GLES2Context() {}
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 gpu::Capabilities capabilities = command_buffer_.GetCapabilities();
44 bool bind_generates_resource =
45 !!capabilities.bind_generates_resource_chromium;
46 // TODO(piman): Some contexts (such as compositor) want this to be true, so
47 // this needs to be a public parameter.
48 bool lose_context_when_out_of_memory = false;
49 bool support_client_side_arrays = false;
50 implementation_.reset(
51 new gpu::gles2::GLES2Implementation(gles2_helper_.get(),
52 NULL,
53 transfer_buffer_.get(),
54 bind_generates_resource,
55 lose_context_when_out_of_memory,
56 support_client_side_arrays,
57 &command_buffer_));
58 return implementation_->Initialize(kDefaultStartTransferBufferSize,
59 kDefaultMinTransferBufferSize,
60 kDefaultMaxTransferBufferSize,
61 gpu::gles2::GLES2Implementation::kNoLimit);
64 void GLES2Context::ContextLost() { lost_callback_(closure_); }
66 } // namespace gles2