| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_MUS_COMMON_GPU_SERVICE_H_ | 5 #ifndef COMPONENTS_MUS_COMMON_GPU_SERVICE_H_ |
| 6 #define COMPONENTS_MUS_COMMON_GPU_SERVICE_H_ | 6 #define COMPONENTS_MUS_COMMON_GPU_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h" |
| 15 #include "components/mus/common/mus_common_export.h" | 16 #include "components/mus/common/mus_common_export.h" |
| 17 #include "components/mus/public/interfaces/gpu_service.mojom.h" |
| 16 #include "gpu/ipc/client/gpu_channel_host.h" | 18 #include "gpu/ipc/client/gpu_channel_host.h" |
| 17 | 19 |
| 18 namespace shell { | 20 namespace shell { |
| 19 class Connector; | 21 class Connector; |
| 20 } | 22 } |
| 21 | 23 |
| 22 namespace mus { | 24 namespace mus { |
| 23 | 25 |
| 24 class MojoGpuMemoryBufferManager; | |
| 25 | |
| 26 class MUS_COMMON_EXPORT GpuService : public gpu::GpuChannelHostFactory { | 26 class MUS_COMMON_EXPORT GpuService : public gpu::GpuChannelHostFactory { |
| 27 public: | 27 public: |
| 28 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannel( | 28 void EstablishGpuChannel(shell::Connector* connector, |
| 29 const base::Closure& callback); |
| 30 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync( |
| 29 shell::Connector* connector); | 31 shell::Connector* connector); |
| 32 scoped_refptr<gpu::GpuChannelHost> GetGpuChannel(); |
| 33 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { |
| 34 return gpu_memory_buffer_manager_.get(); |
| 35 } |
| 30 | 36 |
| 31 static bool UseChromeGpuCommandBuffer(); | 37 static bool UseChromeGpuCommandBuffer(); |
| 32 static GpuService* GetInstance(); | 38 static GpuService* GetInstance(); |
| 33 | 39 |
| 34 private: | 40 private: |
| 35 friend struct base::DefaultSingletonTraits<GpuService>; | 41 friend struct base::DefaultSingletonTraits<GpuService>; |
| 36 | 42 |
| 37 GpuService(); | 43 GpuService(); |
| 38 ~GpuService() override; | 44 ~GpuService() override; |
| 39 | 45 |
| 46 scoped_refptr<gpu::GpuChannelHost> GetGpuChannelLocked(); |
| 47 void EstablishGpuChannelDone(bool locked, |
| 48 int client_id, |
| 49 mojom::ChannelHandlePtr channel_handle, |
| 50 mojom::GpuInfoPtr gpu_info); |
| 51 |
| 40 // gpu::GpuChannelHostFactory overrides: | 52 // gpu::GpuChannelHostFactory overrides: |
| 41 bool IsMainThread() override; | 53 bool IsMainThread() override; |
| 42 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; | 54 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; |
| 43 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( | 55 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( |
| 44 size_t size) override; | 56 size_t size) override; |
| 45 | 57 |
| 46 base::MessageLoop* main_message_loop_; | 58 base::MessageLoop* main_message_loop_; |
| 47 base::WaitableEvent shutdown_event_; | 59 base::WaitableEvent shutdown_event_; |
| 48 base::Thread io_thread_; | 60 base::Thread io_thread_; |
| 49 std::unique_ptr<MojoGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 61 std::unique_ptr<MojoGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
| 50 | 62 |
| 51 // Lock for |gpu_channel_|. | 63 // Lock for |gpu_channel_|, |establish_callbacks_| & |is_establishing_|. |
| 52 base::Lock lock_; | 64 base::Lock lock_; |
| 65 bool is_establishing_; |
| 53 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; | 66 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
| 67 using CallbackVector = std::vector< |
| 68 std::pair<scoped_refptr<base::SingleThreadTaskRunner>, base::Closure>>; |
| 69 CallbackVector establish_callbacks_; |
| 70 base::ConditionVariable establishing_condition_; |
| 54 | 71 |
| 55 DISALLOW_COPY_AND_ASSIGN(GpuService); | 72 DISALLOW_COPY_AND_ASSIGN(GpuService); |
| 56 }; | 73 }; |
| 57 | 74 |
| 58 } // namespace mus | 75 } // namespace mus |
| 59 | 76 |
| 60 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_GPU_SERVICE_CONNECTION_H_ | 77 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_GPU_SERVICE_CONNECTION_H_ |
| OLD | NEW |