• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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();
~BitmapTextureQt()31     ~BitmapTextureQt() { destroy(); }
32     virtual void destroy();
size()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);
isValid()39     virtual bool isValid() const { return !m_pixmap.isNull() || !m_image.isNull(); }
sourceRect()40     IntRect sourceRect() const { return IntRect(0, 0, contentSize().width(), contentSize().height()); }
41     virtual void pack();
42     virtual void unpack();
isPacked()43     virtual bool isPacked() const { return m_isPacked; }
44 
45 private:
46     QPainter m_painter;
47     QPixmap m_pixmap;
48     QImage m_image;
49     bool m_isPacked;
50 };
51 
52 class TextureMapperQt : public TextureMapper {
53 public:
54     TextureMapperQt();
55 
56     virtual void drawTexture(const BitmapTexture& texture, const IntRect& targetRect, const TransformationMatrix& matrix, float opacity, const BitmapTexture* maskTexture);
57     virtual void bindSurface(BitmapTexture* surface);
58     virtual void setClip(const IntRect&);
59     virtual void setGraphicsContext(GraphicsContext*);
allowSurfaceForRoot()60     virtual bool allowSurfaceForRoot() const { return false; }
61     virtual PassRefPtr<BitmapTexture> createTexture();
62 
initialize(QPainter * painter)63     static void initialize(QPainter* painter)
64     {
65         painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false);
66     }
67 
create()68     static PassOwnPtr<TextureMapper> create() { return new TextureMapperQt; }
69 
70 private:
71     QPainter* m_painter;
72     RefPtr<BitmapTextureQt> m_currentSurface;
73 };
74 
75 }
76 #endif
77