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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 { | 121 { |
122 if (size.isEmpty()) | 122 if (size.isEmpty()) |
123 return false; | 123 return false; |
124 if (size.width() * size.height() > MaxCanvasArea) | 124 if (size.width() * size.height() > MaxCanvasArea) |
125 return false; | 125 return false; |
126 if (size.width() > MaxSkiaDim || size.height() > MaxSkiaDim) | 126 if (size.width() > MaxSkiaDim || size.height() > MaxSkiaDim) |
127 return false; | 127 return false; |
128 return true; | 128 return true; |
129 } | 129 } |
130 | 130 |
131 PassRefPtr<Image> createTransparentImage(const IntSize& size) | |
132 { | |
133 DCHECK(canCreateImageBuffer(size)); | |
134 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(size.width(), size
.height()); | |
135 return StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())); | |
136 } | |
137 | |
138 } // namespace | 131 } // namespace |
139 | 132 |
140 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) | 133 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) |
141 : HTMLElement(canvasTag, document) | 134 : HTMLElement(canvasTag, document) |
142 , ContextLifecycleObserver(&document) | 135 , ContextLifecycleObserver(&document) |
143 , PageLifecycleObserver(document.page()) | 136 , PageLifecycleObserver(document.page()) |
144 , m_size(DefaultWidth, DefaultHeight) | 137 , m_size(DefaultWidth, DefaultHeight) |
145 , m_ignoreReset(false) | 138 , m_ignoreReset(false) |
146 , m_externallyAllocatedMemory(0) | 139 , m_externallyAllocatedMemory(0) |
147 , m_originClean(true) | 140 , m_originClean(true) |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 { | 972 { |
980 DCHECK(m_context); | 973 DCHECK(m_context); |
981 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea
teImageBuffer) | 974 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea
teImageBuffer) |
982 return; | 975 return; |
983 discardImageBuffer(); | 976 discardImageBuffer(); |
984 OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque; | 977 OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque; |
985 m_imageBuffer = ImageBuffer::create(size(), opacityMode); | 978 m_imageBuffer = ImageBuffer::create(size(), opacityMode); |
986 m_didFailToCreateImageBuffer = !m_imageBuffer; | 979 m_didFailToCreateImageBuffer = !m_imageBuffer; |
987 } | 980 } |
988 | 981 |
989 PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe
r, AccelerationHint hint) const | 982 Image* HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffer, Accelera
tionHint hint) const |
990 { | 983 { |
991 if (!isPaintable()) | 984 if (!isPaintable()) |
992 return nullptr; | 985 return nullptr; |
993 if (!m_context) | 986 if (!m_context) |
994 return createTransparentImage(size()); | 987 return ensureTransparentImage(); |
995 | 988 |
996 bool needToUpdate = !m_copiedImage; | 989 bool needToUpdate = !m_copiedImage; |
997 // The concept of SourceDrawingBuffer is valid on only WebGL. | 990 // The concept of SourceDrawingBuffer is valid on only WebGL. |
998 if (m_context->is3d()) | 991 if (m_context->is3d()) |
999 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer); | 992 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer); |
1000 if (needToUpdate && buffer()) { | 993 if (needToUpdate && buffer()) { |
1001 m_copiedImage = buffer()->newImageSnapshot(hint, SnapshotReasonGetCopied
Image); | 994 m_copiedImage = buffer()->newImageSnapshot(hint, SnapshotReasonGetCopied
Image); |
1002 updateExternallyAllocatedMemory(); | 995 updateExternallyAllocatedMemory(); |
1003 } | 996 } |
1004 return m_copiedImage; | 997 return m_copiedImage.get(); |
1005 } | 998 } |
1006 | 999 |
1007 void HTMLCanvasElement::discardImageBuffer() | 1000 void HTMLCanvasElement::discardImageBuffer() |
1008 { | 1001 { |
1009 m_imageBuffer.reset(); | 1002 m_imageBuffer.reset(); |
1010 m_dirtyRect = FloatRect(); | 1003 m_dirtyRect = FloatRect(); |
1011 updateExternallyAllocatedMemory(); | 1004 updateExternallyAllocatedMemory(); |
1012 } | 1005 } |
1013 | 1006 |
1014 void HTMLCanvasElement::clearCopiedImage() | 1007 void HTMLCanvasElement::clearCopiedImage() |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 return nullptr; | 1059 return nullptr; |
1067 } | 1060 } |
1068 | 1061 |
1069 if (!isPaintable()) { | 1062 if (!isPaintable()) { |
1070 *status = InvalidSourceImageStatus; | 1063 *status = InvalidSourceImageStatus; |
1071 return nullptr; | 1064 return nullptr; |
1072 } | 1065 } |
1073 | 1066 |
1074 if (!m_context) { | 1067 if (!m_context) { |
1075 *status = NormalSourceImageStatus; | 1068 *status = NormalSourceImageStatus; |
1076 return createTransparentImage(size()); | 1069 return ensureTransparentImage(); |
1077 } | 1070 } |
1078 | 1071 |
1079 if (m_context->is3d()) { | 1072 if (m_context->is3d()) { |
1080 m_context->paintRenderingResultsToCanvas(BackBuffer); | 1073 m_context->paintRenderingResultsToCanvas(BackBuffer); |
1081 } | 1074 } |
1082 | 1075 |
1083 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint, reason); | 1076 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint, reason); |
1084 if (image) { | 1077 if (image) { |
1085 *status = NormalSourceImageStatus; | 1078 *status = NormalSourceImageStatus; |
1086 return StaticBitmapImage::create(image.release()); | 1079 return StaticBitmapImage::create(image.release()); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 } | 1186 } |
1194 | 1187 |
1195 bool HTMLCanvasElement::createSurfaceLayer() | 1188 bool HTMLCanvasElement::createSurfaceLayer() |
1196 { | 1189 { |
1197 DCHECK(!m_surfaceLayerBridge); | 1190 DCHECK(!m_surfaceLayerBridge); |
1198 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); | 1191 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w CanvasSurfaceLayerBridgeClientImpl()); |
1199 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); | 1192 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); |
1200 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); | 1193 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height(
)); |
1201 } | 1194 } |
1202 | 1195 |
| 1196 Image* HTMLCanvasElement::ensureTransparentImage() const |
| 1197 { |
| 1198 if (m_transparentImage && m_transparentImage->size() == size()) |
| 1199 return m_transparentImage.get(); |
| 1200 DCHECK(canCreateImageBuffer(size())); |
| 1201 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(size().width(), si
ze().height()); |
| 1202 m_transparentImage = StaticBitmapImage::create(fromSkSp(surface->makeImageSn
apshot())); |
| 1203 return m_transparentImage.get(); |
| 1204 } |
| 1205 |
1203 } // namespace blink | 1206 } // namespace blink |
OLD | NEW |