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/c/gles2/gles2.h" 11#include "mojo/public/cpp/system/core.h" 12 13namespace mojo { 14namespace gles2 { 15 16namespace { 17const size_t kDefaultCommandBufferSize = 1024 * 1024; 18const size_t kDefaultStartTransferBufferSize = 1 * 1024 * 1024; 19const size_t kDefaultMinTransferBufferSize = 1 * 256 * 1024; 20const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024; 21} 22 23GLES2Context::GLES2Context(const MojoAsyncWaiter* async_waiter, 24 ScopedMessagePipeHandle command_buffer_handle, 25 MojoGLES2ContextLost lost_callback, 26 void* closure) 27 : command_buffer_(this, async_waiter, command_buffer_handle.Pass()), 28 lost_callback_(lost_callback), 29 closure_(closure) {} 30 31GLES2Context::~GLES2Context() {} 32 33bool GLES2Context::Initialize() { 34 if (!command_buffer_.Initialize()) 35 return false; 36 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(&command_buffer_)); 37 if (!gles2_helper_->Initialize(kDefaultCommandBufferSize)) 38 return false; 39 gles2_helper_->SetAutomaticFlushes(false); 40 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); 41 bool bind_generates_resource = true; 42 // TODO(piman): Some contexts (such as compositor) want this to be true, so 43 // this needs to be a public parameter. 44 bool lose_context_when_out_of_memory = false; 45 implementation_.reset( 46 new gpu::gles2::GLES2Implementation(gles2_helper_.get(), 47 NULL, 48 transfer_buffer_.get(), 49 bind_generates_resource, 50 lose_context_when_out_of_memory, 51 &command_buffer_)); 52 return implementation_->Initialize(kDefaultStartTransferBufferSize, 53 kDefaultMinTransferBufferSize, 54 kDefaultMaxTransferBufferSize, 55 gpu::gles2::GLES2Implementation::kNoLimit); 56} 57 58void GLES2Context::ContextLost() { lost_callback_(closure_); } 59 60} // namespace gles2 61} // namespace mojo 62