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