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" |
11 #include "cc/output/compositor_frame_metadata.h" | 11 #include "cc/output/compositor_frame_metadata.h" |
12 #include "cc/output/copy_output_request.h" | 12 #include "cc/output/copy_output_request.h" |
13 #include "cc/output/output_surface.h" | 13 #include "cc/output/output_surface.h" |
14 #include "cc/output/software_output_device.h" | 14 #include "cc/output/software_output_device.h" |
15 #include "cc/quads/checkerboard_draw_quad.h" | 15 #include "cc/quads/checkerboard_draw_quad.h" |
16 #include "cc/quads/debug_border_draw_quad.h" | 16 #include "cc/quads/debug_border_draw_quad.h" |
17 #include "cc/quads/picture_draw_quad.h" | 17 #include "cc/quads/picture_draw_quad.h" |
18 #include "cc/quads/render_pass_draw_quad.h" | 18 #include "cc/quads/render_pass_draw_quad.h" |
19 #include "cc/quads/solid_color_draw_quad.h" | 19 #include "cc/quads/solid_color_draw_quad.h" |
20 #include "cc/quads/texture_draw_quad.h" | 20 #include "cc/quads/texture_draw_quad.h" |
21 #include "cc/quads/tile_draw_quad.h" | 21 #include "cc/quads/tile_draw_quad.h" |
22 #include "third_party/skia/include/core/SkBitmapDevice.h" | 22 #include "skia/ext/opacity_draw_filter.h" |
23 #include "third_party/skia/include/core/SkCanvas.h" | 23 #include "third_party/skia/include/core/SkCanvas.h" |
24 #include "third_party/skia/include/core/SkColor.h" | 24 #include "third_party/skia/include/core/SkColor.h" |
25 #include "third_party/skia/include/core/SkMatrix.h" | 25 #include "third_party/skia/include/core/SkMatrix.h" |
26 #include "third_party/skia/include/core/SkShader.h" | 26 #include "third_party/skia/include/core/SkShader.h" |
27 #include "third_party/skia/include/effects/SkLayerRasterizer.h" | 27 #include "third_party/skia/include/effects/SkLayerRasterizer.h" |
28 #include "ui/gfx/rect_conversions.h" | 28 #include "ui/gfx/rect_conversions.h" |
29 #include "ui/gfx/skia_util.h" | 29 #include "ui/gfx/skia_util.h" |
30 #include "ui/gfx/transform.h" | 30 #include "ui/gfx/transform.h" |
31 | 31 |
32 namespace cc { | 32 namespace cc { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 void SoftwareRenderer::DrawPictureQuad(const DrawingFrame* frame, | 305 void SoftwareRenderer::DrawPictureQuad(const DrawingFrame* frame, |
306 const PictureDrawQuad* quad) { | 306 const PictureDrawQuad* quad) { |
307 SkMatrix content_matrix; | 307 SkMatrix content_matrix; |
308 content_matrix.setRectToRect( | 308 content_matrix.setRectToRect( |
309 gfx::RectFToSkRect(quad->tex_coord_rect), | 309 gfx::RectFToSkRect(quad->tex_coord_rect), |
310 gfx::RectFToSkRect(QuadVertexRect()), | 310 gfx::RectFToSkRect(QuadVertexRect()), |
311 SkMatrix::kFill_ScaleToFit); | 311 SkMatrix::kFill_ScaleToFit); |
312 current_canvas_->concat(content_matrix); | 312 current_canvas_->concat(content_matrix); |
313 | 313 |
314 if (quad->ShouldDrawWithBlending()) { | 314 // TODO(aelias): This isn't correct in all cases. We should detect these |
315 TRACE_EVENT0("cc", "SoftwareRenderer::DrawPictureQuad with blending"); | 315 // cases and fall back to a persistent bitmap backing |
316 SkBitmap temp_bitmap; | 316 // (http://crbug.com/280374). |
317 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 317 DCHECK(!current_canvas_->getDrawFilter()); |
318 quad->texture_size.width(), | 318 current_canvas_->setDrawFilter(new skia::OpacityDrawFilter(quad->opacity(), |
319 quad->texture_size.height()); | 319 true)); |
320 temp_bitmap.allocPixels(); | |
321 SkBitmapDevice temp_device(temp_bitmap); | |
322 SkCanvas temp_canvas(&temp_device); | |
323 | 320 |
324 quad->picture_pile->RasterToBitmap( | 321 TRACE_EVENT0("cc", |
325 &temp_canvas, quad->content_rect, quad->contents_scale, NULL); | 322 "SoftwareRenderer::DrawPictureQuad"); |
| 323 quad->picture_pile->RasterDirect( |
| 324 current_canvas_, quad->content_rect, quad->contents_scale, NULL); |
326 | 325 |
327 current_paint_.setFilterBitmap(true); | 326 current_canvas_->setDrawFilter(NULL); |
328 current_canvas_->drawBitmap(temp_bitmap, 0, 0, ¤t_paint_); | |
329 } else { | |
330 TRACE_EVENT0("cc", | |
331 "SoftwareRenderer::DrawPictureQuad direct from PicturePile"); | |
332 quad->picture_pile->RasterDirect( | |
333 current_canvas_, quad->content_rect, quad->contents_scale, NULL); | |
334 } | |
335 } | 327 } |
336 | 328 |
337 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame, | 329 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame, |
338 const SolidColorDrawQuad* quad) { | 330 const SolidColorDrawQuad* quad) { |
339 current_paint_.setColor(quad->color); | 331 current_paint_.setColor(quad->color); |
340 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); | 332 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); |
341 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), | 333 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), |
342 current_paint_); | 334 current_paint_); |
343 } | 335 } |
344 | 336 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 EnsureBackbuffer(); | 529 EnsureBackbuffer(); |
538 else | 530 else |
539 DiscardBackbuffer(); | 531 DiscardBackbuffer(); |
540 } | 532 } |
541 | 533 |
542 void SoftwareRenderer::SetDiscardBackBufferWhenNotVisible(bool discard) { | 534 void SoftwareRenderer::SetDiscardBackBufferWhenNotVisible(bool discard) { |
543 // The software renderer always discards the backbuffer when not visible. | 535 // The software renderer always discards the backbuffer when not visible. |
544 } | 536 } |
545 | 537 |
546 } // namespace cc | 538 } // namespace cc |
OLD | NEW |