| 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 "cc/surfaces/surface_id.h" | 13 #include "cc/surfaces/surface_id.h" |
| 14 #include "gpu/ipc/client/gpu_channel_host.h" | 14 #include "gpu/ipc/client/gpu_channel_host.h" |
| 15 #include "services/ui/surfaces/display_compositor_frame_sink.h" | 15 #include "services/ui/surfaces/display_compositor_frame_sink.h" |
| 16 #include "services/ui/ws/frame_generator_delegate.h" | 16 #include "services/ui/ws/frame_generator_delegate.h" |
| 17 #include "services/ui/ws/server_window.h" | 17 #include "services/ui/ws/server_window.h" |
| 18 #include "services/ui/ws/server_window_surface.h" | 18 #include "services/ui/ws/server_window_compositor_frame_sink.h" |
| 19 #include "services/ui/ws/server_window_surface_manager.h" | 19 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 20 | 20 |
| 21 namespace ui { | 21 namespace ui { |
| 22 | 22 |
| 23 namespace ws { | 23 namespace ws { |
| 24 | 24 |
| 25 FrameGenerator::FrameGenerator( | 25 FrameGenerator::FrameGenerator( |
| 26 FrameGeneratorDelegate* delegate, | 26 FrameGeneratorDelegate* delegate, |
| 27 scoped_refptr<DisplayCompositor> display_compositor) | 27 scoped_refptr<DisplayCompositor> display_compositor) |
| 28 : delegate_(delegate), | 28 : delegate_(delegate), |
| 29 display_compositor_(display_compositor), | 29 display_compositor_(display_compositor), |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 void FrameGenerator::DrawWindowTree( | 152 void FrameGenerator::DrawWindowTree( |
| 153 cc::RenderPass* pass, | 153 cc::RenderPass* pass, |
| 154 ServerWindow* window, | 154 ServerWindow* window, |
| 155 const gfx::Vector2d& parent_to_root_origin_offset, | 155 const gfx::Vector2d& parent_to_root_origin_offset, |
| 156 float opacity, | 156 float opacity, |
| 157 bool* may_contain_video) { | 157 bool* may_contain_video) { |
| 158 if (!window->visible()) | 158 if (!window->visible()) |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 ServerWindowSurface* default_surface = | 161 ServerWindowCompositorFrameSink* default_compositor_frame_sink = |
| 162 window->surface_manager() ? window->surface_manager()->GetDefaultSurface() | 162 window->compositor_frame_sink_manager() |
| 163 : nullptr; | 163 ? window->compositor_frame_sink_manager() |
| 164 ->GetDefaultCompositorFrameSink() |
| 165 : nullptr; |
| 164 | 166 |
| 165 const gfx::Rect absolute_bounds = | 167 const gfx::Rect absolute_bounds = |
| 166 window->bounds() + parent_to_root_origin_offset; | 168 window->bounds() + parent_to_root_origin_offset; |
| 167 const ServerWindow::Windows& children = window->children(); | 169 const ServerWindow::Windows& children = window->children(); |
| 168 const float combined_opacity = opacity * window->opacity(); | 170 const float combined_opacity = opacity * window->opacity(); |
| 169 for (ServerWindow* child : base::Reversed(children)) { | 171 for (ServerWindow* child : base::Reversed(children)) { |
| 170 DrawWindowTree(pass, child, absolute_bounds.OffsetFromOrigin(), | 172 DrawWindowTree(pass, child, absolute_bounds.OffsetFromOrigin(), |
| 171 combined_opacity, may_contain_video); | 173 combined_opacity, may_contain_video); |
| 172 } | 174 } |
| 173 | 175 |
| 174 if (!window->surface_manager() || !window->surface_manager()->ShouldDraw()) | 176 if (!window->compositor_frame_sink_manager() || |
| 177 !window->compositor_frame_sink_manager()->ShouldDraw()) |
| 175 return; | 178 return; |
| 176 | 179 |
| 177 ServerWindowSurface* underlay_surface = | 180 ServerWindowCompositorFrameSink* underlay_compositor_frame_sink = |
| 178 window->surface_manager()->GetUnderlaySurface(); | 181 window->compositor_frame_sink_manager()->GetUnderlayCompositorFrameSink(); |
| 179 if (!default_surface && !underlay_surface) | 182 if (!default_compositor_frame_sink && !underlay_compositor_frame_sink) |
| 180 return; | 183 return; |
| 181 | 184 |
| 182 if (default_surface) { | 185 if (default_compositor_frame_sink) { |
| 183 gfx::Transform quad_to_target_transform; | 186 gfx::Transform quad_to_target_transform; |
| 184 quad_to_target_transform.Translate(absolute_bounds.x(), | 187 quad_to_target_transform.Translate(absolute_bounds.x(), |
| 185 absolute_bounds.y()); | 188 absolute_bounds.y()); |
| 186 | 189 |
| 187 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 190 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 188 | 191 |
| 189 const gfx::Rect bounds_at_origin(window->bounds().size()); | 192 const gfx::Rect bounds_at_origin(window->bounds().size()); |
| 190 // TODO(fsamuel): These clipping and visible rects are incorrect. They need | 193 // TODO(fsamuel): These clipping and visible rects are incorrect. They need |
| 191 // to be populated from CompositorFrame structs. | 194 // to be populated from CompositorFrame structs. |
| 192 sqs->SetAll(quad_to_target_transform, | 195 sqs->SetAll(quad_to_target_transform, |
| 193 bounds_at_origin.size() /* layer_bounds */, | 196 bounds_at_origin.size() /* layer_bounds */, |
| 194 bounds_at_origin /* visible_layer_bounds */, | 197 bounds_at_origin /* visible_layer_bounds */, |
| 195 bounds_at_origin /* clip_rect */, false /* is_clipped */, | 198 bounds_at_origin /* clip_rect */, false /* is_clipped */, |
| 196 combined_opacity, SkXfermode::kSrcOver_Mode, | 199 combined_opacity, SkXfermode::kSrcOver_Mode, |
| 197 0 /* sorting-context_id */); | 200 0 /* sorting-context_id */); |
| 198 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 201 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 199 AddOrUpdateSurfaceReference(default_surface); | 202 AddOrUpdateSurfaceReference(default_compositor_frame_sink); |
| 200 quad->SetAll(sqs, bounds_at_origin /* rect */, | 203 quad->SetAll(sqs, bounds_at_origin /* rect */, |
| 201 gfx::Rect() /* opaque_rect */, | 204 gfx::Rect() /* opaque_rect */, |
| 202 bounds_at_origin /* visible_rect */, true /* needs_blending*/, | 205 bounds_at_origin /* visible_rect */, true /* needs_blending*/, |
| 203 default_surface->GetSurfaceId()); | 206 default_compositor_frame_sink->GetSurfaceId()); |
| 204 if (default_surface->may_contain_video()) | 207 if (default_compositor_frame_sink->may_contain_video()) |
| 205 *may_contain_video = true; | 208 *may_contain_video = true; |
| 206 } | 209 } |
| 207 if (underlay_surface) { | 210 if (underlay_compositor_frame_sink) { |
| 208 const gfx::Rect underlay_absolute_bounds = | 211 const gfx::Rect underlay_absolute_bounds = |
| 209 absolute_bounds - window->underlay_offset(); | 212 absolute_bounds - window->underlay_offset(); |
| 210 gfx::Transform quad_to_target_transform; | 213 gfx::Transform quad_to_target_transform; |
| 211 quad_to_target_transform.Translate(underlay_absolute_bounds.x(), | 214 quad_to_target_transform.Translate(underlay_absolute_bounds.x(), |
| 212 underlay_absolute_bounds.y()); | 215 underlay_absolute_bounds.y()); |
| 213 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 216 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 214 const gfx::Rect bounds_at_origin( | 217 const gfx::Rect bounds_at_origin( |
| 215 underlay_surface->last_submitted_frame_size()); | 218 underlay_compositor_frame_sink->last_submitted_frame_size()); |
| 216 sqs->SetAll(quad_to_target_transform, | 219 sqs->SetAll(quad_to_target_transform, |
| 217 bounds_at_origin.size() /* layer_bounds */, | 220 bounds_at_origin.size() /* layer_bounds */, |
| 218 bounds_at_origin /* visible_layer_bounds */, | 221 bounds_at_origin /* visible_layer_bounds */, |
| 219 bounds_at_origin /* clip_rect */, false /* is_clipped */, | 222 bounds_at_origin /* clip_rect */, false /* is_clipped */, |
| 220 combined_opacity, SkXfermode::kSrcOver_Mode, | 223 combined_opacity, SkXfermode::kSrcOver_Mode, |
| 221 0 /* sorting-context_id */); | 224 0 /* sorting-context_id */); |
| 222 | 225 |
| 223 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 226 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 224 AddOrUpdateSurfaceReference(underlay_surface); | 227 AddOrUpdateSurfaceReference(underlay_compositor_frame_sink); |
| 225 quad->SetAll(sqs, bounds_at_origin /* rect */, | 228 quad->SetAll(sqs, bounds_at_origin /* rect */, |
| 226 gfx::Rect() /* opaque_rect */, | 229 gfx::Rect() /* opaque_rect */, |
| 227 bounds_at_origin /* visible_rect */, true /* needs_blending*/, | 230 bounds_at_origin /* visible_rect */, true /* needs_blending*/, |
| 228 underlay_surface->GetSurfaceId()); | 231 underlay_compositor_frame_sink->GetSurfaceId()); |
| 229 DCHECK(!underlay_surface->may_contain_video()); | 232 DCHECK(!underlay_compositor_frame_sink->may_contain_video()); |
| 230 } | 233 } |
| 231 } | 234 } |
| 232 | 235 |
| 233 void FrameGenerator::AddOrUpdateSurfaceReference( | 236 void FrameGenerator::AddOrUpdateSurfaceReference( |
| 234 ServerWindowSurface* window_surface) { | 237 ServerWindowCompositorFrameSink* window_surface) { |
| 235 if (!window_surface->has_frame()) | 238 if (!window_surface->has_frame()) |
| 236 return; | 239 return; |
| 237 cc::SurfaceId surface_id = window_surface->GetSurfaceId(); | 240 cc::SurfaceId surface_id = window_surface->GetSurfaceId(); |
| 238 cc::SurfaceManager* surface_manager = display_compositor_->manager(); | 241 cc::SurfaceManager* surface_manager = display_compositor_->manager(); |
| 239 auto it = dependencies_.find(surface_id.frame_sink_id()); | 242 auto it = dependencies_.find(surface_id.frame_sink_id()); |
| 240 if (it == dependencies_.end()) { | 243 if (it == dependencies_.end()) { |
| 241 cc::Surface* surface = surface_manager->GetSurfaceForId(surface_id); | 244 cc::Surface* surface = surface_manager->GetSurfaceForId(surface_id); |
| 242 if (!surface) { | 245 if (!surface) { |
| 243 LOG(ERROR) << "Attempting to add dependency to nonexistent surface " | 246 LOG(ERROR) << "Attempting to add dependency to nonexistent surface " |
| 244 << surface_id.ToString(); | 247 << surface_id.ToString(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 cc::SurfaceManager* surface_manager = display_compositor_->manager(); | 294 cc::SurfaceManager* surface_manager = display_compositor_->manager(); |
| 292 std::vector<uint32_t> sequences; | 295 std::vector<uint32_t> sequences; |
| 293 for (auto& dependency : dependencies_) | 296 for (auto& dependency : dependencies_) |
| 294 sequences.push_back(dependency.second.sequence.sequence); | 297 sequences.push_back(dependency.second.sequence.sequence); |
| 295 surface_manager->DidSatisfySequences(frame_sink_id_, &sequences); | 298 surface_manager->DidSatisfySequences(frame_sink_id_, &sequences); |
| 296 dependencies_.clear(); | 299 dependencies_.clear(); |
| 297 } | 300 } |
| 298 | 301 |
| 299 void FrameGenerator::OnWindowDestroying(ServerWindow* window) { | 302 void FrameGenerator::OnWindowDestroying(ServerWindow* window) { |
| 300 window->RemoveObserver(this); | 303 window->RemoveObserver(this); |
| 301 ServerWindowSurfaceManager* surface_manager = window->surface_manager(); | 304 ServerWindowCompositorFrameSinkManager* surface_manager = |
| 305 window->compositor_frame_sink_manager(); |
| 302 // If FrameGenerator was observing |window|, then that means it had a surface | 306 // If FrameGenerator was observing |window|, then that means it had a surface |
| 303 // at some point in time and should have a ServerWindowSurfaceManager. | 307 // at some point in time and should have a |
| 308 // ServerWindowCompositorFrameSinkManager. |
| 304 DCHECK(surface_manager); | 309 DCHECK(surface_manager); |
| 305 ServerWindowSurface* default_surface = surface_manager->GetDefaultSurface(); | 310 ServerWindowCompositorFrameSink* default_compositor_frame_sink = |
| 306 if (default_surface) | 311 surface_manager->GetDefaultCompositorFrameSink(); |
| 307 ReleaseFrameSinkReference(default_surface->frame_sink_id()); | 312 if (default_compositor_frame_sink) |
| 308 ServerWindowSurface* underlay_surface = surface_manager->GetUnderlaySurface(); | 313 ReleaseFrameSinkReference(default_compositor_frame_sink->frame_sink_id()); |
| 309 if (underlay_surface) | 314 ServerWindowCompositorFrameSink* underlay_compositor_frame_sink = |
| 310 ReleaseFrameSinkReference(underlay_surface->frame_sink_id()); | 315 surface_manager->GetUnderlayCompositorFrameSink(); |
| 316 if (underlay_compositor_frame_sink) |
| 317 ReleaseFrameSinkReference(underlay_compositor_frame_sink->frame_sink_id()); |
| 311 } | 318 } |
| 312 | 319 |
| 313 } // namespace ws | 320 } // namespace ws |
| 314 | 321 |
| 315 } // namespace ui | 322 } // namespace ui |
| OLD | NEW |