initial import
[vuplus_webkit] / Source / WebCore / platform / graphics / qt / TextureMapperQt.h
1 /*
2  Copyright (C) 2010 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 #include "texmap/TextureMapper.h"
21
22 #ifndef TextureMapperQt_h
23 #define TextureMapperQt_h
24
25 namespace WebCore {
26
27 class BitmapTextureQt : public BitmapTexture {
28     friend class TextureMapperQt;
29 public:
30     BitmapTextureQt();
31     ~BitmapTextureQt() { destroy(); }
32     virtual void destroy();
33     virtual IntSize size() const { return IntSize(m_pixmap.width(), m_pixmap.height()); }
34     virtual void reset(const IntSize&, bool opaque);
35     virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect);
36     virtual void endPaint();
37     virtual void setContentsToImage(Image*);
38     virtual bool save(const String& path);
39     virtual bool isValid() const { return !m_pixmap.isNull() || !m_image.isNull(); }
40     IntRect sourceRect() const { return IntRect(0, 0, contentSize().width(), contentSize().height()); }
41     virtual void pack();
42     virtual void unpack();
43     virtual bool isPacked() const { return m_isPacked; }
44
45     QPainter* painter() { return &m_painter; }
46
47 private:
48     QPainter m_painter;
49     QPixmap m_pixmap;
50     QImage m_image;
51     bool m_isPacked;
52 };
53
54 class TextureMapperQt : public TextureMapper {
55 public:
56     TextureMapperQt();
57
58     virtual void drawTexture(const BitmapTexture&, const FloatRect& targetRect, const TransformationMatrix&, float opacity, const BitmapTexture* maskTexture);
59     virtual void bindSurface(BitmapTexture* surface);
60     virtual void beginClip(const TransformationMatrix&, const FloatRect&);
61     virtual void endClip();
62     virtual void setGraphicsContext(GraphicsContext*);
63     virtual GraphicsContext* graphicsContext();
64     virtual bool allowSurfaceForRoot() const { return false; }
65     virtual PassRefPtr<BitmapTexture> createTexture();
66     virtual IntSize viewportSize() const;
67     virtual void beginPainting();
68     virtual void endPainting();
69
70     static void initialize(QPainter* painter)
71     {
72         painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false);
73     }
74
75     static PassOwnPtr<TextureMapper> create() { return adoptPtr(new TextureMapperQt); }
76 private:
77     inline QPainter* currentPainter() { return m_currentSurface ? m_currentSurface->painter() : m_painter; }
78
79     QPainter* m_painter;
80     GraphicsContext* m_context;
81     RefPtr<BitmapTextureQt> m_currentSurface;
82 };
83
84 }
85 #endif