Skip to content

Commit

Permalink
Simplify calls for scale factor
Browse files Browse the repository at this point in the history
Made callsites simpler by replacing multiple commands
with one api |ui::GetScaleFactorForNativeView(gfx::NativeView)|.
Android got further simpler by |ViewAndroid::GetDipScale()|

BUG=699891

Review-Url: https://codereview.chromium.org/2739113002
Cr-Commit-Position: refs/heads/master@{#456560}
  • Loading branch information
JinsukKim authored and Commit bot committed Mar 14, 2017
1 parent 57c3485 commit 61bc73e
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "services/ui/public/cpp/gpu/context_provider_command_buffer.h"
#include "ui/aura/mus/window_port_mus.h"
#include "ui/aura/window.h"
#include "ui/display/screen.h"
#include "ui/base/layout.h"
#include "ui/gfx/geometry/dip_util.h"

namespace content {
Expand Down Expand Up @@ -50,9 +50,8 @@ cc::BeginFrameSource* MusBrowserCompositorOutputSurface::GetBeginFrameSource() {
void MusBrowserCompositorOutputSurface::SwapBuffers(
cc::OutputSurfaceFrame frame) {
cc::CompositorFrame ui_frame;
ui_frame.metadata.device_scale_factor = display::Screen::GetScreen()
->GetDisplayNearestWindow(window_)
.device_scale_factor();
ui_frame.metadata.device_scale_factor =
ui::GetScaleFactorForNativeView(window_);
ui_frame.metadata.latency_info = std::move(frame.latency_info);
// Reset latency_info to known empty state after moving contents.
frame.latency_info.clear();
Expand Down
15 changes: 6 additions & 9 deletions content/browser/renderer_host/render_widget_host_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,9 @@ gfx::Size RenderWidgetHostViewAndroid::GetPhysicalBackingSize() const {
if (!content_view_core_) {
if (default_bounds_.IsEmpty()) return gfx::Size();

return gfx::Size(default_bounds_.right()
* ui::GetScaleFactorForNativeView(GetNativeView()),
default_bounds_.bottom()
* ui::GetScaleFactorForNativeView(GetNativeView()));
float scale_factor = view_.GetDipScale();
return gfx::Size(default_bounds_.right() * scale_factor,
default_bounds_.bottom() * scale_factor);
}

return content_view_core_->GetPhysicalBackingSize();
Expand Down Expand Up @@ -1300,8 +1299,7 @@ RenderWidgetHostViewAndroid::CreateDrawable() {
content_view_core_->GetContext();
return std::unique_ptr<ui::TouchHandleDrawable>(
new CompositedTouchHandleDrawable(
content_view_core_->GetViewAndroid()->GetLayer(),
ui::GetScaleFactorForNativeView(GetNativeView()),
content_view_core_->GetViewAndroid()->GetLayer(), view_.GetDipScale(),
// Use the activity context where possible (instead of the application
// context) to ensure proper handle theming.
activityContext.is_null() ? base::android::GetApplicationContext()
Expand Down Expand Up @@ -1376,7 +1374,7 @@ void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated(
frame_metadata.top_controls_height *
frame_metadata.top_controls_shown_ratio));

float dip_scale = ui::GetScaleFactorForNativeView(GetNativeView());
float dip_scale = view_.GetDipScale();
float top_controls_pix = frame_metadata.top_controls_height * dip_scale;
float top_shown_pix =
top_controls_pix * frame_metadata.top_controls_shown_ratio;
Expand Down Expand Up @@ -2135,8 +2133,7 @@ void RenderWidgetHostViewAndroid::CreateOverscrollControllerIfPossible() {
return;

overscroll_controller_ = base::MakeUnique<OverscrollControllerAndroid>(
overscroll_refresh_handler, compositor,
ui::GetScaleFactorForNativeView(GetNativeView()));
overscroll_refresh_handler, compositor, view_.GetDipScale());
}

} // namespace content
13 changes: 3 additions & 10 deletions content/browser/renderer_host/render_widget_host_view_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
#include "ui/base/ui_base_types.h"
#include "ui/compositor/compositor_vsync_manager.h"
#include "ui/compositor/dip_util.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/blink/web_input_event.h"
Expand Down Expand Up @@ -439,9 +438,7 @@ void RenderWidgetHostViewAura::InitAsChild(
if (parent_view)
parent_view->AddChild(GetNativeView());

const display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
device_scale_factor_ = display.device_scale_factor();
device_scale_factor_ = ui::GetScaleFactorForNativeView(window_);
}

void RenderWidgetHostViewAura::InitAsPopup(
Expand Down Expand Up @@ -490,9 +487,7 @@ void RenderWidgetHostViewAura::InitAsPopup(

event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this));

const display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
device_scale_factor_ = display.device_scale_factor();
device_scale_factor_ = ui::GetScaleFactorForNativeView(window_);
}

void RenderWidgetHostViewAura::InitAsFullscreen(
Expand All @@ -517,9 +512,7 @@ void RenderWidgetHostViewAura::InitAsFullscreen(
Show();
Focus();

const display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
device_scale_factor_ = display.device_scale_factor();
device_scale_factor_ = ui::GetScaleFactorForNativeView(window_);
}

RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const {
Expand Down
9 changes: 4 additions & 5 deletions content/browser/renderer_host/render_widget_host_view_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "content/browser/renderer_host/text_input_manager.h"
#include "content/common/content_switches_internal.h"
#include "media/base/video_frame.h"
#include "ui/display/display.h"
#include "ui/base/layout.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
Expand Down Expand Up @@ -104,10 +104,9 @@ bool RenderWidgetHostViewBase::GetBackgroundOpaque() {
}

gfx::Size RenderWidgetHostViewBase::GetPhysicalBackingSize() const {
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeView());
return gfx::ScaleToCeiledSize(GetRequestedRendererSize(),
display.device_scale_factor());
return gfx::ScaleToCeiledSize(
GetRequestedRendererSize(),
ui::GetScaleFactorForNativeView(GetNativeView()));
}

bool RenderWidgetHostViewBase::DoBrowserControlsShrinkBlinkSize() const {
Expand Down
3 changes: 0 additions & 3 deletions content/browser/renderer_host/render_widget_host_view_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac

int window_number() const;

// The scale factor for the screen that the view is currently on.
float ViewScaleFactor() const;

// Update properties, such as the scale factor for the backing store
// and for any CALayers, and the screen color profile.
void UpdateBackingStoreProperties();
Expand Down
13 changes: 2 additions & 11 deletions content/browser/renderer_host/render_widget_host_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
#include "ui/base/cocoa/cocoa_base_utils.h"
#import "ui/base/cocoa/fullscreen_window_manager.h"
#import "ui/base/cocoa/underlay_opengl_hosting_window.h"
#include "ui/base/layout.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/display/display.h"
Expand Down Expand Up @@ -689,10 +688,6 @@ new BrowserCompositorMac(this, this, render_widget_host_->is_hidden(),
return [window windowNumber];
}

float RenderWidgetHostViewMac::ViewScaleFactor() const {
return ui::GetScaleFactorForNativeView(cocoa_view_);
}

void RenderWidgetHostViewMac::UpdateDisplayLink() {
static bool is_vsync_disabled =
base::CommandLine::ForCurrentProcess()->HasSwitch(
Expand Down Expand Up @@ -1523,9 +1518,7 @@ new BrowserCompositorMac(this, this, render_widget_host_->is_hidden(),
gfx::Point* transformed_point) {
// The surface hittest happens in device pixels, so we need to convert the
// |point| from DIPs to pixels before hittesting.
float scale_factor = display::Screen::GetScreen()
->GetDisplayNearestWindow(cocoa_view_)
.device_scale_factor();
float scale_factor = ui::GetScaleFactorForNativeView(cocoa_view_);
gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point);
cc::SurfaceId id =
browser_compositor_->GetDelegatedFrameHost()->SurfaceIdAtPoint(
Expand Down Expand Up @@ -1580,9 +1573,7 @@ new BrowserCompositorMac(this, this, render_widget_host_->is_hidden(),
gfx::Point* transformed_point) {
// Transformations use physical pixels rather than DIP, so conversion
// is necessary.
float scale_factor = display::Screen::GetScreen()
->GetDisplayNearestWindow(cocoa_view_)
.device_scale_factor();
float scale_factor = ui::GetScaleFactorForNativeView(cocoa_view_);
gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point);
if (!browser_compositor_->GetDelegatedFrameHost()
->TransformPointToLocalCoordSpace(point_in_pixels, original_surface,
Expand Down
6 changes: 2 additions & 4 deletions ui/aura/mus/window_tree_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_tracker.h"
#include "ui/base/layout.h"
#include "ui/base/ui_base_types.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/dip_util.h"
Expand Down Expand Up @@ -140,9 +140,7 @@ void SetWindowTypeFromProperties(
// Helper function to get the device_scale_factor() of the display::Display
// nearest to |window|.
float ScaleFactorForDisplay(Window* window) {
return display::Screen::GetScreen()
->GetDisplayNearestWindow(window)
.device_scale_factor();
return ui::GetScaleFactorForNativeView(window);
}

void ConvertEventLocationToDip(int64_t display_id, ui::LocatedEvent* event) {
Expand Down
6 changes: 2 additions & 4 deletions ui/aura/window_tree_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ui/aura/window_tree_host_observer.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/base/layout.h"
#include "ui/base/view_prop.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
Expand All @@ -35,10 +36,7 @@ const char kWindowTreeHostForAcceleratedWidget[] =
"__AURA_WINDOW_TREE_HOST_ACCELERATED_WIDGET__";

float GetDeviceScaleFactorFromDisplay(Window* window) {
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window);
DCHECK(display.is_valid());
return display.device_scale_factor();
return ui::GetScaleFactorForNativeView(window);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 2 additions & 5 deletions ui/aura/window_tree_host_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
#include "build/build_config.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_port.h"
#include "ui/base/layout.h"
#include "ui/compositor/compositor.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"

#if defined(OS_ANDROID)
Expand Down Expand Up @@ -134,9 +133,7 @@ void WindowTreeHostPlatform::OnCursorVisibilityChangedNative(bool show) {

void WindowTreeHostPlatform::OnBoundsChanged(const gfx::Rect& new_bounds) {
float current_scale = compositor()->device_scale_factor();
float new_scale = display::Screen::GetScreen()
->GetDisplayNearestWindow(window())
.device_scale_factor();
float new_scale = ui::GetScaleFactorForNativeView(window());
gfx::Rect old_bounds = bounds_;
bounds_ = new_bounds;
if (bounds_.origin() != old_bounds.origin()) {
Expand Down
5 changes: 2 additions & 3 deletions ui/aura/window_tree_host_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/layout.h"
#include "ui/base/platform_window_defaults.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/view_prop.h"
Expand Down Expand Up @@ -403,9 +404,7 @@ void WindowTreeHostX11::SetBoundsInPixels(const gfx::Rect& bounds) {
// Even if the host window's size doesn't change, aura's root window
// size, which is in DIP, changes when the scale changes.
float current_scale = compositor()->device_scale_factor();
float new_scale = display::Screen::GetScreen()
->GetDisplayNearestWindow(window())
.device_scale_factor();
float new_scale = ui::GetScaleFactorForNativeView(window());
bool origin_changed = bounds_.origin() != bounds.origin();
bool size_changed = bounds_.size() != bounds.size();
XWindowChanges changes = {0};
Expand Down
7 changes: 4 additions & 3 deletions ui/base/layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ ScopedSetSupportedScaleFactors::~ScopedSetSupportedScaleFactors() {

#if !defined(OS_MACOSX)
float GetScaleFactorForNativeView(gfx::NativeView view) {
return display::Screen::GetScreen()
->GetDisplayNearestWindow(view)
.device_scale_factor();
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(view);
DCHECK(display.is_valid());
return display.device_scale_factor();
}
#endif // !defined(OS_MACOSX)

Expand Down
5 changes: 4 additions & 1 deletion ui/base/layout_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#include "ui/base/layout.h"

#include <Cocoa/Cocoa.h>
#import <Cocoa/Cocoa.h>

#include "base/mac/sdk_forward_declarations.h"
#include "ui/display/display.h"

namespace {

Expand All @@ -28,6 +29,8 @@ float GetScaleFactorScaleForNativeView(gfx::NativeView view) {
namespace ui {

float GetScaleFactorForNativeView(gfx::NativeView view) {
if (display::Display::HasForceDeviceScaleFactor())
return display::Display::GetForcedDeviceScaleFactor();
return GetScaleFactorScaleForNativeView(view);
}

Expand Down
1 change: 1 addition & 0 deletions ui/snapshot/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include_rules = [
"+ui/android/view_android.h",
"+ui/android/window_android.h",
"+ui/android/window_android_compositor.h",
"+ui/base/layout.h",
"+ui/compositor",
"+ui/display",
"+ui/gfx",
Expand Down
7 changes: 2 additions & 5 deletions ui/snapshot/snapshot_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#include "ui/android/view_android.h"
#include "ui/android/window_android.h"
#include "ui/android/window_android_compositor.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/base/layout.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/snapshot/snapshot_async.h"
Expand Down Expand Up @@ -43,9 +42,7 @@ static void MakeAsyncCopyRequest(
std::unique_ptr<cc::CopyOutputRequest> request =
cc::CopyOutputRequest::CreateBitmapRequest(callback);

const display::Display& display =
display::Screen::GetScreen()->GetDisplayNearestWindow(window);
float scale = display.device_scale_factor();
float scale = ui::GetScaleFactorForNativeView(window);
request->set_area(gfx::ScaleToEnclosingRect(source_rect, scale));
window->GetCompositor()->RequestCopyOfOutputOnRootLayer(std::move(request));
}
Expand Down
10 changes: 3 additions & 7 deletions ui/views/cocoa/bridged_native_widget.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
#include "ui/base/hit_test.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/base/layout.h"
#include "ui/gfx/geometry/dip_util.h"
#import "ui/gfx/mac/coordinate_conversion.h"
#import "ui/gfx/mac/nswindow_frame_controls.h"
#import "ui/native_theme/native_theme_mac.h"
#import "ui/views/cocoa/bridged_content_view.h"
#import "ui/views/cocoa/drag_drop_client_mac.h"
#import "ui/views/cocoa/cocoa_mouse_capture.h"
#import "ui/views/cocoa/cocoa_window_move_loop.h"
#import "ui/views/cocoa/drag_drop_client_mac.h"
#include "ui/views/cocoa/tooltip_manager_mac.h"
#import "ui/views/cocoa/views_nswindow_delegate.h"
#import "ui/views/cocoa/widget_owner_nswindow_adapter.h"
Expand Down Expand Up @@ -111,10 +110,7 @@ - (void)setCurrentProgress:(NSAnimationProgress)progress {
int kWindowPropertiesKey;

float GetDeviceScaleFactorFromView(NSView* view) {
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(view);
DCHECK(display.is_valid());
return display.device_scale_factor();
return ui::GetScaleFactorForNativeView(view);
}

// Returns true if bounds passed to window in SetBounds should be treated as
Expand Down
7 changes: 2 additions & 5 deletions ui/views/drag_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#include "ui/views/drag_utils.h"

#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/base/layout.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/widget/widget.h"
Expand All @@ -16,9 +15,7 @@ float ScaleFactorForDragFromWidget(Widget* widget) {
float device_scale = 1.0f;
if (widget && widget->GetNativeView()) {
gfx::NativeView view = widget->GetNativeView();
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestWindow(view);
device_scale = display.device_scale_factor();
device_scale = ui::GetScaleFactorForNativeView(view);
}
return device_scale;
}
Expand Down
Loading

0 comments on commit 61bc73e

Please sign in to comment.