Commit 1165da6c authored by Stephen McGruer's avatar Stephen McGruer Committed by Commit Bot

Refactor filter interpolation functions into an InterpolableFilter

This CL is part of the shift away from NonInterpolableValues to instead
having more InterpolableValue subclasses. It introduces a new subclass,
InterpolableFilter, which can represent a blink::FilterOperation. This
should enable us to more easily implement the correct additive behavior
for filter, see [0].

There should be no behavioral change from this CL, it is (intended to
be) a pure refactoring.

Bug: 1005828

[0]: https://docs.google.com/document/d/1aAvTNwxSSl0OWP3hQAV-Q7ru5-o5MzV4UEz7Uw9VHZk/edit#heading=h.9b2xtih585di

Change-Id: Ib60b5857167db8950f3eb457cfaeec98ee781ff1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1817284
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700843}
parent c281c2a5
...@@ -152,12 +152,12 @@ blink_core_sources("animation") { ...@@ -152,12 +152,12 @@ blink_core_sources("animation") {
"effect_stack.h", "effect_stack.h",
"element_animations.cc", "element_animations.cc",
"element_animations.h", "element_animations.h",
"filter_interpolation_functions.cc",
"filter_interpolation_functions.h",
"image_list_property_functions.h", "image_list_property_functions.h",
"image_slice_property_functions.h", "image_slice_property_functions.h",
"inert_effect.cc", "inert_effect.cc",
"inert_effect.h", "inert_effect.h",
"interpolable_filter.cc",
"interpolable_filter.h",
"interpolable_length.cc", "interpolable_length.cc",
"interpolable_length.h", "interpolable_length.h",
"interpolable_shadow.cc", "interpolable_shadow.cc",
......
// 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 THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_FILTER_INTERPOLATION_FUNCTIONS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_FILTER_INTERPOLATION_FUNCTIONS_H_
#include <memory>
#include "third_party/blink/renderer/core/animation/interpolation_value.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
class FilterOperation;
class CSSValue;
class StyleResolverState;
namespace filter_interpolation_functions {
InterpolationValue MaybeConvertCSSFilter(const CSSValue&);
InterpolationValue MaybeConvertFilter(const FilterOperation&, double zoom);
std::unique_ptr<InterpolableValue> CreateNoneValue(const NonInterpolableValue&);
bool FiltersAreCompatible(const NonInterpolableValue&,
const NonInterpolableValue&);
FilterOperation* CreateFilter(const InterpolableValue&,
const NonInterpolableValue&,
const StyleResolverState&);
} // namespace filter_interpolation_functions
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_FILTER_INTERPOLATION_FUNCTIONS_H_
// Copyright 2019 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 THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLABLE_FILTER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLABLE_FILTER_H_
#include <memory>
#include "third_party/blink/renderer/core/animation/interpolable_value.h"
#include "third_party/blink/renderer/core/style/filter_operation.h"
namespace blink {
class CSSValue;
class StyleResolverState;
// Represents a blink::FilterOperation, converted into a form that can be
// interpolated from/to.
class CORE_EXPORT InterpolableFilter final : public InterpolableValue {
public:
InterpolableFilter(std::unique_ptr<InterpolableValue> value,
FilterOperation::OperationType type)
: value_(std::move(value)), type_(type) {
DCHECK(value_);
}
static std::unique_ptr<InterpolableFilter> MaybeCreate(const FilterOperation&,
double zoom);
static std::unique_ptr<InterpolableFilter> MaybeConvertCSSValue(
const CSSValue&);
// Create an InterpolableFilter representing the 'initial value for
// interpolation' for the given OperationType.
static std::unique_ptr<InterpolableFilter> CreateInitialValue(
FilterOperation::OperationType);
FilterOperation::OperationType GetType() const { return type_; }
// Convert this InterpolableFilter back into a FilterOperation class, usually
// to be applied to the style after interpolating |this|.
FilterOperation* CreateFilterOperation(const StyleResolverState&) const;
// InterpolableValue implementation:
void Interpolate(const InterpolableValue& to,
const double progress,
InterpolableValue& result) const final;
bool IsFilter() const final { return true; }
bool Equals(const InterpolableValue& other) const final {
NOTREACHED();
return false;
}
void Scale(double scale) final { NOTREACHED(); }
void ScaleAndAdd(double scale, const InterpolableValue& other) final {
value_->ScaleAndAdd(scale, *To<InterpolableFilter>(other).value_);
}
void AssertCanInterpolateWith(const InterpolableValue& other) const final;
private:
InterpolableFilter* RawClone() const final {
return new InterpolableFilter(value_->Clone(), type_);
}
InterpolableFilter* RawCloneAndZero() const final {
return new InterpolableFilter(value_->CloneAndZero(), type_);
}
// Stores the interpolable data for the filter. The form varies depending on
// the |type_|; see the implementation file for details of the mapping.
std::unique_ptr<InterpolableValue> value_;
FilterOperation::OperationType type_;
};
template <>
struct DowncastTraits<InterpolableFilter> {
static bool AllowFrom(const InterpolableValue& interpolable_value) {
return interpolable_value.IsFilter();
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLABLE_FILTER_H_
...@@ -39,6 +39,7 @@ class CORE_EXPORT InterpolableValue { ...@@ -39,6 +39,7 @@ class CORE_EXPORT InterpolableValue {
virtual bool IsList() const { return false; } virtual bool IsList() const { return false; }
virtual bool IsLength() const { return false; } virtual bool IsLength() const { return false; }
virtual bool IsShadow() const { return false; } virtual bool IsShadow() const { return false; }
virtual bool IsFilter() const { return false; }
// TODO(alancutter): Remove Equals(). // TODO(alancutter): Remove Equals().
virtual bool Equals(const InterpolableValue&) const = 0; virtual bool Equals(const InterpolableValue&) const = 0;
......
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