OSDN Git Service

Merge WebKit at r71558: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / platform / graphics / opengl / TextureMapperGL.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 #ifndef TextureMapperGL_h
21 #define TextureMapperGL_h
22
23 #if USE(ACCELERATED_COMPOSITING)
24
25 #include "FloatQuad.h"
26 #include "IntSize.h"
27 #include "TransformationMatrix.h"
28 #include "texmap/TextureMapper.h"
29
30 namespace WebCore {
31
32 class TextureMapperGLData;
33
34 // An OpenGL-ES2 implementation of TextureMapper.
35 class TextureMapperGL : public TextureMapper {
36 public:
37     TextureMapperGL();
38     virtual ~TextureMapperGL();
39
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()
51     {
52         return new TextureMapperGL;
53     }
54
55 private:
56     inline TextureMapperGLData& data() { return *m_data; }
57     TextureMapperGLData* m_data;
58     friend class BitmapTextureGL;
59 };
60
61 // An offscreen buffer to be rendered by software.
62 class RGBA32PremultimpliedBuffer : public RefCounted<RGBA32PremultimpliedBuffer> {
63 public:
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();
69 };
70
71 static inline int nextPowerOfTwo(int num)
72 {
73     for (int i = 0x10000000; i > 0; i >>= 1) {
74         if (num == i)
75             return num;
76         if (num & i)
77             return (i << 1);
78     }
79     return 1;
80 }
81
82 static inline IntSize nextPowerOfTwo(const IntSize& size)
83 {
84     return IntSize(nextPowerOfTwo(size.width()), nextPowerOfTwo(size.height()));
85 }
86
87 };
88
89 #endif
90
91 #endif