Commit 867c3730 authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

[Cleanup] Move some code from PaintWorkletGlobalScope to PaintWorklet

This CL moves part of the code from registerPaint into a new API
in PaintWorklet. The reason is that these code are working on a
member that is in the PaintWorklet class, so it really should belong
to the PaintWorklet class.

Bug: None
Change-Id: If8c0eb0390d8c64d2fedb48a1a337e6981c11f65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1644007Reviewed-by: default avatarYi Gu <yigu@chromium.org>
Commit-Queue: Xida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666093}
parent 788e705b
...@@ -145,6 +145,36 @@ void PaintWorklet::Trace(blink::Visitor* visitor) { ...@@ -145,6 +145,36 @@ void PaintWorklet::Trace(blink::Visitor* visitor) {
Supplement<LocalDOMWindow>::Trace(visitor); Supplement<LocalDOMWindow>::Trace(visitor);
} }
void PaintWorklet::RegisterCSSPaintDefinition(const String& name,
CSSPaintDefinition* definition,
ExceptionState& exception_state) {
if (document_definition_map_.Contains(name)) {
DocumentPaintDefinition* existing_document_definition =
document_definition_map_.at(name);
if (existing_document_definition == kInvalidDocumentPaintDefinition)
return;
if (!existing_document_definition->RegisterAdditionalPaintDefinition(
*definition)) {
document_definition_map_.Set(name, kInvalidDocumentPaintDefinition);
exception_state.ThrowDOMException(
DOMExceptionCode::kNotSupportedError,
"A class with name:'" + name +
"' was registered with a different definition.");
return;
}
// Notify the generator ready only when register paint is called the
// second time with the same |name| (i.e. there is already a document
// definition associated with |name|
if (existing_document_definition->GetRegisteredDefinitionCount() ==
PaintWorklet::kNumGlobalScopes)
pending_generator_registry_->NotifyGeneratorReady(name);
} else {
DocumentPaintDefinition* document_definition =
MakeGarbageCollected<DocumentPaintDefinition>(definition);
document_definition_map_.Set(name, document_definition);
}
}
void PaintWorklet::RegisterMainThreadDocumentPaintDefinition( void PaintWorklet::RegisterMainThreadDocumentPaintDefinition(
const String& name, const String& name,
Vector<CSSPropertyID> native_properties, Vector<CSSPropertyID> native_properties,
......
...@@ -60,6 +60,10 @@ class MODULES_EXPORT PaintWorklet : public Worklet, ...@@ -60,6 +60,10 @@ class MODULES_EXPORT PaintWorklet : public Worklet,
return document_definition_map_; return document_definition_map_;
} }
void RegisterCSSPaintDefinition(const String& name,
CSSPaintDefinition*,
ExceptionState&);
// Used for off-thread CSS Paint. In this mode we are not responsible for // Used for off-thread CSS Paint. In this mode we are not responsible for
// tracking whether a definition is valid - this method should only be called // tracking whether a definition is valid - this method should only be called
// once all global scopes have registered the same // once all global scopes have registered the same
......
...@@ -226,33 +226,8 @@ void PaintWorkletGlobalScope::registerPaint(const String& name, ...@@ -226,33 +226,8 @@ void PaintWorkletGlobalScope::registerPaint(const String& name,
} else { } else {
PaintWorklet* paint_worklet = PaintWorklet* paint_worklet =
PaintWorklet::From(*GetFrame()->GetDocument()->domWindow()); PaintWorklet::From(*GetFrame()->GetDocument()->domWindow());
PaintWorklet::DocumentDefinitionMap& document_definition_map = paint_worklet->RegisterCSSPaintDefinition(name, definition,
paint_worklet->GetDocumentDefinitionMap(); exception_state);
if (document_definition_map.Contains(name)) {
DocumentPaintDefinition* existing_document_definition =
document_definition_map.at(name);
if (existing_document_definition == kInvalidDocumentPaintDefinition)
return;
if (!existing_document_definition->RegisterAdditionalPaintDefinition(
*definition)) {
document_definition_map.Set(name, kInvalidDocumentPaintDefinition);
exception_state.ThrowDOMException(
DOMExceptionCode::kNotSupportedError,
"A class with name:'" + name +
"' was registered with a different definition.");
return;
}
// Notify the generator ready only when register paint is called the
// second time with the same |name| (i.e. there is already a document
// definition associated with |name|
if (existing_document_definition->GetRegisteredDefinitionCount() ==
PaintWorklet::kNumGlobalScopes)
pending_generator_registry_->NotifyGeneratorReady(name);
} else {
DocumentPaintDefinition* document_definition =
MakeGarbageCollected<DocumentPaintDefinition>(definition);
document_definition_map.Set(name, document_definition);
}
} }
} }
......
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