2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
20 #ifndef TextureMapperGL_h
21 #define TextureMapperGL_h
23 #if USE(ACCELERATED_COMPOSITING)
25 #include "FloatQuad.h"
27 #include "TransformationMatrix.h"
28 #include "texmap/TextureMapper.h"
32 class TextureMapperGLData;
34 // An OpenGL-ES2 implementation of TextureMapper.
35 class TextureMapperGL : public TextureMapper {
38 virtual ~TextureMapperGL();
40 // reimps from TextureMapper
41 virtual void drawTexture(const BitmapTexture& texture, const IntRect&, const TransformationMatrix& transform, float opacity, const BitmapTexture* maskTexture);
42 virtual void bindSurface(BitmapTexture* surface);
43 virtual void setClip(const IntRect&);
44 virtual void paintToTarget(const BitmapTexture&, const IntSize&, const TransformationMatrix&, float opacity, const IntRect& visibleRect);
45 virtual bool allowSurfaceForRoot() const { return true; }
46 virtual PassRefPtr<BitmapTexture> createTexture();
47 virtual const char* type() const;
48 void obtainCurrentContext();
49 bool makeContextCurrent();
50 static PassOwnPtr<TextureMapperGL> create()
52 return new TextureMapperGL;
56 inline TextureMapperGLData& data() { return *m_data; }
57 TextureMapperGLData* m_data;
58 friend class BitmapTextureGL;
61 // An offscreen buffer to be rendered by software.
62 class RGBA32PremultimpliedBuffer : public RefCounted<RGBA32PremultimpliedBuffer> {
64 virtual ~RGBA32PremultimpliedBuffer() {}
65 virtual PlatformGraphicsContext* beginPaint(const IntRect& dirtyRect, bool opaque) = 0;
66 virtual void endPaint() = 0;
67 virtual const void* data() const = 0;
68 static PassRefPtr<RGBA32PremultimpliedBuffer> create();
71 static inline int nextPowerOfTwo(int num)
73 for (int i = 0x10000000; i > 0; i >>= 1) {
82 static inline IntSize nextPowerOfTwo(const IntSize& size)
84 return IntSize(nextPowerOfTwo(size.width()), nextPowerOfTwo(size.height()));