| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SURFACE_H_ | 5 #ifndef CC_SURFACES_SURFACE_H_ |
| 6 #define CC_SURFACES_SURFACE_H_ | 6 #define CC_SURFACES_SURFACE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <unordered_set> | 14 #include <unordered_set> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/optional.h" | 20 #include "base/optional.h" |
| 21 #include "cc/output/copy_output_request.h" | 21 #include "cc/output/copy_output_request.h" |
| 22 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 22 #include "cc/surfaces/frame_sink_id.h" | 23 #include "cc/surfaces/frame_sink_id.h" |
| 23 #include "cc/surfaces/pending_frame_observer.h" | 24 #include "cc/surfaces/pending_frame_observer.h" |
| 24 #include "cc/surfaces/surface_factory.h" | |
| 25 #include "cc/surfaces/surface_id.h" | 25 #include "cc/surfaces/surface_id.h" |
| 26 #include "cc/surfaces/surface_sequence.h" | 26 #include "cc/surfaces/surface_sequence.h" |
| 27 #include "cc/surfaces/surfaces_export.h" | 27 #include "cc/surfaces/surfaces_export.h" |
| 28 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
| 29 | 29 |
| 30 namespace ui { | 30 namespace ui { |
| 31 class LatencyInfo; | 31 class LatencyInfo; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace cc { | 34 namespace cc { |
| 35 | 35 |
| 36 class CompositorFrame; | 36 class CompositorFrame; |
| 37 class CopyOutputRequest; | 37 class CopyOutputRequest; |
| 38 class SurfaceFactory; | |
| 39 | 38 |
| 40 class CC_SURFACES_EXPORT Surface { | 39 class CC_SURFACES_EXPORT Surface { |
| 41 public: | 40 public: |
| 42 using DrawCallback = SurfaceFactory::DrawCallback; | 41 using WillDrawCallback = |
| 43 using WillDrawCallback = SurfaceFactory::WillDrawCallback; | 42 base::RepeatingCallback<void(const LocalSurfaceId&, const gfx::Rect&)>; |
| 44 | 43 |
| 45 Surface(const SurfaceId& id, base::WeakPtr<SurfaceFactory> factory); | 44 Surface( |
| 45 const SurfaceId& id, |
| 46 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support); |
| 46 ~Surface(); | 47 ~Surface(); |
| 47 | 48 |
| 48 const SurfaceId& surface_id() const { return surface_id_; } | 49 const SurfaceId& surface_id() const { return surface_id_; } |
| 49 const SurfaceId& previous_frame_surface_id() const { | 50 const SurfaceId& previous_frame_surface_id() const { |
| 50 return previous_frame_surface_id_; | 51 return previous_frame_surface_id_; |
| 51 } | 52 } |
| 52 | 53 |
| 53 void SetPreviousFrameSurface(Surface* surface); | 54 void SetPreviousFrameSurface(Surface* surface); |
| 54 | 55 |
| 55 // |draw_callback| is called once to notify the client that the previously | 56 // |draw_callback| is called once to notify the client that the previously |
| 56 // submitted CompositorFrame is processed and that another frame can be | 57 // submitted CompositorFrame is processed and that another frame can be |
| 57 // submitted. | 58 // submitted. |
| 58 // |will_draw_callback| is called when |surface| is scheduled for a draw and | 59 // |will_draw_callback| is called when |surface| is scheduled for a draw and |
| 59 // there is visible damage. | 60 // there is visible damage. |
| 60 void QueueFrame(CompositorFrame frame, | 61 void QueueFrame(CompositorFrame frame, |
| 61 const DrawCallback& draw_callback, | 62 const base::Closure& draw_callback, |
| 62 const WillDrawCallback& will_draw_callback); | 63 const WillDrawCallback& will_draw_callback); |
| 63 void RequestCopyOfOutput(std::unique_ptr<CopyOutputRequest> copy_request); | 64 void RequestCopyOfOutput(std::unique_ptr<CopyOutputRequest> copy_request); |
| 64 | 65 |
| 65 // Notifies the Surface that a blocking SurfaceId now has an active frame. | 66 // Notifies the Surface that a blocking SurfaceId now has an active frame. |
| 66 void NotifySurfaceIdAvailable(const SurfaceId& surface_id); | 67 void NotifySurfaceIdAvailable(const SurfaceId& surface_id); |
| 67 | 68 |
| 68 void AddObserver(PendingFrameObserver* observer); | 69 void AddObserver(PendingFrameObserver* observer); |
| 69 void RemoveObserver(PendingFrameObserver* observer); | 70 void RemoveObserver(PendingFrameObserver* observer); |
| 70 | 71 |
| 71 // Called if a deadline has been hit and this surface is not yet active but | 72 // Called if a deadline has been hit and this surface is not yet active but |
| (...skipping 14 matching lines...) Expand all Loading... |
| 86 // returns true before calling this method. | 87 // returns true before calling this method. |
| 87 const CompositorFrame& GetPendingFrame(); | 88 const CompositorFrame& GetPendingFrame(); |
| 88 | 89 |
| 89 // Returns a number that increments by 1 every time a new frame is enqueued. | 90 // Returns a number that increments by 1 every time a new frame is enqueued. |
| 90 int frame_index() const { return frame_index_; } | 91 int frame_index() const { return frame_index_; } |
| 91 | 92 |
| 92 void TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info); | 93 void TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info); |
| 93 void RunDrawCallback(); | 94 void RunDrawCallback(); |
| 94 void RunWillDrawCallback(const gfx::Rect& damage_rect); | 95 void RunWillDrawCallback(const gfx::Rect& damage_rect); |
| 95 | 96 |
| 96 base::WeakPtr<SurfaceFactory> factory() { return factory_; } | 97 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support() { |
| 98 return compositor_frame_sink_support_; |
| 99 } |
| 97 | 100 |
| 98 // Add a SurfaceSequence that must be satisfied before the Surface is | 101 // Add a SurfaceSequence that must be satisfied before the Surface is |
| 99 // destroyed. | 102 // destroyed. |
| 100 void AddDestructionDependency(SurfaceSequence sequence); | 103 void AddDestructionDependency(SurfaceSequence sequence); |
| 101 | 104 |
| 102 // Satisfy all destruction dependencies that are contained in sequences, and | 105 // Satisfy all destruction dependencies that are contained in sequences, and |
| 103 // remove them from sequences. | 106 // remove them from sequences. |
| 104 void SatisfyDestructionDependencies( | 107 void SatisfyDestructionDependencies( |
| 105 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, | 108 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, |
| 106 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_id_namespaces); | 109 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_id_namespaces); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 120 | 123 |
| 121 bool HasActiveFrame() const { return active_frame_data_.has_value(); } | 124 bool HasActiveFrame() const { return active_frame_data_.has_value(); } |
| 122 bool HasPendingFrame() const { return pending_frame_data_.has_value(); } | 125 bool HasPendingFrame() const { return pending_frame_data_.has_value(); } |
| 123 | 126 |
| 124 bool destroyed() const { return destroyed_; } | 127 bool destroyed() const { return destroyed_; } |
| 125 void set_destroyed(bool destroyed) { destroyed_ = destroyed; } | 128 void set_destroyed(bool destroyed) { destroyed_ = destroyed; } |
| 126 | 129 |
| 127 private: | 130 private: |
| 128 struct FrameData { | 131 struct FrameData { |
| 129 FrameData(CompositorFrame&& frame, | 132 FrameData(CompositorFrame&& frame, |
| 130 const DrawCallback& draw_callback, | 133 const base::Closure& draw_callback, |
| 131 const WillDrawCallback& will_draw_callback); | 134 const WillDrawCallback& will_draw_callback); |
| 132 FrameData(FrameData&& other); | 135 FrameData(FrameData&& other); |
| 133 ~FrameData(); | 136 ~FrameData(); |
| 134 FrameData& operator=(FrameData&& other); | 137 FrameData& operator=(FrameData&& other); |
| 135 CompositorFrame frame; | 138 CompositorFrame frame; |
| 136 DrawCallback draw_callback; | 139 base::Closure draw_callback; |
| 137 WillDrawCallback will_draw_callback; | 140 WillDrawCallback will_draw_callback; |
| 138 }; | 141 }; |
| 139 | 142 |
| 140 // Called to prevent additional CompositorFrames from being accepted into this | 143 // Called to prevent additional CompositorFrames from being accepted into this |
| 141 // surface. Once a Surface is closed, it cannot accept CompositorFrames again. | 144 // surface. Once a Surface is closed, it cannot accept CompositorFrames again. |
| 142 void Close(); | 145 void Close(); |
| 143 | 146 |
| 144 void ActivatePendingFrame(); | 147 void ActivatePendingFrame(); |
| 145 // Called when all of the surface's dependencies have been resolved. | 148 // Called when all of the surface's dependencies have been resolved. |
| 146 void ActivateFrame(FrameData frame_data); | 149 void ActivateFrame(FrameData frame_data); |
| 147 void UpdateBlockingSurfaces(bool has_previous_pending_frame, | 150 void UpdateBlockingSurfaces(bool has_previous_pending_frame, |
| 148 const CompositorFrame& current_frame); | 151 const CompositorFrame& current_frame); |
| 149 | 152 |
| 150 void UnrefFrameResourcesAndRunDrawCallback( | 153 void UnrefFrameResourcesAndRunDrawCallback( |
| 151 base::Optional<FrameData> frame_data); | 154 base::Optional<FrameData> frame_data); |
| 152 void ClearCopyRequests(); | 155 void ClearCopyRequests(); |
| 153 | 156 |
| 154 void TakeLatencyInfoFromPendingFrame( | 157 void TakeLatencyInfoFromPendingFrame( |
| 155 std::vector<ui::LatencyInfo>* latency_info); | 158 std::vector<ui::LatencyInfo>* latency_info); |
| 156 static void TakeLatencyInfoFromFrame( | 159 static void TakeLatencyInfoFromFrame( |
| 157 CompositorFrame* frame, | 160 CompositorFrame* frame, |
| 158 std::vector<ui::LatencyInfo>* latency_info); | 161 std::vector<ui::LatencyInfo>* latency_info); |
| 159 | 162 |
| 160 const SurfaceId surface_id_; | 163 const SurfaceId surface_id_; |
| 161 SurfaceId previous_frame_surface_id_; | 164 SurfaceId previous_frame_surface_id_; |
| 162 base::WeakPtr<SurfaceFactory> factory_; | 165 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support_; |
| 163 | 166 |
| 164 base::Optional<FrameData> pending_frame_data_; | 167 base::Optional<FrameData> pending_frame_data_; |
| 165 base::Optional<FrameData> active_frame_data_; | 168 base::Optional<FrameData> active_frame_data_; |
| 166 int frame_index_; | 169 int frame_index_; |
| 167 bool closed_ = false; | 170 bool closed_ = false; |
| 168 bool destroyed_; | 171 bool destroyed_; |
| 169 std::vector<SurfaceSequence> destruction_dependencies_; | 172 std::vector<SurfaceSequence> destruction_dependencies_; |
| 170 | 173 |
| 171 base::flat_set<SurfaceId> blocking_surfaces_; | 174 base::flat_set<SurfaceId> blocking_surfaces_; |
| 172 base::ObserverList<PendingFrameObserver, true> observers_; | 175 base::ObserverList<PendingFrameObserver, true> observers_; |
| 173 | 176 |
| 174 DISALLOW_COPY_AND_ASSIGN(Surface); | 177 DISALLOW_COPY_AND_ASSIGN(Surface); |
| 175 }; | 178 }; |
| 176 | 179 |
| 177 } // namespace cc | 180 } // namespace cc |
| 178 | 181 |
| 179 #endif // CC_SURFACES_SURFACE_H_ | 182 #endif // CC_SURFACES_SURFACE_H_ |
| OLD | NEW |