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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
10 #include "cc/output/compositor_frame_ack.h" | 10 #include "cc/output/compositor_frame_ack.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "third_party/skia/include/core/SkShader.h" | 24 #include "third_party/skia/include/core/SkShader.h" |
25 #include "third_party/skia/include/effects/SkLayerRasterizer.h" | 25 #include "third_party/skia/include/effects/SkLayerRasterizer.h" |
26 #include "ui/gfx/rect_conversions.h" | 26 #include "ui/gfx/rect_conversions.h" |
27 #include "ui/gfx/skia_util.h" | 27 #include "ui/gfx/skia_util.h" |
28 #include "ui/gfx/transform.h" | 28 #include "ui/gfx/transform.h" |
29 | 29 |
30 namespace cc { | 30 namespace cc { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 void ToSkMatrix(SkMatrix* flattened, const gfx::Transform& m) { | |
35 // Convert from 4x4 to 3x3 by dropping the third row and column. | |
36 flattened->set(0, SkDoubleToScalar(m.matrix().getDouble(0, 0))); | |
37 flattened->set(1, SkDoubleToScalar(m.matrix().getDouble(0, 1))); | |
38 flattened->set(2, SkDoubleToScalar(m.matrix().getDouble(0, 3))); | |
39 flattened->set(3, SkDoubleToScalar(m.matrix().getDouble(1, 0))); | |
40 flattened->set(4, SkDoubleToScalar(m.matrix().getDouble(1, 1))); | |
41 flattened->set(5, SkDoubleToScalar(m.matrix().getDouble(1, 3))); | |
42 flattened->set(6, SkDoubleToScalar(m.matrix().getDouble(3, 0))); | |
43 flattened->set(7, SkDoubleToScalar(m.matrix().getDouble(3, 1))); | |
44 flattened->set(8, SkDoubleToScalar(m.matrix().getDouble(3, 3))); | |
45 } | |
46 | |
47 bool IsScaleAndTranslate(const SkMatrix& matrix) { | 34 bool IsScaleAndTranslate(const SkMatrix& matrix) { |
48 return SkScalarNearlyZero(matrix[SkMatrix::kMSkewX]) && | 35 return SkScalarNearlyZero(matrix[SkMatrix::kMSkewX]) && |
49 SkScalarNearlyZero(matrix[SkMatrix::kMSkewY]) && | 36 SkScalarNearlyZero(matrix[SkMatrix::kMSkewY]) && |
50 SkScalarNearlyZero(matrix[SkMatrix::kMPersp0]) && | 37 SkScalarNearlyZero(matrix[SkMatrix::kMPersp0]) && |
51 SkScalarNearlyZero(matrix[SkMatrix::kMPersp1]) && | 38 SkScalarNearlyZero(matrix[SkMatrix::kMPersp1]) && |
52 SkScalarNearlyZero(matrix[SkMatrix::kMPersp2] - 1.0f); | 39 SkScalarNearlyZero(matrix[SkMatrix::kMPersp2] - 1.0f); |
53 } | 40 } |
54 | 41 |
55 } // anonymous namespace | 42 } // anonymous namespace |
56 | 43 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 208 } |
222 | 209 |
223 void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { | 210 void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) { |
224 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad"); | 211 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad"); |
225 gfx::Transform quad_rect_matrix; | 212 gfx::Transform quad_rect_matrix; |
226 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); | 213 QuadRectTransform(&quad_rect_matrix, quad->quadTransform(), quad->rect); |
227 gfx::Transform contents_device_transform = | 214 gfx::Transform contents_device_transform = |
228 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 215 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
229 contents_device_transform.FlattenTo2d(); | 216 contents_device_transform.FlattenTo2d(); |
230 SkMatrix sk_device_matrix; | 217 SkMatrix sk_device_matrix; |
231 ToSkMatrix(&sk_device_matrix, contents_device_transform); | 218 gfx::TransformToFlattenedSkMatrix(contents_device_transform, |
| 219 &sk_device_matrix); |
232 current_canvas_->setMatrix(sk_device_matrix); | 220 current_canvas_->setMatrix(sk_device_matrix); |
233 | 221 |
234 current_paint_.reset(); | 222 current_paint_.reset(); |
235 if (!IsScaleAndTranslate(sk_device_matrix)) { | 223 if (!IsScaleAndTranslate(sk_device_matrix)) { |
236 current_paint_.setAntiAlias(true); | 224 current_paint_.setAntiAlias(true); |
237 current_paint_.setFilterBitmap(true); | 225 current_paint_.setFilterBitmap(true); |
238 } | 226 } |
239 | 227 |
240 if (quad->ShouldDrawWithBlending()) { | 228 if (quad->ShouldDrawWithBlending()) { |
241 current_paint_.setAlpha(quad->opacity() * 255); | 229 current_paint_.setAlpha(quad->opacity() * 255); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 if (quad->ShouldDrawWithBlending()) { | 290 if (quad->ShouldDrawWithBlending()) { |
303 TRACE_EVENT0("cc", "SoftwareRenderer::DrawPictureQuad with blending"); | 291 TRACE_EVENT0("cc", "SoftwareRenderer::DrawPictureQuad with blending"); |
304 SkBitmap temp_bitmap; | 292 SkBitmap temp_bitmap; |
305 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 293 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
306 quad->texture_size.width(), | 294 quad->texture_size.width(), |
307 quad->texture_size.height()); | 295 quad->texture_size.height()); |
308 temp_bitmap.allocPixels(); | 296 temp_bitmap.allocPixels(); |
309 SkDevice temp_device(temp_bitmap); | 297 SkDevice temp_device(temp_bitmap); |
310 SkCanvas temp_canvas(&temp_device); | 298 SkCanvas temp_canvas(&temp_device); |
311 | 299 |
312 quad->picture_pile->Raster( | 300 quad->picture_pile->RasterToBitmap( |
313 &temp_canvas, quad->content_rect, quad->contents_scale, NULL); | 301 &temp_canvas, quad->content_rect, quad->contents_scale, NULL); |
314 | 302 |
315 current_paint_.setFilterBitmap(true); | 303 current_paint_.setFilterBitmap(true); |
316 current_canvas_->drawBitmap(temp_bitmap, 0, 0, ¤t_paint_); | 304 current_canvas_->drawBitmap(temp_bitmap, 0, 0, ¤t_paint_); |
317 } else { | 305 } else { |
318 TRACE_EVENT0("cc", | 306 TRACE_EVENT0("cc", |
319 "SoftwareRenderer::DrawPictureQuad direct from PicturePile"); | 307 "SoftwareRenderer::DrawPictureQuad direct from PicturePile"); |
320 quad->picture_pile->Raster( | 308 quad->picture_pile->RasterDirect( |
321 current_canvas_, quad->content_rect, quad->contents_scale, NULL); | 309 current_canvas_, quad->content_rect, quad->contents_scale, NULL); |
322 } | 310 } |
323 } | 311 } |
324 | 312 |
325 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame, | 313 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame, |
326 const SolidColorDrawQuad* quad) { | 314 const SolidColorDrawQuad* quad) { |
327 current_paint_.setColor(quad->color); | 315 current_paint_.setColor(quad->color); |
328 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); | 316 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); |
329 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), | 317 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), |
330 current_paint_); | 318 current_paint_); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 4 * rect.width()); | 456 4 * rect.width()); |
469 } | 457 } |
470 | 458 |
471 void SoftwareRenderer::SetVisible(bool visible) { | 459 void SoftwareRenderer::SetVisible(bool visible) { |
472 if (visible_ == visible) | 460 if (visible_ == visible) |
473 return; | 461 return; |
474 visible_ = visible; | 462 visible_ = visible; |
475 } | 463 } |
476 | 464 |
477 } // namespace cc | 465 } // namespace cc |
OLD | NEW |