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_WS_GPU_HOST_H_ | 5 #ifndef SERVICES_UI_WS_GPU_HOST_H_ |
6 #define SERVICES_UI_WS_GPU_HOST_H_ | 6 #define SERVICES_UI_WS_GPU_HOST_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | |
8 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
9 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
11 #include "gpu/config/gpu_info.h" | 12 #include "gpu/config/gpu_info.h" |
12 #include "gpu/ipc/client/gpu_channel_host.h" | 13 #include "gpu/ipc/client/gpu_channel_host.h" |
13 #include "mojo/public/cpp/bindings/binding_set.h" | 14 #include "mojo/public/cpp/bindings/binding_set.h" |
14 #include "mojo/public/cpp/bindings/interface_request.h" | 15 #include "mojo/public/cpp/bindings/interface_request.h" |
16 #include "mojo/public/cpp/bindings/strong_binding_set.h" | |
15 #include "services/ui/gpu/gpu_main.h" | 17 #include "services/ui/gpu/gpu_main.h" |
16 #include "services/ui/gpu/interfaces/gpu_host.mojom.h" | 18 #include "services/ui/gpu/interfaces/gpu_host.mojom.h" |
17 #include "services/ui/gpu/interfaces/gpu_service.mojom.h" | 19 #include "services/ui/gpu/interfaces/gpu_service.mojom.h" |
18 #include "services/ui/public/interfaces/gpu.mojom.h" | 20 #include "services/ui/public/interfaces/gpu.mojom.h" |
19 | 21 |
20 namespace ui { | 22 namespace ui { |
21 | 23 |
22 class ServerGpuMemoryBufferManager; | 24 class ServerGpuMemoryBufferManager; |
23 | 25 |
24 namespace ws { | 26 namespace ws { |
25 | 27 |
28 namespace test { | |
29 class GpuHostTest; | |
30 } // namespace test | |
31 | |
26 class GpuHostDelegate; | 32 class GpuHostDelegate; |
27 | 33 |
28 // Sets up connection from clients to the real service implementation in the GPU | 34 // Sets up connection from clients to the real service implementation in the GPU |
29 // process. | 35 // process. |
30 class GpuHost : public mojom::GpuHost { | 36 class GpuHost : public mojom::GpuHost { |
31 public: | 37 public: |
32 explicit GpuHost(GpuHostDelegate* delegate); | 38 explicit GpuHost(GpuHostDelegate* delegate); |
33 ~GpuHost() override; | 39 ~GpuHost() override; |
34 | 40 |
35 void Add(mojom::GpuRequest request); | 41 void Add(mojom::GpuRequest request); |
36 | 42 |
37 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget); | 43 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget); |
38 void OnAcceleratedWidgetDestroyed(gfx::AcceleratedWidget widget); | 44 void OnAcceleratedWidgetDestroyed(gfx::AcceleratedWidget widget); |
39 | 45 |
40 // Requests a cc::mojom::DisplayCompositor interface from mus-gpu. | 46 // Requests a cc::mojom::DisplayCompositor interface from mus-gpu. |
41 void CreateDisplayCompositor(cc::mojom::DisplayCompositorRequest request, | 47 void CreateDisplayCompositor(cc::mojom::DisplayCompositorRequest request, |
42 cc::mojom::DisplayCompositorClientPtr client); | 48 cc::mojom::DisplayCompositorClientPtr client); |
43 | 49 |
44 private: | 50 private: |
51 friend class test::GpuHostTest; | |
52 | |
53 // The implementation that relays requests from clients to the real | |
54 // service implementation in the GPU process over mojom.GpuService. | |
55 class GpuClient : public base::SupportsWeakPtr<GpuClient>, public mojom::Gpu { | |
sadrul
2017/03/22 16:41:13
Use a WeakPtrFactory<> instead
jonross
2017/03/23 00:38:29
Done.
| |
56 public: | |
57 GpuClient(int client_id, | |
58 gpu::GPUInfo* gpu_info, | |
59 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager, | |
60 mojom::GpuService* gpu_service); | |
61 ~GpuClient() override; | |
62 | |
63 private: | |
64 friend class test::GpuHostTest; | |
65 void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback, | |
66 mojo::ScopedMessagePipeHandle channel_handle); | |
67 // mojom::Gpu overrides: | |
68 void EstablishGpuChannel( | |
69 const EstablishGpuChannelCallback& callback) override; | |
70 void CreateGpuMemoryBuffer( | |
71 gfx::GpuMemoryBufferId id, | |
72 const gfx::Size& size, | |
73 gfx::BufferFormat format, | |
74 gfx::BufferUsage usage, | |
75 const mojom::Gpu::CreateGpuMemoryBufferCallback& callback) override; | |
76 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | |
77 const gpu::SyncToken& sync_token) override; | |
78 | |
79 const int client_id_; | |
80 | |
81 // The objects these pointers refer to are owned by the GpuHost object. | |
82 const gpu::GPUInfo* gpu_info_; | |
83 ServerGpuMemoryBufferManager* gpu_memory_buffer_manager_; | |
84 mojom::GpuService* gpu_service_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(GpuClient); | |
sadrul
2017/03/22 16:41:13
Move this into a separate file.
jonross
2017/03/23 00:38:29
Done.
| |
87 }; | |
88 | |
89 mojom::Gpu* AddInternal(mojom::GpuRequest request); | |
45 void OnBadMessageFromGpu(); | 90 void OnBadMessageFromGpu(); |
46 | 91 |
47 // mojom::GpuHost: | 92 // mojom::GpuHost: |
48 void DidInitialize(const gpu::GPUInfo& gpu_info) override; | 93 void DidInitialize(const gpu::GPUInfo& gpu_info) override; |
49 void DidCreateOffscreenContext(const GURL& url) override; | 94 void DidCreateOffscreenContext(const GURL& url) override; |
50 void DidDestroyOffscreenContext(const GURL& url) override; | 95 void DidDestroyOffscreenContext(const GURL& url) override; |
51 void DidDestroyChannel(int32_t client_id) override; | 96 void DidDestroyChannel(int32_t client_id) override; |
52 void DidLoseContext(bool offscreen, | 97 void DidLoseContext(bool offscreen, |
53 gpu::error::ContextLostReason reason, | 98 gpu::error::ContextLostReason reason, |
54 const GURL& active_url) override; | 99 const GURL& active_url) override; |
(...skipping 10 matching lines...) Expand all Loading... | |
65 mojo::Binding<mojom::GpuHost> gpu_host_binding_; | 110 mojo::Binding<mojom::GpuHost> gpu_host_binding_; |
66 gpu::GPUInfo gpu_info_; | 111 gpu::GPUInfo gpu_info_; |
67 std::unique_ptr<ServerGpuMemoryBufferManager> gpu_memory_buffer_manager_; | 112 std::unique_ptr<ServerGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
68 | 113 |
69 mojom::GpuMainPtr gpu_main_; | 114 mojom::GpuMainPtr gpu_main_; |
70 | 115 |
71 // TODO(fsamuel): GpuHost should not be holding onto |gpu_main_impl| | 116 // TODO(fsamuel): GpuHost should not be holding onto |gpu_main_impl| |
72 // because that will live in another process soon. | 117 // because that will live in another process soon. |
73 std::unique_ptr<GpuMain> gpu_main_impl_; | 118 std::unique_ptr<GpuMain> gpu_main_impl_; |
74 | 119 |
120 mojo::StrongBindingSet<mojom::Gpu> gpu_bindings_; | |
121 | |
75 DISALLOW_COPY_AND_ASSIGN(GpuHost); | 122 DISALLOW_COPY_AND_ASSIGN(GpuHost); |
76 }; | 123 }; |
77 | 124 |
78 } // namespace ws | 125 } // namespace ws |
79 } // namespace ui | 126 } // namespace ui |
80 | 127 |
81 #endif // SERVICES_UI_WS_GPU_HOST_H_ | 128 #endif // SERVICES_UI_WS_GPU_HOST_H_ |
OLD | NEW |