Commit 4f3d842e authored by junov's avatar junov Committed by Commit bot

Remove unnecessary style calculations in HTMLCanvasElement

When creating a WebGL canvas, and when allocating a 2D canvas backing,
the implementation was triggering an immediate style calculation
to evaluate the image-redering CSS property.  This CL gets rid of of
these calculations by relying on the fact that if the style is dirty,
it will be updated before the next paint, which will allow for the state
to be corrected after the fact, if necessary.

BUG=585135

Review URL: https://codereview.chromium.org/1674123003

Cr-Commit-Position: refs/heads/master@{#374753}
parent 2e802760
...@@ -135,7 +135,6 @@ inline HTMLCanvasElement::HTMLCanvasElement(Document& document) ...@@ -135,7 +135,6 @@ inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
, m_didFailToCreateImageBuffer(false) , m_didFailToCreateImageBuffer(false)
, m_imageBufferIsClear(false) , m_imageBufferIsClear(false)
{ {
setHasCustomStyleCallbacks();
CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated); CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated);
} }
...@@ -165,24 +164,6 @@ LayoutObject* HTMLCanvasElement::createLayoutObject(const ComputedStyle& style) ...@@ -165,24 +164,6 @@ LayoutObject* HTMLCanvasElement::createLayoutObject(const ComputedStyle& style)
return HTMLElement::createLayoutObject(style); return HTMLElement::createLayoutObject(style);
} }
void HTMLCanvasElement::didRecalcStyle(StyleRecalcChange)
{
SkFilterQuality filterQuality;
const ComputedStyle* style = ensureComputedStyle();
if (style && style->imageRendering() == ImageRenderingPixelated) {
filterQuality = kNone_SkFilterQuality;
} else {
filterQuality = kLow_SkFilterQuality;
}
if (is3D()) {
m_context->setFilterQuality(filterQuality);
setNeedsCompositingUpdate();
} else if (hasImageBuffer()) {
m_imageBuffer->setFilterQuality(filterQuality);
}
}
Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode* node) Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode* node)
{ {
setIsInCanvasSubtree(true); setIsInCanvasSubtree(true);
...@@ -265,10 +246,6 @@ CanvasRenderingContext* HTMLCanvasElement::getCanvasRenderingContext(const Strin ...@@ -265,10 +246,6 @@ CanvasRenderingContext* HTMLCanvasElement::getCanvasRenderingContext(const Strin
return nullptr; return nullptr;
if (m_context->is3d()) { if (m_context->is3d()) {
document().updateLayoutTreeForNodeIfNeeded(this);
const ComputedStyle* style = ensureComputedStyle();
if (style)
m_context->setFilterQuality(style->imageRendering() == ImageRenderingPixelated ? kNone_SkFilterQuality : kLow_SkFilterQuality);
updateExternallyAllocatedMemory(); updateExternallyAllocatedMemory();
} }
setNeedsCompositingUpdate(); setNeedsCompositingUpdate();
...@@ -458,6 +435,16 @@ void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r) ...@@ -458,6 +435,16 @@ void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r)
// FIXME: crbug.com/438240; there is a bug with the new CSS blending and compositing feature. // FIXME: crbug.com/438240; there is a bug with the new CSS blending and compositing feature.
if (!m_context) if (!m_context)
return; return;
const ComputedStyle* style = ensureComputedStyle();
SkFilterQuality filterQuality = (style && style->imageRendering() == ImageRenderingPixelated) ? kNone_SkFilterQuality : kLow_SkFilterQuality;
if (is3D()) {
m_context->setFilterQuality(filterQuality);
} else if (hasImageBuffer()) {
m_imageBuffer->setFilterQuality(filterQuality);
}
if (!paintsIntoCanvasBuffer() && !document().printing()) if (!paintsIntoCanvasBuffer() && !document().printing())
return; return;
...@@ -782,10 +769,6 @@ void HTMLCanvasElement::createImageBufferInternal(PassOwnPtr<ImageBufferSurface> ...@@ -782,10 +769,6 @@ void HTMLCanvasElement::createImageBufferInternal(PassOwnPtr<ImageBufferSurface>
return; return;
m_imageBuffer->setClient(this); m_imageBuffer->setClient(this);
document().updateLayoutTreeIfNeeded();
const ComputedStyle* style = ensureComputedStyle();
m_imageBuffer->setFilterQuality((style && (style->imageRendering() == ImageRenderingPixelated)) ? kNone_SkFilterQuality : kLow_SkFilterQuality);
m_didFailToCreateImageBuffer = false; m_didFailToCreateImageBuffer = false;
updateExternallyAllocatedMemory(); updateExternallyAllocatedMemory();
......
...@@ -193,7 +193,6 @@ private: ...@@ -193,7 +193,6 @@ private:
void parseAttribute(const QualifiedName&, const AtomicString&, const AtomicString&) override; void parseAttribute(const QualifiedName&, const AtomicString&, const AtomicString&) override;
LayoutObject* createLayoutObject(const ComputedStyle&) override; LayoutObject* createLayoutObject(const ComputedStyle&) override;
void didRecalcStyle(StyleRecalcChange) override;
bool areAuthorShadowsAllowed() const override { return false; } bool areAuthorShadowsAllowed() const override { return false; }
void reset(); void reset();
......
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