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

Unified Diff: ui/gfx/dpi_win.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: constants 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/dpi_win.cc
diff --git a/ui/gfx/win/dpi.cc b/ui/gfx/dpi_win.cc
similarity index 50%
rename from ui/gfx/win/dpi.cc
rename to ui/gfx/dpi_win.cc
index 2777f7cb01235bb838de9c8e7b42343a1f5f2499..a7f6732ae2d3c284cd83e55c7ca65f6fa1d2c368 100644
--- a/ui/gfx/win/dpi.cc
+++ b/ui/gfx/dpi_win.cc
@@ -1,13 +1,15 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/gfx/win/dpi.h"
+#include "ui/gfx/dpi.h"
#include <windows.h>
+
+#include "base/logging.h"
+#include "base/win/registry.h"
#include "base/win/scoped_hdc.h"
#include "base/win/windows_version.h"
-#include "base/win/registry.h"
#include "ui/gfx/display.h"
#include "ui/gfx/point_conversions.h"
#include "ui/gfx/rect_conversions.h"
@@ -15,32 +17,19 @@
namespace {
-int kDefaultDPIX = 96;
-int kDefaultDPIY = 96;
-
-bool force_highdpi_for_testing = false;
-
-BOOL IsProcessDPIAwareWrapper() {
- typedef BOOL(WINAPI *IsProcessDPIAwarePtr)(VOID);
- IsProcessDPIAwarePtr is_process_dpi_aware_func =
- reinterpret_cast<IsProcessDPIAwarePtr>(
- GetProcAddress(GetModuleHandleA("user32.dll"), "IsProcessDPIAware"));
- if (is_process_dpi_aware_func)
- return is_process_dpi_aware_func();
- return FALSE;
-}
-
-float g_device_scale_factor = 0.0f;
-
-float GetUnforcedDeviceScaleFactor() {
- // If the global device scale factor is initialized use it. This is to ensure
- // we use the same scale factor across all callsites. We don't use the
- // GetDeviceScaleFactor function here because it fires a DCHECK if the
- // g_device_scale_factor global is 0.
- if (g_device_scale_factor)
- return g_device_scale_factor;
- return static_cast<float>(gfx::GetDPI().width()) /
- static_cast<float>(kDefaultDPIX);
+DWORD ReadRegistryValue(HKEY root,
+ const wchar_t* base_key,
+ const wchar_t* value_name,
+ DWORD default_value) {
+ base::win::RegKey reg_key(HKEY_CURRENT_USER,
+ base_key,
+ KEY_QUERY_VALUE);
+ DWORD value;
+ if (reg_key.Valid() &&
+ reg_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) {
+ return value;
+ }
+ return default_value;
}
// Duplicated from Win8.1 SDK ShellScalingApi.h
@@ -89,30 +78,10 @@ BOOL SetProcessDPIAwareWrapper() {
set_process_dpi_aware_func();
}
-DWORD ReadRegistryValue(HKEY root,
- const wchar_t* base_key,
- const wchar_t* value_name,
- DWORD default_value) {
- base::win::RegKey reg_key(HKEY_CURRENT_USER,
- base_key,
- KEY_QUERY_VALUE);
- DWORD value;
- if (reg_key.Valid() &&
- reg_key.ReadValueDW(value_name, &value) == ERROR_SUCCESS) {
- return value;
- }
- return default_value;
-}
-
} // namespace
namespace gfx {
-void InitDeviceScaleFactor(float scale) {
- DCHECK_NE(0.0f, scale);
- g_device_scale_factor = scale;
-}
-
Size GetDPI() {
static int dpi_x = 0;
static int dpi_y = 0;
@@ -130,38 +99,20 @@ Size GetDPI() {
return Size(dpi_x, dpi_y);
}
-float GetDPIScale() {
- if (IsHighDPIEnabled()) {
- if (gfx::Display::HasForceDeviceScaleFactor())
- return gfx::Display::GetForcedDeviceScaleFactor();
- float dpi_scale = GetUnforcedDeviceScaleFactor();
- if (dpi_scale <= 1.25) {
- // Force 125% and below to 100% scale. We do this to maintain previous
- // (non-DPI-aware) behavior where only the font size was boosted.
- dpi_scale = 1.0;
- }
- return dpi_scale;
- }
- return 1.0;
-}
-
-void ForceHighDPISupportForTesting(float scale) {
- g_device_scale_factor = scale;
-}
-
bool IsHighDPIEnabled() {
+ static const wchar_t kRegistryProfilePath[] =
+ L"Software\\Google\\Chrome\\Profile";
+ static const wchar_t kHighDPISupportW[] = L"high-dpi-support";
+
// Flag stored in HKEY_CURRENT_USER\SOFTWARE\\Google\\Chrome\\Profile,
// under the DWORD value high-dpi-support.
// Default is disabled.
static DWORD value = ReadRegistryValue(
- HKEY_CURRENT_USER, gfx::win::kRegistryProfilePath,
- gfx::win::kHighDPISupportW, TRUE);
+ HKEY_CURRENT_USER, kRegistryProfilePath, kHighDPISupportW, TRUE);
return value != 0;
}
-bool IsInHighDPIMode() {
- return GetDPIScale() > 1.0;
-}
+namespace win {
void EnableHighDPISupport() {
if (IsHighDPIEnabled() &&
@@ -170,61 +121,10 @@ void EnableHighDPISupport() {
}
}
-namespace win {
-
-GFX_EXPORT const wchar_t kRegistryProfilePath[] =
- L"Software\\Google\\Chrome\\Profile";
-GFX_EXPORT const wchar_t kHighDPISupportW[] = L"high-dpi-support";
-
-float GetDeviceScaleFactor() {
- DCHECK_NE(0.0f, g_device_scale_factor);
- return g_device_scale_factor;
-}
-
-Point ScreenToDIPPoint(const Point& pixel_point) {
- return ToFlooredPoint(ScalePoint(pixel_point,
- 1.0f / GetDeviceScaleFactor()));
-}
-
-Point DIPToScreenPoint(const Point& dip_point) {
- return ToFlooredPoint(ScalePoint(dip_point, GetDeviceScaleFactor()));
-}
-
-Rect ScreenToDIPRect(const Rect& pixel_bounds) {
- // It's important we scale the origin and size separately. If we instead
- // calculated the size from the floored origin and ceiled right the size could
- // vary depending upon where the two points land. That would cause problems
- // for the places this code is used (in particular mapping from native window
- // bounds to DIPs).
- return Rect(ScreenToDIPPoint(pixel_bounds.origin()),
- ScreenToDIPSize(pixel_bounds.size()));
-}
-
-Rect DIPToScreenRect(const Rect& dip_bounds) {
- // See comment in ScreenToDIPRect for why we calculate size like this.
- return Rect(DIPToScreenPoint(dip_bounds.origin()),
- DIPToScreenSize(dip_bounds.size()));
-}
-
-Size ScreenToDIPSize(const Size& size_in_pixels) {
- // Always ceil sizes. Otherwise we may be leaving off part of the bounds.
- return ToCeiledSize(
- ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor()));
-}
-
-Size DIPToScreenSize(const Size& dip_size) {
- // Always ceil sizes. Otherwise we may be leaving off part of the bounds.
- return ToCeiledSize(ScaleSize(dip_size, GetDeviceScaleFactor()));
-}
-
int GetSystemMetricsInDIP(int metric) {
return static_cast<int>(GetSystemMetrics(metric) /
GetDeviceScaleFactor() + 0.5);
}
-bool IsDeviceScaleFactorSet() {
- return g_device_scale_factor != 0.0f;
-}
-
} // namespace win
} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698