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/image/image_skia_operations.h" | 5 #include "ui/gfx/image/image_skia_operations.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 return ImageSkiaRep(rotated_bitmap, image_rep.scale()); | 416 return ImageSkiaRep(rotated_bitmap, image_rep.scale()); |
| 417 } | 417 } |
| 418 | 418 |
| 419 private: | 419 private: |
| 420 const ImageSkia source_; | 420 const ImageSkia source_; |
| 421 const SkBitmapOperations::RotationAmount rotation_; | 421 const SkBitmapOperations::RotationAmount rotation_; |
| 422 | 422 |
| 423 DISALLOW_COPY_AND_ASSIGN(RotatedSource); | 423 DISALLOW_COPY_AND_ASSIGN(RotatedSource); |
| 424 }; | 424 }; |
| 425 | 425 |
| 426 class IconWithBadgeSource : public gfx::CanvasImageSource { | |
| 427 public: | |
| 428 IconWithBadgeSource(const ImageSkia& icon, const ImageSkia& badge) | |
| 429 : gfx::CanvasImageSource(icon.size(), false /* is opaque */), | |
| 430 icon_(icon), | |
| 431 badge_(badge) {} | |
| 432 | |
| 433 ~IconWithBadgeSource() override {} | |
| 434 | |
| 435 // gfx::CanvasImageSource override. | |
| 436 void Draw(Canvas* canvas) override { | |
| 437 canvas->DrawImageInt(icon_, 0, 0); | |
| 438 canvas->DrawImageInt(badge_, (icon_.width() - badge_.width()), | |
| 439 (icon_.height() - badge_.height())); | |
| 440 } | |
| 441 | |
| 442 private: | |
| 443 const ImageSkia icon_; | |
| 444 const ImageSkia badge_; | |
| 445 | |
| 446 DISALLOW_COPY_AND_ASSIGN(IconWithBadgeSource); | |
| 447 }; | |
| 426 | 448 |
| 427 } // namespace | 449 } // namespace |
| 428 | 450 |
| 429 // static | 451 // static |
| 430 ImageSkia ImageSkiaOperations::CreateBlendedImage(const ImageSkia& first, | 452 ImageSkia ImageSkiaOperations::CreateBlendedImage(const ImageSkia& first, |
| 431 const ImageSkia& second, | 453 const ImageSkia& second, |
| 432 double alpha) { | 454 double alpha) { |
| 433 if (first.isNull() || second.isNull()) | 455 if (first.isNull() || second.isNull()) |
| 434 return ImageSkia(); | 456 return ImageSkia(); |
| 435 | 457 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 if (source.isNull()) | 563 if (source.isNull()) |
| 542 return ImageSkia(); | 564 return ImageSkia(); |
| 543 | 565 |
| 544 return ImageSkia(new RotatedSource(source, rotation), | 566 return ImageSkia(new RotatedSource(source, rotation), |
| 545 SkBitmapOperations::ROTATION_180_CW == rotation ? | 567 SkBitmapOperations::ROTATION_180_CW == rotation ? |
| 546 source.size() : | 568 source.size() : |
| 547 gfx::Size(source.height(), source.width())); | 569 gfx::Size(source.height(), source.width())); |
| 548 | 570 |
| 549 } | 571 } |
| 550 | 572 |
| 573 // static | |
| 574 ImageSkia ImageSkiaOperations::CreateIconWithBadge(const ImageSkia& icon, | |
| 575 const ImageSkia& badge) { | |
| 576 if (icon.isNull()) | |
| 577 return ImageSkia(); | |
| 578 | |
| 579 if (!icon.isNull() && badge.isNull()) | |
|
stevenjb
2016/08/10 16:58:48
This can just be if (badge.isNull())
Andra Paraschiv
2016/08/11 07:20:55
Done.
| |
| 580 return icon; | |
| 581 | |
| 582 return ImageSkia(new IconWithBadgeSource(icon, badge), icon.size()); | |
| 583 } | |
| 584 | |
| 551 } // namespace gfx | 585 } // namespace gfx |
| OLD | NEW |