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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 class CanvasRenderingContext; | 54 class CanvasRenderingContext; |
55 class CanvasRenderingContextFactory; | 55 class CanvasRenderingContextFactory; |
56 class GraphicsContext; | 56 class GraphicsContext; |
57 class HTMLCanvasElement; | 57 class HTMLCanvasElement; |
58 class Image; | 58 class Image; |
59 class ImageBuffer; | 59 class ImageBuffer; |
60 class ImageBufferSurface; | 60 class ImageBufferSurface; |
61 class ImageData; | 61 class ImageData; |
62 class IntSize; | 62 class IntSize; |
63 | 63 |
64 class CORE_EXPORT CanvasObserver : public WillBeGarbageCollectedMixin { | |
65 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(CanvasObserver); | |
66 public: | |
67 virtual void canvasChanged(HTMLCanvasElement*, const FloatRect& changedRect)
= 0; | |
68 virtual void canvasResized(HTMLCanvasElement*) = 0; | |
69 #if !ENABLE(OILPAN) | |
70 virtual void canvasDestroyed(HTMLCanvasElement*) = 0; | |
71 #endif | |
72 | |
73 DEFINE_INLINE_VIRTUAL_TRACE() { } | |
74 }; | |
75 | |
76 class CORE_EXPORT HTMLCanvasElement final : public HTMLElement, public DocumentV
isibilityObserver, public CanvasImageSource, public ImageBufferClient { | 64 class CORE_EXPORT HTMLCanvasElement final : public HTMLElement, public DocumentV
isibilityObserver, public CanvasImageSource, public ImageBufferClient { |
77 DEFINE_WRAPPERTYPEINFO(); | 65 DEFINE_WRAPPERTYPEINFO(); |
78 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLCanvasElement); | 66 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLCanvasElement); |
79 public: | 67 public: |
80 DECLARE_NODE_FACTORY(HTMLCanvasElement); | 68 DECLARE_NODE_FACTORY(HTMLCanvasElement); |
81 ~HTMLCanvasElement() override; | 69 ~HTMLCanvasElement() override; |
82 | 70 |
83 static WebThread* getToBlobThreadInstance(); | 71 static WebThread* getToBlobThreadInstance(); |
84 | 72 |
85 void addObserver(CanvasObserver*); | |
86 void removeObserver(CanvasObserver*); | |
87 | |
88 // Attributes and functions exposed to script | 73 // Attributes and functions exposed to script |
89 int width() const { return size().width(); } | 74 int width() const { return size().width(); } |
90 int height() const { return size().height(); } | 75 int height() const { return size().height(); } |
91 | 76 |
92 const IntSize& size() const { return m_size; } | 77 const IntSize& size() const { return m_size; } |
93 | 78 |
94 void setWidth(int); | 79 void setWidth(int); |
95 void setHeight(int); | 80 void setHeight(int); |
96 void setAccelerationDisabled(bool accelerationDisabled) { m_accelerationDisa
bled = accelerationDisabled; } | |
97 bool accelerationDisabled() const { return m_accelerationDisabled; } | |
98 | 81 |
99 void setSize(const IntSize& newSize) | 82 void setSize(const IntSize& newSize) |
100 { | 83 { |
101 if (newSize == size()) | 84 if (newSize == size()) |
102 return; | 85 return; |
103 m_ignoreReset = true; | 86 m_ignoreReset = true; |
104 setWidth(newSize.width()); | 87 setWidth(newSize.width()); |
105 setHeight(newSize.height()); | 88 setHeight(newSize.height()); |
106 m_ignoreReset = false; | 89 m_ignoreReset = false; |
107 reset(); | 90 reset(); |
108 } | 91 } |
109 | 92 |
110 // Called by HTMLCanvasElement's V8 bindings. | 93 // Called by HTMLCanvasElement's V8 bindings. |
111 ScriptValue getContext(ScriptState*, const String&, const CanvasContextCreat
ionAttributes&); | 94 ScriptValue getContext(ScriptState*, const String&, const CanvasContextCreat
ionAttributes&); |
112 // Called by Document::getCSSCanvasContext as well as above getContext(). | 95 // Called by Document::getCSSCanvasContext as well as above getContext(). |
113 CanvasRenderingContext* getCanvasRenderingContext(const String&, const Canva
sContextCreationAttributes&); | 96 CanvasRenderingContext* getCanvasRenderingContext(const String&, const Canva
sContextCreationAttributes&); |
114 | 97 |
115 bool isPaintable() const; | 98 bool isPaintable() const; |
116 | 99 |
117 static String toEncodingMimeType(const String& mimeType); | 100 static String toEncodingMimeType(const String& mimeType); |
118 String toDataURL(const String& mimeType, const ScriptValue& qualityArgument,
ExceptionState&) const; | 101 String toDataURL(const String& mimeType, const ScriptValue& qualityArgument,
ExceptionState&) const; |
119 String toDataURL(const String& mimeType, ExceptionState& exceptionState) con
st { return toDataURL(mimeType, ScriptValue(), exceptionState); } | 102 String toDataURL(const String& mimeType, ExceptionState& exceptionState) con
st { return toDataURL(mimeType, ScriptValue(), exceptionState); } |
120 | 103 |
121 void toBlob(FileCallback*, const String& mimeType, const ScriptValue& qualit
yArgument, ExceptionState&); | 104 void toBlob(FileCallback*, const String& mimeType, const ScriptValue& qualit
yArgument, ExceptionState&); |
122 void toBlob(FileCallback* callback, const String& mimeType, ExceptionState&
exceptionState) { return toBlob(callback, mimeType, ScriptValue(), exceptionStat
e); } | 105 void toBlob(FileCallback* callback, const String& mimeType, ExceptionState&
exceptionState) { return toBlob(callback, mimeType, ScriptValue(), exceptionStat
e); } |
123 | 106 |
124 // Used for rendering | 107 // Used for rendering |
125 void didDraw(const FloatRect&); | 108 void didDraw(const FloatRect&); |
126 void notifyObserversCanvasChanged(const FloatRect&); | |
127 | 109 |
128 void paint(GraphicsContext*, const LayoutRect&); | 110 void paint(GraphicsContext*, const LayoutRect&); |
129 | 111 |
130 SkCanvas* drawingCanvas() const; | 112 SkCanvas* drawingCanvas() const; |
131 void disableDeferral() const; | 113 void disableDeferral() const; |
132 SkCanvas* existingDrawingCanvas() const; | 114 SkCanvas* existingDrawingCanvas() const; |
133 | 115 |
134 void setRenderingContext(PassOwnPtrWillBeRawPtr<CanvasRenderingContext>); | 116 void setRenderingContext(PassOwnPtrWillBeRawPtr<CanvasRenderingContext>); |
135 CanvasRenderingContext* renderingContext() const { return m_context.get(); } | 117 CanvasRenderingContext* renderingContext() const { return m_context.get(); } |
136 | 118 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 void setSurfaceSize(const IntSize&); | 195 void setSurfaceSize(const IntSize&); |
214 | 196 |
215 bool paintsIntoCanvasBuffer() const; | 197 bool paintsIntoCanvasBuffer() const; |
216 | 198 |
217 ImageData* toImageData(SourceDrawingBuffer) const; | 199 ImageData* toImageData(SourceDrawingBuffer) const; |
218 String toDataURLInternal(const String& mimeType, const double& quality, Sour
ceDrawingBuffer) const; | 200 String toDataURLInternal(const String& mimeType, const double& quality, Sour
ceDrawingBuffer) const; |
219 | 201 |
220 static void encodeImageAsync(DOMUint8ClampedArray* imagedata, IntSize imageS
ize, FileCallback*, const String& mimeType, double quality); | 202 static void encodeImageAsync(DOMUint8ClampedArray* imagedata, IntSize imageS
ize, FileCallback*, const String& mimeType, double quality); |
221 static void createBlobAndCall(PassOwnPtr<Vector<char>> encodedImage, const S
tring& mimeType, FileCallback*); | 203 static void createBlobAndCall(PassOwnPtr<Vector<char>> encodedImage, const S
tring& mimeType, FileCallback*); |
222 | 204 |
223 WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver>> m_observers; | |
224 | |
225 IntSize m_size; | 205 IntSize m_size; |
226 | 206 |
227 OwnPtrWillBeMember<CanvasRenderingContext> m_context; | 207 OwnPtrWillBeMember<CanvasRenderingContext> m_context; |
228 | 208 |
229 bool m_ignoreReset; | 209 bool m_ignoreReset; |
230 bool m_accelerationDisabled; | |
231 FloatRect m_dirtyRect; | 210 FloatRect m_dirtyRect; |
232 | 211 |
233 mutable intptr_t m_externallyAllocatedMemory; | 212 mutable intptr_t m_externallyAllocatedMemory; |
234 | 213 |
235 bool m_originClean; | 214 bool m_originClean; |
236 | 215 |
237 // It prevents HTMLCanvasElement::buffer() from continuously re-attempting t
o allocate an imageBuffer | 216 // It prevents HTMLCanvasElement::buffer() from continuously re-attempting t
o allocate an imageBuffer |
238 // after the first attempt failed. | 217 // after the first attempt failed. |
239 mutable bool m_didFailToCreateImageBuffer; | 218 mutable bool m_didFailToCreateImageBuffer; |
240 bool m_imageBufferIsClear; | 219 bool m_imageBufferIsClear; |
241 OwnPtr<ImageBuffer> m_imageBuffer; | 220 OwnPtr<ImageBuffer> m_imageBuffer; |
242 | 221 |
243 mutable RefPtr<Image> m_copiedImage; // FIXME: This is temporary for platfor
ms that have to copy the image buffer to render (and for CSSCanvasValue). | 222 mutable RefPtr<Image> m_copiedImage; // FIXME: This is temporary for platfor
ms that have to copy the image buffer to render (and for CSSCanvasValue). |
244 }; | 223 }; |
245 | 224 |
246 } // namespace blink | 225 } // namespace blink |
247 | 226 |
248 #endif // HTMLCanvasElement_h | 227 #endif // HTMLCanvasElement_h |
OLD | NEW |