Chromium Code Reviews| Index: ui/gfx/win/dpi.cc |
| diff --git a/ui/gfx/win/dpi.cc b/ui/gfx/win/dpi.cc |
| index e6855283f1dcd03cddc53d66f3fa44ce0b880779..8dc3effc9fcd66739af052a972784fa1b9e84775 100644 |
| --- a/ui/gfx/win/dpi.cc |
| +++ b/ui/gfx/win/dpi.cc |
| @@ -5,7 +5,12 @@ |
| #include "ui/gfx/win/dpi.h" |
| #include <windows.h> |
| -#include "base/command_line.h" |
| +#include <wrl\implements.h> |
| +#include <wrl\wrappers\corewrappers.h> |
| +#include <windows.foundation.h> |
| +#include <windows.graphics.display.h> |
| +#include "base/command_line.h" |
| +#include "base/win/scoped_com_initializer.h" |
| #include "base/win/scoped_hdc.h" |
| #include "base/win/windows_version.h" |
| #include "base/win/registry.h" |
| @@ -14,6 +19,7 @@ |
| #include "ui/gfx/point_conversions.h" |
| #include "ui/gfx/rect_conversions.h" |
| #include "ui/gfx/size_conversions.h" |
| +#pragma comment(lib, "runtimeobject.lib") |
| namespace { |
| @@ -32,10 +38,44 @@ BOOL IsProcessDPIAwareWrapper() { |
| float g_device_scale_factor = 0.0f; |
| +// TODO: Merge this with implementation in win8/metro_driver/winrt_utils.cc |
| +void CheckHR(HRESULT hr, const char* message) { |
| + if (FAILED(hr)) { |
| + if (message) |
| + PLOG(DFATAL) << message << ", hr = " << std::hex << hr; |
| + else |
| + PLOG(DFATAL) << "COM ERROR" << ", hr = " << std::hex << hr; |
| + } |
| +} |
| + |
| +// TODO: Merge this with implementation in win8/metro_driver/winrt_utils.h |
| +template<unsigned int size, typename T> |
| +HRESULT CreateActivationFactory(wchar_t const (&class_name)[size], T** object) { |
| + Microsoft::WRL::Wrappers::HStringReference ref_class_name(class_name); |
| + return ABI::Windows::Foundation::GetActivationFactory(ref_class_name.Get(), |
| + object); |
| +} |
| + |
| + |
| } // namespace |
| namespace gfx { |
| +float GetModernUIScale() { |
| + base::win::ScopedCOMInitializer com_init; |
| + Microsoft::WRL::ComPtr< |
| + ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> |
| + display_properties; |
| + if (SUCCEEDED(CreateActivationFactory( |
| + RuntimeClass_Windows_Graphics_Display_DisplayProperties, |
| + display_properties.GetAddressOf()))) { |
| + ABI::Windows::Graphics::Display::ResolutionScale resolution_scale; |
| + if (SUCCEEDED(display_properties->get_ResolutionScale(&resolution_scale))) |
| + return static_cast<float>(resolution_scale)/100.0f; |
|
Ben Goodger (Google)
2013/11/20 18:44:36
nit spaces around /
|
| + } |
| + return 1.0f; |
| +} |
| + |
| void InitDeviceScaleFactor(float scale) { |
| DCHECK_NE(0.0f, scale); |
| g_device_scale_factor = scale; |
| @@ -153,7 +193,6 @@ double GetUndocumentedDPIScale() { |
| return scale; |
| } |
| - |
| double GetUndocumentedDPITouchScale() { |
| static double scale = |
| (base::win::GetVersion() < base::win::VERSION_WIN8_1) ? |
| @@ -161,6 +200,5 @@ double GetUndocumentedDPITouchScale() { |
| return scale; |
| } |
| - |
| } // namespace win |
| } // namespace gfx |