15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef ImageBuffer_h 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ImageBuffer_h 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 31a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/PlatformExport.h" 321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/geometry/FloatRect.h" 331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/geometry/IntSize.h" 34a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/Canvas2DLayerBridge.h" 35f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/graphics/ColorSpace.h" 36f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/graphics/GraphicsTypes.h" 37f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/graphics/GraphicsTypes3D.h" 38a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/ImageBufferSurface.h" 391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/transforms/AffineTransform.h" 40591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/Forward.h" 41591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/OwnPtr.h" 42591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/PassOwnPtr.h" 43591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/PassRefPtr.h" 44591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "wtf/Uint8ClampedArray.h" 45591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)namespace blink { 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 48a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class DrawingBuffer; 495d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)class GraphicsContext; 50591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochclass Image; 51aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdochclass ImageBufferClient; 52591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochclass IntPoint; 53591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochclass IntRect; 54e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)class WebGraphicsContext3D; 55591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 56591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochenum Multiply { 57591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch Premultiplied, 58591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch Unmultiplied 59591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch}; 60591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 61591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochenum BackingStoreCopy { 62591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch CopyBackingStore, // Guarantee subsequent draws don't affect the copy. 63591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch DontCopyBackingStore // Subsequent draws may affect the copy. 64591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch}; 65591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 66591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochenum ScaleBehavior { 67591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch Scaled, 68591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch Unscaled 69591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch}; 70591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 71a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class PLATFORM_EXPORT ImageBuffer { 72591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch WTF_MAKE_NONCOPYABLE(ImageBuffer); WTF_MAKE_FAST_ALLOCATED; 73591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochpublic: 74a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) static PassOwnPtr<ImageBuffer> create(const IntSize&, OpacityMode = NonOpaque); 75a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) static PassOwnPtr<ImageBuffer> create(PassOwnPtr<ImageBufferSurface>); 7651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 77591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch ~ImageBuffer(); 78591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 79aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch void setClient(ImageBufferClient* client) { m_client = client; } 80aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch 81a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) const IntSize& size() const { return m_surface->size(); } 8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) bool isAccelerated() const { return m_surface->isAccelerated(); } 83aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch bool isSurfaceValid() const; 84aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch bool restoreSurface() const; 8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setIsHidden(bool hidden) { m_surface->setIsHidden(hidden); } 87591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 88591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch GraphicsContext* context() const; 89591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 90c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) // Called at the end of a task that rendered a whole frame 917242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci void finalizeFrame(const FloatRect &dirtyRect); 92c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) void didFinalizeFrame(); 93c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 94c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) bool isDirty(); 95c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 9609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const SkBitmap& bitmap() const; 9709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 98591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch PassRefPtr<Image> copyImage(BackingStoreCopy = CopyBackingStore, ScaleBehavior = Scaled) const; 99591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch // Give hints on the faster copyImage Mode, return DontCopyBackingStore if it supports the DontCopyBackingStore behavior 100591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch // or return CopyBackingStore if it doesn't. 101591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch static BackingStoreCopy fastCopyImageMode(); 102591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 103197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch PassRefPtr<Uint8ClampedArray> getImageData(Multiply, const IntRect&) const; 104591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 105197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch void putByteArray(Multiply, Uint8ClampedArray*, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint); 106591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 107a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) String toDataURL(const String& mimeType, const double* quality = 0) const; 108591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch AffineTransform baseTransform() const { return AffineTransform(); } 109591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch void transformColorSpace(ColorSpace srcColorSpace, ColorSpace dstColorSpace); 110e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) WebLayer* platformLayer() const; 111591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 112591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch // FIXME: current implementations of this method have the restriction that they only work 113591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch // with textures that are RGB or RGBA format, UNSIGNED_BYTE type and level 0, as specified in 114591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch // Extensions3D::canUseCopyTextureCHROMIUM(). 11543e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) // Destroys the TEXTURE_2D binding for the active texture unit of the passed context 116e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) bool copyToPlatformTexture(WebGraphicsContext3D*, Platform3DObject, GLenum, GLenum, GLint, bool, bool); 117591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 11851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) Platform3DObject getBackingTexture(); 1197242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci void didModifyBackingTexture(); 12043e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) 1215d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) bool copyRenderingResultsFromDrawingBuffer(DrawingBuffer*, bool fromFrontBuffer = false); 12251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 123a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void flush(); 124a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 125aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch void notifySurfaceInvalid(); 126aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch 127591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochprivate: 128a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) ImageBuffer(PassOwnPtr<ImageBufferSurface>); 129fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch 130c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) void draw(GraphicsContext*, const FloatRect&, const FloatRect* = 0, CompositeOperator = CompositeSourceOver, WebBlendMode = WebBlendModeNormal); 131e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) void drawPattern(GraphicsContext*, const FloatRect&, const FloatSize&, const FloatPoint&, CompositeOperator, const FloatRect&, WebBlendMode, const IntSize& repeatSpacing = IntSize()); 132c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) static PassRefPtr<SkColorFilter> createColorSpaceFilter(ColorSpace srcColorSpace, ColorSpace dstColorSpace); 133591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 134591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch friend class GraphicsContext; 135591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch friend class GeneratedImage; 136591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch friend class CrossfadeGeneratedImage; 137bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) friend class GradientGeneratedImage; 138c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) friend class SkiaImageFilterBuilder; 139591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 140a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) OwnPtr<ImageBufferSurface> m_surface; 141591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch OwnPtr<GraphicsContext> m_context; 142aafa69cb17c9d6606c07663ade5f81388a2c5986Ben Murdoch ImageBufferClient* m_client; 143591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch}; 144591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 14551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)struct ImageDataBuffer { 14651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ImageDataBuffer(const IntSize& size, PassRefPtr<Uint8ClampedArray> data) : m_size(size), m_data(data) { } 14751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) IntSize size() const { return m_size; } 14851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) unsigned char* data() const { return m_data->data(); } 14951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 15051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) IntSize m_size; 15151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) RefPtr<Uint8ClampedArray> m_data; 15251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}; 15351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 154a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)String PLATFORM_EXPORT ImageDataToDataURL(const ImageDataBuffer&, const String& mimeType, const double* quality); 1555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 156c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 1575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // ImageBuffer_h 159