Commit e048b58b authored by Vladimir Levin's avatar Vladimir Levin Committed by Chromium LUCI CQ

[DocumentTransition]: Add viz transition directive.

This patch adds a transition directive class to viz. It isn't currently
used outside of unittests, but will be referenced in cc and indirectly
from Blink in order to construct the right directive for viz to execute.

R=kylechar@chromium.org

Bug: 1150461
Change-Id: I9cbe63507148405b0a363ee6d957d76b1a18b34e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2568985
Commit-Queue: vmpstr <vmpstr@chromium.org>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833759}
parent 6b6ca1e4
...@@ -196,6 +196,8 @@ viz_component("common") { ...@@ -196,6 +196,8 @@ viz_component("common") {
"quads/compositor_frame.h", "quads/compositor_frame.h",
"quads/compositor_frame_metadata.cc", "quads/compositor_frame_metadata.cc",
"quads/compositor_frame_metadata.h", "quads/compositor_frame_metadata.h",
"quads/compositor_frame_transition_directive.cc",
"quads/compositor_frame_transition_directive.h",
"quads/compositor_render_pass.cc", "quads/compositor_render_pass.cc",
"quads/compositor_render_pass.h", "quads/compositor_render_pass.h",
"quads/compositor_render_pass_draw_quad.cc", "quads/compositor_render_pass_draw_quad.cc",
...@@ -353,6 +355,7 @@ viz_source_set("unit_tests") { ...@@ -353,6 +355,7 @@ viz_source_set("unit_tests") {
"frame_sinks/copy_output_util_unittest.cc", "frame_sinks/copy_output_util_unittest.cc",
"frame_sinks/delay_based_time_source_unittest.cc", "frame_sinks/delay_based_time_source_unittest.cc",
"gpu/context_cache_controller_unittest.cc", "gpu/context_cache_controller_unittest.cc",
"quads/compositor_frame_transition_directive_unittest.cc",
"quads/compositor_render_pass_unittest.cc", "quads/compositor_render_pass_unittest.cc",
"quads/draw_quad_unittest.cc", "quads/draw_quad_unittest.cc",
"quads/render_pass_io_unittest.cc", "quads/render_pass_io_unittest.cc",
......
// 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 "components/viz/common/quads/compositor_frame_transition_directive.h"
#include "base/time/time.h"
namespace viz {
constexpr base::TimeDelta CompositorFrameTransitionDirective::kMaxDuration;
CompositorFrameTransitionDirective::CompositorFrameTransitionDirective(
uint32_t sequence_id,
Type type,
Effect effect,
base::TimeDelta duration)
: sequence_id_(sequence_id),
type_(type),
effect_(effect),
duration_(duration) {
DCHECK_LE(duration_, kMaxDuration);
}
} // namespace viz
// 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 COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_TRANSITION_DIRECTIVE_H_
#define COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_TRANSITION_DIRECTIVE_H_
#include "base/time/time.h"
#include "components/viz/common/viz_common_export.h"
namespace viz {
// This is a transition directive that can be associcated with a compositor
// frame. The intent is to be able to animate a compositor frame into the right
// place instead of simply drawing the final result at the final destination.
// This is used by a JavaScript-exposed document transitions API. See
// third_party/blink/renderer/core/document_transition/README.md for more
// information.
class VIZ_COMMON_EXPORT CompositorFrameTransitionDirective {
public:
// What is the directive?
// - Save means that the currently submitted frame will be used in the future
// as the source frame of the animation.
// - Animate means that this frame should be used as a (new) destination frame
// of the animation, using the previously saved frame as the source.
enum class Type { kSave, kAnimate };
// The type of an effect that should be used in the animation.
enum class Effect {
kNone,
kCoverDown,
kCoverLeft,
kCoverRight,
kCoverUp,
kExplode,
kFade,
kImplode,
kRevealDown,
kRevealLeft,
kRevealRight,
kRevealUp
};
// This is the maximum allowable transition duration.
static constexpr base::TimeDelta kMaxDuration =
base::TimeDelta::FromMilliseconds(500);
// Constructs a new directive. Note that if type is `kSave`, the effect and
// duration should be specified for a desired effect. These are ignored for
// the `kAnimate` type.
CompositorFrameTransitionDirective(uint32_t sequence_id,
Type type,
Effect effect = Effect::kNone,
base::TimeDelta duration = {});
// A monotonically increasing sequence_id for a given communication channel
// (i.e. surface). This is used to distinguish new directives from directives
// that have already been processed.
uint32_t sequence_id() const { return sequence_id_; }
// The type of this directive.
Type type() const { return type_; }
// The duration of the animation. Note that this is at most kMaxDuration.
base::TimeDelta duration() const { return duration_; }
// The effect for the transition.
Effect effect() const { return effect_; }
private:
uint32_t sequence_id_;
Type type_;
Effect effect_;
base::TimeDelta duration_;
};
} // namespace viz
#endif // COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_TRANSITION_DIRECTIVE_H_
// 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 "components/viz/common/quads/compositor_frame_transition_directive.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace viz {
namespace {
using Effect = CompositorFrameTransitionDirective::Effect;
using Type = CompositorFrameTransitionDirective::Type;
TEST(CompositorFrameTransitionDirective, GettersReflectParameters) {
CompositorFrameTransitionDirective save_directive(
1u, Type::kSave, Effect::kCoverLeft,
base::TimeDelta::FromMilliseconds(100));
EXPECT_EQ(1u, save_directive.sequence_id());
EXPECT_EQ(Type::kSave, save_directive.type());
EXPECT_EQ(Effect::kCoverLeft, save_directive.effect());
EXPECT_EQ(base::TimeDelta::FromMilliseconds(100), save_directive.duration());
CompositorFrameTransitionDirective animate_directive(2, Type::kAnimate);
EXPECT_EQ(2u, animate_directive.sequence_id());
EXPECT_EQ(Type::kAnimate, animate_directive.type());
}
} // namespace
} // namespace viz
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