Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: cc/output/software_renderer.cc

Issue 22867046: Optimize alpha software PictureDrawQuads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DCHECK for xfermode Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "skia/ext/alpha_proxy_canvas.h"
22 #include "third_party/skia/include/core/SkBitmapDevice.h" 23 #include "third_party/skia/include/core/SkBitmapDevice.h"
23 #include "third_party/skia/include/core/SkCanvas.h" 24 #include "third_party/skia/include/core/SkCanvas.h"
24 #include "third_party/skia/include/core/SkColor.h" 25 #include "third_party/skia/include/core/SkColor.h"
25 #include "third_party/skia/include/core/SkMatrix.h" 26 #include "third_party/skia/include/core/SkMatrix.h"
26 #include "third_party/skia/include/core/SkShader.h" 27 #include "third_party/skia/include/core/SkShader.h"
27 #include "third_party/skia/include/effects/SkLayerRasterizer.h" 28 #include "third_party/skia/include/effects/SkLayerRasterizer.h"
28 #include "ui/gfx/rect_conversions.h" 29 #include "ui/gfx/rect_conversions.h"
29 #include "ui/gfx/skia_util.h" 30 #include "ui/gfx/skia_util.h"
30 #include "ui/gfx/transform.h" 31 #include "ui/gfx/transform.h"
31 32
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 SkPoint transformed_vertices[4]; 292 SkPoint transformed_vertices[4];
292 current_canvas_->getTotalMatrix().mapPoints(transformed_vertices, 293 current_canvas_->getTotalMatrix().mapPoints(transformed_vertices,
293 vertices, 294 vertices,
294 4); 295 4);
295 current_canvas_->resetMatrix(); 296 current_canvas_->resetMatrix();
296 297
297 current_paint_.setColor(quad->color); 298 current_paint_.setColor(quad->color);
298 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); 299 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color));
299 current_paint_.setStyle(SkPaint::kStroke_Style); 300 current_paint_.setStyle(SkPaint::kStroke_Style);
300 current_paint_.setStrokeWidth(quad->width); 301 current_paint_.setStrokeWidth(quad->width);
301 current_canvas_->drawPoints(SkCanvas::kPolygon_PointMode, 302 current_canvas_->drawPoints(
302 4, transformed_vertices, current_paint_); 303 SkCanvas::kPolygon_PointMode, 4, transformed_vertices, current_paint_);
303 } 304 }
304 305
305 void SoftwareRenderer::DrawPictureQuad(const DrawingFrame* frame, 306 void SoftwareRenderer::DrawPictureQuad(const DrawingFrame* frame,
306 const PictureDrawQuad* quad) { 307 const PictureDrawQuad* quad) {
307 SkMatrix content_matrix; 308 SkMatrix content_matrix;
308 content_matrix.setRectToRect( 309 content_matrix.setRectToRect(
309 gfx::RectFToSkRect(quad->tex_coord_rect), 310 gfx::RectFToSkRect(quad->tex_coord_rect),
310 gfx::RectFToSkRect(QuadVertexRect()), 311 gfx::RectFToSkRect(QuadVertexRect()),
311 SkMatrix::kFill_ScaleToFit); 312 SkMatrix::kFill_ScaleToFit);
312 current_canvas_->concat(content_matrix); 313 current_canvas_->concat(content_matrix);
313 314
314 if (quad->ShouldDrawWithBlending()) { 315 TRACE_EVENT0("cc", "SoftwareRenderer::DrawPictureQuad");
315 TRACE_EVENT0("cc", "SoftwareRenderer::DrawPictureQuad with blending"); 316 skia::AlphaProxyCanvas proxy_canvas(current_canvas_, quad->opacity(), false);
316 SkBitmap temp_bitmap; 317 quad->picture_pile->RasterDirect(
317 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 318 &proxy_canvas, quad->content_rect, quad->contents_scale, NULL);
318 quad->texture_size.width(),
319 quad->texture_size.height());
320 temp_bitmap.allocPixels();
321 SkBitmapDevice temp_device(temp_bitmap);
322 SkCanvas temp_canvas(&temp_device);
323
324 quad->picture_pile->RasterToBitmap(
325 &temp_canvas, quad->content_rect, quad->contents_scale, NULL);
326
327 current_paint_.setFilterBitmap(true);
328 current_canvas_->drawBitmap(temp_bitmap, 0, 0, &current_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 } 319 }
336 320
337 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame, 321 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame,
338 const SolidColorDrawQuad* quad) { 322 const SolidColorDrawQuad* quad) {
339 current_paint_.setColor(quad->color); 323 current_paint_.setColor(quad->color);
340 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); 324 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color));
341 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), 325 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()),
342 current_paint_); 326 current_paint_);
343 } 327 }
344 328
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 EnsureBackbuffer(); 521 EnsureBackbuffer();
538 else 522 else
539 DiscardBackbuffer(); 523 DiscardBackbuffer();
540 } 524 }
541 525
542 void SoftwareRenderer::SetDiscardBackBufferWhenNotVisible(bool discard) { 526 void SoftwareRenderer::SetDiscardBackBufferWhenNotVisible(bool discard) {
543 // The software renderer always discards the backbuffer when not visible. 527 // The software renderer always discards the backbuffer when not visible.
544 } 528 }
545 529
546 } // namespace cc 530 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698