| 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/trace_event/trace_event.h" | 7 #include "base/trace_event/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/render_surface_filters.h" | 14 #include "cc/output/render_surface_filters.h" |
| 15 #include "cc/output/software_output_device.h" | 15 #include "cc/output/software_output_device.h" |
| 16 #include "cc/quads/checkerboard_draw_quad.h" | 16 #include "cc/quads/checkerboard_draw_quad.h" |
| 17 #include "cc/quads/debug_border_draw_quad.h" | 17 #include "cc/quads/debug_border_draw_quad.h" |
| 18 #include "cc/quads/picture_draw_quad.h" | |
| 19 #include "cc/quads/render_pass_draw_quad.h" | 18 #include "cc/quads/render_pass_draw_quad.h" |
| 20 #include "cc/quads/solid_color_draw_quad.h" | 19 #include "cc/quads/solid_color_draw_quad.h" |
| 21 #include "cc/quads/texture_draw_quad.h" | 20 #include "cc/quads/texture_draw_quad.h" |
| 22 #include "cc/quads/tile_draw_quad.h" | 21 #include "cc/quads/tile_draw_quad.h" |
| 23 #include "skia/ext/opacity_draw_filter.h" | 22 #include "skia/ext/opacity_draw_filter.h" |
| 24 #include "third_party/skia/include/core/SkCanvas.h" | 23 #include "third_party/skia/include/core/SkCanvas.h" |
| 25 #include "third_party/skia/include/core/SkColor.h" | 24 #include "third_party/skia/include/core/SkColor.h" |
| 26 #include "third_party/skia/include/core/SkImageFilter.h" | 25 #include "third_party/skia/include/core/SkImageFilter.h" |
| 27 #include "third_party/skia/include/core/SkMatrix.h" | 26 #include "third_party/skia/include/core/SkMatrix.h" |
| 28 #include "third_party/skia/include/core/SkPoint.h" | 27 #include "third_party/skia/include/core/SkPoint.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // TODO(enne) For now since checkerboards shouldn't be part of a 3D | 309 // TODO(enne) For now since checkerboards shouldn't be part of a 3D |
| 311 // context, clipping regions aren't supported so we skip drawing them | 310 // context, clipping regions aren't supported so we skip drawing them |
| 312 // if this becomes the case. | 311 // if this becomes the case. |
| 313 if (!draw_region) { | 312 if (!draw_region) { |
| 314 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); | 313 DrawCheckerboardQuad(frame, CheckerboardDrawQuad::MaterialCast(quad)); |
| 315 } | 314 } |
| 316 break; | 315 break; |
| 317 case DrawQuad::DEBUG_BORDER: | 316 case DrawQuad::DEBUG_BORDER: |
| 318 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); | 317 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); |
| 319 break; | 318 break; |
| 320 case DrawQuad::PICTURE_CONTENT: | |
| 321 DrawPictureQuad(frame, PictureDrawQuad::MaterialCast(quad)); | |
| 322 break; | |
| 323 case DrawQuad::RENDER_PASS: | 319 case DrawQuad::RENDER_PASS: |
| 324 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); | 320 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad)); |
| 325 break; | 321 break; |
| 326 case DrawQuad::SOLID_COLOR: | 322 case DrawQuad::SOLID_COLOR: |
| 327 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); | 323 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad)); |
| 328 break; | 324 break; |
| 329 case DrawQuad::TEXTURE_CONTENT: | 325 case DrawQuad::TEXTURE_CONTENT: |
| 330 DrawTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); | 326 DrawTextureQuad(frame, TextureDrawQuad::MaterialCast(quad)); |
| 331 break; | 327 break; |
| 332 case DrawQuad::TILED_CONTENT: | 328 case DrawQuad::TILED_CONTENT: |
| 333 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); | 329 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad)); |
| 334 break; | 330 break; |
| 335 case DrawQuad::SURFACE_CONTENT: | 331 case DrawQuad::SURFACE_CONTENT: |
| 336 // Surface content should be fully resolved to other quad types before | 332 // Surface content should be fully resolved to other quad types before |
| 337 // reaching a direct renderer. | 333 // reaching a direct renderer. |
| 338 NOTREACHED(); | 334 NOTREACHED(); |
| 339 break; | 335 break; |
| 340 case DrawQuad::INVALID: | 336 case DrawQuad::INVALID: |
| 341 case DrawQuad::IO_SURFACE_CONTENT: | 337 case DrawQuad::IO_SURFACE_CONTENT: |
| 342 case DrawQuad::YUV_VIDEO_CONTENT: | 338 case DrawQuad::YUV_VIDEO_CONTENT: |
| 343 case DrawQuad::STREAM_VIDEO_CONTENT: | 339 case DrawQuad::STREAM_VIDEO_CONTENT: |
| 340 case DrawQuad::UNUSED_SPACE_FOR_PICTURE_CONTENT: |
| 344 DrawUnsupportedQuad(frame, quad); | 341 DrawUnsupportedQuad(frame, quad); |
| 345 NOTREACHED(); | 342 NOTREACHED(); |
| 346 break; | 343 break; |
| 347 } | 344 } |
| 348 | 345 |
| 349 current_canvas_->resetMatrix(); | 346 current_canvas_->resetMatrix(); |
| 350 if (draw_region) { | 347 if (draw_region) { |
| 351 current_canvas_->restore(); | 348 current_canvas_->restore(); |
| 352 } | 349 } |
| 353 } | 350 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 374 current_canvas_->resetMatrix(); | 371 current_canvas_->resetMatrix(); |
| 375 | 372 |
| 376 current_paint_.setColor(quad->color); | 373 current_paint_.setColor(quad->color); |
| 377 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); | 374 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); |
| 378 current_paint_.setStyle(SkPaint::kStroke_Style); | 375 current_paint_.setStyle(SkPaint::kStroke_Style); |
| 379 current_paint_.setStrokeWidth(quad->width); | 376 current_paint_.setStrokeWidth(quad->width); |
| 380 current_canvas_->drawPoints(SkCanvas::kPolygon_PointMode, | 377 current_canvas_->drawPoints(SkCanvas::kPolygon_PointMode, |
| 381 4, transformed_vertices, current_paint_); | 378 4, transformed_vertices, current_paint_); |
| 382 } | 379 } |
| 383 | 380 |
| 384 void SoftwareRenderer::DrawPictureQuad(const DrawingFrame* frame, | |
| 385 const PictureDrawQuad* quad) { | |
| 386 SkMatrix content_matrix; | |
| 387 content_matrix.setRectToRect( | |
| 388 gfx::RectFToSkRect(quad->tex_coord_rect), | |
| 389 gfx::RectFToSkRect(QuadVertexRect()), | |
| 390 SkMatrix::kFill_ScaleToFit); | |
| 391 current_canvas_->concat(content_matrix); | |
| 392 | |
| 393 // TODO(aelias): This isn't correct in all cases. We should detect these | |
| 394 // cases and fall back to a persistent bitmap backing | |
| 395 // (http://crbug.com/280374). | |
| 396 skia::RefPtr<SkDrawFilter> opacity_filter = | |
| 397 skia::AdoptRef(new skia::OpacityDrawFilter( | |
| 398 quad->opacity(), frame->disable_picture_quad_image_filtering || | |
| 399 quad->nearest_neighbor)); | |
| 400 DCHECK(!current_canvas_->getDrawFilter()); | |
| 401 current_canvas_->setDrawFilter(opacity_filter.get()); | |
| 402 | |
| 403 TRACE_EVENT0("cc", | |
| 404 "SoftwareRenderer::DrawPictureQuad"); | |
| 405 | |
| 406 quad->raster_source->PlaybackToSharedCanvas( | |
| 407 current_canvas_, quad->content_rect, quad->contents_scale); | |
| 408 | |
| 409 current_canvas_->setDrawFilter(NULL); | |
| 410 } | |
| 411 | |
| 412 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame, | 381 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame, |
| 413 const SolidColorDrawQuad* quad) { | 382 const SolidColorDrawQuad* quad) { |
| 414 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( | 383 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( |
| 415 QuadVertexRect(), quad->rect, quad->visible_rect); | 384 QuadVertexRect(), quad->rect, quad->visible_rect); |
| 416 current_paint_.setColor(quad->color); | 385 current_paint_.setColor(quad->color); |
| 417 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); | 386 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); |
| 418 current_canvas_->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect), | 387 current_canvas_->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect), |
| 419 current_paint_); | 388 current_paint_); |
| 420 } | 389 } |
| 421 | 390 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 } | 623 } |
| 655 | 624 |
| 656 void SoftwareRenderer::DidChangeVisibility() { | 625 void SoftwareRenderer::DidChangeVisibility() { |
| 657 if (visible()) | 626 if (visible()) |
| 658 EnsureBackbuffer(); | 627 EnsureBackbuffer(); |
| 659 else | 628 else |
| 660 DiscardBackbuffer(); | 629 DiscardBackbuffer(); |
| 661 } | 630 } |
| 662 | 631 |
| 663 } // namespace cc | 632 } // namespace cc |
| OLD | NEW |