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 #ifndef COMPONENTS_VIEW_MANAGER_GLES2_COMMAND_BUFFER_IMPL_H_
6 #define COMPONENTS_VIEW_MANAGER_GLES2_COMMAND_BUFFER_IMPL_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/single_thread_task_runner.h"
10 #include "components/view_manager/public/interfaces/command_buffer.mojom.h"
11 #include "components/view_manager/public/interfaces/viewport_parameter_listener.mojom.h"
12 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
15 class SyncPointManager
;
19 class CommandBufferDriver
;
20 class CommandBufferImplObserver
;
22 // This class listens to the CommandBuffer message pipe on a low-latency thread
23 // so that we can insert sync points without blocking on the GL driver. It
24 // forwards most method calls to the CommandBufferDriver, which runs on the
25 // same thread as the native viewport.
26 class CommandBufferImpl
: public mojo::CommandBuffer
,
27 public mojo::ErrorHandler
{
30 mojo::InterfaceRequest
<CommandBuffer
> request
,
31 mojo::ViewportParameterListenerPtr listener
,
32 scoped_refptr
<base::SingleThreadTaskRunner
> control_task_runner
,
33 gpu::SyncPointManager
* sync_point_manager
,
34 scoped_ptr
<CommandBufferDriver
> driver
);
36 // mojo::CommandBuffer:
37 void Initialize(mojo::CommandBufferSyncClientPtr sync_client
,
38 mojo::CommandBufferSyncPointClientPtr sync_point_client
,
39 mojo::CommandBufferLostContextObserverPtr loss_observer
,
40 mojo::ScopedSharedBufferHandle shared_state
) override
;
41 void SetGetBuffer(int32_t buffer
) override
;
42 void Flush(int32_t put_offset
) override
;
43 void MakeProgress(int32_t last_get_offset
) override
;
44 void RegisterTransferBuffer(int32_t id
,
45 mojo::ScopedSharedBufferHandle transfer_buffer
,
46 uint32_t size
) override
;
47 void DestroyTransferBuffer(int32_t id
) override
;
48 void InsertSyncPoint(bool retire
) override
;
49 void RetireSyncPoint(uint32_t sync_point
) override
;
50 void Echo(const mojo::Callback
<void()>& callback
) override
;
51 void CreateImage(int32_t id
,
52 mojo::ScopedHandle memory_handle
,
56 int32_t internal_format
) override
;
57 void DestroyImage(int32_t id
) override
;
59 void DidLoseContext();
61 void set_observer(CommandBufferImplObserver
* observer
) {
66 class CommandBufferDriverClientImpl
;
68 friend class base::DeleteHelper
<CommandBufferImpl
>;
70 ~CommandBufferImpl() override
;
72 void BindToRequest(mojo::InterfaceRequest
<CommandBuffer
> request
);
74 void UpdateVSyncParameters(base::TimeTicks timebase
,
75 base::TimeDelta interval
);
77 // mojo::ErrorHandler:
78 void OnConnectionError() override
;
80 scoped_refptr
<gpu::SyncPointManager
> sync_point_manager_
;
81 scoped_refptr
<base::SingleThreadTaskRunner
> driver_task_runner_
;
82 scoped_ptr
<CommandBufferDriver
> driver_
;
83 mojo::CommandBufferSyncPointClientPtr sync_point_client_
;
84 mojo::ViewportParameterListenerPtr viewport_parameter_listener_
;
85 mojo::Binding
<CommandBuffer
> binding_
;
86 CommandBufferImplObserver
* observer_
;
88 DISALLOW_COPY_AND_ASSIGN(CommandBufferImpl
);
93 #endif // COMPONENTS_VIEW_MANAGER_GLES2_COMMAND_BUFFER_IMPL_H_