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 #include "GraphicsContext.h"
35 #if USE(ACCELERATED_COMPOSITING)
36 #include "PlatformLayer.h"
38 #include "GraphicsTypes.h"
39 #include "GraphicsTypes3D.h"
41 #include "ImageBufferData.h"
42 #include <wtf/Forward.h>
43 #include <wtf/OwnPtr.h>
44 #include <wtf/PassOwnPtr.h>
45 #include <wtf/PassRefPtr.h>
46 #include <wtf/Uint8ClampedArray.h>
47 #include <wtf/Vector.h>
55 class GraphicsContext3D;
64 UnacceleratedNonPlatformBuffer, // Use plain memory allocation rather than platform API to allocate backing store.
68 enum BackingStoreCopy {
69 CopyBackingStore, // Guarantee subsequent draws don't affect the copy.
70 DontCopyBackingStore // Subsequent draws may affect the copy.
79 WTF_MAKE_NONCOPYABLE(ImageBuffer); WTF_MAKE_FAST_ALLOCATED;
81 // Will return a null pointer on allocation failure.
82 static PassOwnPtr<ImageBuffer> create(const IntSize& size, float resolutionScale = 1, ColorSpace colorSpace = ColorSpaceDeviceRGB, RenderingMode renderingMode = Unaccelerated, DeferralMode deferralMode = NonDeferred)
85 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(size, resolutionScale, colorSpace, renderingMode, deferralMode, success));
91 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
92 static PassOwnPtr<ImageBuffer> create(const void *device, const IntSize& size, ColorSpace colorSpace = ColorSpaceDeviceRGB, RenderingMode renderingMode = Unaccelerated)
95 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(device, size, colorSpace, renderingMode, success));
99 buf->m_logicalSize = size;
100 return buf.release();
106 // The actual resolution of the backing store
107 const IntSize& internalSize() const { return m_size; }
108 const IntSize& logicalSize() const { return m_logicalSize; }
110 GraphicsContext* context() const;
112 PassRefPtr<Image> copyImage(BackingStoreCopy = CopyBackingStore) const;
115 cairo_surface_t* getSurface() const { return m_data.m_surface; }
116 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
117 int getPlatformSurfaceID() const { return m_platformSurfaceID; }
121 #if ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
122 void swapPlatformSurfaces();
125 enum CoordinateSystem { LogicalCoordinateSystem, BackingStoreCoordinateSystem };
127 PassRefPtr<Uint8ClampedArray> getUnmultipliedImageData(const IntRect&, CoordinateSystem = LogicalCoordinateSystem) const;
128 PassRefPtr<Uint8ClampedArray> getPremultipliedImageData(const IntRect&, CoordinateSystem = LogicalCoordinateSystem) const;
130 void putByteArray(Multiply multiplied, Uint8ClampedArray*, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem = LogicalCoordinateSystem);
132 void convertToLuminanceMask();
134 String toDataURL(const String& mimeType, const double* quality = 0, CoordinateSystem = LogicalCoordinateSystem) const;
136 AffineTransform baseTransform() const { return AffineTransform(); }
137 void transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace);
138 void platformTransformColorSpace(const Vector<int>&);
140 AffineTransform baseTransform() const { return AffineTransform(1, 0, 0, -1, 0, internalSize().height()); }
142 #if USE(ACCELERATED_COMPOSITING)
143 PlatformLayer* platformLayer() const;
146 bool copyToPlatformTexture(GraphicsContext3D&, Platform3DObject, GC3Denum, bool, bool);
150 NativeImagePtr copyNativeImage(BackingStoreCopy = CopyBackingStore) const;
152 void clip(GraphicsContext*, const FloatRect&) const;
154 void draw(GraphicsContext*, ColorSpace, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1), CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
155 void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
157 inline void genericConvertToLuminanceMask();
159 friend class GraphicsContext;
160 friend class GeneratedImage;
161 friend class CrossfadeGeneratedImage;
162 friend class GeneratorGeneratedImage;
165 ImageBufferData m_data;
167 IntSize m_logicalSize;
168 float m_resolutionScale;
169 OwnPtr<GraphicsContext> m_context;
171 // This constructor will place its success into the given out-variable
172 // so that create() knows when it should return failure.
173 ImageBuffer(const IntSize&, float resolutionScale, ColorSpace, RenderingMode, DeferralMode, bool& success);
175 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING)
176 void clearPlatformSurface();
177 #if ENABLE(TIZEN_WEBKIT2)
178 static cairo_device_t* m_sharedCairoDevice;
180 void* m_nativeDisplay;
182 #endif // ENABLE(TIZEN_WEBKIT2)
183 #endif // ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING)
185 #if ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
186 ImageBuffer(const void *device, const IntSize&, ColorSpace colorSpace, RenderingMode renderingMode, bool& success);
187 void initializeEGL();
189 #if ENABLE(TIZEN_WEBKIT2)
190 static void* m_nativeDisplay;
191 static int m_nativeWindow;
192 static void* m_egl_display;
193 static void* m_egl_config;
194 #endif // ENABLE(TIZEN_WEBKIT2)
196 int m_platformSurfaceID;
198 #endif // ENABLE(TIZEN_CANVAS_CAIRO_GLES_RENDERING) || ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
200 #if ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
201 bool lockSurface() const;
202 PassRefPtr<cairo_surface_t> querySurface() const;
203 bool unlockSurface() const;
204 #endif // ENABLE(TIZEN_CANVAS_SURFACE_LOCKING)
207 #if USE(CG) || USE(SKIA)
208 String ImageDataToDataURL(const ImageData&, const String& mimeType, const double* quality);
211 } // namespace WebCore
213 #endif // ImageBuffer_h