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