1 // Copyright 2015 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 "components/native_viewport/onscreen_context_provider.h"
7 #include "components/gles2/command_buffer_driver.h"
8 #include "components/gles2/command_buffer_impl.h"
9 #include "components/gles2/gpu_state.h"
11 namespace native_viewport
{
13 OnscreenContextProvider::OnscreenContextProvider(
14 const scoped_refptr
<gles2::GpuState
>& state
)
15 : state_(state
), widget_(gfx::kNullAcceleratedWidget
), binding_(this) {
18 OnscreenContextProvider::~OnscreenContextProvider() {
21 void OnscreenContextProvider::Bind(
22 mojo::InterfaceRequest
<mojo::ContextProvider
> request
) {
23 binding_
.Bind(request
.Pass());
26 void OnscreenContextProvider::SetAcceleratedWidget(
27 gfx::AcceleratedWidget widget
) {
29 if (widget_
!= gfx::kNullAcceleratedWidget
&&
30 !pending_create_callback_
.is_null())
31 CreateAndReturnCommandBuffer();
34 void OnscreenContextProvider::Create(
35 mojo::ViewportParameterListenerPtr viewport_parameter_listener
,
36 const CreateCallback
& callback
) {
37 if (!pending_create_callback_
.is_null())
38 pending_create_callback_
.Run(nullptr);
39 pending_listener_
= viewport_parameter_listener
.Pass();
40 pending_create_callback_
= callback
;
42 if (widget_
!= gfx::kNullAcceleratedWidget
)
43 CreateAndReturnCommandBuffer();
46 void OnscreenContextProvider::CreateAndReturnCommandBuffer() {
47 mojo::CommandBufferPtr cb
;
48 new gles2::CommandBufferImpl(
49 GetProxy(&cb
), pending_listener_
.Pass(), state_
->control_task_runner(),
50 state_
->sync_point_manager(),
51 make_scoped_ptr(new gles2::CommandBufferDriver(
52 widget_
, state_
->share_group(), state_
->mailbox_manager(),
53 state_
->sync_point_manager())));
54 pending_create_callback_
.Run(cb
.Pass());
55 pending_create_callback_
.reset();