| 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/frame_sink_id.h" | 22 #include "cc/surfaces/frame_sink_id.h" |
| 23 #include "cc/surfaces/pending_surface_observer.h" |
| 23 #include "cc/surfaces/surface_factory.h" | 24 #include "cc/surfaces/surface_factory.h" |
| 24 #include "cc/surfaces/surface_id.h" | 25 #include "cc/surfaces/surface_id.h" |
| 25 #include "cc/surfaces/surface_sequence.h" | 26 #include "cc/surfaces/surface_sequence.h" |
| 26 #include "cc/surfaces/surfaces_export.h" | 27 #include "cc/surfaces/surfaces_export.h" |
| 27 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
| 28 | 29 |
| 29 namespace ui { | 30 namespace ui { |
| 30 class LatencyInfo; | 31 class LatencyInfo; |
| 31 } | 32 } |
| 32 | 33 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 47 const SurfaceId& surface_id() const { return surface_id_; } | 48 const SurfaceId& surface_id() const { return surface_id_; } |
| 48 const SurfaceId& previous_frame_surface_id() const { | 49 const SurfaceId& previous_frame_surface_id() const { |
| 49 return previous_frame_surface_id_; | 50 return previous_frame_surface_id_; |
| 50 } | 51 } |
| 51 | 52 |
| 52 void SetPreviousFrameSurface(Surface* surface); | 53 void SetPreviousFrameSurface(Surface* surface); |
| 53 | 54 |
| 54 void QueueFrame(CompositorFrame frame, const DrawCallback& draw_callback); | 55 void QueueFrame(CompositorFrame frame, const DrawCallback& draw_callback); |
| 55 void EvictFrame(); | 56 void EvictFrame(); |
| 56 void RequestCopyOfOutput(std::unique_ptr<CopyOutputRequest> copy_request); | 57 void RequestCopyOfOutput(std::unique_ptr<CopyOutputRequest> copy_request); |
| 58 |
| 59 // Reports to the Surface that a blocking SurfaceId is now available. |
| 60 void ReportSurfaceIdAvailable(const SurfaceId& surface_id); |
| 61 |
| 62 void AddObserver(PendingSurfaceObserver* observer); |
| 63 void RemoveObserver(PendingSurfaceObserver* observer); |
| 64 |
| 65 // Called if a deadline has been hit and this surface is not yet active but |
| 66 // it's marked as respecting deadlines. |
| 67 void ActivatePendingFrameForDeadline(); |
| 68 |
| 57 // Adds each CopyOutputRequest in the current frame to copy_requests. The | 69 // Adds each CopyOutputRequest in the current frame to copy_requests. The |
| 58 // caller takes ownership of them. |copy_requests| is keyed by RenderPass ids. | 70 // caller takes ownership of them. |copy_requests| is keyed by RenderPass ids. |
| 59 void TakeCopyOutputRequests( | 71 void TakeCopyOutputRequests( |
| 60 std::multimap<int, std::unique_ptr<CopyOutputRequest>>* copy_requests); | 72 std::multimap<int, std::unique_ptr<CopyOutputRequest>>* copy_requests); |
| 61 | 73 |
| 62 // Returns the most recent frame that is eligible to be rendered. | 74 // Returns the most recent frame that is eligible to be rendered. |
| 63 // You must check whether HasFrame() returns true before calling this method. | 75 // You must check whether HasFrame() returns true before calling this method. |
| 64 const CompositorFrame& GetEligibleFrame() const; | 76 const CompositorFrame& GetEligibleFrame() const; |
| 65 | 77 |
| 78 // Returns the currently pending frame. |
| 79 const base::Optional<CompositorFrame>& GetPendingFrame(); |
| 80 |
| 66 // Returns a number that increments by 1 every time a new frame is enqueued. | 81 // Returns a number that increments by 1 every time a new frame is enqueued. |
| 67 int frame_index() const { return frame_index_; } | 82 int frame_index() const { return frame_index_; } |
| 68 | 83 |
| 69 void TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info); | 84 void TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info); |
| 70 void RunDrawCallbacks(); | 85 void RunDrawCallbacks(); |
| 71 | 86 |
| 72 base::WeakPtr<SurfaceFactory> factory() { return factory_; } | 87 base::WeakPtr<SurfaceFactory> factory() { return factory_; } |
| 73 | 88 |
| 74 // Add a SurfaceSequence that must be satisfied before the Surface is | 89 // Add a SurfaceSequence that must be satisfied before the Surface is |
| 75 // destroyed. | 90 // destroyed. |
| 76 void AddDestructionDependency(SurfaceSequence sequence); | 91 void AddDestructionDependency(SurfaceSequence sequence); |
| 77 | 92 |
| 78 // Satisfy all destruction dependencies that are contained in sequences, and | 93 // Satisfy all destruction dependencies that are contained in sequences, and |
| 79 // remove them from sequences. | 94 // remove them from sequences. |
| 80 void SatisfyDestructionDependencies( | 95 void SatisfyDestructionDependencies( |
| 81 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, | 96 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, |
| 82 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_id_namespaces); | 97 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_id_namespaces); |
| 83 size_t GetDestructionDependencyCount() const { | 98 size_t GetDestructionDependencyCount() const { |
| 84 return destruction_dependencies_.size(); | 99 return destruction_dependencies_.size(); |
| 85 } | 100 } |
| 86 | 101 |
| 87 const std::vector<SurfaceId>& referenced_surfaces() const { | 102 const std::vector<SurfaceId>& referenced_surfaces() const { |
| 88 return referenced_surfaces_; | 103 return referenced_surfaces_; |
| 89 } | 104 } |
| 90 | 105 |
| 91 bool HasFrame() const { return current_frame_.has_value(); } | 106 bool HasFrame() const { return active_frame_.has_value(); } |
| 92 | 107 |
| 93 bool destroyed() const { return destroyed_; } | 108 bool destroyed() const { return destroyed_; } |
| 94 void set_destroyed(bool destroyed) { destroyed_ = destroyed; } | 109 void set_destroyed(bool destroyed) { destroyed_ = destroyed; } |
| 95 | 110 |
| 96 private: | 111 private: |
| 112 void ActivatePendingFrame(); |
| 113 // Called when all of the surface's dependencies have been resolved. |
| 114 void ActivateFrame(CompositorFrame frame); |
| 115 |
| 97 void UnrefFrameResources(const CompositorFrame& frame_data); | 116 void UnrefFrameResources(const CompositorFrame& frame_data); |
| 98 void ClearCopyRequests(); | 117 void ClearCopyRequests(); |
| 99 | 118 |
| 100 SurfaceId surface_id_; | 119 SurfaceId surface_id_; |
| 101 SurfaceId previous_frame_surface_id_; | 120 SurfaceId previous_frame_surface_id_; |
| 102 base::WeakPtr<SurfaceFactory> factory_; | 121 base::WeakPtr<SurfaceFactory> factory_; |
| 103 // TODO(jamesr): Support multiple frames in flight. | 122 // TODO(jamesr): Support multiple frames in flight. |
| 104 base::Optional<CompositorFrame> current_frame_; | 123 base::Optional<CompositorFrame> pending_frame_; |
| 124 base::Optional<CompositorFrame> active_frame_; |
| 105 int frame_index_; | 125 int frame_index_; |
| 106 bool destroyed_; | 126 bool destroyed_; |
| 107 std::vector<SurfaceSequence> destruction_dependencies_; | 127 std::vector<SurfaceSequence> destruction_dependencies_; |
| 108 | 128 |
| 109 // This surface may have multiple BeginFrameSources if it is | 129 // This surface may have multiple BeginFrameSources if it is |
| 110 // on multiple Displays. | 130 // on multiple Displays. |
| 111 std::set<BeginFrameSource*> begin_frame_sources_; | 131 std::set<BeginFrameSource*> begin_frame_sources_; |
| 112 | 132 |
| 113 std::vector<SurfaceId> referenced_surfaces_; | 133 std::vector<SurfaceId> referenced_surfaces_; |
| 114 | 134 |
| 135 SurfaceDependencies blocked_on_surfaces_; |
| 136 base::ObserverList<PendingSurfaceObserver, true> observers_; |
| 137 |
| 115 DrawCallback draw_callback_; | 138 DrawCallback draw_callback_; |
| 116 | 139 |
| 117 DISALLOW_COPY_AND_ASSIGN(Surface); | 140 DISALLOW_COPY_AND_ASSIGN(Surface); |
| 118 }; | 141 }; |
| 119 | 142 |
| 143 using PendingSurfaceSet = std::unordered_set<Surface*>; |
| 144 |
| 120 } // namespace cc | 145 } // namespace cc |
| 121 | 146 |
| 122 #endif // CC_SURFACES_SURFACE_H_ | 147 #endif // CC_SURFACES_SURFACE_H_ |
| OLD | NEW |