2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
31 #include "AffineTransform.h"
32 #include "ColorSpace.h"
33 #include "FloatRect.h"
34 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
35 #include "GLPlatformSurface.h"
37 #include "GraphicsContext.h"
38 #if USE(ACCELERATED_COMPOSITING)
39 #include "PlatformLayer.h"
41 #include "GraphicsTypes.h"
42 #include "GraphicsTypes3D.h"
44 #include "ImageBufferData.h"
45 #include <wtf/Forward.h>
46 #include <wtf/OwnPtr.h>
47 #include <wtf/PassOwnPtr.h>
48 #include <wtf/PassRefPtr.h>
49 #include <wtf/Uint8ClampedArray.h>
50 #include <wtf/Vector.h>
58 class GraphicsContext3D;
67 UnacceleratedNonPlatformBuffer, // Use plain memory allocation rather than platform API to allocate backing store.
69 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
70 , AcceleratedMemorySaving
73 enum BackingStoreCopy {
74 CopyBackingStore, // Guarantee subsequent draws don't affect the copy.
75 DontCopyBackingStore // Subsequent draws may affect the copy.
84 WTF_MAKE_NONCOPYABLE(ImageBuffer); WTF_MAKE_FAST_ALLOCATED;
86 // Will return a null pointer on allocation failure.
87 static PassOwnPtr<ImageBuffer> create(const IntSize& size, float resolutionScale = 1, ColorSpace colorSpace = ColorSpaceDeviceRGB, RenderingMode renderingMode = Unaccelerated, DeferralMode deferralMode = NonDeferred)
90 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(size, resolutionScale, colorSpace, renderingMode, deferralMode, success));
98 // The actual resolution of the backing store
99 const IntSize& internalSize() const { return m_size; }
100 const IntSize& logicalSize() const { return m_logicalSize; }
102 GraphicsContext* context() const;
104 PassRefPtr<Image> copyImage(BackingStoreCopy = CopyBackingStore) const;
107 cairo_surface_t* getSurface() const { return m_data.m_surface; }
110 enum CoordinateSystem { LogicalCoordinateSystem, BackingStoreCoordinateSystem };
112 PassRefPtr<Uint8ClampedArray> getUnmultipliedImageData(const IntRect&, CoordinateSystem = LogicalCoordinateSystem) const;
113 PassRefPtr<Uint8ClampedArray> getPremultipliedImageData(const IntRect&, CoordinateSystem = LogicalCoordinateSystem) const;
115 void putByteArray(Multiply multiplied, Uint8ClampedArray*, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem = LogicalCoordinateSystem);
116 void convertToLuminanceMask();
117 String toDataURL(const String& mimeType, const double* quality = 0, CoordinateSystem = LogicalCoordinateSystem) const;
119 AffineTransform baseTransform() const { return AffineTransform(); }
120 void transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace);
121 void platformTransformColorSpace(const Vector<int>&);
123 AffineTransform baseTransform() const { return AffineTransform(1, 0, 0, -1, 0, internalSize().height()); }
125 #if USE(ACCELERATED_COMPOSITING)
126 PlatformLayer* platformLayer() const;
129 bool copyToPlatformTexture(GraphicsContext3D&, Platform3DObject, GC3Denum, bool, bool);
130 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
131 PlatformBufferHandle getPlatformSurfaceID() const { return m_offScreenSurface->handle(); }
132 bool isLockable() const { return m_isLockable; }
133 void swapPlatformSurfaces();
138 NativeImagePtr copyNativeImage(BackingStoreCopy = CopyBackingStore) const;
140 void clip(GraphicsContext*, const FloatRect&) const;
142 void draw(GraphicsContext*, ColorSpace, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1), CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
143 void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
145 inline void genericConvertToLuminanceMask();
147 friend class GraphicsContext;
148 friend class GeneratedImage;
149 friend class CrossfadeGeneratedImage;
150 friend class GeneratorGeneratedImage;
153 ImageBufferData m_data;
155 IntSize m_logicalSize;
156 float m_resolutionScale;
157 OwnPtr<GraphicsContext> m_context;
159 // This constructor will place its success into the given out-variable
160 // so that create() knows when it should return failure.
161 ImageBuffer(const IntSize&, float resolutionScale, ColorSpace, RenderingMode, DeferralMode, bool& success);
163 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
164 void initializeEGL();
166 bool lockSurface() const;
167 PassRefPtr<cairo_surface_t> querySurface() const;
168 bool unlockSurface() const;
170 OwnPtr<GLPlatformSurface> m_offScreenSurface;
171 #endif // ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
175 #if USE(CG) || USE(SKIA)
176 String ImageDataToDataURL(const ImageData&, const String& mimeType, const double* quality);
179 } // namespace WebCore
181 #endif // ImageBuffer_h