Commit f10e0c27 authored by Adam Raine's avatar Adam Raine Committed by Commit Bot

Added input args to PaintWorkletProxyClient::Paint

In the input data structure passed to PaintWorkletProxyClient::Paint
I added a structure to take the CSSStyleValueVector structure
parsed_input_arguments_ from CSSPaintValue.  The CSSStyleValues
needed to be converted into a vector of CrossThreadStyleValue
which is converted back to a CSSStyleValueVector.

Bug: 946519
Change-Id: I0fd02b88e5f105afc5c3269088bd82c6f72b0eb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1645894
Commit-Queue: Adam Raine <asraine@google.com>
Reviewed-by: default avatarXida Chen <xidachen@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667222}
parent 56bd6b07
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_deferred_image.h" #include "third_party/blink/renderer/core/css/cssom/paint_worklet_deferred_image.h"
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h" #include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h"
#include "third_party/blink/renderer/core/css/cssom/style_value_factory.h" #include "third_party/blink/renderer/core/css/cssom/style_value_factory.h"
#include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
#include "third_party/blink/renderer/core/layout/layout_object.h" #include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/platform/graphics/image.h" #include "third_party/blink/renderer/platform/graphics/image.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
...@@ -79,16 +80,28 @@ scoped_refptr<Image> CSSPaintValue::GetImage( ...@@ -79,16 +80,28 @@ scoped_refptr<Image> CSSPaintValue::GetImage(
PaintWorkletStylePropertyMap::BuildCrossThreadData( PaintWorkletStylePropertyMap::BuildCrossThreadData(
document, style, layout_object.GetNode(), native_properties, document, style, layout_object.GetNode(), native_properties,
custom_properties); custom_properties);
Vector<std::unique_ptr<CrossThreadStyleValue>> cross_thread_input_arguments;
BuildInputArgumentValues(cross_thread_input_arguments);
scoped_refptr<PaintWorkletInput> input = scoped_refptr<PaintWorkletInput> input =
base::MakeRefCounted<PaintWorkletInput>(GetName(), target_size, zoom, base::MakeRefCounted<PaintWorkletInput>(
generator_->WorkletId(), GetName(), target_size, zoom, generator_->WorkletId(),
std::move(style_data)); std::move(style_data), std::move(cross_thread_input_arguments));
return PaintWorkletDeferredImage::Create(std::move(input), target_size); return PaintWorkletDeferredImage::Create(std::move(input), target_size);
} }
return generator_->Paint(client, target_size, parsed_input_arguments_); return generator_->Paint(client, target_size, parsed_input_arguments_);
} }
void CSSPaintValue::BuildInputArgumentValues(
Vector<std::unique_ptr<CrossThreadStyleValue>>&
cross_thread_input_arguments) {
for (const auto& style_value : *parsed_input_arguments_) {
std::unique_ptr<CrossThreadStyleValue> cross_thread_style =
ComputedStyleUtils::CrossThreadStyleValueFromCSSStyleValue(style_value);
cross_thread_input_arguments.push_back(std::move(cross_thread_style));
}
}
bool CSSPaintValue::ParseInputArguments(const Document& document) { bool CSSPaintValue::ParseInputArguments(const Document& document) {
if (input_arguments_invalid_) if (input_arguments_invalid_)
return false; return false;
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
namespace blink { namespace blink {
class CrossThreadStyleValue;
class CORE_EXPORT CSSPaintValue : public CSSImageGeneratorValue { class CORE_EXPORT CSSPaintValue : public CSSImageGeneratorValue {
public: public:
explicit CSSPaintValue(CSSCustomIdentValue* name); explicit CSSPaintValue(CSSCustomIdentValue* name);
...@@ -74,6 +76,9 @@ class CORE_EXPORT CSSPaintValue : public CSSImageGeneratorValue { ...@@ -74,6 +76,9 @@ class CORE_EXPORT CSSPaintValue : public CSSImageGeneratorValue {
bool ParseInputArguments(const Document&); bool ParseInputArguments(const Document&);
void BuildInputArgumentValues(
Vector<std::unique_ptr<CrossThreadStyleValue>>&);
bool input_arguments_invalid_ = false; bool input_arguments_invalid_ = false;
Member<CSSCustomIdentValue> name_; Member<CSSCustomIdentValue> name_;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace blink { namespace blink {
CSSStyleValue* CrossThreadKeywordValue::ToCSSStyleValue() { CSSStyleValue* CrossThreadKeywordValue::ToCSSStyleValue() {
return CSSKeywordValue::Create(keyword_value_); return CSSKeywordValue::Create(std::move(keyword_value_.IsolatedCopy()));
} }
bool CrossThreadKeywordValue::operator==( bool CrossThreadKeywordValue::operator==(
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace blink { namespace blink {
CSSStyleValue* CrossThreadUnsupportedValue::ToCSSStyleValue() { CSSStyleValue* CrossThreadUnsupportedValue::ToCSSStyleValue() {
return CSSUnsupportedStyleValue::Create(value_); return CSSUnsupportedStyleValue::Create(std::move(value_.IsolatedCopy()));
} }
bool CrossThreadUnsupportedValue::operator==( bool CrossThreadUnsupportedValue::operator==(
......
...@@ -13,11 +13,13 @@ PaintWorkletInput::PaintWorkletInput( ...@@ -13,11 +13,13 @@ PaintWorkletInput::PaintWorkletInput(
const FloatSize& container_size, const FloatSize& container_size,
float effective_zoom, float effective_zoom,
int worklet_id, int worklet_id,
PaintWorkletStylePropertyMap::CrossThreadData data) PaintWorkletStylePropertyMap::CrossThreadData data,
Vector<std::unique_ptr<CrossThreadStyleValue>> parsed_input_arguments)
: name_(name.IsolatedCopy()), : name_(name.IsolatedCopy()),
container_size_(container_size), container_size_(container_size),
effective_zoom_(effective_zoom), effective_zoom_(effective_zoom),
worklet_id_(worklet_id), worklet_id_(worklet_id),
style_map_data_(std::move(data)) {} style_map_data_(std::move(data)),
parsed_input_arguments_(std::move(parsed_input_arguments)) {}
} // namespace blink } // namespace blink
...@@ -36,11 +36,13 @@ namespace blink { ...@@ -36,11 +36,13 @@ namespace blink {
// contains will die. // contains will die.
class CORE_EXPORT PaintWorkletInput : public cc::PaintWorkletInput { class CORE_EXPORT PaintWorkletInput : public cc::PaintWorkletInput {
public: public:
PaintWorkletInput(const String& name, PaintWorkletInput(
const FloatSize& container_size, const String& name,
float effective_zoom, const FloatSize& container_size,
int worklet_id, float effective_zoom,
PaintWorkletStylePropertyMap::CrossThreadData values); int worklet_id,
PaintWorkletStylePropertyMap::CrossThreadData values,
Vector<std::unique_ptr<CrossThreadStyleValue>> parsed_input_args);
~PaintWorkletInput() override = default; ~PaintWorkletInput() override = default;
...@@ -53,6 +55,10 @@ class CORE_EXPORT PaintWorkletInput : public cc::PaintWorkletInput { ...@@ -53,6 +55,10 @@ class CORE_EXPORT PaintWorkletInput : public cc::PaintWorkletInput {
// These accessors are safe on any thread. // These accessors are safe on any thread.
const FloatSize& ContainerSize() const { return container_size_; } const FloatSize& ContainerSize() const { return container_size_; }
float EffectiveZoom() const { return effective_zoom_; } float EffectiveZoom() const { return effective_zoom_; }
const Vector<std::unique_ptr<CrossThreadStyleValue>>& ParsedInputArguments()
const {
return parsed_input_arguments_;
}
// These should only be accessed on the PaintWorklet thread. // These should only be accessed on the PaintWorklet thread.
String NameCopy() const { return name_.IsolatedCopy(); } String NameCopy() const { return name_.IsolatedCopy(); }
...@@ -66,6 +72,7 @@ class CORE_EXPORT PaintWorkletInput : public cc::PaintWorkletInput { ...@@ -66,6 +72,7 @@ class CORE_EXPORT PaintWorkletInput : public cc::PaintWorkletInput {
const float effective_zoom_; const float effective_zoom_;
const int worklet_id_; const int worklet_id_;
PaintWorkletStylePropertyMap::CrossThreadData style_map_data_; PaintWorkletStylePropertyMap::CrossThreadData style_map_data_;
Vector<std::unique_ptr<CrossThreadStyleValue>> parsed_input_arguments_;
}; };
} // namespace blink } // namespace blink
......
...@@ -183,13 +183,15 @@ TEST_F(PaintWorkletStylePropertyMapTest, PassValuesCrossThread) { ...@@ -183,13 +183,15 @@ TEST_F(PaintWorkletStylePropertyMapTest, PassValuesCrossThread) {
UpdateAllLifecyclePhasesForTest(); UpdateAllLifecyclePhasesForTest();
Node* node = PageNode(); Node* node = PageNode();
Vector<std::unique_ptr<CrossThreadStyleValue>> input_arguments;
PaintWorkletStylePropertyMap::CrossThreadData data = PaintWorkletStylePropertyMap::CrossThreadData data =
PaintWorkletStylePropertyMap::BuildCrossThreadData( PaintWorkletStylePropertyMap::BuildCrossThreadData(
GetDocument(), node->ComputedStyleRef(), node, native_properties, GetDocument(), node->ComputedStyleRef(), node, native_properties,
custom_properties); custom_properties);
scoped_refptr<PaintWorkletInput> input = scoped_refptr<PaintWorkletInput> input =
base::MakeRefCounted<PaintWorkletInput>("test", FloatSize(100, 100), 1.0f, base::MakeRefCounted<PaintWorkletInput>("test", FloatSize(100, 100), 1.0f,
1, std::move(data)); 1, std::move(data),
std::move(input_arguments));
DCHECK(input); DCHECK(input);
thread_ = std::make_unique<WebThreadSupportingGC>( thread_ = std::make_unique<WebThreadSupportingGC>(
......
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
#include "third_party/blink/renderer/core/css/css_value.h" #include "third_party/blink/renderer/core/css/css_value.h"
#include "third_party/blink/renderer/core/css/css_value_list.h" #include "third_party/blink/renderer/core/css/css_value_list.h"
#include "third_party/blink/renderer/core/css/css_value_pair.h" #include "third_party/blink/renderer/core/css/css_value_pair.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_unit_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_unsupported_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_unit_value.h"
#include "third_party/blink/renderer/core/css/style_color.h" #include "third_party/blink/renderer/core/css/style_color.h"
#include "third_party/blink/renderer/core/layout/layout_block.h" #include "third_party/blink/renderer/core/layout/layout_block.h"
#include "third_party/blink/renderer/core/layout/layout_box.h" #include "third_party/blink/renderer/core/layout/layout_box.h"
...@@ -2396,4 +2401,22 @@ CSSValue* ComputedStyleUtils::ValueForGapLength(const GapLength& gap_length, ...@@ -2396,4 +2401,22 @@ CSSValue* ComputedStyleUtils::ValueForGapLength(const GapLength& gap_length,
return ZoomAdjustedPixelValueForLength(gap_length.GetLength(), style); return ZoomAdjustedPixelValueForLength(gap_length.GetLength(), style);
} }
std::unique_ptr<CrossThreadStyleValue>
ComputedStyleUtils::CrossThreadStyleValueFromCSSStyleValue(
CSSStyleValue* style_value) {
switch (style_value->GetType()) {
case CSSStyleValue::StyleValueType::kKeywordType:
return std::make_unique<CrossThreadKeywordValue>(
To<CSSKeywordValue>(style_value)->value().IsolatedCopy());
case CSSStyleValue::StyleValueType::kUnitType:
return std::make_unique<CrossThreadUnitValue>(
To<CSSUnitValue>(style_value)->value(),
To<CSSUnitValue>(style_value)->GetInternalUnit());
default:
// Make an isolated copy to ensure that it is safe to pass cross thread.
return std::make_unique<CrossThreadUnsupportedValue>(
style_value->toString().IsolatedCopy());
}
}
} // namespace blink } // namespace blink
...@@ -20,6 +20,7 @@ namespace blink { ...@@ -20,6 +20,7 @@ namespace blink {
using namespace cssvalue; using namespace cssvalue;
class ComputedStyle; class ComputedStyle;
class CSSStyleValue;
class CSSValue; class CSSValue;
class StyleColor; class StyleColor;
class StylePropertyShorthand; class StylePropertyShorthand;
...@@ -203,6 +204,8 @@ class ComputedStyleUtils { ...@@ -203,6 +204,8 @@ class ComputedStyleUtils {
static CSSValue* ScrollCustomizationFlagsToCSSValue( static CSSValue* ScrollCustomizationFlagsToCSSValue(
scroll_customization::ScrollDirection); scroll_customization::ScrollDirection);
static CSSValue* ValueForGapLength(const GapLength&, const ComputedStyle&); static CSSValue* ValueForGapLength(const GapLength&, const ComputedStyle&);
static std::unique_ptr<CrossThreadStyleValue>
CrossThreadStyleValueFromCSSStyleValue(CSSStyleValue* style_value);
}; };
} // namespace blink } // namespace blink
......
...@@ -5,13 +5,9 @@ ...@@ -5,13 +5,9 @@
#include "third_party/blink/renderer/core/css/properties/css_property.h" #include "third_party/blink/renderer/core/css/properties/css_property.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_style_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_unit_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_unsupported_value.h" #include "third_party/blink/renderer/core/css/cssom/cross_thread_unsupported_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_unit_value.h"
#include "third_party/blink/renderer/core/css/cssom/style_value_factory.h" #include "third_party/blink/renderer/core/css/cssom/style_value_factory.h"
#include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
#include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/style/svg_computed_style.h" #include "third_party/blink/renderer/core/style/svg_computed_style.h"
#include "third_party/blink/renderer/core/style_property_shorthand.h" #include "third_party/blink/renderer/core/style_property_shorthand.h"
...@@ -42,19 +38,8 @@ CSSProperty::CrossThreadStyleValueFromComputedStyle( ...@@ -42,19 +38,8 @@ CSSProperty::CrossThreadStyleValueFromComputedStyle(
StyleValueFactory::CssValueToStyleValue(GetCSSPropertyName(), *css_value); StyleValueFactory::CssValueToStyleValue(GetCSSPropertyName(), *css_value);
if (!style_value) if (!style_value)
return std::make_unique<CrossThreadUnsupportedValue>(""); return std::make_unique<CrossThreadUnsupportedValue>("");
switch (style_value->GetType()) { return ComputedStyleUtils::CrossThreadStyleValueFromCSSStyleValue(
case CSSStyleValue::StyleValueType::kKeywordType: style_value);
return std::make_unique<CrossThreadKeywordValue>(
To<CSSKeywordValue>(style_value)->value().IsolatedCopy());
case CSSStyleValue::StyleValueType::kUnitType:
return std::make_unique<CrossThreadUnitValue>(
To<CSSUnitValue>(style_value)->value(),
To<CSSUnitValue>(style_value)->GetInternalUnit());
default:
// Make an isolated copy to ensure that it is safe to pass cross thread.
return std::make_unique<CrossThreadUnsupportedValue>(
css_value->CssText().IsolatedCopy());
}
} }
const CSSValue* CSSProperty::CSSValueFromComputedStyle( const CSSValue* CSSProperty::CSSValueFromComputedStyle(
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "third_party/blink/renderer/core/css/cssom/css_style_value.h"
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h" #include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_base.h" #include "third_party/blink/renderer/core/frame/web_frame_widget_base.h"
...@@ -171,8 +172,14 @@ sk_sp<PaintRecord> PaintWorkletProxyClient::Paint( ...@@ -171,8 +172,14 @@ sk_sp<PaintRecord> PaintWorkletProxyClient::Paint(
PaintWorkletStylePropertyMap* style_map = PaintWorkletStylePropertyMap* style_map =
MakeGarbageCollected<PaintWorkletStylePropertyMap>(input->StyleMapData()); MakeGarbageCollected<PaintWorkletStylePropertyMap>(input->StyleMapData());
sk_sp<PaintRecord> result = definition->Paint( CSSStyleValueVector paint_arguments;
FloatSize(input->GetSize()), input->EffectiveZoom(), style_map, nullptr); for (const auto& style_value : input->ParsedInputArguments()) {
paint_arguments.push_back(style_value->ToCSSStyleValue());
}
sk_sp<PaintRecord> result =
definition->Paint(FloatSize(input->GetSize()), input->EffectiveZoom(),
style_map, &paint_arguments);
// CSSPaintDefinition::Paint returns nullptr if it fails, but for // CSSPaintDefinition::Paint returns nullptr if it fails, but for
// OffThread-PaintWorklet we prefer to insert empty PaintRecords into the // OffThread-PaintWorklet we prefer to insert empty PaintRecords into the
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_code.h" #include "third_party/blink/renderer/bindings/core/v8/script_source_code.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_style_value.h"
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h" #include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h" #include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
...@@ -186,9 +187,11 @@ void RunPaintTestOnWorklet(WorkerThread* thread, ...@@ -186,9 +187,11 @@ void RunPaintTestOnWorklet(WorkerThread* thread,
} }
PaintWorkletStylePropertyMap::CrossThreadData data; PaintWorkletStylePropertyMap::CrossThreadData data;
Vector<std::unique_ptr<CrossThreadStyleValue>> input_arguments;
scoped_refptr<PaintWorkletInput> input = scoped_refptr<PaintWorkletInput> input =
base::MakeRefCounted<PaintWorkletInput>("foo", FloatSize(100, 100), 1.0f, base::MakeRefCounted<PaintWorkletInput>("foo", FloatSize(100, 100), 1.0f,
1, std::move(data)); 1, std::move(data),
std::move(input_arguments));
sk_sp<PaintRecord> record = proxy_client->Paint(input.get()); sk_sp<PaintRecord> record = proxy_client->Paint(input.get());
EXPECT_NE(record, nullptr); EXPECT_NE(record, nullptr);
......
...@@ -4021,8 +4021,6 @@ crbug.com/626703 [ Win ] external/wpt/css/css-writing-modes/box-offsets-rel-pos- ...@@ -4021,8 +4021,6 @@ crbug.com/626703 [ Win ] external/wpt/css/css-writing-modes/box-offsets-rel-pos-
crbug.com/957457 virtual/threaded/external/wpt/css/css-paint-api/background-image-tiled.https.html [ Crash ] crbug.com/957457 virtual/threaded/external/wpt/css/css-paint-api/background-image-tiled.https.html [ Crash ]
crbug.com/957457 virtual/threaded/external/wpt/css/css-paint-api/geometry-background-image-tiled-001.https.html [ Crash ] crbug.com/957457 virtual/threaded/external/wpt/css/css-paint-api/geometry-background-image-tiled-001.https.html [ Crash ]
crbug.com/957457 virtual/threaded/external/wpt/css/css-paint-api/invalid-image-pending-script.https.html [ Crash ] crbug.com/957457 virtual/threaded/external/wpt/css/css-paint-api/invalid-image-pending-script.https.html [ Crash ]
crbug.com/957459 virtual/threaded/external/wpt/css/css-paint-api/paint-arguments.https.html [ Failure ]
crbug.com/957459 virtual/threaded/external/wpt/css/css-paint-api/paint-function-arguments.https.html [ Failure ]
crbug.com/957457 virtual/threaded/external/wpt/css/css-paint-api/paint2d-image.https.html [ Failure Timeout ] crbug.com/957457 virtual/threaded/external/wpt/css/css-paint-api/paint2d-image.https.html [ Failure Timeout ]
crbug.com/957459 virtual/threaded/external/wpt/css/css-paint-api/parse-input-arguments-018.https.html [ Crash Failure ] crbug.com/957459 virtual/threaded/external/wpt/css/css-paint-api/parse-input-arguments-018.https.html [ Crash Failure ]
crbug.com/957459 virtual/threaded/external/wpt/css/css-paint-api/registered-property-interpolation-004.https.html [ Failure ] crbug.com/957459 virtual/threaded/external/wpt/css/css-paint-api/registered-property-interpolation-004.https.html [ Failure ]
......
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