| OLD | NEW |
| (Empty) |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_GL_RENDERER_H_ | |
| 6 #define CC_GL_RENDERER_H_ | |
| 7 | |
| 8 #include "cc/base/cc_export.h" | |
| 9 #include "cc/checkerboard_draw_quad.h" | |
| 10 #include "cc/debug_border_draw_quad.h" | |
| 11 #include "cc/direct_renderer.h" | |
| 12 #include "cc/gl_renderer_draw_cache.h" | |
| 13 #include "cc/io_surface_draw_quad.h" | |
| 14 #include "cc/render_pass_draw_quad.h" | |
| 15 #include "cc/renderer.h" | |
| 16 #include "cc/solid_color_draw_quad.h" | |
| 17 #include "cc/tile_draw_quad.h" | |
| 18 #include "cc/yuv_video_draw_quad.h" | |
| 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | |
| 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsMemoryAl
location.h" | |
| 21 #include "ui/gfx/quad_f.h" | |
| 22 | |
| 23 namespace cc { | |
| 24 | |
| 25 class GLRendererShaderTest; | |
| 26 class OutputSurface; | |
| 27 class ScopedResource; | |
| 28 class StreamVideoDrawQuad; | |
| 29 class TextureDrawQuad; | |
| 30 class GeometryBinding; | |
| 31 class ScopedEnsureFramebufferAllocation; | |
| 32 | |
| 33 // Class that handles drawing of composited render layers using GL. | |
| 34 class CC_EXPORT GLRenderer : | |
| 35 public DirectRenderer, | |
| 36 public NON_EXPORTED_BASE( | |
| 37 WebKit::WebGraphicsContext3D:: | |
| 38 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM), | |
| 39 public NON_EXPORTED_BASE( | |
| 40 WebKit::WebGraphicsContext3D:: | |
| 41 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM), | |
| 42 public NON_EXPORTED_BASE( | |
| 43 WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback) { | |
| 44 public: | |
| 45 static scoped_ptr<GLRenderer> Create(RendererClient* client, | |
| 46 OutputSurface* output_surface, | |
| 47 ResourceProvider* resource_provider); | |
| 48 | |
| 49 virtual ~GLRenderer(); | |
| 50 | |
| 51 virtual const RendererCapabilities& Capabilities() const OVERRIDE; | |
| 52 | |
| 53 WebKit::WebGraphicsContext3D* Context(); | |
| 54 | |
| 55 virtual void ViewportChanged() OVERRIDE; | |
| 56 | |
| 57 virtual void ReceiveCompositorFrameAck(const CompositorFrameAck& ack) | |
| 58 OVERRIDE; | |
| 59 | |
| 60 // Waits for rendering to finish. | |
| 61 virtual void Finish() OVERRIDE; | |
| 62 | |
| 63 virtual void DoNoOp() OVERRIDE; | |
| 64 // Puts backbuffer onscreen. | |
| 65 virtual bool SwapBuffers() OVERRIDE; | |
| 66 | |
| 67 virtual void GetFramebufferPixels(void* pixels, gfx::Rect rect) OVERRIDE; | |
| 68 | |
| 69 virtual bool IsContextLost() OVERRIDE; | |
| 70 | |
| 71 virtual void SetVisible(bool visible) OVERRIDE; | |
| 72 | |
| 73 virtual void SendManagedMemoryStats(size_t bytes_visible, | |
| 74 size_t bytes_visible_and_nearby, | |
| 75 size_t bytes_allocated) OVERRIDE; | |
| 76 | |
| 77 static void DebugGLCall(WebKit::WebGraphicsContext3D* context, | |
| 78 const char* command, | |
| 79 const char* file, | |
| 80 int line); | |
| 81 | |
| 82 protected: | |
| 83 GLRenderer(RendererClient* client, | |
| 84 OutputSurface* output_surface, | |
| 85 ResourceProvider* resource_provider); | |
| 86 | |
| 87 bool IsBackbufferDiscarded() const { return is_backbuffer_discarded_; } | |
| 88 bool Initialize(); | |
| 89 | |
| 90 const gfx::QuadF& SharedGeometryQuad() const { return shared_geometry_quad_; } | |
| 91 const GeometryBinding* SharedGeometry() const { | |
| 92 return shared_geometry_.get(); | |
| 93 } | |
| 94 | |
| 95 bool GetFramebufferTexture(ScopedResource* resource, gfx::Rect device_rect); | |
| 96 void ReleaseRenderPassTextures(); | |
| 97 | |
| 98 virtual void BindFramebufferToOutputSurface(DrawingFrame& frame) OVERRIDE; | |
| 99 virtual bool BindFramebufferToTexture(DrawingFrame& frame, | |
| 100 const ScopedResource* resource, | |
| 101 gfx::Rect framebuffer_rect) OVERRIDE; | |
| 102 virtual void SetDrawViewportSize(gfx::Size viewport_size) OVERRIDE; | |
| 103 virtual void SetScissorTestRect(gfx::Rect scissor_rect) OVERRIDE; | |
| 104 virtual void ClearFramebuffer(DrawingFrame& frame) OVERRIDE; | |
| 105 virtual void DoDrawQuad(DrawingFrame& frame, const class DrawQuad*) OVERRIDE; | |
| 106 virtual void BeginDrawingFrame(DrawingFrame& frame) OVERRIDE; | |
| 107 virtual void FinishDrawingFrame(DrawingFrame& frame) OVERRIDE; | |
| 108 virtual bool FlippedFramebuffer() const OVERRIDE; | |
| 109 virtual void EnsureScissorTestEnabled() OVERRIDE; | |
| 110 virtual void EnsureScissorTestDisabled() OVERRIDE; | |
| 111 virtual void FinishDrawingQuadList() OVERRIDE; | |
| 112 | |
| 113 private: | |
| 114 friend class GLRendererShaderTest; | |
| 115 | |
| 116 static void ToGLMatrix(float* gl_matrix, const gfx::Transform& transform); | |
| 117 static ManagedMemoryPolicy::PriorityCutoff PriorityCutoff( | |
| 118 WebKit::WebGraphicsMemoryAllocation::PriorityCutoff priority_cutoff); | |
| 119 | |
| 120 void DrawCheckerboardQuad(const DrawingFrame& frame, | |
| 121 const CheckerboardDrawQuad* quad); | |
| 122 void DrawDebugBorderQuad(const DrawingFrame& frame, | |
| 123 const DebugBorderDrawQuad* quad); | |
| 124 scoped_ptr<ScopedResource> DrawBackgroundFilters( | |
| 125 DrawingFrame& frame, | |
| 126 const RenderPassDrawQuad* quad, | |
| 127 const gfx::Transform& contents_device_transform, | |
| 128 const gfx::Transform& contents_device_transformInverse); | |
| 129 void DrawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQuad* quad); | |
| 130 void DrawSolidColorQuad(const DrawingFrame& frame, | |
| 131 const SolidColorDrawQuad* quad); | |
| 132 void DrawStreamVideoQuad(const DrawingFrame& frame, | |
| 133 const StreamVideoDrawQuad* quad); | |
| 134 void DrawTextureQuad(const DrawingFrame& frame, const TextureDrawQuad* quad); | |
| 135 void EnqueueTextureQuad(const DrawingFrame& frame, | |
| 136 const TextureDrawQuad* quad); | |
| 137 void FlushTextureQuadCache(); | |
| 138 void DrawIOSurfaceQuad(const DrawingFrame& frame, | |
| 139 const IOSurfaceDrawQuad* quad); | |
| 140 void DrawTileQuad(const DrawingFrame& frame, const TileDrawQuad* quad); | |
| 141 void DrawYUVVideoQuad(const DrawingFrame& frame, | |
| 142 const YUVVideoDrawQuad* quad); | |
| 143 | |
| 144 void SetShaderOpacity(float opacity, int alpha_location); | |
| 145 void SetShaderQuadF(const gfx::QuadF& quad, int quad_location); | |
| 146 void DrawQuadGeometry(const DrawingFrame& frame, | |
| 147 const gfx::Transform& draw_transform, | |
| 148 const gfx::RectF& quad_rect, | |
| 149 int matrix_location); | |
| 150 void SetBlendEnabled(bool enabled); | |
| 151 void SetUseProgram(unsigned program); | |
| 152 | |
| 153 void CopyTextureToFramebuffer(const DrawingFrame& frame, | |
| 154 int texture_id, | |
| 155 gfx::Rect rect, | |
| 156 const gfx::Transform& draw_matrix); | |
| 157 | |
| 158 // Check if quad needs antialiasing and if so, inflate the quad and | |
| 159 // fill edge array for fragment shader. localQuad is set to | |
| 160 // inflated quad if antialiasing is required, otherwise it is left | |
| 161 // unchanged. edge array is filled with inflated quad's edge data | |
| 162 // if antialiasing is required, otherwise it is left unchanged. | |
| 163 // Returns true if quad requires antialiasing and false otherwise. | |
| 164 bool SetupQuadForAntialiasing(const gfx::Transform& device_transform, | |
| 165 const DrawQuad* quad, | |
| 166 gfx::QuadF* local_quad, | |
| 167 float edge[24]) const; | |
| 168 | |
| 169 bool UseScopedTexture(DrawingFrame& frame, | |
| 170 const ScopedResource* resource, | |
| 171 gfx::Rect viewport_rect); | |
| 172 | |
| 173 bool MakeContextCurrent(); | |
| 174 | |
| 175 bool InitializeSharedObjects(); | |
| 176 void CleanupSharedObjects(); | |
| 177 | |
| 178 // WebKit:: | |
| 179 // WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM | |
| 180 // implementation. | |
| 181 virtual void onSwapBuffersComplete() OVERRIDE; | |
| 182 | |
| 183 // WebKit:: | |
| 184 // WebGraphicsContext3D::WebGraphicsMemoryAllocationChangedCallbackCHROMIUM | |
| 185 // implementation. | |
| 186 virtual void onMemoryAllocationChanged( | |
| 187 WebKit::WebGraphicsMemoryAllocation allocation) OVERRIDE; | |
| 188 void DiscardBackbuffer(); | |
| 189 void EnsureBackbuffer(); | |
| 190 void EnforceMemoryPolicy(); | |
| 191 | |
| 192 // WebGraphicsContext3D::WebGraphicsContextLostCallback implementation. | |
| 193 virtual void onContextLost() OVERRIDE; | |
| 194 | |
| 195 RendererCapabilities capabilities_; | |
| 196 | |
| 197 unsigned offscreen_framebuffer_id_; | |
| 198 | |
| 199 scoped_ptr<GeometryBinding> shared_geometry_; | |
| 200 gfx::QuadF shared_geometry_quad_; | |
| 201 | |
| 202 // This block of bindings defines all of the programs used by the compositor | |
| 203 // itself. Add any new programs here to GLRendererShaderTest. | |
| 204 | |
| 205 // Tiled layer shaders. | |
| 206 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexAlpha> | |
| 207 TileProgram; | |
| 208 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexClampAlphaAA> | |
| 209 TileProgramAA; | |
| 210 typedef ProgramBinding<VertexShaderTile, | |
| 211 FragmentShaderRGBATexClampSwizzleAlphaAA> | |
| 212 TileProgramSwizzleAA; | |
| 213 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexOpaque> | |
| 214 TileProgramOpaque; | |
| 215 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexSwizzleAlpha> | |
| 216 TileProgramSwizzle; | |
| 217 typedef ProgramBinding<VertexShaderTile, FragmentShaderRGBATexSwizzleOpaque> | |
| 218 TileProgramSwizzleOpaque; | |
| 219 typedef ProgramBinding<VertexShaderPosTex, FragmentShaderCheckerboard> | |
| 220 TileCheckerboardProgram; | |
| 221 | |
| 222 // Render surface shaders. | |
| 223 typedef ProgramBinding<VertexShaderPosTexTransform, | |
| 224 FragmentShaderRGBATexAlpha> RenderPassProgram; | |
| 225 typedef ProgramBinding<VertexShaderPosTexTransform, | |
| 226 FragmentShaderRGBATexAlphaMask> RenderPassMaskProgram; | |
| 227 typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaAA> | |
| 228 RenderPassProgramAA; | |
| 229 typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaMaskAA> | |
| 230 RenderPassMaskProgramAA; | |
| 231 | |
| 232 // Texture shaders. | |
| 233 typedef ProgramBinding<VertexShaderPosTexTransform, | |
| 234 FragmentShaderRGBATexVaryingAlpha> TextureProgram; | |
| 235 typedef ProgramBinding<VertexShaderPosTexTransformFlip, | |
| 236 FragmentShaderRGBATexVaryingAlpha> TextureProgramFlip; | |
| 237 typedef ProgramBinding<VertexShaderPosTexTransform, | |
| 238 FragmentShaderRGBATexRectVaryingAlpha> | |
| 239 TextureIOSurfaceProgram; | |
| 240 | |
| 241 // Video shaders. | |
| 242 typedef ProgramBinding<VertexShaderVideoTransform, | |
| 243 FragmentShaderOESImageExternal> | |
| 244 VideoStreamTextureProgram; | |
| 245 typedef ProgramBinding<VertexShaderPosTexYUVStretch, FragmentShaderYUVVideo> | |
| 246 VideoYUVProgram; | |
| 247 | |
| 248 // Special purpose / effects shaders. | |
| 249 typedef ProgramBinding<VertexShaderPos, FragmentShaderColor> | |
| 250 DebugBorderProgram; | |
| 251 typedef ProgramBinding<VertexShaderQuad, FragmentShaderColor> | |
| 252 SolidColorProgram; | |
| 253 typedef ProgramBinding<VertexShaderQuad, FragmentShaderColorAA> | |
| 254 SolidColorProgramAA; | |
| 255 | |
| 256 const TileProgram* GetTileProgram(); | |
| 257 const TileProgramOpaque* GetTileProgramOpaque(); | |
| 258 const TileProgramAA* GetTileProgramAA(); | |
| 259 const TileProgramSwizzle* GetTileProgramSwizzle(); | |
| 260 const TileProgramSwizzleOpaque* GetTileProgramSwizzleOpaque(); | |
| 261 const TileProgramSwizzleAA* GetTileProgramSwizzleAA(); | |
| 262 const TileCheckerboardProgram* GetTileCheckerboardProgram(); | |
| 263 | |
| 264 const RenderPassProgram* GetRenderPassProgram(); | |
| 265 const RenderPassProgramAA* GetRenderPassProgramAA(); | |
| 266 const RenderPassMaskProgram* GetRenderPassMaskProgram(); | |
| 267 const RenderPassMaskProgramAA* GetRenderPassMaskProgramAA(); | |
| 268 | |
| 269 const TextureProgram* GetTextureProgram(); | |
| 270 const TextureProgramFlip* GetTextureProgramFlip(); | |
| 271 const TextureIOSurfaceProgram* GetTextureIOSurfaceProgram(); | |
| 272 | |
| 273 const VideoYUVProgram* GetVideoYUVProgram(); | |
| 274 const VideoStreamTextureProgram* GetVideoStreamTextureProgram(); | |
| 275 | |
| 276 const DebugBorderProgram* GetDebugBorderProgram(); | |
| 277 const SolidColorProgram* GetSolidColorProgram(); | |
| 278 const SolidColorProgramAA* GetSolidColorProgramAA(); | |
| 279 | |
| 280 scoped_ptr<TileProgram> tile_program_; | |
| 281 scoped_ptr<TileProgramOpaque> tile_program_opaque_; | |
| 282 scoped_ptr<TileProgramAA> tile_program_aa_; | |
| 283 scoped_ptr<TileProgramSwizzle> tile_program_swizzle_; | |
| 284 scoped_ptr<TileProgramSwizzleOpaque> tile_program_swizzle_opaque_; | |
| 285 scoped_ptr<TileProgramSwizzleAA> tile_program_swizzle_aa_; | |
| 286 scoped_ptr<TileCheckerboardProgram> tile_checkerboard_program_; | |
| 287 | |
| 288 scoped_ptr<RenderPassProgram> render_pass_program_; | |
| 289 scoped_ptr<RenderPassProgramAA> render_pass_program_aa_; | |
| 290 scoped_ptr<RenderPassMaskProgram> render_pass_mask_program_; | |
| 291 scoped_ptr<RenderPassMaskProgramAA> render_pass_mask_program_aa_; | |
| 292 | |
| 293 scoped_ptr<TextureProgram> texture_program_; | |
| 294 scoped_ptr<TextureProgramFlip> texture_program_flip_; | |
| 295 scoped_ptr<TextureIOSurfaceProgram> texture_io_surface_program_; | |
| 296 | |
| 297 scoped_ptr<VideoYUVProgram> video_yuv_program_; | |
| 298 scoped_ptr<VideoStreamTextureProgram> video_stream_texture_program_; | |
| 299 | |
| 300 scoped_ptr<DebugBorderProgram> debug_border_program_; | |
| 301 scoped_ptr<SolidColorProgram> solid_color_program_; | |
| 302 scoped_ptr<SolidColorProgramAA> solid_color_program_aa_; | |
| 303 | |
| 304 OutputSurface* output_surface_; | |
| 305 WebKit::WebGraphicsContext3D* context_; | |
| 306 | |
| 307 gfx::Rect swap_buffer_rect_; | |
| 308 gfx::Rect scissor_rect_; | |
| 309 bool is_viewport_changed_; | |
| 310 bool is_backbuffer_discarded_; | |
| 311 bool discard_backbuffer_when_not_visible_; | |
| 312 bool is_using_bind_uniform_; | |
| 313 bool visible_; | |
| 314 bool is_scissor_enabled_; | |
| 315 bool blend_shadow_; | |
| 316 unsigned program_shadow_; | |
| 317 TexturedQuadDrawCache draw_cache_; | |
| 318 | |
| 319 scoped_ptr<ResourceProvider::ScopedWriteLockGL> current_framebuffer_lock_; | |
| 320 | |
| 321 scoped_refptr<ResourceProvider::Fence> last_swap_fence_; | |
| 322 | |
| 323 DISALLOW_COPY_AND_ASSIGN(GLRenderer); | |
| 324 }; | |
| 325 | |
| 326 // Setting DEBUG_GL_CALLS to 1 will call glGetError() after almost every GL | |
| 327 // call made by the compositor. Useful for debugging rendering issues but | |
| 328 // will significantly degrade performance. | |
| 329 #define DEBUG_GL_CALLS 0 | |
| 330 | |
| 331 #if DEBUG_GL_CALLS && !defined(NDEBUG) | |
| 332 #define GLC(context, x) \ | |
| 333 (x, GLRenderer::DebugGLCall (&* context, #x, __FILE__, __LINE__)) | |
| 334 #else | |
| 335 #define GLC(context, x) (x) | |
| 336 #endif | |
| 337 | |
| 338 } | |
| 339 | |
| 340 #endif // CC_GL_RENDERER_H_ | |
| OLD | NEW |