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; }
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    OwnPtr<ImageBuffer> m_image;
47};
48
49
50class TextureMapperImageBuffer : public TextureMapper {
51    WTF_MAKE_FAST_ALLOCATED;
52public:
53    static PassOwnPtr<TextureMapper> create() { return adoptPtr(new TextureMapperImageBuffer); }
54
55    // TextureMapper implementation
56    virtual void drawBorder(const Color&, float borderWidth, const FloatRect&, const TransformationMatrix&) OVERRIDE;
57    virtual void drawNumber(int number, const Color&, const FloatPoint&, const TransformationMatrix&) OVERRIDE;
58    virtual void drawTexture(const BitmapTexture&, const FloatRect& targetRect, const TransformationMatrix&, float opacity, unsigned exposedEdges) OVERRIDE;
59    virtual void drawSolidColor(const FloatRect&, const TransformationMatrix&, const Color&) OVERRIDE;
60    virtual void beginClip(const TransformationMatrix&, const FloatRect&) OVERRIDE;
61    virtual void bindSurface(BitmapTexture* surface) OVERRIDE { m_currentSurface = surface;}
62    virtual void endClip() OVERRIDE { graphicsContext()->restore(); }
63    virtual IntRect clipBounds() OVERRIDE { return currentContext()->clipBounds(); }
64    virtual IntSize maxTextureSize() const;
65    virtual PassRefPtr<BitmapTexture> createTexture() OVERRIDE { return BitmapTextureImageBuffer::create(); }
66
67    inline GraphicsContext* currentContext()
68    {
69        return m_currentSurface ? static_cast<BitmapTextureImageBuffer*>(m_currentSurface.get())->graphicsContext() : graphicsContext();
70    }
71
72private:
73    TextureMapperImageBuffer()
74        : TextureMapper(SoftwareMode)
75    { }
76    RefPtr<BitmapTexture> m_currentSurface;
77};
78
79}
80#endif // USE(TEXTURE_MAPPER)
81
82#endif // TextureMapperImageBuffer_h
83