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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 : HTMLElement(canvasTag, document) | 95 : HTMLElement(canvasTag, document) |
96 , DocumentVisibilityObserver(document) | 96 , DocumentVisibilityObserver(document) |
97 , m_size(DefaultWidth, DefaultHeight) | 97 , m_size(DefaultWidth, DefaultHeight) |
98 , m_ignoreReset(false) | 98 , m_ignoreReset(false) |
99 , m_accelerationDisabled(false) | 99 , m_accelerationDisabled(false) |
100 , m_externallyAllocatedMemory(0) | 100 , m_externallyAllocatedMemory(0) |
101 , m_originClean(true) | 101 , m_originClean(true) |
102 , m_didFailToCreateImageBuffer(false) | 102 , m_didFailToCreateImageBuffer(false) |
103 , m_imageBufferIsClear(false) | 103 , m_imageBufferIsClear(false) |
104 { | 104 { |
| 105 setHasCustomStyleCallbacks(); |
105 } | 106 } |
106 | 107 |
107 DEFINE_NODE_FACTORY(HTMLCanvasElement) | 108 DEFINE_NODE_FACTORY(HTMLCanvasElement) |
108 | 109 |
109 HTMLCanvasElement::~HTMLCanvasElement() | 110 HTMLCanvasElement::~HTMLCanvasElement() |
110 { | 111 { |
111 resetDirtyRect(); | 112 resetDirtyRect(); |
112 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external
lyAllocatedMemory); | 113 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external
lyAllocatedMemory); |
113 #if !ENABLE(OILPAN) | 114 #if !ENABLE(OILPAN) |
114 for (CanvasObserver* canvasObserver : m_observers) | 115 for (CanvasObserver* canvasObserver : m_observers) |
(...skipping 12 matching lines...) Expand all Loading... |
127 } | 128 } |
128 | 129 |
129 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style) | 130 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style) |
130 { | 131 { |
131 LocalFrame* frame = document().frame(); | 132 LocalFrame* frame = document().frame(); |
132 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) | 133 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) |
133 return new RenderHTMLCanvas(this); | 134 return new RenderHTMLCanvas(this); |
134 return HTMLElement::createRenderer(style); | 135 return HTMLElement::createRenderer(style); |
135 } | 136 } |
136 | 137 |
| 138 void HTMLCanvasElement::didRecalcStyle(StyleRecalcChange) |
| 139 { |
| 140 if (!hasImageBuffer()) |
| 141 return; |
| 142 m_imageBuffer->setFilterLevel(computedStyle()->imageRendering() == ImageRend
eringPixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel); |
| 143 } |
| 144 |
137 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode
* node) | 145 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode
* node) |
138 { | 146 { |
139 setIsInCanvasSubtree(true); | 147 setIsInCanvasSubtree(true); |
140 return HTMLElement::insertedInto(node); | 148 return HTMLElement::insertedInto(node); |
141 } | 149 } |
142 | 150 |
143 void HTMLCanvasElement::addObserver(CanvasObserver* observer) | 151 void HTMLCanvasElement::addObserver(CanvasObserver* observer) |
144 { | 152 { |
145 m_observers.add(observer); | 153 m_observers.add(observer); |
146 } | 154 } |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 if (!canCreateImageBuffer(size())) | 578 if (!canCreateImageBuffer(size())) |
571 return; | 579 return; |
572 | 580 |
573 int msaaSampleCount; | 581 int msaaSampleCount; |
574 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS
ampleCount); | 582 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(size(), &msaaS
ampleCount); |
575 if (!surface->isValid()) | 583 if (!surface->isValid()) |
576 return; | 584 return; |
577 | 585 |
578 m_imageBuffer = ImageBuffer::create(surface.release()); | 586 m_imageBuffer = ImageBuffer::create(surface.release()); |
579 m_imageBuffer->setClient(this); | 587 m_imageBuffer->setClient(this); |
| 588 m_imageBuffer->setFilterLevel(computedStyle()->imageRendering() == ImageRend
eringPixelated ? SkPaint::kNone_FilterLevel : SkPaint::kLow_FilterLevel); |
580 | 589 |
581 m_didFailToCreateImageBuffer = false; | 590 m_didFailToCreateImageBuffer = false; |
582 | 591 |
583 updateExternallyAllocatedMemory(); | 592 updateExternallyAllocatedMemory(); |
584 | 593 |
585 if (is3D()) { | 594 if (is3D()) { |
586 // Early out for WebGL canvases | 595 // Early out for WebGL canvases |
587 return; | 596 return; |
588 } | 597 } |
589 | 598 |
590 m_imageBuffer->setClient(this); | 599 m_imageBuffer->setClient(this); |
591 m_imageBuffer->context()->setShouldClampToSourceRect(false); | 600 m_imageBuffer->context()->setShouldClampToSourceRect(false); |
592 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages()
; | 601 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages()
; |
593 m_imageBuffer->context()->setImageInterpolationQuality(CanvasDefaultInterpol
ationQuality); | 602 m_imageBuffer->context()->setImageInterpolationQuality(computedStyle()->imag
eRendering() == ImageRenderingOptimizeContrast ? InterpolationLow : CanvasDefaul
tInterpolationQuality); |
594 // Enabling MSAA overrides a request to disable antialiasing. This is true r
egardless of whether the | 603 // Enabling MSAA overrides a request to disable antialiasing. This is true r
egardless of whether the |
595 // rendering mode is accelerated or not. For consistency, we don't want to a
pply AA in accelerated | 604 // rendering mode is accelerated or not. For consistency, we don't want to a
pply AA in accelerated |
596 // canvases but not in unaccelerated canvases. | 605 // canvases but not in unaccelerated canvases. |
597 if (!msaaSampleCount && document().settings() && !document().settings()->ant
ialiased2dCanvasEnabled()) | 606 if (!msaaSampleCount && document().settings() && !document().settings()->ant
ialiased2dCanvasEnabled()) |
598 m_imageBuffer->context()->setShouldAntialias(false); | 607 m_imageBuffer->context()->setShouldAntialias(false); |
599 // GraphicsContext's defaults don't always agree with the 2d canvas spec. | 608 // GraphicsContext's defaults don't always agree with the 2d canvas spec. |
600 // See CanvasRenderingContext2D::State::State() for more information. | 609 // See CanvasRenderingContext2D::State::State() for more information. |
601 m_imageBuffer->context()->setMiterLimit(10); | 610 m_imageBuffer->context()->setMiterLimit(10); |
602 m_imageBuffer->context()->setStrokeThickness(1); | 611 m_imageBuffer->context()->setStrokeThickness(1); |
603 #if ENABLE(ASSERT) | 612 #if ENABLE(ASSERT) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 if (!width() || !height()) { | 751 if (!width() || !height()) { |
743 *status = ZeroSizeCanvasSourceImageStatus; | 752 *status = ZeroSizeCanvasSourceImageStatus; |
744 return nullptr; | 753 return nullptr; |
745 } | 754 } |
746 | 755 |
747 if (!buffer()) { | 756 if (!buffer()) { |
748 *status = InvalidSourceImageStatus; | 757 *status = InvalidSourceImageStatus; |
749 return nullptr; | 758 return nullptr; |
750 } | 759 } |
751 | 760 |
| 761 m_imageBuffer->willAccessPixels(); |
| 762 |
752 if (m_context && m_context->is3d()) { | 763 if (m_context && m_context->is3d()) { |
753 m_context->paintRenderingResultsToCanvas(BackBuffer); | 764 m_context->paintRenderingResultsToCanvas(BackBuffer); |
754 *status = ExternalSourceImageStatus; | 765 *status = ExternalSourceImageStatus; |
755 | 766 |
756 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi
tmap) | 767 // can't create SkImage from WebGLImageBufferSurface (contains only SkBi
tmap) |
757 return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled); | 768 return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled); |
758 } | 769 } |
759 | 770 |
760 RefPtr<SkImage> image = m_imageBuffer->newImageSnapshot(); | 771 RefPtr<SkImage> image = m_imageBuffer->newImageSnapshot(); |
761 if (image) { | 772 if (image) { |
(...skipping 12 matching lines...) Expand all Loading... |
774 { | 785 { |
775 return !originClean(); | 786 return !originClean(); |
776 } | 787 } |
777 | 788 |
778 FloatSize HTMLCanvasElement::sourceSize() const | 789 FloatSize HTMLCanvasElement::sourceSize() const |
779 { | 790 { |
780 return FloatSize(width(), height()); | 791 return FloatSize(width(), height()); |
781 } | 792 } |
782 | 793 |
783 } | 794 } |
OLD | NEW |