| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/gfx/canvas.h" | 5 #include "ui/gfx/canvas.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 int h) { | 483 int h) { |
| 484 TileImageInt(image, 0, 0, x, y, w, h); | 484 TileImageInt(image, 0, 0, x, y, w, h); |
| 485 } | 485 } |
| 486 | 486 |
| 487 void Canvas::TileImageInt(const ImageSkia& image, | 487 void Canvas::TileImageInt(const ImageSkia& image, |
| 488 int src_x, | 488 int src_x, |
| 489 int src_y, | 489 int src_y, |
| 490 int dest_x, | 490 int dest_x, |
| 491 int dest_y, | 491 int dest_y, |
| 492 int w, | 492 int w, |
| 493 int h) { | 493 int h, |
| 494 TileImageInt(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y, w, h); | 494 cc::PaintFlags* flags) { |
| 495 TileImageInt(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y, w, h, flags); |
| 495 } | 496 } |
| 496 | 497 |
| 497 void Canvas::TileImageInt(const ImageSkia& image, | 498 void Canvas::TileImageInt(const ImageSkia& image, |
| 498 int src_x, | 499 int src_x, |
| 499 int src_y, | 500 int src_y, |
| 500 float tile_scale_x, | 501 float tile_scale_x, |
| 501 float tile_scale_y, | 502 float tile_scale_y, |
| 502 int dest_x, | 503 int dest_x, |
| 503 int dest_y, | 504 int dest_y, |
| 504 int w, | 505 int w, |
| 505 int h) { | 506 int h, |
| 507 cc::PaintFlags* flags) { |
| 506 SkRect dest_rect = { SkIntToScalar(dest_x), | 508 SkRect dest_rect = { SkIntToScalar(dest_x), |
| 507 SkIntToScalar(dest_y), | 509 SkIntToScalar(dest_y), |
| 508 SkIntToScalar(dest_x + w), | 510 SkIntToScalar(dest_x + w), |
| 509 SkIntToScalar(dest_y + h) }; | 511 SkIntToScalar(dest_y + h) }; |
| 510 if (!IntersectsClipRect(dest_rect)) | 512 if (!IntersectsClipRect(dest_rect)) |
| 511 return; | 513 return; |
| 512 | 514 |
| 513 cc::PaintFlags flags; | 515 cc::PaintFlags paint_flags; |
| 516 if (!flags) |
| 517 flags = &paint_flags; |
| 518 |
| 514 if (InitPaintFlagsForTiling(image, src_x, src_y, tile_scale_x, tile_scale_y, | 519 if (InitPaintFlagsForTiling(image, src_x, src_y, tile_scale_x, tile_scale_y, |
| 515 dest_x, dest_y, &flags)) | 520 dest_x, dest_y, flags)) |
| 516 canvas_->drawRect(dest_rect, flags); | 521 canvas_->drawRect(dest_rect, *flags); |
| 517 } | 522 } |
| 518 | 523 |
| 519 bool Canvas::InitPaintFlagsForTiling(const ImageSkia& image, | 524 bool Canvas::InitPaintFlagsForTiling(const ImageSkia& image, |
| 520 int src_x, | 525 int src_x, |
| 521 int src_y, | 526 int src_y, |
| 522 float tile_scale_x, | 527 float tile_scale_x, |
| 523 float tile_scale_y, | 528 float tile_scale_y, |
| 524 int dest_x, | 529 int dest_x, |
| 525 int dest_y, | 530 int dest_y, |
| 526 cc::PaintFlags* flags) { | 531 cc::PaintFlags* flags) { |
| 527 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_); | 532 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_); |
| 528 if (image_rep.is_null()) | 533 if (image_rep.is_null()) |
| 529 return false; | 534 return false; |
| 530 | 535 |
| 531 SkMatrix shader_scale; | 536 SkMatrix shader_scale; |
| 532 shader_scale.setScale(SkFloatToScalar(tile_scale_x), | 537 shader_scale.setScale(SkFloatToScalar(tile_scale_x), |
| 533 SkFloatToScalar(tile_scale_y)); | 538 SkFloatToScalar(tile_scale_y)); |
| 534 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); | 539 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); |
| 535 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); | 540 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); |
| 536 | 541 |
| 537 flags->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode, | 542 flags->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode, |
| 538 shader_scale)); | 543 shader_scale)); |
| 539 flags->setBlendMode(SkBlendMode::kSrcOver); | |
| 540 return true; | 544 return true; |
| 541 } | 545 } |
| 542 | 546 |
| 543 void Canvas::Transform(const gfx::Transform& transform) { | 547 void Canvas::Transform(const gfx::Transform& transform) { |
| 544 canvas_->concat(transform.matrix()); | 548 canvas_->concat(transform.matrix()); |
| 545 } | 549 } |
| 546 | 550 |
| 547 SkBitmap Canvas::GetBitmap() const { | 551 SkBitmap Canvas::GetBitmap() const { |
| 548 DCHECK(bitmap_); | 552 DCHECK(bitmap_); |
| 549 SkBitmap bitmap = bitmap_.value(); | 553 SkBitmap bitmap = bitmap_.value(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 bitmap_.emplace(); | 626 bitmap_.emplace(); |
| 623 bitmap_->allocPixels(info); | 627 bitmap_->allocPixels(info); |
| 624 // Ensure that the bitmap is zeroed, since the code expects that. | 628 // Ensure that the bitmap is zeroed, since the code expects that. |
| 625 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); | 629 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); |
| 626 | 630 |
| 627 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); | 631 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); |
| 628 return &owned_canvas_.value(); | 632 return &owned_canvas_.value(); |
| 629 } | 633 } |
| 630 | 634 |
| 631 } // namespace gfx | 635 } // namespace gfx |
| OLD | NEW |