From efacd5360084bef0ad08873af99af266b2c48b36 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Fri, 12 Feb 2021 18:22:37 +0000 Subject: [PATCH] Add custom loopers for shadows SkDrawLooper is unused and untested in Skia, so moving the functionality into Chrome. Bug: skia:8672 Change-Id: I412ff1f2fe51c87cbe3b173efb0fc6e56df4dabb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2679292 Commit-Queue: Mike Reed Reviewed-by: Florin Malita Reviewed-by: vmpstr Reviewed-by: Scott Violet Reviewed-by: Aaron Krajeski Cr-Commit-Position: refs/heads/master@{#853590} --- ash/magnifier/magnifier_glass.cc | 1 - ash/system/tray/tray_detailed_view.cc | 1 - cc/paint/BUILD.gn | 2 + cc/paint/draw_looper.cc | 90 +++++++++++++ cc/paint/draw_looper.h | 125 ++++++++++++++++++ cc/paint/paint_flags.cc | 22 +-- cc/paint/paint_flags.h | 12 +- cc/paint/paint_op_buffer_unittest.cc | 40 ++---- cc/paint/paint_op_perftest.cc | 13 +- cc/paint/paint_op_reader.cc | 48 +++++-- cc/paint/paint_op_reader.h | 1 + cc/paint/paint_op_writer.cc | 25 +++- cc/paint/paint_op_writer.h | 2 + cc/test/paint_op_helper.h | 12 +- .../privacy_budget_browsertest.cc | 7 +- .../partial_magnification_controller.cc | 1 - .../web_contents/aura/gesture_nav_simple.cc | 1 - .../renderer/core/paint/text_painter_base.cc | 2 +- .../renderer/core/paint/text_painter_base.h | 2 +- .../canvas_rendering_context_2d_state.cc | 6 +- .../canvas_rendering_context_2d_state.h | 13 +- .../platform/graphics/draw_looper_builder.cc | 48 ++----- .../platform/graphics/draw_looper_builder.h | 8 +- .../platform/graphics/graphics_context.cc | 2 +- .../platform/graphics/graphics_context.h | 2 +- .../graphics/graphics_context_state.cc | 2 +- .../graphics/graphics_context_state.h | 5 +- ...dentifiability_paint_op_digest_unittest.cc | 10 +- .../platform/graphics/paint/draw_looper.h | 14 ++ ui/gfx/image/image_skia_operations.cc | 1 - ui/gfx/image/image_skia_operations.h | 1 - ui/gfx/render_text.cc | 4 +- ui/gfx/render_text.h | 6 +- ui/gfx/shadow_util.cc | 1 - ui/gfx/skia_paint_util.cc | 30 ++--- ui/gfx/skia_paint_util.h | 4 +- .../ink_drop_painted_layer_delegates.cc | 1 - ui/views/bubble/bubble_border.cc | 1 - ui/views/controls/button/toggle_button.cc | 1 - 39 files changed, 398 insertions(+), 169 deletions(-) create mode 100644 cc/paint/draw_looper.cc create mode 100644 cc/paint/draw_looper.h create mode 100644 third_party/blink/renderer/platform/graphics/paint/draw_looper.h diff --git a/ash/magnifier/magnifier_glass.cc b/ash/magnifier/magnifier_glass.cc index 1abaa72be89f74..b9f855ab48ca2c 100644 --- a/ash/magnifier/magnifier_glass.cc +++ b/ash/magnifier/magnifier_glass.cc @@ -6,7 +6,6 @@ #include "ash/shell.h" #include "base/check_op.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "ui/compositor/layer.h" #include "ui/compositor/paint_recorder.h" #include "ui/gfx/shadow_value.h" diff --git a/ash/system/tray/tray_detailed_view.cc b/ash/system/tray/tray_detailed_view.cc index d99bc442716023..89017a52c81e9d 100644 --- a/ash/system/tray/tray_detailed_view.cc +++ b/ash/system/tray/tray_detailed_view.cc @@ -17,7 +17,6 @@ #include "ash/system/tray/tri_view.h" #include "base/containers/adapters.h" #include "base/strings/string_number_conversions.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/compositor/clip_recorder.h" diff --git a/cc/paint/BUILD.gn b/cc/paint/BUILD.gn index 3c750b5c4f0e6d..9a8400cc6b5d0d 100644 --- a/cc/paint/BUILD.gn +++ b/cc/paint/BUILD.gn @@ -20,6 +20,8 @@ cc_component("paint") { "display_item_list.h", "draw_image.cc", "draw_image.h", + "draw_looper.cc", + "draw_looper.h", "element_id.cc", "element_id.h", "filter_operation.cc", diff --git a/cc/paint/draw_looper.cc b/cc/paint/draw_looper.cc new file mode 100644 index 00000000000000..00f06c5eb7e029 --- /dev/null +++ b/cc/paint/draw_looper.cc @@ -0,0 +1,90 @@ +// Copyright 2021 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 + +#include "cc/paint/draw_looper.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkColorFilter.h" +#include "third_party/skia/include/core/SkMaskFilter.h" +#include "third_party/skia/include/core/SkPaint.h" + +namespace cc { + +bool DrawLooper::DrawLooper::Layer::operator==(const Layer& other) const { + return offset == other.offset && blurSigma == other.blurSigma && + color == other.color && flags == other.flags; +} + +DrawLooper::DrawLooper(std::vector l) : layers_(std::move(l)) {} +DrawLooper::~DrawLooper() = default; + +void DrawLooper::Layer::Apply(SkCanvas* canvas, SkPaint* paint) const { + if (!(flags & kDontModifyPaintFlag)) { + if (flags & kOverrideAlphaFlag) + paint->setAlpha(0xFF); + + if (blurSigma > 0) + paint->setMaskFilter(SkMaskFilter::MakeBlur( + kNormal_SkBlurStyle, blurSigma, !(flags & kPostTransformFlag))); + + paint->setColorFilter(SkColorFilters::Blend(color, SkBlendMode::kSrcIn)); + } + + if (flags & kPostTransformFlag) + canvas->setMatrix( + canvas->getLocalToDevice().postTranslate(offset.fX, offset.fY)); + else + canvas->translate(offset.fX, offset.fY); +} + +bool DrawLooper::operator==(const DrawLooper& other) const { + return layers_ == other.layers_; +} + +// static +size_t DrawLooper::GetSerializedSize(const DrawLooper* looper) { + size_t size = sizeof(bool); + if (!looper) + return size; + + size_t count = looper->layers_.size(); + size += sizeof(count); + if (count == 0) + return size; + + auto layer = looper->layers_.begin(); + + size_t layer_size = sizeof(layer->offset.fX) + sizeof(layer->offset.fY) + + sizeof(layer->blurSigma) + sizeof(layer->color) + + sizeof(layer->flags); + + return size + count * layer_size; +} + +DrawLooperBuilder::DrawLooperBuilder() = default; +DrawLooperBuilder::~DrawLooperBuilder() = default; + +void DrawLooperBuilder::AddUnmodifiedContent(bool addOnTop) { + AddShadow({0, 0}, 0, 0, DrawLooper::kDontModifyPaintFlag, addOnTop); +} + +void DrawLooperBuilder::AddShadow(SkPoint offset, + float blurSigma, + SkColor color, + uint32_t flags, + bool addOnTop) { + const DrawLooper::Layer layer = {offset, blurSigma, color, + flags & DrawLooper::kAllFlagsMask}; + if (addOnTop) + layers_.insert(layers_.begin(), layer); + else + layers_.push_back(layer); +} + +sk_sp DrawLooperBuilder::Detach() { + return sk_sp(new DrawLooper(std::move(layers_))); +} + +} // namespace cc diff --git a/cc/paint/draw_looper.h b/cc/paint/draw_looper.h new file mode 100644 index 00000000000000..3baa52c64f6497 --- /dev/null +++ b/cc/paint/draw_looper.h @@ -0,0 +1,125 @@ +// Copyright 2021 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 CC_PAINT_DRAW_LOOPER_H_ +#define CC_PAINT_DRAW_LOOPER_H_ + +#include +#include + +#include "base/optional.h" +#include "base/stl_util.h" +#include "cc/paint/paint_export.h" +#include "third_party/skia/include/core/SkBlendMode.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkColor.h" +#include "third_party/skia/include/core/SkPoint.h" +#include "third_party/skia/include/core/SkRefCnt.h" + +class SkCanvas; +class SkPaint; + +namespace cc { + +/* + * Optional collection of modifiers to paint/canvas to facilitate drawing + * a given primitive multiple times. Often this is used for shadows. + */ +class CC_PAINT_EXPORT DrawLooper : public SkRefCnt { + public: + enum Flags { + // If set, apply layer's offset after the canvas' transformation matrix. + // If clear, pre-translate with layer's offset + kPostTransformFlag = 1 << 0, + + // If set, set the paint's alpha to the layer's alpha + // If clear, set the paint's alpha to opaque + kOverrideAlphaFlag = 1 << 1, + + // If set, ignore all modifiers but still translate using layer's offset + kDontModifyPaintFlag = 1 << 2, + }; + + ~DrawLooper() override; + + // The callback will be invoked for each "layer" in the looper, each time + // with a modified canvas and paint (depending on what the looper wanted + // to change). These can each be drawn directly, as the looper will callback + // logically bottom to top visually. + template + void Apply(SkCanvas* canvas, const SkPaint& paint, DrawProc proc) const { + // Our array is stored top to bottom + // e.g. layers_[0] is the top (will be drawn last) + // layers_[N-1] is on bottom, and will be drawn first + // + // Hence, since we must draw in painter's order (bottom to top), we + // walk the array in reverse. + // + // Each time through the loop, we make a copy of the draw's paint, modify + // it as indicated by the layer info, modify the canvas' translate, and + // then call back to issue the actual draw. + for (auto it = layers_.rbegin(); it != layers_.rend(); ++it) { + SkAutoCanvasRestore acr(canvas, true); + SkPaint p(paint); + it->Apply(canvas, &p); + proc(canvas, p); + } + } + + bool operator==(const DrawLooper& other) const; + bool operator!=(const DrawLooper& other) const { return !(*this == other); } + + static size_t GetSerializedSize(const DrawLooper* looper); + + private: + // Keep this in sync with the fields in Flags + // Used to mask out illegal bits when constructing Layer + enum { + kAllFlagsMask = + kPostTransformFlag | kOverrideAlphaFlag | kDontModifyPaintFlag, + }; + + struct Layer { + SkPoint offset; + float blurSigma; + SkColor color; + uint32_t flags; + + bool operator==(const Layer& other) const; + + void Apply(SkCanvas* canvas, SkPaint* paint) const; + }; + std::vector layers_; + + explicit DrawLooper(std::vector l); + + void UpdateForLayer(const Layer& layer, + SkCanvas* canvas, + SkPaint* paint) const; + + friend class DrawLooperBuilder; + friend class PaintOpReader; + friend class PaintOpWriter; +}; + +class CC_PAINT_EXPORT DrawLooperBuilder { + public: + DrawLooperBuilder(); + ~DrawLooperBuilder(); + + void AddUnmodifiedContent(bool addOnTop = false); + void AddShadow(SkPoint offset, + float blurSigma, + SkColor color, + uint32_t flags, + bool addOnTop = false); + sk_sp Detach(); + + private: + std::vector layers_; +}; + +} // namespace cc + +#endif // CC_PAINT_DRAW_LOOPER_H_ diff --git a/cc/paint/paint_flags.cc b/cc/paint/paint_flags.cc index 7e138218e96fd5..07071ba66b1548 100644 --- a/cc/paint/paint_flags.cc +++ b/cc/paint/paint_flags.cc @@ -148,6 +148,11 @@ bool PaintFlags::IsValid() const { return PaintOp::IsValidPaintFlagsSkBlendMode(getBlendMode()); } +template +bool AreEqual(const T* a, const T* b) { + return (a && b) ? *a == *b : a == b; +} + bool PaintFlags::operator==(const PaintFlags& other) const { // Can't just ToSkPaint and operator== here as SkPaint does pointer // comparisons on all the ref'd skia objects on the SkPaint, which @@ -181,20 +186,17 @@ bool PaintFlags::operator==(const PaintFlags& other) const { other.getColorFilter().get())) { return false; } - if (!PaintOp::AreSkFlattenablesEqual(getLooper().get(), - other.getLooper().get())) { + + if (!AreEqual(getLooper().get(), other.getLooper().get())) { return false; } - - if (!getImageFilter() != !other.getImageFilter()) + if (!AreEqual(getImageFilter().get(), other.getImageFilter().get())) { return false; - if (getImageFilter() && *getImageFilter() != *other.getImageFilter()) + } + if (!AreEqual(getShader(), other.getShader())) { return false; + } - if (!getShader() != !other.getShader()) - return false; - if (getShader() && *getShader() != *other.getShader()) - return false; return true; } @@ -212,7 +214,7 @@ size_t PaintFlags::GetSerializedSize() const { PaintOpWriter::Alignment() + PaintOpWriter::GetFlattenableSize(color_filter_.get()) + PaintOpWriter::Alignment() + - PaintOpWriter::GetFlattenableSize(draw_looper_.get()) + + DrawLooper::GetSerializedSize(draw_looper_.get()) + PaintFilter::GetFilterSize(image_filter_.get()) + PaintShader::GetSerializedSize(shader_.get()); } diff --git a/cc/paint/paint_flags.h b/cc/paint/paint_flags.h index 2e76e8c418403d..038cbc23b61b31 100644 --- a/cc/paint/paint_flags.h +++ b/cc/paint/paint_flags.h @@ -6,11 +6,11 @@ #define CC_PAINT_PAINT_FLAGS_H_ #include "base/compiler_specific.h" +#include "cc/paint/draw_looper.h" #include "cc/paint/paint_export.h" #include "cc/paint/paint_shader.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColorFilter.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "third_party/skia/include/core/SkImageFilter.h" #include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/core/SkPaint.h" @@ -139,10 +139,10 @@ class CC_PAINT_EXPORT PaintFlags { } void setImageFilter(sk_sp filter); - ALWAYS_INLINE const sk_sp& getLooper() const { + ALWAYS_INLINE const sk_sp& getLooper() const { return draw_looper_; } - ALWAYS_INLINE void setLooper(sk_sp looper) { + ALWAYS_INLINE void setLooper(sk_sp looper) { draw_looper_ = std::move(looper); } @@ -162,8 +162,8 @@ class CC_PAINT_EXPORT PaintFlags { template void DrawToSk(SkCanvas* canvas, Proc proc) const { SkPaint paint = ToSkPaint(); - if (const sk_sp& looper = getLooper()) - looper->apply(canvas, paint, proc); + if (const sk_sp& looper = getLooper()) + looper->Apply(canvas, paint, proc); else proc(canvas, paint); } @@ -184,7 +184,7 @@ class CC_PAINT_EXPORT PaintFlags { sk_sp shader_; sk_sp mask_filter_; sk_sp color_filter_; - sk_sp draw_looper_; + sk_sp draw_looper_; sk_sp image_filter_; // Match(ish) SkPaint defaults. SkPaintDefaults is not public, so this diff --git a/cc/paint/paint_op_buffer_unittest.cc b/cc/paint/paint_op_buffer_unittest.cc index 91296bb78df9ce..105ab4959b881a 100644 --- a/cc/paint/paint_op_buffer_unittest.cc +++ b/cc/paint/paint_op_buffer_unittest.cc @@ -12,6 +12,7 @@ #include "build/build_config.h" #include "cc/paint/decoded_draw_image.h" #include "cc/paint/display_item_list.h" +#include "cc/paint/draw_looper.h" #include "cc/paint/image_provider.h" #include "cc/paint/image_transfer_cache_entry.h" #include "cc/paint/paint_image_builder.h" @@ -32,7 +33,6 @@ #include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/effects/SkColorMatrixFilter.h" #include "third_party/skia/include/effects/SkDashPathEffect.h" -#include "third_party/skia/include/effects/SkLayerDrawLooper.h" #include "third_party/skia/src/core/SkRemoteGlyphCache.h" using testing::_; @@ -1166,15 +1166,11 @@ std::vector test_flags = { flags.setColorFilter(SkColorMatrixFilter::MakeLightingFilter( SK_ColorYELLOW, SK_ColorGREEN)); - SkLayerDrawLooper::Builder looper_builder; - looper_builder.addLayer(); - looper_builder.addLayer(2.3f, 4.5f); - SkLayerDrawLooper::LayerInfo layer_info; - layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; - layer_info.fColorMode = SkBlendMode::kDst; - layer_info.fOffset.set(-1.f, 5.2f); - looper_builder.addLayer(layer_info); - flags.setLooper(looper_builder.detach()); + DrawLooperBuilder looper_builder; + looper_builder.AddUnmodifiedContent(); + looper_builder.AddShadow({2.3f, 4.5f}, 0, SK_ColorBLACK, 0); + looper_builder.AddShadow({-1.f, 5.2f}, 0, SK_ColorBLACK, 0); + flags.setLooper(looper_builder.Detach()); sk_sp shader = PaintShader::MakeColor(SK_ColorTRANSPARENT); PaintOpSerializationTestUtils::FillArbitraryShaderValues(shader.get(), @@ -3158,21 +3154,17 @@ TEST(PaintOpBufferTest, ReplacesImagesFromProvider) { TEST(PaintOpBufferTest, DrawImageRectOpWithLooperNoImageProvider) { PaintOpBuffer buffer; PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100)); - SkLayerDrawLooper::Builder sk_draw_looper_builder; - sk_draw_looper_builder.addLayer(20.0, 20.0); - SkLayerDrawLooper::LayerInfo info_unmodified; - sk_draw_looper_builder.addLayerOnTop(info_unmodified); + DrawLooperBuilder draw_looper_builder; + draw_looper_builder.AddUnmodifiedContent(); + draw_looper_builder.AddUnmodifiedContent(); PaintFlags paint_flags; - paint_flags.setLooper(sk_draw_looper_builder.detach()); + paint_flags.setLooper(draw_looper_builder.Detach()); buffer.push(image, SkRect::MakeWH(100, 100), SkRect::MakeWH(100, 100), SkSamplingOptions(), &paint_flags, SkCanvas::kFast_SrcRectConstraint); testing::StrictMock canvas; - EXPECT_CALL(canvas, willSave); - EXPECT_CALL(canvas, didTranslate); - EXPECT_CALL(canvas, willRestore); EXPECT_CALL(canvas, onDrawImageRect2).Times(2); buffer.Playback(&canvas, PlaybackParams(nullptr)); @@ -3181,21 +3173,17 @@ TEST(PaintOpBufferTest, DrawImageRectOpWithLooperNoImageProvider) { TEST(PaintOpBufferTest, DrawImageRectOpWithLooperWithImageProvider) { PaintOpBuffer buffer; PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100)); - SkLayerDrawLooper::Builder sk_draw_looper_builder; - sk_draw_looper_builder.addLayer(20.0, 20.0); - SkLayerDrawLooper::LayerInfo info_unmodified; - sk_draw_looper_builder.addLayerOnTop(info_unmodified); + DrawLooperBuilder draw_looper_builder; + draw_looper_builder.AddUnmodifiedContent(); + draw_looper_builder.AddUnmodifiedContent(); PaintFlags paint_flags; - paint_flags.setLooper(sk_draw_looper_builder.detach()); + paint_flags.setLooper(draw_looper_builder.Detach()); buffer.push(image, SkRect::MakeWH(100, 100), SkRect::MakeWH(100, 100), SkSamplingOptions(), &paint_flags, SkCanvas::kFast_SrcRectConstraint); testing::StrictMock canvas; - EXPECT_CALL(canvas, willSave); - EXPECT_CALL(canvas, didTranslate); - EXPECT_CALL(canvas, willRestore); EXPECT_CALL(canvas, onDrawImageRect2).Times(2); std::vector src_rect_offset = {SkSize::MakeEmpty()}; diff --git a/cc/paint/paint_op_perftest.cc b/cc/paint/paint_op_perftest.cc index 8ef166e44f1d25..42c2dcf339a692 100644 --- a/cc/paint/paint_op_perftest.cc +++ b/cc/paint/paint_op_perftest.cc @@ -7,6 +7,7 @@ #include "base/test/launcher/unit_test_launcher.h" #include "base/test/test_suite.h" #include "base/timer/lap_timer.h" +#include "cc/paint/draw_looper.h" #include "cc/paint/paint_op_buffer.h" #include "cc/paint/paint_op_buffer_serializer.h" #include "cc/test/test_options_provider.h" @@ -14,7 +15,6 @@ #include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/effects/SkColorMatrixFilter.h" #include "third_party/skia/include/effects/SkDashPathEffect.h" -#include "third_party/skia/include/effects/SkLayerDrawLooper.h" namespace cc { namespace { @@ -136,12 +136,11 @@ TEST_F(PaintOpPerfTest, ManyFlagsOps) { flags.setColorFilter( SkColorMatrixFilter::MakeLightingFilter(SK_ColorYELLOW, SK_ColorGREEN)); - SkLayerDrawLooper::Builder looper_builder; - looper_builder.addLayer(); - looper_builder.addLayer(2.3f, 4.5f); - SkLayerDrawLooper::LayerInfo layer_info; - looper_builder.addLayer(layer_info); - flags.setLooper(looper_builder.detach()); + DrawLooperBuilder looper_builder; + looper_builder.AddUnmodifiedContent(); + looper_builder.AddShadow({2.3f, 4.5f}, 0, 0, 0); + looper_builder.AddUnmodifiedContent(); + flags.setLooper(looper_builder.Detach()); sk_sp shader = PaintShader::MakeColor(SK_ColorTRANSPARENT); flags.setShader(std::move(shader)); diff --git a/cc/paint/paint_op_reader.cc b/cc/paint/paint_op_reader.cc index eb795ba528e9d8..4c5df33f532142 100644 --- a/cc/paint/paint_op_reader.cc +++ b/cc/paint/paint_op_reader.cc @@ -262,17 +262,7 @@ void PaintOpReader::Read(PaintFlags* flags) { ReadFlattenable(&flags->mask_filter_); ReadFlattenable(&flags->color_filter_); - if (enable_security_constraints_) { - size_t bytes = 0; - ReadSize(&bytes); - if (bytes != 0u) { - SetInvalid(); - return; - } - } else { - ReadFlattenable(&flags->draw_looper_); - } - + Read(&flags->draw_looper_); Read(&flags->image_filter_); Read(&flags->shader_); } @@ -487,6 +477,42 @@ void PaintOpReader::Read(sk_sp* blob) { remaining_bytes_ -= data_bytes; } +void PaintOpReader::Read(sk_sp* looper) { + bool has_looper = false; + ReadSimple(&has_looper); + if (!has_looper) { + *looper = nullptr; + return; + } + + DrawLooperBuilder builder; + size_t count; + ReadSimple(&count); + if (!valid_) { + *looper = nullptr; + return; + } + + for (size_t i = 0; i < count; ++i) { + SkPoint offset; + float blurSigma; + SkColor color; + uint32_t flags; + + ReadSimple(&offset.fX); + ReadSimple(&offset.fY); + ReadSimple(&blurSigma); + ReadSimple(&color); + ReadSimple(&flags); + if (!valid_) { + *looper = nullptr; + return; + } + builder.AddShadow(offset, blurSigma, color, flags); + } + *looper = builder.Detach(); +} + void PaintOpReader::Read(sk_sp* shader) { bool has_shader = false; ReadSimple(&has_shader); diff --git a/cc/paint/paint_op_reader.h b/cc/paint/paint_op_reader.h index fc8cda79bf013c..c2d7c682f1f06c 100644 --- a/cc/paint/paint_op_reader.h +++ b/cc/paint/paint_op_reader.h @@ -68,6 +68,7 @@ class CC_PAINT_EXPORT PaintOpReader { void Read(PaintImage* image); void Read(sk_sp* data); void Read(sk_sp* blob); + void Read(sk_sp* looper); void Read(sk_sp* filter); void Read(sk_sp* shader); void Read(SkMatrix* matrix); diff --git a/cc/paint/paint_op_writer.cc b/cc/paint/paint_op_writer.cc index 32aae4f2ce97bd..158703bcbed215 100644 --- a/cc/paint/paint_op_writer.cc +++ b/cc/paint/paint_op_writer.cc @@ -8,6 +8,7 @@ #include "base/bits.h" #include "cc/paint/draw_image.h" +#include "cc/paint/draw_looper.h" #include "cc/paint/image_provider.h" #include "cc/paint/image_transfer_cache_entry.h" #include "cc/paint/paint_cache.h" @@ -217,11 +218,7 @@ void PaintOpWriter::Write(const PaintFlags& flags) { WriteFlattenable(flags.mask_filter_.get()); WriteFlattenable(flags.color_filter_.get()); - if (enable_security_constraints_) - WriteSize(static_cast(0u)); - else - WriteFlattenable(flags.draw_looper_.get()); - + Write(flags.draw_looper_.get()); Write(flags.image_filter_.get()); Write(flags.shader_.get(), flags.getFilterQuality()); } @@ -464,6 +461,24 @@ void PaintOpWriter::Write(const SkM44& matrix) { WriteSimple(matrix); } +void PaintOpWriter::Write(const DrawLooper* looper) { + if (!looper) { + WriteSimple(false); + return; + } + + WriteSimple(true); + WriteSimple(looper->layers_.size()); + + for (auto const& layer : looper->layers_) { + WriteSimple(layer.offset.fX); + WriteSimple(layer.offset.fY); + WriteSimple(layer.blurSigma); + WriteSimple(layer.color); + WriteSimple(layer.flags); + } +} + void PaintOpWriter::Write(const PaintShader* shader, SkFilterQuality quality) { sk_sp transformed_shader; uint32_t paint_image_transfer_cache_id = kInvalidImageTransferCacheEntryId; diff --git a/cc/paint/paint_op_writer.h b/cc/paint/paint_op_writer.h index 682ba1c8dff06b..2c812e92f19d9f 100644 --- a/cc/paint/paint_op_writer.h +++ b/cc/paint/paint_op_writer.h @@ -26,6 +26,7 @@ struct Mailbox; namespace cc { class DrawImage; +class DrawLooper; class PaintShader; class CC_PAINT_EXPORT PaintOpWriter { @@ -67,6 +68,7 @@ class CC_PAINT_EXPORT PaintOpWriter { void Write(const sk_sp& data); void Write(const SkColorSpace* data); void Write(const SkSamplingOptions&); + void Write(const DrawLooper* looper); void Write(const PaintShader* shader, SkFilterQuality quality); void Write(const PaintFilter* filter); void Write(const sk_sp& blob); diff --git a/cc/test/paint_op_helper.h b/cc/test/paint_op_helper.h index 4408392d97ec22..691c2b3ab28c02 100644 --- a/cc/test/paint_op_helper.h +++ b/cc/test/paint_op_helper.h @@ -9,6 +9,7 @@ #include #include "base/strings/stringprintf.h" +#include "cc/paint/draw_looper.h" #include "cc/paint/paint_filter.h" #include "cc/paint/paint_op_buffer.h" @@ -414,10 +415,10 @@ class PaintOpHelper { return "SkPathEffect"; } - static std::string SkiaTypeToString(const sk_sp& looper) { + static std::string SkiaTypeToString(const sk_sp& looper) { if (!looper) return "(nil)"; - return "SkDrawLooper"; + return "DrawLooper"; } template @@ -490,6 +491,10 @@ class PaintOpHelper { return ""; } + static std::string LooperToString(const sk_sp& looper) { + return looper ? "" : "(nil)"; + } + static std::string SkottieToString(scoped_refptr skottie) { std::ostringstream str; str << " TextPainterBase::CreateDrawLooper( +sk_sp TextPainterBase::CreateDrawLooper( const ShadowList* shadow_list, DrawLooperBuilder::ShadowAlphaMode alpha_mode, const Color& current_color, diff --git a/third_party/blink/renderer/core/paint/text_painter_base.h b/third_party/blink/renderer/core/paint/text_painter_base.h index cdcb917369ea99..0c2cd1561e36f4 100644 --- a/third_party/blink/renderer/core/paint/text_painter_base.h +++ b/third_party/blink/renderer/core/paint/text_painter_base.h @@ -55,7 +55,7 @@ class CORE_EXPORT TextPainterBase { bool horizontal, GraphicsContextStateSaver&, ShadowMode = kBothShadowsAndTextProper); - static sk_sp CreateDrawLooper( + static sk_sp CreateDrawLooper( const ShadowList* shadow_list, DrawLooperBuilder::ShadowAlphaMode, const Color& current_color, diff --git a/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.cc b/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.cc index d72a9126b19716..660a20964cac07 100644 --- a/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.cc +++ b/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.cc @@ -461,14 +461,14 @@ void CanvasRenderingContext2DState::ClearResolvedFilter() const { resolved_filter_.reset(); } -SkDrawLooper* CanvasRenderingContext2DState::EmptyDrawLooper() const { +DrawLooper* CanvasRenderingContext2DState::EmptyDrawLooper() const { if (!empty_draw_looper_) empty_draw_looper_ = DrawLooperBuilder().DetachDrawLooper(); return empty_draw_looper_.get(); } -SkDrawLooper* CanvasRenderingContext2DState::ShadowOnlyDrawLooper() const { +DrawLooper* CanvasRenderingContext2DState::ShadowOnlyDrawLooper() const { if (!shadow_only_draw_looper_) { DrawLooperBuilder draw_looper_builder; draw_looper_builder.AddShadow(shadow_offset_, clampTo(shadow_blur_), @@ -480,7 +480,7 @@ SkDrawLooper* CanvasRenderingContext2DState::ShadowOnlyDrawLooper() const { return shadow_only_draw_looper_.get(); } -SkDrawLooper* CanvasRenderingContext2DState::ShadowAndForegroundDrawLooper() +DrawLooper* CanvasRenderingContext2DState::ShadowAndForegroundDrawLooper() const { if (!shadow_and_foreground_draw_looper_) { DrawLooperBuilder draw_looper_builder; diff --git a/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.h b/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.h index 237a1a8af61e18..87914da5ce59b9 100644 --- a/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.h +++ b/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.h @@ -9,6 +9,7 @@ #include "third_party/blink/renderer/modules/canvas/canvas2d/clip_list.h" #include "third_party/blink/renderer/platform/fonts/font.h" #include "third_party/blink/renderer/platform/fonts/font_selector_client.h" +#include "third_party/blink/renderer/platform/graphics/paint/draw_looper.h" #include "third_party/blink/renderer/platform/graphics/paint/paint_filter.h" #include "third_party/blink/renderer/platform/graphics/paint/paint_flags.h" #include "third_party/blink/renderer/platform/transforms/transformation_matrix.h" @@ -229,9 +230,9 @@ class CanvasRenderingContext2DState final void UpdateFilterQuality() const; void UpdateFilterQualityWithSkFilterQuality(const SkFilterQuality&) const; void ShadowParameterChanged(); - SkDrawLooper* EmptyDrawLooper() const; - SkDrawLooper* ShadowOnlyDrawLooper() const; - SkDrawLooper* ShadowAndForegroundDrawLooper() const; + DrawLooper* EmptyDrawLooper() const; + DrawLooper* ShadowOnlyDrawLooper() const; + DrawLooper* ShadowAndForegroundDrawLooper() const; sk_sp ShadowOnlyImageFilter() const; sk_sp ShadowAndForegroundImageFilter() const; @@ -249,9 +250,9 @@ class CanvasRenderingContext2DState final FloatSize shadow_offset_; double shadow_blur_; SkColor shadow_color_; - mutable sk_sp empty_draw_looper_; - mutable sk_sp shadow_only_draw_looper_; - mutable sk_sp shadow_and_foreground_draw_looper_; + mutable sk_sp empty_draw_looper_; + mutable sk_sp shadow_only_draw_looper_; + mutable sk_sp shadow_and_foreground_draw_looper_; mutable sk_sp shadow_only_image_filter_; mutable sk_sp shadow_and_foreground_image_filter_; diff --git a/third_party/blink/renderer/platform/graphics/draw_looper_builder.cc b/third_party/blink/renderer/platform/graphics/draw_looper_builder.cc index 25f85e70dc2c22..87fa2507d7a58c 100644 --- a/third_party/blink/renderer/platform/graphics/draw_looper_builder.cc +++ b/third_party/blink/renderer/platform/graphics/draw_looper_builder.cc @@ -37,7 +37,6 @@ #include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColorFilter.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/core/SkPaint.h" @@ -47,13 +46,13 @@ DrawLooperBuilder::DrawLooperBuilder() = default; DrawLooperBuilder::~DrawLooperBuilder() = default; -sk_sp DrawLooperBuilder::DetachDrawLooper() { - return sk_draw_looper_builder_.detach(); +sk_sp DrawLooperBuilder::DetachDrawLooper() { + return draw_looper_builder_.Detach(); } void DrawLooperBuilder::AddUnmodifiedContent() { - SkLayerDrawLooper::LayerInfo info; - sk_draw_looper_builder_.addLayerOnTop(info); + const bool add_on_top = true; + draw_looper_builder_.AddUnmodifiedContent(add_on_top); } void DrawLooperBuilder::AddShadow(const FloatSize& offset, @@ -67,37 +66,16 @@ void DrawLooperBuilder::AddShadow(const FloatSize& offset, if (!color.Alpha()) return; - SkColor sk_color = color.Rgb(); + const bool add_on_top = true; + uint32_t flags = 0; + if (shadow_alpha_mode == kShadowIgnoresAlpha) + flags |= DrawLooper::kOverrideAlphaFlag; + if (shadow_transform_mode == kShadowIgnoresTransforms) + flags |= DrawLooper::kPostTransformFlag; - SkLayerDrawLooper::LayerInfo info; - - switch (shadow_alpha_mode) { - case kShadowRespectsAlpha: - info.fColorMode = SkBlendMode::kDst; - break; - case kShadowIgnoresAlpha: - info.fColorMode = SkBlendMode::kSrc; - break; - default: - NOTREACHED(); - } - - if (blur) - info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; // our blur - info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; - info.fOffset.set(offset.Width(), offset.Height()); - info.fPostTranslate = (shadow_transform_mode == kShadowIgnoresTransforms); - - SkPaint* paint = sk_draw_looper_builder_.addLayerOnTop(info); - - if (blur) { - const auto sigma = BlurRadiusToStdDev(blur); - const bool respectCTM = shadow_transform_mode != kShadowIgnoresTransforms; - paint->setMaskFilter( - SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma, respectCTM)); - } - - paint->setColorFilter(SkColorFilters::Blend(sk_color, SkBlendMode::kSrcIn)); + draw_looper_builder_.AddShadow({offset.Width(), offset.Height()}, + BlurRadiusToStdDev(blur), color.Rgb(), flags, + add_on_top); } } // namespace blink diff --git a/third_party/blink/renderer/platform/graphics/draw_looper_builder.h b/third_party/blink/renderer/platform/graphics/draw_looper_builder.h index 79b621517ed207..44a51e97f8e106 100644 --- a/third_party/blink/renderer/platform/graphics/draw_looper_builder.h +++ b/third_party/blink/renderer/platform/graphics/draw_looper_builder.h @@ -34,12 +34,10 @@ #include #include "base/macros.h" +#include "third_party/blink/renderer/platform/graphics/paint/draw_looper.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/SkRefCnt.h" -#include "third_party/skia/include/effects/SkLayerDrawLooper.h" - -class SkDrawLooper; namespace blink { @@ -61,7 +59,7 @@ class PLATFORM_EXPORT DrawLooperBuilder final { // Creates the SkDrawLooper and passes ownership to the caller. The builder // should not be used any more after calling this method. - sk_sp DetachDrawLooper(); + sk_sp DetachDrawLooper(); void AddUnmodifiedContent(); void AddShadow(const FloatSize& offset, @@ -71,7 +69,7 @@ class PLATFORM_EXPORT DrawLooperBuilder final { ShadowAlphaMode = kShadowRespectsAlpha); private: - SkLayerDrawLooper::Builder sk_draw_looper_builder_; + cc::DrawLooperBuilder draw_looper_builder_; // Implementing the copy constructor properly would require writing code to // copy the underlying SkLayerDrawLooper::Builder. diff --git a/third_party/blink/renderer/platform/graphics/graphics_context.cc b/third_party/blink/renderer/platform/graphics/graphics_context.cc index 11c70b635b971d..1dda58d841ea48 100644 --- a/third_party/blink/renderer/platform/graphics/graphics_context.cc +++ b/third_party/blink/renderer/platform/graphics/graphics_context.cc @@ -224,7 +224,7 @@ DOMNodeId GraphicsContext::GetDOMNodeId() const { return dom_node_id_; } -void GraphicsContext::SetDrawLooper(sk_sp draw_looper) { +void GraphicsContext::SetDrawLooper(sk_sp draw_looper) { MutableState()->SetDrawLooper(std::move(draw_looper)); } diff --git a/third_party/blink/renderer/platform/graphics/graphics_context.h b/third_party/blink/renderer/platform/graphics/graphics_context.h index 94ab958545a645..16b592a8dbbf0a 100644 --- a/third_party/blink/renderer/platform/graphics/graphics_context.h +++ b/third_party/blink/renderer/platform/graphics/graphics_context.h @@ -354,7 +354,7 @@ class PLATFORM_EXPORT GraphicsContext { // not necessarily non-empty), even when the context is disabled. sk_sp EndRecording(); - void SetDrawLooper(sk_sp); + void SetDrawLooper(sk_sp); void DrawFocusRing(const Vector&, float width, diff --git a/third_party/blink/renderer/platform/graphics/graphics_context_state.cc b/third_party/blink/renderer/platform/graphics/graphics_context_state.cc index 541d8cbadd5220..ad14698e8ae679 100644 --- a/third_party/blink/renderer/platform/graphics/graphics_context_state.cc +++ b/third_party/blink/renderer/platform/graphics/graphics_context_state.cc @@ -91,7 +91,7 @@ void GraphicsContextState::SetFillColor(const Color& color) { } // Shadow. (This will need tweaking if we use draw loopers for other things.) -void GraphicsContextState::SetDrawLooper(sk_sp draw_looper) { +void GraphicsContextState::SetDrawLooper(sk_sp draw_looper) { // Grab a new ref for stroke. stroke_flags_.setLooper(draw_looper); // Pass the existing ref to fill (to minimize refcount churn). diff --git a/third_party/blink/renderer/platform/graphics/graphics_context_state.h b/third_party/blink/renderer/platform/graphics/graphics_context_state.h index 6bf33c392e5d01..20f4d5bdbdff93 100644 --- a/third_party/blink/renderer/platform/graphics/graphics_context_state.h +++ b/third_party/blink/renderer/platform/graphics/graphics_context_state.h @@ -34,6 +34,7 @@ #include "base/memory/ptr_util.h" #include "third_party/blink/renderer/platform/graphics/draw_looper_builder.h" #include "third_party/blink/renderer/platform/graphics/graphics_types.h" +#include "third_party/blink/renderer/platform/graphics/paint/draw_looper.h" #include "third_party/blink/renderer/platform/graphics/paint/paint_flags.h" #include "third_party/blink/renderer/platform/graphics/stroke_data.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" @@ -84,11 +85,11 @@ class PLATFORM_EXPORT GraphicsContextState final { void SetFillColor(const Color&); // Shadow. (This will need tweaking if we use draw loopers for other things.) - SkDrawLooper* DrawLooper() const { + DrawLooper* GetDrawLooper() const { DCHECK_EQ(fill_flags_.getLooper(), stroke_flags_.getLooper()); return fill_flags_.getLooper().get(); } - void SetDrawLooper(sk_sp); + void SetDrawLooper(sk_sp); // Text. (See TextModeFill & friends.) TextDrawingModeFlags TextDrawingMode() const { return text_drawing_mode_; } diff --git a/third_party/blink/renderer/platform/graphics/identifiability_paint_op_digest_unittest.cc b/third_party/blink/renderer/platform/graphics/identifiability_paint_op_digest_unittest.cc index 5f2bc3b0719f5e..36d15a0d074cf8 100644 --- a/third_party/blink/renderer/platform/graphics/identifiability_paint_op_digest_unittest.cc +++ b/third_party/blink/renderer/platform/graphics/identifiability_paint_op_digest_unittest.cc @@ -185,7 +185,7 @@ TEST(IdentifiabilityPaintOpDigestTest, SkPathDigestStability) { /*num_ops_to_visit=*/1); EXPECT_EQ(identifiability_paintop_digest1.GetToken().ToUkmMetricValue(), identifiability_paintop_digest2.GetToken().ToUkmMetricValue()); - EXPECT_EQ(INT64_C(-1093634256342000670), + EXPECT_EQ(INT64_C(7824610171042359346), identifiability_paintop_digest1.GetToken().ToUkmMetricValue()); EXPECT_FALSE(identifiability_paintop_digest1.encountered_skipped_ops()); @@ -224,7 +224,7 @@ TEST(IdentifiabilityPaintOpDigestTest, PaintShaderStability) { /*num_ops_to_visit=*/1); EXPECT_EQ(identifiability_paintop_digest1.GetToken().ToUkmMetricValue(), identifiability_paintop_digest2.GetToken().ToUkmMetricValue()); - EXPECT_EQ(INT64_C(6157094048912696853), + EXPECT_EQ(INT64_C(8832689822402521636), identifiability_paintop_digest1.GetToken().ToUkmMetricValue()); } @@ -249,7 +249,7 @@ TEST(IdentifiabilityPaintOpDigestTest, BufferLeftoversDontAffectFutureDigests) { /*num_ops_to_visit=*/1); identifiability_paintop_digest2.MaybeUpdateDigest(paint_record2, /*num_ops_to_visit=*/1); - EXPECT_EQ(INT64_C(-1855817800596177722), + EXPECT_EQ(INT64_C(6142427981168684668), identifiability_paintop_digest1.GetToken().ToUkmMetricValue()); EXPECT_EQ(kScaleDigest, identifiability_paintop_digest2.GetToken().ToUkmMetricValue()); @@ -280,7 +280,7 @@ TEST(IdentifiabilityPaintOpDigestTest, paint_record->push(kScaleX, kScaleY); identifiability_paintop_digest.MaybeUpdateDigest(paint_record, /*num_ops_to_visit=*/2); - EXPECT_EQ(INT64_C(-2635322358402873102), + EXPECT_EQ(INT64_C(-4103331043531983164), identifiability_paintop_digest.GetToken().ToUkmMetricValue()); EXPECT_FALSE(identifiability_paintop_digest.encountered_skipped_ops()); @@ -428,7 +428,7 @@ TEST(IdentifiabilityPaintOpDigestTest, DigestImageOp) { cc::CreateDiscardablePaintImage(gfx::Size(10, 10)), 10.0f, 10.0f); identifiability_paintop_digest.MaybeUpdateDigest(paint_record, /*num_ops_to_visit=*/1); - EXPECT_EQ(INT64_C(-3447989221783743109), + EXPECT_EQ(INT64_C(-8521219366610783336), identifiability_paintop_digest.GetToken().ToUkmMetricValue()); EXPECT_FALSE(identifiability_paintop_digest.encountered_skipped_ops()); diff --git a/third_party/blink/renderer/platform/graphics/paint/draw_looper.h b/third_party/blink/renderer/platform/graphics/paint/draw_looper.h new file mode 100644 index 00000000000000..0cd63fc23c54f2 --- /dev/null +++ b/third_party/blink/renderer/platform/graphics/paint/draw_looper.h @@ -0,0 +1,14 @@ +// Copyright 2021 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_PLATFORM_GRAPHICS_PAINT_DRAW_LOOPER_H_ +#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_DRAW_LOOPER_H_ + +#include "cc/paint/draw_looper.h" + +namespace blink { +using cc::DrawLooper; +} + +#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_DRAW_LOOPER_H_ diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc index 9b02af5cfe5efd..bdd9d5af1cc228 100644 --- a/ui/gfx/image/image_skia_operations.cc +++ b/ui/gfx/image/image_skia_operations.cc @@ -14,7 +14,6 @@ #include "base/numerics/safe_conversions.h" #include "skia/ext/image_operations.h" #include "third_party/skia/include/core/SkClipOp.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "ui/gfx/canvas.h" #include "ui/gfx/color_palette.h" #include "ui/gfx/geometry/insets.h" diff --git a/ui/gfx/image/image_skia_operations.h b/ui/gfx/image/image_skia_operations.h index a25afd429d9161..36c4c196f8c4ea 100644 --- a/ui/gfx/image/image_skia_operations.h +++ b/ui/gfx/image/image_skia_operations.h @@ -6,7 +6,6 @@ #define UI_GFX_IMAGE_IMAGE_SKIA_OPERATIONS_H_ #include "skia/ext/image_operations.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkRRect.h" #include "ui/gfx/color_utils.h" diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index 8b6064d15996bd..f1fb391b0ec6cd 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -21,12 +21,12 @@ #include "base/strings/utf_string_conversions.h" #include "base/trace_event/trace_event.h" #include "build/build_config.h" +#include "cc/paint/draw_looper.h" #include "cc/paint/paint_canvas.h" #include "cc/paint/paint_shader.h" #include "third_party/icu/source/common/unicode/rbbi.h" #include "third_party/icu/source/common/unicode/uchar.h" #include "third_party/icu/source/common/unicode/utf16.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "third_party/skia/include/core/SkFontStyle.h" #include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/effects/SkGradientShader.h" @@ -278,7 +278,7 @@ SkiaTextRenderer::SkiaTextRenderer(Canvas* canvas) SkiaTextRenderer::~SkiaTextRenderer() { } -void SkiaTextRenderer::SetDrawLooper(sk_sp draw_looper) { +void SkiaTextRenderer::SetDrawLooper(sk_sp draw_looper) { flags_.setLooper(std::move(draw_looper)); } diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h index bb7ce1ca82b4ca..358cee66f5a394 100644 --- a/ui/gfx/render_text.h +++ b/ui/gfx/render_text.h @@ -38,7 +38,9 @@ #include "ui/gfx/shadow_value.h" #include "ui/gfx/text_constants.h" -class SkDrawLooper; +namespace cc { +class DrawLooper; +} struct SkPoint; class SkTypeface; @@ -61,7 +63,7 @@ class GFX_EXPORT SkiaTextRenderer { explicit SkiaTextRenderer(Canvas* canvas); virtual ~SkiaTextRenderer(); - void SetDrawLooper(sk_sp draw_looper); + void SetDrawLooper(sk_sp draw_looper); void SetFontRenderParams(const FontRenderParams& params, bool subpixel_rendering_suppressed); void SetTypeface(sk_sp typeface); diff --git a/ui/gfx/shadow_util.cc b/ui/gfx/shadow_util.cc index 985d854585251b..3b211eb8d7bf00 100644 --- a/ui/gfx/shadow_util.cc +++ b/ui/gfx/shadow_util.cc @@ -9,7 +9,6 @@ #include "base/lazy_instance.h" #include "base/memory/ptr_util.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "third_party/skia/include/core/SkRRect.h" #include "ui/gfx/canvas.h" #include "ui/gfx/geometry/insets.h" diff --git a/ui/gfx/skia_paint_util.cc b/ui/gfx/skia_paint_util.cc index 32adf0be1985b1..d38a05ffe09d06 100644 --- a/ui/gfx/skia_paint_util.cc +++ b/ui/gfx/skia_paint_util.cc @@ -5,10 +5,7 @@ #include "ui/gfx/skia_paint_util.h" #include "cc/paint/paint_image_builder.h" -#include "third_party/skia/include/core/SkColorFilter.h" -#include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/effects/SkGradientShader.h" -#include "third_party/skia/include/effects/SkLayerDrawLooper.h" #include "ui/gfx/image/image_skia_rep.h" #include "ui/gfx/skia_util.h" #include "ui/gfx/switches.h" @@ -75,36 +72,25 @@ static SkScalar RadiusToSigma(double radius) { return radius > 0 ? SkDoubleToScalar(0.288675f * radius + 0.5f) : 0; } -sk_sp CreateShadowDrawLooper( +sk_sp CreateShadowDrawLooper( const std::vector& shadows) { if (shadows.empty()) return nullptr; - SkLayerDrawLooper::Builder looper_builder; + cc::DrawLooperBuilder looper_builder; - looper_builder.addLayer(); // top layer of the original. - - SkLayerDrawLooper::LayerInfo layer_info; - layer_info.fPaintBits |= SkLayerDrawLooper::kMaskFilter_Bit; - layer_info.fPaintBits |= SkLayerDrawLooper::kColorFilter_Bit; - layer_info.fColorMode = SkBlendMode::kSrc; + looper_builder.AddUnmodifiedContent(); // top layer of the original. for (size_t i = 0; i < shadows.size(); ++i) { const ShadowValue& shadow = shadows[i]; - layer_info.fOffset.set(SkIntToScalar(shadow.x()), - SkIntToScalar(shadow.y())); - - SkPaint* paint = looper_builder.addLayer(layer_info); - // Skia's blur radius defines the range to extend the blur from - // original mask, which is half of blur amount as defined in ShadowValue. - paint->setMaskFilter(SkMaskFilter::MakeBlur( - kNormal_SkBlurStyle, RadiusToSigma(shadow.blur() / 2))); - paint->setColorFilter( - SkColorFilters::Blend(shadow.color(), SkBlendMode::kSrcIn)); + looper_builder.AddShadow( + {SkIntToScalar(shadow.x()), SkIntToScalar(shadow.y())}, + RadiusToSigma(shadow.blur() / 2), shadow.color(), + cc::DrawLooper::kOverrideAlphaFlag); } - return looper_builder.detach(); + return looper_builder.Detach(); } } // namespace gfx diff --git a/ui/gfx/skia_paint_util.h b/ui/gfx/skia_paint_util.h index d334afe7aba0e2..562d3d8ae9b742 100644 --- a/ui/gfx/skia_paint_util.h +++ b/ui/gfx/skia_paint_util.h @@ -8,11 +8,11 @@ #include #include +#include "cc/paint/draw_looper.h" #include "cc/paint/paint_shader.h" #include "ui/gfx/gfx_export.h" #include "ui/gfx/shadow_value.h" -class SkDrawLooper; class SkMatrix; namespace gfx { @@ -50,7 +50,7 @@ GFX_EXPORT sk_sp CreateGradientShader( // Creates a draw looper to generate |shadows|. The caller owns the draw looper. // NULL is returned if |shadows| is empty since no draw looper is needed in // this case. -GFX_EXPORT sk_sp CreateShadowDrawLooper( +GFX_EXPORT sk_sp CreateShadowDrawLooper( const std::vector& shadows); } // namespace gfx diff --git a/ui/views/animation/ink_drop_painted_layer_delegates.cc b/ui/views/animation/ink_drop_painted_layer_delegates.cc index c8504495bdbe88..c09bcef07cba7a 100644 --- a/ui/views/animation/ink_drop_painted_layer_delegates.cc +++ b/ui/views/animation/ink_drop_painted_layer_delegates.cc @@ -8,7 +8,6 @@ #include "cc/paint/paint_canvas.h" #include "cc/paint/paint_flags.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "third_party/skia/include/core/SkRRect.h" #include "ui/compositor/paint_recorder.h" #include "ui/gfx/canvas.h" diff --git a/ui/views/bubble/bubble_border.cc b/ui/views/bubble/bubble_border.cc index 7fb5850a43827a..4661a8b897a390 100644 --- a/ui/views/bubble/bubble_border.cc +++ b/ui/views/bubble/bubble_border.cc @@ -14,7 +14,6 @@ #include "base/no_destructor.h" #include "base/notreached.h" #include "cc/paint/paint_flags.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "third_party/skia/include/core/SkPath.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/color_palette.h" diff --git a/ui/views/controls/button/toggle_button.cc b/ui/views/controls/button/toggle_button.cc index e64e389141fd5d..c0cdfdb7d4f26b 100644 --- a/ui/views/controls/button/toggle_button.cc +++ b/ui/views/controls/button/toggle_button.cc @@ -9,7 +9,6 @@ #include #include "cc/paint/paint_flags.h" -#include "third_party/skia/include/core/SkDrawLooper.h" #include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_node_data.h" #include "ui/gfx/canvas.h"