Commit 3658ce40 authored by sail@chromium.org's avatar sail@chromium.org

Mac HiDPI: Fix scale factor on external display

On Mac OS 10.8, opening a page on external monitor would cause the page to be rendered at the scale factor of the primary display.

The problem is in RenderViewHostImpl::CreateRenderView. It uses the view to calculate the display scale factor but this doesn't work because the view hasn't been added to a window yet.

My fix is to update the scale factor when -[RenderWidgetHostViewCocoa viewDidMoveToWindow:] is called. This CL also caches the scale factor.

Note, for some reason I can't reproduce the bug on 10.7. On 10.7 the scale factor is also incorrect but for some reason the page is displayed correctly. I'm not sure what's going on.

BUG=138039
TBR=sky

Review URL: https://chromiumcodereview.appspot.com/10837154

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150973 0039d316-1c4b-4281-b951-d872f2087c98
parent 697470f7
......@@ -139,6 +139,9 @@ class RenderWidgetHostViewMacEditCommandHelper;
// recursive globalFrameDidChange protection:
BOOL handlingGlobalFrameDidChange_;
// The scale factor of the display this view is in.
float deviceScaleFactor_;
}
@property(nonatomic, readonly) NSRange selectedRange;
......
......@@ -374,10 +374,6 @@ void RenderWidgetHostViewMac::WasShown() {
if (!is_hidden_)
return;
// Check if the backing scale factor changed while the tab was in the
// background.
[cocoa_view_ updateTabBackingStoreScaleFactor];
if (web_contents_switch_paint_time_.is_null())
web_contents_switch_paint_time_ = base::TimeTicks::Now();
is_hidden_ = false;
......@@ -1469,6 +1465,7 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
renderWidgetHostView_.reset(r);
canBeKeyView_ = YES;
focusedPluginIdentifier_ = -1;
deviceScaleFactor_ = ScaleFactor(self);
// OpenGL support:
if ([self respondsToSelector:
......@@ -2062,6 +2059,10 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
return;
float scaleFactor = ScaleFactor(self);
if (scaleFactor == deviceScaleFactor_)
return;
deviceScaleFactor_ = scaleFactor;
BackingStoreMac* backingStore = static_cast<BackingStoreMac*>(
renderWidgetHostView_->render_widget_host_->GetBackingStore(false));
if (backingStore) // NULL in hardware path.
......@@ -2080,8 +2081,8 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
[[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey])
doubleValue];
if (newBackingScaleFactor != oldBackingScaleFactor) {
// Background tabs check if their scale factor changed when they become
// active, in WasShown().
// Background tabs check if their scale factor changed when they are added
// to a window.
// Allocating a CGLayerRef with the current scale factor immediately from
// this handler doesn't work. Schedule the backing store update on the
......@@ -3020,6 +3021,9 @@ extern NSString *NSTextInputReplacementRangeAttributeName;
}
- (void)viewDidMoveToWindow {
if ([self window])
[self updateTabBackingStoreScaleFactor];
if (canBeKeyView_) {
NSWindow* newWindow = [self window];
// Pointer comparison only, since we don't know if lastWindow_ is still
......
......@@ -17,18 +17,20 @@
namespace {
float GetScaleFactorScaleForNativeView(gfx::NativeView view) {
float scale_factor = 1.0f;
if (NSWindow* window = [view window]) {
if ([window respondsToSelector:@selector(backingScaleFactor)])
return [window backingScaleFactor];
scale_factor = [window userSpaceScaleFactor];
return [window userSpaceScaleFactor];
}
if (NSScreen* screen = [NSScreen mainScreen]) {
if ([screen respondsToSelector:@selector(backingScaleFactor)])
return [screen backingScaleFactor];
return [screen userSpaceScaleFactor];
}
return 1.0f;
NSArray* screens = [NSScreen screens];
if (![screens count])
return 1.0f;
NSScreen* screen = [screens objectAtIndex:0];
if ([screen respondsToSelector:@selector(backingScaleFactor)])
return [screen backingScaleFactor];
return [screen userSpaceScaleFactor];
}
} // namespace
......
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