1 // Copyright 2013 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_GLES2_COMMAND_BUFFER_DRIVER_H_
6 #define COMPONENTS_GLES2_COMMAND_BUFFER_DRIVER_H_
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/timer/timer.h"
13 #include "components/gpu/public/interfaces/command_buffer.mojom.h"
14 #include "ui/gfx/geometry/size.h"
15 #include "ui/gfx/native_widget_types.h"
18 class CommandBufferService
;
20 class GpuControlService
;
21 class SyncPointManager
;
36 class CommandBufferDriver
{
41 virtual void UpdateVSyncParameters(base::TimeTicks timebase
,
42 base::TimeDelta interval
) = 0;
43 virtual void DidLoseContext() = 0;
46 CommandBufferDriver(gfx::GLShareGroup
* share_group
,
47 gpu::gles2::MailboxManager
* mailbox_manager
,
48 gpu::SyncPointManager
* sync_point_manager
);
50 CommandBufferDriver(gfx::AcceleratedWidget widget
,
51 gfx::GLShareGroup
* share_group
,
52 gpu::gles2::MailboxManager
* mailbox_manager
,
53 gpu::SyncPointManager
* sync_point_manager
);
54 ~CommandBufferDriver();
56 void set_client(scoped_ptr
<Client
> client
) { client_
= client
.Pass(); }
58 void Initialize(mojo::CommandBufferSyncClientPtr sync_client
,
59 mojo::CommandBufferLostContextObserverPtr loss_observer
,
60 mojo::ScopedSharedBufferHandle shared_state
);
61 void SetGetBuffer(int32_t buffer
);
62 void Flush(int32_t put_offset
);
63 void MakeProgress(int32_t last_get_offset
);
64 void RegisterTransferBuffer(int32_t id
,
65 mojo::ScopedSharedBufferHandle transfer_buffer
,
67 void DestroyTransferBuffer(int32_t id
);
68 void Echo(const mojo::Callback
<void()>& callback
);
71 bool DoInitialize(mojo::ScopedSharedBufferHandle shared_state
);
72 void OnResize(gfx::Size size
, float scale_factor
);
73 bool OnWaitSyncPoint(uint32_t sync_point
);
74 void OnSyncPointRetired();
76 void OnContextLost(uint32_t reason
);
77 void OnUpdateVSyncParameters(const base::TimeTicks timebase
,
78 const base::TimeDelta interval
);
80 scoped_ptr
<Client
> client_
;
81 mojo::CommandBufferSyncClientPtr sync_client_
;
82 mojo::CommandBufferLostContextObserverPtr loss_observer_
;
83 gfx::AcceleratedWidget widget_
;
84 scoped_ptr
<gpu::CommandBufferService
> command_buffer_
;
85 scoped_ptr
<gpu::gles2::GLES2Decoder
> decoder_
;
86 scoped_ptr
<gpu::GpuScheduler
> scheduler_
;
87 scoped_refptr
<gfx::GLContext
> context_
;
88 scoped_refptr
<gfx::GLSurface
> surface_
;
89 scoped_refptr
<gfx::GLShareGroup
> share_group_
;
90 scoped_refptr
<gpu::gles2::MailboxManager
> mailbox_manager_
;
91 scoped_refptr
<gpu::SyncPointManager
> sync_point_manager_
;
93 scoped_refptr
<base::SingleThreadTaskRunner
> context_lost_task_runner_
;
94 base::Callback
<void(int32_t)> context_lost_callback_
;
96 base::WeakPtrFactory
<CommandBufferDriver
> weak_factory_
;
98 DISALLOW_COPY_AND_ASSIGN(CommandBufferDriver
);
103 #endif // COMPONENTS_GLES2_COMMAND_BUFFER_DRIVER_H_