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 | #ifndef TextureMapper_h |
21 | #define TextureMapper_h |
22 | |
23 | #include "BitmapTexture.h" |
24 | #include "Color.h" |
25 | #include "IntRect.h" |
26 | #include "IntSize.h" |
27 | #include "TransformationMatrix.h" |
28 | |
29 | /* |
30 | TextureMapper is a mechanism that enables hardware acceleration of CSS animations (accelerated compositing) without |
31 | a need for a platform specific scene-graph library like CoreAnimations or QGraphicsView. |
32 | */ |
33 | |
34 | namespace WebCore { |
35 | |
36 | class BitmapTexturePool; |
37 | class GraphicsLayer; |
38 | class TextureMapper; |
39 | class FilterOperations; |
40 | |
41 | class TextureMapper { |
42 | WTF_MAKE_FAST_ALLOCATED; |
43 | public: |
44 | enum PaintFlag { |
45 | PaintingMirrored = 1 << 0, |
46 | }; |
47 | |
48 | enum WrapMode { |
49 | StretchWrap, |
50 | RepeatWrap |
51 | }; |
52 | |
53 | typedef unsigned PaintFlags; |
54 | |
55 | WEBCORE_EXPORT static std::unique_ptr<TextureMapper> create(); |
56 | |
57 | explicit TextureMapper(); |
58 | virtual ~TextureMapper(); |
59 | |
60 | enum ExposedEdges { |
61 | NoEdges = 0, |
62 | LeftEdge = 1 << 0, |
63 | RightEdge = 1 << 1, |
64 | TopEdge = 1 << 2, |
65 | BottomEdge = 1 << 3, |
66 | AllEdges = LeftEdge | RightEdge | TopEdge | BottomEdge, |
67 | }; |
68 | |
69 | virtual void drawBorder(const Color&, float borderWidth, const FloatRect&, const TransformationMatrix&) = 0; |
70 | virtual void drawNumber(int number, const Color&, const FloatPoint&, const TransformationMatrix&) = 0; |
71 | |
72 | virtual void drawTexture(const BitmapTexture&, const FloatRect& target, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0f, unsigned exposedEdges = AllEdges) = 0; |
73 | virtual void drawSolidColor(const FloatRect&, const TransformationMatrix&, const Color&, bool) = 0; |
74 | virtual void clearColor(const Color&) = 0; |
75 | |
76 | // makes a surface the target for the following drawTexture calls. |
77 | virtual void bindSurface(BitmapTexture* surface) = 0; |
78 | virtual void beginClip(const TransformationMatrix&, const FloatRect&) = 0; |
79 | virtual void endClip() = 0; |
80 | virtual IntRect clipBounds() = 0; |
81 | virtual Ref<BitmapTexture> createTexture() = 0; |
82 | virtual Ref<BitmapTexture> createTexture(int internalFormat) = 0; |
83 | |
84 | virtual void beginPainting(PaintFlags = 0) { } |
85 | virtual void endPainting() { } |
86 | |
87 | void setMaskMode(bool m) { m_isMaskMode = m; } |
88 | |
89 | virtual IntSize maxTextureSize() const = 0; |
90 | |
91 | virtual RefPtr<BitmapTexture> acquireTextureFromPool(const IntSize&, const BitmapTexture::Flags = BitmapTexture::SupportsAlpha); |
92 | |
93 | void setPatternTransform(const TransformationMatrix& p) { m_patternTransform = p; } |
94 | void setWrapMode(WrapMode m) { m_wrapMode = m; } |
95 | |
96 | protected: |
97 | std::unique_ptr<BitmapTexturePool> m_texturePool; |
98 | |
99 | bool isInMaskMode() const { return m_isMaskMode; } |
100 | WrapMode wrapMode() const { return m_wrapMode; } |
101 | const TransformationMatrix& patternTransform() const { return m_patternTransform; } |
102 | |
103 | private: |
104 | #if USE(TEXTURE_MAPPER_GL) |
105 | static std::unique_ptr<TextureMapper> platformCreateAccelerated(); |
106 | #else |
107 | static std::unique_ptr<TextureMapper> platformCreateAccelerated() |
108 | { |
109 | return nullptr; |
110 | } |
111 | #endif |
112 | bool m_isMaskMode { false }; |
113 | TransformationMatrix m_patternTransform; |
114 | WrapMode m_wrapMode { StretchWrap }; |
115 | }; |
116 | |
117 | } |
118 | |
119 | #endif |
120 | |