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 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 return; | 1092 return; |
1093 discardImageBuffer(); | 1093 discardImageBuffer(); |
1094 OpacityMode opacityMode = | 1094 OpacityMode opacityMode = |
1095 m_context->creationAttributes().alpha() ? NonOpaque : Opaque; | 1095 m_context->creationAttributes().alpha() ? NonOpaque : Opaque; |
1096 m_imageBuffer = ImageBuffer::create(size(), opacityMode); | 1096 m_imageBuffer = ImageBuffer::create(size(), opacityMode); |
1097 m_didFailToCreateImageBuffer = !m_imageBuffer; | 1097 m_didFailToCreateImageBuffer = !m_imageBuffer; |
1098 } | 1098 } |
1099 | 1099 |
1100 PassRefPtr<Image> HTMLCanvasElement::copiedImage( | 1100 PassRefPtr<Image> HTMLCanvasElement::copiedImage( |
1101 SourceDrawingBuffer sourceBuffer, | 1101 SourceDrawingBuffer sourceBuffer, |
1102 AccelerationHint hint) const { | 1102 AccelerationHint hint, |
| 1103 SnapshotReason snapshotReason) const { |
1103 if (!isPaintable()) | 1104 if (!isPaintable()) |
1104 return nullptr; | 1105 return nullptr; |
1105 if (!m_context) | 1106 if (!m_context) |
1106 return createTransparentImage(size()); | 1107 return createTransparentImage(size()); |
1107 | 1108 |
1108 if (m_context->getContextType() == | 1109 if (m_context->getContextType() == |
1109 CanvasRenderingContext::ContextImageBitmap) { | 1110 CanvasRenderingContext::ContextImageBitmap) { |
1110 RefPtr<Image> image = | 1111 RefPtr<Image> image = m_context->getImage(hint, snapshotReason); |
1111 m_context->getImage(hint, SnapshotReasonGetCopiedImage); | |
1112 if (image) | 1112 if (image) |
1113 return m_context->getImage(hint, SnapshotReasonGetCopiedImage); | 1113 return m_context->getImage(hint, snapshotReason); |
1114 // Special case: transferFromImageBitmap is not yet called. | 1114 // Special case: transferFromImageBitmap is not yet called. |
1115 sk_sp<SkSurface> surface = | 1115 sk_sp<SkSurface> surface = |
1116 SkSurface::MakeRasterN32Premul(width(), height()); | 1116 SkSurface::MakeRasterN32Premul(width(), height()); |
1117 return StaticBitmapImage::create(surface->makeImageSnapshot()); | 1117 return StaticBitmapImage::create(surface->makeImageSnapshot()); |
1118 } | 1118 } |
1119 | 1119 |
1120 bool needToUpdate = !m_copiedImage; | 1120 bool needToUpdate = !m_copiedImage; |
1121 // The concept of SourceDrawingBuffer is valid on only WebGL. | 1121 // The concept of SourceDrawingBuffer is valid on only WebGL. |
1122 if (m_context->is3d()) | 1122 if (m_context->is3d()) |
1123 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer); | 1123 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer); |
1124 if (needToUpdate && buffer()) { | 1124 if (needToUpdate && buffer()) { |
1125 m_copiedImage = | 1125 m_copiedImage = buffer()->newImageSnapshot(hint, snapshotReason); |
1126 buffer()->newImageSnapshot(hint, SnapshotReasonGetCopiedImage); | |
1127 updateExternallyAllocatedMemory(); | 1126 updateExternallyAllocatedMemory(); |
1128 } | 1127 } |
1129 return m_copiedImage; | 1128 return m_copiedImage; |
1130 } | 1129 } |
1131 | 1130 |
1132 void HTMLCanvasElement::discardImageBuffer() { | 1131 void HTMLCanvasElement::discardImageBuffer() { |
1133 m_imageBuffer.reset(); | 1132 m_imageBuffer.reset(); |
1134 m_dirtyRect = FloatRect(); | 1133 m_dirtyRect = FloatRect(); |
1135 updateExternallyAllocatedMemory(); | 1134 updateExternallyAllocatedMemory(); |
1136 } | 1135 } |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 mojom::blink::OffscreenCanvasSurfacePtr service; | 1368 mojom::blink::OffscreenCanvasSurfacePtr service; |
1370 Platform::current()->interfaceProvider()->getInterface( | 1369 Platform::current()->interfaceProvider()->getInterface( |
1371 mojo::GetProxy(&service)); | 1370 mojo::GetProxy(&service)); |
1372 m_surfaceLayerBridge = | 1371 m_surfaceLayerBridge = |
1373 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); | 1372 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); |
1374 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), | 1373 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), |
1375 this->height()); | 1374 this->height()); |
1376 } | 1375 } |
1377 | 1376 |
1378 } // namespace blink | 1377 } // namespace blink |
OLD | NEW |