| OLD | NEW |
| (Empty) |
| 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/scoped_ptr_deque.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 "ui/gfx/geometry/quad_f.h" | |
| 17 | |
| 18 namespace cc { | |
| 19 | |
| 20 class DrawPolygon; | |
| 21 class ResourceProvider; | |
| 22 | |
| 23 // This is the base class for code shared between the GL and software | |
| 24 // renderer implementations. "Direct" refers to the fact that it does not | |
| 25 // delegate rendering to another compositor. | |
| 26 class DirectRenderer : public Renderer { | |
| 27 public: | |
| 28 ~DirectRenderer() override; | |
| 29 | |
| 30 void DecideRenderPassAllocationsForFrame( | |
| 31 const RenderPassList& render_passes_in_draw_order) override; | |
| 32 bool HasAllocatedResourcesForTesting(RenderPassId id) const override; | |
| 33 void DrawFrame(RenderPassList* render_passes_in_draw_order, | |
| 34 float device_scale_factor, | |
| 35 const gfx::Rect& device_viewport_rect, | |
| 36 const gfx::Rect& device_clip_rect, | |
| 37 bool disable_picture_quad_image_filtering) override; | |
| 38 | |
| 39 struct DrawingFrame { | |
| 40 DrawingFrame(); | |
| 41 ~DrawingFrame(); | |
| 42 | |
| 43 const RenderPassList* render_passes_in_draw_order; | |
| 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 void DoDrawPolygon(const DrawPolygon& poly, | |
| 62 DrawingFrame* frame, | |
| 63 const gfx::Rect& render_pass_scissor, | |
| 64 bool use_render_pass_scissor); | |
| 65 | |
| 66 protected: | |
| 67 enum SurfaceInitializationMode { | |
| 68 SURFACE_INITIALIZATION_MODE_PRESERVE, | |
| 69 SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR, | |
| 70 SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR, | |
| 71 }; | |
| 72 | |
| 73 DirectRenderer(RendererClient* client, | |
| 74 const RendererSettings* settings, | |
| 75 OutputSurface* output_surface, | |
| 76 ResourceProvider* resource_provider); | |
| 77 | |
| 78 static gfx::RectF QuadVertexRect(); | |
| 79 static void QuadRectTransform(gfx::Transform* quad_rect_transform, | |
| 80 const gfx::Transform& quad_transform, | |
| 81 const gfx::RectF& quad_rect); | |
| 82 void InitializeViewport(DrawingFrame* frame, | |
| 83 const gfx::Rect& draw_rect, | |
| 84 const gfx::Rect& viewport_rect, | |
| 85 const gfx::Size& surface_size); | |
| 86 gfx::Rect MoveFromDrawToWindowSpace(const DrawingFrame* frame, | |
| 87 const gfx::Rect& draw_rect) const; | |
| 88 | |
| 89 bool NeedDeviceClip(const DrawingFrame* frame) const; | |
| 90 gfx::Rect DeviceClipRectInDrawSpace(const DrawingFrame* frame) const; | |
| 91 gfx::Rect DeviceViewportRectInDrawSpace(const DrawingFrame* frame) const; | |
| 92 gfx::Rect OutputSurfaceRectInDrawSpace(const DrawingFrame* frame) const; | |
| 93 static gfx::Rect ComputeScissorRectForRenderPass(const DrawingFrame* frame); | |
| 94 void SetScissorStateForQuad(const DrawingFrame* frame, | |
| 95 const DrawQuad& quad, | |
| 96 const gfx::Rect& render_pass_scissor, | |
| 97 bool use_render_pass_scissor); | |
| 98 bool ShouldSkipQuad(const DrawQuad& quad, | |
| 99 const gfx::Rect& render_pass_scissor); | |
| 100 void SetScissorTestRectInDrawSpace(const DrawingFrame* frame, | |
| 101 const gfx::Rect& draw_space_rect); | |
| 102 | |
| 103 static gfx::Size RenderPassTextureSize(const RenderPass* render_pass); | |
| 104 | |
| 105 void FlushPolygons(ScopedPtrDeque<DrawPolygon>* poly_list, | |
| 106 DrawingFrame* frame, | |
| 107 const gfx::Rect& render_pass_scissor, | |
| 108 bool use_render_pass_scissor); | |
| 109 void DrawRenderPass(DrawingFrame* frame, const RenderPass* render_pass); | |
| 110 bool UseRenderPass(DrawingFrame* frame, const RenderPass* render_pass); | |
| 111 | |
| 112 virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) = 0; | |
| 113 virtual bool BindFramebufferToTexture(DrawingFrame* frame, | |
| 114 const ScopedResource* resource, | |
| 115 const gfx::Rect& target_rect) = 0; | |
| 116 virtual void SetDrawViewport(const gfx::Rect& window_space_viewport) = 0; | |
| 117 virtual void SetScissorTestRect(const gfx::Rect& scissor_rect) = 0; | |
| 118 virtual void PrepareSurfaceForPass( | |
| 119 DrawingFrame* frame, | |
| 120 SurfaceInitializationMode initialization_mode, | |
| 121 const gfx::Rect& render_pass_scissor) = 0; | |
| 122 // clip_region is a (possibly null) pointer to a quad in the same | |
| 123 // space as the quad. When non-null only the area of the quad that overlaps | |
| 124 // with clip_region will be drawn. | |
| 125 virtual void DoDrawQuad(DrawingFrame* frame, | |
| 126 const DrawQuad* quad, | |
| 127 const gfx::QuadF* clip_region) = 0; | |
| 128 virtual void BeginDrawingFrame(DrawingFrame* frame) = 0; | |
| 129 virtual void FinishDrawingFrame(DrawingFrame* frame) = 0; | |
| 130 virtual void FinishDrawingQuadList(); | |
| 131 virtual bool FlippedFramebuffer(const DrawingFrame* frame) const = 0; | |
| 132 virtual void EnsureScissorTestEnabled() = 0; | |
| 133 virtual void EnsureScissorTestDisabled() = 0; | |
| 134 virtual void DiscardBackbuffer() {} | |
| 135 virtual void EnsureBackbuffer() {} | |
| 136 | |
| 137 virtual void CopyCurrentRenderPassToBitmap( | |
| 138 DrawingFrame* frame, | |
| 139 scoped_ptr<CopyOutputRequest> request) = 0; | |
| 140 | |
| 141 base::ScopedPtrHashMap<RenderPassId, scoped_ptr<ScopedResource>> render_pass_t
extures_; | |
| 142 OutputSurface* output_surface_; | |
| 143 ResourceProvider* resource_provider_; | |
| 144 scoped_ptr<OverlayProcessor> overlay_processor_; | |
| 145 | |
| 146 // For use in coordinate conversion, this stores the output rect, viewport | |
| 147 // rect (= unflipped version of glViewport rect), and the size of target | |
| 148 // framebuffer. During a draw, this stores the values for the current render | |
| 149 // pass; in between draws, they retain the values for the root render pass of | |
| 150 // the last draw. | |
| 151 gfx::Rect current_draw_rect_; | |
| 152 gfx::Rect current_viewport_rect_; | |
| 153 gfx::Size current_surface_size_; | |
| 154 | |
| 155 private: | |
| 156 gfx::Vector2d enlarge_pass_texture_amount_; | |
| 157 | |
| 158 DISALLOW_COPY_AND_ASSIGN(DirectRenderer); | |
| 159 }; | |
| 160 | |
| 161 } // namespace cc | |
| 162 | |
| 163 #endif // CC_OUTPUT_DIRECT_RENDERER_H_ | |
| OLD | NEW |