Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2451)

Unified Diff: cc/surfaces/display_begin_frame_source.h

Issue 2527283003: cc: Introduce BeginFrame sequence numbers and acknowledgements.
Patch Set: Address Brian's comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/surfaces/display.cc ('k') | cc/surfaces/display_begin_frame_source.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2643275eb2370ce6ba56f27e38f9f5cd1c73bd0e
--- /dev/null
+++ b/cc/surfaces/display_begin_frame_source.h
@@ -0,0 +1,100 @@
+// 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);
+
+ // Returns the source ID of the current BeginFrame.
+ uint64_t CurrentSourceId();
+
+ // Returns the sequence number of the current BeginFrame.
+ uint64_t CurrentFrameNumber();
+
+ // Returns the latest confirmed frame number for the current BeginFrame.
+ uint64_t LatestConfirmedFrame();
+
+ // 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 latest_confirmed_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_
« no previous file with comments | « cc/surfaces/display.cc ('k') | cc/surfaces/display_begin_frame_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698