Chromium Code Reviews| 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" | |
| 15 #include "services/ui/surfaces/display_compositor.h" | |
| 16 #include "services/ui/surfaces/surfaces_context_provider.h" | |
| 17 #include "services/ui/ws/frame_generator_delegate.h" | 14 #include "services/ui/ws/frame_generator_delegate.h" |
| 18 #include "services/ui/ws/server_window.h" | 15 #include "services/ui/ws/server_window.h" |
| 19 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" | 16 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 20 #include "services/ui/ws/server_window_delegate.h" | 17 #include "services/ui/ws/server_window_delegate.h" |
| 21 | 18 |
| 22 namespace ui { | 19 namespace ui { |
| 23 | 20 |
| 24 namespace ws { | 21 namespace ws { |
| 25 | 22 |
| 26 FrameGenerator::FrameGenerator(FrameGeneratorDelegate* delegate, | 23 FrameGenerator::FrameGenerator(FrameGeneratorDelegate* delegate, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 37 } | 34 } |
| 38 | 35 |
| 39 FrameGenerator::~FrameGenerator() { | 36 FrameGenerator::~FrameGenerator() { |
| 40 ReleaseAllSurfaceReferences(); | 37 ReleaseAllSurfaceReferences(); |
| 41 // Invalidate WeakPtrs now to avoid callbacks back into the | 38 // Invalidate WeakPtrs now to avoid callbacks back into the |
| 42 // FrameGenerator during destruction of |compositor_frame_sink_|. | 39 // FrameGenerator during destruction of |compositor_frame_sink_|. |
| 43 weak_factory_.InvalidateWeakPtrs(); | 40 weak_factory_.InvalidateWeakPtrs(); |
| 44 compositor_frame_sink_.reset(); | 41 compositor_frame_sink_.reset(); |
| 45 } | 42 } |
| 46 | 43 |
| 47 void FrameGenerator::OnGpuChannelEstablished( | |
| 48 scoped_refptr<gpu::GpuChannelHost> channel) { | |
| 49 if (widget_ != gfx::kNullAcceleratedWidget) { | |
| 50 cc::mojom::MojoCompositorFrameSinkRequest request = | |
| 51 mojo::GetProxy(&compositor_frame_sink_); | |
| 52 // TODO(fsamuel): FrameGenerator should not know about | |
| 53 // SurfacesContextProvider. In fact, FrameGenerator should not know | |
| 54 // about GpuChannelHost. | |
| 55 root_window_->CreateCompositorFrameSink( | |
| 56 mojom::CompositorFrameSinkType::DEFAULT, widget_, | |
| 57 channel->gpu_memory_buffer_manager(), | |
| 58 new SurfacesContextProvider(widget_, channel), std::move(request), | |
| 59 binding_.CreateInterfacePtrAndBind()); | |
| 60 // TODO(fsamuel): This means we're always requesting a new BeginFrame signal | |
| 61 // even when we don't need it. Once surface ID propagation work is done, | |
| 62 // this will not be necessary because FrameGenerator will only need a | |
| 63 // BeginFrame if the window manager changes. | |
| 64 compositor_frame_sink_->SetNeedsBeginFrame(true); | |
| 65 } else { | |
| 66 gpu_channel_ = std::move(channel); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 void FrameGenerator::OnAcceleratedWidgetAvailable( | 44 void FrameGenerator::OnAcceleratedWidgetAvailable( |
| 71 gfx::AcceleratedWidget widget) { | 45 gfx::AcceleratedWidget widget) { |
| 72 widget_ = widget; | 46 DCHECK(widget != gfx::kNullAcceleratedWidget); |
|
sadrul
2016/11/21 17:23:49
DCHECK_NE
Fady Samuel
2016/11/21 20:40:41
Done.
| |
| 73 if (gpu_channel_ && widget != gfx::kNullAcceleratedWidget) { | 47 cc::mojom::MojoCompositorFrameSinkRequest request = |
| 74 cc::mojom::MojoCompositorFrameSinkRequest request = | 48 mojo::GetProxy(&compositor_frame_sink_); |
| 75 mojo::GetProxy(&compositor_frame_sink_); | 49 root_window_->CreateCompositorFrameSink( |
| 76 root_window_->CreateCompositorFrameSink( | 50 mojom::CompositorFrameSinkType::DEFAULT, widget, std::move(request), |
| 77 mojom::CompositorFrameSinkType::DEFAULT, widget_, | 51 binding_.CreateInterfacePtrAndBind()); |
| 78 gpu_channel_->gpu_memory_buffer_manager(), | 52 // TODO(fsamuel): This means we're always requesting a new BeginFrame signal |
| 79 new SurfacesContextProvider(widget_, gpu_channel_), | 53 // even when we don't need it. Once surface ID propagation work is done, |
| 80 std::move(request), binding_.CreateInterfacePtrAndBind()); | 54 // this will not be necessary because FrameGenerator will only need a |
| 81 // TODO(fsamuel): This means we're always requesting a new BeginFrame signal | 55 // BeginFrame if the window manager changes. |
| 82 // even when we don't need it. Once surface ID propagation work is done, | 56 compositor_frame_sink_->SetNeedsBeginFrame(true); |
| 83 // this will not be necessary because FrameGenerator will only need a | |
| 84 // BeginFrame if the window manager changes. | |
| 85 compositor_frame_sink_->SetNeedsBeginFrame(true); | |
| 86 } | |
| 87 } | 57 } |
| 88 | 58 |
| 89 void FrameGenerator::DidReceiveCompositorFrameAck() {} | 59 void FrameGenerator::DidReceiveCompositorFrameAck() {} |
| 90 | 60 |
| 91 void FrameGenerator::OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) { | 61 void FrameGenerator::OnBeginFrame(const cc::BeginFrameArgs& begin_frame_arags) { |
| 92 if (!root_window_->visible()) | 62 if (!root_window_->visible()) |
| 93 return; | 63 return; |
| 94 | 64 |
| 95 // TODO(fsamuel): We should add a trace for generating a top level frame. | 65 // TODO(fsamuel): We should add a trace for generating a top level frame. |
| 96 cc::CompositorFrame frame(GenerateCompositorFrame(root_window_->bounds())); | 66 cc::CompositorFrame frame(GenerateCompositorFrame(root_window_->bounds())); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 } | 242 } |
| 273 | 243 |
| 274 void FrameGenerator::ReleaseAllSurfaceReferences() { | 244 void FrameGenerator::ReleaseAllSurfaceReferences() { |
| 275 std::vector<uint32_t> sequences; | 245 std::vector<uint32_t> sequences; |
| 276 for (auto& dependency : dependencies_) | 246 for (auto& dependency : dependencies_) |
| 277 sequences.push_back(dependency.second.sequence.sequence); | 247 sequences.push_back(dependency.second.sequence.sequence); |
| 278 GetDisplayCompositor()->ReturnSurfaceReferences(frame_sink_id_, sequences); | 248 GetDisplayCompositor()->ReturnSurfaceReferences(frame_sink_id_, sequences); |
| 279 dependencies_.clear(); | 249 dependencies_.clear(); |
| 280 } | 250 } |
| 281 | 251 |
| 282 ui::DisplayCompositor* FrameGenerator::GetDisplayCompositor() { | 252 cc::mojom::DisplayCompositor* FrameGenerator::GetDisplayCompositor() { |
| 283 return root_window_->delegate()->GetDisplayCompositor(); | 253 return root_window_->delegate()->GetDisplayCompositor(); |
| 284 } | 254 } |
| 285 | 255 |
| 286 void FrameGenerator::OnWindowDestroying(ServerWindow* window) { | 256 void FrameGenerator::OnWindowDestroying(ServerWindow* window) { |
| 287 Remove(window); | 257 Remove(window); |
| 288 ServerWindowCompositorFrameSinkManager* compositor_frame_sink_manager = | 258 ServerWindowCompositorFrameSinkManager* compositor_frame_sink_manager = |
| 289 window->compositor_frame_sink_manager(); | 259 window->compositor_frame_sink_manager(); |
| 290 // If FrameGenerator was observing |window|, then that means it had a | 260 // If FrameGenerator was observing |window|, then that means it had a |
| 291 // CompositorFrame at some point in time and should have a | 261 // CompositorFrame at some point in time and should have a |
| 292 // ServerWindowCompositorFrameSinkManager. | 262 // ServerWindowCompositorFrameSinkManager. |
| 293 DCHECK(compositor_frame_sink_manager); | 263 DCHECK(compositor_frame_sink_manager); |
| 294 | 264 |
| 295 cc::SurfaceId default_surface_id = | 265 cc::SurfaceId default_surface_id = |
| 296 window->compositor_frame_sink_manager()->GetLatestSurfaceId( | 266 window->compositor_frame_sink_manager()->GetLatestSurfaceId( |
| 297 mojom::CompositorFrameSinkType::DEFAULT); | 267 mojom::CompositorFrameSinkType::DEFAULT); |
| 298 if (default_surface_id.is_valid()) | 268 if (default_surface_id.is_valid()) |
| 299 ReleaseFrameSinkReference(default_surface_id.frame_sink_id()); | 269 ReleaseFrameSinkReference(default_surface_id.frame_sink_id()); |
| 300 | 270 |
| 301 cc::SurfaceId underlay_surface_id = | 271 cc::SurfaceId underlay_surface_id = |
| 302 window->compositor_frame_sink_manager()->GetLatestSurfaceId( | 272 window->compositor_frame_sink_manager()->GetLatestSurfaceId( |
| 303 mojom::CompositorFrameSinkType::UNDERLAY); | 273 mojom::CompositorFrameSinkType::UNDERLAY); |
| 304 if (underlay_surface_id.is_valid()) | 274 if (underlay_surface_id.is_valid()) |
| 305 ReleaseFrameSinkReference(underlay_surface_id.frame_sink_id()); | 275 ReleaseFrameSinkReference(underlay_surface_id.frame_sink_id()); |
| 306 } | 276 } |
| 307 | 277 |
| 308 } // namespace ws | 278 } // namespace ws |
| 309 | 279 |
| 310 } // namespace ui | 280 } // namespace ui |
| OLD | NEW |