| 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_FRAME_GENERATOR_H_ | 5 #ifndef SERVICES_UI_WS_FRAME_GENERATOR_H_ |
| 6 #define SERVICES_UI_WS_FRAME_GENERATOR_H_ | 6 #define SERVICES_UI_WS_FRAME_GENERATOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "cc/surfaces/frame_sink_id.h" | 13 #include "cc/surfaces/frame_sink_id.h" |
| 14 #include "cc/surfaces/local_frame_id.h" | 14 #include "cc/surfaces/surface_id.h" |
| 15 #include "cc/surfaces/surface_sequence.h" | |
| 16 #include "cc/surfaces/surface_sequence_generator.h" | |
| 17 #include "services/ui/public/interfaces/window_tree_constants.mojom.h" | 15 #include "services/ui/public/interfaces/window_tree_constants.mojom.h" |
| 18 #include "services/ui/ws/ids.h" | 16 #include "services/ui/ws/ids.h" |
| 19 #include "services/ui/ws/server_window_tracker.h" | 17 #include "services/ui/ws/server_window_tracker.h" |
| 20 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 21 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
| 22 | 20 |
| 23 namespace cc { | 21 namespace cc { |
| 24 class CompositorFrame; | 22 class CompositorFrame; |
| 25 class RenderPass; | 23 class RenderPass; |
| 26 class SurfaceId; | 24 class SurfaceId; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 49 public cc::mojom::MojoCompositorFrameSinkClient { | 47 public cc::mojom::MojoCompositorFrameSinkClient { |
| 50 public: | 48 public: |
| 51 FrameGenerator(FrameGeneratorDelegate* delegate, ServerWindow* root_window); | 49 FrameGenerator(FrameGeneratorDelegate* delegate, ServerWindow* root_window); |
| 52 ~FrameGenerator() override; | 50 ~FrameGenerator() override; |
| 53 | 51 |
| 54 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); | 52 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); |
| 55 | 53 |
| 56 // Schedules a redraw for the provided region. | 54 // Schedules a redraw for the provided region. |
| 57 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget); | 55 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget); |
| 58 | 56 |
| 57 // Adds a reference to new surface with |surface_id| for |window|. This |
| 58 // reference is to ensure the surface is not deleted while it's still being |
| 59 // displayed. The display root surface has a reference from the top level |
| 60 // root. All child surfaces are embedded by the display root and receive a |
| 61 // reference from it. |
| 62 // |
| 63 // If a new display root Surface is created, then all child surfaces will |
| 64 // receive a reference from the new display root so they are not deleted with |
| 65 // the old display root. |
| 66 // |
| 67 // If there is an existing reference to an old surface with the same |
| 68 // FrameSinkId then that reference will be removed after the next |
| 69 // CompositorFrame is submitted. |
| 70 void OnSurfaceCreated(const cc::SurfaceId& surface_id, ServerWindow* window); |
| 71 |
| 59 private: | 72 private: |
| 60 friend class ui::ws::test::FrameGeneratorTest; | 73 friend class ui::ws::test::FrameGeneratorTest; |
| 61 | 74 |
| 62 // cc::mojom::MojoCompositorFrameSinkClient implementation: | 75 // cc::mojom::MojoCompositorFrameSinkClient implementation: |
| 63 void DidReceiveCompositorFrameAck() override; | 76 void DidReceiveCompositorFrameAck() override; |
| 64 void OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) override; | 77 void OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) override; |
| 65 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; | 78 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; |
| 66 | 79 |
| 67 // Generates the CompositorFrame. | 80 // Generates the CompositorFrame. |
| 68 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect); | 81 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect); |
| 69 | 82 |
| 70 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad | 83 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad |
| 71 // for each that lacks one. | 84 // for each that lacks one. |
| 72 void DrawWindowTree(cc::RenderPass* pass, | 85 void DrawWindowTree(cc::RenderPass* pass, |
| 73 ServerWindow* window, | 86 ServerWindow* window, |
| 74 const gfx::Vector2d& parent_to_root_origin_offset, | 87 const gfx::Vector2d& parent_to_root_origin_offset, |
| 75 float opacity); | 88 float opacity); |
| 76 | 89 |
| 77 // Adds a reference to the current cc::Surface of the provided | 90 // Finds the parent surface id for |window|. |
| 78 // |window_compositor_frame_sink|. If an existing reference is held with a | 91 cc::SurfaceId FindParentSurfaceId(ServerWindow* window); |
| 79 // different LocalFrameId then release that reference first. This is called on | |
| 80 // each ServerWindowCompositorFrameSink as FrameGenerator walks the window | |
| 81 // tree to generate a CompositorFrame. This is done to make sure that the | |
| 82 // window surfaces are retained for the entirety of the time between | |
| 83 // submission of the top-level frame to drawing the frame to screen. | |
| 84 // TODO(fsamuel, kylechar): This will go away once we get surface lifetime | |
| 85 // management. | |
| 86 void AddOrUpdateSurfaceReference(mojom::CompositorFrameSinkType type, | |
| 87 ServerWindow* window); | |
| 88 | 92 |
| 89 // Releases any retained references for the provided FrameSink. | 93 // Adds surface reference to local cache and surface manager. |
| 90 // TODO(fsamuel, kylechar): This will go away once we get surface lifetime | 94 void AddSurfaceReference(const cc::SurfaceId& parent_id, |
| 91 // management. | 95 const cc::SurfaceId& child_id); |
| 92 void ReleaseFrameSinkReference(const cc::FrameSinkId& frame_sink_id); | |
| 93 | 96 |
| 94 // Releases all retained references to surfaces. | 97 // Does work necessary for adding the first surface reference. |
| 95 // TODO(fsamuel, kylechar): This will go away once we get surface lifetime | 98 void AddFirstReference(const cc::SurfaceId& surface_id, ServerWindow* window); |
| 96 // management. | 99 |
| 97 void ReleaseAllSurfaceReferences(); | 100 // Finds all Surfaces with references from |old_surface_id| and adds a new |
| 101 // reference from |new_surface_id|. The caller should remove any references |
| 102 // to |old_surface_id| afterwards to finish cleanup. |
| 103 void AddNewParentReferences(const cc::SurfaceId& old_surface_id, |
| 104 const cc::SurfaceId& new_surface_id); |
| 105 |
| 106 // Removes all references to surfaces in |dead_references_|. |
| 107 void RemoveDeadSurfaceReferences(); |
| 108 |
| 109 // Removes any retained references for the provided FrameSink. |
| 110 void RemoveFrameSinkReference(const cc::FrameSinkId& frame_sink_id); |
| 111 |
| 112 // Removes all retained references to surfaces. |
| 113 void RemoveAllSurfaceReferences(); |
| 98 | 114 |
| 99 ui::DisplayCompositor* GetDisplayCompositor(); | 115 ui::DisplayCompositor* GetDisplayCompositor(); |
| 100 | 116 |
| 101 // ServerWindowObserver implementation. | 117 // ServerWindowObserver implementation. |
| 102 void OnWindowDestroying(ServerWindow* window) override; | 118 void OnWindowDestroying(ServerWindow* window) override; |
| 103 | 119 |
| 104 FrameGeneratorDelegate* delegate_; | 120 FrameGeneratorDelegate* delegate_; |
| 105 cc::FrameSinkId frame_sink_id_; | |
| 106 ServerWindow* const root_window_; | 121 ServerWindow* const root_window_; |
| 107 cc::SurfaceSequenceGenerator surface_sequence_generator_; | |
| 108 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; | 122 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
| 109 | 123 |
| 110 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink_; | 124 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink_; |
| 111 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; | 125 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; |
| 112 | 126 |
| 113 struct SurfaceDependency { | 127 // Represents the top level root surface id that should reference the display |
| 114 cc::LocalFrameId local_frame_id; | 128 // root surface. We don't know the actual value, because it's generated in |
| 115 cc::SurfaceSequence sequence; | 129 // another process, this is used internally as a placeholder. |
| 130 const cc::SurfaceId top_level_root_surface_id_; |
| 131 |
| 132 struct SurfaceReference { |
| 133 cc::SurfaceId parent_id; |
| 134 cc::SurfaceId child_id; |
| 116 }; | 135 }; |
| 117 std::unordered_map<cc::FrameSinkId, SurfaceDependency, cc::FrameSinkIdHash> | 136 |
| 118 dependencies_; | 137 // Active references held by this client to surfaces that could be embedded in |
| 138 // a CompositorFrame submitted from FrameGenerator. |
| 139 std::unordered_map<cc::FrameSinkId, SurfaceReference, cc::FrameSinkIdHash> |
| 140 active_references_; |
| 141 |
| 142 // References to surfaces that should be removed after a CompositorFrame has |
| 143 // been submitted and the surfaces are not being used. |
| 144 std::vector<SurfaceReference> dead_references_; |
| 145 |
| 146 // If a CompositorFrame for a child surface is submitted before the first |
| 147 // display root CompositorFrame, we can't add a reference from the unknown |
| 148 // display root SurfaceId. Track the child SurfaceId here and add a reference |
| 149 // to it when the display root SurfaceId is available. |
| 150 std::vector<cc::SurfaceId> waiting_for_references_; |
| 119 | 151 |
| 120 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> binding_; | 152 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> binding_; |
| 121 | 153 |
| 122 base::WeakPtrFactory<FrameGenerator> weak_factory_; | 154 base::WeakPtrFactory<FrameGenerator> weak_factory_; |
| 123 | 155 |
| 124 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); | 156 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); |
| 125 }; | 157 }; |
| 126 | 158 |
| 127 } // namespace ws | 159 } // namespace ws |
| 128 | 160 |
| 129 } // namespace ui | 161 } // namespace ui |
| 130 | 162 |
| 131 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ | 163 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ |
| OLD | NEW |