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