| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved. | |
| 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | |
| 5 * | |
| 6 * Redistribution and use in source and binary forms, with or without | |
| 7 * modification, are permitted provided that the following conditions | |
| 8 * are met: | |
| 9 * 1. Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | |
| 12 * notice, this list of conditions and the following disclaimer in the | |
| 13 * documentation and/or other materials provided with the distribution. | |
| 14 * | |
| 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | |
| 28 #ifndef SKY_ENGINE_CORE_HTML_HTMLCANVASELEMENT_H_ | |
| 29 #define SKY_ENGINE_CORE_HTML_HTMLCANVASELEMENT_H_ | |
| 30 | |
| 31 #include "base/cancelable_callback.h" | |
| 32 #include "sky/engine/core/dom/Document.h" | |
| 33 #include "sky/engine/core/html/HTMLElement.h" | |
| 34 #include "sky/engine/core/html/canvas/CanvasImageSource.h" | |
| 35 #include "sky/engine/platform/geometry/FloatRect.h" | |
| 36 #include "sky/engine/platform/geometry/IntSize.h" | |
| 37 #include "sky/engine/platform/graphics/Canvas2DLayerBridge.h" | |
| 38 #include "sky/engine/platform/graphics/GraphicsTypes.h" | |
| 39 #include "sky/engine/platform/graphics/ImageBufferClient.h" | |
| 40 #include "sky/engine/platform/heap/Handle.h" | |
| 41 #include "sky/engine/public/platform/WebThread.h" | |
| 42 #include "sky/engine/wtf/Forward.h" | |
| 43 | |
| 44 #define CanvasDefaultInterpolationQuality InterpolationLow | |
| 45 | |
| 46 namespace blink { | |
| 47 | |
| 48 class AffineTransform; | |
| 49 class CanvasContextAttributes; | |
| 50 class CanvasRenderingContext; | |
| 51 class GraphicsContext; | |
| 52 class GraphicsContextStateSaver; | |
| 53 class HTMLCanvasElement; | |
| 54 class Image; | |
| 55 class ImageData; | |
| 56 class ImageBuffer; | |
| 57 class ImageBufferSurface; | |
| 58 class IntSize; | |
| 59 | |
| 60 class CanvasObserver { | |
| 61 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(CanvasObserver); | |
| 62 public: | |
| 63 virtual void canvasChanged(HTMLCanvasElement*, const FloatRect& changedRect)
= 0; | |
| 64 virtual void canvasResized(HTMLCanvasElement*) = 0; | |
| 65 #if !ENABLE(OILPAN) | |
| 66 virtual void canvasDestroyed(HTMLCanvasElement*) = 0; | |
| 67 #endif | |
| 68 }; | |
| 69 | |
| 70 class HTMLCanvasElement final : public HTMLElement, public CanvasImageSource, pu
blic ImageBufferClient { | |
| 71 DEFINE_WRAPPERTYPEINFO(); | |
| 72 public: | |
| 73 DECLARE_NODE_FACTORY(HTMLCanvasElement); | |
| 74 virtual ~HTMLCanvasElement(); | |
| 75 | |
| 76 void addObserver(CanvasObserver*); | |
| 77 void removeObserver(CanvasObserver*); | |
| 78 | |
| 79 // Attributes and functions exposed to script | |
| 80 int width() const { return size().width(); } | |
| 81 int height() const { return size().height(); } | |
| 82 | |
| 83 const IntSize& size() const { return m_size; } | |
| 84 | |
| 85 void setWidth(int); | |
| 86 void setHeight(int); | |
| 87 void setAccelerationDisabled(bool accelerationDisabled) { m_accelerationDisa
bled = accelerationDisabled; } | |
| 88 bool accelerationDisabled() const { return m_accelerationDisabled; } | |
| 89 | |
| 90 void setSize(const IntSize& newSize) | |
| 91 { | |
| 92 if (newSize == size()) | |
| 93 return; | |
| 94 m_ignoreReset = true; | |
| 95 setWidth(newSize.width()); | |
| 96 setHeight(newSize.height()); | |
| 97 m_ignoreReset = false; | |
| 98 reset(); | |
| 99 } | |
| 100 | |
| 101 CanvasRenderingContext2D* getContext(const String&, CanvasContextAttributes*
attributes = 0); | |
| 102 | |
| 103 static String toEncodingMimeType(const String& mimeType); | |
| 104 String toDataURL(const String& mimeType, const double* quality, ExceptionSta
te&) const; | |
| 105 String toDataURL(const String& mimeType, ExceptionState& exceptionState) con
st { return toDataURL(mimeType, 0, exceptionState); } | |
| 106 | |
| 107 // Used for rendering | |
| 108 void didDraw(const FloatRect&); | |
| 109 void notifyObserversCanvasChanged(const FloatRect&); | |
| 110 | |
| 111 void paint(GraphicsContext*, const LayoutRect&); | |
| 112 | |
| 113 GraphicsContext* drawingContext() const; | |
| 114 GraphicsContext* existingDrawingContext() const; | |
| 115 | |
| 116 CanvasRenderingContext* renderingContext() const { return m_context.get(); } | |
| 117 | |
| 118 void ensureUnacceleratedImageBuffer(); | |
| 119 ImageBuffer* buffer() const; | |
| 120 Image* copiedImage() const; | |
| 121 void clearCopiedImage(); | |
| 122 PassRefPtr<ImageData> getImageData() const; | |
| 123 void makePresentationCopy(); | |
| 124 void clearPresentationCopy(); | |
| 125 | |
| 126 AffineTransform baseTransform() const; | |
| 127 | |
| 128 bool is3D() const; | |
| 129 | |
| 130 bool hasImageBuffer() const { return m_imageBuffer; } | |
| 131 bool hasValidImageBuffer() const; | |
| 132 void discardImageBuffer(); | |
| 133 | |
| 134 bool shouldAccelerate(const IntSize&) const; | |
| 135 | |
| 136 virtual const AtomicString imageSourceURL() const override; | |
| 137 | |
| 138 // CanvasImageSource implementation | |
| 139 virtual PassRefPtr<Image> getSourceImageForCanvas(SourceImageMode, SourceIma
geStatus*) const override; | |
| 140 virtual FloatSize sourceSize() const override; | |
| 141 | |
| 142 // ImageBufferClient implementation | |
| 143 virtual void notifySurfaceInvalid() override; | |
| 144 virtual bool isDirty() override { return !m_dirtyRect.isEmpty(); } | |
| 145 virtual void didFinalizeFrame() override; | |
| 146 | |
| 147 private: | |
| 148 explicit HTMLCanvasElement(Document&); | |
| 149 | |
| 150 virtual void parseAttribute(const QualifiedName&, const AtomicString&) overr
ide; | |
| 151 virtual RenderObject* createRenderer(RenderStyle*) override; | |
| 152 | |
| 153 void finalizeFrameMicrotask(); | |
| 154 | |
| 155 void reset(); | |
| 156 | |
| 157 PassOwnPtr<ImageBufferSurface> createImageBufferSurface(const IntSize& devic
eSize, int* msaaSampleCount); | |
| 158 void createImageBuffer(); | |
| 159 void createImageBufferInternal(); | |
| 160 void clearImageBuffer(); | |
| 161 | |
| 162 void resetDirtyRect(); | |
| 163 | |
| 164 void setSurfaceSize(const IntSize&); | |
| 165 | |
| 166 bool paintsIntoCanvasBuffer() const; | |
| 167 | |
| 168 void updateExternallyAllocatedMemory() const; | |
| 169 | |
| 170 String toDataURLInternal(const String& mimeType, const double* quality, bool
isSaving = false) const; | |
| 171 | |
| 172 HashSet<RawPtr<CanvasObserver> > m_observers; | |
| 173 | |
| 174 IntSize m_size; | |
| 175 | |
| 176 OwnPtr<CanvasRenderingContext> m_context; | |
| 177 | |
| 178 bool m_ignoreReset; | |
| 179 bool m_accelerationDisabled; | |
| 180 // FIXME(sky): Do we need this in sky since we don't do paint invalidation? | |
| 181 FloatRect m_dirtyRect; | |
| 182 base::CancelableClosure m_finalizeFrameTask; | |
| 183 | |
| 184 mutable intptr_t m_externallyAllocatedMemory; | |
| 185 | |
| 186 // It prevents HTMLCanvasElement::buffer() from continuously re-attempting t
o allocate an imageBuffer | |
| 187 // after the first attempt failed. | |
| 188 mutable bool m_didFailToCreateImageBuffer; | |
| 189 mutable bool m_didClearImageBuffer; | |
| 190 OwnPtr<ImageBuffer> m_imageBuffer; | |
| 191 mutable OwnPtr<GraphicsContextStateSaver> m_contextStateSaver; | |
| 192 | |
| 193 mutable RefPtr<Image> m_presentedImage; | |
| 194 mutable RefPtr<Image> m_copiedImage; // FIXME: This is temporary for platfor
ms that have to copy the image buffer to render. | |
| 195 }; | |
| 196 | |
| 197 } // namespace blink | |
| 198 | |
| 199 #endif // SKY_ENGINE_CORE_HTML_HTMLCANVASELEMENT_H_ | |
| OLD | NEW |