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 CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ | 5 #ifndef CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ |
6 #define CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ | 6 #define CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
11 #include "cc/scheduler/begin_frame_source.h" | 11 #include "cc/scheduler/begin_frame_source.h" |
12 #include "cc/surfaces/display.h" | 12 #include "cc/surfaces/display.h" |
13 #include "cc/surfaces/display_client.h" | 13 #include "cc/surfaces/display_client.h" |
14 #include "cc/surfaces/surface_factory.h" | 14 #include "cc/surfaces/surface_factory.h" |
15 #include "cc/surfaces/surface_factory_client.h" | 15 #include "cc/surfaces/surface_factory_client.h" |
16 #include "cc/surfaces/surfaces_export.h" | 16 #include "cc/surfaces/surfaces_export.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 class CompositorFrameSinkSupportClient; | 20 class CompositorFrameSinkSupportClient; |
21 class Display; | 21 class Display; |
22 class SurfaceManager; | 22 class SurfaceManager; |
23 | 23 |
24 class CC_SURFACES_EXPORT CompositorFrameSinkSupport | 24 class CC_SURFACES_EXPORT CompositorFrameSinkSupport |
25 : public NON_EXPORTED_BASE(DisplayClient), | 25 : public NON_EXPORTED_BASE(DisplayClient), |
26 public SurfaceFactoryClient, | 26 public SurfaceFactoryClient, |
27 public BeginFrameObserver { | 27 public BeginFrameObserver { |
28 public: | 28 public: |
29 // |display| is nullptr if the CompositorFrameSinkSupport submits | 29 CompositorFrameSinkSupport( |
30 // CompositorFrames to a offscreen texutre/bitmap instead of a | 30 CompositorFrameSinkSupportClient* client, |
31 // DisplayCompositor. e.g. OffscreenCanvasCompositorFrameSink and | 31 SurfaceManager* surface_manager, |
32 // GpuOffscreenCompositorFrameSink. | 32 const FrameSinkId& frame_sink_id, |
33 CompositorFrameSinkSupport(CompositorFrameSinkSupportClient* client, | 33 std::unique_ptr<Display> display, |
34 SurfaceManager* surface_manager, | 34 std::unique_ptr<BeginFrameSource> display_begin_frame_source); |
35 const FrameSinkId& frame_sink_id, | |
36 Display* display, | |
37 bool handles_frame_sink_id_invalidation, | |
38 bool needs_sync_points); | |
39 | 35 |
40 ~CompositorFrameSinkSupport() override; | 36 ~CompositorFrameSinkSupport() override; |
41 | 37 |
42 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } | 38 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } |
43 | 39 |
44 void EvictFrame(); | 40 void EvictFrame(); |
45 void SetNeedsBeginFrame(bool needs_begin_frame); | 41 void SetNeedsBeginFrame(bool needs_begin_frame); |
46 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, | 42 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, |
47 CompositorFrame frame); | 43 CompositorFrame frame); |
48 void Require(const LocalSurfaceId& local_surface_id, | 44 void Require(const LocalSurfaceId& local_surface_id, |
49 const SurfaceSequence& sequence); | 45 const SurfaceSequence& sequence); |
50 void Satisfy(const SurfaceSequence& sequence); | 46 void Satisfy(const SurfaceSequence& sequence); |
51 void AddChildFrameSink(const FrameSinkId& child_frame_sink_id); | 47 void AddChildFrameSink(const FrameSinkId& child_frame_sink_id); |
52 void RemoveChildFrameSink(const FrameSinkId& child_frame_sink_id); | 48 void RemoveChildFrameSink(const FrameSinkId& child_frame_sink_id); |
53 void ForceReclaimResources(); | |
54 | 49 |
55 Display* display() { return display_; } | 50 Display* display() { return display_.get(); } |
56 | 51 |
57 private: | 52 private: |
58 void DidReceiveCompositorFrameAck(); | 53 void DidReceiveCompositorFrameAck(); |
59 | 54 |
60 // DisplayClient implementation. | 55 // DisplayClient implementation. |
61 void DisplayOutputSurfaceLost() override; | 56 void DisplayOutputSurfaceLost() override; |
62 void DisplayWillDrawAndSwap(bool will_draw_and_swap, | 57 void DisplayWillDrawAndSwap(bool will_draw_and_swap, |
63 const RenderPassList& render_passes) override; | 58 const RenderPassList& render_passes) override; |
64 void DisplayDidDrawAndSwap() override; | 59 void DisplayDidDrawAndSwap() override; |
65 | 60 |
66 // SurfaceFactoryClient implementation. | 61 // SurfaceFactoryClient implementation. |
67 void ReturnResources(const ReturnedResourceArray& resources) override; | 62 void ReturnResources(const ReturnedResourceArray& resources) override; |
68 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override; | 63 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override; |
69 void WillDrawSurface(const LocalSurfaceId& local_surface_id, | 64 void WillDrawSurface(const LocalSurfaceId& local_surface_id, |
70 const gfx::Rect& damage_rect) override; | 65 const gfx::Rect& damage_rect) override; |
71 | 66 |
72 // BeginFrameObserver implementation. | 67 // BeginFrameObserver implementation. |
73 void OnBeginFrame(const BeginFrameArgs& args) override; | 68 void OnBeginFrame(const BeginFrameArgs& args) override; |
74 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; | 69 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; |
75 void OnBeginFrameSourcePausedChanged(bool paused) override; | 70 void OnBeginFrameSourcePausedChanged(bool paused) override; |
76 | 71 |
77 void UpdateNeedsBeginFramesInternal(); | 72 void UpdateNeedsBeginFramesInternal(); |
78 | 73 |
79 CompositorFrameSinkSupportClient* const client_; | 74 CompositorFrameSinkSupportClient* const client_; |
80 | 75 |
81 SurfaceManager* const surface_manager_; | 76 SurfaceManager* const surface_manager_; |
| 77 |
82 const FrameSinkId frame_sink_id_; | 78 const FrameSinkId frame_sink_id_; |
83 Display* const display_; | 79 |
| 80 // GpuCompositorFrameSink holds a Display and its BeginFrameSource if it |
| 81 // created with non-null gpu::SurfaceHandle. In the window server, the display |
| 82 // root window's CompositorFrameSink will have a valid gpu::SurfaceHandle. |
| 83 std::unique_ptr<BeginFrameSource> display_begin_frame_source_; |
| 84 std::unique_ptr<Display> display_; |
84 | 85 |
85 SurfaceFactory surface_factory_; | 86 SurfaceFactory surface_factory_; |
86 // Counts the number of CompositorFrames that have been submitted and have not | 87 // Counts the number of CompositorFrames that have been submitted and have not |
87 // yet received an ACK. | 88 // yet received an ACK. |
88 int ack_pending_count_ = 0; | 89 int ack_pending_count_ = 0; |
89 ReturnedResourceArray surface_returned_resources_; | 90 ReturnedResourceArray surface_returned_resources_; |
90 | 91 |
91 // The begin frame source being observered. Null if none. | 92 // The begin frame source being observered. Null if none. |
92 BeginFrameSource* begin_frame_source_ = nullptr; | 93 BeginFrameSource* begin_frame_source_ = nullptr; |
93 | 94 |
94 // The last begin frame args generated by the begin frame source. | 95 // The last begin frame args generated by the begin frame source. |
95 BeginFrameArgs last_begin_frame_args_; | 96 BeginFrameArgs last_begin_frame_args_; |
96 | 97 |
97 // Whether a request for begin frames has been issued. | 98 // Whether a request for begin frames has been issued. |
98 bool needs_begin_frame_ = false; | 99 bool needs_begin_frame_ = false; |
99 | 100 |
100 // Whether or not a frame observer has been added. | 101 // Whether or not a frame observer has been added. |
101 bool added_frame_observer_ = false; | 102 bool added_frame_observer_ = false; |
102 | 103 |
103 // TODO(staraz): Remove this flag once ui::Compositor no longer needs | |
104 // RegisterFrameSinkId(). | |
105 // A SurfaceSequence's validity is bound to the lifetime of the parent | |
106 // FrameSink that created it. We track the lifetime of FrameSink's through | |
107 // RegisterFrameSinkId and InvalidateFrameSink. During startup and GPU | |
108 // restart, a SurfaceSequence created by the top most layer compositor may be | |
109 // used prior to the creation of the associated CompositorFrameSinkSupport. | |
110 // CompositorFrameSinkSupport is created asynchronously when a new GPU channel | |
111 // is established. Once we switch to SurfaceReferences, this ordering concern | |
112 // goes away and we can remove this bool. | |
113 const bool handles_frame_sink_id_invalidation_; | |
114 | |
115 // The set of BeginFrame children of this CompositorFrameSink. | 104 // The set of BeginFrame children of this CompositorFrameSink. |
116 std::unordered_set<FrameSinkId, FrameSinkIdHash> child_frame_sinks_; | 105 std::unordered_set<FrameSinkId, FrameSinkIdHash> child_frame_sinks_; |
117 | 106 |
118 base::WeakPtrFactory<CompositorFrameSinkSupport> weak_factory_; | 107 base::WeakPtrFactory<CompositorFrameSinkSupport> weak_factory_; |
119 | 108 |
120 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupport); | 109 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupport); |
121 }; | 110 }; |
122 | 111 |
123 } // namespace cc | 112 } // namespace cc |
124 | 113 |
125 #endif // CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ | 114 #endif // CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ |
OLD | NEW |