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 #include "services/ui/ws/frame_generator.h" | 5 #include "services/ui/ws/frame_generator.h" |
6 | 6 |
7 #include "base/containers/adapters.h" | 7 #include "base/containers/adapters.h" |
8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
9 #include "cc/quads/render_pass.h" | 9 #include "cc/quads/render_pass.h" |
10 #include "cc/quads/render_pass_draw_quad.h" | 10 #include "cc/quads/render_pass_draw_quad.h" |
11 #include "cc/quads/shared_quad_state.h" | 11 #include "cc/quads/shared_quad_state.h" |
12 #include "cc/quads/surface_draw_quad.h" | 12 #include "cc/quads/surface_draw_quad.h" |
13 #include "gpu/ipc/client/gpu_channel_host.h" | 13 #include "gpu/ipc/client/gpu_channel_host.h" |
14 #include "services/ui/surfaces/display_compositor.h" | 14 #include "services/ui/surfaces/compositor_frame_sink.h" |
15 #include "services/ui/ws/frame_generator_delegate.h" | 15 #include "services/ui/ws/frame_generator_delegate.h" |
16 #include "services/ui/ws/server_window.h" | 16 #include "services/ui/ws/server_window.h" |
17 #include "services/ui/ws/server_window_surface.h" | 17 #include "services/ui/ws/server_window_surface.h" |
18 #include "services/ui/ws/server_window_surface_manager.h" | 18 #include "services/ui/ws/server_window_surface_manager.h" |
19 | 19 |
20 namespace ui { | 20 namespace ui { |
21 | 21 |
22 namespace ws { | 22 namespace ws { |
23 | 23 |
24 FrameGenerator::FrameGenerator(FrameGeneratorDelegate* delegate, | 24 FrameGenerator::FrameGenerator( |
25 scoped_refptr<SurfacesState> surfaces_state) | 25 FrameGeneratorDelegate* delegate, |
| 26 scoped_refptr<surfaces::DisplayCompositor> display_compositor) |
26 : delegate_(delegate), | 27 : delegate_(delegate), |
27 surfaces_state_(surfaces_state), | 28 display_compositor_(display_compositor), |
28 draw_timer_(false, false), | 29 draw_timer_(false, false), |
29 weak_factory_(this) { | 30 weak_factory_(this) { |
30 DCHECK(delegate_); | 31 DCHECK(delegate_); |
31 } | 32 } |
32 | 33 |
33 FrameGenerator::~FrameGenerator() { | 34 FrameGenerator::~FrameGenerator() { |
34 // Invalidate WeakPtrs now to avoid callbacks back into the | 35 // Invalidate WeakPtrs now to avoid callbacks back into the |
35 // FrameGenerator during destruction of |display_compositor_|. | 36 // FrameGenerator during destruction of |compositor_frame_sink_|. |
36 weak_factory_.InvalidateWeakPtrs(); | 37 weak_factory_.InvalidateWeakPtrs(); |
37 display_compositor_.reset(); | 38 compositor_frame_sink_.reset(); |
38 } | 39 } |
39 | 40 |
40 void FrameGenerator::OnGpuChannelEstablished( | 41 void FrameGenerator::OnGpuChannelEstablished( |
41 scoped_refptr<gpu::GpuChannelHost> channel) { | 42 scoped_refptr<gpu::GpuChannelHost> channel) { |
42 if (widget_ != gfx::kNullAcceleratedWidget) { | 43 if (widget_ != gfx::kNullAcceleratedWidget) { |
43 display_compositor_.reset( | 44 compositor_frame_sink_.reset(new surfaces::CompositorFrameSink( |
44 new DisplayCompositor(base::ThreadTaskRunnerHandle::Get(), widget_, | 45 base::ThreadTaskRunnerHandle::Get(), widget_, std::move(channel), |
45 std::move(channel), surfaces_state_)); | 46 display_compositor_)); |
46 } else { | 47 } else { |
47 gpu_channel_ = std::move(channel); | 48 gpu_channel_ = std::move(channel); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 void FrameGenerator::RequestRedraw(const gfx::Rect& redraw_region) { | 52 void FrameGenerator::RequestRedraw(const gfx::Rect& redraw_region) { |
52 dirty_rect_.Union(redraw_region); | 53 dirty_rect_.Union(redraw_region); |
53 WantToDraw(); | 54 WantToDraw(); |
54 } | 55 } |
55 | 56 |
56 void FrameGenerator::OnAcceleratedWidgetAvailable( | 57 void FrameGenerator::OnAcceleratedWidgetAvailable( |
57 gfx::AcceleratedWidget widget) { | 58 gfx::AcceleratedWidget widget) { |
58 widget_ = widget; | 59 widget_ = widget; |
59 if (gpu_channel_ && widget != gfx::kNullAcceleratedWidget) { | 60 if (gpu_channel_ && widget != gfx::kNullAcceleratedWidget) { |
60 display_compositor_.reset( | 61 compositor_frame_sink_.reset(new surfaces::CompositorFrameSink( |
61 new DisplayCompositor(base::ThreadTaskRunnerHandle::Get(), widget_, | 62 base::ThreadTaskRunnerHandle::Get(), widget_, std::move(gpu_channel_), |
62 std::move(gpu_channel_), surfaces_state_)); | 63 display_compositor_)); |
63 } | 64 } |
64 } | 65 } |
65 | 66 |
66 void FrameGenerator::RequestCopyOfOutput( | 67 void FrameGenerator::RequestCopyOfOutput( |
67 std::unique_ptr<cc::CopyOutputRequest> output_request) { | 68 std::unique_ptr<cc::CopyOutputRequest> output_request) { |
68 if (display_compositor_) | 69 if (compositor_frame_sink_) |
69 display_compositor_->RequestCopyOfOutput(std::move(output_request)); | 70 compositor_frame_sink_->RequestCopyOfOutput(std::move(output_request)); |
70 } | 71 } |
71 | 72 |
72 void FrameGenerator::WantToDraw() { | 73 void FrameGenerator::WantToDraw() { |
73 if (draw_timer_.IsRunning() || frame_pending_) | 74 if (draw_timer_.IsRunning() || frame_pending_) |
74 return; | 75 return; |
75 | 76 |
76 // TODO(rjkroege): Use vblank to kick off Draw. | 77 // TODO(rjkroege): Use vblank to kick off Draw. |
77 draw_timer_.Start( | 78 draw_timer_.Start( |
78 FROM_HERE, base::TimeDelta(), | 79 FROM_HERE, base::TimeDelta(), |
79 base::Bind(&FrameGenerator::Draw, weak_factory_.GetWeakPtr())); | 80 base::Bind(&FrameGenerator::Draw, weak_factory_.GetWeakPtr())); |
80 } | 81 } |
81 | 82 |
82 void FrameGenerator::Draw() { | 83 void FrameGenerator::Draw() { |
83 if (!delegate_->GetRootWindow()->visible()) | 84 if (!delegate_->GetRootWindow()->visible()) |
84 return; | 85 return; |
85 | 86 |
86 const ViewportMetrics& metrics = delegate_->GetViewportMetrics(); | 87 const ViewportMetrics& metrics = delegate_->GetViewportMetrics(); |
87 const gfx::Rect output_rect(metrics.bounds.size()); | 88 const gfx::Rect output_rect(metrics.bounds.size()); |
88 dirty_rect_.Intersect(output_rect); | 89 dirty_rect_.Intersect(output_rect); |
89 // TODO(fsamuel): We should add a trace for generating a top level frame. | 90 // TODO(fsamuel): We should add a trace for generating a top level frame. |
90 cc::CompositorFrame frame(GenerateCompositorFrame(output_rect)); | 91 cc::CompositorFrame frame(GenerateCompositorFrame(output_rect)); |
91 if (frame.metadata.may_contain_video != may_contain_video_) { | 92 if (frame.metadata.may_contain_video != may_contain_video_) { |
92 may_contain_video_ = frame.metadata.may_contain_video; | 93 may_contain_video_ = frame.metadata.may_contain_video; |
93 // TODO(sad): Schedule notifying observers. | 94 // TODO(sad): Schedule notifying observers. |
94 if (may_contain_video_) { | 95 if (may_contain_video_) { |
95 // TODO(sad): Start a timer to reset the bit if no new frame with video | 96 // TODO(sad): Start a timer to reset the bit if no new frame with video |
96 // is submitted 'soon'. | 97 // is submitted 'soon'. |
97 } | 98 } |
98 } | 99 } |
99 if (display_compositor_) { | 100 if (compositor_frame_sink_) { |
100 frame_pending_ = true; | 101 frame_pending_ = true; |
101 display_compositor_->SubmitCompositorFrame( | 102 compositor_frame_sink_->SubmitCompositorFrame( |
102 std::move(frame), | 103 std::move(frame), |
103 base::Bind(&FrameGenerator::DidDraw, weak_factory_.GetWeakPtr())); | 104 base::Bind(&FrameGenerator::DidDraw, weak_factory_.GetWeakPtr())); |
104 } | 105 } |
105 dirty_rect_ = gfx::Rect(); | 106 dirty_rect_ = gfx::Rect(); |
106 } | 107 } |
107 | 108 |
108 void FrameGenerator::DidDraw() { | 109 void FrameGenerator::DidDraw() { |
109 frame_pending_ = false; | 110 frame_pending_ = false; |
110 delegate_->OnCompositorFrameDrawn(); | 111 delegate_->OnCompositorFrameDrawn(); |
111 if (!dirty_rect_.IsEmpty()) | 112 // if (!dirty_rect_.IsEmpty()) |
112 WantToDraw(); | 113 WantToDraw(); |
113 } | 114 } |
114 | 115 |
115 cc::CompositorFrame FrameGenerator::GenerateCompositorFrame( | 116 cc::CompositorFrame FrameGenerator::GenerateCompositorFrame( |
116 const gfx::Rect& output_rect) const { | 117 const gfx::Rect& output_rect) const { |
117 const cc::RenderPassId render_pass_id(1, 1); | 118 const cc::RenderPassId render_pass_id(1, 1); |
118 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 119 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
119 render_pass->SetNew(render_pass_id, output_rect, dirty_rect_, | 120 render_pass->SetNew(render_pass_id, output_rect, dirty_rect_, |
120 gfx::Transform()); | 121 gfx::Transform()); |
121 | 122 |
122 bool may_contain_video = false; | 123 bool may_contain_video = false; |
123 DrawWindowTree(render_pass.get(), delegate_->GetRootWindow(), gfx::Vector2d(), | 124 DrawWindowTree(render_pass.get(), delegate_->GetActiveRootWindow(), |
124 1.0f, &may_contain_video); | 125 gfx::Vector2d(), 1.0f, &may_contain_video); |
125 | 126 |
126 std::unique_ptr<cc::DelegatedFrameData> frame_data( | 127 std::unique_ptr<cc::DelegatedFrameData> frame_data( |
127 new cc::DelegatedFrameData); | 128 new cc::DelegatedFrameData); |
128 frame_data->render_pass_list.push_back(std::move(render_pass)); | 129 frame_data->render_pass_list.push_back(std::move(render_pass)); |
129 if (delegate_->IsInHighContrastMode()) { | 130 if (delegate_->IsInHighContrastMode()) { |
130 std::unique_ptr<cc::RenderPass> invert_pass = cc::RenderPass::Create(); | 131 std::unique_ptr<cc::RenderPass> invert_pass = cc::RenderPass::Create(); |
131 invert_pass->SetNew(cc::RenderPassId(2, 0), output_rect, dirty_rect_, | 132 invert_pass->SetNew(cc::RenderPassId(2, 0), output_rect, dirty_rect_, |
132 gfx::Transform()); | 133 gfx::Transform()); |
133 cc::SharedQuadState* shared_state = | 134 cc::SharedQuadState* shared_state = |
134 invert_pass->CreateAndAppendSharedQuadState(); | 135 invert_pass->CreateAndAppendSharedQuadState(); |
(...skipping 25 matching lines...) Expand all Loading... |
160 bool* may_contain_video) const { | 161 bool* may_contain_video) const { |
161 if (!window->visible()) | 162 if (!window->visible()) |
162 return; | 163 return; |
163 | 164 |
164 ServerWindowSurface* default_surface = | 165 ServerWindowSurface* default_surface = |
165 window->surface_manager() ? window->surface_manager()->GetDefaultSurface() | 166 window->surface_manager() ? window->surface_manager()->GetDefaultSurface() |
166 : nullptr; | 167 : nullptr; |
167 | 168 |
168 const gfx::Rect absolute_bounds = | 169 const gfx::Rect absolute_bounds = |
169 window->bounds() + parent_to_root_origin_offset; | 170 window->bounds() + parent_to_root_origin_offset; |
170 const ServerWindow::Windows& children = window->children(); | |
171 const float combined_opacity = opacity * window->opacity(); | 171 const float combined_opacity = opacity * window->opacity(); |
172 for (ServerWindow* child : base::Reversed(children)) { | |
173 DrawWindowTree(pass, child, absolute_bounds.OffsetFromOrigin(), | |
174 combined_opacity, may_contain_video); | |
175 } | |
176 | 172 |
177 if (!window->surface_manager() || !window->surface_manager()->ShouldDraw()) | 173 if (!window->surface_manager()) |
178 return; | 174 return; |
179 | 175 |
180 ServerWindowSurface* underlay_surface = | 176 ServerWindowSurface* underlay_surface = |
181 window->surface_manager()->GetUnderlaySurface(); | 177 window->surface_manager()->GetUnderlaySurface(); |
182 if (!default_surface && !underlay_surface) | 178 if (!default_surface && !underlay_surface) |
183 return; | 179 return; |
184 | 180 |
185 if (default_surface) { | 181 if (default_surface) { |
186 gfx::Transform quad_to_target_transform; | 182 gfx::Transform quad_to_target_transform; |
187 quad_to_target_transform.Translate(absolute_bounds.x(), | 183 quad_to_target_transform.Translate(absolute_bounds.x(), |
(...skipping 11 matching lines...) Expand all Loading... |
199 combined_opacity, SkXfermode::kSrcOver_Mode, | 195 combined_opacity, SkXfermode::kSrcOver_Mode, |
200 0 /* sorting-context_id */); | 196 0 /* sorting-context_id */); |
201 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 197 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
202 quad->SetAll(sqs, bounds_at_origin /* rect */, | 198 quad->SetAll(sqs, bounds_at_origin /* rect */, |
203 gfx::Rect() /* opaque_rect */, | 199 gfx::Rect() /* opaque_rect */, |
204 bounds_at_origin /* visible_rect */, true /* needs_blending*/, | 200 bounds_at_origin /* visible_rect */, true /* needs_blending*/, |
205 default_surface->id()); | 201 default_surface->id()); |
206 if (default_surface->may_contain_video()) | 202 if (default_surface->may_contain_video()) |
207 *may_contain_video = true; | 203 *may_contain_video = true; |
208 } | 204 } |
209 if (underlay_surface) { | 205 //if (underlay_surface) { |
210 const gfx::Rect underlay_absolute_bounds = | 206 // const gfx::Rect underlay_absolute_bounds = |
211 absolute_bounds - window->underlay_offset(); | 207 // absolute_bounds - window->underlay_offset(); |
212 gfx::Transform quad_to_target_transform; | 208 // gfx::Transform quad_to_target_transform; |
213 quad_to_target_transform.Translate(underlay_absolute_bounds.x(), | 209 // quad_to_target_transform.Translate(underlay_absolute_bounds.x(), |
214 underlay_absolute_bounds.y()); | 210 // underlay_absolute_bounds.y()); |
215 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 211 // cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
216 const gfx::Rect bounds_at_origin( | 212 // const gfx::Rect bounds_at_origin( |
217 underlay_surface->last_submitted_frame_size()); | 213 // underlay_surface->last_submitted_frame_size()); |
218 sqs->SetAll(quad_to_target_transform, | 214 // sqs->SetAll(quad_to_target_transform, |
219 bounds_at_origin.size() /* layer_bounds */, | 215 // bounds_at_origin.size() /* layer_bounds */, |
220 bounds_at_origin /* visible_layer_bounds */, | 216 // bounds_at_origin /* visible_layer_bounds */, |
221 bounds_at_origin /* clip_rect */, false /* is_clipped */, | 217 // bounds_at_origin /* clip_rect */, false /* is_clipped */, |
222 combined_opacity, SkXfermode::kSrcOver_Mode, | 218 // combined_opacity, SkXfermode::kSrcOver_Mode, |
223 0 /* sorting-context_id */); | 219 // 0 /* sorting-context_id */); |
224 | 220 |
225 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 221 // auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
226 quad->SetAll(sqs, bounds_at_origin /* rect */, | 222 // quad->SetAll(sqs, bounds_at_origin /* rect */, |
227 gfx::Rect() /* opaque_rect */, | 223 // gfx::Rect() /* opaque_rect */, |
228 bounds_at_origin /* visible_rect */, true /* needs_blending*/, | 224 // bounds_at_origin /* visible_rect */, true /* needs_blending*/
, |
229 underlay_surface->id()); | 225 // underlay_surface->id()); |
230 DCHECK(!underlay_surface->may_contain_video()); | 226 // DCHECK(!underlay_surface->may_contain_video()); |
231 } | 227 //} |
232 } | 228 } |
233 | 229 |
234 } // namespace ws | 230 } // namespace ws |
235 | 231 |
236 } // namespace ui | 232 } // namespace ui |
OLD | NEW |