blob: 2fec3d5d4381f74406fc8acf2aca10d23e8822b9 [file] [log] [blame]
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/layout.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
namespace ui {
float GetScaleFactorForNativeView(gfx::NativeView view) {
// A number of unit tests do not setup the screen.
if (!display::Screen::GetScreen())
return 1.0f;
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestView(view);
// GetDisplayNearestView() may return null Display if the |view| is not shown
// on the screen and there is no primary display. In that case use scale
// factor 1.0.
if (!display.is_valid())
return 1.0f;
return display.device_scale_factor();
}
} // namespace ui