OSDN Git Service

Merge WebKit at r71558: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / platform / graphics / chromium / LayerRendererChromium.h
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31
32 #ifndef LayerRendererChromium_h
33 #define LayerRendererChromium_h
34
35 #if USE(ACCELERATED_COMPOSITING)
36
37 #include "CanvasLayerChromium.h"
38 #include "ContentLayerChromium.h"
39 #include "IntRect.h"
40 #include "LayerChromium.h"
41 #include "PluginLayerChromium.h"
42 #include "SkBitmap.h"
43 #include "VideoLayerChromium.h"
44 #include <wtf/HashMap.h>
45 #include <wtf/Noncopyable.h>
46 #include <wtf/PassOwnPtr.h>
47 #include <wtf/PassRefPtr.h>
48 #include <wtf/RefCounted.h>
49 #include <wtf/Vector.h>
50
51 #if PLATFORM(CG)
52 #include <CoreGraphics/CGContext.h>
53 #include <wtf/RetainPtr.h>
54 #endif
55
56 namespace WebCore {
57
58 class GraphicsContext3D;
59
60 // Class that handles drawing of composited render layers using GL.
61 class LayerRendererChromium : public RefCounted<LayerRendererChromium> {
62 public:
63     static PassRefPtr<LayerRendererChromium> create(PassRefPtr<GraphicsContext3D> graphicsContext3D);
64
65     ~LayerRendererChromium();
66
67     GraphicsContext3D* context();
68
69     // updates size of root texture, if needed, and scrolls the backbuffer.
70     void prepareToDrawLayers(const IntRect& visibleRect, const IntRect& contentRect, const IntPoint& scrollPosition);
71
72     // updates a rectangle within the root layer texture
73     void updateRootLayerTextureRect(const IntRect& updateRect);
74
75     // draws the current layers onto the backbuffer
76     void drawLayers(const IntRect& visibleRect, const IntRect& contentRect);
77
78     // waits for rendering to finish
79     void finish();
80
81     // puts backbuffer onscreen
82     void present();
83
84     void setRootLayer(PassRefPtr<LayerChromium> layer) { m_rootLayer = layer; }
85     LayerChromium* rootLayer() { return m_rootLayer.get(); }
86     void transferRootLayer(LayerRendererChromium* other) { other->m_rootLayer = m_rootLayer.release(); }
87
88     bool hardwareCompositing() const { return m_hardwareCompositing; }
89
90     void setRootLayerCanvasSize(const IntSize&);
91
92     GraphicsContext* rootLayerGraphicsContext() const { return m_rootLayerGraphicsContext.get(); }
93
94     unsigned createLayerTexture();
95     void deleteLayerTexture(unsigned);
96
97     IntRect currentScissorRect() const { return m_currentScissorRect; }
98
99     static void debugGLCall(GraphicsContext3D*, const char* command, const char* file, int line);
100
101     const TransformationMatrix& projectionMatrix() const { return m_projectionMatrix; }
102
103     void useShader(unsigned);
104
105     bool checkTextureSize(const IntSize&);
106
107     const LayerChromium::SharedValues* layerSharedValues() const { return m_layerSharedValues.get(); }
108     const ContentLayerChromium::SharedValues* contentLayerSharedValues() const { return m_contentLayerSharedValues.get(); }
109     const CanvasLayerChromium::SharedValues* canvasLayerSharedValues() const { return m_canvasLayerSharedValues.get(); }
110     const VideoLayerChromium::SharedValues* videoLayerSharedValues() const { return m_videoLayerSharedValues.get(); }
111     const PluginLayerChromium::SharedValues* pluginLayerSharedValues() const { return m_pluginLayerSharedValues.get(); }
112
113     void resizeOnscreenContent(const IntSize&);
114
115     IntSize rootLayerTextureSize() const { return IntSize(m_rootLayerTextureWidth, m_rootLayerTextureHeight); }
116     IntRect rootLayerContentRect() const { return m_rootContentRect; }
117     void getFramebufferPixels(void *pixels, const IntRect& rect);
118
119 private:
120     explicit LayerRendererChromium(PassRefPtr<GraphicsContext3D> graphicsContext3D);
121
122     void updateLayersRecursive(LayerChromium* layer, const TransformationMatrix& parentMatrix, float opacity);
123
124     void drawLayersRecursive(LayerChromium*);
125
126     void drawLayer(LayerChromium*);
127
128     bool isLayerVisible(LayerChromium*, const TransformationMatrix&, const IntRect& visibleRect);
129
130     void drawLayerIntoStencilBuffer(LayerChromium*, bool decrement);
131
132     void scissorToRect(const IntRect&);
133
134     bool makeContextCurrent();
135
136     bool initializeSharedObjects();
137     void cleanupSharedObjects();
138
139     unsigned m_rootLayerTextureId;
140     int m_rootLayerTextureWidth;
141     int m_rootLayerTextureHeight;
142
143     // Scroll shader uniform locations.
144     unsigned m_scrollShaderProgram;
145     int m_scrollShaderSamplerLocation;
146     int m_scrollShaderMatrixLocation;
147
148     TransformationMatrix m_projectionMatrix;
149
150     RefPtr<LayerChromium> m_rootLayer;
151
152     IntPoint m_scrollPosition;
153     bool m_hardwareCompositing;
154
155     unsigned int m_currentShader;
156
157 #if PLATFORM(SKIA)
158     OwnPtr<skia::PlatformCanvas> m_rootLayerCanvas;
159     OwnPtr<PlatformContextSkia> m_rootLayerSkiaContext;
160     OwnPtr<GraphicsContext> m_rootLayerGraphicsContext;
161 #elif PLATFORM(CG)
162     Vector<uint8_t> m_rootLayerBackingStore;
163     RetainPtr<CGContextRef> m_rootLayerCGContext;
164     OwnPtr<GraphicsContext> m_rootLayerGraphicsContext;
165 #endif
166
167     IntSize m_rootLayerCanvasSize;
168
169     IntRect m_rootVisibleRect;
170     IntRect m_rootContentRect;
171     IntRect m_currentScissorRect;
172
173     int m_maxTextureSize;
174
175     int m_numStencilBits;
176
177     // Store values that are shared between instances of each layer type
178     // associated with this instance of the compositor. Since there can be
179     // multiple instances of the compositor running in the same renderer process
180     // we cannot store these values in static variables.
181     OwnPtr<LayerChromium::SharedValues> m_layerSharedValues;
182     OwnPtr<ContentLayerChromium::SharedValues> m_contentLayerSharedValues;
183     OwnPtr<CanvasLayerChromium::SharedValues> m_canvasLayerSharedValues;
184     OwnPtr<VideoLayerChromium::SharedValues> m_videoLayerSharedValues;
185     OwnPtr<PluginLayerChromium::SharedValues> m_pluginLayerSharedValues;
186
187     RefPtr<GraphicsContext3D> m_context;
188 };
189
190 // Setting DEBUG_GL_CALLS to 1 will call glGetError() after almost every GL
191 // call made by the compositor. Useful for debugging rendering issues but
192 // will significantly degrade performance.
193 #define DEBUG_GL_CALLS 0
194
195 #if DEBUG_GL_CALLS && !defined ( NDEBUG )
196 #define GLC(context, x) { (x), LayerRendererChromium::debugGLCall(context, #x, __FILE__, __LINE__); }
197 #else
198 #define GLC(context, x) (x)
199 #endif
200
201
202 }
203
204 #endif // USE(ACCELERATED_COMPOSITING)
205
206 #endif