| 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/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const int kMediumFontSizeDelta = 3; | 39 const int kMediumFontSizeDelta = 3; |
| 40 const int kLargeFontSizeDelta = 8; | 40 const int kLargeFontSizeDelta = 8; |
| 41 | 41 |
| 42 // Returns the actual scale factor of |bitmap| given the image representations | 42 // Returns the actual scale factor of |bitmap| given the image representations |
| 43 // which have already been added to |image|. | 43 // which have already been added to |image|. |
| 44 // TODO(pkotwicz): Remove this once we are no longer loading 1x resources | 44 // TODO(pkotwicz): Remove this once we are no longer loading 1x resources |
| 45 // as part of 2x data packs. | 45 // as part of 2x data packs. |
| 46 ui::ScaleFactor GetActualScaleFactor(const gfx::ImageSkia& image, | 46 ui::ScaleFactor GetActualScaleFactor(const gfx::ImageSkia& image, |
| 47 const SkBitmap& bitmap, | 47 const SkBitmap& bitmap, |
| 48 ui::ScaleFactor data_pack_scale_factor) { | 48 ui::ScaleFactor data_pack_scale_factor) { |
| 49 if (image.empty()) | 49 if (image.isNull()) |
| 50 return data_pack_scale_factor; | 50 return data_pack_scale_factor; |
| 51 | 51 |
| 52 return ui::GetScaleFactorFromScale( | 52 return ui::GetScaleFactorFromScale( |
| 53 static_cast<float>(bitmap.width()) / image.width()); | 53 static_cast<float>(bitmap.width()) / image.width()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // If 2x resource is missing from |image| or is the incorrect size, | 56 // If 2x resource is missing from |image| or is the incorrect size, |
| 57 // logs the resource id and creates a 2x version of the resource. | 57 // logs the resource id and creates a 2x version of the resource. |
| 58 // Blends the created resource with red to make it distinguishable from | 58 // Blends the created resource with red to make it distinguishable from |
| 59 // bitmaps in the resource pak. | 59 // bitmaps in the resource pak. |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 if (gfx::Screen::IsDIPEnabled()) { | 319 if (gfx::Screen::IsDIPEnabled()) { |
| 320 scale_factor = GetActualScaleFactor(image_skia, *bitmap, | 320 scale_factor = GetActualScaleFactor(image_skia, *bitmap, |
| 321 data_packs_[i]->GetScaleFactor()); | 321 data_packs_[i]->GetScaleFactor()); |
| 322 } else { | 322 } else { |
| 323 scale_factor = ui::SCALE_FACTOR_100P; | 323 scale_factor = ui::SCALE_FACTOR_100P; |
| 324 } | 324 } |
| 325 image_skia.AddRepresentation(gfx::ImageSkiaRep(*bitmap, scale_factor)); | 325 image_skia.AddRepresentation(gfx::ImageSkiaRep(*bitmap, scale_factor)); |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 if (image_skia.empty()) { | 329 if (image_skia.isNull()) { |
| 330 LOG(WARNING) << "Unable to load image with id " << resource_id; | 330 LOG(WARNING) << "Unable to load image with id " << resource_id; |
| 331 NOTREACHED(); // Want to assert in debug mode. | 331 NOTREACHED(); // Want to assert in debug mode. |
| 332 // The load failed to retrieve the image; show a debugging red square. | 332 // The load failed to retrieve the image; show a debugging red square. |
| 333 return GetEmptyImage(); | 333 return GetEmptyImage(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 Create2xResourceIfMissing(image_skia, resource_id); | 336 Create2xResourceIfMissing(image_skia, resource_id); |
| 337 | 337 |
| 338 image = gfx::Image(image_skia); | 338 image = gfx::Image(image_skia); |
| 339 } | 339 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 SkBitmap bitmap; | 565 SkBitmap bitmap; |
| 566 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32, 32); | 566 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32, 32); |
| 567 bitmap.allocPixels(); | 567 bitmap.allocPixels(); |
| 568 bitmap.eraseARGB(255, 255, 0, 0); | 568 bitmap.eraseARGB(255, 255, 0, 0); |
| 569 empty_image_ = gfx::Image(bitmap); | 569 empty_image_ = gfx::Image(bitmap); |
| 570 } | 570 } |
| 571 return empty_image_; | 571 return empty_image_; |
| 572 } | 572 } |
| 573 | 573 |
| 574 } // namespace ui | 574 } // namespace ui |
| OLD | NEW |