Commit 828e3c9a authored by Michael Spang's avatar Michael Spang Committed by Commit Bot

chromecast: Tighten up scale factors used for automatic scaling

Rather than allowing arbitrary scales, only allow integer scales and 1.5
(for 1080p). This means we won't apply strange scales that may not work
well when using a non-standard resolution. There's no change for standard
TV resolutions.

Bug: b/117782357
Test: cast_graphics_unittests

Change-Id: Ied44492232fbe7bf61d0d48e99ab5a6038f28031

Reviewed-on: https://chromium-review.googlesource.com/c/1344904
Commit-Queue: Michael Spang <spang@chromium.org>
Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609853}
parent 72f650d9
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chromecast/base/cast_features.h" #include "chromecast/base/cast_features.h"
#include "chromecast/browser/cast_touch_device_manager.h" #include "chromecast/browser/cast_touch_device_manager.h"
#include "chromecast/graphics/cast_display_util.h"
#include "chromecast/graphics/cast_screen.h" #include "chromecast/graphics/cast_screen.h"
#include "chromecast/public/graphics_properties_shlib.h" #include "chromecast/public/graphics_properties_shlib.h"
#include "ui/display/types/display_snapshot.h" #include "ui/display/types/display_snapshot.h"
...@@ -68,17 +69,6 @@ display::Display::Rotation GetRotationFromCommandLine() { ...@@ -68,17 +69,6 @@ display::Display::Rotation GetRotationFromCommandLine() {
return display::Display::ROTATE_0; return display::Display::ROTATE_0;
} }
float GetDeviceScaleFactor(gfx::Size display_resolution) {
// TODO(spang): Look into tightening up the allowed scale factors here
// rather than allowing all scales >= 1.f
int smaller_dimension =
std::min(display_resolution.width(), display_resolution.height());
float ratio = smaller_dimension / 720.f;
if (ratio < 1.f)
return 1.f;
return ratio;
}
gfx::Rect GetScreenBounds(const gfx::Size& size_in_pixels, gfx::Rect GetScreenBounds(const gfx::Size& size_in_pixels,
display::Display::Rotation rotation) { display::Display::Rotation rotation) {
switch (rotation) { switch (rotation) {
......
...@@ -43,6 +43,8 @@ cast_source_set("graphics") { ...@@ -43,6 +43,8 @@ cast_source_set("graphics") {
"accessibility/magnification_controller.h", "accessibility/magnification_controller.h",
"accessibility/partial_magnification_controller.cc", "accessibility/partial_magnification_controller.cc",
"accessibility/partial_magnification_controller.h", "accessibility/partial_magnification_controller.h",
"cast_display_util.cc",
"cast_display_util.h",
"cast_focus_client_aura.cc", "cast_focus_client_aura.cc",
"cast_focus_client_aura.h", "cast_focus_client_aura.h",
"cast_touch_event_gate.cc", "cast_touch_event_gate.cc",
...@@ -116,6 +118,7 @@ if (use_aura && !is_cast_audio_only) { ...@@ -116,6 +118,7 @@ if (use_aura && !is_cast_audio_only) {
sources = [ sources = [
"accessibility/accessibility_focus_ring_controller_unittest.cc", "accessibility/accessibility_focus_ring_controller_unittest.cc",
"accessibility/partial_magnification_controller_unittest.cc", "accessibility/partial_magnification_controller_unittest.cc",
"cast_display_util_unittest.cc",
"cast_focus_client_aura_test.cc", "cast_focus_client_aura_test.cc",
"cast_touch_event_gate_test.cc", "cast_touch_event_gate_test.cc",
"cast_views_test.cc", "cast_views_test.cc",
......
// Copyright 2018 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 "chromecast/graphics/cast_display_util.h"
#include <math.h>
#include <algorithm>
namespace chromecast {
float GetDeviceScaleFactor(const gfx::Size& display_resolution) {
int smaller_dimension =
std::min(display_resolution.width(), display_resolution.height());
float ratio = smaller_dimension / 720.f;
if (ratio >= 2.f)
return floorf(ratio);
if (ratio >= 1.5f)
return 1.5f;
return 1.f;
}
} // namespace chromecast
// Copyright 2018 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.
#ifndef CHROMECAST_GRAPHICS_CAST_DISPLAY_UTIL_H_
#define CHROMECAST_GRAPHICS_CAST_DISPLAY_UTIL_H_
#include "ui/gfx/geometry/size.h"
namespace chromecast {
// Computes the default scale factor for display with given resolution.
//
// Cast applications target 720p; larger resolutions will be scaled up so
// that content fills the screen.
float GetDeviceScaleFactor(const gfx::Size& display_resolution);
} // namespace chromecast
#endif // CHROMECAST_GRAPHICS_CAST_DISPLAY_UTIL_H_
// Copyright 2018 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 "chromecast/graphics/cast_display_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromecast {
TEST(CastDisplayScaleTest, StandardResolutions_16x9) {
const gfx::Size kResolution720p(1280, 720);
const gfx::Size kResolution1080p(1920, 1080);
const gfx::Size kResolution1440p(2560, 1440);
const gfx::Size kResolution2160p(3840, 2160);
const gfx::Size kResolution4320p(7680, 4320);
EXPECT_EQ(1.f, GetDeviceScaleFactor(kResolution720p));
EXPECT_EQ(1.5f, GetDeviceScaleFactor(kResolution1080p));
EXPECT_EQ(2.f, GetDeviceScaleFactor(kResolution1440p));
EXPECT_EQ(3.f, GetDeviceScaleFactor(kResolution2160p));
EXPECT_EQ(6.f, GetDeviceScaleFactor(kResolution4320p));
}
TEST(CastDisplayScaleTest, NonstandardResolutions) {
const gfx::Size kResolutionHomeHub(600, 1024);
EXPECT_EQ(1.f, GetDeviceScaleFactor(kResolutionHomeHub));
}
} // namespace chromecast
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