software_renderer.h revision 58537e28ecd584eab876aee8be7156509866d23a
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
13namespace cc {
14
15class OutputSurface;
16class RendererClient;
17class ResourceProvider;
18class SoftwareOutputDevice;
19
20class CheckerboardDrawQuad;
21class DebugBorderDrawQuad;
22class PictureDrawQuad;
23class RenderPassDrawQuad;
24class SolidColorDrawQuad;
25class TextureDrawQuad;
26class TileDrawQuad;
27
28class 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 RendererCapabilities& Capabilities() const OVERRIDE;
38  virtual void Finish() OVERRIDE;
39  virtual void SwapBuffers() 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 SetDiscardBackBufferWhenNotVisible(bool discard) OVERRIDE;
49  virtual void DiscardBackbuffer() OVERRIDE;
50  virtual void EnsureBackbuffer() OVERRIDE;
51
52 protected:
53  virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) OVERRIDE;
54  virtual bool BindFramebufferToTexture(
55      DrawingFrame* frame,
56      const ScopedResource* texture,
57      gfx::Rect target_rect) OVERRIDE;
58  virtual void SetDrawViewport(gfx::Rect window_space_viewport) OVERRIDE;
59  virtual void SetScissorTestRect(gfx::Rect scissor_rect) OVERRIDE;
60  virtual void ClearFramebuffer(DrawingFrame* frame) OVERRIDE;
61  virtual void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) OVERRIDE;
62  virtual void BeginDrawingFrame(DrawingFrame* frame) OVERRIDE;
63  virtual void FinishDrawingFrame(DrawingFrame* frame) OVERRIDE;
64  virtual bool FlippedFramebuffer() const OVERRIDE;
65  virtual void EnsureScissorTestEnabled() OVERRIDE;
66  virtual void EnsureScissorTestDisabled() OVERRIDE;
67  virtual void CopyCurrentRenderPassToBitmap(
68      DrawingFrame* frame,
69      scoped_ptr<CopyOutputRequest> request) OVERRIDE;
70
71  SoftwareRenderer(RendererClient* client,
72                   const LayerTreeSettings* settings,
73                   OutputSurface* output_surface,
74                   ResourceProvider* resource_provider);
75
76 private:
77  void ClearCanvas(SkColor color);
78  void SetClipRect(gfx::Rect rect);
79  bool IsSoftwareResource(ResourceProvider::ResourceId resource_id) const;
80
81  void DrawCheckerboardQuad(const DrawingFrame* frame,
82                            const CheckerboardDrawQuad* quad);
83  void DrawDebugBorderQuad(const DrawingFrame* frame,
84                           const DebugBorderDrawQuad* quad);
85  void DrawPictureQuad(const DrawingFrame* frame,
86                       const PictureDrawQuad* quad);
87  void DrawRenderPassQuad(const DrawingFrame* frame,
88                          const RenderPassDrawQuad* quad);
89  void DrawSolidColorQuad(const DrawingFrame* frame,
90                          const SolidColorDrawQuad* quad);
91  void DrawTextureQuad(const DrawingFrame* frame,
92                       const TextureDrawQuad* quad);
93  void DrawTileQuad(const DrawingFrame* frame,
94                    const TileDrawQuad* quad);
95  void DrawUnsupportedQuad(const DrawingFrame* frame,
96                           const DrawQuad* quad);
97
98  RendererCapabilities capabilities_;
99  bool visible_;
100  bool is_scissor_enabled_;
101  bool is_backbuffer_discarded_;
102  gfx::Rect scissor_rect_;
103
104  SoftwareOutputDevice* output_device_;
105  SkCanvas* root_canvas_;
106  SkCanvas* current_canvas_;
107  SkPaint current_paint_;
108  scoped_ptr<ResourceProvider::ScopedWriteLockSoftware>
109      current_framebuffer_lock_;
110  scoped_ptr<SoftwareFrameData> current_frame_data_;
111
112  DISALLOW_COPY_AND_ASSIGN(SoftwareRenderer);
113};
114
115}  // namespace cc
116
117#endif  // CC_OUTPUT_SOFTWARE_RENDERER_H_
118