Commit 6834fb78 authored by Adam Raine's avatar Adam Raine Committed by Commit Bot

Ensure consistent document paint definiton between threads

RegisterMainThreadDocumentPaint definition now handles the case where
a definiton registered on the worklet thread is different from a
definiton on the main thread with the same name.  In this case,
the reference in document_definiton_map_ is set to null.

Bug: 948761
Change-Id: Ic969e2faf09c66013d79ab9ae8966befdf263432
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1662531
Commit-Queue: Adam Raine <asraine@google.com>
Reviewed-by: default avatarXida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670104}
parent 25dac1c8
...@@ -21,10 +21,25 @@ DocumentPaintDefinition::~DocumentPaintDefinition() = default; ...@@ -21,10 +21,25 @@ DocumentPaintDefinition::~DocumentPaintDefinition() = default;
bool DocumentPaintDefinition::RegisterAdditionalPaintDefinition( bool DocumentPaintDefinition::RegisterAdditionalPaintDefinition(
const CSSPaintDefinition& other) { const CSSPaintDefinition& other) {
if (alpha() != other.GetPaintRenderingContext2DSettings()->alpha() || if (other.NativeInvalidationProperties() != NativeInvalidationProperties() ||
NativeInvalidationProperties() != other.NativeInvalidationProperties() || other.CustomInvalidationProperties() != CustomInvalidationProperties() ||
CustomInvalidationProperties() != other.CustomInvalidationProperties() || other.InputArgumentTypes() != InputArgumentTypes() ||
InputArgumentTypes() != other.InputArgumentTypes()) other.GetPaintRenderingContext2DSettings()->alpha() != alpha())
return false;
registered_definitions_count_++;
return true;
}
bool DocumentPaintDefinition::RegisterAdditionalPaintDefinition(
const Vector<CSSPropertyID>& native_properties,
const Vector<String>& custom_properties,
const Vector<CSSSyntaxDescriptor>& input_argument_types,
bool alpha) {
if (native_properties != NativeInvalidationProperties() ||
!std::equal(custom_properties.begin(), custom_properties.end(),
CustomInvalidationProperties().begin(),
CustomInvalidationProperties().end()) ||
input_argument_types != InputArgumentTypes() || alpha != this->alpha())
return false; return false;
registered_definitions_count_++; registered_definitions_count_++;
return true; return true;
......
...@@ -43,6 +43,10 @@ class MODULES_EXPORT DocumentPaintDefinition { ...@@ -43,6 +43,10 @@ class MODULES_EXPORT DocumentPaintDefinition {
bool alpha() const { return alpha_; } bool alpha() const { return alpha_; }
bool RegisterAdditionalPaintDefinition(const CSSPaintDefinition&); bool RegisterAdditionalPaintDefinition(const CSSPaintDefinition&);
bool RegisterAdditionalPaintDefinition(const Vector<CSSPropertyID>&,
const Vector<String>&,
const Vector<CSSSyntaxDescriptor>&,
bool alpha);
unsigned GetRegisteredDefinitionCount() const { unsigned GetRegisteredDefinitionCount() const {
return registered_definitions_count_; return registered_definitions_count_;
......
...@@ -164,8 +164,15 @@ void PaintWorklet::RegisterCSSPaintDefinition(const String& name, ...@@ -164,8 +164,15 @@ void PaintWorklet::RegisterCSSPaintDefinition(const String& name,
// Notify the generator ready only when register paint is called the // Notify the generator ready only when register paint is called the
// second time with the same |name| (i.e. there is already a document // second time with the same |name| (i.e. there is already a document
// definition associated with |name| // definition associated with |name|
//
// We are looking for kNumGlobalScopesPerThread number of definitions
// regiserered from RegisterCSSPaintDefinition and one extra definition from
// RegisterMainThreadDocumentPaintDefinition if OffMainThreadCSSPaintEnabled
// is true.
if (existing_document_definition->GetRegisteredDefinitionCount() == if (existing_document_definition->GetRegisteredDefinitionCount() ==
PaintWorklet::kNumGlobalScopesPerThread) RuntimeEnabledFeatures::OffMainThreadCSSPaintEnabled()
? kNumGlobalScopesPerThread + 1
: kNumGlobalScopesPerThread)
pending_generator_registry_->NotifyGeneratorReady(name); pending_generator_registry_->NotifyGeneratorReady(name);
} else { } else {
auto document_definition = std::make_unique<DocumentPaintDefinition>( auto document_definition = std::make_unique<DocumentPaintDefinition>(
...@@ -183,18 +190,38 @@ void PaintWorklet::RegisterMainThreadDocumentPaintDefinition( ...@@ -183,18 +190,38 @@ void PaintWorklet::RegisterMainThreadDocumentPaintDefinition(
Vector<String> custom_properties, Vector<String> custom_properties,
Vector<CSSSyntaxDescriptor> input_argument_types, Vector<CSSSyntaxDescriptor> input_argument_types,
double alpha) { double alpha) {
// Because this method is called cross-thread, |custom_properties| cannot be if (document_definition_map_.Contains(name)) {
// an AtomicString. Instead, convert to AtomicString now that we are on the DocumentPaintDefinition* document_definition =
// main thread. document_definition_map_.at(name);
Vector<AtomicString> new_custom_properties; if (!document_definition)
new_custom_properties.ReserveInitialCapacity(custom_properties.size()); return;
for (const String& property : custom_properties) if (!document_definition->RegisterAdditionalPaintDefinition(
new_custom_properties.push_back(AtomicString(property)); native_properties, custom_properties, input_argument_types,
auto definition = std::make_unique<DocumentPaintDefinition>( alpha)) {
std::move(native_properties), std::move(new_custom_properties), document_definition_map_.Set(name, nullptr);
std::move(input_argument_types), alpha); return;
document_definition_map_.insert(name, std::move(definition)); }
pending_generator_registry_->NotifyGeneratorReady(name); } else {
// Because this method is called cross-thread, |custom_properties| cannot be
// an AtomicString. Instead, convert to AtomicString now that we are on the
// main thread.
Vector<AtomicString> new_custom_properties;
new_custom_properties.ReserveInitialCapacity(custom_properties.size());
for (const String& property : custom_properties)
new_custom_properties.push_back(AtomicString(property));
auto document_definition = std::make_unique<DocumentPaintDefinition>(
std::move(native_properties), std::move(new_custom_properties),
std::move(input_argument_types), alpha);
document_definition_map_.insert(name, std::move(document_definition));
}
DocumentPaintDefinition* document_definition =
document_definition_map_.at(name);
// We are looking for kNumGlobalScopesPerThread number of definitions
// registered from RegisterCSSPaintDefinition and one extra definition from
// RegisterMainThreadDocumentPaintDefinition
if (document_definition->GetRegisteredDefinitionCount() ==
kNumGlobalScopesPerThread + 1)
pending_generator_registry_->NotifyGeneratorReady(name);
} }
bool PaintWorklet::NeedsToCreateGlobalScope() { bool PaintWorklet::NeedsToCreateGlobalScope() {
......
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