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 SERVICES_UI_COMMON_GPU_SERVICE_H_ | 5 #ifndef SERVICES_UI_COMMON_GPU_SERVICE_H_ |
6 #define SERVICES_UI_COMMON_GPU_SERVICE_H_ | 6 #define SERVICES_UI_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/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "gpu/ipc/client/gpu_channel_host.h" | 17 #include "gpu/ipc/client/gpu_channel_host.h" |
18 #include "services/ui/common/mojo_gpu_memory_buffer_manager.h" | 18 #include "services/ui/common/mojo_gpu_memory_buffer_manager.h" |
19 #include "services/ui/common/mus_common_export.h" | 19 #include "services/ui/common/mus_common_export.h" |
20 #include "services/ui/public/interfaces/gpu_service.mojom.h" | 20 #include "services/ui/public/interfaces/gpu_service.mojom.h" |
21 | 21 |
22 namespace shell { | 22 namespace shell { |
23 class Connector; | 23 class Connector; |
24 } | 24 } |
25 | 25 |
26 namespace ui { | 26 namespace ui { |
27 | 27 |
28 class MUS_COMMON_EXPORT GpuService : public gpu::GpuChannelHostFactory { | 28 class MUS_COMMON_EXPORT GpuService : public gpu::GpuChannelHostFactory, |
| 29 public gpu::GpuChannelEstablishFactory { |
29 public: | 30 public: |
30 ~GpuService() override; | 31 ~GpuService() override; |
31 | 32 |
32 void EstablishGpuChannel(const base::Closure& callback); | |
33 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync(); | |
34 scoped_refptr<gpu::GpuChannelHost> GetGpuChannel(); | |
35 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { | 33 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { |
36 return gpu_memory_buffer_manager_.get(); | 34 return gpu_memory_buffer_manager_.get(); |
37 } | 35 } |
38 | 36 |
39 // The GpuService has to be initialized in the main thread before establishing | 37 // The GpuService has to be initialized in the main thread before establishing |
40 // the gpu channel. | 38 // the gpu channel. |
41 static std::unique_ptr<GpuService> Initialize(shell::Connector* connector); | 39 static std::unique_ptr<GpuService> Initialize(shell::Connector* connector); |
42 static GpuService* GetInstance(); | 40 static GpuService* GetInstance(); |
43 | 41 |
| 42 // gpu::GpuChannelEstablishFactory: |
| 43 void EstablishGpuChannel( |
| 44 const gpu::GpuChannelEstablishedCallback& callback) override; |
| 45 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSync() override; |
| 46 |
44 private: | 47 private: |
45 friend struct base::DefaultSingletonTraits<GpuService>; | 48 friend struct base::DefaultSingletonTraits<GpuService>; |
46 | 49 |
47 explicit GpuService(shell::Connector* connector); | 50 explicit GpuService(shell::Connector* connector); |
48 | 51 |
49 scoped_refptr<gpu::GpuChannelHost> GetGpuChannelLocked(); | 52 scoped_refptr<gpu::GpuChannelHost> GetGpuChannelLocked(); |
50 void EstablishGpuChannelOnMainThread(); | 53 void EstablishGpuChannelOnMainThread(); |
51 void EstablishGpuChannelOnMainThreadSyncLocked(); | 54 void EstablishGpuChannelOnMainThreadSyncLocked(); |
52 void EstablishGpuChannelOnMainThreadDone( | 55 void EstablishGpuChannelOnMainThreadDone( |
53 bool locked, | 56 bool locked, |
(...skipping 11 matching lines...) Expand all Loading... |
65 shell::Connector* connector_; | 68 shell::Connector* connector_; |
66 base::WaitableEvent shutdown_event_; | 69 base::WaitableEvent shutdown_event_; |
67 base::Thread io_thread_; | 70 base::Thread io_thread_; |
68 std::unique_ptr<MojoGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 71 std::unique_ptr<MojoGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
69 | 72 |
70 // Lock for |gpu_channel_|, |establish_callbacks_| & |is_establishing_|. | 73 // Lock for |gpu_channel_|, |establish_callbacks_| & |is_establishing_|. |
71 base::Lock lock_; | 74 base::Lock lock_; |
72 bool is_establishing_; | 75 bool is_establishing_; |
73 ui::mojom::GpuServicePtr gpu_service_; | 76 ui::mojom::GpuServicePtr gpu_service_; |
74 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; | 77 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
75 std::vector<base::Closure> establish_callbacks_; | 78 std::vector<gpu::GpuChannelEstablishedCallback> establish_callbacks_; |
76 base::ConditionVariable establishing_condition_; | 79 base::ConditionVariable establishing_condition_; |
77 | 80 |
78 DISALLOW_COPY_AND_ASSIGN(GpuService); | 81 DISALLOW_COPY_AND_ASSIGN(GpuService); |
79 }; | 82 }; |
80 | 83 |
81 } // namespace ui | 84 } // namespace ui |
82 | 85 |
83 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_GPU_SERVICE_CONNECTION_H_ | 86 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_GPU_SERVICE_CONNECTION_H_ |
OLD | NEW |