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.
5 #ifndef CC_OUTPUT_SOFTWARE_RENDERER_H_
6 #define CC_OUTPUT_SOFTWARE_RENDERER_H_
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"
17 class ResourceProvider
;
18 class SoftwareOutputDevice
;
20 class CheckerboardDrawQuad
;
21 class DebugBorderDrawQuad
;
22 class PictureDrawQuad
;
23 class RenderPassDrawQuad
;
24 class SolidColorDrawQuad
;
25 class TextureDrawQuad
;
28 class CC_EXPORT SoftwareRenderer
: public DirectRenderer
{
30 static scoped_ptr
<SoftwareRenderer
> Create(
31 RendererClient
* client
,
32 const LayerTreeSettings
* settings
,
33 OutputSurface
* output_surface
,
34 ResourceProvider
* resource_provider
);
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
,
41 const gfx::Rect
& rect
) OVERRIDE
;
42 virtual void SetVisible(bool visible
) OVERRIDE
;
43 virtual void SendManagedMemoryStats(
45 size_t bytes_visible_and_nearby
,
46 size_t bytes_allocated
) OVERRIDE
{}
47 virtual void ReceiveSwapBuffersAck(
48 const CompositorFrameAck
& ack
) OVERRIDE
;
49 virtual void DiscardBackbuffer() OVERRIDE
;
50 virtual void EnsureBackbuffer() OVERRIDE
;
53 virtual void BindFramebufferToOutputSurface(DrawingFrame
* frame
) OVERRIDE
;
54 virtual bool BindFramebufferToTexture(
56 const ScopedResource
* texture
,
57 const gfx::Rect
& target_rect
) OVERRIDE
;
58 virtual void SetDrawViewport(const gfx::Rect
& window_space_viewport
) OVERRIDE
;
59 virtual void SetScissorTestRect(const gfx::Rect
& scissor_rect
) OVERRIDE
;
60 virtual void DiscardPixels(bool has_external_stencil_test
,
61 bool draw_rect_covers_full_surface
) OVERRIDE
;
62 virtual void ClearFramebuffer(DrawingFrame
* frame
,
63 bool has_external_stencil_test
) OVERRIDE
;
64 virtual void DoDrawQuad(DrawingFrame
* frame
, const DrawQuad
* quad
) OVERRIDE
;
65 virtual void BeginDrawingFrame(DrawingFrame
* frame
) OVERRIDE
;
66 virtual void FinishDrawingFrame(DrawingFrame
* frame
) OVERRIDE
;
67 virtual bool FlippedFramebuffer() const OVERRIDE
;
68 virtual void EnsureScissorTestEnabled() OVERRIDE
;
69 virtual void EnsureScissorTestDisabled() OVERRIDE
;
70 virtual void CopyCurrentRenderPassToBitmap(
72 scoped_ptr
<CopyOutputRequest
> request
) OVERRIDE
;
74 SoftwareRenderer(RendererClient
* client
,
75 const LayerTreeSettings
* settings
,
76 OutputSurface
* output_surface
,
77 ResourceProvider
* resource_provider
);
80 void ClearCanvas(SkColor color
);
81 void SetClipRect(const gfx::Rect
& rect
);
82 bool IsSoftwareResource(ResourceProvider::ResourceId resource_id
) const;
84 void DrawCheckerboardQuad(const DrawingFrame
* frame
,
85 const CheckerboardDrawQuad
* quad
);
86 void DrawDebugBorderQuad(const DrawingFrame
* frame
,
87 const DebugBorderDrawQuad
* quad
);
88 void DrawPictureQuad(const DrawingFrame
* frame
,
89 const PictureDrawQuad
* quad
);
90 void DrawRenderPassQuad(const DrawingFrame
* frame
,
91 const RenderPassDrawQuad
* quad
);
92 void DrawSolidColorQuad(const DrawingFrame
* frame
,
93 const SolidColorDrawQuad
* quad
);
94 void DrawTextureQuad(const DrawingFrame
* frame
,
95 const TextureDrawQuad
* quad
);
96 void DrawTileQuad(const DrawingFrame
* frame
,
97 const TileDrawQuad
* quad
);
98 void DrawUnsupportedQuad(const DrawingFrame
* frame
,
99 const DrawQuad
* quad
);
101 RendererCapabilitiesImpl capabilities_
;
103 bool is_scissor_enabled_
;
104 bool is_backbuffer_discarded_
;
105 gfx::Rect scissor_rect_
;
107 SoftwareOutputDevice
* output_device_
;
108 SkCanvas
* root_canvas_
;
109 SkCanvas
* current_canvas_
;
110 SkPaint current_paint_
;
111 scoped_ptr
<ResourceProvider::ScopedWriteLockSoftware
>
112 current_framebuffer_lock_
;
113 scoped_ptr
<SoftwareFrameData
> current_frame_data_
;
115 DISALLOW_COPY_AND_ASSIGN(SoftwareRenderer
);
120 #endif // CC_OUTPUT_SOFTWARE_RENDERER_H_