Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/themes/browser_theme_pack.cc

Issue 24175004: Remove dependency on ui::ScaleFactor from ui/gfx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/memory/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 470 }
471 471
472 // A ImageSkiaSource that scales 100P image to the target scale factor 472 // A ImageSkiaSource that scales 100P image to the target scale factor
473 // if the ImageSkiaRep for the target scale factor isn't available. 473 // if the ImageSkiaRep for the target scale factor isn't available.
474 class ThemeImageSource: public gfx::ImageSkiaSource { 474 class ThemeImageSource: public gfx::ImageSkiaSource {
475 public: 475 public:
476 explicit ThemeImageSource(const gfx::ImageSkia& source) : source_(source) { 476 explicit ThemeImageSource(const gfx::ImageSkia& source) : source_(source) {
477 } 477 }
478 virtual ~ThemeImageSource() {} 478 virtual ~ThemeImageSource() {}
479 479
480 virtual gfx::ImageSkiaRep GetImageForScale( 480 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
481 ui::ScaleFactor scale_factor) OVERRIDE { 481 if (source_.HasRepresentation(scale))
482 if (source_.HasRepresentation(scale_factor)) 482 return source_.GetRepresentation(scale);
483 return source_.GetRepresentation(scale_factor);
484 const gfx::ImageSkiaRep& rep_100p = 483 const gfx::ImageSkiaRep& rep_100p =
485 source_.GetRepresentation(ui::SCALE_FACTOR_100P); 484 source_.GetRepresentation(1.0f);
486 SkBitmap scaled_bitmap = CreateLowQualityResizedBitmap( 485 SkBitmap scaled_bitmap = CreateLowQualityResizedBitmap(
487 rep_100p.sk_bitmap(), 486 rep_100p.sk_bitmap(),
488 ui::SCALE_FACTOR_100P, 487 ui::SCALE_FACTOR_100P,
489 scale_factor); 488 ui::GetScaleFactorFromScale(scale));
490 return gfx::ImageSkiaRep(scaled_bitmap, scale_factor); 489 return gfx::ImageSkiaRep(scaled_bitmap, scale);
491 } 490 }
492 491
493 private: 492 private:
494 const gfx::ImageSkia source_; 493 const gfx::ImageSkia source_;
495 494
496 DISALLOW_COPY_AND_ASSIGN(ThemeImageSource); 495 DISALLOW_COPY_AND_ASSIGN(ThemeImageSource);
497 }; 496 };
498 497
499 // An ImageSkiaSource that delays decoding PNG data into bitmaps until 498 // An ImageSkiaSource that delays decoding PNG data into bitmaps until
500 // needed. Missing data for a scale factor is computed by scaling data for an 499 // needed. Missing data for a scale factor is computed by scaling data for an
501 // available scale factor. Computed bitmaps are stored for future look up. 500 // available scale factor. Computed bitmaps are stored for future look up.
502 class ThemeImagePngSource : public gfx::ImageSkiaSource { 501 class ThemeImagePngSource : public gfx::ImageSkiaSource {
503 public: 502 public:
504 typedef std::map<ui::ScaleFactor, 503 typedef std::map<ui::ScaleFactor,
505 scoped_refptr<base::RefCountedMemory> > PngMap; 504 scoped_refptr<base::RefCountedMemory> > PngMap;
506 505
507 explicit ThemeImagePngSource(const PngMap& png_map) : png_map_(png_map) {} 506 explicit ThemeImagePngSource(const PngMap& png_map) : png_map_(png_map) {}
508 507
509 virtual ~ThemeImagePngSource() {} 508 virtual ~ThemeImagePngSource() {}
510 509
511 private: 510 private:
512 virtual gfx::ImageSkiaRep GetImageForScale( 511 virtual gfx::ImageSkiaRep GetImageForScale(float scale) OVERRIDE {
513 ui::ScaleFactor scale_factor) OVERRIDE { 512 ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale);
514 // Look up the bitmap for |scale factor| in the bitmap map. If found 513 // Look up the bitmap for |scale factor| in the bitmap map. If found
515 // return it. 514 // return it.
516 BitmapMap::const_iterator exact_bitmap_it = bitmap_map_.find(scale_factor); 515 BitmapMap::const_iterator exact_bitmap_it = bitmap_map_.find(scale_factor);
517 if (exact_bitmap_it != bitmap_map_.end()) 516 if (exact_bitmap_it != bitmap_map_.end())
518 return gfx::ImageSkiaRep(exact_bitmap_it->second, scale_factor); 517 return gfx::ImageSkiaRep(exact_bitmap_it->second, scale);
519 518
520 // Look up the raw PNG data for |scale_factor| in the png map. If found, 519 // Look up the raw PNG data for |scale_factor| in the png map. If found,
521 // decode it, store the result in the bitmap map and return it. 520 // decode it, store the result in the bitmap map and return it.
522 PngMap::const_iterator exact_png_it = png_map_.find(scale_factor); 521 PngMap::const_iterator exact_png_it = png_map_.find(scale_factor);
523 if (exact_png_it != png_map_.end()) { 522 if (exact_png_it != png_map_.end()) {
524 SkBitmap bitmap; 523 SkBitmap bitmap;
525 if (!gfx::PNGCodec::Decode(exact_png_it->second->front(), 524 if (!gfx::PNGCodec::Decode(exact_png_it->second->front(),
526 exact_png_it->second->size(), 525 exact_png_it->second->size(),
527 &bitmap)) { 526 &bitmap)) {
528 NOTREACHED(); 527 NOTREACHED();
529 return gfx::ImageSkiaRep(); 528 return gfx::ImageSkiaRep();
530 } 529 }
531 bitmap_map_[scale_factor] = bitmap; 530 bitmap_map_[scale_factor] = bitmap;
532 return gfx::ImageSkiaRep(bitmap, scale_factor); 531 return gfx::ImageSkiaRep(bitmap, scale);
533 } 532 }
534 533
535 // Find an available PNG for another scale factor. We want to use the 534 // Find an available PNG for another scale factor. We want to use the
536 // highest available scale factor. 535 // highest available scale factor.
537 PngMap::const_iterator available_png_it = png_map_.end(); 536 PngMap::const_iterator available_png_it = png_map_.end();
538 for (PngMap::const_iterator png_it = png_map_.begin(); 537 for (PngMap::const_iterator png_it = png_map_.begin();
539 png_it != png_map_.end(); ++png_it) { 538 png_it != png_map_.end(); ++png_it) {
540 if (available_png_it == png_map_.end() || 539 if (available_png_it == png_map_.end() ||
541 ui::GetScaleFactorScale(png_it->first) > 540 ui::GetScaleFactorScale(png_it->first) >
542 ui::GetScaleFactorScale(available_png_it->first)) { 541 ui::GetScaleFactorScale(available_png_it->first)) {
(...skipping 21 matching lines...) Expand all
564 available_bitmap_it = bitmap_map_.find(available_scale_factor); 563 available_bitmap_it = bitmap_map_.find(available_scale_factor);
565 } 564 }
566 565
567 // Scale the available bitmap to the desired scale factor, store the result 566 // Scale the available bitmap to the desired scale factor, store the result
568 // in the bitmap map and return it. 567 // in the bitmap map and return it.
569 SkBitmap scaled_bitmap = CreateLowQualityResizedBitmap( 568 SkBitmap scaled_bitmap = CreateLowQualityResizedBitmap(
570 available_bitmap_it->second, 569 available_bitmap_it->second,
571 available_scale_factor, 570 available_scale_factor,
572 scale_factor); 571 scale_factor);
573 bitmap_map_[scale_factor] = scaled_bitmap; 572 bitmap_map_[scale_factor] = scaled_bitmap;
574 return gfx::ImageSkiaRep(scaled_bitmap, scale_factor); 573 return gfx::ImageSkiaRep(scaled_bitmap, scale);
575 } 574 }
576 575
577 PngMap png_map_; 576 PngMap png_map_;
578 577
579 typedef std::map<ui::ScaleFactor, SkBitmap> BitmapMap; 578 typedef std::map<ui::ScaleFactor, SkBitmap> BitmapMap;
580 BitmapMap bitmap_map_; 579 BitmapMap bitmap_map_;
581 580
582 DISALLOW_COPY_AND_ASSIGN(ThemeImagePngSource); 581 DISALLOW_COPY_AND_ASSIGN(ThemeImagePngSource);
583 }; 582 };
584 583
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 return false; 1277 return false;
1279 } 1278 }
1280 if (is_copyable) { 1279 if (is_copyable) {
1281 int raw_id = GetRawIDByPersistentID(prs_id, scale_factor); 1280 int raw_id = GetRawIDByPersistentID(prs_id, scale_factor);
1282 image_memory_[raw_id] = raw_data; 1281 image_memory_[raw_id] = raw_data;
1283 } else { 1282 } else {
1284 SkBitmap bitmap; 1283 SkBitmap bitmap;
1285 if (gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(), 1284 if (gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(),
1286 &bitmap)) { 1285 &bitmap)) {
1287 image_skia.AddRepresentation( 1286 image_skia.AddRepresentation(
1288 gfx::ImageSkiaRep(bitmap, scale_factor)); 1287 gfx::ImageSkiaRep(bitmap,
1288 ui::GetScaleFactorScale(scale_factor)));
1289 } else { 1289 } else {
1290 NOTREACHED() << "Unable to decode theme image resource " 1290 NOTREACHED() << "Unable to decode theme image resource "
1291 << it->first; 1291 << it->first;
1292 } 1292 }
1293 } 1293 }
1294 } 1294 }
1295 } 1295 }
1296 if (!is_copyable && !image_skia.isNull()) 1296 if (!is_copyable && !image_skia.isNull())
1297 (*image_cache)[prs_id] = gfx::Image(image_skia); 1297 (*image_cache)[prs_id] = gfx::Image(image_skia);
1298 } 1298 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 NOTREACHED() << "No image reps for resource " << it->first << "."; 1466 NOTREACHED() << "No image reps for resource " << it->first << ".";
1467 } 1467 }
1468 for (ImageSkiaReps::iterator rep_it = image_reps.begin(); 1468 for (ImageSkiaReps::iterator rep_it = image_reps.begin();
1469 rep_it != image_reps.end(); ++rep_it) { 1469 rep_it != image_reps.end(); ++rep_it) {
1470 std::vector<unsigned char> bitmap_data; 1470 std::vector<unsigned char> bitmap_data;
1471 if (!gfx::PNGCodec::EncodeBGRASkBitmap(rep_it->sk_bitmap(), false, 1471 if (!gfx::PNGCodec::EncodeBGRASkBitmap(rep_it->sk_bitmap(), false,
1472 &bitmap_data)) { 1472 &bitmap_data)) {
1473 NOTREACHED() << "Image file for resource " << it->first 1473 NOTREACHED() << "Image file for resource " << it->first
1474 << " could not be encoded."; 1474 << " could not be encoded.";
1475 } 1475 }
1476 int raw_id = GetRawIDByPersistentID(it->first, rep_it->scale_factor()); 1476 int raw_id = GetRawIDByPersistentID(
1477 it->first,
1478 ui::GetScaleFactorFromScale(rep_it->scale()));
1477 (*reencoded_images)[raw_id] = 1479 (*reencoded_images)[raw_id] =
1478 base::RefCountedBytes::TakeVector(&bitmap_data); 1480 base::RefCountedBytes::TakeVector(&bitmap_data);
1479 } 1481 }
1480 } 1482 }
1481 } 1483 }
1482 1484
1483 void BrowserThemePack::MergeImageCaches( 1485 void BrowserThemePack::MergeImageCaches(
1484 const ImageCache& source, ImageCache* destination) const { 1486 const ImageCache& source, ImageCache* destination) const {
1485 for (ImageCache::const_iterator it = source.begin(); it != source.end(); 1487 for (ImageCache::const_iterator it = source.begin(); it != source.end();
1486 ++it) { 1488 ++it) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 false, 1608 false,
1607 &bitmap_data)) { 1609 &bitmap_data)) {
1608 NOTREACHED() << "Unable to encode theme image for prs_id=" 1610 NOTREACHED() << "Unable to encode theme image for prs_id="
1609 << prs_id << " for scale_factor=" << scale_factors_[i]; 1611 << prs_id << " for scale_factor=" << scale_factors_[i];
1610 break; 1612 break;
1611 } 1613 }
1612 image_memory_[scaled_raw_id] = 1614 image_memory_[scaled_raw_id] =
1613 base::RefCountedBytes::TakeVector(&bitmap_data); 1615 base::RefCountedBytes::TakeVector(&bitmap_data);
1614 } 1616 }
1615 } 1617 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698