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 <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
23 #include "skia/ext/image_operations.h" | 23 #include "skia/ext/image_operations.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/base/layout.h" | 26 #include "ui/base/layout.h" |
27 #include "ui/base/resource/data_pack.h" | 27 #include "ui/base/resource/data_pack.h" |
28 #include "ui/base/ui_base_paths.h" | 28 #include "ui/base/ui_base_paths.h" |
29 #include "ui/base/ui_base_switches.h" | 29 #include "ui/base/ui_base_switches.h" |
30 #include "ui/gfx/codec/jpeg_codec.h" | 30 #include "ui/gfx/codec/jpeg_codec.h" |
31 #include "ui/gfx/codec/png_codec.h" | 31 #include "ui/gfx/codec/png_codec.h" |
| 32 #include "ui/gfx/dpi.h" |
32 #include "ui/gfx/image/image_skia.h" | 33 #include "ui/gfx/image/image_skia.h" |
33 #include "ui/gfx/image/image_skia_source.h" | 34 #include "ui/gfx/image/image_skia_source.h" |
34 #include "ui/gfx/safe_integer_conversions.h" | 35 #include "ui/gfx/safe_integer_conversions.h" |
35 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
36 #include "ui/gfx/size_conversions.h" | 37 #include "ui/gfx/size_conversions.h" |
37 #include "ui/strings/grit/app_locale_settings.h" | 38 #include "ui/strings/grit/app_locale_settings.h" |
38 | 39 |
39 #if defined(OS_ANDROID) | 40 #if defined(OS_ANDROID) |
40 #include "ui/base/resource/resource_bundle_android.h" | 41 #include "ui/base/resource/resource_bundle_android.h" |
41 #endif | 42 #endif |
42 | 43 |
43 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
44 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
45 #include "ui/gfx/platform_font_pango.h" | 46 #include "ui/gfx/platform_font_pango.h" |
46 #endif | 47 #endif |
47 | 48 |
48 #if defined(OS_WIN) | |
49 #include "ui/base/win/dpi_setup.h" | |
50 #include "ui/gfx/win/dpi.h" | |
51 #endif | |
52 | |
53 #if defined(OS_MACOSX) && !defined(OS_IOS) | 49 #if defined(OS_MACOSX) && !defined(OS_IOS) |
54 #include "base/mac/mac_util.h" | 50 #include "base/mac/mac_util.h" |
55 #endif | 51 #endif |
56 | 52 |
57 namespace ui { | 53 namespace ui { |
58 | 54 |
59 namespace { | 55 namespace { |
60 | 56 |
61 // Font sizes relative to base font. | 57 // Font sizes relative to base font. |
62 const int kSmallFontSizeDelta = -1; | 58 const int kSmallFontSizeDelta = -1; |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 375 } |
380 | 376 |
381 gfx::Image image; | 377 gfx::Image image; |
382 if (delegate_) | 378 if (delegate_) |
383 image = delegate_->GetImageNamed(resource_id); | 379 image = delegate_->GetImageNamed(resource_id); |
384 | 380 |
385 if (image.IsEmpty()) { | 381 if (image.IsEmpty()) { |
386 DCHECK(!data_packs_.empty()) << | 382 DCHECK(!data_packs_.empty()) << |
387 "Missing call to SetResourcesDataDLL?"; | 383 "Missing call to SetResourcesDataDLL?"; |
388 | 384 |
389 #if defined(OS_CHROMEOS) || defined(OS_WIN) | 385 #if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_LINUX) |
390 ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor(); | 386 ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor(); |
391 #else | 387 #else |
392 ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P; | 388 ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P; |
393 #endif | 389 #endif |
394 | 390 |
395 // TODO(oshima): Consider reading the image size from png IHDR chunk and | 391 // TODO(oshima): Consider reading the image size from png IHDR chunk and |
396 // skip decoding here and remove #ifdef below. | 392 // skip decoding here and remove #ifdef below. |
397 // ResourceBundle::GetSharedInstance() is destroyed after the | 393 // ResourceBundle::GetSharedInstance() is destroyed after the |
398 // BrowserMainLoop has finished running. |image_skia| is guaranteed to be | 394 // BrowserMainLoop has finished running. |image_skia| is guaranteed to be |
399 // destroyed before the resource bundle is destroyed. | 395 // destroyed before the resource bundle is destroyed. |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 supported_scale_factors.push_back(SCALE_FACTOR_200P); | 615 supported_scale_factors.push_back(SCALE_FACTOR_200P); |
620 } else { | 616 } else { |
621 supported_scale_factors.push_back(SCALE_FACTOR_100P); | 617 supported_scale_factors.push_back(SCALE_FACTOR_100P); |
622 } | 618 } |
623 #elif defined(OS_MACOSX) | 619 #elif defined(OS_MACOSX) |
624 if (base::mac::IsOSLionOrLater()) | 620 if (base::mac::IsOSLionOrLater()) |
625 supported_scale_factors.push_back(SCALE_FACTOR_200P); | 621 supported_scale_factors.push_back(SCALE_FACTOR_200P); |
626 #elif defined(OS_CHROMEOS) | 622 #elif defined(OS_CHROMEOS) |
627 // TODO(oshima): Include 200P only if the device support 200P | 623 // TODO(oshima): Include 200P only if the device support 200P |
628 supported_scale_factors.push_back(SCALE_FACTOR_200P); | 624 supported_scale_factors.push_back(SCALE_FACTOR_200P); |
629 #elif defined(OS_LINUX) && defined(ENABLE_HIDPI) | 625 #elif defined(OS_LINUX) |
630 supported_scale_factors.push_back(SCALE_FACTOR_200P); | 626 supported_scale_factors.push_back(SCALE_FACTOR_200P); |
631 #elif defined(OS_WIN) | 627 #elif defined(OS_WIN) |
632 bool default_to_100P = true; | 628 bool default_to_100P = true; |
633 if (gfx::IsHighDPIEnabled()) { | 629 if (gfx::IsHighDPIEnabled()) { |
634 // On Windows if the dpi scale is greater than 1.25 on high dpi machines | 630 // On Windows if the dpi scale is greater than 1.25 on high dpi machines |
635 // downscaling from 200 percent looks better than scaling up from 100 | 631 // downscaling from 200 percent looks better than scaling up from 100 |
636 // percent. | 632 // percent. |
637 if (gfx::GetDPIScale() > 1.25) { | 633 if (gfx::GetDPIScale() > 1.25) { |
638 supported_scale_factors.push_back(SCALE_FACTOR_200P); | 634 supported_scale_factors.push_back(SCALE_FACTOR_200P); |
639 default_to_100P = false; | 635 default_to_100P = false; |
640 } | 636 } |
641 } | 637 } |
642 if (default_to_100P) | 638 if (default_to_100P) |
643 supported_scale_factors.push_back(SCALE_FACTOR_100P); | 639 supported_scale_factors.push_back(SCALE_FACTOR_100P); |
644 #endif | 640 #endif |
645 ui::SetSupportedScaleFactors(supported_scale_factors); | 641 ui::SetSupportedScaleFactors(supported_scale_factors); |
646 #if defined(OS_WIN) | 642 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
647 // Must be called _after_ supported scale factors are set since it | 643 // Must be called _after_ supported scale factors are set since it |
648 // uses them. | 644 // uses them. |
649 // Don't initialize the device scale factor if it has already been | 645 // Don't initialize the device scale factor if it has already been |
650 // initialized. | 646 // initialized. |
651 if (!gfx::win::IsDeviceScaleFactorSet()) | 647 if (!gfx::IsDeviceScaleFactorSet()) |
652 ui::win::InitDeviceScaleFactor(); | 648 gfx::InitDeviceScaleFactor(gfx::GetDPIScale()); |
653 #endif | 649 #endif |
654 } | 650 } |
655 | 651 |
656 void ResourceBundle::FreeImages() { | 652 void ResourceBundle::FreeImages() { |
657 images_.clear(); | 653 images_.clear(); |
658 } | 654 } |
659 | 655 |
660 void ResourceBundle::AddDataPackFromPathInternal(const base::FilePath& path, | 656 void ResourceBundle::AddDataPackFromPathInternal(const base::FilePath& path, |
661 ScaleFactor scale_factor, | 657 ScaleFactor scale_factor, |
662 bool optional) { | 658 bool optional) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 // static | 855 // static |
860 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 856 bool ResourceBundle::DecodePNG(const unsigned char* buf, |
861 size_t size, | 857 size_t size, |
862 SkBitmap* bitmap, | 858 SkBitmap* bitmap, |
863 bool* fell_back_to_1x) { | 859 bool* fell_back_to_1x) { |
864 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 860 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); |
865 return gfx::PNGCodec::Decode(buf, size, bitmap); | 861 return gfx::PNGCodec::Decode(buf, size, bitmap); |
866 } | 862 } |
867 | 863 |
868 } // namespace ui | 864 } // namespace ui |
OLD | NEW |