Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / output / direct_renderer.h
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_DIRECT_RENDERER_H_
6 #define CC_OUTPUT_DIRECT_RENDERER_H_
7
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"
16 #include "cc/resources/task_graph_runner.h"
17
18 namespace cc {
19
20 class ResourceProvider;
21
22 // This is the base class for code shared between the GL and software
23 // renderer implementations.  "Direct" refers to the fact that it does not
24 // delegate rendering to another compositor.
25 class CC_EXPORT DirectRenderer : public Renderer {
26  public:
27   virtual ~DirectRenderer();
28
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                          float device_scale_factor,
36                          const gfx::Rect& device_viewport_rect,
37                          const gfx::Rect& device_clip_rect,
38                          bool disable_picture_quad_image_filtering) OVERRIDE;
39
40   struct CC_EXPORT DrawingFrame {
41     DrawingFrame();
42     ~DrawingFrame();
43
44     const RenderPass* root_render_pass;
45     const RenderPass* current_render_pass;
46     const ScopedResource* current_texture;
47
48     gfx::Rect root_damage_rect;
49     gfx::Rect device_viewport_rect;
50     gfx::Rect device_clip_rect;
51
52     gfx::Transform projection_matrix;
53     gfx::Transform window_matrix;
54
55     bool disable_picture_quad_image_filtering;
56
57     OverlayCandidateList overlay_list;
58   };
59
60   void SetEnlargePassTextureAmountForTesting(const gfx::Vector2d& amount);
61
62  protected:
63   DirectRenderer(RendererClient* client,
64                  const LayerTreeSettings* settings,
65                  OutputSurface* output_surface,
66                  ResourceProvider* resource_provider);
67
68   static gfx::RectF QuadVertexRect();
69   static void QuadRectTransform(gfx::Transform* quad_rect_transform,
70                                 const gfx::Transform& quad_transform,
71                                 const gfx::RectF& quad_rect);
72   void InitializeViewport(DrawingFrame* frame,
73                           const gfx::Rect& draw_rect,
74                           const gfx::Rect& viewport_rect,
75                           const gfx::Size& surface_size);
76   gfx::Rect MoveFromDrawToWindowSpace(const gfx::Rect& draw_rect) const;
77
78   bool NeedDeviceClip(const DrawingFrame* frame) const;
79   gfx::Rect DeviceClipRectInWindowSpace(const DrawingFrame* frame) const;
80   static gfx::Rect ComputeScissorRectForRenderPass(const DrawingFrame* frame);
81   void SetScissorStateForQuad(const DrawingFrame* frame, const DrawQuad& quad);
82   void SetScissorStateForQuadWithRenderPassScissor(
83       const DrawingFrame* frame,
84       const DrawQuad& quad,
85       const gfx::Rect& render_pass_scissor,
86       bool* should_skip_quad);
87   void SetScissorTestRectInDrawSpace(const DrawingFrame* frame,
88                                      const gfx::Rect& draw_space_rect);
89
90   static gfx::Size RenderPassTextureSize(const RenderPass* render_pass);
91
92   void DrawRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
93   bool UseRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
94
95   void RunOnDemandRasterTask(Task* on_demand_raster_task);
96
97   virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) = 0;
98   virtual bool BindFramebufferToTexture(DrawingFrame* frame,
99                                         const ScopedResource* resource,
100                                         const gfx::Rect& target_rect) = 0;
101   virtual void SetDrawViewport(const gfx::Rect& window_space_viewport) = 0;
102   virtual void SetScissorTestRect(const gfx::Rect& scissor_rect) = 0;
103   virtual void DiscardPixels(bool has_external_stencil_test,
104                              bool draw_rect_covers_full_surface) = 0;
105   virtual void ClearFramebuffer(DrawingFrame* frame,
106                                 bool has_external_stencil_test) = 0;
107   virtual void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) = 0;
108   virtual void BeginDrawingFrame(DrawingFrame* frame) = 0;
109   virtual void FinishDrawingFrame(DrawingFrame* frame) = 0;
110   virtual void FinishDrawingQuadList();
111   virtual bool FlippedFramebuffer() const = 0;
112   virtual void EnsureScissorTestEnabled() = 0;
113   virtual void EnsureScissorTestDisabled() = 0;
114   virtual void DiscardBackbuffer() {}
115   virtual void EnsureBackbuffer() {}
116
117   virtual void CopyCurrentRenderPassToBitmap(
118       DrawingFrame* frame,
119       scoped_ptr<CopyOutputRequest> request) = 0;
120
121   base::ScopedPtrHashMap<RenderPass::Id, ScopedResource> render_pass_textures_;
122   OutputSurface* output_surface_;
123   ResourceProvider* resource_provider_;
124   scoped_ptr<OverlayProcessor> overlay_processor_;
125
126   // For use in coordinate conversion, this stores the output rect, viewport
127   // rect (= unflipped version of glViewport rect), and the size of target
128   // framebuffer. During a draw, this stores the values for the current render
129   // pass; in between draws, they retain the values for the root render pass of
130   // the last draw.
131   gfx::Rect current_draw_rect_;
132   gfx::Rect current_viewport_rect_;
133   gfx::Size current_surface_size_;
134
135  private:
136   gfx::Vector2d enlarge_pass_texture_amount_;
137
138   NamespaceToken on_demand_task_namespace_;
139
140   DISALLOW_COPY_AND_ASSIGN(DirectRenderer);
141 };
142
143 }  // namespace cc
144
145 #endif  // CC_OUTPUT_DIRECT_RENDERER_H_