OLD | NEW |
(Empty) | |
| 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 "Extensions3DChromium.h" |
| 38 #include "TextureCopier.h" |
| 39 #include "TrackingTextureAllocator.h" |
| 40 #include "cc/CCRenderer.h" |
| 41 #include <wtf/PassOwnPtr.h> |
| 42 |
| 43 namespace WebKit { |
| 44 class WebGraphicsContext3D; |
| 45 } |
| 46 |
| 47 namespace WebCore { |
| 48 |
| 49 class CCCheckerboardDrawQuad; |
| 50 class CCDebugBorderDrawQuad; |
| 51 class CCDrawQuad; |
| 52 class CCIOSurfaceDrawQuad; |
| 53 class CCRenderPassDrawQuad; |
| 54 class CCSolidColorDrawQuad; |
| 55 class CCStreamVideoDrawQuad; |
| 56 class CCTextureDrawQuad; |
| 57 class CCTileDrawQuad; |
| 58 class CCYUVVideoDrawQuad; |
| 59 class GeometryBinding; |
| 60 class ManagedTexture; |
| 61 class ScopedEnsureFramebufferAllocation; |
| 62 |
| 63 // Class that handles drawing of composited render layers using GL. |
| 64 class LayerRendererChromium : public CCRenderer, |
| 65 public WebKit::WebGraphicsContext3D::WebGraphicsSw
apBuffersCompleteCallbackCHROMIUM, |
| 66 public WebKit::WebGraphicsContext3D::WebGraphicsMe
moryAllocationChangedCallbackCHROMIUM , |
| 67 public WebKit::WebGraphicsContext3D::WebGraphicsCo
ntextLostCallback { |
| 68 WTF_MAKE_NONCOPYABLE(LayerRendererChromium); |
| 69 public: |
| 70 static PassOwnPtr<LayerRendererChromium> create(CCRendererClient*, WebKit::W
ebGraphicsContext3D*, TextureUploaderOption); |
| 71 |
| 72 virtual ~LayerRendererChromium(); |
| 73 |
| 74 virtual const LayerRendererCapabilities& capabilities() const OVERRIDE { ret
urn m_capabilities; } |
| 75 |
| 76 WebKit::WebGraphicsContext3D* context(); |
| 77 |
| 78 virtual void viewportChanged() OVERRIDE; |
| 79 |
| 80 const FloatQuad& sharedGeometryQuad() const { return m_sharedGeometryQuad; } |
| 81 |
| 82 virtual void decideRenderPassAllocationsForFrame(const CCRenderPassList&) OV
ERRIDE; |
| 83 virtual void beginDrawingFrame(const CCRenderPass* defaultRenderPass) OVERRI
DE; |
| 84 virtual void drawRenderPass(const CCRenderPass*, const FloatRect& framebuffe
rDamageRect) OVERRIDE; |
| 85 virtual void finishDrawingFrame() OVERRIDE; |
| 86 |
| 87 virtual void drawHeadsUpDisplay(ManagedTexture*, const IntSize& hudSize) OVE
RRIDE; |
| 88 |
| 89 // waits for rendering to finish |
| 90 virtual void finish() OVERRIDE; |
| 91 |
| 92 virtual void doNoOp() OVERRIDE; |
| 93 // puts backbuffer onscreen |
| 94 virtual bool swapBuffers(const IntRect& subBuffer) OVERRIDE; |
| 95 |
| 96 static void debugGLCall(WebKit::WebGraphicsContext3D*, const char* command,
const char* file, int line); |
| 97 |
| 98 const GeometryBinding* sharedGeometry() const { return m_sharedGeometry.get(
); } |
| 99 |
| 100 virtual void getFramebufferPixels(void *pixels, const IntRect&) OVERRIDE; |
| 101 bool getFramebufferTexture(ManagedTexture*, const IntRect& deviceRect); |
| 102 |
| 103 virtual TextureManager* implTextureManager() const OVERRIDE { return m_implT
extureManager.get(); } |
| 104 virtual TextureCopier* textureCopier() const OVERRIDE { return m_textureCopi
er.get(); } |
| 105 virtual TextureUploader* textureUploader() const OVERRIDE { return m_texture
Uploader.get(); } |
| 106 virtual TextureAllocator* implTextureAllocator() const OVERRIDE { return m_i
mplTextureAllocator.get(); } |
| 107 virtual TextureAllocator* contentsTextureAllocator() const OVERRIDE { return
m_contentsTextureAllocator.get(); } |
| 108 |
| 109 virtual void setScissorToRect(const IntRect&) OVERRIDE; |
| 110 |
| 111 virtual bool isContextLost() OVERRIDE; |
| 112 |
| 113 virtual void setVisible(bool) OVERRIDE; |
| 114 |
| 115 void drawTexturedQuad(const WebKit::WebTransformationMatrix& layerMatrix, |
| 116 float width, float height, float opacity, const FloatQ
uad&, |
| 117 int matrixLocation, int alphaLocation, int quadLocatio
n); |
| 118 void copyTextureToFramebuffer(int textureId, const IntSize& bounds, const We
bKit::WebTransformationMatrix& drawMatrix); |
| 119 |
| 120 protected: |
| 121 LayerRendererChromium(CCRendererClient*, WebKit::WebGraphicsContext3D*, Text
ureUploaderOption); |
| 122 |
| 123 bool isFramebufferDiscarded() const { return m_isFramebufferDiscarded; } |
| 124 bool initialize(); |
| 125 |
| 126 private: |
| 127 static void toGLMatrix(float*, const WebKit::WebTransformationMatrix&); |
| 128 |
| 129 void drawQuad(const CCDrawQuad*); |
| 130 void drawCheckerboardQuad(const CCCheckerboardDrawQuad*); |
| 131 void drawDebugBorderQuad(const CCDebugBorderDrawQuad*); |
| 132 void drawBackgroundFilters(const CCRenderPassDrawQuad*, const WebKit::WebTra
nsformationMatrix& deviceTransform); |
| 133 void drawRenderPassQuad(const CCRenderPassDrawQuad*); |
| 134 void drawSolidColorQuad(const CCSolidColorDrawQuad*); |
| 135 void drawStreamVideoQuad(const CCStreamVideoDrawQuad*); |
| 136 void drawTextureQuad(const CCTextureDrawQuad*); |
| 137 void drawIOSurfaceQuad(const CCIOSurfaceDrawQuad*); |
| 138 void drawTileQuad(const CCTileDrawQuad*); |
| 139 void drawYUVVideoQuad(const CCYUVVideoDrawQuad*); |
| 140 |
| 141 void setDrawFramebufferRect(const IntRect&, bool flipY); |
| 142 |
| 143 // The current drawing target is either a RenderPass or ManagedTexture. Use
these functions to switch to a new drawing target. |
| 144 bool useRenderPass(const CCRenderPass*); |
| 145 bool useManagedTexture(ManagedTexture*, const IntRect& viewportRect); |
| 146 bool isCurrentRenderPass(const CCRenderPass*); |
| 147 |
| 148 bool bindFramebufferToTexture(ManagedTexture*, const IntRect& viewportRect); |
| 149 |
| 150 void clearRenderPass(const CCRenderPass*, const FloatRect& framebufferDamage
Rect); |
| 151 |
| 152 void releaseRenderPassTextures(); |
| 153 |
| 154 bool makeContextCurrent(); |
| 155 |
| 156 bool initializeSharedObjects(); |
| 157 void cleanupSharedObjects(); |
| 158 |
| 159 // WebKit::WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROM
IUM implementation. |
| 160 virtual void onSwapBuffersComplete() OVERRIDE; |
| 161 |
| 162 // WebKit::WebGraphicsContext3D::WebGraphicsMemoryAllocationChangedCallbackC
HROMIUM implementation. |
| 163 virtual void onMemoryAllocationChanged(WebKit::WebGraphicsMemoryAllocation)
OVERRIDE; |
| 164 void onMemoryAllocationChangedOnImplThread(WebKit::WebGraphicsMemoryAllocati
on); |
| 165 void discardFramebuffer(); |
| 166 void ensureFramebuffer(); |
| 167 |
| 168 // WebGraphicsContext3D::WebGraphicsContextLostCallback implementation. |
| 169 virtual void onContextLost() OVERRIDE; |
| 170 |
| 171 LayerRendererCapabilities m_capabilities; |
| 172 |
| 173 const CCRenderPass* m_currentRenderPass; |
| 174 ManagedTexture* m_currentManagedTexture; |
| 175 unsigned m_offscreenFramebufferId; |
| 176 |
| 177 OwnPtr<GeometryBinding> m_sharedGeometry; |
| 178 FloatQuad m_sharedGeometryQuad; |
| 179 |
| 180 // This block of bindings defines all of the programs used by the compositor
itself. |
| 181 |
| 182 // Tiled layer shaders. |
| 183 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexAlpha> TilePro
gram; |
| 184 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexClampAlphaAA>
TileProgramAA; |
| 185 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexClampSwizzleAl
phaAA> TileProgramSwizzleAA; |
| 186 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexOpaque> TilePr
ogramOpaque; |
| 187 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexSwizzleAlpha>
TileProgramSwizzle; |
| 188 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexSwizzleOpaque>
TileProgramSwizzleOpaque; |
| 189 typedef ProgramBinding<VertexShaderPosTex, FragmentShaderCheckerboard> TileC
heckerboardProgram; |
| 190 |
| 191 // Render surface shaders. |
| 192 typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexAlpha> Rende
rPassProgram; |
| 193 typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexAlphaMask> R
enderPassMaskProgram; |
| 194 typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaAA> Rende
rPassProgramAA; |
| 195 typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaMaskAA> R
enderPassMaskProgramAA; |
| 196 |
| 197 // Texture shaders. |
| 198 typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexAlp
ha> TextureProgram; |
| 199 typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexFli
pAlpha> TextureProgramFlip; |
| 200 typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexRec
tFlipAlpha> TextureIOSurfaceProgram; |
| 201 |
| 202 // Video shaders. |
| 203 typedef ProgramBinding<VertexShaderVideoTransform, FragmentShaderOESImageExt
ernal> VideoStreamTextureProgram; |
| 204 typedef ProgramBinding<VertexShaderPosTexYUVStretch, FragmentShaderYUVVideo>
VideoYUVProgram; |
| 205 |
| 206 // Special purpose / effects shaders. |
| 207 typedef ProgramBinding<VertexShaderPos, FragmentShaderColor> SolidColorProgr
am; |
| 208 |
| 209 // Debugging shaders. |
| 210 typedef ProgramBinding<VertexShaderPosTex, FragmentShaderRGBATexSwizzleAlpha
> HeadsUpDisplayProgram; |
| 211 |
| 212 |
| 213 const TileProgram* tileProgram(); |
| 214 const TileProgramOpaque* tileProgramOpaque(); |
| 215 const TileProgramAA* tileProgramAA(); |
| 216 const TileProgramSwizzle* tileProgramSwizzle(); |
| 217 const TileProgramSwizzleOpaque* tileProgramSwizzleOpaque(); |
| 218 const TileProgramSwizzleAA* tileProgramSwizzleAA(); |
| 219 const TileCheckerboardProgram* tileCheckerboardProgram(); |
| 220 |
| 221 const RenderPassProgram* renderPassProgram(); |
| 222 const RenderPassProgramAA* renderPassProgramAA(); |
| 223 const RenderPassMaskProgram* renderPassMaskProgram(); |
| 224 const RenderPassMaskProgramAA* renderPassMaskProgramAA(); |
| 225 |
| 226 const TextureProgram* textureProgram(); |
| 227 const TextureProgramFlip* textureProgramFlip(); |
| 228 const TextureIOSurfaceProgram* textureIOSurfaceProgram(); |
| 229 |
| 230 const VideoYUVProgram* videoYUVProgram(); |
| 231 const VideoStreamTextureProgram* videoStreamTextureProgram(); |
| 232 |
| 233 const SolidColorProgram* solidColorProgram(); |
| 234 |
| 235 const HeadsUpDisplayProgram* headsUpDisplayProgram(); |
| 236 |
| 237 OwnPtr<TileProgram> m_tileProgram; |
| 238 OwnPtr<TileProgramOpaque> m_tileProgramOpaque; |
| 239 OwnPtr<TileProgramAA> m_tileProgramAA; |
| 240 OwnPtr<TileProgramSwizzle> m_tileProgramSwizzle; |
| 241 OwnPtr<TileProgramSwizzleOpaque> m_tileProgramSwizzleOpaque; |
| 242 OwnPtr<TileProgramSwizzleAA> m_tileProgramSwizzleAA; |
| 243 OwnPtr<TileCheckerboardProgram> m_tileCheckerboardProgram; |
| 244 |
| 245 OwnPtr<RenderPassProgram> m_renderPassProgram; |
| 246 OwnPtr<RenderPassProgramAA> m_renderPassProgramAA; |
| 247 OwnPtr<RenderPassMaskProgram> m_renderPassMaskProgram; |
| 248 OwnPtr<RenderPassMaskProgramAA> m_renderPassMaskProgramAA; |
| 249 |
| 250 OwnPtr<TextureProgram> m_textureProgram; |
| 251 OwnPtr<TextureProgramFlip> m_textureProgramFlip; |
| 252 OwnPtr<TextureIOSurfaceProgram> m_textureIOSurfaceProgram; |
| 253 |
| 254 OwnPtr<VideoYUVProgram> m_videoYUVProgram; |
| 255 OwnPtr<VideoStreamTextureProgram> m_videoStreamTextureProgram; |
| 256 |
| 257 OwnPtr<SolidColorProgram> m_solidColorProgram; |
| 258 OwnPtr<HeadsUpDisplayProgram> m_headsUpDisplayProgram; |
| 259 |
| 260 OwnPtr<TextureManager> m_implTextureManager; |
| 261 OwnPtr<AcceleratedTextureCopier> m_textureCopier; |
| 262 OwnPtr<TextureUploader> m_textureUploader; |
| 263 OwnPtr<TrackingTextureAllocator> m_contentsTextureAllocator; |
| 264 OwnPtr<TrackingTextureAllocator> m_implTextureAllocator; |
| 265 |
| 266 WebKit::WebGraphicsContext3D* m_context; |
| 267 |
| 268 const CCRenderPass* m_defaultRenderPass; |
| 269 |
| 270 bool m_isViewportChanged; |
| 271 bool m_isFramebufferDiscarded; |
| 272 bool m_visible; |
| 273 TextureUploaderOption m_textureUploaderSetting; |
| 274 }; |
| 275 |
| 276 |
| 277 // Setting DEBUG_GL_CALLS to 1 will call glGetError() after almost every GL |
| 278 // call made by the compositor. Useful for debugging rendering issues but |
| 279 // will significantly degrade performance. |
| 280 #define DEBUG_GL_CALLS 0 |
| 281 |
| 282 #if DEBUG_GL_CALLS && !defined ( NDEBUG ) |
| 283 #define GLC(context, x) (x, LayerRendererChromium::debugGLCall(&*context, #x, __
FILE__, __LINE__)) |
| 284 #else |
| 285 #define GLC(context, x) (x) |
| 286 #endif |
| 287 |
| 288 |
| 289 } |
| 290 |
| 291 #endif // USE(ACCELERATED_COMPOSITING) |
| 292 |
| 293 #endif |
OLD | NEW |