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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~ThemeImageSource() {} |
497 | 497 |
498 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 498 virtual 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 virtual ~ThemeImagePngSource() {} |
526 | 526 |
527 private: | 527 private: |
528 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE { | 528 virtual 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~TabBackgroundImageSource() { |
615 } | 615 } |
616 | 616 |
617 // Overridden from CanvasImageSource: | 617 // Overridden from CanvasImageSource: |
618 virtual void Draw(gfx::Canvas* canvas) OVERRIDE { | 618 virtual void Draw(gfx::Canvas* canvas) override { |
619 gfx::ImageSkia bg_tint = | 619 gfx::ImageSkia bg_tint = |
620 gfx::ImageSkiaOperations::CreateHSLShiftedImage(image_to_tint_, | 620 gfx::ImageSkiaOperations::CreateHSLShiftedImage(image_to_tint_, |
621 hsl_shift_); | 621 hsl_shift_); |
622 canvas->TileImageInt(bg_tint, 0, vertical_offset_, 0, 0, | 622 canvas->TileImageInt(bg_tint, 0, vertical_offset_, 0, 0, |
623 size().width(), size().height()); | 623 size().width(), size().height()); |
624 | 624 |
625 // If they've provided a custom image, overlay it. | 625 // If they've provided a custom image, overlay it. |
626 if (!overlay_.isNull()) { | 626 if (!overlay_.isNull()) { |
627 canvas->TileImageInt(overlay_, 0, 0, size().width(), | 627 canvas->TileImageInt(overlay_, 0, 0, size().width(), |
628 overlay_.height()); | 628 overlay_.height()); |
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 false, | 1629 false, |
1630 &bitmap_data)) { | 1630 &bitmap_data)) { |
1631 NOTREACHED() << "Unable to encode theme image for prs_id=" | 1631 NOTREACHED() << "Unable to encode theme image for prs_id=" |
1632 << prs_id << " for scale_factor=" << scale_factors_[i]; | 1632 << prs_id << " for scale_factor=" << scale_factors_[i]; |
1633 break; | 1633 break; |
1634 } | 1634 } |
1635 image_memory_[scaled_raw_id] = | 1635 image_memory_[scaled_raw_id] = |
1636 base::RefCountedBytes::TakeVector(&bitmap_data); | 1636 base::RefCountedBytes::TakeVector(&bitmap_data); |
1637 } | 1637 } |
1638 } | 1638 } |
OLD | NEW |