Home | History | Annotate | Download | only in output
      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 GetFramebufferPixels(void* pixels, gfx::Rect rect) OVERRIDE;
     41   virtual void SetVisible(bool visible) OVERRIDE;
     42   virtual void SendManagedMemoryStats(
     43       size_t bytes_visible,
     44       size_t bytes_visible_and_nearby,
     45       size_t bytes_allocated) OVERRIDE  {}
     46   virtual void ReceiveSwapBuffersAck(
     47       const CompositorFrameAck& ack) OVERRIDE;
     48   virtual void DiscardBackbuffer() OVERRIDE;
     49   virtual void EnsureBackbuffer() OVERRIDE;
     50 
     51  protected:
     52   virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) OVERRIDE;
     53   virtual bool BindFramebufferToTexture(
     54       DrawingFrame* frame,
     55       const ScopedResource* texture,
     56       gfx::Rect target_rect) OVERRIDE;
     57   virtual void SetDrawViewport(gfx::Rect window_space_viewport) OVERRIDE;
     58   virtual void SetScissorTestRect(gfx::Rect scissor_rect) OVERRIDE;
     59   virtual void DiscardPixels(bool has_external_stencil_test,
     60                              bool draw_rect_covers_full_surface) OVERRIDE;
     61   virtual void ClearFramebuffer(DrawingFrame* frame,
     62                                 bool has_external_stencil_test) OVERRIDE;
     63   virtual void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) OVERRIDE;
     64   virtual void BeginDrawingFrame(DrawingFrame* frame) OVERRIDE;
     65   virtual void FinishDrawingFrame(DrawingFrame* frame) OVERRIDE;
     66   virtual bool FlippedFramebuffer() const OVERRIDE;
     67   virtual void EnsureScissorTestEnabled() OVERRIDE;
     68   virtual void EnsureScissorTestDisabled() OVERRIDE;
     69   virtual void CopyCurrentRenderPassToBitmap(
     70       DrawingFrame* frame,
     71       scoped_ptr<CopyOutputRequest> request) OVERRIDE;
     72 
     73   SoftwareRenderer(RendererClient* client,
     74                    const LayerTreeSettings* settings,
     75                    OutputSurface* output_surface,
     76                    ResourceProvider* resource_provider);
     77 
     78  private:
     79   void ClearCanvas(SkColor color);
     80   void SetClipRect(gfx::Rect rect);
     81   bool IsSoftwareResource(ResourceProvider::ResourceId resource_id) const;
     82 
     83   void DrawCheckerboardQuad(const DrawingFrame* frame,
     84                             const CheckerboardDrawQuad* quad);
     85   void DrawDebugBorderQuad(const DrawingFrame* frame,
     86                            const DebugBorderDrawQuad* quad);
     87   void DrawPictureQuad(const DrawingFrame* frame,
     88                        const PictureDrawQuad* quad);
     89   void DrawRenderPassQuad(const DrawingFrame* frame,
     90                           const RenderPassDrawQuad* quad);
     91   void DrawSolidColorQuad(const DrawingFrame* frame,
     92                           const SolidColorDrawQuad* quad);
     93   void DrawTextureQuad(const DrawingFrame* frame,
     94                        const TextureDrawQuad* quad);
     95   void DrawTileQuad(const DrawingFrame* frame,
     96                     const TileDrawQuad* quad);
     97   void DrawUnsupportedQuad(const DrawingFrame* frame,
     98                            const DrawQuad* quad);
     99 
    100   RendererCapabilitiesImpl capabilities_;
    101   bool visible_;
    102   bool is_scissor_enabled_;
    103   bool is_backbuffer_discarded_;
    104   gfx::Rect scissor_rect_;
    105 
    106   SoftwareOutputDevice* output_device_;
    107   SkCanvas* root_canvas_;
    108   SkCanvas* current_canvas_;
    109   SkPaint current_paint_;
    110   scoped_ptr<ResourceProvider::ScopedWriteLockSoftware>
    111       current_framebuffer_lock_;
    112   scoped_ptr<SoftwareFrameData> current_frame_data_;
    113 
    114   DISALLOW_COPY_AND_ASSIGN(SoftwareRenderer);
    115 };
    116 
    117 }  // namespace cc
    118 
    119 #endif  // CC_OUTPUT_SOFTWARE_RENDERER_H_
    120