OLD | NEW |
---|---|
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 : HTMLElement(canvasTag, document) | 105 : HTMLElement(canvasTag, document) |
106 , DocumentVisibilityObserver(document) | 106 , DocumentVisibilityObserver(document) |
107 , m_size(DefaultWidth, DefaultHeight) | 107 , m_size(DefaultWidth, DefaultHeight) |
108 , m_ignoreReset(false) | 108 , m_ignoreReset(false) |
109 , m_accelerationDisabled(false) | 109 , m_accelerationDisabled(false) |
110 , m_externallyAllocatedMemory(0) | 110 , m_externallyAllocatedMemory(0) |
111 , m_originClean(true) | 111 , m_originClean(true) |
112 , m_didFailToCreateImageBuffer(false) | 112 , m_didFailToCreateImageBuffer(false) |
113 , m_imageBufferIsClear(false) | 113 , m_imageBufferIsClear(false) |
114 { | 114 { |
115 setHasCustomStyleCallbacks(); | |
115 } | 116 } |
116 | 117 |
117 DEFINE_NODE_FACTORY(HTMLCanvasElement) | 118 DEFINE_NODE_FACTORY(HTMLCanvasElement) |
118 | 119 |
119 HTMLCanvasElement::~HTMLCanvasElement() | 120 HTMLCanvasElement::~HTMLCanvasElement() |
120 { | 121 { |
121 resetDirtyRect(); | 122 resetDirtyRect(); |
122 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory); | 123 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory); |
123 #if !ENABLE(OILPAN) | 124 #if !ENABLE(OILPAN) |
124 for (CanvasObserver* canvasObserver : m_observers) | 125 for (CanvasObserver* canvasObserver : m_observers) |
125 canvasObserver->canvasDestroyed(this); | 126 canvasObserver->canvasDestroyed(this); |
126 // Ensure these go away before the ImageBuffer. | 127 // Ensure these go away before the ImageBuffer. |
127 m_contextStateSaver.clear(); | 128 m_contextStateSaver.clear(); |
128 m_context.clear(); | 129 m_context.clear(); |
129 #endif | 130 #endif |
130 } | 131 } |
131 | 132 |
132 void HTMLCanvasElement::parseAttribute(const QualifiedName& name, const AtomicSt ring& value) | 133 void HTMLCanvasElement::parseAttribute(const QualifiedName& name, const AtomicSt ring& value) |
133 { | 134 { |
134 if (name == widthAttr || name == heightAttr) | 135 if (name == widthAttr || name == heightAttr) |
135 reset(); | 136 reset(); |
136 HTMLElement::parseAttribute(name, value); | 137 HTMLElement::parseAttribute(name, value); |
137 } | 138 } |
138 | 139 |
139 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style) | 140 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style) |
140 { | 141 { |
142 if (hasImageBuffer()) | |
143 m_imageBuffer->setFilterLevel(style->imageRendering() == ImageRenderingP ixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel); | |
esprehn
2014/12/15 20:24:51
If you have code in ::didRecalcStyle, you shouldn'
jackhou1
2014/12/15 23:17:24
Done.
This was added for the case where a canvas
| |
141 LocalFrame* frame = document().frame(); | 144 LocalFrame* frame = document().frame(); |
142 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) | 145 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) |
143 return new RenderHTMLCanvas(this); | 146 return new RenderHTMLCanvas(this); |
144 return HTMLElement::createRenderer(style); | 147 return HTMLElement::createRenderer(style); |
145 } | 148 } |
146 | 149 |
150 void HTMLCanvasElement::didRecalcStyle(StyleRecalcChange) | |
151 { | |
152 if (!hasImageBuffer()) | |
153 return; | |
154 m_imageBuffer->setFilterLevel(computedStyle()->imageRendering() == ImageRend eringPixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel); | |
155 } | |
156 | |
147 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) | 157 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) |
148 { | 158 { |
149 setIsInCanvasSubtree(true); | 159 setIsInCanvasSubtree(true); |
150 return HTMLElement::insertedInto(node); | 160 return HTMLElement::insertedInto(node); |
151 } | 161 } |
152 | 162 |
153 void HTMLCanvasElement::addObserver(CanvasObserver* observer) | 163 void HTMLCanvasElement::addObserver(CanvasObserver* observer) |
154 { | 164 { |
155 m_observers.add(observer); | 165 m_observers.add(observer); |
156 } | 166 } |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 m_imageBufferIsClear = true; | 596 m_imageBufferIsClear = true; |
587 | 597 |
588 if (!canCreateImageBuffer(size())) | 598 if (!canCreateImageBuffer(size())) |
589 return; | 599 return; |
590 | 600 |
591 int msaaSampleCount; | 601 int msaaSampleCount; |
592 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS ampleCount); | 602 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS ampleCount); |
593 if (!surface->isValid()) | 603 if (!surface->isValid()) |
594 return; | 604 return; |
595 | 605 |
606 document().updateRenderTreeIfNeeded(); | |
607 RenderStyle* style = computedStyle(); | |
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); | |
esprehn
2014/12/15 20:24:51
Why can't this just wait until didRecalcStyle to r
jackhou1
2014/12/15 23:17:24
It doesn't seem like didRecalcStyle will always ru
| |
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 Loading... | |
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 } |
OLD | NEW |