OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 COMPONENTS_DISPLAY_COMPOSITOR_DISPLAY_COMPOSITOR_H_ |
| 6 #define COMPONENTS_DISPLAY_COMPOSITOR_DISPLAY_COMPOSITOR_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <unordered_map> |
| 12 |
| 13 #include "base/macros.h" |
| 14 #include "base/threading/thread_checker.h" |
| 15 #include "cc/ipc/display_compositor.mojom.h" |
| 16 #include "cc/surfaces/frame_sink_id.h" |
| 17 #include "cc/surfaces/local_surface_id.h" |
| 18 #include "cc/surfaces/surface_id.h" |
| 19 #include "cc/surfaces/surface_manager.h" |
| 20 #include "cc/surfaces/surface_observer.h" |
| 21 #include "components/display_compositor/display_compositor_export.h" |
| 22 #include "components/display_compositor/gpu_compositor_frame_sink_delegate.h" |
| 23 #include "mojo/public/cpp/bindings/binding.h" |
| 24 |
| 25 namespace display_compositor { |
| 26 |
| 27 class GpuCompositorFrameSink; |
| 28 |
| 29 // The DisplayCompositor object is an object global to the Window Server app |
| 30 // that holds the SurfaceServer and allocates new Surfaces namespaces. |
| 31 // This object lives on the main thread of the Window Server. |
| 32 // TODO(rjkroege, fsamuel): This object will need to change to support multiple |
| 33 // displays. |
| 34 class DISPLAY_COMPOSITOR_EXPORT DisplayCompositor |
| 35 : public cc::SurfaceObserver, |
| 36 public GpuCompositorFrameSinkDelegate, |
| 37 public cc::mojom::DisplayCompositor { |
| 38 public: |
| 39 DisplayCompositor(); |
| 40 DisplayCompositor(cc::mojom::DisplayCompositorRequest request, |
| 41 cc::mojom::DisplayCompositorClientPtr client); |
| 42 ~DisplayCompositor() override; |
| 43 |
| 44 void Bind(cc::mojom::DisplayCompositorRequest request, |
| 45 cc::mojom::DisplayCompositorClientPtr client); |
| 46 |
| 47 cc::SurfaceManager* surface_manager() { return &surface_manager_; } |
| 48 |
| 49 // GpuCompositorFrameSinkDelegate implementation. |
| 50 void OnClientConnectionLost(const cc::FrameSinkId& frame_sink_id, |
| 51 bool destroy_compositor_frame_sink) override; |
| 52 void OnPrivateConnectionLost(const cc::FrameSinkId& frame_sink_id, |
| 53 bool destroy_compositor_frame_sink) override; |
| 54 |
| 55 // cc::mojom::DisplayCompositor implementation: |
| 56 void CreateDisplayCompositorFrameSink( |
| 57 const cc::FrameSinkId& frame_sink_id, |
| 58 gpu::SurfaceHandle surface_handle, |
| 59 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request, |
| 60 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 61 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
| 62 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) |
| 63 override; |
| 64 void CreateOffscreenCompositorFrameSink( |
| 65 const cc::FrameSinkId& frame_sink_id, |
| 66 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 67 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 68 cc::mojom::MojoCompositorFrameSinkClientPtr client) override; |
| 69 |
| 70 private: |
| 71 // It is necessary to pass |frame_sink_id| by value because the id |
| 72 // is owned by the GpuCompositorFrameSink in the map. When the sink is |
| 73 // removed from the map, |frame_sink_id| would also be destroyed if it were a |
| 74 // reference. But the map can continue to iterate and try to use it. Passing |
| 75 // by value avoids this. |
| 76 void DestroyCompositorFrameSink(cc::FrameSinkId frame_sink_id); |
| 77 |
| 78 // cc::SurfaceObserver implementation. |
| 79 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override; |
| 80 void OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
| 81 bool* changed) override; |
| 82 |
| 83 // SurfaceManager should be the first object constructed and the last object |
| 84 // destroyed in order to ensure that all other objects that depend on it have |
| 85 // access to a valid pointer for the entirety of their liftimes. |
| 86 cc::SurfaceManager surface_manager_; |
| 87 |
| 88 std::unordered_map<cc::FrameSinkId, |
| 89 std::unique_ptr<GpuCompositorFrameSink>, |
| 90 cc::FrameSinkIdHash> |
| 91 compositor_frame_sinks_; |
| 92 |
| 93 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 94 |
| 95 base::ThreadChecker thread_checker_; |
| 96 |
| 97 cc::mojom::DisplayCompositorClientPtr client_; |
| 98 mojo::Binding<cc::mojom::DisplayCompositor> binding_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(DisplayCompositor); |
| 101 }; |
| 102 |
| 103 } // namespace display_compositor |
| 104 |
| 105 #endif // COMPONENTS_DISPLAY_COMPOSITOR_DISPLAY_COMPOSITOR_H_ |
OLD | NEW |