Commit 46607313 authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Added --animation-duration-scale to allow the setting of a duration scale factor for all

animations using and derived from LinearAnimation.

This allows for easier testing and tuning of the many animations throughout the code. By
setting a scale factor, animations can be sped up or slowed down. This allows for them
to be better observed to ensure the intermediate states for transitions, movements, and
fades look good.

Bug: None
Change-Id: Ia2350e71bf6f3bac3fae26351418a95d2452f415
Reviewed-on: https://chromium-review.googlesource.com/1138820
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576280}
parent a0dacdac
......@@ -8,12 +8,14 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_features.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
......@@ -86,9 +88,9 @@ MaterialDesignController::Mode MaterialDesignController::mode_ =
void MaterialDesignController::Initialize() {
TRACE_EVENT0("startup", "MaterialDesignController::InitializeMode");
CHECK(!is_mode_initialized_);
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
const std::string switch_value =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kTopChromeMD);
command_line->GetSwitchValueASCII(switches::kTopChromeMD);
bool force_material_refresh = false;
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
......@@ -125,8 +127,18 @@ void MaterialDesignController::Initialize() {
SetMode(DefaultMode());
}
// Ideally, there would be a more general, "initialize random stuff here"
// function into which these things and a call to this function can be placed.
// TODO(crbug.com/864544)
if (IsRefreshUi())
color_utils::SetDarkestColor(gfx::kGoogleGrey900);
double animation_duration_scale;
if (base::StringToDouble(
command_line->GetSwitchValueASCII(switches::kAnimationDurationScale),
&animation_duration_scale)) {
gfx::LinearAnimation::SetDurationScale(animation_duration_scale);
}
}
// static
......
......@@ -25,6 +25,10 @@ const char kDisableRemoteCoreAnimation[] = "disable-remote-core-animation";
const char kShowMacOverlayBorders[] = "show-mac-overlay-borders";
#endif
// Scale factor to apply to every animation duration. Must be >= 0.0. This will
// only apply to LinearAnimation and its subclasses.
const char kAnimationDurationScale[] = "animation-duration-scale";
// Disables layer-edge anti-aliasing in the compositor.
const char kDisableCompositedAntialiasing[] = "disable-composited-antialiasing";
......
......@@ -20,6 +20,7 @@ UI_BASE_EXPORT extern const char kDisableRemoteCoreAnimation[];
UI_BASE_EXPORT extern const char kShowMacOverlayBorders[];
#endif
UI_BASE_EXPORT extern const char kAnimationDurationScale[];
UI_BASE_EXPORT extern const char kDisableCompositedAntialiasing[];
UI_BASE_EXPORT extern const char kDisableDwmComposition[];
UI_BASE_EXPORT extern const char kDisableTouchAdjustment[];
......
......@@ -12,6 +12,12 @@
#include "ui/gfx/animation/animation_container.h"
#include "ui/gfx/animation/animation_delegate.h"
namespace {
double g_duration_scale_factor = 1.0;
} // namespace
namespace gfx {
static base::TimeDelta CalculateInterval(int frame_rate) {
......@@ -58,13 +64,19 @@ void LinearAnimation::End() {
}
void LinearAnimation::SetDuration(base::TimeDelta duration) {
duration_ = duration;
duration_ = duration * g_duration_scale_factor;
if (duration_ < timer_interval())
duration_ = timer_interval();
if (is_animating())
SetStartTime(container()->last_tick_time());
}
// static
void LinearAnimation::SetDurationScale(const double scale_factor) {
if (scale_factor >= 0.0)
g_duration_scale_factor = scale_factor;
}
void LinearAnimation::Step(base::TimeTicks time_now) {
base::TimeDelta elapsed_time = time_now - start_time();
state_ = static_cast<double>(elapsed_time.InMicroseconds()) /
......
......@@ -46,9 +46,15 @@ class ANIMATION_EXPORT LinearAnimation : public Animation {
void End();
// Changes the length of the animation. This resets the current
// state of the animation to the beginning.
// state of the animation to the beginning. This value will be multiplied by
// the currently set scale factor.
void SetDuration(base::TimeDelta duration);
// Sets the duration scale factor. This scale factor will be applied to all
// animation durations globally. This value must be >= 0. The default value
// is 1.0.
static void SetDurationScale(double scale_factor);
protected:
// Called when the animation progresses. Subclasses override this to
// efficiently update their state.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment