OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_SURFACES_DISPLAY_BEGIN_FRAME_SOURCE_H_ |
| 6 #define CC_SURFACES_DISPLAY_BEGIN_FRAME_SOURCE_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <set> |
| 10 #include <unordered_map> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "cc/output/begin_frame_args.h" |
| 14 #include "cc/scheduler/begin_frame_source.h" |
| 15 #include "cc/surfaces/surfaces_export.h" |
| 16 |
| 17 namespace cc { |
| 18 |
| 19 class CC_SURFACES_EXPORT DisplayBeginFrameSourceClient { |
| 20 public: |
| 21 virtual void BeginFrameObserverStatusChanged() = 0; |
| 22 virtual void OnBeginFrame(const BeginFrameArgs& args) = 0; |
| 23 virtual const BeginFrameArgs& LastUsedBeginFrameArgs() const = 0; |
| 24 }; |
| 25 |
| 26 // Wraps a BeginFrameSource and keeps track of observers that have finished a |
| 27 // BeginFrame. Supports swapping the wrapped source underneath it. |
| 28 class CC_SURFACES_EXPORT DisplayBeginFrameSource : public BeginFrameSource, |
| 29 public BeginFrameObserver { |
| 30 public: |
| 31 explicit DisplayBeginFrameSource( |
| 32 std::unique_ptr<BeginFrameSource> wrapped_source); |
| 33 ~DisplayBeginFrameSource() override; |
| 34 |
| 35 BeginFrameSource* GetWrappedSource() { return wrapped_source_.get(); } |
| 36 |
| 37 void SetClient(DisplayBeginFrameSourceClient* client); |
| 38 void SetClientNeedsBeginFrames(bool needs_begin_frames); |
| 39 |
| 40 // Returns |true| if it the source has any active observers. |
| 41 bool HasObservers() const; |
| 42 |
| 43 // Returns |true| if all the source's observers completed the current frame. |
| 44 bool AllObserversFinishedFrame() const; |
| 45 |
| 46 // Completes the currently active frame. The client calls this to signal |
| 47 // that it has executed the deadline for the BeginFrame. |had_updates| |
| 48 // indicates whether the client produced an update (draw) as a result of the |
| 49 // frame, and |has_pending_updates| whether it still has updates pending that |
| 50 // it could not produce during this frame. |
| 51 void FinishClientFrame(bool had_updates, bool has_pending_updates); |
| 52 |
| 53 // Swaps the current wrapped source with the one pointed to by |
| 54 // |begin_frame_source|. The old source is returned through the provided |
| 55 // pointer, transferring its ownership to the caller. |
| 56 void SwapWrappedSource(std::unique_ptr<BeginFrameSource>* begin_frame_source); |
| 57 |
| 58 // BeginFrameSource implementation. |
| 59 void DidFinishFrame(BeginFrameObserver* obs, |
| 60 const BeginFrameAck& ack) override; |
| 61 void AddObserver(BeginFrameObserver* obs) override; |
| 62 void RemoveObserver(BeginFrameObserver* obs) override; |
| 63 bool IsThrottled() const override; |
| 64 |
| 65 // BeginFrameObserver implementation. |
| 66 void OnBeginFrame(const BeginFrameArgs& args) override; |
| 67 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; |
| 68 void OnBeginFrameSourcePausedChanged(bool paused) override; |
| 69 |
| 70 private: |
| 71 void UpdateObservingBeginFrames(); |
| 72 BeginFrameArgs GetMissedArgs(const BeginFrameArgs& last_args) const; |
| 73 void ObserverStatusChanged(); |
| 74 |
| 75 std::unique_ptr<BeginFrameSource> wrapped_source_; |
| 76 std::set<BeginFrameObserver*> observers_; |
| 77 BeginFrameObserverAckTracker ack_tracker_; |
| 78 BeginFrameArgs current_begin_frame_args_; |
| 79 bool observing_begin_frames_; |
| 80 bool frame_active_; |
| 81 uint64_t current_source_id_; |
| 82 uint64_t oldest_incorporated_frame_; |
| 83 |
| 84 DisplayBeginFrameSourceClient* client_; // Not owned. |
| 85 bool client_needs_begin_frames_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(DisplayBeginFrameSource); |
| 88 }; |
| 89 |
| 90 } // namespace cc |
| 91 |
| 92 #endif // CC_SURFACES_DISPLAY_BEGIN_FRAME_SOURCE_H_ |
OLD | NEW |