OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2009, 2010 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 28 matching lines...) Expand all Loading... |
39 #include "core/html/canvas/CanvasImageSource.h" | 39 #include "core/html/canvas/CanvasImageSource.h" |
40 #include "core/imagebitmap/ImageBitmapSource.h" | 40 #include "core/imagebitmap/ImageBitmapSource.h" |
41 #include "core/page/PageLifecycleObserver.h" | 41 #include "core/page/PageLifecycleObserver.h" |
42 #include "platform/geometry/FloatRect.h" | 42 #include "platform/geometry/FloatRect.h" |
43 #include "platform/geometry/IntSize.h" | 43 #include "platform/geometry/IntSize.h" |
44 #include "platform/graphics/CanvasSurfaceLayerBridge.h" | 44 #include "platform/graphics/CanvasSurfaceLayerBridge.h" |
45 #include "platform/graphics/GraphicsTypes.h" | 45 #include "platform/graphics/GraphicsTypes.h" |
46 #include "platform/graphics/GraphicsTypes3D.h" | 46 #include "platform/graphics/GraphicsTypes3D.h" |
47 #include "platform/graphics/ImageBufferClient.h" | 47 #include "platform/graphics/ImageBufferClient.h" |
48 #include "platform/heap/Handle.h" | 48 #include "platform/heap/Handle.h" |
| 49 #include <memory> |
49 | 50 |
50 #define CanvasDefaultInterpolationQuality InterpolationLow | 51 #define CanvasDefaultInterpolationQuality InterpolationLow |
51 | 52 |
52 namespace blink { | 53 namespace blink { |
53 | 54 |
54 class AffineTransform; | 55 class AffineTransform; |
55 class CanvasContextCreationAttributes; | 56 class CanvasContextCreationAttributes; |
56 class CanvasRenderingContext; | 57 class CanvasRenderingContext; |
57 class CanvasRenderingContextFactory; | 58 class CanvasRenderingContextFactory; |
58 class GraphicsContext; | 59 class GraphicsContext; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 void doDeferredPaintInvalidation(); | 179 void doDeferredPaintInvalidation(); |
179 | 180 |
180 // ImageBitmapSource implementation | 181 // ImageBitmapSource implementation |
181 IntSize bitmapSourceSize() const override; | 182 IntSize bitmapSourceSize() const override; |
182 ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy,
int sw, int sh, const ImageBitmapOptions&, ExceptionState&) override; | 183 ScriptPromise createImageBitmap(ScriptState*, EventTarget&, int sx, int sy,
int sw, int sh, const ImageBitmapOptions&, ExceptionState&) override; |
183 | 184 |
184 DECLARE_VIRTUAL_TRACE(); | 185 DECLARE_VIRTUAL_TRACE(); |
185 | 186 |
186 DECLARE_VIRTUAL_TRACE_WRAPPERS(); | 187 DECLARE_VIRTUAL_TRACE_WRAPPERS(); |
187 | 188 |
188 void createImageBufferUsingSurfaceForTesting(PassOwnPtr<ImageBufferSurface>)
; | 189 void createImageBufferUsingSurfaceForTesting(std::unique_ptr<ImageBufferSurf
ace>); |
189 | 190 |
190 static void registerRenderingContextFactory(PassOwnPtr<CanvasRenderingContex
tFactory>); | 191 static void registerRenderingContextFactory(std::unique_ptr<CanvasRenderingC
ontextFactory>); |
191 void updateExternallyAllocatedMemory() const; | 192 void updateExternallyAllocatedMemory() const; |
192 | 193 |
193 void styleDidChange(const ComputedStyle* oldStyle, const ComputedStyle& newS
tyle); | 194 void styleDidChange(const ComputedStyle* oldStyle, const ComputedStyle& newS
tyle); |
194 | 195 |
195 void notifyListenersCanvasChanged(); | 196 void notifyListenersCanvasChanged(); |
196 | 197 |
197 // For Canvas HitRegions | 198 // For Canvas HitRegions |
198 bool isSupportedInteractiveCanvasFallback(const Element&); | 199 bool isSupportedInteractiveCanvasFallback(const Element&); |
199 std::pair<Element*, String> getControlAndIdIfHitRegionExists(const LayoutPoi
nt&); | 200 std::pair<Element*, String> getControlAndIdIfHitRegionExists(const LayoutPoi
nt&); |
200 String getIdFromControl(const Element*); | 201 String getIdFromControl(const Element*); |
201 | 202 |
202 // For OffscreenCanvas that controls this html canvas element | 203 // For OffscreenCanvas that controls this html canvas element |
203 CanvasSurfaceLayerBridge* surfaceLayerBridge() const { return m_surfaceLayer
Bridge.get(); } | 204 CanvasSurfaceLayerBridge* surfaceLayerBridge() const { return m_surfaceLayer
Bridge.get(); } |
204 void createSurfaceLayerBridge(); | 205 void createSurfaceLayerBridge(); |
205 | 206 |
206 void detachContext() { m_context = nullptr; } | 207 void detachContext() { m_context = nullptr; } |
207 | 208 |
208 protected: | 209 protected: |
209 void didMoveToNewDocument(Document& oldDocument) override; | 210 void didMoveToNewDocument(Document& oldDocument) override; |
210 | 211 |
211 private: | 212 private: |
212 explicit HTMLCanvasElement(Document&); | 213 explicit HTMLCanvasElement(Document&); |
213 void dispose(); | 214 void dispose(); |
214 | 215 |
215 using ContextFactoryVector = Vector<OwnPtr<CanvasRenderingContextFactory>>; | 216 using ContextFactoryVector = Vector<std::unique_ptr<CanvasRenderingContextFa
ctory>>; |
216 static ContextFactoryVector& renderingContextFactories(); | 217 static ContextFactoryVector& renderingContextFactories(); |
217 static CanvasRenderingContextFactory* getRenderingContextFactory(int); | 218 static CanvasRenderingContextFactory* getRenderingContextFactory(int); |
218 | 219 |
219 void parseAttribute(const QualifiedName&, const AtomicString&, const AtomicS
tring&) override; | 220 void parseAttribute(const QualifiedName&, const AtomicString&, const AtomicS
tring&) override; |
220 LayoutObject* createLayoutObject(const ComputedStyle&) override; | 221 LayoutObject* createLayoutObject(const ComputedStyle&) override; |
221 bool areAuthorShadowsAllowed() const override { return false; } | 222 bool areAuthorShadowsAllowed() const override { return false; } |
222 | 223 |
223 void reset(); | 224 void reset(); |
224 | 225 |
225 PassOwnPtr<ImageBufferSurface> createImageBufferSurface(const IntSize& devic
eSize, int* msaaSampleCount); | 226 std::unique_ptr<ImageBufferSurface> createImageBufferSurface(const IntSize&
deviceSize, int* msaaSampleCount); |
226 void createImageBuffer(); | 227 void createImageBuffer(); |
227 void createImageBufferInternal(PassOwnPtr<ImageBufferSurface> externalSurfac
e); | 228 void createImageBufferInternal(std::unique_ptr<ImageBufferSurface> externalS
urface); |
228 bool shouldUseDisplayList(const IntSize& deviceSize); | 229 bool shouldUseDisplayList(const IntSize& deviceSize); |
229 | 230 |
230 void setSurfaceSize(const IntSize&); | 231 void setSurfaceSize(const IntSize&); |
231 | 232 |
232 bool paintsIntoCanvasBuffer() const; | 233 bool paintsIntoCanvasBuffer() const; |
233 | 234 |
234 ImageData* toImageData(SourceDrawingBuffer, SnapshotReason) const; | 235 ImageData* toImageData(SourceDrawingBuffer, SnapshotReason) const; |
235 | 236 |
236 String toDataURLInternal(const String& mimeType, const double& quality, Sour
ceDrawingBuffer) const; | 237 String toDataURLInternal(const String& mimeType, const double& quality, Sour
ceDrawingBuffer) const; |
237 | 238 |
238 HeapHashSet<WeakMember<CanvasDrawListener>> m_listeners; | 239 HeapHashSet<WeakMember<CanvasDrawListener>> m_listeners; |
239 | 240 |
240 IntSize m_size; | 241 IntSize m_size; |
241 | 242 |
242 Member<CanvasRenderingContext> m_context; | 243 Member<CanvasRenderingContext> m_context; |
243 | 244 |
244 bool m_ignoreReset; | 245 bool m_ignoreReset; |
245 FloatRect m_dirtyRect; | 246 FloatRect m_dirtyRect; |
246 | 247 |
247 mutable intptr_t m_externallyAllocatedMemory; | 248 mutable intptr_t m_externallyAllocatedMemory; |
248 | 249 |
249 bool m_originClean; | 250 bool m_originClean; |
250 | 251 |
251 // It prevents HTMLCanvasElement::buffer() from continuously re-attempting t
o allocate an imageBuffer | 252 // It prevents HTMLCanvasElement::buffer() from continuously re-attempting t
o allocate an imageBuffer |
252 // after the first attempt failed. | 253 // after the first attempt failed. |
253 mutable bool m_didFailToCreateImageBuffer; | 254 mutable bool m_didFailToCreateImageBuffer; |
254 bool m_imageBufferIsClear; | 255 bool m_imageBufferIsClear; |
255 OwnPtr<ImageBuffer> m_imageBuffer; | 256 std::unique_ptr<ImageBuffer> m_imageBuffer; |
256 | 257 |
257 mutable RefPtr<Image> m_copiedImage; // FIXME: This is temporary for platfor
ms that have to copy the image buffer to render (and for CSSCanvasValue). | 258 mutable RefPtr<Image> m_copiedImage; // FIXME: This is temporary for platfor
ms that have to copy the image buffer to render (and for CSSCanvasValue). |
258 | 259 |
259 // Used for OffscreenCanvas that controls this HTML canvas element | 260 // Used for OffscreenCanvas that controls this HTML canvas element |
260 OwnPtr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge; | 261 std::unique_ptr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge; |
261 }; | 262 }; |
262 | 263 |
263 } // namespace blink | 264 } // namespace blink |
264 | 265 |
265 #endif // HTMLCanvasElement_h | 266 #endif // HTMLCanvasElement_h |
OLD | NEW |