OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef SERVICES_UI_GLES2_COMMAND_BUFFER_DRIVER_H_ |
| 6 #define SERVICES_UI_GLES2_COMMAND_BUFFER_DRIVER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/threading/non_thread_safe.h" |
| 17 #include "base/time/time.h" |
| 18 #include "gpu/command_buffer/common/capabilities.h" |
| 19 #include "gpu/command_buffer/common/command_buffer.h" |
| 20 #include "gpu/command_buffer/common/command_buffer_id.h" |
| 21 #include "gpu/command_buffer/common/constants.h" |
| 22 #include "mojo/public/cpp/bindings/array.h" |
| 23 #include "mojo/public/cpp/system/buffer.h" |
| 24 #include "ui/gfx/buffer_types.h" |
| 25 #include "ui/gfx/geometry/mojo/geometry.mojom.h" |
| 26 #include "ui/gfx/geometry/size.h" |
| 27 #include "ui/gfx/native_widget_types.h" |
| 28 #include "ui/gfx/swap_result.h" |
| 29 |
| 30 namespace gl { |
| 31 class GLContext; |
| 32 class GLSurface; |
| 33 } |
| 34 |
| 35 namespace gpu { |
| 36 class CommandBufferService; |
| 37 class CommandExecutor; |
| 38 class SyncPointClient; |
| 39 class SyncPointOrderData; |
| 40 |
| 41 namespace gles2 { |
| 42 class GLES2Decoder; |
| 43 } // namespace gles2 |
| 44 |
| 45 } // namespace gpu |
| 46 |
| 47 namespace ui { |
| 48 class NativePixmap; |
| 49 } |
| 50 |
| 51 namespace ui { |
| 52 |
| 53 class GpuState; |
| 54 |
| 55 // This class receives CommandBuffer messages on the same thread as the native |
| 56 // viewport. |
| 57 class CommandBufferDriver : base::NonThreadSafe { |
| 58 public: |
| 59 class Client { |
| 60 public: |
| 61 virtual ~Client(); |
| 62 virtual void DidLoseContext(uint32_t reason) = 0; |
| 63 virtual void UpdateVSyncParameters(const base::TimeTicks& timebase, |
| 64 const base::TimeDelta& interval) = 0; |
| 65 virtual void OnGpuCompletedSwapBuffers(gfx::SwapResult result) = 0; |
| 66 }; |
| 67 CommandBufferDriver(gpu::CommandBufferNamespace command_buffer_namespace, |
| 68 gpu::CommandBufferId command_buffer_id, |
| 69 gfx::AcceleratedWidget widget, |
| 70 scoped_refptr<GpuState> gpu_state); |
| 71 ~CommandBufferDriver(); |
| 72 |
| 73 // The class owning the CommandBufferDriver instance (e.g. CommandBufferLocal) |
| 74 // is itself the Client implementation so CommandBufferDriver does not own the |
| 75 // client. |
| 76 void set_client(Client* client) { client_ = client; } |
| 77 |
| 78 bool Initialize(mojo::ScopedSharedBufferHandle shared_state, |
| 79 mojo::Array<int32_t> attribs); |
| 80 void SetGetBuffer(int32_t buffer); |
| 81 void Flush(int32_t put_offset); |
| 82 void RegisterTransferBuffer(int32_t id, |
| 83 mojo::ScopedSharedBufferHandle transfer_buffer, |
| 84 uint32_t size); |
| 85 void DestroyTransferBuffer(int32_t id); |
| 86 void CreateImage(int32_t id, |
| 87 mojo::ScopedHandle memory_handle, |
| 88 int32_t type, |
| 89 const gfx::Size& size, |
| 90 int32_t format, |
| 91 int32_t internal_format); |
| 92 void CreateImageNativeOzone(int32_t id, |
| 93 int32_t type, |
| 94 gfx::Size size, |
| 95 gfx::BufferFormat format, |
| 96 uint32_t internal_format, |
| 97 ui::NativePixmap* pixmap); |
| 98 void DestroyImage(int32_t id); |
| 99 bool IsScheduled() const; |
| 100 bool HasUnprocessedCommands() const; |
| 101 gpu::Capabilities GetCapabilities() const; |
| 102 gpu::CommandBuffer::State GetLastState() const; |
| 103 gpu::CommandBufferNamespace GetNamespaceID() const { |
| 104 return command_buffer_namespace_; |
| 105 } |
| 106 gpu::CommandBufferId GetCommandBufferID() const { return command_buffer_id_; } |
| 107 gpu::SyncPointOrderData* sync_point_order_data() { |
| 108 return sync_point_order_data_.get(); |
| 109 } |
| 110 uint32_t GetUnprocessedOrderNum() const; |
| 111 uint32_t GetProcessedOrderNum() const; |
| 112 void SignalQuery(uint32_t query_id, const base::Closure& callback); |
| 113 |
| 114 private: |
| 115 bool MakeCurrent(); |
| 116 |
| 117 // Process pending queries and call |ScheduleDelayedWork| to schedule |
| 118 // processing of delayed work. |
| 119 void ProcessPendingAndIdleWork(); |
| 120 |
| 121 // Schedule processing of delayed work. This updates the time at which |
| 122 // delayed work should be processed. |process_delayed_work_time_| is |
| 123 // updated to current time + delay. Call this after processing some amount |
| 124 // of delayed work. |
| 125 void ScheduleDelayedWork(base::TimeDelta delay); |
| 126 |
| 127 // Poll the command buffer to execute work. |
| 128 void PollWork(); |
| 129 void PerformWork(); |
| 130 |
| 131 void DestroyDecoder(); |
| 132 |
| 133 // Callbacks: |
| 134 void OnUpdateVSyncParameters(const base::TimeTicks timebase, |
| 135 const base::TimeDelta interval); |
| 136 void OnFenceSyncRelease(uint64_t release); |
| 137 bool OnWaitFenceSync(gpu::CommandBufferNamespace namespace_id, |
| 138 gpu::CommandBufferId command_buffer_id, |
| 139 uint64_t release); |
| 140 void OnDescheduleUntilFinished(); |
| 141 void OnRescheduleAfterFinished(); |
| 142 void OnParseError(); |
| 143 void OnContextLost(uint32_t reason); |
| 144 void OnGpuCompletedSwapBuffers(gfx::SwapResult result); |
| 145 |
| 146 const gpu::CommandBufferNamespace command_buffer_namespace_; |
| 147 const gpu::CommandBufferId command_buffer_id_; |
| 148 gfx::AcceleratedWidget widget_; |
| 149 Client* client_; // NOT OWNED. |
| 150 std::unique_ptr<gpu::CommandBufferService> command_buffer_; |
| 151 std::unique_ptr<gpu::gles2::GLES2Decoder> decoder_; |
| 152 std::unique_ptr<gpu::CommandExecutor> executor_; |
| 153 scoped_refptr<gpu::SyncPointOrderData> sync_point_order_data_; |
| 154 std::unique_ptr<gpu::SyncPointClient> sync_point_client_; |
| 155 scoped_refptr<gl::GLContext> context_; |
| 156 scoped_refptr<gl::GLSurface> surface_; |
| 157 scoped_refptr<GpuState> gpu_state_; |
| 158 |
| 159 scoped_refptr<base::SingleThreadTaskRunner> context_lost_task_runner_; |
| 160 base::Callback<void(int32_t)> context_lost_callback_; |
| 161 |
| 162 base::TimeTicks process_delayed_work_time_; |
| 163 uint32_t previous_processed_num_; |
| 164 base::TimeTicks last_idle_time_; |
| 165 |
| 166 base::WeakPtrFactory<CommandBufferDriver> weak_factory_; |
| 167 |
| 168 DISALLOW_COPY_AND_ASSIGN(CommandBufferDriver); |
| 169 }; |
| 170 |
| 171 } // namespace ui |
| 172 |
| 173 #endif // COMPONENTS_GLES2_COMMAND_BUFFER_DRIVER_H_ |
OLD | NEW |