Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(994)

Unified Diff: Source/core/html/HTMLCanvasElement.cpp

Issue 562583002: Implement image-rendering:pixelated for accelerated 2D canvases. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Sync and rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/HTMLCanvasElement.cpp
diff --git a/Source/core/html/HTMLCanvasElement.cpp b/Source/core/html/HTMLCanvasElement.cpp
index 08bbb9b8ed8e510a2487914d4857ad8a741af137..b025c5c2b0f8108122a51cad95ed1e3b3179689f 100644
--- a/Source/core/html/HTMLCanvasElement.cpp
+++ b/Source/core/html/HTMLCanvasElement.cpp
@@ -148,11 +148,16 @@ RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style)
void HTMLCanvasElement::didRecalcStyle(StyleRecalcChange)
{
- SkPaint::FilterLevel filterLevel = computedStyle()->imageRendering() == ImageRenderingPixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel;
+ bool pixelated = computedStyle()->imageRendering() == ImageRenderingPixelated;
+ SkPaint::FilterLevel filterLevel = pixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel;
if (m_context && m_context->is3d()) {
toWebGLRenderingContext(m_context.get())->setFilterLevel(filterLevel);
setNeedsCompositingUpdate();
}
+ if (hasImageBuffer()) {
+ m_imageBuffer->setFilterLevel(filterLevel);
+ m_imageBuffer->context()->setImageInterpolationQuality(pixelated ? InterpolationLow : CanvasDefaultInterpolationQuality);
esprehn 2014/12/17 23:05:19 Did you add a test that this dynamically updates?
jackhou1 2014/12/18 03:48:07 I have layout tests that cover changing the CSS pr
+ }
}
Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode* node)
@@ -624,8 +629,13 @@ void HTMLCanvasElement::createImageBufferInternal()
if (!surface->isValid())
return;
+ document().updateRenderTreeIfNeeded();
+ RenderStyle* style = computedStyle();
+ bool pixelated = style && (style->imageRendering() == ImageRenderingPixelated || style->imageRendering() == ImageRenderingOptimizeContrast);
+
m_imageBuffer = ImageBuffer::create(surface.release());
m_imageBuffer->setClient(this);
+ m_imageBuffer->setFilterLevel(pixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel);
m_didFailToCreateImageBuffer = false;
@@ -639,7 +649,7 @@ void HTMLCanvasElement::createImageBufferInternal()
m_imageBuffer->setClient(this);
m_imageBuffer->context()->setShouldClampToSourceRect(false);
m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages();
- m_imageBuffer->context()->setImageInterpolationQuality(CanvasDefaultInterpolationQuality);
+ m_imageBuffer->context()->setImageInterpolationQuality(pixelated ? InterpolationLow : CanvasDefaultInterpolationQuality);
// Enabling MSAA overrides a request to disable antialiasing. This is true regardless of whether the
// rendering mode is accelerated or not. For consistency, we don't want to apply AA in accelerated
// canvases but not in unaccelerated canvases.
@@ -813,6 +823,8 @@ PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(SourceImageMode mod
return createTransparentImage(size());
}
+ m_imageBuffer->willAccessPixels();
+
if (m_context->is3d()) {
m_context->paintRenderingResultsToCanvas(BackBuffer);
*status = ExternalSourceImageStatus;
« no previous file with comments | « LayoutTests/virtual/gpu/fast/canvas/pixelated-expected.txt ('k') | Source/platform/graphics/Canvas2DImageBufferSurface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698