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 "services/ui/gpu/gpu_service_internal.h" | 13 #include "gpu/ipc/client/gpu_channel_host.h" |
14 #include "services/ui/surfaces/display_compositor.h" | 14 #include "services/ui/surfaces/display_compositor.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(FrameGeneratorDelegate* delegate, |
25 scoped_refptr<SurfacesState> surfaces_state) | 25 scoped_refptr<SurfacesState> surfaces_state) |
26 : delegate_(delegate), | 26 : delegate_(delegate), |
27 surfaces_state_(surfaces_state), | 27 surfaces_state_(surfaces_state), |
28 draw_timer_(false, false), | 28 draw_timer_(false, false), |
29 weak_factory_(this) { | 29 weak_factory_(this) { |
30 DCHECK(delegate_); | 30 DCHECK(delegate_); |
31 } | 31 } |
32 | 32 |
33 FrameGenerator::~FrameGenerator() { | 33 FrameGenerator::~FrameGenerator() { |
34 // Invalidate WeakPtrs now to avoid callbacks back into the | 34 // Invalidate WeakPtrs now to avoid callbacks back into the |
35 // FrameGenerator during destruction of |display_compositor_|. | 35 // FrameGenerator during destruction of |display_compositor_|. |
36 weak_factory_.InvalidateWeakPtrs(); | 36 weak_factory_.InvalidateWeakPtrs(); |
37 display_compositor_.reset(); | 37 display_compositor_.reset(); |
38 } | 38 } |
39 | 39 |
| 40 void FrameGenerator::OnGpuChannelEstablished( |
| 41 scoped_refptr<gpu::GpuChannelHost> channel) { |
| 42 if (widget_ != gfx::kNullAcceleratedWidget) { |
| 43 display_compositor_.reset( |
| 44 new DisplayCompositor(base::ThreadTaskRunnerHandle::Get(), widget_, |
| 45 std::move(channel), surfaces_state_)); |
| 46 } else { |
| 47 gpu_channel_ = std::move(channel); |
| 48 } |
| 49 } |
| 50 |
40 void FrameGenerator::RequestRedraw(const gfx::Rect& redraw_region) { | 51 void FrameGenerator::RequestRedraw(const gfx::Rect& redraw_region) { |
41 dirty_rect_.Union(redraw_region); | 52 dirty_rect_.Union(redraw_region); |
42 WantToDraw(); | 53 WantToDraw(); |
43 } | 54 } |
44 | 55 |
45 void FrameGenerator::OnAcceleratedWidgetAvailable( | 56 void FrameGenerator::OnAcceleratedWidgetAvailable( |
46 gfx::AcceleratedWidget widget) { | 57 gfx::AcceleratedWidget widget) { |
47 if (widget != gfx::kNullAcceleratedWidget) { | 58 widget_ = widget; |
48 display_compositor_.reset(new DisplayCompositor( | 59 if (gpu_channel_ && widget != gfx::kNullAcceleratedWidget) { |
49 base::ThreadTaskRunnerHandle::Get(), widget, | 60 display_compositor_.reset( |
50 GpuServiceInternal::GetInstance()->gpu_channel_local(), | 61 new DisplayCompositor(base::ThreadTaskRunnerHandle::Get(), widget_, |
51 surfaces_state_)); | 62 std::move(gpu_channel_), surfaces_state_)); |
52 } | 63 } |
53 } | 64 } |
54 | 65 |
55 void FrameGenerator::RequestCopyOfOutput( | 66 void FrameGenerator::RequestCopyOfOutput( |
56 std::unique_ptr<cc::CopyOutputRequest> output_request) { | 67 std::unique_ptr<cc::CopyOutputRequest> output_request) { |
57 if (display_compositor_) | 68 if (display_compositor_) |
58 display_compositor_->RequestCopyOfOutput(std::move(output_request)); | 69 display_compositor_->RequestCopyOfOutput(std::move(output_request)); |
59 } | 70 } |
60 | 71 |
61 void FrameGenerator::WantToDraw() { | 72 void FrameGenerator::WantToDraw() { |
(...skipping 16 matching lines...) Expand all Loading... |
78 // TODO(fsamuel): We should add a trace for generating a top level frame. | 89 // TODO(fsamuel): We should add a trace for generating a top level frame. |
79 cc::CompositorFrame frame(GenerateCompositorFrame(output_rect)); | 90 cc::CompositorFrame frame(GenerateCompositorFrame(output_rect)); |
80 if (frame.metadata.may_contain_video != may_contain_video_) { | 91 if (frame.metadata.may_contain_video != may_contain_video_) { |
81 may_contain_video_ = frame.metadata.may_contain_video; | 92 may_contain_video_ = frame.metadata.may_contain_video; |
82 // TODO(sad): Schedule notifying observers. | 93 // TODO(sad): Schedule notifying observers. |
83 if (may_contain_video_) { | 94 if (may_contain_video_) { |
84 // TODO(sad): Start a timer to reset the bit if no new frame with video | 95 // TODO(sad): Start a timer to reset the bit if no new frame with video |
85 // is submitted 'soon'. | 96 // is submitted 'soon'. |
86 } | 97 } |
87 } | 98 } |
88 frame_pending_ = true; | |
89 if (display_compositor_) { | 99 if (display_compositor_) { |
| 100 frame_pending_ = true; |
90 display_compositor_->SubmitCompositorFrame( | 101 display_compositor_->SubmitCompositorFrame( |
91 std::move(frame), | 102 std::move(frame), |
92 base::Bind(&FrameGenerator::DidDraw, weak_factory_.GetWeakPtr())); | 103 base::Bind(&FrameGenerator::DidDraw, weak_factory_.GetWeakPtr())); |
93 } | 104 } |
94 dirty_rect_ = gfx::Rect(); | 105 dirty_rect_ = gfx::Rect(); |
95 } | 106 } |
96 | 107 |
97 void FrameGenerator::DidDraw() { | 108 void FrameGenerator::DidDraw() { |
98 frame_pending_ = false; | 109 frame_pending_ = false; |
99 delegate_->OnCompositorFrameDrawn(); | 110 delegate_->OnCompositorFrameDrawn(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 gfx::Rect() /* opaque_rect */, | 226 gfx::Rect() /* opaque_rect */, |
216 bounds_at_origin /* visible_rect */, true /* needs_blending*/, | 227 bounds_at_origin /* visible_rect */, true /* needs_blending*/, |
217 underlay_surface->id()); | 228 underlay_surface->id()); |
218 DCHECK(!underlay_surface->may_contain_video()); | 229 DCHECK(!underlay_surface->may_contain_video()); |
219 } | 230 } |
220 } | 231 } |
221 | 232 |
222 } // namespace ws | 233 } // namespace ws |
223 | 234 |
224 } // namespace ui | 235 } // namespace ui |
OLD | NEW |