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" |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( | 408 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( |
409 QuadVertexRect(), quad->rect, quad->visible_rect); | 409 QuadVertexRect(), quad->rect, quad->visible_rect); |
410 current_paint_.setColor(quad->color); | 410 current_paint_.setColor(quad->color); |
411 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); | 411 current_paint_.setAlpha(quad->opacity() * SkColorGetA(quad->color)); |
412 current_canvas_->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect), | 412 current_canvas_->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect), |
413 current_paint_); | 413 current_paint_); |
414 } | 414 } |
415 | 415 |
416 void SoftwareRenderer::DrawTextureQuad(const DrawingFrame* frame, | 416 void SoftwareRenderer::DrawTextureQuad(const DrawingFrame* frame, |
417 const TextureDrawQuad* quad) { | 417 const TextureDrawQuad* quad) { |
418 if (!IsSoftwareResource(quad->resource_id)) { | 418 if (!IsSoftwareResource(quad->resource_id())) { |
419 DrawUnsupportedQuad(frame, quad); | 419 DrawUnsupportedQuad(frame, quad); |
420 return; | 420 return; |
421 } | 421 } |
422 | 422 |
423 // TODO(skaslev): Add support for non-premultiplied alpha. | 423 // TODO(skaslev): Add support for non-premultiplied alpha. |
424 ResourceProvider::ScopedReadLockSoftware lock(resource_provider_, | 424 ResourceProvider::ScopedReadLockSoftware lock(resource_provider_, |
425 quad->resource_id); | 425 quad->resource_id()); |
426 if (!lock.valid()) | 426 if (!lock.valid()) |
427 return; | 427 return; |
428 const SkBitmap* bitmap = lock.sk_bitmap(); | 428 const SkBitmap* bitmap = lock.sk_bitmap(); |
429 gfx::RectF uv_rect = gfx::ScaleRect(gfx::BoundingRect(quad->uv_top_left, | 429 gfx::RectF uv_rect = gfx::ScaleRect(gfx::BoundingRect(quad->uv_top_left, |
430 quad->uv_bottom_right), | 430 quad->uv_bottom_right), |
431 bitmap->width(), | 431 bitmap->width(), |
432 bitmap->height()); | 432 bitmap->height()); |
433 gfx::RectF visible_uv_rect = | 433 gfx::RectF visible_uv_rect = |
434 MathUtil::ScaleRectProportional(uv_rect, quad->rect, quad->visible_rect); | 434 MathUtil::ScaleRectProportional(uv_rect, quad->rect, quad->visible_rect); |
435 SkRect sk_uv_rect = gfx::RectFToSkRect(visible_uv_rect); | 435 SkRect sk_uv_rect = gfx::RectFToSkRect(visible_uv_rect); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 473 |
474 if (needs_layer) | 474 if (needs_layer) |
475 current_canvas_->restore(); | 475 current_canvas_->restore(); |
476 } | 476 } |
477 | 477 |
478 void SoftwareRenderer::DrawTileQuad(const DrawingFrame* frame, | 478 void SoftwareRenderer::DrawTileQuad(const DrawingFrame* frame, |
479 const TileDrawQuad* quad) { | 479 const TileDrawQuad* quad) { |
480 // |resource_provider_| can be NULL in resourceless software draws, which | 480 // |resource_provider_| can be NULL in resourceless software draws, which |
481 // should never produce tile quads in the first place. | 481 // should never produce tile quads in the first place. |
482 DCHECK(resource_provider_); | 482 DCHECK(resource_provider_); |
483 DCHECK(IsSoftwareResource(quad->resource_id)); | 483 DCHECK(IsSoftwareResource(quad->resource_id())); |
484 | 484 |
485 ResourceProvider::ScopedReadLockSoftware lock(resource_provider_, | 485 ResourceProvider::ScopedReadLockSoftware lock(resource_provider_, |
486 quad->resource_id); | 486 quad->resource_id()); |
487 if (!lock.valid()) | 487 if (!lock.valid()) |
488 return; | 488 return; |
489 DCHECK_EQ(GL_CLAMP_TO_EDGE, lock.wrap_mode()); | 489 DCHECK_EQ(GL_CLAMP_TO_EDGE, lock.wrap_mode()); |
490 | 490 |
491 gfx::RectF visible_tex_coord_rect = MathUtil::ScaleRectProportional( | 491 gfx::RectF visible_tex_coord_rect = MathUtil::ScaleRectProportional( |
492 quad->tex_coord_rect, quad->rect, quad->visible_rect); | 492 quad->tex_coord_rect, quad->rect, quad->visible_rect); |
493 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( | 493 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( |
494 QuadVertexRect(), quad->rect, quad->visible_rect); | 494 QuadVertexRect(), quad->rect, quad->visible_rect); |
495 | 495 |
496 SkRect uv_rect = gfx::RectFToSkRect(visible_tex_coord_rect); | 496 SkRect uv_rect = gfx::RectFToSkRect(visible_tex_coord_rect); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 skia::RefPtr<SkShader> shader; | 553 skia::RefPtr<SkShader> shader; |
554 if (filter_bitmap.isNull()) { | 554 if (filter_bitmap.isNull()) { |
555 shader = skia::AdoptRef(SkShader::CreateBitmapShader( | 555 shader = skia::AdoptRef(SkShader::CreateBitmapShader( |
556 *content, content_tile_mode, content_tile_mode, &content_mat)); | 556 *content, content_tile_mode, content_tile_mode, &content_mat)); |
557 } else { | 557 } else { |
558 shader = skia::AdoptRef(SkShader::CreateBitmapShader( | 558 shader = skia::AdoptRef(SkShader::CreateBitmapShader( |
559 filter_bitmap, content_tile_mode, content_tile_mode, &content_mat)); | 559 filter_bitmap, content_tile_mode, content_tile_mode, &content_mat)); |
560 } | 560 } |
561 current_paint_.setShader(shader.get()); | 561 current_paint_.setShader(shader.get()); |
562 | 562 |
563 if (quad->mask_resource_id) { | 563 if (quad->mask_resource_id()) { |
564 ResourceProvider::ScopedReadLockSoftware mask_lock(resource_provider_, | 564 ResourceProvider::ScopedReadLockSoftware mask_lock( |
565 quad->mask_resource_id); | 565 resource_provider_, quad->mask_resource_id()); |
566 if (!lock.valid()) | 566 if (!lock.valid()) |
567 return; | 567 return; |
568 SkShader::TileMode mask_tile_mode = WrapModeToTileMode( | 568 SkShader::TileMode mask_tile_mode = WrapModeToTileMode( |
569 mask_lock.wrap_mode()); | 569 mask_lock.wrap_mode()); |
570 | 570 |
571 const SkBitmap* mask = mask_lock.sk_bitmap(); | 571 const SkBitmap* mask = mask_lock.sk_bitmap(); |
572 | 572 |
573 // Scale normalized uv rect into absolute texel coordinates. | 573 // Scale normalized uv rect into absolute texel coordinates. |
574 SkRect mask_rect = | 574 SkRect mask_rect = |
575 gfx::RectFToSkRect(gfx::ScaleRect(quad->MaskUVRect(), | 575 gfx::RectFToSkRect(gfx::ScaleRect(quad->MaskUVRect(), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 } | 650 } |
651 | 651 |
652 void SoftwareRenderer::DidChangeVisibility() { | 652 void SoftwareRenderer::DidChangeVisibility() { |
653 if (visible()) | 653 if (visible()) |
654 EnsureBackbuffer(); | 654 EnsureBackbuffer(); |
655 else | 655 else |
656 DiscardBackbuffer(); | 656 DiscardBackbuffer(); |
657 } | 657 } |
658 | 658 |
659 } // namespace cc | 659 } // namespace cc |
OLD | NEW |