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

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

Issue 14417014: cc: Add tile-free software compositing mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
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/output_surface.h" 12 #include "cc/output/output_surface.h"
13 #include "cc/output/software_output_device.h" 13 #include "cc/output/software_output_device.h"
14 #include "cc/quads/debug_border_draw_quad.h" 14 #include "cc/quads/debug_border_draw_quad.h"
15 #include "cc/quads/picture_draw_quad.h"
15 #include "cc/quads/render_pass_draw_quad.h" 16 #include "cc/quads/render_pass_draw_quad.h"
16 #include "cc/quads/solid_color_draw_quad.h" 17 #include "cc/quads/solid_color_draw_quad.h"
17 #include "cc/quads/texture_draw_quad.h" 18 #include "cc/quads/texture_draw_quad.h"
18 #include "cc/quads/tile_draw_quad.h" 19 #include "cc/quads/tile_draw_quad.h"
19 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkCanvas.h"
20 #include "third_party/skia/include/core/SkColor.h" 21 #include "third_party/skia/include/core/SkColor.h"
21 #include "third_party/skia/include/core/SkDevice.h" 22 #include "third_party/skia/include/core/SkDevice.h"
22 #include "third_party/skia/include/core/SkMatrix.h" 23 #include "third_party/skia/include/core/SkMatrix.h"
23 #include "third_party/skia/include/core/SkShader.h" 24 #include "third_party/skia/include/core/SkShader.h"
24 #include "third_party/skia/include/effects/SkLayerRasterizer.h" 25 #include "third_party/skia/include/effects/SkLayerRasterizer.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 SoftwareRenderer::SoftwareRenderer(RendererClient* client, 65 SoftwareRenderer::SoftwareRenderer(RendererClient* client,
65 OutputSurface* output_surface, 66 OutputSurface* output_surface,
66 ResourceProvider* resource_provider) 67 ResourceProvider* resource_provider)
67 : DirectRenderer(client, resource_provider), 68 : DirectRenderer(client, resource_provider),
68 visible_(true), 69 visible_(true),
69 is_scissor_enabled_(false), 70 is_scissor_enabled_(false),
70 is_viewport_changed_(true), 71 is_viewport_changed_(true),
71 output_surface_(output_surface), 72 output_surface_(output_surface),
72 output_device_(output_surface->software_device()), 73 output_device_(output_surface->software_device()),
73 current_canvas_(NULL) { 74 current_canvas_(NULL) {
74 capabilities_.max_texture_size = resource_provider_->max_texture_size(); 75 if (resource_provider_) {
75 capabilities_.best_texture_format = resource_provider_->best_texture_format(); 76 capabilities_.max_texture_size = resource_provider_->max_texture_size();
77 capabilities_.best_texture_format =
78 resource_provider_->best_texture_format();
79 }
76 capabilities_.using_set_visibility = true; 80 capabilities_.using_set_visibility = true;
77 // The updater can access bitmaps while the SoftwareRenderer is using them. 81 // The updater can access bitmaps while the SoftwareRenderer is using them.
78 capabilities_.allow_partial_texture_updates = true; 82 capabilities_.allow_partial_texture_updates = true;
79 capabilities_.using_partial_swap = true; 83 capabilities_.using_partial_swap = true;
80 if (Settings().compositor_frame_message && client_->HasImplThread()) 84 if (Settings().compositor_frame_message && client_->HasImplThread())
81 capabilities_.using_swap_complete_callback = true; 85 capabilities_.using_swap_complete_callback = true;
82 compositor_frame_.software_frame_data.reset(new SoftwareFrameData()); 86 compositor_frame_.software_frame_data.reset(new SoftwareFrameData());
83 } 87 }
84 88
85 SoftwareRenderer::~SoftwareRenderer() {} 89 SoftwareRenderer::~SoftwareRenderer() {}
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 current_paint_.setAlpha(quad->opacity() * 255); 241 current_paint_.setAlpha(quad->opacity() * 255);
238 current_paint_.setXfermodeMode(SkXfermode::kSrcOver_Mode); 242 current_paint_.setXfermodeMode(SkXfermode::kSrcOver_Mode);
239 } else { 243 } else {
240 current_paint_.setXfermodeMode(SkXfermode::kSrc_Mode); 244 current_paint_.setXfermodeMode(SkXfermode::kSrc_Mode);
241 } 245 }
242 246
243 switch (quad->material) { 247 switch (quad->material) {
244 case DrawQuad::DEBUG_BORDER: 248 case DrawQuad::DEBUG_BORDER:
245 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); 249 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad));
246 break; 250 break;
251 case DrawQuad::PICTURE_CONTENT:
252 DrawPictureQuad(frame, PictureDrawQuad::MaterialCast(quad));
253 break;
247 case DrawQuad::SOLID_COLOR: 254 case DrawQuad::SOLID_COLOR:
248 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); 255 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad));
249 break; 256 break;
250 case DrawQuad::TEXTURE_CONTENT: 257 case DrawQuad::TEXTURE_CONTENT:
251 DrawTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); 258 DrawTextureQuad(frame, TextureDrawQuad::MaterialCast(quad));
252 break; 259 break;
253 case DrawQuad::TILED_CONTENT: 260 case DrawQuad::TILED_CONTENT:
254 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); 261 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad));
255 break; 262 break;
256 case DrawQuad::RENDER_PASS: 263 case DrawQuad::RENDER_PASS:
257 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); 264 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad));
258 break; 265 break;
259 default: 266 default:
260 DrawUnsupportedQuad(frame, quad); 267 DrawUnsupportedQuad(frame, quad);
261 break; 268 break;
262 } 269 }
263 270
264 current_canvas_->resetMatrix(); 271 current_canvas_->resetMatrix();
265 } 272 }
266 273
274 // static
275 SkMatrix SoftwareRenderer::ContentDrawQuadMatrix(
276 const ContentDrawQuadBase* quad) {
277 SkMatrix content_draw_quad_matrix;
278 content_draw_quad_matrix.setRectToRect(
279 gfx::RectFToSkRect(quad->tex_coord_rect),
enne (OOO) 2013/04/28 22:42:27 I would actually like to get rid of this tex coord
280 gfx::RectFToSkRect(QuadVertexRect()),
281 SkMatrix::kFill_ScaleToFit);
282 return content_draw_quad_matrix;
283 }
284
267 void SoftwareRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, 285 void SoftwareRenderer::DrawDebugBorderQuad(const DrawingFrame* frame,
268 const DebugBorderDrawQuad* quad) { 286 const DebugBorderDrawQuad* quad) {
269 // We need to apply the matrix manually to have pixel-sized stroke width. 287 // We need to apply the matrix manually to have pixel-sized stroke width.
270 SkPoint vertices[4]; 288 SkPoint vertices[4];
271 gfx::RectFToSkRect(QuadVertexRect()).toQuad(vertices); 289 gfx::RectFToSkRect(QuadVertexRect()).toQuad(vertices);
272 SkPoint transformed_vertices[4]; 290 SkPoint transformed_vertices[4];
273 current_canvas_->getTotalMatrix().mapPoints(transformed_vertices, 291 current_canvas_->getTotalMatrix().mapPoints(transformed_vertices,
274 vertices, 292 vertices,
275 4); 293 4);
276 current_canvas_->resetMatrix(); 294 current_canvas_->resetMatrix();
277 295
278 current_paint_.setColor(quad->color); 296 current_paint_.setColor(quad->color);
279 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); 297 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color));
280 current_paint_.setStyle(SkPaint::kStroke_Style); 298 current_paint_.setStyle(SkPaint::kStroke_Style);
281 current_paint_.setStrokeWidth(quad->width); 299 current_paint_.setStrokeWidth(quad->width);
282 current_canvas_->drawPoints(SkCanvas::kPolygon_PointMode, 300 current_canvas_->drawPoints(SkCanvas::kPolygon_PointMode,
283 4, transformed_vertices, current_paint_); 301 4, transformed_vertices, current_paint_);
284 } 302 }
285 303
304 void SoftwareRenderer::DrawPictureQuad(const DrawingFrame* frame,
305 const PictureDrawQuad* quad) {
306 current_canvas_->concat(ContentDrawQuadMatrix(quad));
307
308 if (quad->ShouldDrawWithBlending()) {
309 TRACE_EVENT0("cc", "SoftwareRenderer::DrawPictureQuad with blending");
310 SkBitmap temp_bitmap;
311 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
312 quad->texture_size.width(),
313 quad->texture_size.height());
314 temp_bitmap.allocPixels();
315 SkDevice temp_device(temp_bitmap);
316 SkCanvas temp_canvas(&temp_device);
317
318 quad->picture_pile->Raster(
319 &temp_canvas, quad->content_rect, quad->contents_scale, NULL);
320
321 current_paint_.setFilterBitmap(true);
322 current_canvas_->drawBitmap(temp_bitmap, 0, 0, &current_paint_);
323 } else {
324 TRACE_EVENT0("cc",
325 "SoftwareRenderer::DrawPictureQuad direct from PicturePile");
326 quad->picture_pile->Raster(
327 current_canvas_, quad->content_rect, quad->contents_scale, NULL);
328 }
329 }
330
286 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame, 331 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame,
287 const SolidColorDrawQuad* quad) { 332 const SolidColorDrawQuad* quad) {
288 current_paint_.setColor(quad->color); 333 current_paint_.setColor(quad->color);
289 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); 334 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color));
290 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), 335 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()),
291 current_paint_); 336 current_paint_);
292 } 337 }
293 338
294 void SoftwareRenderer::DrawTextureQuad(const DrawingFrame* frame, 339 void SoftwareRenderer::DrawTextureQuad(const DrawingFrame* frame,
295 const TextureDrawQuad* quad) { 340 const TextureDrawQuad* quad) {
(...skipping 17 matching lines...) Expand all
313 gfx::RectFToSkRect(QuadVertexRect()), 358 gfx::RectFToSkRect(QuadVertexRect()),
314 &current_paint_); 359 &current_paint_);
315 } 360 }
316 361
317 void SoftwareRenderer::DrawTileQuad(const DrawingFrame* frame, 362 void SoftwareRenderer::DrawTileQuad(const DrawingFrame* frame,
318 const TileDrawQuad* quad) { 363 const TileDrawQuad* quad) {
319 DCHECK(IsSoftwareResource(quad->resource_id)); 364 DCHECK(IsSoftwareResource(quad->resource_id));
320 ResourceProvider::ScopedReadLockSoftware lock(resource_provider_, 365 ResourceProvider::ScopedReadLockSoftware lock(resource_provider_,
321 quad->resource_id); 366 quad->resource_id);
322 367
323 SkRect uv_rect = gfx::RectFToSkRect(quad->tex_coord_rect);
324 current_paint_.setFilterBitmap(true); 368 current_paint_.setFilterBitmap(true);
325 current_canvas_->drawBitmapRectToRect(*lock.sk_bitmap(), &uv_rect, 369 current_canvas_->drawBitmapMatrix(
326 gfx::RectFToSkRect(QuadVertexRect()), 370 *lock.sk_bitmap(), ContentDrawQuadMatrix(quad), &current_paint_);
327 &current_paint_);
328 } 371 }
329 372
330 void SoftwareRenderer::DrawRenderPassQuad(const DrawingFrame* frame, 373 void SoftwareRenderer::DrawRenderPassQuad(const DrawingFrame* frame,
331 const RenderPassDrawQuad* quad) { 374 const RenderPassDrawQuad* quad) {
332 CachedResource* content_texture = 375 CachedResource* content_texture =
333 render_pass_textures_.get(quad->render_pass_id); 376 render_pass_textures_.get(quad->render_pass_id);
334 if (!content_texture || !content_texture->id()) 377 if (!content_texture || !content_texture->id())
335 return; 378 return;
336 379
337 DCHECK(IsSoftwareResource(content_texture->id())); 380 DCHECK(IsSoftwareResource(content_texture->id()));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 4 * rect.width()); 466 4 * rect.width());
424 } 467 }
425 468
426 void SoftwareRenderer::SetVisible(bool visible) { 469 void SoftwareRenderer::SetVisible(bool visible) {
427 if (visible_ == visible) 470 if (visible_ == visible)
428 return; 471 return;
429 visible_ = visible; 472 visible_ = visible;
430 } 473 }
431 474
432 } // namespace cc 475 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698