Commit 7e39a8f1 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Fold SVGFilterPainter::FinishEffect

This function is now reasonably simple and small so we can fold it into
its only user (the ScopedSVGPaintState destructor).
This makes ScopedSVGPaintState::filter_ useless, so remove that field.

Bug: 109224
Change-Id: I24a90c300744802e0ab2d1b2e0b1d33fbc977797
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105218
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750903}
parent f8b2c5e9
...@@ -30,22 +30,51 @@ ...@@ -30,22 +30,51 @@
#include "third_party/blink/renderer/core/layout/svg/svg_resources.h" #include "third_party/blink/renderer/core/layout/svg/svg_resources.h"
#include "third_party/blink/renderer/core/layout/svg/svg_resources_cache.h" #include "third_party/blink/renderer/core/layout/svg/svg_resources_cache.h"
#include "third_party/blink/renderer/core/paint/svg_mask_painter.h" #include "third_party/blink/renderer/core/paint/svg_mask_painter.h"
#include "third_party/blink/renderer/platform/graphics/paint/drawing_recorder.h"
namespace blink { namespace blink {
static void PaintFilteredContent(GraphicsContext& context,
const LayoutObject& object,
const DisplayItemClient& display_item_client,
FilterData* filter_data) {
if (DrawingRecorder::UseCachedDrawingIfPossible(context, display_item_client,
DisplayItem::kSVGFilter))
return;
DrawingRecorder recorder(context, display_item_client,
DisplayItem::kSVGFilter);
sk_sp<PaintFilter> image_filter = filter_data->CreateFilter();
context.Save();
// Clip drawing of filtered image to the minimum required paint rect.
const FloatRect object_bounds = object.StrokeBoundingBox();
const FloatRect paint_rect = filter_data->MapRect(object_bounds);
context.ClipRect(paint_rect);
// Use the union of the pre-image and the post-image as the layer bounds.
const FloatRect layer_bounds = UnionRect(object_bounds, paint_rect);
context.BeginLayer(1, SkBlendMode::kSrcOver, &layer_bounds, kColorFilterNone,
std::move(image_filter));
context.EndLayer();
context.Restore();
}
ScopedSVGPaintState::~ScopedSVGPaintState() { ScopedSVGPaintState::~ScopedSVGPaintState() {
if (filter_data_) { if (filter_data_ && filter_data_->UpdateStateOnFinish()) {
DCHECK(filter_);
DCHECK(SVGResourcesCache::CachedResourcesForLayoutObject(object_)); DCHECK(SVGResourcesCache::CachedResourcesForLayoutObject(object_));
DCHECK( DCHECK(
SVGResourcesCache::CachedResourcesForLayoutObject(object_)->Filter() == SVGResourcesCache::CachedResourcesForLayoutObject(object_)->Filter());
filter_);
DCHECK(filter_recording_context_); DCHECK(filter_recording_context_);
SVGFilterPainter(*filter_).FinishEffect(object_, display_item_client_,
*filter_recording_context_);
if (filter_data_->ContentNeedsUpdate())
filter_data_->UpdateContent(filter_recording_context_->EndContent());
PaintFilteredContent(paint_info_.context, object_, display_item_client_,
filter_data_);
// Reset the paint info after the filter effect has been completed. // Reset the paint info after the filter effect has been completed.
filter_paint_info_ = nullptr; filter_paint_info_ = nullptr;
filter_data_ = nullptr;
} }
if (masker_) { if (masker_) {
...@@ -54,7 +83,7 @@ ScopedSVGPaintState::~ScopedSVGPaintState() { ...@@ -54,7 +83,7 @@ ScopedSVGPaintState::~ScopedSVGPaintState() {
SVGResourcesCache::CachedResourcesForLayoutObject(object_)->Masker() == SVGResourcesCache::CachedResourcesForLayoutObject(object_)->Masker() ==
masker_); masker_);
SVGMaskPainter(*masker_).FinishEffect(object_, display_item_client_, SVGMaskPainter(*masker_).FinishEffect(object_, display_item_client_,
GetPaintInfo().context); paint_info_.context);
} }
} }
...@@ -165,7 +194,6 @@ bool ScopedSVGPaintState::ApplyFilterIfNecessary(SVGResources* resources) { ...@@ -165,7 +194,6 @@ bool ScopedSVGPaintState::ApplyFilterIfNecessary(SVGResources* resources) {
filter->ClearInvalidationMask(); filter->ClearInvalidationMask();
filter_recording_context_ = filter_recording_context_ =
std::make_unique<SVGFilterRecordingContext>(GetPaintInfo().context); std::make_unique<SVGFilterRecordingContext>(GetPaintInfo().context);
filter_ = filter;
filter_data_ = SVGFilterPainter(*filter).PrepareEffect(object_); filter_data_ = SVGFilterPainter(*filter).PrepareEffect(object_);
// If we have no filter data (== the filter was invalid) or if we // If we have no filter data (== the filter was invalid) or if we
// don't need to update the source graphics, we can short-circuit // don't need to update the source graphics, we can short-circuit
......
...@@ -37,7 +37,6 @@ namespace blink { ...@@ -37,7 +37,6 @@ namespace blink {
class FilterData; class FilterData;
class LayoutObject; class LayoutObject;
class LayoutSVGResourceFilter;
class LayoutSVGResourceMasker; class LayoutSVGResourceMasker;
class SVGResources; class SVGResources;
...@@ -90,7 +89,6 @@ class ScopedSVGPaintState { ...@@ -90,7 +89,6 @@ class ScopedSVGPaintState {
: object_(object), : object_(object),
paint_info_(paint_info), paint_info_(paint_info),
display_item_client_(display_item_client), display_item_client_(display_item_client),
filter_(nullptr),
filter_data_(nullptr), filter_data_(nullptr),
masker_(nullptr) {} masker_(nullptr) {}
...@@ -120,7 +118,6 @@ class ScopedSVGPaintState { ...@@ -120,7 +118,6 @@ class ScopedSVGPaintState {
PaintInfo paint_info_; PaintInfo paint_info_;
const DisplayItemClient& display_item_client_; const DisplayItemClient& display_item_client_;
std::unique_ptr<PaintInfo> filter_paint_info_; std::unique_ptr<PaintInfo> filter_paint_info_;
LayoutSVGResourceFilter* filter_;
FilterData* filter_data_; FilterData* filter_data_;
LayoutSVGResourceMasker* masker_; LayoutSVGResourceMasker* masker_;
base::Optional<ClipPathClipper> clip_path_clipper_; base::Optional<ClipPathClipper> clip_path_clipper_;
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "third_party/blink/renderer/core/svg/svg_filter_element.h" #include "third_party/blink/renderer/core/svg/svg_filter_element.h"
#include "third_party/blink/renderer/platform/graphics/filters/filter.h" #include "third_party/blink/renderer/platform/graphics/filters/filter.h"
#include "third_party/blink/renderer/platform/graphics/filters/source_graphic.h" #include "third_party/blink/renderer/platform/graphics/filters/source_graphic.h"
#include "third_party/blink/renderer/platform/graphics/paint/drawing_recorder.h"
namespace blink { namespace blink {
...@@ -46,32 +45,6 @@ sk_sp<PaintRecord> SVGFilterRecordingContext::EndContent() { ...@@ -46,32 +45,6 @@ sk_sp<PaintRecord> SVGFilterRecordingContext::EndContent() {
return content; return content;
} }
static void PaintFilteredContent(GraphicsContext& context,
const LayoutObject& object,
const DisplayItemClient& display_item_client,
FilterData* filter_data) {
if (DrawingRecorder::UseCachedDrawingIfPossible(context, display_item_client,
DisplayItem::kSVGFilter))
return;
DrawingRecorder recorder(context, display_item_client,
DisplayItem::kSVGFilter);
sk_sp<PaintFilter> image_filter = filter_data->CreateFilter();
context.Save();
// Clip drawing of filtered image to the minimum required paint rect.
const FloatRect object_bounds = object.StrokeBoundingBox();
const FloatRect paint_rect = filter_data->MapRect(object_bounds);
context.ClipRect(paint_rect);
// Use the union of the pre-image and the post-image as the layer bounds.
const FloatRect layer_bounds = UnionRect(object_bounds, paint_rect);
context.BeginLayer(1, SkBlendMode::kSrcOver, &layer_bounds, kColorFilterNone,
std::move(image_filter));
context.EndLayer();
context.Restore();
}
FilterData* SVGFilterPainter::PrepareEffect(const LayoutObject& object) { FilterData* SVGFilterPainter::PrepareEffect(const LayoutObject& object) {
SVGElementResourceClient* client = SVGResources::GetClient(object); SVGElementResourceClient* client = SVGResources::GetClient(object);
if (FilterData* filter_data = client->GetFilterData()) { if (FilterData* filter_data = client->GetFilterData()) {
...@@ -99,22 +72,4 @@ FilterData* SVGFilterPainter::PrepareEffect(const LayoutObject& object) { ...@@ -99,22 +72,4 @@ FilterData* SVGFilterPainter::PrepareEffect(const LayoutObject& object) {
return filter_data; return filter_data;
} }
void SVGFilterPainter::FinishEffect(
const LayoutObject& object,
const DisplayItemClient& display_item_client,
SVGFilterRecordingContext& recording_context) {
FilterData* filter_data = SVGResources::GetClient(object)->GetFilterData();
DCHECK(filter_data);
if (!filter_data->UpdateStateOnFinish())
return;
// Check for RecordingContent here because we may can be re-painting
// without re-recording the contents to be filtered.
if (filter_data->ContentNeedsUpdate())
filter_data->UpdateContent(recording_context.EndContent());
PaintFilteredContent(recording_context.PaintingContext(), object,
display_item_client, filter_data);
}
} // namespace blink } // namespace blink
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
namespace blink { namespace blink {
class DisplayItemClient;
class FilterData; class FilterData;
class LayoutObject; class LayoutObject;
class LayoutSVGResourceFilter; class LayoutSVGResourceFilter;
...@@ -28,8 +27,6 @@ class SVGFilterRecordingContext { ...@@ -28,8 +27,6 @@ class SVGFilterRecordingContext {
GraphicsContext* BeginContent(); GraphicsContext* BeginContent();
sk_sp<PaintRecord> EndContent(); sk_sp<PaintRecord> EndContent();
GraphicsContext& PaintingContext() const { return initial_context_; }
private: private:
std::unique_ptr<PaintController> paint_controller_; std::unique_ptr<PaintController> paint_controller_;
std::unique_ptr<GraphicsContext> context_; std::unique_ptr<GraphicsContext> context_;
...@@ -46,9 +43,6 @@ class SVGFilterPainter { ...@@ -46,9 +43,6 @@ class SVGFilterPainter {
// Returns the FilterData for the filter effect, or null if the // Returns the FilterData for the filter effect, or null if the
// filter is invalid. // filter is invalid.
FilterData* PrepareEffect(const LayoutObject&); FilterData* PrepareEffect(const LayoutObject&);
void FinishEffect(const LayoutObject&,
const DisplayItemClient&,
SVGFilterRecordingContext&);
private: private:
LayoutSVGResourceFilter& filter_; LayoutSVGResourceFilter& filter_;
......
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