Commit efb7179d authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

Add a CrossThreadCopier in CSSSyntaxDescriptor

Current the RegisterMainThreadDocumentPaintDefinition is taking a
std::unique_ptr<Vector<CSSSyntaxDescriptor>> because the
CrossThreadCopier doesn't yet know how to handle a Vectof of
CSSSyntaxDescriptor.

This CL adds a CrossThreadCopier template in the css_syntax_descriptor.h
so that we no longer need to wrap the Vector<CSSSyntaxDescriptor> into
a std::unique_ptr. We add this template in the specific header file
such that it won't pollute the cross_thread_copier.h.

This CL does not change behavior.

Bug: None
Change-Id: Idcad4f578f44605cf535598713e3c03c5035b7aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1642957Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Xida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666089}
parent 81776a1a
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/css/css_syntax_component.h" #include "third_party/blink/renderer/core/css/css_syntax_component.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_token_range.h" #include "third_party/blink/renderer/core/css/parser/css_parser_token_range.h"
#include "third_party/blink/renderer/platform/cross_thread_copier.h"
namespace blink { namespace blink {
...@@ -48,6 +49,19 @@ class CORE_EXPORT CSSSyntaxDescriptor { ...@@ -48,6 +49,19 @@ class CORE_EXPORT CSSSyntaxDescriptor {
Vector<CSSSyntaxComponent> syntax_components_; Vector<CSSSyntaxComponent> syntax_components_;
}; };
template <wtf_size_t inlineCapacity, typename Allocator>
struct CrossThreadCopier<
Vector<CSSSyntaxDescriptor, inlineCapacity, Allocator>> {
using Type = Vector<CSSSyntaxDescriptor, inlineCapacity, Allocator>;
static Type Copy(const Type& value) {
Type result;
result.ReserveInitialCapacity(value.size());
for (const auto& element : value)
result.push_back(element.IsolatedCopy());
return result;
}
};
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_SYNTAX_DESCRIPTOR_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_SYNTAX_DESCRIPTOR_H_
...@@ -149,12 +149,12 @@ void PaintWorklet::RegisterMainThreadDocumentPaintDefinition( ...@@ -149,12 +149,12 @@ void PaintWorklet::RegisterMainThreadDocumentPaintDefinition(
const String& name, const String& name,
Vector<CSSPropertyID> native_properties, Vector<CSSPropertyID> native_properties,
Vector<String> custom_properties, Vector<String> custom_properties,
std::unique_ptr<Vector<CSSSyntaxDescriptor>> input_argument_types, Vector<CSSSyntaxDescriptor> input_argument_types,
double alpha) { double alpha) {
DCHECK(!main_thread_document_definition_map_.Contains(name)); DCHECK(!main_thread_document_definition_map_.Contains(name));
auto definition = std::make_unique<MainThreadDocumentPaintDefinition>( auto definition = std::make_unique<MainThreadDocumentPaintDefinition>(
std::move(native_properties), std::move(custom_properties), std::move(native_properties), std::move(custom_properties),
std::move(*input_argument_types), alpha); std::move(input_argument_types), alpha);
main_thread_document_definition_map_.insert(name, std::move(definition)); main_thread_document_definition_map_.insert(name, std::move(definition));
pending_generator_registry_->NotifyGeneratorReady(name); pending_generator_registry_->NotifyGeneratorReady(name);
} }
......
...@@ -68,7 +68,7 @@ class MODULES_EXPORT PaintWorklet : public Worklet, ...@@ -68,7 +68,7 @@ class MODULES_EXPORT PaintWorklet : public Worklet,
const String& name, const String& name,
Vector<CSSPropertyID> native_properties, Vector<CSSPropertyID> native_properties,
Vector<String> custom_properties, Vector<String> custom_properties,
std::unique_ptr<Vector<CSSSyntaxDescriptor>> input_argument_types, Vector<CSSSyntaxDescriptor> input_argument_types,
double alpha); double alpha);
typedef HashMap<String, std::unique_ptr<MainThreadDocumentPaintDefinition>> typedef HashMap<String, std::unique_ptr<MainThreadDocumentPaintDefinition>>
MainThreadDocumentDefinitionMap; MainThreadDocumentDefinitionMap;
......
...@@ -112,17 +112,13 @@ void PaintWorkletProxyClient::RegisterCSSPaintDefinition( ...@@ -112,17 +112,13 @@ void PaintWorkletProxyClient::RegisterCSSPaintDefinition(
for (const auto& property : custom_properties) for (const auto& property : custom_properties)
passed_custom_properties.push_back(property.GetString()); passed_custom_properties.push_back(property.GetString());
Vector<CSSSyntaxDescriptor> passed_input_argument_types;
for (const auto& syntax_descriptor : definition->InputArgumentTypes())
passed_input_argument_types.push_back(syntax_descriptor.IsolatedCopy());
PostCrossThreadTask( PostCrossThreadTask(
*main_thread_runner_, FROM_HERE, *main_thread_runner_, FROM_HERE,
CrossThreadBindOnce( CrossThreadBindOnce(
&PaintWorklet::RegisterMainThreadDocumentPaintDefinition, &PaintWorklet::RegisterMainThreadDocumentPaintDefinition,
paint_worklet_, name, definition->NativeInvalidationProperties(), paint_worklet_, name, definition->NativeInvalidationProperties(),
WTF::Passed(std::move(passed_custom_properties)), WTF::Passed(std::move(passed_custom_properties)),
std::make_unique<Vector<CSSSyntaxDescriptor>>( definition->InputArgumentTypes(),
passed_input_argument_types),
definition->GetPaintRenderingContext2DSettings()->alpha())); definition->GetPaintRenderingContext2DSettings()->alpha()));
} }
} }
......
...@@ -190,7 +190,7 @@ TEST_F(PaintWorkletTest, NativeAndCustomProperties) { ...@@ -190,7 +190,7 @@ TEST_F(PaintWorkletTest, NativeAndCustomProperties) {
TestPaintWorklet* paint_worklet_to_test = GetTestPaintWorklet(); TestPaintWorklet* paint_worklet_to_test = GetTestPaintWorklet();
paint_worklet_to_test->RegisterMainThreadDocumentPaintDefinition( paint_worklet_to_test->RegisterMainThreadDocumentPaintDefinition(
"foo", native_invalidation_properties, custom_invalidation_properties, "foo", native_invalidation_properties, custom_invalidation_properties,
std::make_unique<Vector<CSSSyntaxDescriptor>>(), true); Vector<CSSSyntaxDescriptor>(), true);
CSSPaintImageGeneratorImpl* generator = CSSPaintImageGeneratorImpl* generator =
MakeGarbageCollected<CSSPaintImageGeneratorImpl>(paint_worklet_to_test, MakeGarbageCollected<CSSPaintImageGeneratorImpl>(paint_worklet_to_test,
......
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