software_renderer.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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 SoftwareOutputDevice; 17class ContentDrawQuadBase; 18class DebugBorderDrawQuad; 19class PictureDrawQuad; 20class RendererClient; 21class RenderPassDrawQuad; 22class ResourceProvider; 23class SolidColorDrawQuad; 24class TextureDrawQuad; 25class TileDrawQuad; 26 27class CC_EXPORT SoftwareRenderer : public DirectRenderer { 28 public: 29 static scoped_ptr<SoftwareRenderer> Create( 30 RendererClient* client, 31 OutputSurface* output_surface, 32 ResourceProvider* resource_provider); 33 34 virtual ~SoftwareRenderer(); 35 virtual const RendererCapabilities& Capabilities() const OVERRIDE; 36 virtual void ViewportChanged() OVERRIDE; 37 virtual void Finish() OVERRIDE; 38 virtual void SwapBuffers(const ui::LatencyInfo& latency_info) OVERRIDE; 39 virtual void GetFramebufferPixels(void* pixels, gfx::Rect rect) OVERRIDE; 40 virtual void SetVisible(bool visible) OVERRIDE; 41 virtual void SendManagedMemoryStats( 42 size_t bytes_visible, 43 size_t bytes_visible_and_nearby, 44 size_t bytes_allocated) OVERRIDE {} 45 virtual void ReceiveCompositorFrameAck( 46 const CompositorFrameAck& ack) OVERRIDE; 47 48 protected: 49 virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) OVERRIDE; 50 virtual bool BindFramebufferToTexture( 51 DrawingFrame* frame, 52 const ScopedResource* texture, 53 gfx::Rect framebuffer_rect) OVERRIDE; 54 virtual void SetDrawViewportSize(gfx::Size viewport_size) OVERRIDE; 55 virtual void SetScissorTestRect(gfx::Rect scissor_rect) OVERRIDE; 56 virtual void ClearFramebuffer(DrawingFrame* frame) 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 private: 68 SoftwareRenderer( 69 RendererClient* client, 70 OutputSurface* output_surface, 71 ResourceProvider* resource_provider); 72 73 void ClearCanvas(SkColor color); 74 void SetClipRect(gfx::Rect rect); 75 bool IsSoftwareResource(ResourceProvider::ResourceId resource_id) const; 76 77 void DrawDebugBorderQuad(const DrawingFrame* frame, 78 const DebugBorderDrawQuad* quad); 79 void DrawPictureQuad(const DrawingFrame* frame, 80 const PictureDrawQuad* quad); 81 void DrawSolidColorQuad(const DrawingFrame* frame, 82 const SolidColorDrawQuad* quad); 83 void DrawTextureQuad(const DrawingFrame* frame, 84 const TextureDrawQuad* quad); 85 void DrawTileQuad(const DrawingFrame* frame, 86 const TileDrawQuad* quad); 87 void DrawRenderPassQuad(const DrawingFrame* frame, 88 const RenderPassDrawQuad* quad); 89 void DrawUnsupportedQuad(const DrawingFrame* frame, 90 const DrawQuad* quad); 91 92 RendererCapabilities capabilities_; 93 bool visible_; 94 bool is_scissor_enabled_; 95 bool is_viewport_changed_; 96 gfx::Rect scissor_rect_; 97 98 OutputSurface* output_surface_; 99 SoftwareOutputDevice* output_device_; 100 SkCanvas* root_canvas_; 101 SkCanvas* current_canvas_; 102 SkPaint current_paint_; 103 scoped_ptr<ResourceProvider::ScopedWriteLockSoftware> 104 current_framebuffer_lock_; 105 CompositorFrame compositor_frame_; 106 107 DISALLOW_COPY_AND_ASSIGN(SoftwareRenderer); 108}; 109 110} // namespace cc 111 112#endif // CC_OUTPUT_SOFTWARE_RENDERER_H_ 113