OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SERVICES_UI_GPU_GPU_SERVICE_MUS_H_ | |
6 #define SERVICES_UI_GPU_GPU_SERVICE_MUS_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/synchronization/waitable_event.h" | |
10 #include "base/threading/non_thread_safe.h" | |
11 #include "base/threading/thread.h" | |
12 #include "build/build_config.h" | |
13 #include "gpu/command_buffer/service/gpu_preferences.h" | |
14 #include "gpu/config/gpu_info.h" | |
15 #include "gpu/ipc/client/gpu_channel_host.h" | |
16 #include "gpu/ipc/common/surface_handle.h" | |
17 #include "gpu/ipc/service/gpu_channel.h" | |
18 #include "gpu/ipc/service/gpu_channel_manager.h" | |
19 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" | |
20 #include "gpu/ipc/service/gpu_config.h" | |
21 #include "gpu/ipc/service/x_util.h" | |
22 #include "ui/gfx/native_widget_types.h" | |
23 | |
24 namespace base { | |
25 template <typename T> | |
26 struct DefaultSingletonTraits; | |
27 } | |
28 | |
29 namespace gpu { | |
30 class GpuChannelHost; | |
31 class GpuMemoryBufferFactory; | |
32 class SyncPointManager; | |
33 } | |
34 | |
35 namespace media { | |
36 class MediaService; | |
37 } | |
38 | |
39 namespace ui { | |
40 | |
41 class MusGpuMemoryBufferManager; | |
42 | |
43 // TODO(fsamuel): GpuServiceMus is intended to be the Gpu thread within Mus. | |
44 // Similar to GpuChildThread, it is a GpuChannelManagerDelegate and will have a | |
45 // GpuChannelManager. | |
46 class GpuServiceMus : public gpu::GpuChannelManagerDelegate, | |
47 public gpu::GpuChannelHostFactory, | |
48 public base::NonThreadSafe { | |
49 public: | |
50 typedef base::Callback<void(int client_id, mojo::ScopedMessagePipeHandle)> | |
51 EstablishGpuChannelCallback; | |
52 void EstablishGpuChannel(uint64_t client_tracing_id, | |
53 bool preempts, | |
54 bool allow_view_command_buffers, | |
55 bool allow_real_time_streams, | |
56 const EstablishGpuChannelCallback& callback); | |
57 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer( | |
58 gfx::GpuMemoryBufferId id, | |
59 const gfx::Size& size, | |
60 gfx::BufferFormat format, | |
61 gfx::BufferUsage usage, | |
62 int client_id, | |
63 gpu::SurfaceHandle surface_handle); | |
64 gfx::GpuMemoryBufferHandle CreateGpuMemoryBufferFromeHandle( | |
65 gfx::GpuMemoryBufferHandle buffer_handle, | |
66 gfx::GpuMemoryBufferId id, | |
67 const gfx::Size& size, | |
68 gfx::BufferFormat format, | |
69 int client_id); | |
70 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | |
71 int client_id, | |
72 const gpu::SyncToken& sync_token); | |
73 | |
74 gpu::GpuChannelManager* gpu_channel_manager() const { | |
75 return gpu_channel_manager_.get(); | |
76 } | |
77 | |
78 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory() const { | |
79 return gpu_memory_buffer_factory_.get(); | |
80 } | |
81 | |
82 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local() const { | |
83 return gpu_channel_local_; | |
84 } | |
85 | |
86 const gpu::GPUInfo& gpu_info() const { return gpu_info_; } | |
87 | |
88 // GpuChannelManagerDelegate overrides: | |
89 void DidCreateOffscreenContext(const GURL& active_url) override; | |
90 void DidDestroyChannel(int client_id) override; | |
91 void DidDestroyOffscreenContext(const GURL& active_url) override; | |
92 void DidLoseContext(bool offscreen, | |
93 gpu::error::ContextLostReason reason, | |
94 const GURL& active_url) override; | |
95 void GpuMemoryUmaStats(const gpu::GPUMemoryUmaStats& params) override; | |
96 void StoreShaderToDisk(int client_id, | |
97 const std::string& key, | |
98 const std::string& shader) override; | |
99 #if defined(OS_WIN) | |
100 void SendAcceleratedSurfaceCreatedChildWindow( | |
101 gpu::SurfaceHandle parent_window, | |
102 gpu::SurfaceHandle child_window) override; | |
103 #endif | |
104 void SetActiveURL(const GURL& url) override; | |
105 | |
106 // GpuChannelHostFactory overrides: | |
107 bool IsMainThread() override; | |
108 scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; | |
109 std::unique_ptr<base::SharedMemory> AllocateSharedMemory( | |
110 size_t size) override; | |
111 | |
112 static GpuServiceMus* GetInstance(); | |
113 | |
114 private: | |
115 friend struct base::DefaultSingletonTraits<GpuServiceMus>; | |
116 | |
117 GpuServiceMus(); | |
118 ~GpuServiceMus() override; | |
119 | |
120 void Initialize(); | |
121 void InitializeOnGpuThread(mojo::ScopedMessagePipeHandle* channel_handle, | |
122 base::WaitableEvent* event); | |
123 void EstablishGpuChannelOnGpuThread( | |
124 int client_id, | |
125 uint64_t client_tracing_id, | |
126 bool preempts, | |
127 bool allow_view_command_buffers, | |
128 bool allow_real_time_streams, | |
129 mojo::ScopedMessagePipeHandle* channel_handle); | |
130 | |
131 // The next client id. | |
132 int next_client_id_; | |
133 | |
134 // The main thread task runner. | |
135 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
136 | |
137 // An event that will be signalled when we shutdown. | |
138 base::WaitableEvent shutdown_event_; | |
139 | |
140 // The main thread for GpuService. | |
141 base::Thread gpu_thread_; | |
142 | |
143 // The thread that handles IO events for GpuService. | |
144 base::Thread io_thread_; | |
145 | |
146 std::unique_ptr<gpu::SyncPointManager> owned_sync_point_manager_; | |
147 | |
148 std::unique_ptr<gpu::GpuChannelManager> gpu_channel_manager_; | |
149 | |
150 std::unique_ptr<media::MediaService> media_service_; | |
151 | |
152 std::unique_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory_; | |
153 | |
154 // A GPU memory buffer manager used locally. | |
155 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager_local_; | |
156 | |
157 // A GPU channel used locally. | |
158 scoped_refptr<gpu::GpuChannelHost> gpu_channel_local_; | |
159 | |
160 gpu::GpuPreferences gpu_preferences_; | |
161 | |
162 // Information about the GPU, such as device and vendor ID. | |
163 gpu::GPUInfo gpu_info_; | |
164 | |
165 DISALLOW_COPY_AND_ASSIGN(GpuServiceMus); | |
166 }; | |
167 | |
168 } // namespace ui | |
169 | |
170 #endif // SERVICES_UI_GPU_GPU_SERVICE_MUS_H_ | |
OLD | NEW |