| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 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 11 matching lines...) Expand all Loading... |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #ifndef ImageBuffer_h | 28 #ifndef ImageBuffer_h |
| 29 #define ImageBuffer_h | 29 #define ImageBuffer_h |
| 30 | 30 |
| 31 #include "core/platform/graphics/GraphicsContext.h" | 31 #include "core/platform/graphics/GraphicsContext.h" |
| 32 #include "core/platform/graphics/Canvas2DLayerBridge.h" | |
| 33 #include "platform/geometry/FloatRect.h" | 32 #include "platform/geometry/FloatRect.h" |
| 34 #include "platform/geometry/IntSize.h" | |
| 35 #include "platform/graphics/ColorSpace.h" | 33 #include "platform/graphics/ColorSpace.h" |
| 36 #include "platform/graphics/GraphicsTypes.h" | 34 #include "platform/graphics/GraphicsTypes.h" |
| 37 #include "platform/graphics/GraphicsTypes3D.h" | 35 #include "platform/graphics/GraphicsTypes3D.h" |
| 36 #include "platform/graphics/ImageBufferSurface.h" |
| 38 #include "platform/transforms/AffineTransform.h" | 37 #include "platform/transforms/AffineTransform.h" |
| 39 #include "wtf/Forward.h" | 38 #include "wtf/Forward.h" |
| 40 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
| 41 #include "wtf/PassOwnPtr.h" | 40 #include "wtf/PassOwnPtr.h" |
| 42 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
| 43 #include "wtf/Uint8ClampedArray.h" | 42 #include "wtf/Uint8ClampedArray.h" |
| 44 #include "wtf/Vector.h" | 43 #include "wtf/Vector.h" |
| 45 | 44 |
| 46 class SkCanvas; | 45 class SkCanvas; |
| 47 | 46 |
| 48 namespace blink { class WebLayer; } | |
| 49 | |
| 50 namespace WebCore { | 47 namespace WebCore { |
| 51 | 48 |
| 49 class DrawingBuffer; |
| 50 class GraphicsContext3D; |
| 52 class Image; | 51 class Image; |
| 53 class IntPoint; | 52 class IntPoint; |
| 54 class IntRect; | 53 class IntRect; |
| 55 class GraphicsContext3D; | |
| 56 | 54 |
| 57 enum Multiply { | 55 enum Multiply { |
| 58 Premultiplied, | 56 Premultiplied, |
| 59 Unmultiplied | 57 Unmultiplied |
| 60 }; | 58 }; |
| 61 | 59 |
| 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 { | 60 enum BackingStoreCopy { |
| 70 CopyBackingStore, // Guarantee subsequent draws don't affect the copy. | 61 CopyBackingStore, // Guarantee subsequent draws don't affect the copy. |
| 71 DontCopyBackingStore // Subsequent draws may affect the copy. | 62 DontCopyBackingStore // Subsequent draws may affect the copy. |
| 72 }; | 63 }; |
| 73 | 64 |
| 74 enum ScaleBehavior { | 65 enum ScaleBehavior { |
| 75 Scaled, | 66 Scaled, |
| 76 Unscaled | 67 Unscaled |
| 77 }; | 68 }; |
| 78 | 69 |
| 79 enum OpacityMode { | |
| 80 NonOpaque, | |
| 81 Opaque, | |
| 82 }; | |
| 83 | |
| 84 class ImageBuffer { | 70 class ImageBuffer { |
| 85 WTF_MAKE_NONCOPYABLE(ImageBuffer); WTF_MAKE_FAST_ALLOCATED; | 71 WTF_MAKE_NONCOPYABLE(ImageBuffer); WTF_MAKE_FAST_ALLOCATED; |
| 86 public: | 72 public: |
| 87 // Will return a null pointer on allocation failure. | 73 ImageBuffer(PassOwnPtr<ImageBufferSurface>); |
| 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(); | 74 ~ImageBuffer(); |
| 103 | 75 |
| 104 // The actual resolution of the backing store | 76 // The actual resolution of the backing store |
| 105 const IntSize& internalSize() const { return m_size; } | 77 const IntSize& internalSize() const { return m_surface->size(); } |
| 106 const IntSize& logicalSize() const { return m_logicalSize; } | 78 const IntSize& logicalSize() const { return m_surface->size(); } |
| 107 | 79 |
| 108 GraphicsContext* context() const; | 80 GraphicsContext* context() const; |
| 109 | 81 |
| 110 PassRefPtr<Image> copyImage(BackingStoreCopy = CopyBackingStore, ScaleBehavi
or = Scaled) const; | 82 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 | 83 // Give hints on the faster copyImage Mode, return DontCopyBackingStore if i
t supports the DontCopyBackingStore behavior |
| 112 // or return CopyBackingStore if it doesn't. | 84 // or return CopyBackingStore if it doesn't. |
| 113 static BackingStoreCopy fastCopyImageMode(); | 85 static BackingStoreCopy fastCopyImageMode(); |
| 114 | 86 |
| 115 enum CoordinateSystem { LogicalCoordinateSystem, BackingStoreCoordinateSyste
m }; | 87 enum CoordinateSystem { LogicalCoordinateSystem, BackingStoreCoordinateSyste
m }; |
| 116 | 88 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 138 void draw(GraphicsContext*, const FloatRect&, const FloatRect& = FloatRect(0
, 0, -1, -1), CompositeOperator = CompositeSourceOver, blink::WebBlendMode = bli
nk::WebBlendModeNormal, bool useLowQualityScale = false); | 110 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()); | 111 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); | 112 static PassRefPtr<SkColorFilter> createColorSpaceFilter(ColorSpace srcColorS
pace, ColorSpace dstColorSpace); |
| 141 | 113 |
| 142 friend class GraphicsContext; | 114 friend class GraphicsContext; |
| 143 friend class GeneratedImage; | 115 friend class GeneratedImage; |
| 144 friend class CrossfadeGeneratedImage; | 116 friend class CrossfadeGeneratedImage; |
| 145 friend class GradientGeneratedImage; | 117 friend class GradientGeneratedImage; |
| 146 friend class SkiaImageFilterBuilder; | 118 friend class SkiaImageFilterBuilder; |
| 147 | 119 |
| 148 IntSize m_size; | 120 OwnPtr<ImageBufferSurface> m_surface; |
| 149 IntSize m_logicalSize; | |
| 150 float m_resolutionScale; | |
| 151 RefPtr<SkCanvas> m_canvas; | |
| 152 OwnPtr<GraphicsContext> m_context; | 121 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 }; | 122 }; |
| 160 | 123 |
| 161 struct ImageDataBuffer { | 124 struct ImageDataBuffer { |
| 162 ImageDataBuffer(const IntSize& size, PassRefPtr<Uint8ClampedArray> data) : m
_size(size), m_data(data) { } | 125 ImageDataBuffer(const IntSize& size, PassRefPtr<Uint8ClampedArray> data) : m
_size(size), m_data(data) { } |
| 163 IntSize size() const { return m_size; } | 126 IntSize size() const { return m_size; } |
| 164 unsigned char* data() const { return m_data->data(); } | 127 unsigned char* data() const { return m_data->data(); } |
| 165 | 128 |
| 166 IntSize m_size; | 129 IntSize m_size; |
| 167 RefPtr<Uint8ClampedArray> m_data; | 130 RefPtr<Uint8ClampedArray> m_data; |
| 168 }; | 131 }; |
| 169 | 132 |
| 170 String ImageDataToDataURL(const ImageDataBuffer&, const String& mimeType, const
double* quality); | 133 String ImageDataToDataURL(const ImageDataBuffer&, const String& mimeType, const
double* quality); |
| 171 | 134 |
| 172 } // namespace WebCore | 135 } // namespace WebCore |
| 173 | 136 |
| 174 #endif // ImageBuffer_h | 137 #endif // ImageBuffer_h |
| OLD | NEW |