| 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<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_ = base::MakeUnique<DisplayCompositor>( | 44 compositor_frame_sink_ = base::MakeUnique<surfaces::CompositorFrameSink>( |
| 44 base::ThreadTaskRunnerHandle::Get(), widget_, std::move(channel), | 45 base::ThreadTaskRunnerHandle::Get(), widget_, std::move(channel), |
| 45 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.pixel_size); | 88 const gfx::Rect output_rect(metrics.pixel_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()) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 gfx::Rect() /* opaque_rect */, | 228 gfx::Rect() /* opaque_rect */, |
| 228 bounds_at_origin /* visible_rect */, true /* needs_blending*/, | 229 bounds_at_origin /* visible_rect */, true /* needs_blending*/, |
| 229 underlay_surface->id()); | 230 underlay_surface->id()); |
| 230 DCHECK(!underlay_surface->may_contain_video()); | 231 DCHECK(!underlay_surface->may_contain_video()); |
| 231 } | 232 } |
| 232 } | 233 } |
| 233 | 234 |
| 234 } // namespace ws | 235 } // namespace ws |
| 235 | 236 |
| 236 } // namespace ui | 237 } // namespace ui |
| OLD | NEW |