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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 return new LayoutHTMLCanvas(this); | 167 return new LayoutHTMLCanvas(this); |
168 return HTMLElement::createLayoutObject(style); | 168 return HTMLElement::createLayoutObject(style); |
169 } | 169 } |
170 | 170 |
171 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode
* node) | 171 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode
* node) |
172 { | 172 { |
173 setIsInCanvasSubtree(true); | 173 setIsInCanvasSubtree(true); |
174 return HTMLElement::insertedInto(node); | 174 return HTMLElement::insertedInto(node); |
175 } | 175 } |
176 | 176 |
177 void HTMLCanvasElement::setHeight(int value, ExceptionState& exceptionState) | 177 void HTMLCanvasElement::setHeight(int value) |
178 { | 178 { |
179 if (surfaceLayerBridge()) { | |
180 // The existence of surfaceLayerBridge indicates that | |
181 // canvas.transferControlToOffscreen has been called. | |
182 exceptionState.throwDOMException(InvalidStateError, "Resizing is not all
owed for a canvas that has transferred its control to offscreen."); | |
183 return; | |
184 } | |
185 setIntegralAttribute(heightAttr, value); | 179 setIntegralAttribute(heightAttr, value); |
186 } | 180 } |
187 | 181 |
188 void HTMLCanvasElement::setWidth(int value, ExceptionState& exceptionState) | 182 void HTMLCanvasElement::setWidth(int value) |
189 { | 183 { |
190 if (surfaceLayerBridge()) { | |
191 // Same comment as above. | |
192 exceptionState.throwDOMException(InvalidStateError, "Resizing is not all
owed for a canvas that has transferred its control to offscreen."); | |
193 return; | |
194 } | |
195 setIntegralAttribute(widthAttr, value); | 184 setIntegralAttribute(widthAttr, value); |
196 } | 185 } |
197 | 186 |
198 void HTMLCanvasElement::setSize(const IntSize& newSize) | |
199 { | |
200 if (newSize == size()) | |
201 return; | |
202 m_ignoreReset = true; | |
203 setIntegralAttribute(widthAttr, newSize.width()); | |
204 setIntegralAttribute(heightAttr, newSize.height()); | |
205 m_ignoreReset = false; | |
206 reset(); | |
207 } | |
208 | |
209 HTMLCanvasElement::ContextFactoryVector& HTMLCanvasElement::renderingContextFact
ories() | 187 HTMLCanvasElement::ContextFactoryVector& HTMLCanvasElement::renderingContextFact
ories() |
210 { | 188 { |
211 DCHECK(isMainThread()); | 189 DCHECK(isMainThread()); |
212 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (CanvasRenderi
ngContext::ContextTypeCount)); | 190 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (CanvasRenderi
ngContext::ContextTypeCount)); |
213 return s_contextFactories; | 191 return s_contextFactories; |
214 } | 192 } |
215 | 193 |
216 CanvasRenderingContextFactory* HTMLCanvasElement::getRenderingContextFactory(int
type) | 194 CanvasRenderingContextFactory* HTMLCanvasElement::getRenderingContextFactory(int
type) |
217 { | 195 { |
218 DCHECK(type < CanvasRenderingContext::ContextTypeCount); | 196 DCHECK(type < CanvasRenderingContext::ContextTypeCount); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 633 |
656 String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToDataURL
); | 634 String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToDataURL
); |
657 | 635 |
658 ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL); | 636 ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL); |
659 | 637 |
660 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU
RL(encodingMimeType, quality); | 638 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU
RL(encodingMimeType, quality); |
661 } | 639 } |
662 | 640 |
663 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q
ualityArgument, ExceptionState& exceptionState) const | 641 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q
ualityArgument, ExceptionState& exceptionState) const |
664 { | 642 { |
665 if (surfaceLayerBridge()) { | |
666 exceptionState.throwDOMException(InvalidStateError, "canvas.toDataURL is
not allowed for a canvas that has transferred its control to offscreen."); | |
667 } | |
668 if (!originClean()) { | 643 if (!originClean()) { |
669 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); | 644 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); |
670 return String(); | 645 return String(); |
671 } | 646 } |
672 Optional<ScopedUsHistogramTimer> timer; | 647 Optional<ScopedUsHistogramTimer> timer; |
673 String lowercaseMimeType = mimeType.lower(); | 648 String lowercaseMimeType = mimeType.lower(); |
674 if (mimeType.isNull()) | 649 if (mimeType.isNull()) |
675 lowercaseMimeType = DefaultMimeType; | 650 lowercaseMimeType = DefaultMimeType; |
676 if (lowercaseMimeType == "image/png") { | 651 if (lowercaseMimeType == "image/png") { |
677 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterPNG
, new CustomCountHistogram("Blink.Canvas.ToDataURL.PNG", 0, 10000000, 50)); | 652 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterPNG
, new CustomCountHistogram("Blink.Canvas.ToDataURL.PNG", 0, 10000000, 50)); |
(...skipping 26 matching lines...) Expand all Loading... |
704 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); | 679 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); |
705 if (v8Value->IsNumber()) { | 680 if (v8Value->IsNumber()) { |
706 quality = v8Value.As<v8::Number>()->Value(); | 681 quality = v8Value.As<v8::Number>()->Value(); |
707 } | 682 } |
708 } | 683 } |
709 return toDataURLInternal(mimeType, quality, BackBuffer); | 684 return toDataURLInternal(mimeType, quality, BackBuffer); |
710 } | 685 } |
711 | 686 |
712 void HTMLCanvasElement::toBlob(BlobCallback* callback, const String& mimeType, c
onst ScriptValue& qualityArgument, ExceptionState& exceptionState) | 687 void HTMLCanvasElement::toBlob(BlobCallback* callback, const String& mimeType, c
onst ScriptValue& qualityArgument, ExceptionState& exceptionState) |
713 { | 688 { |
714 if (surfaceLayerBridge()) { | |
715 exceptionState.throwDOMException(InvalidStateError, "canvas.toBlob is no
t allowed for a canvas that has transferred its control to offscreen."); | |
716 } | |
717 | |
718 if (!originClean()) { | 689 if (!originClean()) { |
719 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); | 690 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); |
720 return; | 691 return; |
721 } | 692 } |
722 | 693 |
723 if (!isPaintable()) { | 694 if (!isPaintable()) { |
724 // If the canvas element's bitmap has no pixels | 695 // If the canvas element's bitmap has no pixels |
725 TaskRunnerHelper::get(TaskType::CanvasBlobSerialization, &document())->p
ostTask(BLINK_FROM_HERE, WTF::bind(&BlobCallback::handleEvent, wrapPersistent(ca
llback), nullptr)); | 696 TaskRunnerHelper::get(TaskType::CanvasBlobSerialization, &document())->p
ostTask(BLINK_FROM_HERE, WTF::bind(&BlobCallback::handleEvent, wrapPersistent(ca
llback), nullptr)); |
726 return; | 697 return; |
727 } | 698 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 DCHECK(m_context); | 1013 DCHECK(m_context); |
1043 DCHECK(m_context->getContextType() != CanvasRenderingContext::ContextImageBi
tmap); | 1014 DCHECK(m_context->getContextType() != CanvasRenderingContext::ContextImageBi
tmap); |
1044 if (!hasImageBuffer() && !m_didFailToCreateImageBuffer) | 1015 if (!hasImageBuffer() && !m_didFailToCreateImageBuffer) |
1045 const_cast<HTMLCanvasElement*>(this)->createImageBuffer(); | 1016 const_cast<HTMLCanvasElement*>(this)->createImageBuffer(); |
1046 return m_imageBuffer.get(); | 1017 return m_imageBuffer.get(); |
1047 } | 1018 } |
1048 | 1019 |
1049 void HTMLCanvasElement::createImageBufferUsingSurfaceForTesting(std::unique_ptr<
ImageBufferSurface> surface) | 1020 void HTMLCanvasElement::createImageBufferUsingSurfaceForTesting(std::unique_ptr<
ImageBufferSurface> surface) |
1050 { | 1021 { |
1051 discardImageBuffer(); | 1022 discardImageBuffer(); |
1052 setIntegralAttribute(widthAttr, surface->size().width()); | 1023 setWidth(surface->size().width()); |
1053 setIntegralAttribute(heightAttr, surface->size().height()); | 1024 setHeight(surface->size().height()); |
1054 createImageBufferInternal(std::move(surface)); | 1025 createImageBufferInternal(std::move(surface)); |
1055 } | 1026 } |
1056 | 1027 |
1057 void HTMLCanvasElement::ensureUnacceleratedImageBuffer() | 1028 void HTMLCanvasElement::ensureUnacceleratedImageBuffer() |
1058 { | 1029 { |
1059 DCHECK(m_context); | 1030 DCHECK(m_context); |
1060 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea
teImageBuffer) | 1031 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea
teImageBuffer) |
1061 return; | 1032 return; |
1062 discardImageBuffer(); | 1033 discardImageBuffer(); |
1063 OpacityMode opacityMode = m_context->creationAttributes().alpha() ? NonOpaqu
e : Opaque; | 1034 OpacityMode opacityMode = m_context->creationAttributes().alpha() ? NonOpaqu
e : Opaque; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 | 1252 |
1282 bool HTMLCanvasElement::createSurfaceLayer() | 1253 bool HTMLCanvasElement::createSurfaceLayer() |
1283 { | 1254 { |
1284 DCHECK(!m_surfaceLayerBridge); | 1255 DCHECK(!m_surfaceLayerBridge); |
1285 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); | 1256 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); |
1286 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); | 1257 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); |
1287 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); | 1258 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); |
1288 } | 1259 } |
1289 | 1260 |
1290 } // namespace blink | 1261 } // namespace blink |
OLD | NEW |