summaryrefslogtreecommitdiff
path: root/chromium/media/gpu/android/promotion_hint_aggregator_impl.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-18 14:34:04 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-10-04 11:15:27 +0000
commite6430e577f105ad8813c92e75c54660c4985026e (patch)
tree88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/media/gpu/android/promotion_hint_aggregator_impl.cc
parent53d399fe6415a96ea6986ec0d402a9c07da72453 (diff)
downloadqtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/media/gpu/android/promotion_hint_aggregator_impl.cc')
-rw-r--r--chromium/media/gpu/android/promotion_hint_aggregator_impl.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/chromium/media/gpu/android/promotion_hint_aggregator_impl.cc b/chromium/media/gpu/android/promotion_hint_aggregator_impl.cc
new file mode 100644
index 00000000000..ec5ab7885b5
--- /dev/null
+++ b/chromium/media/gpu/android/promotion_hint_aggregator_impl.cc
@@ -0,0 +1,73 @@
+// Copyright 2017 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.
+
+#include "media/gpu/android/promotion_hint_aggregator_impl.h"
+
+#include "base/bind.h"
+#include "base/memory/ptr_util.h"
+#include "base/time/default_tick_clock.h"
+
+namespace media {
+
+// Minimum amount of time between promotable frames before we start over. The
+// idea is to prevent promoting on paused / background rendering. Note that
+// this time is only enforced when transitioning from unpromotable to promotable
+// frames. We don't unpromote later because of this.
+constexpr base::TimeDelta MaximumInterFrameTime =
+ base::TimeDelta::FromMilliseconds(100);
+
+// Minimum number of consecutive promotable frames before we actually start
+// promoting frames.
+constexpr int MinimumPromotableFrames = 10;
+
+// Minimum time since the last unpromotable frame that we require before we will
+// promote new ones.
+constexpr base::TimeDelta MinimumUnpromotableFrameTime =
+ base::TimeDelta::FromMilliseconds(2000);
+
+PromotionHintAggregatorImpl::PromotionHintAggregatorImpl(
+ base::TickClock* tick_clock)
+ : weak_ptr_factory_(this) {
+ if (!tick_clock) {
+ clock_we_own_ = base::MakeUnique<base::DefaultTickClock>();
+ tick_clock = clock_we_own_.get();
+ }
+
+ tick_clock_ = tick_clock;
+}
+
+PromotionHintAggregatorImpl::~PromotionHintAggregatorImpl() {}
+
+void PromotionHintAggregatorImpl::NotifyPromotionHint(const Hint& hint) {
+ base::TimeTicks now = tick_clock_->NowTicks();
+
+ if (!hint.is_promotable) {
+ most_recent_unpromotable_ = now;
+ consecutive_promotable_frames_ = 0;
+ } else if (!IsSafeToPromote() &&
+ now - most_recent_update_ > MaximumInterFrameTime) {
+ // Promotable, but we aren't getting frames fast enough to count. We
+ // don't want to transition to promotable unless frames are actually
+ // playing. We check IsSafeToPromote() so that we don't transition back
+ // to unpromotable just because it's paused; that would cause the frame
+ // to become unrenderable. We just want to delay the transition into
+ // promotable until it works.
+ consecutive_promotable_frames_ = 1;
+ } else {
+ // Promotable frame, and we're getting frames fast enough.
+ consecutive_promotable_frames_++;
+ }
+
+ most_recent_update_ = now;
+}
+
+bool PromotionHintAggregatorImpl::IsSafeToPromote() {
+ base::TimeTicks now = tick_clock_->NowTicks();
+ base::TimeDelta since_last_unpromotable = now - most_recent_unpromotable_;
+
+ return consecutive_promotable_frames_ >= MinimumPromotableFrames &&
+ since_last_unpromotable >= MinimumUnpromotableFrameTime;
+}
+
+} // namespace media