Index: cc/surfaces/display_begin_frame_source.h |
diff --git a/cc/surfaces/display_begin_frame_source.h b/cc/surfaces/display_begin_frame_source.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..212e3c4eaf781499eeda233be92cda41786d0d4e |
--- /dev/null |
+++ b/cc/surfaces/display_begin_frame_source.h |
@@ -0,0 +1,92 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CC_SURFACES_DISPLAY_BEGIN_FRAME_SOURCE_H_ |
+#define CC_SURFACES_DISPLAY_BEGIN_FRAME_SOURCE_H_ |
+ |
+#include <memory> |
+#include <set> |
+#include <unordered_map> |
+ |
+#include "base/macros.h" |
+#include "cc/output/begin_frame_args.h" |
+#include "cc/scheduler/begin_frame_source.h" |
+#include "cc/surfaces/surfaces_export.h" |
+ |
+namespace cc { |
+ |
+class CC_SURFACES_EXPORT DisplayBeginFrameSourceClient { |
+ public: |
+ virtual void BeginFrameObserverStatusChanged() = 0; |
+ virtual void OnBeginFrame(const BeginFrameArgs& args) = 0; |
+ virtual const BeginFrameArgs& LastUsedBeginFrameArgs() const = 0; |
+}; |
+ |
+// Wraps a BeginFrameSource and keeps track of observers that have finished a |
+// BeginFrame. Supports swapping the wrapped source underneath it. |
+class CC_SURFACES_EXPORT DisplayBeginFrameSource : public BeginFrameSource, |
+ public BeginFrameObserver { |
+ public: |
+ explicit DisplayBeginFrameSource( |
+ std::unique_ptr<BeginFrameSource> wrapped_source); |
+ ~DisplayBeginFrameSource() override; |
+ |
+ BeginFrameSource* GetWrappedSource() { return wrapped_source_.get(); } |
+ |
+ void SetClient(DisplayBeginFrameSourceClient* client); |
+ void SetClientNeedsBeginFrames(bool needs_begin_frames); |
+ |
+ // Returns |true| if it the source has any active observers. |
+ bool HasObservers() const; |
+ |
+ // Returns |true| if all the source's observers completed the current frame. |
+ bool AllObserversFinishedFrame() const; |
+ |
+ // Completes the currently active frame. The client calls this to signal |
+ // that it has executed the deadline for the BeginFrame. |had_updates| |
+ // indicates whether the client produced an update (draw) as a result of the |
+ // frame, and |has_pending_updates| whether it still has updates pending that |
+ // it could not produce during this frame. |
+ void FinishClientFrame(bool had_updates, bool has_pending_updates); |
+ |
+ // Swaps the current wrapped source with the one pointed to by |
+ // |begin_frame_source|. The old source is returned through the provided |
+ // pointer, transferring its ownership to the caller. |
+ void SwapWrappedSource(std::unique_ptr<BeginFrameSource>* begin_frame_source); |
+ |
+ // BeginFrameSource implementation. |
+ void DidFinishFrame(BeginFrameObserver* obs, |
+ const BeginFrameAck& ack) override; |
+ void AddObserver(BeginFrameObserver* obs) override; |
+ void RemoveObserver(BeginFrameObserver* obs) override; |
+ bool IsThrottled() const override; |
+ |
+ // BeginFrameObserver implementation. |
+ void OnBeginFrame(const BeginFrameArgs& args) override; |
+ const BeginFrameArgs& LastUsedBeginFrameArgs() const override; |
+ void OnBeginFrameSourcePausedChanged(bool paused) override; |
+ |
+ private: |
+ void UpdateObservingBeginFrames(); |
+ BeginFrameArgs GetMissedArgs(const BeginFrameArgs& last_args) const; |
+ void ObserverStatusChanged(); |
+ |
+ std::unique_ptr<BeginFrameSource> wrapped_source_; |
+ std::set<BeginFrameObserver*> observers_; |
+ BeginFrameObserverAckTracker ack_tracker_; |
+ BeginFrameArgs current_begin_frame_args_; |
+ bool observing_begin_frames_; |
+ bool frame_active_; |
+ uint64_t current_source_id_; |
+ uint64_t oldest_incorporated_frame_; |
+ |
+ DisplayBeginFrameSourceClient* client_; // Not owned. |
+ bool client_needs_begin_frames_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DisplayBeginFrameSource); |
+}; |
+ |
+} // namespace cc |
+ |
+#endif // CC_SURFACES_DISPLAY_BEGIN_FRAME_SOURCE_H_ |