2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "core/html/HTMLCanvasElement.h"
31 #include "bindings/core/v8/ExceptionMessages.h"
32 #include "bindings/core/v8/ExceptionState.h"
33 #include "bindings/core/v8/ScriptController.h"
34 #include "core/HTMLNames.h"
35 #include "core/dom/Document.h"
36 #include "core/dom/ExceptionCode.h"
37 #include "core/frame/LocalFrame.h"
38 #include "core/frame/Settings.h"
39 #include "core/html/ImageData.h"
40 #include "core/html/canvas/Canvas2DContextAttributes.h"
41 #include "core/html/canvas/CanvasRenderingContext2D.h"
42 #include "core/html/canvas/WebGLContextAttributes.h"
43 #include "core/html/canvas/WebGLContextEvent.h"
44 #include "core/html/canvas/WebGLRenderingContext.h"
45 #include "core/rendering/RenderHTMLCanvas.h"
46 #include "platform/MIMETypeRegistry.h"
47 #include "platform/RuntimeEnabledFeatures.h"
48 #include "platform/graphics/Canvas2DImageBufferSurface.h"
49 #include "platform/graphics/GraphicsContextStateSaver.h"
50 #include "platform/graphics/ImageBuffer.h"
51 #include "platform/graphics/RecordingImageBufferSurface.h"
52 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
53 #include "platform/graphics/gpu/WebGLImageBufferSurface.h"
54 #include "platform/transforms/AffineTransform.h"
55 #include "public/platform/Platform.h"
61 using namespace HTMLNames;
63 // These values come from the WhatWG spec.
64 static const int DefaultWidth = 300;
65 static const int DefaultHeight = 150;
67 // Firefox limits width/height to 32767 pixels, but slows down dramatically before it
68 // reaches that limit. We limit by area instead, giving us larger maximum dimensions,
69 // in exchange for a smaller maximum canvas size.
70 static const int MaxCanvasArea = 32768 * 8192; // Maximum canvas area in CSS pixels
72 //In Skia, we will also limit width/height to 32767.
73 static const int MaxSkiaDim = 32767; // Maximum width/height in CSS pixels.
75 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CanvasObserver);
77 inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
78 : HTMLElement(canvasTag, document)
79 , DocumentVisibilityObserver(document)
80 , m_size(DefaultWidth, DefaultHeight)
81 , m_ignoreReset(false)
82 , m_accelerationDisabled(false)
83 , m_externallyAllocatedMemory(0)
85 , m_didFailToCreateImageBuffer(false)
86 , m_didClearImageBuffer(false)
88 ScriptWrappable::init(this);
91 DEFINE_NODE_FACTORY(HTMLCanvasElement)
93 HTMLCanvasElement::~HTMLCanvasElement()
96 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_externallyAllocatedMemory);
98 HashSet<RawPtr<CanvasObserver> >::iterator end = m_observers.end();
99 for (HashSet<RawPtr<CanvasObserver> >::iterator it = m_observers.begin(); it != end; ++it)
100 (*it)->canvasDestroyed(this);
101 // Ensure these go away before the ImageBuffer.
102 m_contextStateSaver.clear();
107 void HTMLCanvasElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
109 if (name == widthAttr || name == heightAttr)
111 HTMLElement::parseAttribute(name, value);
114 RenderObject* HTMLCanvasElement::createRenderer(RenderStyle* style)
116 LocalFrame* frame = document().frame();
117 if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript))
118 return new RenderHTMLCanvas(this);
119 return HTMLElement::createRenderer(style);
122 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode* node)
124 setIsInCanvasSubtree(true);
125 return HTMLElement::insertedInto(node);
128 void HTMLCanvasElement::addObserver(CanvasObserver* observer)
130 m_observers.add(observer);
133 void HTMLCanvasElement::removeObserver(CanvasObserver* observer)
135 m_observers.remove(observer);
138 void HTMLCanvasElement::setHeight(int value)
140 setIntegralAttribute(heightAttr, value);
143 void HTMLCanvasElement::setWidth(int value)
145 setIntegralAttribute(widthAttr, value);
148 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, CanvasContextAttributes* attrs)
150 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2D canvas and the existing
151 // context is already 2D, just return that. If the existing context is WebGL, then destroy it
152 // before creating a new 2D context. Vice versa when requesting a WebGL canvas. Requesting a
153 // context with any other type string will destroy any existing context.
157 ContextExperimentalWebgl,
159 // Only add new items to the end and keep the order of existing items.
163 // FIXME - The code depends on the context not going away once created, to prevent JS from
164 // seeing a dangling pointer. So for now we will disallow the context from being changed
165 // once it is created.
167 if (m_context && !m_context->is2d())
170 blink::Platform::current()->histogramEnumeration("Canvas.ContextType", Context2d, ContextTypeCount);
171 m_context = CanvasRenderingContext2D::create(this, static_cast<Canvas2DContextAttributes*>(attrs), document().inQuirksMode());
172 setNeedsCompositingUpdate();
174 return m_context.get();
177 // Accept the the provisional "experimental-webgl" or official "webgl" context ID.
178 if (type == "webgl" || type == "experimental-webgl") {
179 ContextType contextType = (type == "webgl") ? ContextWebgl : ContextExperimentalWebgl;
181 blink::Platform::current()->histogramEnumeration("Canvas.ContextType", contextType, ContextTypeCount);
182 m_context = WebGLRenderingContext::create(this, static_cast<WebGLContextAttributes*>(attrs));
183 setNeedsCompositingUpdate();
184 updateExternallyAllocatedMemory();
185 } else if (!m_context->is3d()) {
186 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontextcreationerror, false, true, "Canvas has an existing, non-WebGL context"));
189 return m_context.get();
195 void HTMLCanvasElement::didDraw(const FloatRect& rect)
200 if (m_dirtyRect.isEmpty())
201 blink::Platform::current()->currentThread()->addTaskObserver(this);
202 m_dirtyRect.unite(rect);
205 void HTMLCanvasElement::didFinalizeFrame()
207 if (m_dirtyRect.isEmpty())
210 // Propagate the m_dirtyRect accumulated so far to the compositor
211 // before restarting with a blank dirty rect.
212 FloatRect srcRect(0, 0, size().width(), size().height());
213 m_dirtyRect.intersect(srcRect);
214 if (RenderBox* ro = renderBox()) {
215 FloatRect mappedDirtyRect = mapRect(m_dirtyRect, srcRect, ro->contentBoxRect());
216 ro->invalidatePaintRectangle(enclosingIntRect(mappedDirtyRect));
218 notifyObserversCanvasChanged(m_dirtyRect);
219 blink::Platform::current()->currentThread()->removeTaskObserver(this);
220 m_dirtyRect = FloatRect();
223 void HTMLCanvasElement::resetDirtyRect()
225 if (m_dirtyRect.isEmpty())
227 blink::Platform::current()->currentThread()->removeTaskObserver(this);
228 m_dirtyRect = FloatRect();
231 void HTMLCanvasElement::didProcessTask()
233 // This method gets invoked if didDraw was called earlier in the current task.
234 ASSERT(!m_dirtyRect.isEmpty());
238 ASSERT(hasImageBuffer());
239 m_imageBuffer->finalizeFrame();
241 ASSERT(m_dirtyRect.isEmpty());
244 void HTMLCanvasElement::willProcessTask()
246 ASSERT_NOT_REACHED();
249 void HTMLCanvasElement::notifyObserversCanvasChanged(const FloatRect& rect)
251 WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator end = m_observers.end();
252 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator it = m_observers.begin(); it != end; ++it)
253 (*it)->canvasChanged(this, rect);
256 void HTMLCanvasElement::reset()
264 bool hadImageBuffer = hasImageBuffer();
266 int w = getAttribute(widthAttr).toInt(&ok);
270 int h = getAttribute(heightAttr).toInt(&ok);
274 if (m_contextStateSaver) {
275 // Reset to the initial graphics context state.
276 m_contextStateSaver->restore();
277 m_contextStateSaver->save();
280 if (m_context && m_context->is2d())
281 toCanvasRenderingContext2D(m_context.get())->reset();
283 IntSize oldSize = size();
284 IntSize newSize(w, h);
286 // If the size of an existing buffer matches, we can just clear it instead of reallocating.
287 // This optimization is only done for 2D canvases for now.
288 if (hadImageBuffer && oldSize == newSize && m_context && m_context->is2d()) {
289 if (!m_didClearImageBuffer)
294 setSurfaceSize(newSize);
296 if (m_context && m_context->is3d() && oldSize != size())
297 toWebGLRenderingContext(m_context.get())->reshape(width(), height());
299 if (RenderObject* renderer = this->renderer()) {
300 if (renderer->isCanvas()) {
301 if (oldSize != size()) {
302 toRenderHTMLCanvas(renderer)->canvasSizeChanged();
303 if (renderBox() && renderBox()->hasAcceleratedCompositing())
304 renderBox()->contentChanged(CanvasChanged);
307 renderer->paintInvalidationForWholeRenderer();
311 WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator end = m_observers.end();
312 for (WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator it = m_observers.begin(); it != end; ++it)
313 (*it)->canvasResized(this);
316 bool HTMLCanvasElement::paintsIntoCanvasBuffer() const
320 if (!m_context->isAccelerated())
323 if (renderBox() && renderBox()->hasAcceleratedCompositing())
330 void HTMLCanvasElement::paint(GraphicsContext* context, const LayoutRect& r)
333 if (!paintsIntoCanvasBuffer() && !document().printing())
335 m_context->paintRenderingResultsToCanvas();
338 if (hasImageBuffer()) {
339 ImageBuffer* imageBuffer = buffer();
341 CompositeOperator compositeOperator = !m_context || m_context->hasAlpha() ? CompositeSourceOver : CompositeCopy;
342 if (m_presentedImage)
343 context->drawImage(m_presentedImage.get(), pixelSnappedIntRect(r), compositeOperator, DoNotRespectImageOrientation);
345 context->drawImageBuffer(imageBuffer, pixelSnappedIntRect(r), 0, compositeOperator);
348 // When alpha is false, we should draw to opaque black.
349 if (m_context && !m_context->hasAlpha())
350 context->fillRect(FloatRect(r), Color(0, 0, 0));
354 toWebGLRenderingContext(m_context.get())->markLayerComposited();
357 bool HTMLCanvasElement::is3D() const
359 return m_context && m_context->is3d();
362 void HTMLCanvasElement::makePresentationCopy()
364 if (!m_presentedImage) {
365 // The buffer contains the last presented data, so save a copy of it.
366 m_presentedImage = buffer()->copyImage(CopyBackingStore, Unscaled);
367 updateExternallyAllocatedMemory();
371 void HTMLCanvasElement::clearPresentationCopy()
373 m_presentedImage.clear();
374 updateExternallyAllocatedMemory();
377 void HTMLCanvasElement::setSurfaceSize(const IntSize& size)
380 m_didFailToCreateImageBuffer = false;
381 discardImageBuffer();
383 if (m_context && m_context->is2d()) {
384 CanvasRenderingContext2D* context2d = toCanvasRenderingContext2D(m_context.get());
385 if (context2d->isContextLost()) {
386 context2d->restoreContext();
391 String HTMLCanvasElement::toEncodingMimeType(const String& mimeType)
393 String lowercaseMimeType = mimeType.lower();
395 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread).
396 if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(lowercaseMimeType))
397 lowercaseMimeType = "image/png";
399 return lowercaseMimeType;
402 const AtomicString HTMLCanvasElement::imageSourceURL() const
404 return AtomicString(toDataURLInternal("image/png", 0, true));
407 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double* quality, bool isSaving) const
409 if (m_size.isEmpty() || !buffer())
410 return String("data:,");
412 String encodingMimeType = toEncodingMimeType(mimeType);
414 // Try to get ImageData first, as that may avoid lossy conversions.
415 RefPtrWillBeRawPtr<ImageData> imageData = getImageData();
418 return ImageDataToDataURL(ImageDataBuffer(imageData->size(), imageData->data()), encodingMimeType, quality);
420 if (m_context && m_context->is3d()) {
421 toWebGLRenderingContext(m_context.get())->setSavingImage(isSaving);
422 m_context->paintRenderingResultsToCanvas();
423 toWebGLRenderingContext(m_context.get())->setSavingImage(false);
426 return buffer()->toDataURL(encodingMimeType, quality);
429 String HTMLCanvasElement::toDataURL(const String& mimeType, const double* quality, ExceptionState& exceptionState) const
431 if (!m_originClean) {
432 exceptionState.throwSecurityError("Tainted canvases may not be exported.");
436 return toDataURLInternal(mimeType, quality);
439 PassRefPtrWillBeRawPtr<ImageData> HTMLCanvasElement::getImageData() const
441 if (!m_context || !m_context->is3d())
443 return toWebGLRenderingContext(m_context.get())->paintRenderingResultsToImageData();
446 SecurityOrigin* HTMLCanvasElement::securityOrigin() const
448 return document().securityOrigin();
451 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const
453 if (m_context && !m_context->is2d())
456 if (m_accelerationDisabled)
459 Settings* settings = document().settings();
460 if (!settings || !settings->accelerated2dCanvasEnabled())
463 // Do not use acceleration for small canvas.
464 if (size.width() * size.height() < settings->minimumAccelerated2dCanvasSize())
467 if (!blink::Platform::current()->canAccelerate2dCanvas())
473 PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const IntSize& deviceSize, int* msaaSampleCount)
475 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque;
477 *msaaSampleCount = 0;
479 return adoptPtr(new WebGLImageBufferSurface(size(), opacityMode));
481 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) {
482 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSurface(size(), opacityMode));
483 if (surface->isValid())
484 return surface.release();
487 if (shouldAccelerate(deviceSize)) {
488 if (document().settings())
489 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASampleCount();
490 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSurface(size(), opacityMode, *msaaSampleCount));
491 if (surface->isValid())
492 return surface.release();
495 return adoptPtr(new UnacceleratedImageBufferSurface(size(), opacityMode));
498 void HTMLCanvasElement::createImageBuffer()
500 createImageBufferInternal();
501 if (m_didFailToCreateImageBuffer && m_context && m_context->is2d())
502 toCanvasRenderingContext2D(m_context.get())->loseContext();
505 void HTMLCanvasElement::createImageBufferInternal()
507 ASSERT(!m_imageBuffer);
508 ASSERT(!m_contextStateSaver);
510 m_didFailToCreateImageBuffer = true;
511 m_didClearImageBuffer = true;
513 IntSize deviceSize = size();
514 if (deviceSize.width() * deviceSize.height() > MaxCanvasArea)
517 if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim)
520 if (!deviceSize.width() || !deviceSize.height())
524 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(deviceSize, &msaaSampleCount);
525 if (!surface->isValid())
528 m_imageBuffer = ImageBuffer::create(surface.release());
529 m_imageBuffer->setClient(this);
531 m_didFailToCreateImageBuffer = false;
533 updateExternallyAllocatedMemory();
536 // Early out for WebGL canvases
540 m_imageBuffer->setClient(this);
541 m_imageBuffer->context()->setShouldClampToSourceRect(false);
542 m_imageBuffer->context()->disableAntialiasingOptimizationForHairlineImages();
543 m_imageBuffer->context()->setImageInterpolationQuality(CanvasDefaultInterpolationQuality);
544 // Enabling MSAA overrides a request to disable antialiasing. This is true regardless of whether the
545 // rendering mode is accelerated or not. For consistency, we don't want to apply AA in accelerated
546 // canvases but not in unaccelerated canvases.
547 if (!msaaSampleCount && document().settings() && !document().settings()->antialiased2dCanvasEnabled())
548 m_imageBuffer->context()->setShouldAntialias(false);
549 // GraphicsContext's defaults don't always agree with the 2d canvas spec.
550 // See CanvasRenderingContext2D::State::State() for more information.
551 m_imageBuffer->context()->setMiterLimit(10);
552 m_imageBuffer->context()->setStrokeThickness(1);
554 m_imageBuffer->context()->disableDestructionChecks(); // 2D canvas is allowed to leave context in an unfinalized state.
556 m_contextStateSaver = adoptPtr(new GraphicsContextStateSaver(*m_imageBuffer->context()));
559 setNeedsCompositingUpdate();
562 void HTMLCanvasElement::notifySurfaceInvalid()
564 if (m_context && m_context->is2d()) {
565 CanvasRenderingContext2D* context2d = toCanvasRenderingContext2D(m_context.get());
566 context2d->loseContext();
570 void HTMLCanvasElement::trace(Visitor* visitor)
573 visitor->trace(m_observers);
574 visitor->trace(m_context);
576 DocumentVisibilityObserver::trace(visitor);
577 HTMLElement::trace(visitor);
580 void HTMLCanvasElement::updateExternallyAllocatedMemory() const
589 if (m_presentedImage)
592 Checked<intptr_t, RecordOverflow> checkedExternallyAllocatedMemory = 4 * bufferCount;
593 checkedExternallyAllocatedMemory *= width();
594 checkedExternallyAllocatedMemory *= height();
595 intptr_t externallyAllocatedMemory;
596 if (checkedExternallyAllocatedMemory.safeGet(externallyAllocatedMemory) == CheckedState::DidOverflow)
597 externallyAllocatedMemory = std::numeric_limits<intptr_t>::max();
599 // Subtracting two intptr_t that are known to be positive will never underflow.
600 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(externallyAllocatedMemory - m_externallyAllocatedMemory);
601 m_externallyAllocatedMemory = externallyAllocatedMemory;
604 GraphicsContext* HTMLCanvasElement::drawingContext() const
606 return buffer() ? m_imageBuffer->context() : 0;
609 GraphicsContext* HTMLCanvasElement::existingDrawingContext() const
611 if (!hasImageBuffer())
614 return drawingContext();
617 ImageBuffer* HTMLCanvasElement::buffer() const
619 if (!hasImageBuffer() && !m_didFailToCreateImageBuffer)
620 const_cast<HTMLCanvasElement*>(this)->createImageBuffer();
621 return m_imageBuffer.get();
624 void HTMLCanvasElement::ensureUnacceleratedImageBuffer()
626 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCreateImageBuffer)
628 discardImageBuffer();
629 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque;
630 m_imageBuffer = ImageBuffer::create(size(), opacityMode);
631 m_didFailToCreateImageBuffer = !m_imageBuffer;
634 Image* HTMLCanvasElement::copiedImage() const
636 if (!m_copiedImage && buffer()) {
637 if (m_context && m_context->is3d()) {
638 toWebGLRenderingContext(m_context.get())->setSavingImage(true);
639 m_context->paintRenderingResultsToCanvas();
640 toWebGLRenderingContext(m_context.get())->setSavingImage(false);
642 m_copiedImage = buffer()->copyImage(CopyBackingStore, Unscaled);
643 updateExternallyAllocatedMemory();
645 return m_copiedImage.get();
648 void HTMLCanvasElement::clearImageBuffer()
650 ASSERT(hasImageBuffer() && !m_didFailToCreateImageBuffer);
651 ASSERT(!m_didClearImageBuffer);
654 m_didClearImageBuffer = true;
656 if (m_context->is2d()) {
657 // No need to undo transforms/clip/etc. because we are called right
658 // after the context is reset.
659 toCanvasRenderingContext2D(m_context.get())->clearRect(0, 0, width(), height());
663 void HTMLCanvasElement::discardImageBuffer()
665 m_contextStateSaver.clear(); // uses context owned by m_imageBuffer
666 m_imageBuffer.clear();
668 updateExternallyAllocatedMemory();
671 bool HTMLCanvasElement::hasValidImageBuffer() const
673 return m_imageBuffer && m_imageBuffer->isSurfaceValid();
676 void HTMLCanvasElement::clearCopiedImage()
679 m_copiedImage.clear();
680 updateExternallyAllocatedMemory();
682 m_didClearImageBuffer = false;
685 AffineTransform HTMLCanvasElement::baseTransform() const
687 ASSERT(hasImageBuffer() && !m_didFailToCreateImageBuffer);
688 return m_imageBuffer->baseTransform();
691 void HTMLCanvasElement::didChangeVisibilityState(PageVisibilityState visibility)
693 if (hasImageBuffer()) {
694 bool hidden = visibility != PageVisibilityStateVisible;
698 discardImageBuffer();
701 if (hasImageBuffer()) {
702 m_imageBuffer->setIsHidden(hidden);
707 void HTMLCanvasElement::didMoveToNewDocument(Document& oldDocument)
709 setObservedDocument(document());
710 HTMLElement::didMoveToNewDocument(oldDocument);
713 PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(SourceImageMode mode, SourceImageStatus* status) const
715 if (!width() || !height()) {
716 *status = ZeroSizeCanvasSourceImageStatus;
721 *status = InvalidSourceImageStatus;
725 if (mode == CopySourceImageIfVolatile) {
726 *status = NormalSourceImageStatus;
727 return copiedImage();
730 if (m_context && m_context->is3d()) {
731 m_context->paintRenderingResultsToCanvas();
732 *status = ExternalSourceImageStatus;
734 *status = NormalSourceImageStatus;
736 return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled);
739 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const
741 return !originClean();
744 FloatSize HTMLCanvasElement::sourceSize() const
746 return FloatSize(width(), height());