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

Side by Side Diff: ui/base/resource/resource_bundle.cc

Issue 659883002: Enable hidpi on Linux, refactor a bit on Windows to share Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resource bundle loading Created 6 years, 2 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
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 "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
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
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 supported_scale_factors.push_back(SCALE_FACTOR_200P); 612 supported_scale_factors.push_back(SCALE_FACTOR_200P);
617 } else { 613 } else {
618 supported_scale_factors.push_back(SCALE_FACTOR_100P); 614 supported_scale_factors.push_back(SCALE_FACTOR_100P);
619 } 615 }
620 #elif defined(OS_MACOSX) 616 #elif defined(OS_MACOSX)
621 if (base::mac::IsOSLionOrLater()) 617 if (base::mac::IsOSLionOrLater())
622 supported_scale_factors.push_back(SCALE_FACTOR_200P); 618 supported_scale_factors.push_back(SCALE_FACTOR_200P);
623 #elif defined(OS_CHROMEOS) 619 #elif defined(OS_CHROMEOS)
624 // TODO(oshima): Include 200P only if the device support 200P 620 // TODO(oshima): Include 200P only if the device support 200P
625 supported_scale_factors.push_back(SCALE_FACTOR_200P); 621 supported_scale_factors.push_back(SCALE_FACTOR_200P);
626 #elif defined(OS_LINUX) && defined(ENABLE_HIDPI) 622 #elif defined(OS_LINUX)
627 supported_scale_factors.push_back(SCALE_FACTOR_200P); 623 supported_scale_factors.push_back(SCALE_FACTOR_200P);
628 #elif defined(OS_WIN) 624 #elif defined(OS_WIN)
629 bool default_to_100P = true; 625 bool default_to_100P = true;
630 if (gfx::IsHighDPIEnabled()) { 626 if (gfx::IsHighDPIEnabled()) {
631 // On Windows if the dpi scale is greater than 1.25 on high dpi machines 627 // On Windows if the dpi scale is greater than 1.25 on high dpi machines
632 // downscaling from 200 percent looks better than scaling up from 100 628 // downscaling from 200 percent looks better than scaling up from 100
633 // percent. 629 // percent.
634 if (gfx::GetDPIScale() > 1.25) { 630 if (gfx::GetDPIScale() > 1.25) {
635 supported_scale_factors.push_back(SCALE_FACTOR_200P); 631 supported_scale_factors.push_back(SCALE_FACTOR_200P);
636 default_to_100P = false; 632 default_to_100P = false;
637 } 633 }
638 } 634 }
639 if (default_to_100P) 635 if (default_to_100P)
640 supported_scale_factors.push_back(SCALE_FACTOR_100P); 636 supported_scale_factors.push_back(SCALE_FACTOR_100P);
641 #endif 637 #endif
642 ui::SetSupportedScaleFactors(supported_scale_factors); 638 ui::SetSupportedScaleFactors(supported_scale_factors);
643 #if defined(OS_WIN) 639 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
644 // Must be called _after_ supported scale factors are set since it 640 // Must be called _after_ supported scale factors are set since it
645 // uses them. 641 // uses them.
646 // Don't initialize the device scale factor if it has already been 642 // Don't initialize the device scale factor if it has already been
647 // initialized. 643 // initialized.
648 if (!gfx::win::IsDeviceScaleFactorSet()) 644 if (!gfx::IsDeviceScaleFactorSet())
649 ui::win::InitDeviceScaleFactor(); 645 gfx::InitDeviceScaleFactor(gfx::GetDPIScale());
650 #endif 646 #endif
651 } 647 }
652 648
653 void ResourceBundle::FreeImages() { 649 void ResourceBundle::FreeImages() {
654 images_.clear(); 650 images_.clear();
655 } 651 }
656 652
657 void ResourceBundle::AddDataPackFromPathInternal(const base::FilePath& path, 653 void ResourceBundle::AddDataPackFromPathInternal(const base::FilePath& path,
658 ScaleFactor scale_factor, 654 ScaleFactor scale_factor,
659 bool optional) { 655 bool optional) {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 // static 852 // static
857 bool ResourceBundle::DecodePNG(const unsigned char* buf, 853 bool ResourceBundle::DecodePNG(const unsigned char* buf,
858 size_t size, 854 size_t size,
859 SkBitmap* bitmap, 855 SkBitmap* bitmap,
860 bool* fell_back_to_1x) { 856 bool* fell_back_to_1x) {
861 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); 857 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size);
862 return gfx::PNGCodec::Decode(buf, size, bitmap); 858 return gfx::PNGCodec::Decode(buf, size, bitmap);
863 } 859 }
864 860
865 } // namespace ui 861 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/layout.cc ('k') | ui/base/resource/resource_bundle_unittest.cc » ('j') | ui/gfx/dpi.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698