1 // Copyright 2012 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_OUTPUT_SOFTWARE_RENDERER_H_ 6 #define CC_OUTPUT_SOFTWARE_RENDERER_H_ 7 8 #include "base/basictypes.h" 9 #include "cc/base/cc_export.h" 10 #include "cc/output/compositor_frame.h" 11 #include "cc/output/direct_renderer.h" 12 13 namespace cc { 14 15 class OutputSurface; 16 class RendererClient; 17 class ResourceProvider; 18 class SoftwareOutputDevice; 19 20 class CheckerboardDrawQuad; 21 class DebugBorderDrawQuad; 22 class PictureDrawQuad; 23 class RenderPassDrawQuad; 24 class SolidColorDrawQuad; 25 class TextureDrawQuad; 26 class TileDrawQuad; 27 28 class CC_EXPORT SoftwareRenderer : public DirectRenderer { 29 public: 30 static scoped_ptr<SoftwareRenderer> Create( 31 RendererClient* client, 32 const LayerTreeSettings* settings, 33 OutputSurface* output_surface, 34 ResourceProvider* resource_provider); 35 36 virtual ~SoftwareRenderer(); 37 virtual const RendererCapabilitiesImpl& Capabilities() const OVERRIDE; 38 virtual void Finish() OVERRIDE; 39 virtual void SwapBuffers(const CompositorFrameMetadata& metadata) OVERRIDE; 40 virtual void ReceiveSwapBuffersAck( 41 const CompositorFrameAck& ack) OVERRIDE; 42 virtual void DiscardBackbuffer() OVERRIDE; 43 virtual void EnsureBackbuffer() OVERRIDE; 44 45 protected: 46 virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) OVERRIDE; 47 virtual bool BindFramebufferToTexture( 48 DrawingFrame* frame, 49 const ScopedResource* texture, 50 const gfx::Rect& target_rect) OVERRIDE; 51 virtual void SetDrawViewport(const gfx::Rect& window_space_viewport) OVERRIDE; 52 virtual void SetScissorTestRect(const gfx::Rect& scissor_rect) OVERRIDE; 53 virtual void DiscardPixels(bool has_external_stencil_test, 54 bool draw_rect_covers_full_surface) OVERRIDE; 55 virtual void ClearFramebuffer(DrawingFrame* frame, 56 bool has_external_stencil_test) OVERRIDE; 57 virtual void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) OVERRIDE; 58 virtual void BeginDrawingFrame(DrawingFrame* frame) OVERRIDE; 59 virtual void FinishDrawingFrame(DrawingFrame* frame) OVERRIDE; 60 virtual bool FlippedFramebuffer() const OVERRIDE; 61 virtual void EnsureScissorTestEnabled() OVERRIDE; 62 virtual void EnsureScissorTestDisabled() OVERRIDE; 63 virtual void CopyCurrentRenderPassToBitmap( 64 DrawingFrame* frame, 65 scoped_ptr<CopyOutputRequest> request) OVERRIDE; 66 67 SoftwareRenderer(RendererClient* client, 68 const LayerTreeSettings* settings, 69 OutputSurface* output_surface, 70 ResourceProvider* resource_provider); 71 72 virtual void DidChangeVisibility() OVERRIDE; 73 74 private: 75 void ClearCanvas(SkColor color); 76 void SetClipRect(const gfx::Rect& rect); 77 bool IsSoftwareResource(ResourceProvider::ResourceId resource_id) const; 78 79 void DrawCheckerboardQuad(const DrawingFrame* frame, 80 const CheckerboardDrawQuad* quad); 81 void DrawDebugBorderQuad(const DrawingFrame* frame, 82 const DebugBorderDrawQuad* quad); 83 void DrawPictureQuad(const DrawingFrame* frame, 84 const PictureDrawQuad* quad); 85 void DrawRenderPassQuad(const DrawingFrame* frame, 86 const RenderPassDrawQuad* quad); 87 void DrawSolidColorQuad(const DrawingFrame* frame, 88 const SolidColorDrawQuad* quad); 89 void DrawTextureQuad(const DrawingFrame* frame, 90 const TextureDrawQuad* quad); 91 void DrawTileQuad(const DrawingFrame* frame, 92 const TileDrawQuad* quad); 93 void DrawUnsupportedQuad(const DrawingFrame* frame, 94 const DrawQuad* quad); 95 96 RendererCapabilitiesImpl capabilities_; 97 bool is_scissor_enabled_; 98 bool is_backbuffer_discarded_; 99 gfx::Rect scissor_rect_; 100 101 SoftwareOutputDevice* output_device_; 102 SkCanvas* root_canvas_; 103 SkCanvas* current_canvas_; 104 SkPaint current_paint_; 105 scoped_ptr<ResourceProvider::ScopedWriteLockSoftware> 106 current_framebuffer_lock_; 107 scoped_ptr<SoftwareFrameData> current_frame_data_; 108 109 DISALLOW_COPY_AND_ASSIGN(SoftwareRenderer); 110 }; 111 112 } // namespace cc 113 114 #endif // CC_OUTPUT_SOFTWARE_RENDERER_H_ 115