OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SERVICES_GLES2_COMMAND_BUFFER_IMPL_H_ | 5 #ifndef SERVICES_GLES2_COMMAND_BUFFER_IMPL_H_ |
6 #define SERVICES_GLES2_COMMAND_BUFFER_IMPL_H_ | 6 #define SERVICES_GLES2_COMMAND_BUFFER_IMPL_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "mojo/public/cpp/bindings/strong_binding.h" | 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
12 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h" | 12 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h" |
13 #include "mojo/services/gpu/public/interfaces/viewport_parameter_listener.mojom.
h" | 13 #include "mojo/services/gpu/public/interfaces/viewport_parameter_listener.mojom.
h" |
14 | 14 |
15 namespace gpu { | 15 namespace gpu { |
16 class SyncPointManager; | 16 class SyncPointManager; |
17 } | 17 } |
18 | 18 |
19 namespace gles2 { | 19 namespace gles2 { |
20 class CommandBufferDriver; | 20 class CommandBufferDriver; |
21 | 21 |
22 // This class listens to the CommandBuffer message pipe on a low-latency thread | 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 | 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 | 24 // forwards most method calls to the CommandBufferDriver, which runs on the |
25 // same thread as the native viewport. | 25 // same thread as the native viewport. |
26 class CommandBufferImpl : public mojo::CommandBuffer { | 26 class CommandBufferImpl : public mojo::CommandBuffer { |
27 public: | 27 public: |
| 28 class Observer { |
| 29 public: |
| 30 virtual void OnCommandBufferImplDestroyed() = 0; |
| 31 }; |
| 32 |
28 CommandBufferImpl( | 33 CommandBufferImpl( |
29 mojo::InterfaceRequest<CommandBuffer> request, | 34 mojo::InterfaceRequest<CommandBuffer> request, |
30 mojo::ViewportParameterListenerPtr listener, | 35 mojo::ViewportParameterListenerPtr listener, |
31 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner, | 36 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner, |
32 gpu::SyncPointManager* sync_point_manager, | 37 gpu::SyncPointManager* sync_point_manager, |
33 scoped_ptr<CommandBufferDriver> driver); | 38 scoped_ptr<CommandBufferDriver> driver); |
34 ~CommandBufferImpl() override; | 39 ~CommandBufferImpl() override; |
35 | 40 |
36 void Initialize(mojo::CommandBufferSyncClientPtr sync_client, | 41 void Initialize(mojo::CommandBufferSyncClientPtr sync_client, |
37 mojo::CommandBufferSyncPointClientPtr sync_point_client, | 42 mojo::CommandBufferSyncPointClientPtr sync_point_client, |
38 mojo::CommandBufferLostContextObserverPtr loss_observer, | 43 mojo::CommandBufferLostContextObserverPtr loss_observer, |
39 mojo::ScopedSharedBufferHandle shared_state) override; | 44 mojo::ScopedSharedBufferHandle shared_state) override; |
40 void SetGetBuffer(int32_t buffer) override; | 45 void SetGetBuffer(int32_t buffer) override; |
41 void Flush(int32_t put_offset) override; | 46 void Flush(int32_t put_offset) override; |
42 void MakeProgress(int32_t last_get_offset) override; | 47 void MakeProgress(int32_t last_get_offset) override; |
43 void RegisterTransferBuffer(int32_t id, | 48 void RegisterTransferBuffer(int32_t id, |
44 mojo::ScopedSharedBufferHandle transfer_buffer, | 49 mojo::ScopedSharedBufferHandle transfer_buffer, |
45 uint32_t size) override; | 50 uint32_t size) override; |
46 void DestroyTransferBuffer(int32_t id) override; | 51 void DestroyTransferBuffer(int32_t id) override; |
47 void InsertSyncPoint(bool retire) override; | 52 void InsertSyncPoint(bool retire) override; |
48 void RetireSyncPoint(uint32_t sync_point) override; | 53 void RetireSyncPoint(uint32_t sync_point) override; |
49 void Echo(const mojo::Callback<void()>& callback) override; | 54 void Echo(const mojo::Callback<void()>& callback) override; |
50 | 55 |
51 void DidLoseContext(); | 56 void DidLoseContext(); |
52 void UpdateVSyncParameters(base::TimeTicks timebase, | 57 void UpdateVSyncParameters(base::TimeTicks timebase, |
53 base::TimeDelta interval); | 58 base::TimeDelta interval); |
54 | 59 |
| 60 void set_observer(Observer* observer) { observer_ = observer; } |
| 61 |
55 private: | 62 private: |
56 void BindToRequest(mojo::InterfaceRequest<CommandBuffer> request); | 63 void BindToRequest(mojo::InterfaceRequest<CommandBuffer> request); |
57 | 64 |
58 scoped_refptr<gpu::SyncPointManager> sync_point_manager_; | 65 scoped_refptr<gpu::SyncPointManager> sync_point_manager_; |
59 scoped_refptr<base::SingleThreadTaskRunner> driver_task_runner_; | 66 scoped_refptr<base::SingleThreadTaskRunner> driver_task_runner_; |
60 scoped_ptr<CommandBufferDriver> driver_; | 67 scoped_ptr<CommandBufferDriver> driver_; |
61 mojo::CommandBufferSyncPointClientPtr sync_point_client_; | 68 mojo::CommandBufferSyncPointClientPtr sync_point_client_; |
62 mojo::ViewportParameterListenerPtr viewport_parameter_listener_; | 69 mojo::ViewportParameterListenerPtr viewport_parameter_listener_; |
63 mojo::StrongBinding<CommandBuffer> binding_; | 70 mojo::StrongBinding<CommandBuffer> binding_; |
| 71 Observer* observer_; |
64 | 72 |
65 base::WeakPtrFactory<CommandBufferImpl> weak_factory_; | 73 base::WeakPtrFactory<CommandBufferImpl> weak_factory_; |
66 DISALLOW_COPY_AND_ASSIGN(CommandBufferImpl); | 74 DISALLOW_COPY_AND_ASSIGN(CommandBufferImpl); |
67 }; | 75 }; |
68 | 76 |
69 } // namespace gles2 | 77 } // namespace gles2 |
70 | 78 |
71 #endif // SERVICES_GLES2_COMMAND_BUFFER_IMPL_H_ | 79 #endif // SERVICES_GLES2_COMMAND_BUFFER_IMPL_H_ |
OLD | NEW |