Commit 667dd405 authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

Split blink::PaintWorkletInput into two classes

This is a code health CL, it doesn't change behavior.

We are moving the NativePaintWorklet paint off the main thread, which
is captured in this CL:
https://chromium-review.googlesource.com/c/chromium/src/+/2466140

As part of it, we are creating a NativePaintWorkletInput, and it
would share some common bits with the CSS version. So this CL
splits the blink::PaintWorkletInput into two classes:
1. The base class that contains the common bits.
2. A CSSPaintWorkletInput that is specifically for the CSS paint.

Bug: 1139004
Change-Id: Id6d814a0f1e479f6895897e458b3d0995b80d0ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2506078Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Xida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822191}
parent 53cde64f
......@@ -248,6 +248,8 @@ blink_core_sources_css = [
"cssom/css_numeric_value.h",
"cssom/css_numeric_value_type.cc",
"cssom/css_numeric_value_type.h",
"cssom/css_paint_worklet_input.cc",
"cssom/css_paint_worklet_input.h",
"cssom/css_perspective.cc",
"cssom/css_perspective.h",
"cssom/css_position_value.cc",
......@@ -295,7 +297,6 @@ blink_core_sources_css = [
"cssom/inline_style_property_map.h",
"cssom/paint_worklet_deferred_image.cc",
"cssom/paint_worklet_deferred_image.h",
"cssom/paint_worklet_input.cc",
"cssom/paint_worklet_input.h",
"cssom/paint_worklet_style_property_map.cc",
"cssom/paint_worklet_style_property_map.h",
......
......@@ -8,8 +8,8 @@
#include "third_party/blink/renderer/core/css/css_custom_ident_value.h"
#include "third_party/blink/renderer/core/css/css_paint_image_generator.h"
#include "third_party/blink/renderer/core/css/css_syntax_definition.h"
#include "third_party/blink/renderer/core/css/cssom/css_paint_worklet_input.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/style_value_factory.h"
#include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
......@@ -163,8 +163,8 @@ scoped_refptr<Image> CSSPaintValue::GetImage(
Vector<std::unique_ptr<CrossThreadStyleValue>>
cross_thread_input_arguments;
BuildInputArgumentValues(cross_thread_input_arguments);
scoped_refptr<PaintWorkletInput> input =
base::MakeRefCounted<PaintWorkletInput>(
scoped_refptr<CSSPaintWorkletInput> input =
base::MakeRefCounted<CSSPaintWorkletInput>(
GetName(), target_size, zoom, device_scale_factor,
generator.WorkletId(), std::move(style_data.value()),
std::move(cross_thread_input_arguments),
......
......@@ -4,11 +4,11 @@
#include <utility>
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h"
#include "third_party/blink/renderer/core/css/cssom/css_paint_worklet_input.h"
namespace blink {
PaintWorkletInput::PaintWorkletInput(
CSSPaintWorkletInput::CSSPaintWorkletInput(
const String& name,
const FloatSize& container_size,
float effective_zoom,
......@@ -17,13 +17,11 @@ PaintWorkletInput::PaintWorkletInput(
PaintWorkletStylePropertyMap::CrossThreadData data,
Vector<std::unique_ptr<CrossThreadStyleValue>> parsed_input_arguments,
cc::PaintWorkletInput::PropertyKeys property_keys)
: name_(name.IsolatedCopy()),
container_size_(container_size),
: PaintWorkletInput(container_size, worklet_id, property_keys),
name_(name.IsolatedCopy()),
effective_zoom_(effective_zoom),
device_scale_factor_(device_scale_factor),
worklet_id_(worklet_id),
style_map_data_(std::move(data)),
parsed_input_arguments_(std::move(parsed_input_arguments)),
property_keys_(std::move(property_keys)) {}
parsed_input_arguments_(std::move(parsed_input_arguments)) {}
} // namespace blink
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CSS_PAINT_WORKLET_INPUT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CSS_PAINT_WORKLET_INPUT_H_
#include <memory>
#include <utility>
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h"
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_style_property_map.h"
#include "third_party/blink/renderer/platform/geometry/float_size.h"
#include "third_party/blink/renderer/platform/graphics/compositor_element_id.h"
namespace blink {
// CSSPaintWorkletInput encapsulates the necessary information to run a CSS
// Paint instance (a 'PaintWorklet') for a given target (e.g. the
// 'background-image' property of a particular element). It is used to enable
// Off-Thread PaintWorklet, allowing us to defer the actual JavaScript calls
// until the cc-Raster phase (and even then run the JavaScript on a separate
// worklet thread).
//
// This object is passed cross-thread, but contains thread-unsafe objects (the
// WTF::Strings for |name_| and the WTF::Strings stored in |style_map_|). As
// such CSSPaintWorkletInput must be treated carefully. In essence, it 'belongs'
// to the PaintWorklet thread for the purposes of the WTF::String members. None
// of the WTF::String accessors should be accessed on any thread apart from the
// PaintWorklet thread, where an IsolatedCopy should still be taken.
//
// An IsolatedCopy is still needed on the PaintWorklet thread because
// cc::PaintWorkletInput is thread-safe ref-counted (it is shared between Blink,
// cc-impl, and the cc-raster thread pool), so we *do not know* on what thread
// this object will die - and thus on what thread the WTF::Strings that it
// contains will die.
class CORE_EXPORT CSSPaintWorkletInput : public PaintWorkletInput {
public:
CSSPaintWorkletInput(
const String& name,
const FloatSize& container_size,
float effective_zoom,
float device_scale_factor,
int worklet_id,
PaintWorkletStylePropertyMap::CrossThreadData values,
Vector<std::unique_ptr<CrossThreadStyleValue>> parsed_input_args,
cc::PaintWorkletInput::PropertyKeys property_keys);
~CSSPaintWorkletInput() override = default;
// These accessors are safe on any thread.
float EffectiveZoom() const { return effective_zoom_; }
float DeviceScaleFactor() const { return device_scale_factor_; }
const Vector<std::unique_ptr<CrossThreadStyleValue>>& ParsedInputArguments()
const {
return parsed_input_arguments_;
}
// These should only be accessed on the PaintWorklet thread.
String NameCopy() const { return name_.IsolatedCopy(); }
PaintWorkletStylePropertyMap::CrossThreadData StyleMapData() const {
return PaintWorkletStylePropertyMap::CopyCrossThreadData(style_map_data_);
}
private:
const String name_;
const float effective_zoom_;
const float device_scale_factor_;
PaintWorkletStylePropertyMap::CrossThreadData style_map_data_;
Vector<std::unique_ptr<CrossThreadStyleValue>> parsed_input_arguments_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CSS_PAINT_WORKLET_INPUT_H_
......@@ -10,45 +10,14 @@
#include "cc/paint/paint_worklet_input.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_style_property_map.h"
#include "third_party/blink/renderer/platform/geometry/float_size.h"
#include "third_party/blink/renderer/platform/graphics/compositor_element_id.h"
namespace blink {
// PaintWorkletInput encapsulates the necessary information to run a CSS Paint
// instance (a 'PaintWorklet') for a given target (e.g. the 'background-image'
// property of a particular element). It is used to enable Off-Thread
// PaintWorklet, allowing us to defer the actual JavaScript calls until the
// cc-Raster phase (and even then run the JavaScript on a separate worklet
// thread).
//
// This object is passed cross-thread, but contains thread-unsafe objects (the
// WTF::Strings for |name_| and the WTF::Strings stored in |style_map_|). As
// such PaintWorkletInput must be treated carefully. In essence, it 'belongs' to
// the PaintWorklet thread for the purposes of the WTF::String members. None of
// the WTF::String accessors should be accessed on any thread apart from the
// PaintWorklet thread, where an IsolatedCopy should still be taken.
//
// An IsolatedCopy is still needed on the PaintWorklet thread because
// cc::PaintWorkletInput is thread-safe ref-counted (it is shared between Blink,
// cc-impl, and the cc-raster thread pool), so we *do not know* on what thread
// this object will die - and thus on what thread the WTF::Strings that it
// contains will die.
// PaintWorkletInput contains information that is shared by the native and the
// CSS paint worklet.
class CORE_EXPORT PaintWorkletInput : public cc::PaintWorkletInput {
public:
PaintWorkletInput(
const String& name,
const FloatSize& container_size,
float effective_zoom,
float device_scale_factor,
int worklet_id,
PaintWorkletStylePropertyMap::CrossThreadData values,
Vector<std::unique_ptr<CrossThreadStyleValue>> parsed_input_args,
cc::PaintWorkletInput::PropertyKeys property_keys);
~PaintWorkletInput() override = default;
// PaintWorkletInput implementation
gfx::SizeF GetSize() const override {
return gfx::SizeF(container_size_.Width(), container_size_.Height());
......@@ -60,27 +29,20 @@ class CORE_EXPORT PaintWorkletInput : public cc::PaintWorkletInput {
// These accessors are safe on any thread.
const FloatSize& ContainerSize() const { return container_size_; }
float EffectiveZoom() const { return effective_zoom_; }
float DeviceScaleFactor() const { return device_scale_factor_; }
const Vector<std::unique_ptr<CrossThreadStyleValue>>& ParsedInputArguments()
const {
return parsed_input_arguments_;
}
// These should only be accessed on the PaintWorklet thread.
String NameCopy() const { return name_.IsolatedCopy(); }
PaintWorkletStylePropertyMap::CrossThreadData StyleMapData() const {
return PaintWorkletStylePropertyMap::CopyCrossThreadData(style_map_data_);
}
protected:
PaintWorkletInput(const FloatSize& container_size,
int worklet_id,
cc::PaintWorkletInput::PropertyKeys property_keys)
: container_size_(container_size),
worklet_id_(worklet_id),
property_keys_(std::move(property_keys)) {}
~PaintWorkletInput() override = default;
private:
const String name_;
const FloatSize container_size_;
const float effective_zoom_;
const float device_scale_factor_;
const int worklet_id_;
PaintWorkletStylePropertyMap::CrossThreadData style_map_data_;
Vector<std::unique_ptr<CrossThreadStyleValue>> parsed_input_arguments_;
// List of properties associated with this PaintWorkletInput.
// Kept and initialized here, but used in CC, so using C++ std library types.
......
......@@ -11,10 +11,10 @@
#include "third_party/blink/renderer/core/css/css_computed_style_declaration.h"
#include "third_party/blink/renderer/core/css/css_test_helpers.h"
#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_paint_worklet_input.h"
#include "third_party/blink/renderer/core/css/cssom/css_unit_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_unparsed_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_unsupported_color_value.h"
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h"
#include "third_party/blink/renderer/core/css/properties/longhands/custom_property.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
......@@ -50,7 +50,7 @@ class PaintWorkletStylePropertyMapTest : public PageTestBase {
}
void CheckUnregisteredProperty(base::WaitableEvent* waitable_event,
scoped_refptr<PaintWorkletInput> input) {
scoped_refptr<CSSPaintWorkletInput> input) {
ASSERT_TRUE(!IsMainThread());
PaintWorkletStylePropertyMap* map =
......@@ -71,7 +71,7 @@ class PaintWorkletStylePropertyMapTest : public PageTestBase {
}
void CheckCrossThreadData(base::WaitableEvent* waitable_event,
scoped_refptr<PaintWorkletInput> input) {
scoped_refptr<CSSPaintWorkletInput> input) {
DCHECK(!IsMainThread());
PaintWorkletStylePropertyMap* map =
......@@ -130,8 +130,8 @@ TEST_F(PaintWorkletStylePropertyMapTest, UnregisteredCustomProperty) {
Vector<std::unique_ptr<CrossThreadStyleValue>> input_arguments;
std::vector<cc::PaintWorkletInput::PropertyKey> property_keys;
scoped_refptr<PaintWorkletInput> input =
base::MakeRefCounted<PaintWorkletInput>(
scoped_refptr<CSSPaintWorkletInput> input =
base::MakeRefCounted<CSSPaintWorkletInput>(
"test", FloatSize(100, 100), 1.0f, 1.0f, 1, std::move(data.value()),
std::move(input_arguments), std::move(property_keys));
ASSERT_TRUE(input);
......@@ -178,8 +178,8 @@ TEST_F(PaintWorkletStylePropertyMapTest, SupportedCrossThreadData) {
EXPECT_TRUE(data.has_value());
std::vector<cc::PaintWorkletInput::PropertyKey> property_keys;
scoped_refptr<PaintWorkletInput> input =
base::MakeRefCounted<PaintWorkletInput>(
scoped_refptr<CSSPaintWorkletInput> input =
base::MakeRefCounted<CSSPaintWorkletInput>(
"test", FloatSize(100, 100), 1.0f, 1.0f, 1, std::move(data.value()),
std::move(input_arguments), std::move(property_keys));
DCHECK(input);
......
......@@ -9,8 +9,8 @@
#include "base/single_thread_task_runner.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_color_value.h"
#include "third_party/blink/renderer/core/css/cssom/cross_thread_unit_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_paint_worklet_input.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/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_base.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
......@@ -184,8 +184,8 @@ sk_sp<PaintRecord> PaintWorkletProxyClient::Paint(
PaintWorkletGlobalScope* global_scope = global_scopes_[base::RandInt(
0, (PaintWorklet::kNumGlobalScopesPerThread)-1)];
const PaintWorkletInput* input =
static_cast<const PaintWorkletInput*>(compositor_input);
const CSSPaintWorkletInput* input =
static_cast<const CSSPaintWorkletInput*>(compositor_input);
CSSPaintDefinition* definition =
global_scope->FindDefinition(input->NameCopy());
PaintWorkletStylePropertyMap* style_map =
......
......@@ -12,7 +12,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_code.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/css_paint_worklet_input.h"
#include "third_party/blink/renderer/core/script/classic_script.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
......@@ -219,8 +219,8 @@ void RunPaintTestOnWorklet(WorkerThread* thread,
PaintWorkletStylePropertyMap::CrossThreadData data;
Vector<std::unique_ptr<CrossThreadStyleValue>> input_arguments;
std::vector<cc::PaintWorkletInput::PropertyKey> property_keys;
scoped_refptr<PaintWorkletInput> input =
base::MakeRefCounted<PaintWorkletInput>(
scoped_refptr<CSSPaintWorkletInput> input =
base::MakeRefCounted<CSSPaintWorkletInput>(
"foo", FloatSize(100, 100), 1.0f, 1.0f, 1, std::move(data),
std::move(input_arguments), std::move(property_keys));
sk_sp<PaintRecord> record = proxy_client->Paint(input.get(), {});
......
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