Add cc::PathEffect to wrap SkPathEffect
Removes another instance of SkFlattenable serialization. Bug: chromium:40064090 Change-Id: Ie82c8fd353382d4db5071809dabe1dcc5444e70d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5420809 Reviewed-by: Keren Zhu <kerenzhu@chromium.org> Reviewed-by: Florin Malita <fmalita@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Xianzhu Wang <wangxianzhu@chromium.org> Commit-Queue: Brian Osman <brianosman@google.com> Cr-Commit-Position: refs/heads/main@{#1284815}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
dfd7a35f02
commit
3e05240748
ash
accessibility
hud_display
cc
paint
BUILD.gnpaint_flags.ccpaint_flags.hpaint_op.ccpaint_op_buffer_unittest.ccpaint_op_perftest.ccpaint_op_reader.ccpaint_op_reader.hpaint_op_writer.ccpaint_op_writer.hpath_effect.ccpath_effect.h
test
components/ui_devtools/views
third_party/blink
renderer
modules
canvas
platform
tools
blinkpy
presubmit
ui/gfx
@ -7,7 +7,6 @@
|
||||
#include "ash/shell.h"
|
||||
#include "third_party/skia/include/core/SkPaint.h"
|
||||
#include "third_party/skia/include/core/SkPath.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/compositor/paint_recorder.h"
|
||||
@ -93,7 +92,8 @@ void PointScanLayer::OnPaintLayer(const ui::PaintContext& context) {
|
||||
if (!is_moving_) {
|
||||
SkScalar intervals[] = {kDashLengthDips, kGapLengthDips};
|
||||
int intervals_length = 2;
|
||||
flags.setPathEffect(SkDashPathEffect::Make(intervals, intervals_length, 0));
|
||||
flags.setPathEffect(
|
||||
cc::PathEffect::MakeDash(intervals, intervals_length, 0));
|
||||
}
|
||||
|
||||
flags.setColor(kOuterColor);
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "base/functional/bind.h"
|
||||
#include "third_party/skia/include/core/SkPaint.h"
|
||||
#include "third_party/skia/include/core/SkPath.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/gfx/canvas.h"
|
||||
@ -190,7 +189,7 @@ void AccessibilityFocusRingLayer::DrawDashedFocusRing(
|
||||
|
||||
SkScalar intervals[] = {kDashLengthDip, kGapLengthDip};
|
||||
int intervals_length = 2;
|
||||
flags.setPathEffect(SkDashPathEffect::Make(intervals, intervals_length, 0));
|
||||
flags.setPathEffect(cc::PathEffect::MakeDash(intervals, intervals_length, 0));
|
||||
flags.setColor(secondary_color_);
|
||||
|
||||
path = MakePath(ring_, kDefaultStrokeWidth, offset);
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "third_party/skia/include/core/SkBlendMode.h"
|
||||
#include "third_party/skia/include/core/SkPaint.h"
|
||||
#include "third_party/skia/include/core/SkPath.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
#include "ui/base/metadata/metadata_impl_macros.h"
|
||||
#include "ui/gfx/canvas.h"
|
||||
#include "ui/gfx/text_constants.h"
|
||||
@ -198,7 +197,7 @@ void ReferenceLines::OnPaint(gfx::Canvas* canvas) {
|
||||
canvas->DrawPath(solid_path, flags);
|
||||
|
||||
const SkScalar intervals[] = {5, 3};
|
||||
flags.setPathEffect(SkDashPathEffect::Make(
|
||||
flags.setPathEffect(cc::PathEffect::MakeDash(
|
||||
intervals, sizeof(intervals) / sizeof(intervals[0]), /*phase=*/0));
|
||||
canvas->DrawPath(dotted_path, flags);
|
||||
}
|
||||
|
@ -77,6 +77,8 @@ cc_component("paint") {
|
||||
"paint_worklet_job.cc",
|
||||
"paint_worklet_job.h",
|
||||
"paint_worklet_layer_painter.h",
|
||||
"path_effect.cc",
|
||||
"path_effect.h",
|
||||
"raw_memory_transfer_cache_entry.cc",
|
||||
"raw_memory_transfer_cache_entry.h",
|
||||
"record_paint_canvas.cc",
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "cc/paint/paint_op_buffer.h"
|
||||
#include "cc/paint/paint_shader.h"
|
||||
#include "third_party/skia/include/core/SkColorFilter.h"
|
||||
#include "third_party/skia/include/core/SkPathEffect.h"
|
||||
#include "third_party/skia/include/core/SkPathUtils.h"
|
||||
|
||||
namespace {
|
||||
@ -137,15 +138,19 @@ bool PaintFlags::SupportsFoldingAlpha() const {
|
||||
|
||||
SkPaint PaintFlags::ToSkPaint() const {
|
||||
SkPaint paint;
|
||||
paint.setPathEffect(path_effect_);
|
||||
if (shader_)
|
||||
if (path_effect_) {
|
||||
paint.setPathEffect(path_effect_->GetSkPathEffect());
|
||||
}
|
||||
if (shader_) {
|
||||
paint.setShader(shader_->GetSkShader(getFilterQuality()));
|
||||
}
|
||||
paint.setMaskFilter(mask_filter_);
|
||||
if (color_filter_) {
|
||||
paint.setColorFilter(color_filter_->sk_color_filter_);
|
||||
}
|
||||
if (image_filter_)
|
||||
if (image_filter_) {
|
||||
paint.setImageFilter(image_filter_->cached_sk_filter_);
|
||||
}
|
||||
paint.setColor(color_);
|
||||
paint.setStrokeWidth(width_);
|
||||
paint.setStrokeMiter(miter_limit_);
|
||||
@ -192,8 +197,8 @@ bool PaintFlags::EqualsForTesting(const PaintFlags& other) const {
|
||||
getFilterQuality() == other.getFilterQuality() &&
|
||||
getDynamicRangeLimit() == other.getDynamicRangeLimit() &&
|
||||
isArcClosed() == other.isArcClosed() &&
|
||||
AreSkFlattenablesEqualForTesting(path_effect_, // IN-TEST
|
||||
other.path_effect_) &&
|
||||
AreValuesEqualForTesting(path_effect_, // IN-TEST
|
||||
other.path_effect_) &&
|
||||
AreSkFlattenablesEqualForTesting(mask_filter_, // IN-TEST
|
||||
other.mask_filter_) &&
|
||||
AreValuesEqualForTesting(color_filter_, // IN-TEST
|
||||
|
@ -11,12 +11,13 @@
|
||||
#include "cc/paint/color_filter.h"
|
||||
#include "cc/paint/draw_looper.h"
|
||||
#include "cc/paint/paint_export.h"
|
||||
#include "cc/paint/path_effect.h"
|
||||
#include "third_party/skia/include/core/SkMaskFilter.h"
|
||||
#include "third_party/skia/include/core/SkPaint.h"
|
||||
#include "third_party/skia/include/core/SkPathEffect.h"
|
||||
#include "third_party/skia/include/core/SkSamplingOptions.h"
|
||||
|
||||
class SkCanvas;
|
||||
class SkPath;
|
||||
|
||||
namespace cc {
|
||||
class PaintFilter;
|
||||
@ -189,10 +190,10 @@ class CC_PAINT_EXPORT PaintFlags {
|
||||
|
||||
void setShader(sk_sp<PaintShader> shader);
|
||||
|
||||
ALWAYS_INLINE const sk_sp<SkPathEffect>& getPathEffect() const {
|
||||
ALWAYS_INLINE const sk_sp<PathEffect>& getPathEffect() const {
|
||||
return path_effect_;
|
||||
}
|
||||
ALWAYS_INLINE void setPathEffect(sk_sp<SkPathEffect> effect) {
|
||||
ALWAYS_INLINE void setPathEffect(sk_sp<PathEffect> effect) {
|
||||
path_effect_ = std::move(effect);
|
||||
}
|
||||
bool getFillPath(const SkPath& src,
|
||||
@ -243,7 +244,7 @@ class CC_PAINT_EXPORT PaintFlags {
|
||||
friend class PaintOpReader;
|
||||
friend class PaintOpWriter;
|
||||
|
||||
sk_sp<SkPathEffect> path_effect_;
|
||||
sk_sp<PathEffect> path_effect_;
|
||||
sk_sp<PaintShader> shader_;
|
||||
sk_sp<SkMaskFilter> mask_filter_;
|
||||
sk_sp<ColorFilter> color_filter_;
|
||||
|
@ -2144,11 +2144,9 @@ int ClipPathOp::CountSlowPaths() const {
|
||||
}
|
||||
|
||||
int DrawLineOp::CountSlowPaths() const {
|
||||
if (const SkPathEffect* effect = flags.getPathEffect().get()) {
|
||||
SkPathEffect::DashInfo info;
|
||||
SkPathEffect::DashType dashType = effect->asADash(&info);
|
||||
if (const PathEffect* effect = flags.getPathEffect().get()) {
|
||||
if (flags.getStrokeCap() != PaintFlags::kRound_Cap &&
|
||||
dashType == SkPathEffect::kDash_DashType && info.fCount == 2) {
|
||||
effect->dash_interval_count() == 2) {
|
||||
// The PaintFlags will count this as 1, so uncount that here as
|
||||
// this kind of line is special cased and not slow.
|
||||
return -1;
|
||||
|
@ -57,7 +57,6 @@
|
||||
#include "third_party/skia/include/core/SkTextBlob.h"
|
||||
#include "third_party/skia/include/core/SkTileMode.h"
|
||||
#include "third_party/skia/include/effects/SkColorMatrixFilter.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
#include "third_party/skia/include/private/chromium/SkChromeRemoteGlyphCache.h"
|
||||
#include "ui/gfx/geometry/test/geometry_util.h"
|
||||
|
||||
@ -557,7 +556,7 @@ TEST(PaintOpBufferTest, SlowPaths) {
|
||||
line_effect_slow.setStyle(PaintFlags::kStroke_Style);
|
||||
line_effect_slow.setStrokeCap(PaintFlags::kRound_Cap);
|
||||
SkScalar intervals[] = {1.f, 1.f};
|
||||
line_effect_slow.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0));
|
||||
line_effect_slow.setPathEffect(PathEffect::MakeDash(intervals, 2, 0));
|
||||
|
||||
buffer.push<DrawLineOp>(1.f, 2.f, 3.f, 4.f, line_effect_slow);
|
||||
EXPECT_EQ(buffer.num_slow_paths_up_to_min_for_MSAA(), 1);
|
||||
@ -1184,7 +1183,7 @@ std::vector<PaintFlags> test_flags = {
|
||||
flags.setFilterQuality(PaintFlags::FilterQuality::kHigh);
|
||||
|
||||
SkScalar intervals[] = {1.f, 1.f};
|
||||
flags.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0));
|
||||
flags.setPathEffect(PathEffect::MakeDash(intervals, 2, 0));
|
||||
flags.setMaskFilter(SkMaskFilter::MakeBlur(
|
||||
SkBlurStyle::kOuter_SkBlurStyle, 4.3f));
|
||||
flags.setColorFilter(ColorFilter::MakeBlend({0.4f, 0.3f, 0.2f, 0.1f},
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkMaskFilter.h"
|
||||
#include "third_party/skia/include/effects/SkColorMatrixFilter.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
|
||||
namespace cc {
|
||||
namespace {
|
||||
@ -125,7 +124,7 @@ TEST_F(PaintOpPerfTest, ManyFlagsOps) {
|
||||
|
||||
PaintFlags flags;
|
||||
SkScalar intervals[] = {1.f, 1.f};
|
||||
flags.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0));
|
||||
flags.setPathEffect(PathEffect::MakeDash(intervals, 2, 0));
|
||||
flags.setMaskFilter(SkMaskFilter::MakeBlur(
|
||||
SkBlurStyle::kOuter_SkBlurStyle, 4.3));
|
||||
flags.setColorFilter(ColorFilter::MakeLuma());
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "cc/paint/paint_image_builder.h"
|
||||
#include "cc/paint/paint_op_buffer.h"
|
||||
#include "cc/paint/paint_shader.h"
|
||||
#include "cc/paint/path_effect.h"
|
||||
#include "cc/paint/shader_transfer_cache_entry.h"
|
||||
#include "cc/paint/skottie_transfer_cache_entry.h"
|
||||
#include "cc/paint/skottie_wrapper.h"
|
||||
@ -312,8 +313,7 @@ void PaintOpReader::Read(PaintFlags* flags) {
|
||||
|
||||
ReadSimple(&flags->bitfields_uint_);
|
||||
|
||||
ReadFlattenable(&flags->path_effect_, SkPathEffect::Deserialize,
|
||||
DeserializationError::kSkPathEffectUnflattenFailure);
|
||||
Read(&flags->path_effect_);
|
||||
ReadFlattenable(&flags->mask_filter_, SkMaskFilter::Deserialize,
|
||||
DeserializationError::kSkMaskFilterUnflattenFailure);
|
||||
Read(&flags->color_filter_);
|
||||
@ -981,6 +981,19 @@ void PaintOpReader::Read(sk_sp<ColorFilter>* filter) {
|
||||
*filter = ColorFilter::Deserialize(*this, type);
|
||||
}
|
||||
|
||||
void PaintOpReader::Read(sk_sp<PathEffect>* effect) {
|
||||
PathEffect::Type type;
|
||||
ReadEnum(&type);
|
||||
if (!valid_) {
|
||||
return;
|
||||
}
|
||||
if (type == PathEffect::Type::kNull) {
|
||||
*effect = nullptr;
|
||||
return;
|
||||
}
|
||||
*effect = PathEffect::Deserialize(*this, type);
|
||||
}
|
||||
|
||||
void PaintOpReader::Read(sk_sp<PaintFilter>* filter) {
|
||||
PaintFilter::Type type;
|
||||
ReadEnum(&type);
|
||||
|
@ -35,6 +35,7 @@ struct HDRMetadata;
|
||||
namespace cc {
|
||||
|
||||
class PaintShader;
|
||||
class PathEffect;
|
||||
class SkottieWrapper;
|
||||
|
||||
// PaintOpReader takes garbage |memory| and clobbers it with successive
|
||||
@ -260,6 +261,7 @@ class CC_PAINT_EXPORT PaintOpReader {
|
||||
void SetInvalid(DeserializationError error);
|
||||
|
||||
void Read(sk_sp<ColorFilter>* filter);
|
||||
void Read(sk_sp<PathEffect>* effect);
|
||||
|
||||
// The main entry point is Read(sk_sp<PaintFilter>* filter) which calls one of
|
||||
// the following functions depending on read type.
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "cc/paint/paint_flags.h"
|
||||
#include "cc/paint/paint_op_buffer_serializer.h"
|
||||
#include "cc/paint/paint_shader.h"
|
||||
#include "cc/paint/path_effect.h"
|
||||
#include "cc/paint/skottie_transfer_cache_entry.h"
|
||||
#include "cc/paint/skottie_wrapper.h"
|
||||
#include "cc/paint/transfer_cache_serialize_helper.h"
|
||||
@ -162,6 +163,16 @@ size_t PaintOpWriter::SerializedSize(const PaintFilter* filter) {
|
||||
return filter->SerializedSize();
|
||||
}
|
||||
|
||||
// static
|
||||
size_t PaintOpWriter::SerializedSize(const PathEffect* effect) {
|
||||
if (!effect) {
|
||||
return SerializedSize(PathEffect::Type::kNull);
|
||||
}
|
||||
base::CheckedNumeric<size_t> size = SerializedSize(effect->type_);
|
||||
size += effect->SerializedDataSize();
|
||||
return size.ValueOrDie();
|
||||
}
|
||||
|
||||
PaintOpWriter::~PaintOpWriter() = default;
|
||||
|
||||
size_t PaintOpWriter::FinishOp(uint8_t type) {
|
||||
@ -291,7 +302,7 @@ void PaintOpWriter::Write(const PaintFlags& flags, const SkM44& current_ctm) {
|
||||
WriteSimpleMultiple(
|
||||
flags.color_, flags.width_, flags.miter_limit_, flags.bitfields_uint_,
|
||||
// flags.path_effect_.
|
||||
uint32_t{0}, uint32_t{0},
|
||||
base::checked_cast<uint8_t>(PathEffect::Type::kNull),
|
||||
// flags.mask_filter_.
|
||||
uint32_t{0}, uint32_t{0},
|
||||
// flags.color_filter_.
|
||||
@ -310,7 +321,7 @@ void PaintOpWriter::Write(const PaintFlags& flags, const SkM44& current_ctm) {
|
||||
Write(flags.miter_limit_);
|
||||
WriteSimple(flags.bitfields_uint_);
|
||||
|
||||
WriteFlattenable(flags.path_effect_.get());
|
||||
Write(flags.path_effect_.get());
|
||||
WriteFlattenable(flags.mask_filter_.get());
|
||||
Write(flags.color_filter_.get());
|
||||
|
||||
@ -845,6 +856,15 @@ void PaintOpWriter::Write(const PaintFilter* filter, const SkM44& current_ctm) {
|
||||
}
|
||||
}
|
||||
|
||||
void PaintOpWriter::Write(const PathEffect* effect) {
|
||||
if (!effect) {
|
||||
WriteEnum(PathEffect::Type::kNull);
|
||||
return;
|
||||
}
|
||||
WriteEnum(effect->type_);
|
||||
effect->SerializeData(*this);
|
||||
}
|
||||
|
||||
void PaintOpWriter::Write(const ColorFilterPaintFilter& filter,
|
||||
const SkM44& current_ctm) {
|
||||
Write(filter.color_filter().get());
|
||||
|
@ -44,6 +44,7 @@ class DecodedDrawImage;
|
||||
class DrawImage;
|
||||
class DrawLooper;
|
||||
class PaintShader;
|
||||
class PathEffect;
|
||||
|
||||
class CC_PAINT_EXPORT PaintOpWriter {
|
||||
STACK_ALLOCATED();
|
||||
@ -155,6 +156,7 @@ class CC_PAINT_EXPORT PaintOpWriter {
|
||||
static size_t SerializedSize(const ColorFilter* filter);
|
||||
static size_t SerializedSize(const DrawLooper* looper);
|
||||
static size_t SerializedSize(const PaintFilter* filter);
|
||||
static size_t SerializedSize(const PathEffect* effect);
|
||||
|
||||
template <typename T>
|
||||
static size_t SerializedSize(const std::optional<T>& o) {
|
||||
@ -242,6 +244,7 @@ class CC_PAINT_EXPORT PaintOpWriter {
|
||||
void Write(const ColorFilter* filter);
|
||||
void Write(const DrawLooper* looper);
|
||||
void Write(const PaintFilter* filter, const SkM44& current_ctm);
|
||||
void Write(const PathEffect* effect);
|
||||
void Write(const gfx::HDRMetadata& hdr_metadata);
|
||||
|
||||
void Write(SkClipOp op) { WriteEnum(op); }
|
||||
|
152
cc/paint/path_effect.cc
Normal file
152
cc/paint/path_effect.cc
Normal file
@ -0,0 +1,152 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "cc/paint/path_effect.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "base/check_op.h"
|
||||
#include "base/notreached.h"
|
||||
#include "base/numerics/checked_math.h"
|
||||
#include "base/numerics/safe_conversions.h"
|
||||
#include "cc/paint/paint_op_reader.h"
|
||||
#include "cc/paint/paint_op_writer.h"
|
||||
#include "third_party/abseil-cpp/absl/container/inlined_vector.h"
|
||||
#include "third_party/skia/include/core/SkPathEffect.h"
|
||||
#include "third_party/skia/include/effects/SkCornerPathEffect.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
bool AreEqualForTesting(const PathEffect& a, const PathEffect& b) {
|
||||
return static_cast<const T&>(a).EqualsForTesting( // IN-TEST
|
||||
static_cast<const T&>(b));
|
||||
}
|
||||
|
||||
class DashPathEffect final : public PathEffect {
|
||||
public:
|
||||
explicit DashPathEffect(const float intervals[], int count, float phase)
|
||||
: PathEffect(Type::kDash),
|
||||
intervals_(intervals, intervals + count),
|
||||
phase_(phase) {}
|
||||
|
||||
bool EqualsForTesting(const DashPathEffect& other) const {
|
||||
return phase_ == other.phase_ && intervals_ == other.intervals_;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t SerializedDataSize() const override {
|
||||
return (base::CheckedNumeric<size_t>(
|
||||
PaintOpWriter::SerializedSizeOfElements(intervals_.data(),
|
||||
intervals_.size())) +
|
||||
PaintOpWriter::SerializedSize(phase_))
|
||||
.ValueOrDie();
|
||||
}
|
||||
void SerializeData(PaintOpWriter& writer) const override {
|
||||
// This serialization is identical to the behavior of
|
||||
// PaintOpWriter::Write(std::vector), which lets us use
|
||||
// PaintOpReader::Read(std::vector) below.
|
||||
writer.WriteSize(intervals_.size());
|
||||
writer.WriteData(intervals_.size() * sizeof(float), intervals_.data());
|
||||
writer.Write(phase_);
|
||||
}
|
||||
|
||||
sk_sp<SkPathEffect> GetSkPathEffect() const override {
|
||||
return SkDashPathEffect::Make(
|
||||
intervals_.data(), base::checked_cast<int>(intervals_.size()), phase_);
|
||||
}
|
||||
|
||||
size_t dash_interval_count() const override { return intervals_.size(); }
|
||||
|
||||
absl::InlinedVector<float, 2> intervals_;
|
||||
float phase_;
|
||||
};
|
||||
|
||||
class CornerPathEffect final : public PathEffect {
|
||||
public:
|
||||
explicit CornerPathEffect(float radius)
|
||||
: PathEffect(Type::kCorner), radius_(radius) {}
|
||||
|
||||
bool EqualsForTesting(const CornerPathEffect& other) const {
|
||||
return radius_ == other.radius_;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t SerializedDataSize() const override {
|
||||
return PaintOpWriter::SerializedSize(radius_);
|
||||
}
|
||||
void SerializeData(PaintOpWriter& writer) const override {
|
||||
writer.Write(radius_);
|
||||
}
|
||||
|
||||
sk_sp<SkPathEffect> GetSkPathEffect() const override {
|
||||
return SkCornerPathEffect::Make(radius_);
|
||||
}
|
||||
float radius_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
PathEffect::PathEffect(Type type) : type_(type) {
|
||||
DCHECK_NE(type, Type::kNull);
|
||||
}
|
||||
|
||||
sk_sp<PathEffect> PathEffect::MakeDash(const float* intervals,
|
||||
int count,
|
||||
float phase) {
|
||||
return sk_make_sp<DashPathEffect>(intervals, count, phase);
|
||||
}
|
||||
|
||||
sk_sp<PathEffect> PathEffect::MakeCorner(float radius) {
|
||||
return sk_make_sp<CornerPathEffect>(radius);
|
||||
}
|
||||
|
||||
size_t PathEffect::dash_interval_count() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool PathEffect::EqualsForTesting(const PathEffect& other) const {
|
||||
if (type_ != other.type_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (type_) {
|
||||
case Type::kNull:
|
||||
return true;
|
||||
case Type::kDash:
|
||||
return AreEqualForTesting<DashPathEffect>(*this, other);
|
||||
case Type::kCorner:
|
||||
return AreEqualForTesting<CornerPathEffect>(*this, other);
|
||||
}
|
||||
NOTREACHED();
|
||||
return true;
|
||||
}
|
||||
|
||||
sk_sp<PathEffect> PathEffect::Deserialize(PaintOpReader& reader, Type type) {
|
||||
switch (type) {
|
||||
case Type::kDash: {
|
||||
std::vector<float> intervals;
|
||||
float phase;
|
||||
reader.Read(&intervals);
|
||||
reader.Read(&phase);
|
||||
return reader.valid()
|
||||
? MakeDash(intervals.data(),
|
||||
base::checked_cast<int>(intervals.size()), phase)
|
||||
: nullptr;
|
||||
}
|
||||
case Type::kCorner: {
|
||||
float radius;
|
||||
reader.Read(&radius);
|
||||
return reader.valid() ? MakeCorner(radius) : nullptr;
|
||||
}
|
||||
default:
|
||||
NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cc
|
61
cc/paint/path_effect.h
Normal file
61
cc/paint/path_effect.h
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CC_PAINT_PATH_EFFECT_H_
|
||||
#define CC_PAINT_PATH_EFFECT_H_
|
||||
|
||||
#include "cc/paint/paint_export.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
|
||||
class SkPathEffect;
|
||||
|
||||
namespace cc {
|
||||
|
||||
class PaintOpWriter;
|
||||
class PaintOpReader;
|
||||
|
||||
class CC_PAINT_EXPORT PathEffect : public SkRefCnt {
|
||||
public:
|
||||
PathEffect(const PathEffect&) = delete;
|
||||
PathEffect& operator=(const PathEffect&) = delete;
|
||||
|
||||
static sk_sp<PathEffect> MakeDash(const float intervals[],
|
||||
int count,
|
||||
float phase);
|
||||
static sk_sp<PathEffect> MakeCorner(float radius);
|
||||
|
||||
bool EqualsForTesting(const PathEffect& other) const;
|
||||
|
||||
// If this is a Dash PathEffect, how many intervals are in the dash pattern?
|
||||
// Returns 0 for all other kinds of PathEffect.
|
||||
virtual size_t dash_interval_count() const;
|
||||
|
||||
protected:
|
||||
friend class PaintFlags;
|
||||
friend class PaintOpReader;
|
||||
friend class PaintOpWriter;
|
||||
|
||||
enum class Type {
|
||||
// kNull is for serialization purposes only, to indicate a null path effect
|
||||
// in a containing object (e.g. PaintFlags).
|
||||
kNull,
|
||||
kDash,
|
||||
kCorner,
|
||||
kMaxValue = kCorner,
|
||||
};
|
||||
|
||||
virtual sk_sp<SkPathEffect> GetSkPathEffect() const = 0;
|
||||
|
||||
explicit PathEffect(Type type);
|
||||
// These functions don't handle type_. It's handled in PaintOpWriter/Reader.
|
||||
virtual size_t SerializedDataSize() const = 0;
|
||||
virtual void SerializeData(PaintOpWriter& writer) const = 0;
|
||||
static sk_sp<PathEffect> Deserialize(PaintOpReader& reader, Type type);
|
||||
|
||||
Type type_;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
#endif // CC_PAINT_COLOR_FILTER_H_
|
@ -507,9 +507,7 @@ class PaintOpHelper {
|
||||
return "SkMaskFilter";
|
||||
}
|
||||
|
||||
static std::string ToString(const SkPathEffect& effect) {
|
||||
return "SkPathEffect";
|
||||
}
|
||||
static std::string ToString(const PathEffect& effect) { return "PathEffect"; }
|
||||
|
||||
static std::string ToString(const DrawLooper& looper) { return "DrawLooper"; }
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "components/ui_devtools/views/view_element.h"
|
||||
#include "components/ui_devtools/views/widget_element.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
#include "ui/compositor/paint_recorder.h"
|
||||
#include "ui/events/event.h"
|
||||
#include "ui/gfx/canvas.h"
|
||||
@ -584,7 +583,7 @@ void OverlayAgentViews::OnPaintLayer(const ui::PaintContext& context) {
|
||||
flags.setStyle(cc::PaintFlags::kStroke_Style);
|
||||
|
||||
constexpr SkScalar intervals[] = {1.f, 4.f};
|
||||
flags.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0));
|
||||
flags.setPathEffect(cc::PathEffect::MakeDash(intervals, 2, 0));
|
||||
|
||||
if (!render_text_)
|
||||
render_text_ = gfx::RenderText::CreateRenderText();
|
||||
@ -644,7 +643,7 @@ void OverlayAgentViews::OnPaintLayer(const ui::PaintContext& context) {
|
||||
render_text_.get());
|
||||
|
||||
// Draw 4 guide lines along distance lines.
|
||||
flags.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0));
|
||||
flags.setPathEffect(cc::PathEffect::MakeDash(intervals, 2, 0));
|
||||
|
||||
// Bottom horizontal dotted line from left to right.
|
||||
canvas->DrawLine(
|
||||
@ -671,7 +670,7 @@ void OverlayAgentViews::OnPaintLayer(const ui::PaintContext& context) {
|
||||
render_text_.get());
|
||||
|
||||
// Draw 2 guide lines along distance lines.
|
||||
flags.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0));
|
||||
flags.setPathEffect(cc::PathEffect::MakeDash(intervals, 2, 0));
|
||||
|
||||
// Top horizontal dotted line from left to right.
|
||||
canvas->DrawLine(
|
||||
@ -688,7 +687,7 @@ void OverlayAgentViews::OnPaintLayer(const ui::PaintContext& context) {
|
||||
render_text_.get());
|
||||
|
||||
// Draw 1 guide line along distance lines.
|
||||
flags.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0));
|
||||
flags.setPathEffect(cc::PathEffect::MakeDash(intervals, 2, 0));
|
||||
|
||||
// Top horizontal dotted line from left to right.
|
||||
canvas->DrawLine(gfx::PointF(0.0f, pinned_rect_f.y()),
|
||||
@ -703,7 +702,7 @@ void OverlayAgentViews::OnPaintLayer(const ui::PaintContext& context) {
|
||||
DrawR1IntersectsR2(pinned_rect_f, hovered_rect_f, flags, canvas,
|
||||
render_text_.get());
|
||||
// Draw 4 guide line along distance lines.
|
||||
flags.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0));
|
||||
flags.setPathEffect(cc::PathEffect::MakeDash(intervals, 2, 0));
|
||||
|
||||
DrawRectGuideLinesOnCanvas(screen_bounds, hovered_rect_f, flags, canvas);
|
||||
return;
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "third_party/blink/renderer/platform/graphics/paint/paint_canvas.h"
|
||||
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"
|
||||
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
|
||||
static const char defaultFont[] = "10px sans-serif";
|
||||
static const char defaultFilter[] = "none";
|
||||
@ -224,7 +223,7 @@ ALWAYS_INLINE void CanvasRenderingContext2DState::UpdateLineDash() const {
|
||||
} else {
|
||||
Vector<float> line_dash(line_dash_.size());
|
||||
base::ranges::copy(line_dash_, line_dash.begin());
|
||||
stroke_flags_.setPathEffect(SkDashPathEffect::Make(
|
||||
stroke_flags_.setPathEffect(cc::PathEffect::MakeDash(
|
||||
line_dash.data(), line_dash.size(), line_dash_offset_));
|
||||
}
|
||||
line_dash_dirty_ = false;
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "third_party/blink/renderer/platform/graphics/graphics_context.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/allocator/partitions.h"
|
||||
#include "third_party/skia/include/core/SkColorSpace.h"
|
||||
#include "third_party/skia/include/effects/SkCornerPathEffect.h"
|
||||
#include "third_party/skia/modules/skcms/skcms.h"
|
||||
#include "ui/base/ui_base_features.h"
|
||||
|
||||
@ -413,8 +412,7 @@ void DrawPlatformFocusRing(const SkPath& path,
|
||||
float corner_radius) {
|
||||
cc::PaintFlags path_flags = PaintFlagsForFocusRing(color, width);
|
||||
if (corner_radius) {
|
||||
path_flags.setPathEffect(
|
||||
SkCornerPathEffect::Make(SkFloatToScalar(corner_radius)));
|
||||
path_flags.setPathEffect(cc::PathEffect::MakeCorner(corner_radius));
|
||||
}
|
||||
canvas->drawPath(path, path_flags);
|
||||
}
|
||||
|
@ -30,8 +30,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
void StrokeData::SetLineDash(const DashArray& dashes, float dash_offset) {
|
||||
@ -47,10 +45,10 @@ void StrokeData::SetLineDash(const DashArray& dashes, float dash_offset) {
|
||||
for (wtf_size_t i = 0; i < count; i++)
|
||||
intervals[i] = dashes[i % dash_length];
|
||||
|
||||
dash_ = SkDashPathEffect::Make(intervals.get(), count, dash_offset);
|
||||
dash_ = cc::PathEffect::MakeDash(intervals.get(), count, dash_offset);
|
||||
}
|
||||
|
||||
void StrokeData::SetDashEffect(sk_sp<SkPathEffect> dash_effect) {
|
||||
void StrokeData::SetDashEffect(sk_sp<cc::PathEffect> dash_effect) {
|
||||
dash_ = std::move(dash_effect);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "third_party/blink/renderer/platform/graphics/graphics_types.h"
|
||||
#include "third_party/blink/renderer/platform/platform_export.h"
|
||||
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
|
||||
#include "third_party/skia/include/core/SkPathEffect.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
|
||||
namespace blink {
|
||||
@ -62,7 +61,7 @@ class PLATFORM_EXPORT StrokeData final {
|
||||
void SetMiterLimit(float miter_limit) { miter_limit_ = miter_limit; }
|
||||
|
||||
void SetLineDash(const DashArray&, float);
|
||||
void SetDashEffect(sk_sp<SkPathEffect> dash_effect);
|
||||
void SetDashEffect(sk_sp<cc::PathEffect> dash_effect);
|
||||
|
||||
// Sets everything on the paint except the pattern, gradient and color.
|
||||
void SetupPaint(cc::PaintFlags*) const;
|
||||
@ -72,7 +71,7 @@ class PLATFORM_EXPORT StrokeData final {
|
||||
cc::PaintFlags::Cap line_cap_ = cc::PaintFlags::kDefault_Cap;
|
||||
cc::PaintFlags::Join line_join_ = cc::PaintFlags::kDefault_Join;
|
||||
float miter_limit_ = 4;
|
||||
sk_sp<SkPathEffect> dash_;
|
||||
sk_sp<cc::PathEffect> dash_;
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include <optional>
|
||||
|
||||
#include "third_party/blink/renderer/platform/graphics/stroke_data.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
@ -154,7 +153,7 @@ void StyledStrokeData::SetupPaintDashPathEffect(
|
||||
cc::PaintFlags* flags,
|
||||
const GeometryInfo& info) const {
|
||||
if (auto dash = DashEffectFromStrokeStyle(*this, info)) {
|
||||
flags->setPathEffect(SkDashPathEffect::Make(dash->intervals, 2, 0));
|
||||
flags->setPathEffect(cc::PathEffect::MakeDash(dash->intervals, 2, 0));
|
||||
flags->setStrokeCap(dash->cap);
|
||||
} else {
|
||||
flags->setPathEffect(nullptr);
|
||||
@ -166,7 +165,7 @@ StrokeData StyledStrokeData::ConvertToStrokeData(
|
||||
StrokeData stroke_data;
|
||||
stroke_data.SetThickness(thickness_);
|
||||
if (auto dash = DashEffectFromStrokeStyle(*this, info)) {
|
||||
stroke_data.SetDashEffect(SkDashPathEffect::Make(dash->intervals, 2, 0));
|
||||
stroke_data.SetDashEffect(cc::PathEffect::MakeDash(dash->intervals, 2, 0));
|
||||
stroke_data.SetLineCap(static_cast<LineCap>(dash->cap));
|
||||
}
|
||||
return stroke_data;
|
||||
|
@ -337,6 +337,7 @@ _CONFIG = [
|
||||
'cc::CategorizedWorkerPool',
|
||||
'cc::ColorFilter',
|
||||
'cc::DrawLooper',
|
||||
'cc::PathEffect',
|
||||
'cc::InspectablePaintRecorder',
|
||||
'cc::InspectableRecordPaintCanvas',
|
||||
'cc::PaintCanvas',
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkPath.h"
|
||||
#include "third_party/skia/include/core/SkRefCnt.h"
|
||||
#include "third_party/skia/include/effects/SkDashPathEffect.h"
|
||||
#include "third_party/skia/include/effects/SkGradientShader.h"
|
||||
#include "ui/gfx/font_list.h"
|
||||
#include "ui/gfx/geometry/insets_f.h"
|
||||
|
Reference in New Issue
Block a user