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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 SkPaint::FilterLevel filterLevel = computedStyle()->imageRendering() == Imag eRenderingPixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel; |
152 if (m_context && m_context->is3d()) { | 152 if (m_context && m_context->is3d()) { |
153 toWebGLRenderingContext(m_context.get())->setFilterLevel(filterLevel); | 153 toWebGLRenderingContext(m_context.get())->setFilterLevel(filterLevel); |
154 setNeedsCompositingUpdate(); | 154 setNeedsCompositingUpdate(); |
155 } | 155 } |
156 if (hasImageBuffer()) | |
157 m_imageBuffer->setFilterLevel(filterLevel); | |
156 } | 158 } |
157 | 159 |
158 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) | 160 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) |
159 { | 161 { |
160 setIsInCanvasSubtree(true); | 162 setIsInCanvasSubtree(true); |
161 return HTMLElement::insertedInto(node); | 163 return HTMLElement::insertedInto(node); |
162 } | 164 } |
163 | 165 |
164 void HTMLCanvasElement::addObserver(CanvasObserver* observer) | 166 void HTMLCanvasElement::addObserver(CanvasObserver* observer) |
165 { | 167 { |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 m_imageBufferIsClear = true; | 619 m_imageBufferIsClear = true; |
618 | 620 |
619 if (!canCreateImageBuffer(size())) | 621 if (!canCreateImageBuffer(size())) |
620 return; | 622 return; |
621 | 623 |
622 int msaaSampleCount; | 624 int msaaSampleCount; |
623 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS ampleCount); | 625 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS ampleCount); |
624 if (!surface->isValid()) | 626 if (!surface->isValid()) |
625 return; | 627 return; |
626 | 628 |
629 document().updateRenderTreeIfNeeded(); | |
630 RenderStyle* style = computedStyle(); | |
631 bool pixelated = style && (style->imageRendering() == ImageRenderingPixelate d || style->imageRendering() == ImageRenderingOptimizeContrast); | |
632 | |
627 m_imageBuffer = ImageBuffer::create(surface.release()); | 633 m_imageBuffer = ImageBuffer::create(surface.release()); |
628 m_imageBuffer->setClient(this); | 634 m_imageBuffer->setClient(this); |
635 m_imageBuffer->setFilterLevel(pixelated ? SkPaint::kNone_FilterLevel : SkPai nt::kLow_FilterLevel); | |
esprehn
2014/12/16 19:22:32
You don't need this line or the bool pixelated or
jackhou1
2014/12/17 01:28:09
This is what I tried earlier but it didn't work. I
| |
629 | 636 |
630 m_didFailToCreateImageBuffer = false; | 637 m_didFailToCreateImageBuffer = false; |
631 | 638 |
632 updateExternallyAllocatedMemory(); | 639 updateExternallyAllocatedMemory(); |
633 | 640 |
634 if (is3D()) { | 641 if (is3D()) { |
635 // Early out for WebGL canvases | 642 // Early out for WebGL canvases |
636 return; | 643 return; |
637 } | 644 } |
638 | 645 |
639 m_imageBuffer->setClient(this); | 646 m_imageBuffer->setClient(this); |
640 m_imageBuffer->context()->setShouldClampToSourceRect(false); | 647 m_imageBuffer->context()->setShouldClampToSourceRect(false); |
641 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages() ; | 648 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages() ; |
642 m_imageBuffer->context()->setImageInterpolationQuality(CanvasDefaultInterpol ationQuality); | 649 m_imageBuffer->context()->setImageInterpolationQuality(pixelated ? Interpola tionLow : CanvasDefaultInterpolationQuality); |
esprehn
2014/12/16 19:22:32
Doesn't this need to be dynamically updated in wil
jackhou1
2014/12/17 01:28:09
Done.
| |
643 // Enabling MSAA overrides a request to disable antialiasing. This is true r egardless of whether the | 650 // 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 | 651 // 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. | 652 // canvases but not in unaccelerated canvases. |
646 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled()) | 653 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled()) |
647 m_imageBuffer->context()->setShouldAntialias(false); | 654 m_imageBuffer->context()->setShouldAntialias(false); |
648 // GraphicsContext's defaults don't always agree with the 2d canvas spec. | 655 // GraphicsContext's defaults don't always agree with the 2d canvas spec. |
649 // See CanvasRenderingContext2D::State::State() for more information. | 656 // See CanvasRenderingContext2D::State::State() for more information. |
650 m_imageBuffer->context()->setMiterLimit(10); | 657 m_imageBuffer->context()->setMiterLimit(10); |
651 m_imageBuffer->context()->setStrokeThickness(1); | 658 m_imageBuffer->context()->setStrokeThickness(1); |
652 #if ENABLE(ASSERT) | 659 #if ENABLE(ASSERT) |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
803 if (!isPaintable()) { | 810 if (!isPaintable()) { |
804 *status = InvalidSourceImageStatus; | 811 *status = InvalidSourceImageStatus; |
805 return nullptr; | 812 return nullptr; |
806 } | 813 } |
807 | 814 |
808 if (!m_context) { | 815 if (!m_context) { |
809 *status = NormalSourceImageStatus; | 816 *status = NormalSourceImageStatus; |
810 return createTransparentImage(size()); | 817 return createTransparentImage(size()); |
811 } | 818 } |
812 | 819 |
820 m_imageBuffer->willAccessPixels(); | |
821 | |
813 if (m_context->is3d()) { | 822 if (m_context->is3d()) { |
814 m_context->paintRenderingResultsToCanvas(BackBuffer); | 823 m_context->paintRenderingResultsToCanvas(BackBuffer); |
815 *status = ExternalSourceImageStatus; | 824 *status = ExternalSourceImageStatus; |
816 | 825 |
817 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi tmap) | 826 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi tmap) |
818 return buffer()->copyImage(DontCopyBackingStore, Unscaled); | 827 return buffer()->copyImage(DontCopyBackingStore, Unscaled); |
819 } | 828 } |
820 | 829 |
821 RefPtr<SkImage> image = buffer()->newImageSnapshot(); | 830 RefPtr<SkImage> image = buffer()->newImageSnapshot(); |
822 if (image) { | 831 if (image) { |
823 *status = NormalSourceImageStatus; | 832 *status = NormalSourceImageStatus; |
824 return StaticBitmapImage::create(image.release()); | 833 return StaticBitmapImage::create(image.release()); |
825 } | 834 } |
826 | 835 |
827 *status = InvalidSourceImageStatus; | 836 *status = InvalidSourceImageStatus; |
828 return nullptr; | 837 return nullptr; |
829 } | 838 } |
830 | 839 |
831 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const | 840 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const |
832 { | 841 { |
833 return !originClean(); | 842 return !originClean(); |
834 } | 843 } |
835 | 844 |
836 FloatSize HTMLCanvasElement::sourceSize() const | 845 FloatSize HTMLCanvasElement::sourceSize() const |
837 { | 846 { |
838 return FloatSize(width(), height()); | 847 return FloatSize(width(), height()); |
839 } | 848 } |
840 | 849 |
841 } | 850 } |
OLD | NEW |