Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: services/ui/ws/frame_generator.h

Issue 2489003002: Convert mustash use surface references. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 the display root Surface is updated, 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 AddSurfaceReference(const cc::SurfaceId& surface_id,
71 ServerWindow* window);
72
59 private: 73 private:
60 friend class ui::ws::test::FrameGeneratorTest; 74 friend class ui::ws::test::FrameGeneratorTest;
61 75
62 // cc::mojom::MojoCompositorFrameSinkClient implementation: 76 // cc::mojom::MojoCompositorFrameSinkClient implementation:
63 void DidReceiveCompositorFrameAck() override; 77 void DidReceiveCompositorFrameAck() override;
64 void OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) override; 78 void OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) override;
65 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; 79 void ReclaimResources(const cc::ReturnedResourceArray& resources) override;
66 80
67 // Generates the CompositorFrame. 81 // Generates the CompositorFrame.
68 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect); 82 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect);
69 83
70 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad 84 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad
71 // for each that lacks one. 85 // for each that lacks one.
72 void DrawWindowTree(cc::RenderPass* pass, 86 void DrawWindowTree(cc::RenderPass* pass,
73 ServerWindow* window, 87 ServerWindow* window,
74 const gfx::Vector2d& parent_to_root_origin_offset, 88 const gfx::Vector2d& parent_to_root_origin_offset,
75 float opacity); 89 float opacity);
76 90
77 // Adds a reference to the current cc::Surface of the provided 91 // Finds all Surfaces with references from |old_surface_id| and adds a new
78 // |window_compositor_frame_sink|. If an existing reference is held with a 92 // reference from |new_surface_id|. The caller should remove any references
79 // different LocalFrameId then release that reference first. This is called on 93 // to |old_surface_id| afterwards to finish cleanup.
80 // each ServerWindowCompositorFrameSink as FrameGenerator walks the window 94 void AddNewParentReferences(const cc::SurfaceId& old_surface_id,
81 // tree to generate a CompositorFrame. This is done to make sure that the 95 const cc::SurfaceId& new_surface_id);
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 96
89 // Releases any retained references for the provided FrameSink. 97 // Removes all references to surfaces in |dead_references_|.
90 // TODO(fsamuel, kylechar): This will go away once we get surface lifetime 98 void RemoveDeadSurfaceReferences();
91 // management.
92 void ReleaseFrameSinkReference(const cc::FrameSinkId& frame_sink_id);
93 99
94 // Releases all retained references to surfaces. 100 // Removes any retained references for the provided FrameSink.
95 // TODO(fsamuel, kylechar): This will go away once we get surface lifetime 101 void RemoveFrameSinkReference(const cc::FrameSinkId& frame_sink_id);
96 // management. 102
97 void ReleaseAllSurfaceReferences(); 103 // Removes all retained references to surfaces.
104 void RemoveAllSurfaceReferences();
98 105
99 ui::DisplayCompositor* GetDisplayCompositor(); 106 ui::DisplayCompositor* GetDisplayCompositor();
100 107
101 // ServerWindowObserver implementation. 108 // ServerWindowObserver implementation.
102 void OnWindowDestroying(ServerWindow* window) override; 109 void OnWindowDestroying(ServerWindow* window) override;
103 110
104 FrameGeneratorDelegate* delegate_; 111 FrameGeneratorDelegate* delegate_;
105 cc::FrameSinkId frame_sink_id_;
106 ServerWindow* const root_window_; 112 ServerWindow* const root_window_;
107 cc::SurfaceSequenceGenerator surface_sequence_generator_;
108 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; 113 scoped_refptr<gpu::GpuChannelHost> gpu_channel_;
109 114
110 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink_; 115 cc::mojom::MojoCompositorFrameSinkPtr compositor_frame_sink_;
111 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; 116 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
112 117
113 struct SurfaceDependency { 118 struct SurfaceReference {
114 cc::LocalFrameId local_frame_id; 119 cc::SurfaceId parent_id;
115 cc::SurfaceSequence sequence; 120 cc::SurfaceId child_id;
116 }; 121 };
117 std::unordered_map<cc::FrameSinkId, SurfaceDependency, cc::FrameSinkIdHash> 122
118 dependencies_; 123 // Active references held by this client to Surfaces that could be used in a
124 // CompositorFrame.
125 std::unordered_map<cc::FrameSinkId, SurfaceReference, cc::FrameSinkIdHash>
126 active_references_;
127
128 // References to surfaces that should be removed after a CompositorFrame has
129 // been submitted and the surfaces are no longer being referenced.
130 std::vector<SurfaceReference> dead_references_;
119 131
120 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> binding_; 132 mojo::Binding<cc::mojom::MojoCompositorFrameSinkClient> binding_;
121 133
122 base::WeakPtrFactory<FrameGenerator> weak_factory_; 134 base::WeakPtrFactory<FrameGenerator> weak_factory_;
123 135
124 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); 136 DISALLOW_COPY_AND_ASSIGN(FrameGenerator);
125 }; 137 };
126 138
127 } // namespace ws 139 } // namespace ws
128 140
129 } // namespace ui 141 } // namespace ui
130 142
131 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ 143 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698