diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-14 05:21:24 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-14 05:21:24 +0000 |
commit | dea5e7688fd74d358377d6d31089feaa4c07bc63 (patch) | |
tree | e5c071647e6cbb004c556bce1b3806837c698fb1 /content | |
parent | 168a841c741eaa8438abecfb6677c8de454b38eb (diff) | |
download | chromium_src-dea5e7688fd74d358377d6d31089feaa4c07bc63.zip chromium_src-dea5e7688fd74d358377d6d31089feaa4c07bc63.tar.gz chromium_src-dea5e7688fd74d358377d6d31089feaa4c07bc63.tar.bz2 |
mac: Make dynamic DPI changes work.
This fixes the software case completely, and makes everything
look good on the hardware path after a few frames. In the
hardware path, the IOSurfaces aren't tagged with their own DPI,
so they are rendered at the wrong scale for a few frames, until
the "DPI changed" message made it from the browser to the
renderer.
This CL adds three things that happen in response to DPI changes:
1.) It reallocates the browser-side BackingStoreMac at the new DPI.
2.) It lets the renderer do a full repaint after DPI changed.
3.) It passes the new DPI on to WebKit (in render_view_impl.cc)
(3) won't have an effect for hardware pages until
https://bugs.webkit.org/show_bug.cgi?id=88916 lands.
BUG=128267
TEST=change from lodpi and hidpi and back, check that software- and
hardware-rendered pages look good after the change in both foreground
and background tabs.
Review URL: https://chromiumcodereview.appspot.com/10548026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142099 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/renderer_host/backing_store_mac.h | 3 | ||||
-rw-r--r-- | content/browser/renderer_host/backing_store_mac.mm | 22 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_mac.mm | 36 | ||||
-rw-r--r-- | content/renderer/render_view_impl.cc | 6 | ||||
-rw-r--r-- | content/renderer/render_view_impl.h | 1 | ||||
-rw-r--r-- | content/renderer/render_widget.cc | 11 | ||||
-rw-r--r-- | content/renderer/render_widget.h | 2 |
7 files changed, 72 insertions, 9 deletions
diff --git a/content/browser/renderer_host/backing_store_mac.h b/content/browser/renderer_host/backing_store_mac.h index 17f3e2f..4037071 100644 --- a/content/browser/renderer_host/backing_store_mac.h +++ b/content/browser/renderer_host/backing_store_mac.h @@ -27,6 +27,9 @@ class BackingStoreMac : public BackingStore { // corresponding Cocoa view has not been inserted into an NSWindow yet. CGContextRef cg_bitmap() { return cg_bitmap_; } + // Called when the view's backing scale factor changes. + void ScaleFactorChanged(float device_scale_factor); + // BackingStore implementation. virtual size_t MemorySize() OVERRIDE; virtual void PaintToBackingStore( diff --git a/content/browser/renderer_host/backing_store_mac.mm b/content/browser/renderer_host/backing_store_mac.mm index 326e0d4..ebc0c0d 100644 --- a/content/browser/renderer_host/backing_store_mac.mm +++ b/content/browser/renderer_host/backing_store_mac.mm @@ -41,6 +41,28 @@ BackingStoreMac::BackingStoreMac(content::RenderWidgetHost* widget, BackingStoreMac::~BackingStoreMac() { } +void BackingStoreMac::ScaleFactorChanged(float device_scale_factor) { + if (device_scale_factor == device_scale_factor_) + return; + + device_scale_factor_ = device_scale_factor; + + base::mac::ScopedCFTypeRef<CGLayerRef> new_layer(CreateCGLayer()); + // If we have a layer, copy the old contents. A pixelated flash is better + // than a white flash. + if (new_layer && cg_layer_) { + CGContextRef layer = CGLayerGetContext(new_layer); + CGContextDrawLayerAtPoint(layer, CGPointMake(0, 0), cg_layer_); + } + + cg_layer_.swap(new_layer); + if (!cg_layer_) { + // The view isn't in a window yet. Use a CGBitmapContext for now. + cg_bitmap_.reset(CreateCGBitmapContext()); + CGContextScaleCTM(cg_bitmap_, device_scale_factor_, device_scale_factor_); + } +} + size_t BackingStoreMac::MemorySize() { return size().Scale(device_scale_factor_).GetArea() * 4; } diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index 7a95ba3..d0e675c 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -159,6 +159,7 @@ float ScaleFactor(NSView* view) { - (void)cancelChildPopups; - (void)windowDidChangeBackingProperties:(NSNotification*)notification; - (void)checkForPluginImeCancellation; +- (void)updateTabBackingStoreScaleFactor; @end // NSEvent subtype for scroll gestures events. @@ -399,6 +400,10 @@ void RenderWidgetHostViewMac::DidBecomeSelected() { 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; @@ -820,8 +825,6 @@ bool RenderWidgetHostViewMac::IsPopup() const { BackingStore* RenderWidgetHostViewMac::AllocBackingStore( const gfx::Size& size) { - // TODO(thakis): Register for backing scale factor change events and pass - // that on. float scale = ScaleFactor(cocoa_view_); return new BackingStoreMac(render_widget_host_, size, scale); } @@ -1890,6 +1893,20 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { } } +- (void)updateTabBackingStoreScaleFactor { + if (!renderWidgetHostView_->render_widget_host_) + return; + + float scaleFactor = ScaleFactor(self); + BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( + renderWidgetHostView_->render_widget_host_->GetBackingStore(false)); + if (backingStore) // NULL in hardware path. + backingStore->ScaleFactorChanged(scaleFactor); + + renderWidgetHostView_->render_widget_host_->SetDeviceScaleFactor( + scaleFactor); +} + // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//apple_ref/doc/uid/TP40012302-CH10-SW4 - (void)windowDidChangeBackingProperties:(NSNotification*)notification { NSWindow* window = (NSWindow*)[notification object]; @@ -1899,11 +1916,16 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey]) doubleValue]; if (newBackingScaleFactor != oldBackingScaleFactor) { - // TODO(thakis): Tell backing store about new DPI, schedule repaint. - if (renderWidgetHostView_->render_widget_host_) { - renderWidgetHostView_->render_widget_host_->SetDeviceScaleFactor( - newBackingScaleFactor); - } + // Background tabs check if their scale factor changed when they become + // active, in DidBecomeSelected(). + + // Allocating a CGLayerRef with the current scale factor immediately from + // this handler doesn't work. Schedule the backing store update on the + // next runloop cycle, then things are read for CGLayerRef allocations to + // work. + [self performSelector:@selector(updateTabBackingStoreScaleFactor) + withObject:nil + afterDelay:0]; } } diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 3882d2f..3d29c1d 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -5329,6 +5329,12 @@ void RenderViewImpl::OnImeConfirmComposition( } } +void RenderViewImpl::OnSetDeviceScaleFactor(float device_scale_factor) { + RenderWidget::OnSetDeviceScaleFactor(device_scale_factor); + if (webview()) + webview()->setDeviceScaleFactor(device_scale_factor); +} + ui::TextInputType RenderViewImpl::GetTextInputType() { return pepper_delegate_.IsPluginFocused() ? pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType(); diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index 62559f43..f240194 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -753,6 +753,7 @@ class RenderViewImpl : public RenderWidget, int selection_end) OVERRIDE; virtual void OnImeConfirmComposition( const string16& text, const ui::Range& replacement_range) OVERRIDE; + virtual void OnSetDeviceScaleFactor(float device_scale_factor) OVERRIDE; virtual ui::TextInputType GetTextInputType() OVERRIDE; virtual void GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) OVERRIDE; virtual void GetCompositionCharacterBounds( diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc index af69bf1..12cad67 100644 --- a/content/renderer/render_widget.cc +++ b/content/renderer/render_widget.cc @@ -1490,7 +1490,16 @@ void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { } void RenderWidget::OnSetDeviceScaleFactor(float device_scale_factor) { - // TODO(thakis): Set device_scale_factor_, possibly trigger a repaint. + if (device_scale_factor_ == device_scale_factor) + return; + + device_scale_factor_ = device_scale_factor; + + if (!is_accelerated_compositing_active_) { + didInvalidateRect(gfx::Rect(size_.width(), size_.height())); + } else { + scheduleComposite(); + } } void RenderWidget::OnSetTextDirection(WebTextDirection direction) { diff --git a/content/renderer/render_widget.h b/content/renderer/render_widget.h index 5b6d07f..6411374 100644 --- a/content/renderer/render_widget.h +++ b/content/renderer/render_widget.h @@ -254,7 +254,7 @@ class CONTENT_EXPORT RenderWidget const gfx::Size& page_size, const gfx::Size& desired_size); void OnMsgRepaint(const gfx::Size& size_to_paint); - void OnSetDeviceScaleFactor(float device_scale_factor); + virtual void OnSetDeviceScaleFactor(float device_scale_factor); void OnSetTextDirection(WebKit::WebTextDirection direction); void OnGetFPS(); |