[NaCl SDK] Fix mysterious gtest failure in Html5FsTest::OpenForCreate
[chromium-blink-merge.git] / cc / output / direct_renderer.h
blob40fff835736e2452251df8bf33f0f5d9857db36d
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/overlay_processor.h"
13 #include "cc/output/renderer.h"
14 #include "cc/resources/resource_provider.h"
15 #include "cc/resources/scoped_resource.h"
17 namespace cc {
19 class ResourceProvider;
21 // This is the base class for code shared between the GL and software
22 // renderer implementations. "Direct" refers to the fact that it does not
23 // delegate rendering to another compositor.
24 class CC_EXPORT DirectRenderer : public Renderer {
25 public:
26 ~DirectRenderer() override;
28 void DecideRenderPassAllocationsForFrame(
29 const RenderPassList& render_passes_in_draw_order) override;
30 bool HasAllocatedResourcesForTesting(RenderPassId id) const override;
31 void DrawFrame(RenderPassList* render_passes_in_draw_order,
32 float device_scale_factor,
33 const gfx::Rect& device_viewport_rect,
34 const gfx::Rect& device_clip_rect,
35 bool disable_picture_quad_image_filtering) override;
37 struct CC_EXPORT DrawingFrame {
38 DrawingFrame();
39 ~DrawingFrame();
41 const RenderPassList* render_passes_in_draw_order;
42 const RenderPass* root_render_pass;
43 const RenderPass* current_render_pass;
44 const ScopedResource* current_texture;
46 gfx::Rect root_damage_rect;
47 gfx::Rect device_viewport_rect;
48 gfx::Rect device_clip_rect;
50 gfx::Transform projection_matrix;
51 gfx::Transform window_matrix;
53 bool disable_picture_quad_image_filtering;
55 OverlayCandidateList overlay_list;
58 void SetEnlargePassTextureAmountForTesting(const gfx::Vector2d& amount);
60 protected:
61 DirectRenderer(RendererClient* client,
62 const LayerTreeSettings* settings,
63 OutputSurface* output_surface,
64 ResourceProvider* resource_provider);
66 static gfx::RectF QuadVertexRect();
67 static void QuadRectTransform(gfx::Transform* quad_rect_transform,
68 const gfx::Transform& quad_transform,
69 const gfx::RectF& quad_rect);
70 void InitializeViewport(DrawingFrame* frame,
71 const gfx::Rect& draw_rect,
72 const gfx::Rect& viewport_rect,
73 const gfx::Size& surface_size);
74 gfx::Rect MoveFromDrawToWindowSpace(const DrawingFrame* frame,
75 const gfx::Rect& draw_rect) const;
77 bool NeedDeviceClip(const DrawingFrame* frame) const;
78 gfx::Rect DeviceClipRectInWindowSpace(const DrawingFrame* frame) const;
79 static gfx::Rect ComputeScissorRectForRenderPass(const DrawingFrame* frame);
80 void SetScissorStateForQuad(const DrawingFrame* frame, const DrawQuad& quad);
81 void SetScissorStateForQuadWithRenderPassScissor(
82 const DrawingFrame* frame,
83 const DrawQuad& quad,
84 const gfx::Rect& render_pass_scissor,
85 bool* should_skip_quad);
86 void SetScissorTestRectInDrawSpace(const DrawingFrame* frame,
87 const gfx::Rect& draw_space_rect);
89 static gfx::Size RenderPassTextureSize(const RenderPass* render_pass);
91 void DrawRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
92 bool UseRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
94 virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) = 0;
95 virtual bool BindFramebufferToTexture(DrawingFrame* frame,
96 const ScopedResource* resource,
97 const gfx::Rect& target_rect) = 0;
98 virtual void SetDrawViewport(const gfx::Rect& window_space_viewport) = 0;
99 virtual void SetScissorTestRect(const gfx::Rect& scissor_rect) = 0;
100 virtual void DiscardPixels(bool has_external_stencil_test,
101 bool draw_rect_covers_full_surface) = 0;
102 virtual void ClearFramebuffer(DrawingFrame* frame,
103 bool has_external_stencil_test) = 0;
104 virtual void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) = 0;
105 virtual void BeginDrawingFrame(DrawingFrame* frame) = 0;
106 virtual void FinishDrawingFrame(DrawingFrame* frame) = 0;
107 virtual void FinishDrawingQuadList();
108 virtual bool FlippedFramebuffer(const DrawingFrame* frame) const = 0;
109 virtual void EnsureScissorTestEnabled() = 0;
110 virtual void EnsureScissorTestDisabled() = 0;
111 virtual void DiscardBackbuffer() {}
112 virtual void EnsureBackbuffer() {}
114 virtual void CopyCurrentRenderPassToBitmap(
115 DrawingFrame* frame,
116 scoped_ptr<CopyOutputRequest> request) = 0;
118 base::ScopedPtrHashMap<RenderPassId, ScopedResource> render_pass_textures_;
119 OutputSurface* output_surface_;
120 ResourceProvider* resource_provider_;
121 scoped_ptr<OverlayProcessor> overlay_processor_;
123 // For use in coordinate conversion, this stores the output rect, viewport
124 // rect (= unflipped version of glViewport rect), and the size of target
125 // framebuffer. During a draw, this stores the values for the current render
126 // pass; in between draws, they retain the values for the root render pass of
127 // the last draw.
128 gfx::Rect current_draw_rect_;
129 gfx::Rect current_viewport_rect_;
130 gfx::Size current_surface_size_;
132 private:
133 gfx::Vector2d enlarge_pass_texture_amount_;
135 DISALLOW_COPY_AND_ASSIGN(DirectRenderer);
138 } // namespace cc
140 #endif // CC_OUTPUT_DIRECT_RENDERER_H_