OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/software_renderer.h" | 5 #include "cc/output/software_renderer.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
10 #include "cc/base/render_surface_filters.h" | 10 #include "cc/base/render_surface_filters.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 output_frame.latency_info = std::move(latency_info); | 92 output_frame.latency_info = std::move(latency_info); |
93 output_surface_->SwapBuffers(std::move(output_frame)); | 93 output_surface_->SwapBuffers(std::move(output_frame)); |
94 } | 94 } |
95 | 95 |
96 bool SoftwareRenderer::FlippedFramebuffer() const { | 96 bool SoftwareRenderer::FlippedFramebuffer() const { |
97 return false; | 97 return false; |
98 } | 98 } |
99 | 99 |
100 void SoftwareRenderer::EnsureScissorTestEnabled() { | 100 void SoftwareRenderer::EnsureScissorTestEnabled() { |
101 is_scissor_enabled_ = true; | 101 is_scissor_enabled_ = true; |
102 SetClipRect(scissor_rect_); | |
103 } | 102 } |
104 | 103 |
105 void SoftwareRenderer::EnsureScissorTestDisabled() { | 104 void SoftwareRenderer::EnsureScissorTestDisabled() { |
106 // There is no explicit notion of enabling/disabling scissoring in software | |
107 // rendering, but the underlying effect we want is to clear any existing | |
108 // clipRect on the current SkCanvas. This is done by setting clipRect to | |
109 // the viewport's dimensions. | |
110 if (!current_canvas_) | |
111 return; | |
112 is_scissor_enabled_ = false; | 105 is_scissor_enabled_ = false; |
113 SkISize size = current_canvas_->getBaseLayerSize(); | |
114 SetClipRect(gfx::Rect(size.width(), size.height())); | |
115 } | 106 } |
116 | 107 |
117 void SoftwareRenderer::BindFramebufferToOutputSurface() { | 108 void SoftwareRenderer::BindFramebufferToOutputSurface() { |
118 DCHECK(!output_surface_->HasExternalStencilTest()); | 109 DCHECK(!output_surface_->HasExternalStencilTest()); |
119 current_framebuffer_lock_ = nullptr; | 110 current_framebuffer_lock_ = nullptr; |
120 current_framebuffer_canvas_.reset(); | 111 current_framebuffer_canvas_.reset(); |
121 current_canvas_ = root_canvas_; | 112 current_canvas_ = root_canvas_; |
122 } | 113 } |
123 | 114 |
124 bool SoftwareRenderer::BindFramebufferToTexture( | 115 bool SoftwareRenderer::BindFramebufferToTexture( |
125 const ScopedResource* texture) { | 116 const ScopedResource* texture) { |
126 DCHECK(texture->id()); | 117 DCHECK(texture->id()); |
127 | 118 |
128 // Explicitly release lock, otherwise we can crash when try to lock | 119 // Explicitly release lock, otherwise we can crash when try to lock |
129 // same texture again. | 120 // same texture again. |
130 current_framebuffer_lock_ = nullptr; | 121 current_framebuffer_lock_ = nullptr; |
131 current_framebuffer_lock_ = | 122 current_framebuffer_lock_ = |
132 base::MakeUnique<ResourceProvider::ScopedWriteLockSoftware>( | 123 base::MakeUnique<ResourceProvider::ScopedWriteLockSoftware>( |
133 resource_provider_, texture->id()); | 124 resource_provider_, texture->id()); |
134 current_framebuffer_canvas_ = | 125 current_framebuffer_canvas_ = |
135 base::MakeUnique<SkCanvas>(current_framebuffer_lock_->sk_bitmap()); | 126 base::MakeUnique<SkCanvas>(current_framebuffer_lock_->sk_bitmap()); |
136 current_canvas_ = current_framebuffer_canvas_.get(); | 127 current_canvas_ = current_framebuffer_canvas_.get(); |
137 return true; | 128 return true; |
138 } | 129 } |
139 | 130 |
140 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { | 131 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { |
141 is_scissor_enabled_ = true; | 132 is_scissor_enabled_ = true; |
142 scissor_rect_ = scissor_rect; | 133 scissor_rect_ = scissor_rect; |
143 SetClipRect(scissor_rect); | |
144 } | 134 } |
145 | 135 |
146 void SoftwareRenderer::SetClipRect(const gfx::Rect& rect) { | 136 void SoftwareRenderer::SetClipRect(const gfx::Rect& rect) { |
147 if (!current_canvas_) | 137 if (!current_canvas_) |
148 return; | 138 return; |
149 // Skia applies the current matrix to clip rects so we reset it temporary. | 139 // Skia applies the current matrix to clip rects so we reset it temporary. |
150 SkMatrix current_matrix = current_canvas_->getTotalMatrix(); | 140 SkMatrix current_matrix = current_canvas_->getTotalMatrix(); |
151 current_canvas_->resetMatrix(); | 141 current_canvas_->resetMatrix(); |
152 // TODO(fmalita) stop using kReplace (see crbug.com/673851) | 142 // SetClipRect is assumed to be applied temporarily, on an |
153 current_canvas_->clipRect(gfx::RectToSkRect(rect), | 143 // otherwise-unclipped canvas. |
154 SkClipOp::kReplace_deprecated); | 144 DCHECK_EQ(current_canvas_->getDeviceClipBounds().width(), |
| 145 current_canvas_->imageInfo().width()); |
| 146 DCHECK_EQ(current_canvas_->getDeviceClipBounds().height(), |
| 147 current_canvas_->imageInfo().height()); |
| 148 current_canvas_->clipRect(gfx::RectToSkRect(rect)); |
155 current_canvas_->setMatrix(current_matrix); | 149 current_canvas_->setMatrix(current_matrix); |
156 } | 150 } |
157 | 151 |
158 void SoftwareRenderer::ClearCanvas(SkColor color) { | 152 void SoftwareRenderer::ClearCanvas(SkColor color) { |
159 if (!current_canvas_) | 153 if (!current_canvas_) |
160 return; | 154 return; |
161 current_canvas_->clear(color); | 155 current_canvas_->clear(color); |
162 } | 156 } |
163 | 157 |
164 void SoftwareRenderer::ClearFramebuffer() { | 158 void SoftwareRenderer::ClearFramebuffer() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 195 } |
202 | 196 |
203 LOG(FATAL) << "Invalid resource type."; | 197 LOG(FATAL) << "Invalid resource type."; |
204 return false; | 198 return false; |
205 } | 199 } |
206 | 200 |
207 void SoftwareRenderer::DoDrawQuad(const DrawQuad* quad, | 201 void SoftwareRenderer::DoDrawQuad(const DrawQuad* quad, |
208 const gfx::QuadF* draw_region) { | 202 const gfx::QuadF* draw_region) { |
209 if (!current_canvas_) | 203 if (!current_canvas_) |
210 return; | 204 return; |
211 if (draw_region) { | 205 |
212 current_canvas_->save(); | 206 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad"); |
| 207 bool do_save = draw_region || is_scissor_enabled_; |
| 208 SkAutoCanvasRestore canvas_restore(current_canvas_, do_save); |
| 209 if (is_scissor_enabled_) { |
| 210 SetClipRect(scissor_rect_); |
213 } | 211 } |
214 | 212 |
215 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad"); | |
216 gfx::Transform quad_rect_matrix; | 213 gfx::Transform quad_rect_matrix; |
217 QuadRectTransform(&quad_rect_matrix, | 214 QuadRectTransform(&quad_rect_matrix, |
218 quad->shared_quad_state->quad_to_target_transform, | 215 quad->shared_quad_state->quad_to_target_transform, |
219 gfx::RectF(quad->rect)); | 216 gfx::RectF(quad->rect)); |
220 gfx::Transform contents_device_transform = | 217 gfx::Transform contents_device_transform = |
221 current_frame()->window_matrix * current_frame()->projection_matrix * | 218 current_frame()->window_matrix * current_frame()->projection_matrix * |
222 quad_rect_matrix; | 219 quad_rect_matrix; |
223 contents_device_transform.FlattenTo2d(); | 220 contents_device_transform.FlattenTo2d(); |
224 SkMatrix sk_device_matrix; | 221 SkMatrix sk_device_matrix; |
225 gfx::TransformToFlattenedSkMatrix(contents_device_transform, | 222 gfx::TransformToFlattenedSkMatrix(contents_device_transform, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 break; | 288 break; |
292 case DrawQuad::INVALID: | 289 case DrawQuad::INVALID: |
293 case DrawQuad::YUV_VIDEO_CONTENT: | 290 case DrawQuad::YUV_VIDEO_CONTENT: |
294 case DrawQuad::STREAM_VIDEO_CONTENT: | 291 case DrawQuad::STREAM_VIDEO_CONTENT: |
295 DrawUnsupportedQuad(quad); | 292 DrawUnsupportedQuad(quad); |
296 NOTREACHED(); | 293 NOTREACHED(); |
297 break; | 294 break; |
298 } | 295 } |
299 | 296 |
300 current_canvas_->resetMatrix(); | 297 current_canvas_->resetMatrix(); |
301 if (draw_region) { | |
302 current_canvas_->restore(); | |
303 } | |
304 } | 298 } |
305 | 299 |
306 void SoftwareRenderer::DrawDebugBorderQuad(const DebugBorderDrawQuad* quad) { | 300 void SoftwareRenderer::DrawDebugBorderQuad(const DebugBorderDrawQuad* quad) { |
307 // We need to apply the matrix manually to have pixel-sized stroke width. | 301 // We need to apply the matrix manually to have pixel-sized stroke width. |
308 SkPoint vertices[4]; | 302 SkPoint vertices[4]; |
309 gfx::RectFToSkRect(QuadVertexRect()).toQuad(vertices); | 303 gfx::RectFToSkRect(QuadVertexRect()).toQuad(vertices); |
310 SkPoint transformed_vertices[4]; | 304 SkPoint transformed_vertices[4]; |
311 current_canvas_->getTotalMatrix().mapPoints(transformed_vertices, | 305 current_canvas_->getTotalMatrix().mapPoints(transformed_vertices, |
312 vertices, | 306 vertices, |
313 4); | 307 4); |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 ApplyImageFilter(filter.get(), quad, backdrop_bitmap, nullptr); | 721 ApplyImageFilter(filter.get(), quad, backdrop_bitmap, nullptr); |
728 | 722 |
729 if (!filter_backdrop_image) | 723 if (!filter_backdrop_image) |
730 return nullptr; | 724 return nullptr; |
731 | 725 |
732 return filter_backdrop_image->makeShader(content_tile_mode, content_tile_mode, | 726 return filter_backdrop_image->makeShader(content_tile_mode, content_tile_mode, |
733 &filter_backdrop_transform); | 727 &filter_backdrop_transform); |
734 } | 728 } |
735 | 729 |
736 } // namespace cc | 730 } // namespace cc |
OLD | NEW |