| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_SURFACES_DISPLAY_COMPOSITOR_H_ | 5 #ifndef SERVICES_UI_SURFACES_DISPLAY_COMPOSITOR_H_ |
| 6 #define SERVICES_UI_SURFACES_DISPLAY_COMPOSITOR_H_ | 6 #define SERVICES_UI_SURFACES_DISPLAY_COMPOSITOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <unordered_map> | 11 #include <unordered_map> |
| 12 #include <vector> | |
| 13 | 12 |
| 14 #include "base/macros.h" | 13 #include "base/macros.h" |
| 15 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 16 #include "cc/ipc/display_compositor.mojom.h" | 15 #include "cc/ipc/display_compositor.mojom.h" |
| 17 #include "cc/surfaces/frame_sink_id.h" | 16 #include "cc/surfaces/frame_sink_id.h" |
| 18 #include "cc/surfaces/local_surface_id.h" | |
| 19 #include "cc/surfaces/surface_id.h" | |
| 20 #include "cc/surfaces/surface_manager.h" | 17 #include "cc/surfaces/surface_manager.h" |
| 21 #include "cc/surfaces/surface_observer.h" | 18 #include "cc/surfaces/surface_observer.h" |
| 22 #include "components/display_compositor/gpu_compositor_frame_sink_delegate.h" | 19 #include "components/display_compositor/gpu_compositor_frame_sink_delegate.h" |
| 23 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | |
| 24 #include "gpu/ipc/common/surface_handle.h" | 20 #include "gpu/ipc/common/surface_handle.h" |
| 25 #include "gpu/ipc/in_process_command_buffer.h" | |
| 26 #include "ipc/ipc_channel_handle.h" | |
| 27 #include "mojo/public/cpp/bindings/binding.h" | 21 #include "mojo/public/cpp/bindings/binding.h" |
| 28 | 22 |
| 29 namespace gpu { | 23 namespace ui { |
| 30 class GpuMemoryBufferManager; | |
| 31 class ImageFactory; | |
| 32 } | |
| 33 | 24 |
| 34 namespace cc { | 25 class DisplayProvider; |
| 35 class Display; | |
| 36 class SyntheticBeginFrameSource; | |
| 37 } | |
| 38 | |
| 39 namespace display_compositor { | |
| 40 class GpuCompositorFrameSink; | |
| 41 } | |
| 42 | |
| 43 namespace ui { | |
| 44 | 26 |
| 45 // The DisplayCompositor object is an object global to the Window Server app | 27 // The DisplayCompositor object is an object global to the Window Server app |
| 46 // that holds the SurfaceServer and allocates new Surfaces namespaces. | 28 // that holds the SurfaceServer and allocates new Surfaces namespaces. |
| 47 // This object lives on the main thread of the Window Server. | 29 // This object lives on the main thread of the Window Server. |
| 48 // TODO(rjkroege, fsamuel): This object will need to change to support multiple | 30 // TODO(rjkroege, fsamuel): This object will need to change to support multiple |
| 49 // displays. | 31 // displays. |
| 50 class DisplayCompositor | 32 class DisplayCompositor |
| 51 : public cc::SurfaceObserver, | 33 : public cc::SurfaceObserver, |
| 52 public display_compositor::GpuCompositorFrameSinkDelegate, | 34 public display_compositor::GpuCompositorFrameSinkDelegate, |
| 53 public cc::mojom::DisplayCompositor { | 35 public cc::mojom::DisplayCompositor { |
| 54 public: | 36 public: |
| 55 DisplayCompositor( | 37 DisplayCompositor(DisplayProvider* display_provider, |
| 56 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, | 38 cc::mojom::DisplayCompositorRequest request, |
| 57 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager, | 39 cc::mojom::DisplayCompositorClientPtr client); |
| 58 gpu::ImageFactory* image_factory, | |
| 59 cc::mojom::DisplayCompositorRequest request, | |
| 60 cc::mojom::DisplayCompositorClientPtr client); | |
| 61 ~DisplayCompositor() override; | 40 ~DisplayCompositor() override; |
| 62 | 41 |
| 63 cc::SurfaceManager* manager() { return &manager_; } | 42 cc::SurfaceManager* manager() { return &manager_; } |
| 64 | 43 |
| 65 // cc::mojom::DisplayCompositor implementation: | 44 // cc::mojom::DisplayCompositor implementation: |
| 66 void CreateRootCompositorFrameSink( | 45 void CreateRootCompositorFrameSink( |
| 67 const cc::FrameSinkId& frame_sink_id, | 46 const cc::FrameSinkId& frame_sink_id, |
| 68 gpu::SurfaceHandle surface_handle, | 47 gpu::SurfaceHandle surface_handle, |
| 69 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, | 48 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, |
| 70 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 49 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 71 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 50 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 72 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) | 51 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) |
| 73 override; | 52 override; |
| 74 void CreateCompositorFrameSink( | 53 void CreateCompositorFrameSink( |
| 75 const cc::FrameSinkId& frame_sink_id, | 54 const cc::FrameSinkId& frame_sink_id, |
| 76 cc::mojom::MojoCompositorFrameSinkRequest request, | 55 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 77 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, | 56 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 78 cc::mojom::MojoCompositorFrameSinkClientPtr client) override; | 57 cc::mojom::MojoCompositorFrameSinkClientPtr client) override; |
| 79 void RegisterFrameSinkHierarchy( | 58 void RegisterFrameSinkHierarchy( |
| 80 const cc::FrameSinkId& parent_frame_sink_id, | 59 const cc::FrameSinkId& parent_frame_sink_id, |
| 81 const cc::FrameSinkId& child_frame_sink_id) override; | 60 const cc::FrameSinkId& child_frame_sink_id) override; |
| 82 void UnregisterFrameSinkHierarchy( | 61 void UnregisterFrameSinkHierarchy( |
| 83 const cc::FrameSinkId& parent_frame_sink_id, | 62 const cc::FrameSinkId& parent_frame_sink_id, |
| 84 const cc::FrameSinkId& child_frame_sink_id) override; | 63 const cc::FrameSinkId& child_frame_sink_id) override; |
| 85 void DropTemporaryReference(const cc::SurfaceId& surface_id) override; | 64 void DropTemporaryReference(const cc::SurfaceId& surface_id) override; |
| 86 | 65 |
| 87 private: | 66 private: |
| 88 std::unique_ptr<cc::Display> CreateDisplay( | |
| 89 const cc::FrameSinkId& frame_sink_id, | |
| 90 gpu::SurfaceHandle surface_handle, | |
| 91 cc::SyntheticBeginFrameSource* begin_frame_source); | |
| 92 | |
| 93 // It is necessary to pass |frame_sink_id| by value because the id | 67 // It is necessary to pass |frame_sink_id| by value because the id |
| 94 // is owned by the GpuCompositorFrameSink in the map. When the sink is | 68 // is owned by the GpuCompositorFrameSink in the map. When the sink is |
| 95 // removed from the map, |frame_sink_id| would also be destroyed if it were a | 69 // removed from the map, |frame_sink_id| would also be destroyed if it were a |
| 96 // reference. But the map can continue to iterate and try to use it. Passing | 70 // reference. But the map can continue to iterate and try to use it. Passing |
| 97 // by value avoids this. | 71 // by value avoids this. |
| 98 void DestroyCompositorFrameSink(cc::FrameSinkId frame_sink_id); | 72 void DestroyCompositorFrameSink(cc::FrameSinkId frame_sink_id); |
| 99 | 73 |
| 100 // cc::SurfaceObserver implementation. | 74 // cc::SurfaceObserver implementation. |
| 101 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override; | 75 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override; |
| 102 void OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 76 void OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 103 bool* changed) override; | 77 bool* changed) override; |
| 104 | 78 |
| 105 // display_compositor::GpuCompositorFrameSinkDelegate implementation. | 79 // display_compositor::GpuCompositorFrameSinkDelegate implementation. |
| 106 void OnClientConnectionLost(const cc::FrameSinkId& frame_sink_id, | 80 void OnClientConnectionLost(const cc::FrameSinkId& frame_sink_id, |
| 107 bool destroy_compositor_frame_sink) override; | 81 bool destroy_compositor_frame_sink) override; |
| 108 void OnPrivateConnectionLost(const cc::FrameSinkId& frame_sink_id, | 82 void OnPrivateConnectionLost(const cc::FrameSinkId& frame_sink_id, |
| 109 bool destroy_compositor_frame_sink) override; | 83 bool destroy_compositor_frame_sink) override; |
| 110 | 84 |
| 111 // SurfaceManager should be the first object constructed and the last object | 85 // SurfaceManager should be the first object constructed and the last object |
| 112 // destroyed in order to ensure that all other objects that depend on it have | 86 // destroyed in order to ensure that all other objects that depend on it have |
| 113 // access to a valid pointer for the entirety of their liftimes. | 87 // access to a valid pointer for the entirety of their liftimes. |
| 114 cc::SurfaceManager manager_; | 88 cc::SurfaceManager manager_; |
| 115 | 89 |
| 116 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service_; | 90 // Provides a cc::Display for CreateRootCompositorFrameSink(). |
| 117 std::unique_ptr<gpu::GpuMemoryBufferManager> gpu_memory_buffer_manager_; | 91 DisplayProvider* const display_provider_; |
| 118 gpu::ImageFactory* image_factory_; | |
| 119 | 92 |
| 120 std::unordered_map<cc::FrameSinkId, | 93 std::unordered_map<cc::FrameSinkId, |
| 121 std::unique_ptr<cc::mojom::MojoCompositorFrameSink>, | 94 std::unique_ptr<cc::mojom::MojoCompositorFrameSink>, |
| 122 cc::FrameSinkIdHash> | 95 cc::FrameSinkIdHash> |
| 123 compositor_frame_sinks_; | 96 compositor_frame_sinks_; |
| 124 | 97 |
| 125 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 126 | |
| 127 base::ThreadChecker thread_checker_; | 98 base::ThreadChecker thread_checker_; |
| 128 | 99 |
| 129 cc::mojom::DisplayCompositorClientPtr client_; | 100 cc::mojom::DisplayCompositorClientPtr client_; |
| 130 mojo::Binding<cc::mojom::DisplayCompositor> binding_; | 101 mojo::Binding<cc::mojom::DisplayCompositor> binding_; |
| 131 | 102 |
| 132 DISALLOW_COPY_AND_ASSIGN(DisplayCompositor); | 103 DISALLOW_COPY_AND_ASSIGN(DisplayCompositor); |
| 133 }; | 104 }; |
| 134 | 105 |
| 135 } // namespace ui | 106 } // namespace ui |
| 136 | 107 |
| 137 #endif // SERVICES_UI_SURFACES_DISPLAY_COMPOSITOR_H_ | 108 #endif // SERVICES_UI_SURFACES_DISPLAY_COMPOSITOR_H_ |
| OLD | NEW |