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

Unified Diff: ui/gfx/win/dpi.cc

Issue 672673005: Remove IsHighDPIEnabled, move EnableHighDPISupport to only place it's used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dpi-cleanup-5
Patch Set: rebase-6 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
« no previous file with comments | « ui/gfx/win/dpi.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/win/dpi.cc
diff --git a/ui/gfx/win/dpi.cc b/ui/gfx/win/dpi.cc
index a9352a817acfaf05221f9d0d4e96cf690657e4aa..6ea9ba829688f2c9d03cdc1a24bd9fa581f1139d 100644
--- a/ui/gfx/win/dpi.cc
+++ b/ui/gfx/win/dpi.cc
@@ -6,8 +6,6 @@
#include <windows.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"
@@ -20,16 +18,6 @@ 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() {
@@ -41,67 +29,6 @@ float GetUnforcedDeviceScaleFactor() {
static_cast<float>(kDefaultDPIX);
}
-// Duplicated from Win8.1 SDK ShellScalingApi.h
-typedef enum PROCESS_DPI_AWARENESS {
- PROCESS_DPI_UNAWARE = 0,
- PROCESS_SYSTEM_DPI_AWARE = 1,
- PROCESS_PER_MONITOR_DPI_AWARE = 2
-} PROCESS_DPI_AWARENESS;
-
-typedef enum MONITOR_DPI_TYPE {
- MDT_EFFECTIVE_DPI = 0,
- MDT_ANGULAR_DPI = 1,
- MDT_RAW_DPI = 2,
- MDT_DEFAULT = MDT_EFFECTIVE_DPI
-} MONITOR_DPI_TYPE;
-
-// Win8.1 supports monitor-specific DPI scaling.
-bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) {
- typedef BOOL(WINAPI *SetProcessDpiAwarenessPtr)(PROCESS_DPI_AWARENESS);
- SetProcessDpiAwarenessPtr set_process_dpi_awareness_func =
- reinterpret_cast<SetProcessDpiAwarenessPtr>(
- GetProcAddress(GetModuleHandleA("user32.dll"),
- "SetProcessDpiAwarenessInternal"));
- if (set_process_dpi_awareness_func) {
- HRESULT hr = set_process_dpi_awareness_func(value);
- if (SUCCEEDED(hr)) {
- VLOG(1) << "SetProcessDpiAwareness succeeded.";
- return true;
- } else if (hr == E_ACCESSDENIED) {
- LOG(ERROR) << "Access denied error from SetProcessDpiAwareness. "
- "Function called twice, or manifest was used.";
- }
- }
- return false;
-}
-
-// This function works for Windows Vista through Win8. Win8.1 must use
-// SetProcessDpiAwareness[Wrapper]
-BOOL SetProcessDPIAwareWrapper() {
- typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID);
- SetProcessDPIAwarePtr set_process_dpi_aware_func =
- reinterpret_cast<SetProcessDPIAwarePtr>(
- GetProcAddress(GetModuleHandleA("user32.dll"),
- "SetProcessDPIAware"));
- return set_process_dpi_aware_func &&
- 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 {
@@ -129,47 +56,19 @@ Size GetDPI() {
}
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() {
- // 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);
- return value != 0;
-}
-
-void EnableHighDPISupport() {
- if (IsHighDPIEnabled() &&
- !SetProcessDpiAwarenessWrapper(PROCESS_SYSTEM_DPI_AWARE)) {
- SetProcessDPIAwareWrapper();
+ 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;
}
namespace win {
-GFX_EXPORT const wchar_t kRegistryProfilePath[] =
- L"Software\\Google\\Chrome\\Profile";
-GFX_EXPORT const wchar_t kHighDPISupportW[] = L"high-dpi-support";
-
Point ScreenToDIPPoint(const Point& pixel_point) {
return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDPIScale()));
}
@@ -208,9 +107,5 @@ int GetSystemMetricsInDIP(int metric) {
return static_cast<int>(GetSystemMetrics(metric) / GetDPIScale() + 0.5);
}
-bool IsDeviceScaleFactorSet() {
- return g_device_scale_factor != 0.0f;
-}
-
} // namespace win
} // namespace gfx
« no previous file with comments | « ui/gfx/win/dpi.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698