1/* 2 Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20#ifndef TextureMapperImageBuffer_h 21#define TextureMapperImageBuffer_h 22 23#include "ImageBuffer.h" 24#include "TextureMapper.h" 25 26#if USE(TEXTURE_MAPPER) 27namespace WebCore { 28 29class BitmapTextureImageBuffer : public BitmapTexture { 30 friend class TextureMapperImageBuffer; 31public: 32 static PassRefPtr<BitmapTexture> create() { return adoptRef(new BitmapTextureImageBuffer); } 33 virtual IntSize size() const { return m_image->internalSize(); } 34 virtual void didReset(); 35 virtual bool isValid() const { return m_image.get(); } 36 inline GraphicsContext* graphicsContext() { return m_image ? m_image->context() : 0; } 37 virtual void updateContents(Image*, const IntRect&, const IntPoint&, UpdateContentsFlag); 38 virtual void updateContents(TextureMapper*, GraphicsLayer*, const IntRect& target, const IntPoint& offset, UpdateContentsFlag); 39 virtual void updateContents(const void*, const IntRect& target, const IntPoint& sourceOffset, int bytesPerLine, UpdateContentsFlag); 40#if ENABLE(CSS_FILTERS) 41 PassRefPtr<BitmapTexture> applyFilters(TextureMapper*, const FilterOperations&); 42#endif 43 44private: 45 BitmapTextureImageBuffer() { } 46 std::unique_ptr<ImageBuffer> m_image; 47}; 48 49 50class TextureMapperImageBuffer : public TextureMapper { 51 WTF_MAKE_FAST_ALLOCATED; 52public: 53 TextureMapperImageBuffer() 54 : TextureMapper(SoftwareMode) 55 { } 56 57 // TextureMapper implementation 58 virtual void drawBorder(const Color&, float borderWidth, const FloatRect&, const TransformationMatrix&) override; 59 virtual void drawNumber(int number, const Color&, const FloatPoint&, const TransformationMatrix&) override; 60 virtual void drawTexture(const BitmapTexture&, const FloatRect& targetRect, const TransformationMatrix&, float opacity, unsigned exposedEdges) override; 61 virtual void drawSolidColor(const FloatRect&, const TransformationMatrix&, const Color&) override; 62 virtual void beginClip(const TransformationMatrix&, const FloatRect&) override; 63 virtual void bindSurface(BitmapTexture* surface) override { m_currentSurface = surface;} 64 virtual void endClip() override { graphicsContext()->restore(); } 65 virtual IntRect clipBounds() override { return currentContext()->clipBounds(); } 66 virtual IntSize maxTextureSize() const; 67 virtual PassRefPtr<BitmapTexture> createTexture() override { return BitmapTextureImageBuffer::create(); } 68 69 inline GraphicsContext* currentContext() 70 { 71 return m_currentSurface ? static_cast<BitmapTextureImageBuffer*>(m_currentSurface.get())->graphicsContext() : graphicsContext(); 72 } 73 74private: 75 RefPtr<BitmapTexture> m_currentSurface; 76}; 77 78} 79#endif // USE(TEXTURE_MAPPER) 80 81#endif // TextureMapperImageBuffer_h 82