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