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 RendererSettings
* settings
,
33 OutputSurface
* output_surface
,
34 ResourceProvider
* resource_provider
);
36 ~SoftwareRenderer() override
;
37 const RendererCapabilitiesImpl
& Capabilities() const override
;
38 void Finish() override
;
39 void SwapBuffers(const CompositorFrameMetadata
& metadata
) override
;
40 void ReceiveSwapBuffersAck(const CompositorFrameAck
& ack
) override
;
41 void DiscardBackbuffer() override
;
42 void EnsureBackbuffer() override
;
45 void BindFramebufferToOutputSurface(DrawingFrame
* frame
) override
;
46 bool BindFramebufferToTexture(DrawingFrame
* frame
,
47 const ScopedResource
* texture
,
48 const gfx::Rect
& target_rect
) override
;
49 void SetDrawViewport(const gfx::Rect
& window_space_viewport
) override
;
50 void SetScissorTestRect(const gfx::Rect
& scissor_rect
) override
;
51 void DiscardPixels(bool has_external_stencil_test
,
52 bool draw_rect_covers_full_surface
) override
;
53 void ClearFramebuffer(DrawingFrame
* frame
,
54 bool has_external_stencil_test
) override
;
56 void DoDrawQuad(DrawingFrame
* frame
,
58 const gfx::QuadF
* draw_region
) override
;
59 void BeginDrawingFrame(DrawingFrame
* frame
) override
;
60 void FinishDrawingFrame(DrawingFrame
* frame
) override
;
61 bool FlippedFramebuffer(const DrawingFrame
* frame
) const override
;
62 void EnsureScissorTestEnabled() override
;
63 void EnsureScissorTestDisabled() override
;
64 void CopyCurrentRenderPassToBitmap(
66 scoped_ptr
<CopyOutputRequest
> request
) override
;
68 SoftwareRenderer(RendererClient
* client
,
69 const RendererSettings
* settings
,
70 OutputSurface
* output_surface
,
71 ResourceProvider
* resource_provider
);
73 void DidChangeVisibility() override
;
76 void ClearCanvas(SkColor color
);
77 void SetClipRect(const gfx::Rect
& rect
);
78 bool IsSoftwareResource(ResourceProvider::ResourceId resource_id
) const;
80 void DrawCheckerboardQuad(const DrawingFrame
* frame
,
81 const CheckerboardDrawQuad
* quad
);
82 void DrawDebugBorderQuad(const DrawingFrame
* frame
,
83 const DebugBorderDrawQuad
* quad
);
84 void DrawPictureQuad(const DrawingFrame
* frame
,
85 const PictureDrawQuad
* quad
);
86 void DrawRenderPassQuad(const DrawingFrame
* frame
,
87 const RenderPassDrawQuad
* quad
);
88 void DrawSolidColorQuad(const DrawingFrame
* frame
,
89 const SolidColorDrawQuad
* quad
);
90 void DrawTextureQuad(const DrawingFrame
* frame
,
91 const TextureDrawQuad
* quad
);
92 void DrawTileQuad(const DrawingFrame
* frame
,
93 const TileDrawQuad
* quad
);
94 void DrawUnsupportedQuad(const DrawingFrame
* frame
,
95 const DrawQuad
* quad
);
97 RendererCapabilitiesImpl capabilities_
;
98 bool is_scissor_enabled_
;
99 bool is_backbuffer_discarded_
;
100 gfx::Rect scissor_rect_
;
102 SoftwareOutputDevice
* output_device_
;
103 SkCanvas
* root_canvas_
;
104 SkCanvas
* current_canvas_
;
105 SkPaint current_paint_
;
106 scoped_ptr
<ResourceProvider::ScopedWriteLockSoftware
>
107 current_framebuffer_lock_
;
108 skia::RefPtr
<SkCanvas
> current_framebuffer_canvas_
;
109 scoped_ptr
<SoftwareFrameData
> current_frame_data_
;
111 DISALLOW_COPY_AND_ASSIGN(SoftwareRenderer
);
116 #endif // CC_OUTPUT_SOFTWARE_RENDERER_H_