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

Side by Side 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: #include NodeRenderStyle.h 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 16 matching lines...) Expand all
27 27
28 #include "config.h" 28 #include "config.h"
29 #include "core/html/HTMLCanvasElement.h" 29 #include "core/html/HTMLCanvasElement.h"
30 30
31 #include "bindings/core/v8/ExceptionMessages.h" 31 #include "bindings/core/v8/ExceptionMessages.h"
32 #include "bindings/core/v8/ExceptionState.h" 32 #include "bindings/core/v8/ExceptionState.h"
33 #include "bindings/core/v8/ScriptController.h" 33 #include "bindings/core/v8/ScriptController.h"
34 #include "core/HTMLNames.h" 34 #include "core/HTMLNames.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 #include "core/dom/NodeRenderStyle.h"
37 #include "core/frame/LocalFrame.h" 38 #include "core/frame/LocalFrame.h"
38 #include "core/frame/Settings.h" 39 #include "core/frame/Settings.h"
39 #include "core/html/ImageData.h" 40 #include "core/html/ImageData.h"
40 #include "core/html/canvas/Canvas2DContextAttributes.h" 41 #include "core/html/canvas/Canvas2DContextAttributes.h"
41 #include "core/html/canvas/CanvasRenderingContext2D.h" 42 #include "core/html/canvas/CanvasRenderingContext2D.h"
42 #include "core/html/canvas/WebGLContextAttributes.h" 43 #include "core/html/canvas/WebGLContextAttributes.h"
43 #include "core/html/canvas/WebGLContextEvent.h" 44 #include "core/html/canvas/WebGLContextEvent.h"
44 #include "core/html/canvas/WebGLRenderingContext.h" 45 #include "core/html/canvas/WebGLRenderingContext.h"
45 #include "core/rendering/RenderHTMLCanvas.h" 46 #include "core/rendering/RenderHTMLCanvas.h"
46 #include "core/rendering/RenderLayer.h" 47 #include "core/rendering/RenderLayer.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 : HTMLElement(canvasTag, document) 106 : HTMLElement(canvasTag, document)
106 , DocumentVisibilityObserver(document) 107 , DocumentVisibilityObserver(document)
107 , m_size(DefaultWidth, DefaultHeight) 108 , m_size(DefaultWidth, DefaultHeight)
108 , m_ignoreReset(false) 109 , m_ignoreReset(false)
109 , m_accelerationDisabled(false) 110 , m_accelerationDisabled(false)
110 , m_externallyAllocatedMemory(0) 111 , m_externallyAllocatedMemory(0)
111 , m_originClean(true) 112 , m_originClean(true)
112 , m_didFailToCreateImageBuffer(false) 113 , m_didFailToCreateImageBuffer(false)
113 , m_imageBufferIsClear(false) 114 , m_imageBufferIsClear(false)
114 { 115 {
116 setHasCustomStyleCallbacks();
115 } 117 }
116 118
117 DEFINE_NODE_FACTORY(HTMLCanvasElement) 119 DEFINE_NODE_FACTORY(HTMLCanvasElement)
118 120
119 HTMLCanvasElement::~HTMLCanvasElement() 121 HTMLCanvasElement::~HTMLCanvasElement()
120 { 122 {
121 resetDirtyRect(); 123 resetDirtyRect();
122 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory); 124 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory);
123 #if !ENABLE(OILPAN) 125 #if !ENABLE(OILPAN)
124 for (CanvasObserver* canvasObserver : m_observers) 126 for (CanvasObserver* canvasObserver : m_observers)
125 canvasObserver->canvasDestroyed(this); 127 canvasObserver->canvasDestroyed(this);
126 // Ensure these go away before the ImageBuffer. 128 // Ensure these go away before the ImageBuffer.
127 m_contextStateSaver.clear(); 129 m_contextStateSaver.clear();
128 m_context.clear(); 130 m_context.clear();
129 #endif 131 #endif
130 } 132 }
131 133
132 void HTMLCanvasElement::parseAttribute(const QualifiedName& name, const AtomicSt ring& value) 134 void HTMLCanvasElement::parseAttribute(const QualifiedName& name, const AtomicSt ring& value)
133 { 135 {
134 if (name == widthAttr || name == heightAttr) 136 if (name == widthAttr || name == heightAttr)
135 reset(); 137 reset();
136 HTMLElement::parseAttribute(name, value); 138 HTMLElement::parseAttribute(name, value);
137 } 139 }
138 140
139 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style) 141 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style)
140 { 142 {
143 if (hasImageBuffer())
144 m_imageBuffer->setFilterLevel(style->imageRendering() == ImageRenderingP ixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel);
141 LocalFrame* frame = document().frame(); 145 LocalFrame* frame = document().frame();
142 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) 146 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript))
143 return new RenderHTMLCanvas(this); 147 return new RenderHTMLCanvas(this);
144 return HTMLElement::createRenderer(style); 148 return HTMLElement::createRenderer(style);
145 } 149 }
146 150
151 void HTMLCanvasElement::didRecalcStyle(StyleRecalcChange)
152 {
153 if (!hasImageBuffer())
154 return;
155 m_imageBuffer->setFilterLevel(renderStyle()->imageRendering() == ImageRender ingPixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel);
Justin Novosad 2014/12/04 15:27:07 This seems wrong to me. We should always use the c
jackhou1 2014/12/05 02:00:58 Done.
156 }
157
147 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) 158 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node)
148 { 159 {
149 setIsInCanvasSubtree(true); 160 setIsInCanvasSubtree(true);
150 return HTMLElement::insertedInto(node); 161 return HTMLElement::insertedInto(node);
151 } 162 }
152 163
153 void HTMLCanvasElement::addObserver(CanvasObserver* observer) 164 void HTMLCanvasElement::addObserver(CanvasObserver* observer)
154 { 165 {
155 m_observers.add(observer); 166 m_observers.add(observer);
156 } 167 }
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 m_imageBufferIsClear = true; 597 m_imageBufferIsClear = true;
587 598
588 if (!canCreateImageBuffer(size())) 599 if (!canCreateImageBuffer(size()))
589 return; 600 return;
590 601
591 int msaaSampleCount; 602 int msaaSampleCount;
592 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS ampleCount); 603 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS ampleCount);
593 if (!surface->isValid()) 604 if (!surface->isValid())
594 return; 605 return;
595 606
607 RenderStyle* style = renderStyle();
Justin Novosad 2014/12/04 15:27:07 Same thing here
jackhou1 2014/12/05 02:00:58 Done.
608 bool pixelated = style && (style->imageRendering() == ImageRenderingPixelate d || style->imageRendering() == ImageRenderingOptimizeContrast);
609
596 m_imageBuffer = ImageBuffer::create(surface.release()); 610 m_imageBuffer = ImageBuffer::create(surface.release());
597 m_imageBuffer->setClient(this); 611 m_imageBuffer->setClient(this);
612 m_imageBuffer->setFilterLevel(pixelated ? SkPaint::kNone_FilterLevel : SkPai nt::kLow_FilterLevel);
598 613
599 m_didFailToCreateImageBuffer = false; 614 m_didFailToCreateImageBuffer = false;
600 615
601 updateExternallyAllocatedMemory(); 616 updateExternallyAllocatedMemory();
602 617
603 if (is3D()) { 618 if (is3D()) {
604 // Early out for WebGL canvases 619 // Early out for WebGL canvases
605 return; 620 return;
606 } 621 }
607 622
608 m_imageBuffer->setClient(this); 623 m_imageBuffer->setClient(this);
609 m_imageBuffer->context()->setShouldClampToSourceRect(false); 624 m_imageBuffer->context()->setShouldClampToSourceRect(false);
610 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages() ; 625 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages() ;
611 m_imageBuffer->context()->setImageInterpolationQuality(CanvasDefaultInterpol ationQuality); 626 m_imageBuffer->context()->setImageInterpolationQuality(pixelated ? Interpola tionLow : CanvasDefaultInterpolationQuality);
612 // Enabling MSAA overrides a request to disable antialiasing. This is true r egardless of whether the 627 // Enabling MSAA overrides a request to disable antialiasing. This is true r egardless of whether the
613 // rendering mode is accelerated or not. For consistency, we don't want to a pply AA in accelerated 628 // rendering mode is accelerated or not. For consistency, we don't want to a pply AA in accelerated
614 // canvases but not in unaccelerated canvases. 629 // canvases but not in unaccelerated canvases.
615 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled()) 630 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled())
616 m_imageBuffer->context()->setShouldAntialias(false); 631 m_imageBuffer->context()->setShouldAntialias(false);
617 // GraphicsContext's defaults don't always agree with the 2d canvas spec. 632 // GraphicsContext's defaults don't always agree with the 2d canvas spec.
618 // See CanvasRenderingContext2D::State::State() for more information. 633 // See CanvasRenderingContext2D::State::State() for more information.
619 m_imageBuffer->context()->setMiterLimit(10); 634 m_imageBuffer->context()->setMiterLimit(10);
620 m_imageBuffer->context()->setStrokeThickness(1); 635 m_imageBuffer->context()->setStrokeThickness(1);
621 #if ENABLE(ASSERT) 636 #if ENABLE(ASSERT)
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 if (!isPaintable()) { 787 if (!isPaintable()) {
773 *status = InvalidSourceImageStatus; 788 *status = InvalidSourceImageStatus;
774 return nullptr; 789 return nullptr;
775 } 790 }
776 791
777 if (!m_context) { 792 if (!m_context) {
778 *status = NormalSourceImageStatus; 793 *status = NormalSourceImageStatus;
779 return createTransparentImage(size()); 794 return createTransparentImage(size());
780 } 795 }
781 796
797 m_imageBuffer->willAccessPixels();
798
782 if (m_context->is3d()) { 799 if (m_context->is3d()) {
783 m_context->paintRenderingResultsToCanvas(BackBuffer); 800 m_context->paintRenderingResultsToCanvas(BackBuffer);
784 *status = ExternalSourceImageStatus; 801 *status = ExternalSourceImageStatus;
785 802
786 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi tmap) 803 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi tmap)
787 return buffer()->copyImage(DontCopyBackingStore, Unscaled); 804 return buffer()->copyImage(DontCopyBackingStore, Unscaled);
788 } 805 }
789 806
790 RefPtr<SkImage> image = buffer()->newImageSnapshot(); 807 RefPtr<SkImage> image = buffer()->newImageSnapshot();
791 if (image) { 808 if (image) {
792 *status = NormalSourceImageStatus; 809 *status = NormalSourceImageStatus;
793 return StaticBitmapImage::create(image.release()); 810 return StaticBitmapImage::create(image.release());
794 } 811 }
795 812
796 *status = InvalidSourceImageStatus; 813 *status = InvalidSourceImageStatus;
797 return nullptr; 814 return nullptr;
798 } 815 }
799 816
800 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const 817 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const
801 { 818 {
802 return !originClean(); 819 return !originClean();
803 } 820 }
804 821
805 FloatSize HTMLCanvasElement::sourceSize() const 822 FloatSize HTMLCanvasElement::sourceSize() const
806 { 823 {
807 return FloatSize(width(), height()); 824 return FloatSize(width(), height());
808 } 825 }
809 826
810 } 827 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698