Commit 5cb0c01e authored by oshima's avatar oshima Committed by Commit bot

Compute the base dpi from X

X uses 96 as default, and alters the screen size
but it can be overwritten. Compute the dpi from X
to match what gtk sues as base.

Round the dsf to 1 decimals as finer grained value can cause rendering problem than benefit.

Gpu test expectation on nvidia needs to be updated, so mark these tests as failing now.

BUG=485183

Review URL: https://codereview.chromium.org/1136913005

Cr-Commit-Position: refs/heads/master@{#330212}
parent 25f30bbb
......@@ -8,6 +8,7 @@
#include <set>
#include <pango/pango.h>
#include <X11/Xlib.h>
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
......@@ -49,6 +50,7 @@
#include "ui/gfx/image/image.h"
#include "ui/gfx/skbitmap_operations.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/label_button_border.h"
......@@ -378,20 +380,27 @@ gfx::FontRenderParams GetGtkFontRenderParams() {
return params;
}
double GetDPI() {
double GetBaseDPI() {
XDisplay* xdisplay = gfx::GetXDisplay();
int xscreen = DefaultScreen(xdisplay);
return (DisplayHeight(xdisplay, xscreen) * 25.4) /
DisplayHeightMM(xdisplay, xscreen);
}
double GetFontDPI() {
GtkSettings* gtk_settings = gtk_settings_get_default();
CHECK(gtk_settings);
gint gtk_dpi = -1;
g_object_get(gtk_settings, "gtk-xft-dpi", &gtk_dpi, NULL);
// GTK multiplies the DPI by 1024 before storing it.
return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0;
return (gtk_dpi > 0) ? gtk_dpi / 1024.0 : GetBaseDPI();
}
// Queries GTK for its font DPI setting and returns the number of pixels in a
// point.
double GetPixelsInPoint(float device_scale_factor) {
double dpi = GetDPI();
double dpi = GetFontDPI();
// Take device_scale_factor into account — if Chrome already scales the
// entire UI up by 2x, we should not also scale up.
......@@ -1424,10 +1433,9 @@ void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) {
}
float Gtk2UI::GetDeviceScaleFactor() const {
const int kCSSDefaultDPI = 96;
float scale = GetDPI() / kCSSDefaultDPI;
// Round to 2 decimals, e.g. to 1.33.
return roundf(scale * 100) / 100;
float scale = GetFontDPI() / GetBaseDPI();
// Round to 1 decimal, e.g. to 1.4.
return roundf(scale * 10) / 10;
}
} // namespace libgtk2ui
......
......@@ -11,4 +11,6 @@ class PixelExpectations(GpuTestExpectations):
# Sample Usage:
# self.Fail('Pixel.Canvas2DRedBox',
# ['mac', 'amd', ('nvidia', 0x1234)], bug=123)
pass
self.Fail('Pixel.Canvas2DRedBox', bug=485183)
self.Fail('Pixel.CSS3DBlueBox', bug=485183)
self.Fail('Pixel.WebGLGreenTriangle', bug=485183)
......@@ -30,19 +30,19 @@ class PixelTestsPageSet(page_set_module.PageSet):
url='file://../../data/gpu/pixel_canvas2d.html',
name=base_name + '.Canvas2DRedBox',
test_rect=[0, 0, 300, 300],
revision=4,
revision=5,
page_set=self))
self.AddUserStory(PixelTestsPage(
url='file://../../data/gpu/pixel_css3d.html',
name=base_name + '.CSS3DBlueBox',
test_rect=[0, 0, 300, 300],
revision=12,
revision=13,
page_set=self))
self.AddUserStory(PixelTestsPage(
url='file://../../data/gpu/pixel_webgl.html',
name=base_name + '.WebGLGreenTriangle',
test_rect=[0, 0, 300, 300],
revision=9,
revision=10,
page_set=self))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment