Chromium Code Reviews| 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 } | |
| 496 | |
| 497 void Canvas::TileImageInt(const ImageSkia& image, | |
| 498 int src_x, | |
| 499 int src_y, | |
| 500 float tile_scale_x, | |
| 501 float tile_scale_y, | |
| 502 int dest_x, | |
| 503 int dest_y, | |
| 504 int w, | |
| 505 int h) { | |
| 506 SkRect dest_rect = { SkIntToScalar(dest_x), | 495 SkRect dest_rect = { SkIntToScalar(dest_x), |
| 507 SkIntToScalar(dest_y), | 496 SkIntToScalar(dest_y), |
| 508 SkIntToScalar(dest_x + w), | 497 SkIntToScalar(dest_x + w), |
| 509 SkIntToScalar(dest_y + h) }; | 498 SkIntToScalar(dest_y + h) }; |
| 510 if (!IntersectsClipRect(dest_rect)) | 499 if (!IntersectsClipRect(dest_rect)) |
| 511 return; | 500 return; |
| 512 | 501 |
| 513 cc::PaintFlags flags; | 502 if (!flags) { |
| 514 if (InitPaintFlagsForTiling(image, src_x, src_y, tile_scale_x, tile_scale_y, | 503 cc::PaintFlags paint_flags; |
| 515 dest_x, dest_y, &flags)) | 504 flags = &paint_flags; |
|
Peter Kasting
2017/03/24 22:52:35
This doesn't work -- you've declared your temp ins
Qiang(Joe) Xu
2017/03/24 22:57:00
oh, right! sorry for the iterations...
| |
| 516 canvas_->drawRect(dest_rect, flags); | 505 } |
| 506 if (InitPaintFlagsForTiling(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y, | |
| 507 flags)) { | |
|
Peter Kasting
2017/03/24 22:52:35
Nit: Don't add {}
Qiang(Joe) Xu
2017/03/24 22:57:00
Done.
| |
| 508 canvas_->drawRect(dest_rect, *flags); | |
| 509 } | |
| 517 } | 510 } |
| 518 | 511 |
| 519 bool Canvas::InitPaintFlagsForTiling(const ImageSkia& image, | 512 bool Canvas::InitPaintFlagsForTiling(const ImageSkia& image, |
| 520 int src_x, | 513 int src_x, |
| 521 int src_y, | 514 int src_y, |
| 522 float tile_scale_x, | 515 float tile_scale_x, |
| 523 float tile_scale_y, | 516 float tile_scale_y, |
| 524 int dest_x, | 517 int dest_x, |
| 525 int dest_y, | 518 int dest_y, |
| 526 cc::PaintFlags* flags) { | 519 cc::PaintFlags* flags) { |
| 527 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_); | 520 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_); |
| 528 if (image_rep.is_null()) | 521 if (image_rep.is_null()) |
| 529 return false; | 522 return false; |
| 530 | 523 |
| 531 SkMatrix shader_scale; | 524 SkMatrix shader_scale; |
| 532 shader_scale.setScale(SkFloatToScalar(tile_scale_x), | 525 shader_scale.setScale(SkFloatToScalar(tile_scale_x), |
| 533 SkFloatToScalar(tile_scale_y)); | 526 SkFloatToScalar(tile_scale_y)); |
| 534 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); | 527 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); |
| 535 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); | 528 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); |
| 536 | 529 |
| 537 flags->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode, | 530 flags->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode, |
| 538 shader_scale)); | 531 shader_scale)); |
| 539 flags->setBlendMode(SkBlendMode::kSrcOver); | |
| 540 return true; | 532 return true; |
| 541 } | 533 } |
| 542 | 534 |
| 543 void Canvas::Transform(const gfx::Transform& transform) { | 535 void Canvas::Transform(const gfx::Transform& transform) { |
| 544 canvas_->concat(transform.matrix()); | 536 canvas_->concat(transform.matrix()); |
| 545 } | 537 } |
| 546 | 538 |
| 547 SkBitmap Canvas::GetBitmap() const { | 539 SkBitmap Canvas::GetBitmap() const { |
| 548 DCHECK(bitmap_); | 540 DCHECK(bitmap_); |
| 549 SkBitmap bitmap = bitmap_.value(); | 541 SkBitmap bitmap = bitmap_.value(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 bitmap_.emplace(); | 614 bitmap_.emplace(); |
| 623 bitmap_->allocPixels(info); | 615 bitmap_->allocPixels(info); |
| 624 // Ensure that the bitmap is zeroed, since the code expects that. | 616 // Ensure that the bitmap is zeroed, since the code expects that. |
| 625 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); | 617 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); |
| 626 | 618 |
| 627 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); | 619 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); |
| 628 return &owned_canvas_.value(); | 620 return &owned_canvas_.value(); |
| 629 } | 621 } |
| 630 | 622 |
| 631 } // namespace gfx | 623 } // namespace gfx |
| OLD | NEW |