| 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 "chrome/browser/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 canvas.drawBitmapRect(source_bitmap, NULL, scaled_bounds); | 486 canvas.drawBitmapRect(source_bitmap, NULL, scaled_bounds); |
| 487 return scaled_bitmap; | 487 return scaled_bitmap; |
| 488 } | 488 } |
| 489 | 489 |
| 490 // A ImageSkiaSource that scales 100P image to the target scale factor | 490 // A ImageSkiaSource that scales 100P image to the target scale factor |
| 491 // if the ImageSkiaRep for the target scale factor isn't available. | 491 // if the ImageSkiaRep for the target scale factor isn't available. |
| 492 class ThemeImageSource: public gfx::ImageSkiaSource { | 492 class ThemeImageSource: public gfx::ImageSkiaSource { |
| 493 public: | 493 public: |
| 494 explicit ThemeImageSource(const gfx::ImageSkia& source) : source_(source) { | 494 explicit ThemeImageSource(const gfx::ImageSkia& source) : source_(source) { |
| 495 } | 495 } |
| 496 virtual ~ThemeImageSource() {} | 496 ~ThemeImageSource() override {} |
| 497 | 497 |
| 498 virtual gfx::ImageSkiaRep GetImageForScale(float scale) override { | 498 gfx::ImageSkiaRep GetImageForScale(float scale) override { |
| 499 if (source_.HasRepresentation(scale)) | 499 if (source_.HasRepresentation(scale)) |
| 500 return source_.GetRepresentation(scale); | 500 return source_.GetRepresentation(scale); |
| 501 const gfx::ImageSkiaRep& rep_100p = source_.GetRepresentation(1.0f); | 501 const gfx::ImageSkiaRep& rep_100p = source_.GetRepresentation(1.0f); |
| 502 SkBitmap scaled_bitmap = CreateLowQualityResizedBitmap( | 502 SkBitmap scaled_bitmap = CreateLowQualityResizedBitmap( |
| 503 rep_100p.sk_bitmap(), | 503 rep_100p.sk_bitmap(), |
| 504 ui::SCALE_FACTOR_100P, | 504 ui::SCALE_FACTOR_100P, |
| 505 ui::GetSupportedScaleFactor(scale)); | 505 ui::GetSupportedScaleFactor(scale)); |
| 506 return gfx::ImageSkiaRep(scaled_bitmap, scale); | 506 return gfx::ImageSkiaRep(scaled_bitmap, scale); |
| 507 } | 507 } |
| 508 | 508 |
| 509 private: | 509 private: |
| 510 const gfx::ImageSkia source_; | 510 const gfx::ImageSkia source_; |
| 511 | 511 |
| 512 DISALLOW_COPY_AND_ASSIGN(ThemeImageSource); | 512 DISALLOW_COPY_AND_ASSIGN(ThemeImageSource); |
| 513 }; | 513 }; |
| 514 | 514 |
| 515 // An ImageSkiaSource that delays decoding PNG data into bitmaps until | 515 // An ImageSkiaSource that delays decoding PNG data into bitmaps until |
| 516 // needed. Missing data for a scale factor is computed by scaling data for an | 516 // needed. Missing data for a scale factor is computed by scaling data for an |
| 517 // available scale factor. Computed bitmaps are stored for future look up. | 517 // available scale factor. Computed bitmaps are stored for future look up. |
| 518 class ThemeImagePngSource : public gfx::ImageSkiaSource { | 518 class ThemeImagePngSource : public gfx::ImageSkiaSource { |
| 519 public: | 519 public: |
| 520 typedef std::map<ui::ScaleFactor, | 520 typedef std::map<ui::ScaleFactor, |
| 521 scoped_refptr<base::RefCountedMemory> > PngMap; | 521 scoped_refptr<base::RefCountedMemory> > PngMap; |
| 522 | 522 |
| 523 explicit ThemeImagePngSource(const PngMap& png_map) : png_map_(png_map) {} | 523 explicit ThemeImagePngSource(const PngMap& png_map) : png_map_(png_map) {} |
| 524 | 524 |
| 525 virtual ~ThemeImagePngSource() {} | 525 ~ThemeImagePngSource() override {} |
| 526 | 526 |
| 527 private: | 527 private: |
| 528 virtual gfx::ImageSkiaRep GetImageForScale(float scale) override { | 528 gfx::ImageSkiaRep GetImageForScale(float scale) override { |
| 529 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale); | 529 ui::ScaleFactor scale_factor = ui::GetSupportedScaleFactor(scale); |
| 530 // Look up the bitmap for |scale factor| in the bitmap map. If found | 530 // Look up the bitmap for |scale factor| in the bitmap map. If found |
| 531 // return it. | 531 // return it. |
| 532 BitmapMap::const_iterator exact_bitmap_it = bitmap_map_.find(scale_factor); | 532 BitmapMap::const_iterator exact_bitmap_it = bitmap_map_.find(scale_factor); |
| 533 if (exact_bitmap_it != bitmap_map_.end()) | 533 if (exact_bitmap_it != bitmap_map_.end()) |
| 534 return gfx::ImageSkiaRep(exact_bitmap_it->second, scale); | 534 return gfx::ImageSkiaRep(exact_bitmap_it->second, scale); |
| 535 | 535 |
| 536 // Look up the raw PNG data for |scale_factor| in the png map. If found, | 536 // Look up the raw PNG data for |scale_factor| in the png map. If found, |
| 537 // decode it, store the result in the bitmap map and return it. | 537 // decode it, store the result in the bitmap map and return it. |
| 538 PngMap::const_iterator exact_png_it = png_map_.find(scale_factor); | 538 PngMap::const_iterator exact_png_it = png_map_.find(scale_factor); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 const gfx::ImageSkia& overlay, | 604 const gfx::ImageSkia& overlay, |
| 605 const color_utils::HSL& hsl_shift, | 605 const color_utils::HSL& hsl_shift, |
| 606 int vertical_offset) | 606 int vertical_offset) |
| 607 : gfx::CanvasImageSource(image_to_tint.size(), false), | 607 : gfx::CanvasImageSource(image_to_tint.size(), false), |
| 608 image_to_tint_(image_to_tint), | 608 image_to_tint_(image_to_tint), |
| 609 overlay_(overlay), | 609 overlay_(overlay), |
| 610 hsl_shift_(hsl_shift), | 610 hsl_shift_(hsl_shift), |
| 611 vertical_offset_(vertical_offset) { | 611 vertical_offset_(vertical_offset) { |
| 612 } | 612 } |
| 613 | 613 |
| 614 virtual ~TabBackgroundImageSource() { | 614 ~TabBackgroundImageSource() override {} |
| 615 } | |
| 616 | 615 |
| 617 // Overridden from CanvasImageSource: | 616 // Overridden from CanvasImageSource: |
| 618 virtual void Draw(gfx::Canvas* canvas) override { | 617 void Draw(gfx::Canvas* canvas) override { |
| 619 gfx::ImageSkia bg_tint = | 618 gfx::ImageSkia bg_tint = |
| 620 gfx::ImageSkiaOperations::CreateHSLShiftedImage(image_to_tint_, | 619 gfx::ImageSkiaOperations::CreateHSLShiftedImage(image_to_tint_, |
| 621 hsl_shift_); | 620 hsl_shift_); |
| 622 canvas->TileImageInt(bg_tint, 0, vertical_offset_, 0, 0, | 621 canvas->TileImageInt(bg_tint, 0, vertical_offset_, 0, 0, |
| 623 size().width(), size().height()); | 622 size().width(), size().height()); |
| 624 | 623 |
| 625 // If they've provided a custom image, overlay it. | 624 // If they've provided a custom image, overlay it. |
| 626 if (!overlay_.isNull()) { | 625 if (!overlay_.isNull()) { |
| 627 canvas->TileImageInt(overlay_, 0, 0, size().width(), | 626 canvas->TileImageInt(overlay_, 0, 0, size().width(), |
| 628 overlay_.height()); | 627 overlay_.height()); |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 false, | 1629 false, |
| 1631 &bitmap_data)) { | 1630 &bitmap_data)) { |
| 1632 NOTREACHED() << "Unable to encode theme image for prs_id=" | 1631 NOTREACHED() << "Unable to encode theme image for prs_id=" |
| 1633 << prs_id << " for scale_factor=" << scale_factors_[i]; | 1632 << prs_id << " for scale_factor=" << scale_factors_[i]; |
| 1634 break; | 1633 break; |
| 1635 } | 1634 } |
| 1636 image_memory_[scaled_raw_id] = | 1635 image_memory_[scaled_raw_id] = |
| 1637 base::RefCountedBytes::TakeVector(&bitmap_data); | 1636 base::RefCountedBytes::TakeVector(&bitmap_data); |
| 1638 } | 1637 } |
| 1639 } | 1638 } |
| OLD | NEW |