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 #ifndef SERVICES_UI_WS_FRAME_GENERATOR_H_ | 5 #ifndef SERVICES_UI_WS_FRAME_GENERATOR_H_ |
| 6 #define SERVICES_UI_WS_FRAME_GENERATOR_H_ | 6 #define SERVICES_UI_WS_FRAME_GENERATOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <unordered_map> | |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 12 #include "cc/surfaces/frame_sink_id.h" | 13 #include "cc/surfaces/frame_sink_id.h" |
| 14 #include "cc/surfaces/local_frame_id.h" | |
| 15 #include "cc/surfaces/surface_sequence.h" | |
| 16 #include "cc/surfaces/surface_sequence_generator.h" | |
| 17 #include "services/ui/ws/server_window_observer.h" | |
| 13 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 14 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
| 15 | 20 |
| 16 namespace cc { | 21 namespace cc { |
| 17 class CompositorFrame; | 22 class CompositorFrame; |
| 18 class CopyOutputRequest; | 23 class CopyOutputRequest; |
| 19 class RenderPass; | 24 class RenderPass; |
| 25 class SurfaceId; | |
| 20 } | 26 } |
| 21 | 27 |
| 22 namespace gpu { | 28 namespace gpu { |
| 23 class GpuChannelHost; | 29 class GpuChannelHost; |
| 24 } | 30 } |
| 25 | 31 |
| 26 namespace ui { | 32 namespace ui { |
| 27 | 33 |
| 28 namespace surfaces { | 34 namespace surfaces { |
| 29 class CompositorFrameSink; | 35 class CompositorFrameSink; |
| 30 } | 36 } |
| 31 | 37 |
| 32 class DisplayCompositor; | 38 class DisplayCompositor; |
| 33 | 39 |
| 34 namespace ws { | 40 namespace ws { |
| 35 | 41 |
| 36 namespace test { | 42 namespace test { |
| 37 class FrameGeneratorTest; | 43 class FrameGeneratorTest; |
| 38 } | 44 } |
| 39 | 45 |
| 40 class FrameGeneratorDelegate; | 46 class FrameGeneratorDelegate; |
| 41 class ServerWindow; | 47 class ServerWindow; |
| 48 class ServerWindowSurface; | |
| 42 | 49 |
| 43 // Responsible for redrawing the display in response to the redraw requests by | 50 // Responsible for redrawing the display in response to the redraw requests by |
| 44 // submitting CompositorFrames to the owned CompositorFrameSink. | 51 // submitting CompositorFrames to the owned CompositorFrameSink. |
| 45 class FrameGenerator { | 52 class FrameGenerator : public ServerWindowObserver { |
| 46 public: | 53 public: |
| 47 FrameGenerator(FrameGeneratorDelegate* delegate, | 54 FrameGenerator(FrameGeneratorDelegate* delegate, |
| 48 scoped_refptr<DisplayCompositor> display_compositor); | 55 scoped_refptr<DisplayCompositor> display_compositor); |
| 49 virtual ~FrameGenerator(); | 56 ~FrameGenerator() override; |
| 50 | 57 |
| 51 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); | 58 void OnGpuChannelEstablished(scoped_refptr<gpu::GpuChannelHost> gpu_channel); |
| 52 | 59 |
| 53 // Schedules a redraw for the provided region. | 60 // Schedules a redraw for the provided region. |
| 54 void RequestRedraw(const gfx::Rect& redraw_region); | 61 void RequestRedraw(const gfx::Rect& redraw_region); |
| 55 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget); | 62 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget); |
| 56 void RequestCopyOfOutput( | 63 void RequestCopyOfOutput( |
| 57 std::unique_ptr<cc::CopyOutputRequest> output_request); | 64 std::unique_ptr<cc::CopyOutputRequest> output_request); |
| 58 | 65 |
| 59 bool is_frame_pending() { return frame_pending_; } | 66 bool is_frame_pending() { return frame_pending_; } |
| 60 | 67 |
| 61 private: | 68 private: |
| 62 friend class ui::ws::test::FrameGeneratorTest; | 69 friend class ui::ws::test::FrameGeneratorTest; |
| 63 | 70 |
| 64 void WantToDraw(); | 71 void WantToDraw(); |
| 65 | 72 |
| 66 // This method initiates a top level redraw of the display. | 73 // This method initiates a top level redraw of the display. |
| 67 // TODO(fsamuel): This should use vblank as a signal rather than a timer | 74 // TODO(fsamuel): This should use vblank as a signal rather than a timer |
| 68 // http://crbug.com/533042 | 75 // http://crbug.com/533042 |
| 69 void Draw(); | 76 void Draw(); |
|
rjkroege
2016/10/07 19:34:50
there's something not right about this comment? Or
Fady Samuel
2016/10/07 20:31:33
We're not there yet. That's once all my code and S
rjkroege
2016/10/07 20:48:13
please update the TODO for the brave polliwog worl
| |
| 70 | 77 |
| 71 // This is called after the CompositorFrameSink has completed generating a new | 78 // This is called after the CompositorFrameSink has completed generating a new |
| 72 // frame for the display. TODO(fsamuel): Idle time processing should happen | 79 // frame for the display. TODO(fsamuel): Idle time processing should happen |
| 73 // here if there is budget for it. | 80 // here if there is budget for it. |
| 74 void DidDraw(); | 81 void DidDraw(); |
| 75 | 82 |
| 76 // Generates the CompositorFrame for the current |dirty_rect_|. | 83 // Generates the CompositorFrame for the current |dirty_rect_|. |
| 77 cc::CompositorFrame GenerateCompositorFrame( | 84 cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect); |
| 78 const gfx::Rect& output_rect) const; | |
| 79 | 85 |
| 80 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad | 86 // DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad |
| 81 // for each that lacks one. | 87 // for each that lacks one. |
| 82 void DrawWindowTree(cc::RenderPass* pass, | 88 void DrawWindowTree(cc::RenderPass* pass, |
| 83 ServerWindow* window, | 89 ServerWindow* window, |
| 84 const gfx::Vector2d& parent_to_root_origin_offset, | 90 const gfx::Vector2d& parent_to_root_origin_offset, |
| 85 float opacity, | 91 float opacity, |
| 86 bool* may_contain_video) const; | 92 bool* may_contain_video); |
| 93 | |
| 94 // Adds a reference to the current cc::Surface of the provided | |
| 95 // |window_surface|. If an existing reference is held with a different | |
| 96 // LocalFrameId then release that reference first. | |
|
rjkroege
2016/10/07 19:34:50
the arg is surface. not window_surface? Something
Fady Samuel
2016/10/07 20:31:33
Done.
| |
| 97 void AddOrUpdateSurfaceReference(ServerWindowSurface* surface); | |
|
rjkroege
2016/10/07 19:34:50
can you say why/when we should call this?
Fady Samuel
2016/10/07 20:31:33
Done.
| |
| 98 | |
| 99 // Releases any retained references for the provided FrameSink. | |
| 100 void ReleaseFrameSinkReference(const cc::FrameSinkId& frame_sink_id); | |
| 101 | |
| 102 // Releases all retained references to surfaces. | |
| 103 void ReleaseAllSurfaceReferences(); | |
| 104 | |
| 105 // ServerWindowObserver implementation. | |
| 106 void OnWindowDestroying(ServerWindow* window) override; | |
| 87 | 107 |
| 88 FrameGeneratorDelegate* delegate_; | 108 FrameGeneratorDelegate* delegate_; |
| 89 scoped_refptr<DisplayCompositor> display_compositor_; | 109 scoped_refptr<DisplayCompositor> display_compositor_; |
| 90 cc::FrameSinkId frame_sink_id_; | 110 cc::FrameSinkId frame_sink_id_; |
| 111 cc::SurfaceSequenceGenerator surface_sequence_generator_; | |
| 91 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; | 112 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
| 92 | 113 |
| 93 std::unique_ptr<surfaces::CompositorFrameSink> compositor_frame_sink_; | 114 std::unique_ptr<surfaces::CompositorFrameSink> compositor_frame_sink_; |
| 94 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; | 115 gfx::AcceleratedWidget widget_ = gfx::kNullAcceleratedWidget; |
| 95 | 116 |
| 96 // The region that needs to be redrawn next time the compositor frame is | 117 // The region that needs to be redrawn next time the compositor frame is |
| 97 // generated. | 118 // generated. |
| 98 gfx::Rect dirty_rect_; | 119 gfx::Rect dirty_rect_; |
| 99 base::Timer draw_timer_; | 120 base::Timer draw_timer_; |
| 100 bool frame_pending_ = false; | 121 bool frame_pending_ = false; |
| 101 bool may_contain_video_ = false; | 122 bool may_contain_video_ = false; |
| 123 struct SurfaceDependency { | |
| 124 cc::LocalFrameId local_frame_id; | |
| 125 cc::SurfaceSequence sequence; | |
| 126 }; | |
| 127 std::unordered_map<cc::FrameSinkId, SurfaceDependency, cc::FrameSinkIdHash> | |
| 128 dependencies_; | |
| 102 | 129 |
| 103 base::WeakPtrFactory<FrameGenerator> weak_factory_; | 130 base::WeakPtrFactory<FrameGenerator> weak_factory_; |
| 104 | 131 |
| 105 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); | 132 DISALLOW_COPY_AND_ASSIGN(FrameGenerator); |
| 106 }; | 133 }; |
| 107 | 134 |
| 108 } // namespace ws | 135 } // namespace ws |
| 109 | 136 |
| 110 } // namespace ui | 137 } // namespace ui |
| 111 | 138 |
| 112 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ | 139 #endif // SERVICES_UI_WS_FRAME_GENERATOR_H_ |
| OLD | NEW |