forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Frame throttling in overview mode (browsers only)
Ideally, frame submission is expected to be at full rate of 60fps. However, in many scenarios, this is not necessary. For example, when a window is (partially) occluded by another window, or when a window is behind a backdrop filter that blurs its content, or when a window is going through an animation (e.g. going in or out of overview mode). In such cases, we'd like to submit frames to a lower fps to improve performance - this is where the frame throttling comes in. This changelist only deals with browser windows, and when UI is going into and out of overview mode. We'd like to throttle the BeginFrames (ShouldSendBeginFrames), so that all the browser windows in overview mode will update at a reasonable lower fps. Here is the design doc if you'd like to inspect more. https://docs.google.com/document/d/1kvCIuA_xsh1VAsFiC5i1paAtjkGm2z-hFhFXWYfL7Sg/edit?usp=sharing Bug: 1095670 Change-Id: I8c9697fa5c0886032525395355d3c8ce76e439cd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2246716 Reviewed-by: kylechar <kylechar@chromium.org> Reviewed-by: Mitsuru Oshima <oshima@chromium.org> Reviewed-by: Will Harris <wfh@chromium.org> Commit-Queue: Jun Liu <yjliu@chromium.org> Auto-Submit: Jun Liu <yjliu@chromium.org> Cr-Commit-Position: refs/heads/master@{#789550}
- Loading branch information
yjliu
authored and
Commit Bot
committed
Jul 17, 2020
1 parent
06bec5c
commit 10679cf
Showing
18 changed files
with
392 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2020 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 "ash/frame_throttler/frame_throttling_controller.h" | ||
#include "ash/public/cpp/app_types.h" | ||
#include "components/viz/common/surfaces/frame_sink_id.h" | ||
#include "components/viz/host/host_frame_sink_manager.h" | ||
#include "ui/aura/client/aura_constants.h" | ||
#include "ui/aura/window.h" | ||
|
||
namespace ash { | ||
|
||
namespace { | ||
|
||
void CollectFrameSinkIds(const aura::Window* window, | ||
std::vector<viz::FrameSinkId>* frame_sink_ids) { | ||
if (window->GetFrameSinkId().is_valid()) { | ||
frame_sink_ids->push_back(window->GetFrameSinkId()); | ||
return; | ||
} | ||
for (auto* child : window->children()) { | ||
CollectFrameSinkIds(child, frame_sink_ids); | ||
} | ||
} | ||
|
||
void CollectBrowserFrameSinkIds(const std::vector<aura::Window*>& windows, | ||
std::vector<viz::FrameSinkId>* frame_sink_ids) { | ||
for (auto* window : windows) { | ||
if (ash::AppType::BROWSER == static_cast<ash::AppType>(window->GetProperty( | ||
aura::client::kAppType))) { | ||
CollectFrameSinkIds(window, frame_sink_ids); | ||
} | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
FrameThrottlingController::FrameThrottlingController( | ||
ui::ContextFactory* context_factory) | ||
: context_factory_(context_factory) {} | ||
|
||
FrameThrottlingController::~FrameThrottlingController() { | ||
EndThrottling(); | ||
} | ||
|
||
void FrameThrottlingController::StartThrottling( | ||
const std::vector<aura::Window*>& windows, | ||
uint8_t fps) { | ||
std::vector<viz::FrameSinkId> frame_sink_ids; | ||
frame_sink_ids.reserve(windows.size()); | ||
|
||
CollectBrowserFrameSinkIds(windows, &frame_sink_ids); | ||
StartThrottling(frame_sink_ids, fps); | ||
} | ||
|
||
void FrameThrottlingController::StartThrottling( | ||
const std::vector<viz::FrameSinkId>& frame_sink_ids, | ||
uint8_t fps) { | ||
DCHECK_GT(fps, 0); | ||
if (context_factory_ && !frame_sink_ids.empty()) { | ||
context_factory_->GetHostFrameSinkManager()->StartThrottling( | ||
frame_sink_ids, base::TimeDelta::FromSeconds(1) / fps); | ||
} | ||
} | ||
|
||
void FrameThrottlingController::EndThrottling() { | ||
if (context_factory_) | ||
context_factory_->GetHostFrameSinkManager()->EndThrottling(); | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2020 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 ASH_FRAME_THROTTLER_FRAME_THROTTLING_CONTROLLER_H_ | ||
#define ASH_FRAME_THROTTLER_FRAME_THROTTLING_CONTROLLER_H_ | ||
|
||
#include <stdint.h> | ||
#include <vector> | ||
#include "ash/ash_export.h" | ||
#include "base/macros.h" | ||
#include "components/viz/common/surfaces/frame_sink_id.h" | ||
|
||
namespace aura { | ||
class Window; | ||
} | ||
|
||
namespace ui { | ||
class ContextFactory; | ||
} | ||
|
||
namespace ash { | ||
|
||
constexpr uint8_t kDefaultThrottleFps = 20; | ||
|
||
class ASH_EXPORT FrameThrottlingController { | ||
public: | ||
explicit FrameThrottlingController(ui::ContextFactory* context_factory); | ||
~FrameThrottlingController(); | ||
|
||
// Starts to throttle the framerate of |windows|. | ||
void StartThrottling(const std::vector<aura::Window*>& windows, | ||
uint8_t fps = kDefaultThrottleFps); | ||
// Ends throttling of all throttled windows. | ||
void EndThrottling(); | ||
|
||
private: | ||
void StartThrottling(const std::vector<viz::FrameSinkId>& frame_sink_ids, | ||
uint8_t fps); | ||
|
||
ui::ContextFactory* context_factory_; | ||
|
||
friend class FrameThrottlingControllerTest; | ||
DISALLOW_COPY_AND_ASSIGN(FrameThrottlingController); | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_FRAME_THROTTLER_FRAME_THROTTLING_CONTROLLER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.