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

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

Issue 2400723003: Mus+Ash: Use standard cc mechanism for surface lifetime. (Closed)
Patch Set: Only AddObserver once Created 4 years, 2 months 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
« no previous file with comments | « services/ui/ws/display.cc ('k') | services/ui/ws/frame_generator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
12 #include "cc/surfaces/frame_sink_id.h" 13 #include "cc/surfaces/frame_sink_id.h"
14 #include "cc/surfaces/local_frame_id.h"
15 #include "cc/surfaces/surface_sequence.h"
16 #include "cc/surfaces/surface_sequence_generator.h"
17 #include "services/ui/ws/server_window_observer.h"
13 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/native_widget_types.h" 19 #include "ui/gfx/native_widget_types.h"
15 20
16 namespace cc { 21 namespace cc {
17 class CompositorFrame; 22 class CompositorFrame;
18 class CopyOutputRequest; 23 class CopyOutputRequest;
19 class RenderPass; 24 class RenderPass;
25 class SurfaceId;
20 } 26 }
21 27
22 namespace gpu { 28 namespace gpu {
23 class GpuChannelHost; 29 class GpuChannelHost;
24 } 30 }
25 31
26 namespace ui { 32 namespace ui {
27 33
28 namespace surfaces { 34 namespace surfaces {
29 class CompositorFrameSink; 35 class CompositorFrameSink;
30 } 36 }
31 37
32 class DisplayCompositor; 38 class DisplayCompositor;
33 39
34 namespace ws { 40 namespace ws {
35 41
36 namespace test { 42 namespace test {
37 class FrameGeneratorTest; 43 class FrameGeneratorTest;
38 } 44 }
39 45
40 class FrameGeneratorDelegate; 46 class FrameGeneratorDelegate;
41 class ServerWindow; 47 class ServerWindow;
48 class ServerWindowSurface;
42 49
43 // Responsible for redrawing the display in response to the redraw requests by 50 // Responsible for redrawing the display in response to the redraw requests by
44 // submitting CompositorFrames to the owned CompositorFrameSink. 51 // submitting CompositorFrames to the owned CompositorFrameSink.
45 class FrameGenerator { 52 class FrameGenerator : public ServerWindowObserver {
46 public: 53 public:
47 FrameGenerator(FrameGeneratorDelegate* delegate, 54 FrameGenerator(FrameGeneratorDelegate* delegate,
48 scoped_refptr<DisplayCompositor> display_compositor); 55 scoped_refptr<DisplayCompositor> display_compositor);
49 virtual ~FrameGenerator(); 56 ~FrameGenerator() override;
50 57
51 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); 58 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel);
52 59
53 // Schedules a redraw for the provided region. 60 // Schedules a redraw for the provided region.
54 void RequestRedraw(const gfx::Rect& redraw_region); 61 void RequestRedraw(const gfx::Rect& redraw_region);
55 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget); 62 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget);
56 void RequestCopyOfOutput( 63 void RequestCopyOfOutput(
57 std::unique_ptr<cc::CopyOutputRequest> output_request); 64 std::unique_ptr<cc::CopyOutputRequest> output_request);
58 65
59 bool is_frame_pending() { return frame_pending_; } 66 bool is_frame_pending() { return frame_pending_; }
60 67
61 private: 68 private:
62 friend class ui::ws::test::FrameGeneratorTest; 69 friend class ui::ws::test::FrameGeneratorTest;
63 70
64 void WantToDraw(); 71 void WantToDraw();
65 72
66 // This method initiates a top level redraw of the display. 73 // This method initiates a top level redraw of the display.
67 // TODO(fsamuel): This should use vblank as a signal rather than a timer 74 // TODO(fsamuel): In polliwog, this only gets called when the window manager
68 // http://crbug.com/533042 75 // changes.
69 void Draw(); 76 void Draw();
70 77
71 // This is called after the CompositorFrameSink has completed generating a new 78 // This is called after the CompositorFrameSink has completed generating a new
72 // frame for the display. TODO(fsamuel): Idle time processing should happen 79 // frame for the display.
73 // here if there is budget for it.
74 void DidDraw(); 80 void DidDraw();
75 81
76 // Generates the CompositorFrame for the current |dirty_rect_|. 82 // Generates the CompositorFrame for the current |dirty_rect_|.
77 cc::CompositorFrame GenerateCompositorFrame( 83 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect);
78 const gfx::Rect& output_rect) const;
79 84
80 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad 85 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad
81 // for each that lacks one. 86 // for each that lacks one.
82 void DrawWindowTree(cc::RenderPass* pass, 87 void DrawWindowTree(cc::RenderPass* pass,
83 ServerWindow* window, 88 ServerWindow* window,
84 const gfx::Vector2d& parent_to_root_origin_offset, 89 const gfx::Vector2d& parent_to_root_origin_offset,
85 float opacity, 90 float opacity,
86 bool* may_contain_video) const; 91 bool* may_contain_video);
92
93 // Adds a reference to the current cc::Surface of the provided
94 // |window_surface|. If an existing reference is held with a different
95 // LocalFrameId then release that reference first. This is called on each
96 // ServerWindowSurface as FrameGenerator walks the window tree to generate a
97 /// CompositorFrame. This is done to make sure that the window surfaces are
98 // retained for the entirety of the time between submission of the top-level
99 // frame to drawing the frame to screen.
100 // TODO(fsamuel, kylechar): This will go away once we get surface lifetime
101 // management.
102 void AddOrUpdateSurfaceReference(ServerWindowSurface* window_surface);
103
104 // Releases any retained references for the provided FrameSink.
105 // TODO(fsamuel, kylechar): This will go away once we get surface lifetime
106 // management.
107 void ReleaseFrameSinkReference(const cc::FrameSinkId& frame_sink_id);
108
109 // Releases all retained references to surfaces.
110 // TODO(fsamuel, kylechar): This will go away once we get surface lifetime
111 // management.
112 void ReleaseAllSurfaceReferences();
113
114 // ServerWindowObserver implementation.
115 void OnWindowDestroying(ServerWindow* window) override;
87 116
88 FrameGeneratorDelegate* delegate_; 117 FrameGeneratorDelegate* delegate_;
89 scoped_refptr<DisplayCompositor> display_compositor_; 118 scoped_refptr<DisplayCompositor> display_compositor_;
90 cc::FrameSinkId frame_sink_id_; 119 cc::FrameSinkId frame_sink_id_;
120 cc::SurfaceSequenceGenerator surface_sequence_generator_;
91 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; 121 scoped_refptr<gpu::GpuChannelHost> gpu_channel_;
92 122
93 std::unique_ptr<surfaces::CompositorFrameSink> compositor_frame_sink_; 123 std::unique_ptr<surfaces::CompositorFrameSink> compositor_frame_sink_;
94 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; 124 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget;
95 125
96 // The region that needs to be redrawn next time the compositor frame is 126 // The region that needs to be redrawn next time the compositor frame is
97 // generated. 127 // generated.
98 gfx::Rect dirty_rect_; 128 gfx::Rect dirty_rect_;
99 base::Timer draw_timer_; 129 base::Timer draw_timer_;
100 bool frame_pending_ = false; 130 bool frame_pending_ = false;
101 bool may_contain_video_ = false; 131 bool may_contain_video_ = false;
132 struct SurfaceDependency {
133 cc::LocalFrameId local_frame_id;
134 cc::SurfaceSequence sequence;
135 };
136 std::unordered_map<cc::FrameSinkId, SurfaceDependency, cc::FrameSinkIdHash>
137 dependencies_;
102 138
103 base::WeakPtrFactory<FrameGenerator> weak_factory_; 139 base::WeakPtrFactory<FrameGenerator> weak_factory_;
104 140
105 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); 141 DISALLOW_COPY_AND_ASSIGN(FrameGenerator);
106 }; 142 };
107 143
108 } // namespace ws 144 } // namespace ws
109 145
110 } // namespace ui 146 } // namespace ui
111 147
112 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ 148 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_
OLDNEW
« no previous file with comments | « services/ui/ws/display.cc ('k') | services/ui/ws/frame_generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698