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

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

Issue 2140783002: services/ui: Detect when a video is playing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tot merge Created 4 years, 4 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/frame_generator.h ('k') | services/ui/ws/frame_generator_unittest.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 #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"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // TODO(rjkroege): Use vblank to kick off Draw. 62 // TODO(rjkroege): Use vblank to kick off Draw.
63 draw_timer_.Start( 63 draw_timer_.Start(
64 FROM_HERE, base::TimeDelta(), 64 FROM_HERE, base::TimeDelta(),
65 base::Bind(&FrameGenerator::Draw, weak_factory_.GetWeakPtr())); 65 base::Bind(&FrameGenerator::Draw, weak_factory_.GetWeakPtr()));
66 } 66 }
67 67
68 void FrameGenerator::Draw() { 68 void FrameGenerator::Draw() {
69 if (!delegate_->GetRootWindow()->visible()) 69 if (!delegate_->GetRootWindow()->visible())
70 return; 70 return;
71 71
72 const ViewportMetrics& metrics = delegate_->GetViewportMetrics();
73 const gfx::Rect& output_rect = metrics.bounds;
74 dirty_rect_.Intersect(output_rect);
72 // TODO(fsamuel): We should add a trace for generating a top level frame. 75 // TODO(fsamuel): We should add a trace for generating a top level frame.
73 cc::CompositorFrame frame(GenerateCompositorFrame()); 76 cc::CompositorFrame frame(GenerateCompositorFrame(output_rect));
77 if (frame.metadata.may_contain_video != may_contain_video_) {
78 may_contain_video_ = frame.metadata.may_contain_video;
79 // TODO(sad): Schedule notifying observers.
80 if (may_contain_video_) {
81 // TODO(sad): Start a timer to reset the bit if no new frame with video
82 // is submitted 'soon'.
83 }
84 }
74 frame_pending_ = true; 85 frame_pending_ = true;
75 if (display_compositor_) { 86 if (display_compositor_) {
76 display_compositor_->SubmitCompositorFrame( 87 display_compositor_->SubmitCompositorFrame(
77 std::move(frame), 88 std::move(frame),
78 base::Bind(&FrameGenerator::DidDraw, weak_factory_.GetWeakPtr())); 89 base::Bind(&FrameGenerator::DidDraw, weak_factory_.GetWeakPtr()));
79 } 90 }
80 dirty_rect_ = gfx::Rect(); 91 dirty_rect_ = gfx::Rect();
81 } 92 }
82 93
83 void FrameGenerator::DidDraw() { 94 void FrameGenerator::DidDraw() {
84 frame_pending_ = false; 95 frame_pending_ = false;
85 delegate_->OnCompositorFrameDrawn(); 96 delegate_->OnCompositorFrameDrawn();
86 if (!dirty_rect_.IsEmpty()) 97 if (!dirty_rect_.IsEmpty())
87 WantToDraw(); 98 WantToDraw();
88 } 99 }
89 100
90 cc::CompositorFrame FrameGenerator::GenerateCompositorFrame() { 101 cc::CompositorFrame FrameGenerator::GenerateCompositorFrame(
91 const ViewportMetrics& metrics = delegate_->GetViewportMetrics(); 102 const gfx::Rect& output_rect) const {
103 const cc::RenderPassId render_pass_id(1, 1);
92 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); 104 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
93 gfx::Rect output_rect = metrics.bounds;
94 dirty_rect_.Intersect(output_rect);
95 const cc::RenderPassId render_pass_id(1, 1);
96 render_pass->SetNew(render_pass_id, output_rect, dirty_rect_, 105 render_pass->SetNew(render_pass_id, output_rect, dirty_rect_,
97 gfx::Transform()); 106 gfx::Transform());
98 107
108 bool may_contain_video = false;
99 DrawWindowTree(render_pass.get(), delegate_->GetRootWindow(), gfx::Vector2d(), 109 DrawWindowTree(render_pass.get(), delegate_->GetRootWindow(), gfx::Vector2d(),
100 1.0f); 110 1.0f, &may_contain_video);
101 111
102 std::unique_ptr<cc::DelegatedFrameData> frame_data( 112 std::unique_ptr<cc::DelegatedFrameData> frame_data(
103 new cc::DelegatedFrameData); 113 new cc::DelegatedFrameData);
104 frame_data->render_pass_list.push_back(std::move(render_pass)); 114 frame_data->render_pass_list.push_back(std::move(render_pass));
105 if (delegate_->IsInHighContrastMode()) { 115 if (delegate_->IsInHighContrastMode()) {
106 std::unique_ptr<cc::RenderPass> invert_pass = cc::RenderPass::Create(); 116 std::unique_ptr<cc::RenderPass> invert_pass = cc::RenderPass::Create();
107 invert_pass->SetNew(cc::RenderPassId(2, 0), output_rect, dirty_rect_, 117 invert_pass->SetNew(cc::RenderPassId(2, 0), output_rect, dirty_rect_,
108 gfx::Transform()); 118 gfx::Transform());
109 cc::SharedQuadState* shared_state = 119 cc::SharedQuadState* shared_state =
110 invert_pass->CreateAndAppendSharedQuadState(); 120 invert_pass->CreateAndAppendSharedQuadState();
111 shared_state->SetAll(gfx::Transform(), output_rect.size(), output_rect, 121 shared_state->SetAll(gfx::Transform(), output_rect.size(), output_rect,
112 output_rect, false, 1.f, SkXfermode::kSrcOver_Mode, 0); 122 output_rect, false, 1.f, SkXfermode::kSrcOver_Mode, 0);
113 auto* quad = invert_pass->CreateAndAppendDrawQuad<cc::RenderPassDrawQuad>(); 123 auto* quad = invert_pass->CreateAndAppendDrawQuad<cc::RenderPassDrawQuad>();
114 cc::FilterOperations filters; 124 cc::FilterOperations filters;
115 filters.Append(cc::FilterOperation::CreateInvertFilter(1.f)); 125 filters.Append(cc::FilterOperation::CreateInvertFilter(1.f));
116 quad->SetNew(shared_state, output_rect, output_rect, render_pass_id, 126 quad->SetNew(shared_state, output_rect, output_rect, render_pass_id,
117 0 /* mask_resource_id */, gfx::Vector2dF() /* mask_uv_scale */, 127 0 /* mask_resource_id */, gfx::Vector2dF() /* mask_uv_scale */,
118 gfx::Size() /* mask_texture_size */, filters, 128 gfx::Size() /* mask_texture_size */, filters,
119 gfx::Vector2dF() /* filters_scale */, 129 gfx::Vector2dF() /* filters_scale */,
120 cc::FilterOperations() /* background_filters */); 130 cc::FilterOperations() /* background_filters */);
121 frame_data->render_pass_list.push_back(std::move(invert_pass)); 131 frame_data->render_pass_list.push_back(std::move(invert_pass));
122 } 132 }
123 133
124 cc::CompositorFrame frame; 134 cc::CompositorFrame frame;
125 frame.delegated_frame_data = std::move(frame_data); 135 frame.delegated_frame_data = std::move(frame_data);
136 frame.metadata.may_contain_video = may_contain_video;
126 return frame; 137 return frame;
127 } 138 }
128 139
129 void FrameGenerator::DrawWindowTree( 140 void FrameGenerator::DrawWindowTree(
130 cc::RenderPass* pass, 141 cc::RenderPass* pass,
131 ServerWindow* window, 142 ServerWindow* window,
132 const gfx::Vector2d& parent_to_root_origin_offset, 143 const gfx::Vector2d& parent_to_root_origin_offset,
133 float opacity) { 144 float opacity,
145 bool* may_contain_video) const {
134 if (!window->visible()) 146 if (!window->visible())
135 return; 147 return;
136 148
137 ServerWindowSurface* default_surface = 149 ServerWindowSurface* default_surface =
138 window->surface_manager() ? window->surface_manager()->GetDefaultSurface() 150 window->surface_manager() ? window->surface_manager()->GetDefaultSurface()
139 : nullptr; 151 : nullptr;
140 152
141 const gfx::Rect absolute_bounds = 153 const gfx::Rect absolute_bounds =
142 window->bounds() + parent_to_root_origin_offset; 154 window->bounds() + parent_to_root_origin_offset;
143 const ServerWindow::Windows& children = window->children(); 155 const ServerWindow::Windows& children = window->children();
144 const float combined_opacity = opacity * window->opacity(); 156 const float combined_opacity = opacity * window->opacity();
145 for (ServerWindow* child : base::Reversed(children)) { 157 for (ServerWindow* child : base::Reversed(children)) {
146 DrawWindowTree(pass, child, absolute_bounds.OffsetFromOrigin(), 158 DrawWindowTree(pass, child, absolute_bounds.OffsetFromOrigin(),
147 combined_opacity); 159 combined_opacity, may_contain_video);
148 } 160 }
149 161
150 if (!window->surface_manager() || !window->surface_manager()->ShouldDraw()) 162 if (!window->surface_manager() || !window->surface_manager()->ShouldDraw())
151 return; 163 return;
152 164
153 ServerWindowSurface* underlay_surface = 165 ServerWindowSurface* underlay_surface =
154 window->surface_manager()->GetUnderlaySurface(); 166 window->surface_manager()->GetUnderlaySurface();
155 if (!default_surface && !underlay_surface) 167 if (!default_surface && !underlay_surface)
156 return; 168 return;
157 169
(...skipping 11 matching lines...) Expand all
169 bounds_at_origin.size() /* layer_bounds */, 181 bounds_at_origin.size() /* layer_bounds */,
170 bounds_at_origin /* visible_layer_bounds */, 182 bounds_at_origin /* visible_layer_bounds */,
171 bounds_at_origin /* clip_rect */, false /* is_clipped */, 183 bounds_at_origin /* clip_rect */, false /* is_clipped */,
172 combined_opacity, SkXfermode::kSrcOver_Mode, 184 combined_opacity, SkXfermode::kSrcOver_Mode,
173 0 /* sorting-context_id */); 185 0 /* sorting-context_id */);
174 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); 186 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
175 quad->SetAll(sqs, bounds_at_origin /* rect */, 187 quad->SetAll(sqs, bounds_at_origin /* rect */,
176 gfx::Rect() /* opaque_rect */, 188 gfx::Rect() /* opaque_rect */,
177 bounds_at_origin /* visible_rect */, true /* needs_blending*/, 189 bounds_at_origin /* visible_rect */, true /* needs_blending*/,
178 default_surface->id()); 190 default_surface->id());
191 if (default_surface->may_contain_video())
192 *may_contain_video = true;
179 } 193 }
180 if (underlay_surface) { 194 if (underlay_surface) {
181 const gfx::Rect underlay_absolute_bounds = 195 const gfx::Rect underlay_absolute_bounds =
182 absolute_bounds - window->underlay_offset(); 196 absolute_bounds - window->underlay_offset();
183 gfx::Transform quad_to_target_transform; 197 gfx::Transform quad_to_target_transform;
184 quad_to_target_transform.Translate(underlay_absolute_bounds.x(), 198 quad_to_target_transform.Translate(underlay_absolute_bounds.x(),
185 underlay_absolute_bounds.y()); 199 underlay_absolute_bounds.y());
186 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 200 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
187 const gfx::Rect bounds_at_origin( 201 const gfx::Rect bounds_at_origin(
188 underlay_surface->last_submitted_frame_size()); 202 underlay_surface->last_submitted_frame_size());
189 sqs->SetAll(quad_to_target_transform, 203 sqs->SetAll(quad_to_target_transform,
190 bounds_at_origin.size() /* layer_bounds */, 204 bounds_at_origin.size() /* layer_bounds */,
191 bounds_at_origin /* visible_layer_bounds */, 205 bounds_at_origin /* visible_layer_bounds */,
192 bounds_at_origin /* clip_rect */, false /* is_clipped */, 206 bounds_at_origin /* clip_rect */, false /* is_clipped */,
193 combined_opacity, SkXfermode::kSrcOver_Mode, 207 combined_opacity, SkXfermode::kSrcOver_Mode,
194 0 /* sorting-context_id */); 208 0 /* sorting-context_id */);
195 209
196 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); 210 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
197 quad->SetAll(sqs, bounds_at_origin /* rect */, 211 quad->SetAll(sqs, bounds_at_origin /* rect */,
198 gfx::Rect() /* opaque_rect */, 212 gfx::Rect() /* opaque_rect */,
199 bounds_at_origin /* visible_rect */, true /* needs_blending*/, 213 bounds_at_origin /* visible_rect */, true /* needs_blending*/,
200 underlay_surface->id()); 214 underlay_surface->id());
215 DCHECK(!underlay_surface->may_contain_video());
201 } 216 }
202 } 217 }
203 218
204 } // namespace ws 219 } // namespace ws
205 220
206 } // namespace ui 221 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/frame_generator.h ('k') | services/ui/ws/frame_generator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698