Chromium Code Reviews| 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..63a1eeb91d8ae745416baaf47a248bab3b379b0e |
| --- /dev/null |
| +++ b/cc/surfaces/display_begin_frame_source.h |
| @@ -0,0 +1,87 @@ |
| +// 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 target BeginFrameSource and keeps track of observers that have |
| +// finished a BeginFrame. Supports swapping the target source underneath it. |
| +class CC_SURFACES_EXPORT DisplayBeginFrameSource : public BeginFrameSource, |
| + public BeginFrameObserver { |
| + public: |
| + explicit DisplayBeginFrameSource( |
| + std::unique_ptr<BeginFrameSource> target_source); |
|
Sami
2016/12/06 12:41:07
Sorry for the bikeshed but "target source" is brea
Eric Seckler
2016/12/06 17:34:00
Done.
|
| + ~DisplayBeginFrameSource() override; |
| + |
| + BeginFrameSource* GetTargetSource() { return target_source_.get(); } |
| + void SetClient(DisplayBeginFrameSourceClient* client) { client_ = client; } |
| + |
| + void SetClientNeedsBeginFrames(bool needs_begin_frames); |
| + |
| + // Returns |true| if all the source's observers completed the current frame. |
| + bool ObserversFinishedFrame(); |
|
Sami
2016/12/06 12:41:07
ditto: AllObservers...?
Eric Seckler
2016/12/06 17:34:00
Done.
|
| + |
| + // 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 FinishFrame(bool had_updates, bool has_pending_updates); |
|
Sami
2016/12/06 12:41:07
Should we call this FinishClientFrame()? I'd like
Eric Seckler
2016/12/06 17:34:00
Done.
|
| + |
| + // Swaps the current target 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 SwapTargetSource(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 ObserverStatusChanged(); |
| + |
| + std::unique_ptr<BeginFrameSource> target_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_ |