| OLD | NEW |
| (Empty) |
| 1 /* | |
| 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. | |
| 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 ImageBuffer_h | |
| 29 #define ImageBuffer_h | |
| 30 | |
| 31 #include "core/platform/graphics/GraphicsContext.h" | |
| 32 #include "core/platform/graphics/Canvas2DLayerBridge.h" | |
| 33 #include "platform/geometry/FloatRect.h" | |
| 34 #include "platform/geometry/IntSize.h" | |
| 35 #include "platform/graphics/ColorSpace.h" | |
| 36 #include "platform/graphics/GraphicsTypes.h" | |
| 37 #include "platform/graphics/GraphicsTypes3D.h" | |
| 38 #include "platform/transforms/AffineTransform.h" | |
| 39 #include "wtf/Forward.h" | |
| 40 #include "wtf/OwnPtr.h" | |
| 41 #include "wtf/PassOwnPtr.h" | |
| 42 #include "wtf/PassRefPtr.h" | |
| 43 #include "wtf/Uint8ClampedArray.h" | |
| 44 #include "wtf/Vector.h" | |
| 45 | |
| 46 class SkCanvas; | |
| 47 | |
| 48 namespace blink { class WebLayer; } | |
| 49 | |
| 50 namespace WebCore { | |
| 51 | |
| 52 class Image; | |
| 53 class IntPoint; | |
| 54 class IntRect; | |
| 55 class GraphicsContext3D; | |
| 56 | |
| 57 enum Multiply { | |
| 58 Premultiplied, | |
| 59 Unmultiplied | |
| 60 }; | |
| 61 | |
| 62 enum RenderingMode { | |
| 63 Unaccelerated, | |
| 64 UnacceleratedNonPlatformBuffer, // Use plain memory allocation rather than p
latform API to allocate backing store. | |
| 65 TextureBacked, // Allocate a texture-based SkBitmap for the backing store. | |
| 66 Accelerated, // Besides a texture-based SkBitmap for the backing store, allo
cate Canvas2DLayerBridge, etc as well for 2D Canvas drawing. | |
| 67 }; | |
| 68 | |
| 69 enum BackingStoreCopy { | |
| 70 CopyBackingStore, // Guarantee subsequent draws don't affect the copy. | |
| 71 DontCopyBackingStore // Subsequent draws may affect the copy. | |
| 72 }; | |
| 73 | |
| 74 enum ScaleBehavior { | |
| 75 Scaled, | |
| 76 Unscaled | |
| 77 }; | |
| 78 | |
| 79 enum OpacityMode { | |
| 80 NonOpaque, | |
| 81 Opaque, | |
| 82 }; | |
| 83 | |
| 84 class ImageBuffer { | |
| 85 WTF_MAKE_NONCOPYABLE(ImageBuffer); WTF_MAKE_FAST_ALLOCATED; | |
| 86 public: | |
| 87 // Will return a null pointer on allocation failure. | |
| 88 static PassOwnPtr<ImageBuffer> create(const IntSize& size, float resolutionS
cale = 1, RenderingMode renderingMode = Unaccelerated, OpacityMode opacityMode =
NonOpaque, int acceleratedMSAASampleCount = 0) | |
| 89 { | |
| 90 bool success = false; | |
| 91 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(size, resolutionScale
, renderingMode, opacityMode, acceleratedMSAASampleCount, success)); | |
| 92 if (!success) | |
| 93 return nullptr; | |
| 94 return buf.release(); | |
| 95 } | |
| 96 | |
| 97 static PassOwnPtr<ImageBuffer> createCompatibleBuffer(const IntSize&, float
resolutionScale, const GraphicsContext*, bool hasAlpha); | |
| 98 | |
| 99 // Tiles may need float-to-integer coordinate mapping. | |
| 100 static PassOwnPtr<ImageBuffer> createBufferForTile(const FloatSize& tileSize
, const FloatSize& clampedTileSize, RenderingMode); | |
| 101 | |
| 102 ~ImageBuffer(); | |
| 103 | |
| 104 // The actual resolution of the backing store | |
| 105 const IntSize& internalSize() const { return m_size; } | |
| 106 const IntSize& logicalSize() const { return m_logicalSize; } | |
| 107 | |
| 108 GraphicsContext* context() const; | |
| 109 | |
| 110 PassRefPtr<Image> copyImage(BackingStoreCopy = CopyBackingStore, ScaleBehavi
or = Scaled) const; | |
| 111 // Give hints on the faster copyImage Mode, return DontCopyBackingStore if i
t supports the DontCopyBackingStore behavior | |
| 112 // or return CopyBackingStore if it doesn't. | |
| 113 static BackingStoreCopy fastCopyImageMode(); | |
| 114 | |
| 115 enum CoordinateSystem { LogicalCoordinateSystem, BackingStoreCoordinateSyste
m }; | |
| 116 | |
| 117 PassRefPtr<Uint8ClampedArray> getUnmultipliedImageData(const IntRect&, Coord
inateSystem = LogicalCoordinateSystem) const; | |
| 118 PassRefPtr<Uint8ClampedArray> getPremultipliedImageData(const IntRect&, Coor
dinateSystem = LogicalCoordinateSystem) const; | |
| 119 | |
| 120 void putByteArray(Multiply multiplied, Uint8ClampedArray*, const IntSize& so
urceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem
= LogicalCoordinateSystem); | |
| 121 | |
| 122 String toDataURL(const String& mimeType, const double* quality = 0, Coordina
teSystem = LogicalCoordinateSystem) const; | |
| 123 AffineTransform baseTransform() const { return AffineTransform(); } | |
| 124 void transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace)
; | |
| 125 blink::WebLayer* platformLayer() const; | |
| 126 | |
| 127 // FIXME: current implementations of this method have the restriction that t
hey only work | |
| 128 // with textures that are RGB or RGBA format, UNSIGNED_BYTE type and level 0
, as specified in | |
| 129 // Extensions3D::canUseCopyTextureCHROMIUM(). | |
| 130 bool copyToPlatformTexture(GraphicsContext3D&, Platform3DObject, GC3Denum, G
C3Denum, GC3Dint, bool, bool); | |
| 131 | |
| 132 Platform3DObject getBackingTexture(); | |
| 133 bool copyRenderingResultsFromDrawingBuffer(DrawingBuffer*); | |
| 134 | |
| 135 private: | |
| 136 bool isValid() const; | |
| 137 | |
| 138 void draw(GraphicsContext*, const FloatRect&, const FloatRect& = FloatRect(0
, 0, -1, -1), CompositeOperator = CompositeSourceOver, blink::WebBlendMode = bli
nk::WebBlendModeNormal, bool useLowQualityScale = false); | |
| 139 void drawPattern(GraphicsContext*, const FloatRect&, const FloatSize&, const
FloatPoint&, CompositeOperator, const FloatRect&, blink::WebBlendMode, const In
tSize& repeatSpacing = IntSize()); | |
| 140 static PassRefPtr<SkColorFilter> createColorSpaceFilter(ColorSpace srcColorS
pace, ColorSpace dstColorSpace); | |
| 141 | |
| 142 friend class GraphicsContext; | |
| 143 friend class GeneratedImage; | |
| 144 friend class CrossfadeGeneratedImage; | |
| 145 friend class GradientGeneratedImage; | |
| 146 friend class SkiaImageFilterBuilder; | |
| 147 | |
| 148 IntSize m_size; | |
| 149 IntSize m_logicalSize; | |
| 150 float m_resolutionScale; | |
| 151 RefPtr<SkCanvas> m_canvas; | |
| 152 OwnPtr<GraphicsContext> m_context; | |
| 153 Canvas2DLayerBridgePtr m_layerBridge; | |
| 154 | |
| 155 // This constructor will place its success into the given out-variable | |
| 156 // so that create() knows when it should return failure. | |
| 157 ImageBuffer(const IntSize&, float resolutionScale, RenderingMode, OpacityMod
e, int acceleratedSampleCount, bool& success); | |
| 158 ImageBuffer(const IntSize&, float resolutionScale, const GraphicsContext*, b
ool hasAlpha, bool& success); | |
| 159 }; | |
| 160 | |
| 161 struct ImageDataBuffer { | |
| 162 ImageDataBuffer(const IntSize& size, PassRefPtr<Uint8ClampedArray> data) : m
_size(size), m_data(data) { } | |
| 163 IntSize size() const { return m_size; } | |
| 164 unsigned char* data() const { return m_data->data(); } | |
| 165 | |
| 166 IntSize m_size; | |
| 167 RefPtr<Uint8ClampedArray> m_data; | |
| 168 }; | |
| 169 | |
| 170 String ImageDataToDataURL(const ImageDataBuffer&, const String& mimeType, const
double* quality); | |
| 171 | |
| 172 } // namespace WebCore | |
| 173 | |
| 174 #endif // ImageBuffer_h | |
| OLD | NEW |