| 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 <memory> | 8 #include <memory> |
| 9 #include <unordered_set> | 9 #include <unordered_set> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "cc/output/compositor_frame.h" | 13 #include "cc/output/compositor_frame.h" |
| 14 #include "cc/scheduler/begin_frame_source.h" | 14 #include "cc/scheduler/begin_frame_source.h" |
| 15 #include "cc/surfaces/display.h" | |
| 16 #include "cc/surfaces/display_client.h" | |
| 17 #include "cc/surfaces/referenced_surface_tracker.h" | 15 #include "cc/surfaces/referenced_surface_tracker.h" |
| 18 #include "cc/surfaces/surface_factory.h" | 16 #include "cc/surfaces/surface_factory.h" |
| 19 #include "cc/surfaces/surface_factory_client.h" | 17 #include "cc/surfaces/surface_factory_client.h" |
| 20 #include "cc/surfaces/surface_id.h" | 18 #include "cc/surfaces/surface_id.h" |
| 21 #include "cc/surfaces/surfaces_export.h" | 19 #include "cc/surfaces/surfaces_export.h" |
| 22 | 20 |
| 23 namespace cc { | 21 namespace cc { |
| 24 | 22 |
| 25 class CompositorFrameSinkSupportClient; | 23 class CompositorFrameSinkSupportClient; |
| 26 class Display; | |
| 27 class SurfaceManager; | 24 class SurfaceManager; |
| 28 | 25 |
| 29 class CC_SURFACES_EXPORT CompositorFrameSinkSupport | 26 class CC_SURFACES_EXPORT CompositorFrameSinkSupport |
| 30 : public NON_EXPORTED_BASE(DisplayClient), | 27 : public SurfaceFactoryClient, |
| 31 public SurfaceFactoryClient, | |
| 32 public BeginFrameObserver { | 28 public BeginFrameObserver { |
| 33 public: | 29 public: |
| 34 CompositorFrameSinkSupport( | 30 CompositorFrameSinkSupport(CompositorFrameSinkSupportClient* client, |
| 35 CompositorFrameSinkSupportClient* client, | 31 SurfaceManager* surface_manager, |
| 36 SurfaceManager* surface_manager, | 32 const FrameSinkId& frame_sink_id, |
| 37 const FrameSinkId& frame_sink_id, | 33 bool submits_to_display_compositor); |
| 38 std::unique_ptr<Display> display, | |
| 39 std::unique_ptr<BeginFrameSource> display_begin_frame_source); | |
| 40 | 34 |
| 41 ~CompositorFrameSinkSupport() override; | 35 ~CompositorFrameSinkSupport() override; |
| 42 | 36 |
| 43 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } | 37 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } |
| 44 | 38 |
| 45 Surface* current_surface_for_testing() { | 39 Surface* current_surface_for_testing() { |
| 46 return surface_factory_.current_surface_for_testing(); | 40 return surface_factory_.current_surface_for_testing(); |
| 47 } | 41 } |
| 48 | 42 |
| 49 const ReferencedSurfaceTracker& ReferenceTrackerForTesting() const { | 43 const ReferencedSurfaceTracker& ReferenceTrackerForTesting() const { |
| 50 return reference_tracker_; | 44 return reference_tracker_; |
| 51 } | 45 } |
| 52 | 46 |
| 53 void EvictFrame(); | 47 void EvictFrame(); |
| 54 void SetNeedsBeginFrame(bool needs_begin_frame); | 48 void SetNeedsBeginFrame(bool needs_begin_frame); |
| 55 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, | 49 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, |
| 56 CompositorFrame frame); | 50 CompositorFrame frame); |
| 57 void Require(const LocalSurfaceId& local_surface_id, | 51 void Require(const LocalSurfaceId& local_surface_id, |
| 58 const SurfaceSequence& sequence); | 52 const SurfaceSequence& sequence); |
| 59 void Satisfy(const SurfaceSequence& sequence); | 53 void Satisfy(const SurfaceSequence& sequence); |
| 60 void AddChildFrameSink(const FrameSinkId& child_frame_sink_id); | 54 void AddChildFrameSink(const FrameSinkId& child_frame_sink_id); |
| 61 void RemoveChildFrameSink(const FrameSinkId& child_frame_sink_id); | 55 void RemoveChildFrameSink(const FrameSinkId& child_frame_sink_id); |
| 62 | 56 |
| 63 Display* display() { return display_.get(); } | |
| 64 | |
| 65 private: | 57 private: |
| 66 // Update surface references with SurfaceManager for current CompositorFrame | 58 // Update surface references with SurfaceManager for current CompositorFrame |
| 67 // that has |local_surface_id|. UpdateReferences() must be called on | 59 // that has |local_surface_id|. UpdateReferences() must be called on |
| 68 // |reference_tracker_| before calling this. Will add and remove top-level | 60 // |reference_tracker_| before calling this. Will add and remove top-level |
| 69 // root references if |display_| is not null. | 61 // root references if |display_| is not null. |
| 70 void UpdateSurfaceReferences(const SurfaceId& last_surface_id, | 62 void UpdateSurfaceReferences(const SurfaceId& last_surface_id, |
| 71 const LocalSurfaceId& local_surface_id); | 63 const LocalSurfaceId& local_surface_id); |
| 72 | 64 |
| 73 void AddTopLevelRootReference(const SurfaceId& surface_id); | 65 void AddTopLevelRootReference(const SurfaceId& surface_id); |
| 74 void RemoveTopLevelRootReference(const SurfaceId& surface_id); | 66 void RemoveTopLevelRootReference(const SurfaceId& surface_id); |
| 75 | 67 |
| 76 void DidReceiveCompositorFrameAck(); | 68 void DidReceiveCompositorFrameAck(); |
| 77 | 69 |
| 78 // DisplayClient implementation. | |
| 79 void DisplayOutputSurfaceLost() override; | |
| 80 void DisplayWillDrawAndSwap(bool will_draw_and_swap, | |
| 81 const RenderPassList& render_passes) override; | |
| 82 void DisplayDidDrawAndSwap() override; | |
| 83 | |
| 84 // SurfaceFactoryClient implementation. | 70 // SurfaceFactoryClient implementation. |
| 85 void ReturnResources(const ReturnedResourceArray& resources) override; | 71 void ReturnResources(const ReturnedResourceArray& resources) override; |
| 86 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override; | 72 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override; |
| 87 void WillDrawSurface(const LocalSurfaceId& local_surface_id, | 73 void WillDrawSurface(const LocalSurfaceId& local_surface_id, |
| 88 const gfx::Rect& damage_rect) override; | 74 const gfx::Rect& damage_rect) override; |
| 89 | 75 |
| 90 // BeginFrameObserver implementation. | 76 // BeginFrameObserver implementation. |
| 91 void OnBeginFrame(const BeginFrameArgs& args) override; | 77 void OnBeginFrame(const BeginFrameArgs& args) override; |
| 92 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; | 78 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; |
| 93 void OnBeginFrameSourcePausedChanged(bool paused) override; | 79 void OnBeginFrameSourcePausedChanged(bool paused) override; |
| 94 | 80 |
| 95 void UpdateNeedsBeginFramesInternal(); | 81 void UpdateNeedsBeginFramesInternal(); |
| 96 | 82 |
| 97 CompositorFrameSinkSupportClient* const client_; | 83 CompositorFrameSinkSupportClient* const client_; |
| 98 | 84 |
| 99 SurfaceManager* const surface_manager_; | 85 SurfaceManager* const surface_manager_; |
| 100 | 86 |
| 101 const FrameSinkId frame_sink_id_; | 87 const FrameSinkId frame_sink_id_; |
| 102 | 88 |
| 103 // GpuCompositorFrameSink holds a Display and its BeginFrameSource if it | |
| 104 // created with non-null gpu::SurfaceHandle. In the window server, the display | |
| 105 // root window's CompositorFrameSink will have a valid gpu::SurfaceHandle. | |
| 106 std::unique_ptr<BeginFrameSource> display_begin_frame_source_; | |
| 107 std::unique_ptr<Display> display_; | |
| 108 | |
| 109 SurfaceFactory surface_factory_; | 89 SurfaceFactory surface_factory_; |
| 110 // Counts the number of CompositorFrames that have been submitted and have not | 90 // Counts the number of CompositorFrames that have been submitted and have not |
| 111 // yet received an ACK. | 91 // yet received an ACK. |
| 112 int ack_pending_count_ = 0; | 92 int ack_pending_count_ = 0; |
| 113 ReturnedResourceArray surface_returned_resources_; | 93 ReturnedResourceArray surface_returned_resources_; |
| 114 | 94 |
| 115 // The begin frame source being observered. Null if none. | 95 // The begin frame source being observered. Null if none. |
| 116 BeginFrameSource* begin_frame_source_ = nullptr; | 96 BeginFrameSource* begin_frame_source_ = nullptr; |
| 117 | 97 |
| 118 // The last begin frame args generated by the begin frame source. | 98 // The last begin frame args generated by the begin frame source. |
| 119 BeginFrameArgs last_begin_frame_args_; | 99 BeginFrameArgs last_begin_frame_args_; |
| 120 | 100 |
| 121 // Whether a request for begin frames has been issued. | 101 // Whether a request for begin frames has been issued. |
| 122 bool needs_begin_frame_ = false; | 102 bool needs_begin_frame_ = false; |
| 123 | 103 |
| 124 // Whether or not a frame observer has been added. | 104 // Whether or not a frame observer has been added. |
| 125 bool added_frame_observer_ = false; | 105 bool added_frame_observer_ = false; |
| 126 | 106 |
| 127 // Track the surface references for the surface corresponding to this | 107 // Track the surface references for the surface corresponding to this |
| 128 // compositor frame sink. | 108 // compositor frame sink. |
| 129 ReferencedSurfaceTracker reference_tracker_; | 109 ReferencedSurfaceTracker reference_tracker_; |
| 130 | 110 |
| 131 // The set of BeginFrame children of this CompositorFrameSink. | 111 // The set of BeginFrame children of this CompositorFrameSink. |
| 132 std::unordered_set<FrameSinkId, FrameSinkIdHash> child_frame_sinks_; | 112 std::unordered_set<FrameSinkId, FrameSinkIdHash> child_frame_sinks_; |
| 133 | 113 |
| 114 const bool submits_to_display_compositor_; |
| 115 |
| 134 base::WeakPtrFactory<CompositorFrameSinkSupport> weak_factory_; | 116 base::WeakPtrFactory<CompositorFrameSinkSupport> weak_factory_; |
| 135 | 117 |
| 136 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupport); | 118 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupport); |
| 137 }; | 119 }; |
| 138 | 120 |
| 139 } // namespace cc | 121 } // namespace cc |
| 140 | 122 |
| 141 #endif // CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ | 123 #endif // CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ |
| OLD | NEW |