Fix import error in mac_platform_backend.py
[chromium-blink-merge.git] / cc / output / direct_renderer.h
blob451c7d712ef84d143b0bee8adcbf4c7d1740e380
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_DIRECT_RENDERER_H_
6 #define CC_OUTPUT_DIRECT_RENDERER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/containers/scoped_ptr_hash_map.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/output/renderer.h"
13 #include "cc/resources/resource_provider.h"
14 #include "cc/resources/scoped_resource.h"
16 namespace cc {
18 class ResourceProvider;
20 // This is the base class for code shared between the GL and software
21 // renderer implementations. "Direct" refers to the fact that it does not
22 // delegate rendering to another compositor.
23 class CC_EXPORT DirectRenderer : public Renderer {
24 public:
25 virtual ~DirectRenderer();
27 ResourceProvider* resource_provider() const { return resource_provider_; }
29 virtual bool CanReadPixels() const OVERRIDE;
30 virtual void DecideRenderPassAllocationsForFrame(
31 const RenderPassList& render_passes_in_draw_order) OVERRIDE;
32 virtual bool HasAllocatedResourcesForTesting(RenderPass::Id id) const
33 OVERRIDE;
34 virtual void DrawFrame(RenderPassList* render_passes_in_draw_order,
35 ContextProvider* offscreen_context_provider,
36 float device_scale_factor,
37 const gfx::Rect& device_viewport_rect,
38 const gfx::Rect& device_clip_rect,
39 bool allow_partial_swap,
40 bool disable_picture_quad_image_filtering) OVERRIDE;
42 struct CC_EXPORT DrawingFrame {
43 DrawingFrame();
44 ~DrawingFrame();
46 const RenderPass* root_render_pass;
47 const RenderPass* current_render_pass;
48 const ScopedResource* current_texture;
50 gfx::RectF root_damage_rect;
51 gfx::Rect device_viewport_rect;
52 gfx::Rect device_clip_rect;
54 gfx::Transform projection_matrix;
55 gfx::Transform window_matrix;
57 ContextProvider* offscreen_context_provider;
59 bool disable_picture_quad_image_filtering;
62 void SetEnlargePassTextureAmountForTesting(const gfx::Vector2d& amount);
64 protected:
65 DirectRenderer(RendererClient* client,
66 const LayerTreeSettings* settings,
67 OutputSurface* output_surface,
68 ResourceProvider* resource_provider);
70 static gfx::RectF QuadVertexRect();
71 static void QuadRectTransform(gfx::Transform* quad_rect_transform,
72 const gfx::Transform& quad_transform,
73 const gfx::RectF& quad_rect);
74 void InitializeViewport(DrawingFrame* frame,
75 const gfx::Rect& draw_rect,
76 const gfx::Rect& viewport_rect,
77 const gfx::Size& surface_size);
78 gfx::Rect MoveFromDrawToWindowSpace(const gfx::RectF& draw_rect) const;
80 bool NeedDeviceClip(const DrawingFrame* frame) const;
81 gfx::Rect DeviceClipRectInWindowSpace(const DrawingFrame* frame) const;
82 static gfx::RectF ComputeScissorRectForRenderPass(const DrawingFrame* frame);
83 void SetScissorStateForQuad(const DrawingFrame* frame, const DrawQuad& quad);
84 void SetScissorStateForQuadWithRenderPassScissor(
85 const DrawingFrame* frame,
86 const DrawQuad& quad,
87 const gfx::RectF& render_pass_scissor,
88 bool* should_skip_quad);
89 void SetScissorTestRectInDrawSpace(const DrawingFrame* frame,
90 const gfx::RectF& draw_space_rect);
92 static gfx::Size RenderPassTextureSize(const RenderPass* render_pass);
94 void DrawRenderPass(DrawingFrame* frame,
95 const RenderPass* render_pass,
96 bool allow_partial_swap);
97 bool UseRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
99 virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) = 0;
100 virtual bool BindFramebufferToTexture(DrawingFrame* frame,
101 const ScopedResource* resource,
102 const gfx::Rect& target_rect) = 0;
103 virtual void SetDrawViewport(const gfx::Rect& window_space_viewport) = 0;
104 virtual void SetScissorTestRect(const gfx::Rect& scissor_rect) = 0;
105 virtual void DiscardPixels(bool has_external_stencil_test,
106 bool draw_rect_covers_full_surface) = 0;
107 virtual void ClearFramebuffer(DrawingFrame* frame,
108 bool has_external_stencil_test) = 0;
109 virtual void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) = 0;
110 virtual void BeginDrawingFrame(DrawingFrame* frame) = 0;
111 virtual void FinishDrawingFrame(DrawingFrame* frame) = 0;
112 virtual void FinishDrawingQuadList();
113 virtual bool FlippedFramebuffer() const = 0;
114 virtual void EnsureScissorTestEnabled() = 0;
115 virtual void EnsureScissorTestDisabled() = 0;
116 virtual void DiscardBackbuffer() {}
117 virtual void EnsureBackbuffer() {}
119 virtual void CopyCurrentRenderPassToBitmap(
120 DrawingFrame* frame,
121 scoped_ptr<CopyOutputRequest> request) = 0;
123 base::ScopedPtrHashMap<RenderPass::Id, ScopedResource> render_pass_textures_;
124 OutputSurface* output_surface_;
125 ResourceProvider* resource_provider_;
127 // For use in coordinate conversion, this stores the output rect, viewport
128 // rect (= unflipped version of glViewport rect), and the size of target
129 // framebuffer. During a draw, this stores the values for the current render
130 // pass; in between draws, they retain the values for the root render pass of
131 // the last draw.
132 gfx::Rect current_draw_rect_;
133 gfx::Rect current_viewport_rect_;
134 gfx::Size current_surface_size_;
136 private:
137 gfx::Vector2d enlarge_pass_texture_amount_;
139 DISALLOW_COPY_AND_ASSIGN(DirectRenderer);
142 } // namespace cc
144 #endif // CC_OUTPUT_DIRECT_RENDERER_H_