Chromium Code Reviews| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style) | 141 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style) |
| 142 { | 142 { |
| 143 LocalFrame* frame = document().frame(); | 143 LocalFrame* frame = document().frame(); |
| 144 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) | 144 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) |
| 145 return new RenderHTMLCanvas(this); | 145 return new RenderHTMLCanvas(this); |
| 146 return HTMLElement::createRenderer(style); | 146 return HTMLElement::createRenderer(style); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void HTMLCanvasElement::didRecalcStyle(StyleRecalcChange) | 149 void HTMLCanvasElement::didRecalcStyle(StyleRecalcChange) |
| 150 { | 150 { |
| 151 SkPaint::FilterLevel filterLevel = computedStyle()->imageRendering() == Imag eRenderingPixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel; | 151 bool pixelated = computedStyle()->imageRendering() == ImageRenderingPixelate d; |
| 152 SkPaint::FilterLevel filterLevel = pixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel; | |
| 152 if (m_context && m_context->is3d()) { | 153 if (m_context && m_context->is3d()) { |
| 153 toWebGLRenderingContext(m_context.get())->setFilterLevel(filterLevel); | 154 toWebGLRenderingContext(m_context.get())->setFilterLevel(filterLevel); |
| 154 setNeedsCompositingUpdate(); | 155 setNeedsCompositingUpdate(); |
| 155 } | 156 } |
| 157 if (hasImageBuffer()) { | |
| 158 m_imageBuffer->setFilterLevel(filterLevel); | |
| 159 m_imageBuffer->context()->setImageInterpolationQuality(pixelated ? Inter polationLow : 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
| |
| 160 } | |
| 156 } | 161 } |
| 157 | 162 |
| 158 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) | 163 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) |
| 159 { | 164 { |
| 160 setIsInCanvasSubtree(true); | 165 setIsInCanvasSubtree(true); |
| 161 return HTMLElement::insertedInto(node); | 166 return HTMLElement::insertedInto(node); |
| 162 } | 167 } |
| 163 | 168 |
| 164 void HTMLCanvasElement::addObserver(CanvasObserver* observer) | 169 void HTMLCanvasElement::addObserver(CanvasObserver* observer) |
| 165 { | 170 { |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 m_imageBufferIsClear = true; | 622 m_imageBufferIsClear = true; |
| 618 | 623 |
| 619 if (!canCreateImageBuffer(size())) | 624 if (!canCreateImageBuffer(size())) |
| 620 return; | 625 return; |
| 621 | 626 |
| 622 int msaaSampleCount; | 627 int msaaSampleCount; |
| 623 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS ampleCount); | 628 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS ampleCount); |
| 624 if (!surface->isValid()) | 629 if (!surface->isValid()) |
| 625 return; | 630 return; |
| 626 | 631 |
| 632 document().updateRenderTreeIfNeeded(); | |
| 633 RenderStyle* style = computedStyle(); | |
| 634 bool pixelated = style && (style->imageRendering() == ImageRenderingPixelate d || style->imageRendering() == ImageRenderingOptimizeContrast); | |
| 635 | |
| 627 m_imageBuffer = ImageBuffer::create(surface.release()); | 636 m_imageBuffer = ImageBuffer::create(surface.release()); |
| 628 m_imageBuffer->setClient(this); | 637 m_imageBuffer->setClient(this); |
| 638 m_imageBuffer->setFilterLevel(pixelated ? SkPaint::kNone_FilterLevel : SkPai nt::kLow_FilterLevel); | |
| 629 | 639 |
| 630 m_didFailToCreateImageBuffer = false; | 640 m_didFailToCreateImageBuffer = false; |
| 631 | 641 |
| 632 updateExternallyAllocatedMemory(); | 642 updateExternallyAllocatedMemory(); |
| 633 | 643 |
| 634 if (is3D()) { | 644 if (is3D()) { |
| 635 // Early out for WebGL canvases | 645 // Early out for WebGL canvases |
| 636 return; | 646 return; |
| 637 } | 647 } |
| 638 | 648 |
| 639 m_imageBuffer->setClient(this); | 649 m_imageBuffer->setClient(this); |
| 640 m_imageBuffer->context()->setShouldClampToSourceRect(false); | 650 m_imageBuffer->context()->setShouldClampToSourceRect(false); |
| 641 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages() ; | 651 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages() ; |
| 642 m_imageBuffer->context()->setImageInterpolationQuality(CanvasDefaultInterpol ationQuality); | 652 m_imageBuffer->context()->setImageInterpolationQuality(pixelated ? Interpola tionLow : CanvasDefaultInterpolationQuality); |
| 643 // Enabling MSAA overrides a request to disable antialiasing. This is true r egardless of whether the | 653 // Enabling MSAA overrides a request to disable antialiasing. This is true r egardless of whether the |
| 644 // rendering mode is accelerated or not. For consistency, we don't want to a pply AA in accelerated | 654 // rendering mode is accelerated or not. For consistency, we don't want to a pply AA in accelerated |
| 645 // canvases but not in unaccelerated canvases. | 655 // canvases but not in unaccelerated canvases. |
| 646 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled()) | 656 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled()) |
| 647 m_imageBuffer->context()->setShouldAntialias(false); | 657 m_imageBuffer->context()->setShouldAntialias(false); |
| 648 // GraphicsContext's defaults don't always agree with the 2d canvas spec. | 658 // GraphicsContext's defaults don't always agree with the 2d canvas spec. |
| 649 // See CanvasRenderingContext2D::State::State() for more information. | 659 // See CanvasRenderingContext2D::State::State() for more information. |
| 650 m_imageBuffer->context()->setMiterLimit(10); | 660 m_imageBuffer->context()->setMiterLimit(10); |
| 651 m_imageBuffer->context()->setStrokeThickness(1); | 661 m_imageBuffer->context()->setStrokeThickness(1); |
| 652 #if ENABLE(ASSERT) | 662 #if ENABLE(ASSERT) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 if (!isPaintable()) { | 816 if (!isPaintable()) { |
| 807 *status = InvalidSourceImageStatus; | 817 *status = InvalidSourceImageStatus; |
| 808 return nullptr; | 818 return nullptr; |
| 809 } | 819 } |
| 810 | 820 |
| 811 if (!m_context) { | 821 if (!m_context) { |
| 812 *status = NormalSourceImageStatus; | 822 *status = NormalSourceImageStatus; |
| 813 return createTransparentImage(size()); | 823 return createTransparentImage(size()); |
| 814 } | 824 } |
| 815 | 825 |
| 826 m_imageBuffer->willAccessPixels(); | |
| 827 | |
| 816 if (m_context->is3d()) { | 828 if (m_context->is3d()) { |
| 817 m_context->paintRenderingResultsToCanvas(BackBuffer); | 829 m_context->paintRenderingResultsToCanvas(BackBuffer); |
| 818 *status = ExternalSourceImageStatus; | 830 *status = ExternalSourceImageStatus; |
| 819 | 831 |
| 820 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi tmap) | 832 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi tmap) |
| 821 return buffer()->copyImage(DontCopyBackingStore, Unscaled); | 833 return buffer()->copyImage(DontCopyBackingStore, Unscaled); |
| 822 } | 834 } |
| 823 | 835 |
| 824 RefPtr<SkImage> image = buffer()->newImageSnapshot(); | 836 RefPtr<SkImage> image = buffer()->newImageSnapshot(); |
| 825 if (image) { | 837 if (image) { |
| 826 *status = NormalSourceImageStatus; | 838 *status = NormalSourceImageStatus; |
| 827 return StaticBitmapImage::create(image.release()); | 839 return StaticBitmapImage::create(image.release()); |
| 828 } | 840 } |
| 829 | 841 |
| 830 *status = InvalidSourceImageStatus; | 842 *status = InvalidSourceImageStatus; |
| 831 return nullptr; | 843 return nullptr; |
| 832 } | 844 } |
| 833 | 845 |
| 834 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const | 846 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const |
| 835 { | 847 { |
| 836 return !originClean(); | 848 return !originClean(); |
| 837 } | 849 } |
| 838 | 850 |
| 839 FloatSize HTMLCanvasElement::sourceSize() const | 851 FloatSize HTMLCanvasElement::sourceSize() const |
| 840 { | 852 { |
| 841 return FloatSize(width(), height()); | 853 return FloatSize(width(), height()); |
| 842 } | 854 } |
| 843 | 855 |
| 844 } | 856 } |
| OLD | NEW |