Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(780)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 171763002: Refactor device scale factor on Mac and fix CoreAnimation bug (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <QuartzCore/QuartzCore.h> 8 #include <QuartzCore/QuartzCore.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 windowDelegateProtocol, 122 windowDelegateProtocol,
123 @selector(windowDidChangeBackingProperties:), 123 @selector(windowDidChangeBackingProperties:),
124 NO, 124 NO,
125 YES); 125 YES);
126 126
127 // If the protocol does not contain the method, the returned method 127 // If the protocol does not contain the method, the returned method
128 // description is {NULL, NULL} 128 // description is {NULL, NULL}
129 return methodDescription.name != NULL || methodDescription.types != NULL; 129 return methodDescription.name != NULL || methodDescription.types != NULL;
130 } 130 }
131 131
132 static float ScaleFactor(NSView* view) { 132 static float ScaleFactorForView(NSView* view) {
133 return ui::GetImageScale(ui::GetScaleFactorForNativeView(view)); 133 return ui::GetImageScale(ui::GetScaleFactorForNativeView(view));
134 } 134 }
135 135
136 // Private methods: 136 // Private methods:
137 @interface RenderWidgetHostViewCocoa () 137 @interface RenderWidgetHostViewCocoa ()
138 @property(nonatomic, assign) NSRange selectedRange; 138 @property(nonatomic, assign) NSRange selectedRange;
139 @property(nonatomic, assign) NSRange markedRange; 139 @property(nonatomic, assign) NSRange markedRange;
140 140
141 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; 141 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event;
142 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; 142 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r;
143 - (void)gotUnhandledWheelEvent; 143 - (void)gotUnhandledWheelEvent;
144 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; 144 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right;
145 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; 145 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar;
146 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; 146 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv;
147 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; 147 - (void)windowDidChangeBackingProperties:(NSNotification*)notification;
148 - (void)windowChangedGlobalFrame:(NSNotification*)notification; 148 - (void)windowChangedGlobalFrame:(NSNotification*)notification;
149 - (void)drawBackingStore:(BackingStoreMac*)backingStore 149 - (void)drawBackingStore:(BackingStoreMac*)backingStore
150 dirtyRect:(CGRect)dirtyRect 150 dirtyRect:(CGRect)dirtyRect
151 inContext:(CGContextRef)context; 151 inContext:(CGContextRef)context;
152 - (void)updateSoftwareLayerScaleFactor;
153 - (void)checkForPluginImeCancellation; 152 - (void)checkForPluginImeCancellation;
154 - (void)updateTabBackingStoreScaleFactor; 153 - (void)updateTabBackingStoreScaleFactor;
155 - (void)setResponderDelegate: 154 - (void)setResponderDelegate:
156 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; 155 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate;
157 @end 156 @end
158 157
159 // A window subclass that allows the fullscreen window to become main and gain 158 // A window subclass that allows the fullscreen window to become main and gain
160 // keyboard focus. This is only used for pepper flash. Normal fullscreen is 159 // keyboard focus. This is only used for pepper flash. Normal fullscreen is
161 // handled by the browser. 160 // handled by the browser.
162 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow 161 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 last_frame_was_accelerated_(false), 407 last_frame_was_accelerated_(false),
409 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 408 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
410 can_compose_inline_(true), 409 can_compose_inline_(true),
411 compositing_iosurface_layer_async_timer_( 410 compositing_iosurface_layer_async_timer_(
412 FROM_HERE, base::TimeDelta::FromMilliseconds(250), 411 FROM_HERE, base::TimeDelta::FromMilliseconds(250),
413 this, &RenderWidgetHostViewMac::TimerSinceGotAcceleratedFrameFired), 412 this, &RenderWidgetHostViewMac::TimerSinceGotAcceleratedFrameFired),
414 allow_overlapping_views_(false), 413 allow_overlapping_views_(false),
415 use_core_animation_(false), 414 use_core_animation_(false),
416 pending_latency_info_delay_(0), 415 pending_latency_info_delay_(0),
417 pending_latency_info_delay_weak_ptr_factory_(this), 416 pending_latency_info_delay_weak_ptr_factory_(this),
417 backing_store_scale_factor_(1),
418 is_loading_(false), 418 is_loading_(false),
419 weak_factory_(this), 419 weak_factory_(this),
420 fullscreen_parent_host_view_(NULL), 420 fullscreen_parent_host_view_(NULL),
421 underlay_view_has_drawn_(false), 421 underlay_view_has_drawn_(false),
422 overlay_view_weak_factory_(this), 422 overlay_view_weak_factory_(this),
423 software_frame_weak_ptr_factory_(this) { 423 software_frame_weak_ptr_factory_(this) {
424 software_frame_manager_.reset(new SoftwareFrameManager( 424 software_frame_manager_.reset(new SoftwareFrameManager(
425 software_frame_weak_ptr_factory_.GetWeakPtr())); 425 software_frame_weak_ptr_factory_.GetWeakPtr()));
426 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| 426 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_|
427 // goes away. Since we autorelease it, our caller must put 427 // goes away. Since we autorelease it, our caller must put
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 // not use explicit setView and clearDrawable calls. 484 // not use explicit setView and clearDrawable calls.
485 ClearBoundContextDrawable(); 485 ClearBoundContextDrawable();
486 486
487 software_layer_.reset([[CALayer alloc] init]); 487 software_layer_.reset([[CALayer alloc] init]);
488 if (!software_layer_) 488 if (!software_layer_)
489 LOG(ERROR) << "Failed to create CALayer for software rendering"; 489 LOG(ERROR) << "Failed to create CALayer for software rendering";
490 [software_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; 490 [software_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)];
491 [software_layer_ setDelegate:cocoa_view_]; 491 [software_layer_ setDelegate:cocoa_view_];
492 [software_layer_ setContentsGravity:kCAGravityTopLeft]; 492 [software_layer_ setContentsGravity:kCAGravityTopLeft];
493 [software_layer_ setFrame:NSRectToCGRect([cocoa_view_ bounds])]; 493 [software_layer_ setFrame:NSRectToCGRect([cocoa_view_ bounds])];
494 if ([software_layer_ respondsToSelector:@selector(setContentsScale:)])
495 [software_layer_ setContentsScale:backing_store_scale_factor_];
494 [software_layer_ setNeedsDisplay]; 496 [software_layer_ setNeedsDisplay];
495 [cocoa_view_ updateSoftwareLayerScaleFactor];
496 497
497 [cocoa_view_ setLayer:software_layer_]; 498 [cocoa_view_ setLayer:software_layer_];
498 [cocoa_view_ setWantsLayer:YES]; 499 [cocoa_view_ setWantsLayer:YES];
499
500 if (compositing_iosurface_) {
ccameron 2014/02/19 00:52:05 This block was a remnant from when dynamically ena
501 if (!CreateCompositedIOSurfaceLayer()) {
502 LOG(ERROR) << "Failed to create CALayer for existing IOSurface";
503 GotAcceleratedCompositingError();
504 return;
505 }
506 }
507 } 500 }
508 501
509 bool RenderWidgetHostViewMac::CreateCompositedIOSurface() { 502 bool RenderWidgetHostViewMac::CreateCompositedIOSurface() {
510 int current_window_number = use_core_animation_ ? 503 int current_window_number = use_core_animation_ ?
511 CompositingIOSurfaceContext::kOffscreenContextWindowNumber : 504 CompositingIOSurfaceContext::kOffscreenContextWindowNumber :
512 window_number(); 505 window_number();
513 bool new_surface_needed = !compositing_iosurface_; 506 bool new_surface_needed = !compositing_iosurface_;
514 bool new_context_needed = 507 bool new_context_needed =
515 !compositing_iosurface_context_ || 508 !compositing_iosurface_context_ ||
516 (compositing_iosurface_context_ && 509 (compositing_iosurface_context_ &&
(...skipping 27 matching lines...) Expand all
544 if (!compositing_iosurface_) { 537 if (!compositing_iosurface_) {
545 LOG(ERROR) << "Failed to create CompositingIOSurface"; 538 LOG(ERROR) << "Failed to create CompositingIOSurface";
546 return false; 539 return false;
547 } 540 }
548 } 541 }
549 542
550 return true; 543 return true;
551 } 544 }
552 545
553 bool RenderWidgetHostViewMac::CreateCompositedIOSurfaceLayer() { 546 bool RenderWidgetHostViewMac::CreateCompositedIOSurfaceLayer() {
554 CHECK(compositing_iosurface_context_ && compositing_iosurface_);
555 if (compositing_iosurface_layer_ || !use_core_animation_) 547 if (compositing_iosurface_layer_ || !use_core_animation_)
556 return true; 548 return true;
557 549
558 ScopedCAActionDisabler disabler; 550 ScopedCAActionDisabler disabler;
559 551
560 // Create the GL CoreAnimation layer. 552 // Create the GL CoreAnimation layer.
561 if (!compositing_iosurface_layer_) { 553 if (!compositing_iosurface_layer_) {
562 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc] 554 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc]
563 initWithRenderWidgetHostViewMac:this]); 555 initWithRenderWidgetHostViewMac:this]);
564 if (!compositing_iosurface_layer_) { 556 if (!compositing_iosurface_layer_) {
565 LOG(ERROR) << "Failed to create CALayer for IOSurface"; 557 LOG(ERROR) << "Failed to create CALayer for IOSurface";
566 return false; 558 return false;
567 } 559 }
568 [software_layer_ addSublayer:compositing_iosurface_layer_]; 560 [software_layer_ addSublayer:compositing_iosurface_layer_];
569 } 561 }
570 562
571 // Creating the CompositingIOSurfaceLayer may attempt to draw in setLayer, 563 // Creating the CompositingIOSurfaceLayer may attempt to draw in setLayer,
572 // which, if it fails, will promptly tear down everything that was just 564 // which, if it fails, will promptly tear down everything that was just
573 // created. If that happened, return failure. 565 // created. If that happened, return failure.
574 return compositing_iosurface_context_ && 566 return compositing_iosurface_layer_;
575 compositing_iosurface_ &&
576 (compositing_iosurface_layer_ || !use_core_animation_);
577 } 567 }
578 568
579 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceAndLayer( 569 void RenderWidgetHostViewMac::DestroyCompositedIOSurfaceAndLayer(
580 DestroyContextBehavior destroy_context_behavior) { 570 DestroyContextBehavior destroy_context_behavior) {
581 // Any pending frames will not be displayed, so ack them now. 571 // Any pending frames will not be displayed, so ack them now.
582 SendPendingSwapAck(); 572 SendPendingSwapAck();
583 573
584 ScopedCAActionDisabler disabler; 574 ScopedCAActionDisabler disabler;
585 575
586 compositing_iosurface_.reset(); 576 compositing_iosurface_.reset();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 pepper_fullscreen_window_.reset(); 710 pepper_fullscreen_window_.reset();
721 } 711 }
722 712
723 int RenderWidgetHostViewMac::window_number() const { 713 int RenderWidgetHostViewMac::window_number() const {
724 NSWindow* window = [cocoa_view_ window]; 714 NSWindow* window = [cocoa_view_ window];
725 if (!window) 715 if (!window)
726 return -1; 716 return -1;
727 return [window windowNumber]; 717 return [window windowNumber];
728 } 718 }
729 719
730 float RenderWidgetHostViewMac::scale_factor() const { 720 float RenderWidgetHostViewMac::ViewScaleFactor() const {
731 return ScaleFactor(cocoa_view_); 721 return ScaleFactorForView(cocoa_view_);
722 }
723
724 void RenderWidgetHostViewMac::UpdateBackingStoreScaleFactor() {
725 if (!render_widget_host_)
726 return;
727
728 float new_scale_factor = ScaleFactorForView(cocoa_view_);
729 if (new_scale_factor == backing_store_scale_factor_)
730 return;
731 backing_store_scale_factor_ = new_scale_factor;
732
733 BackingStoreMac* backing_store = static_cast<BackingStoreMac*>(
734 render_widget_host_->GetBackingStore(false));
735 if (backing_store)
736 backing_store->ScaleFactorChanged(backing_store_scale_factor_);
737
738 ScopedCAActionDisabler disabler;
739
740 if ([software_layer_ respondsToSelector:@selector(setContentsScale:)])
741 [software_layer_ setContentsScale:backing_store_scale_factor_];
742
743 // Dynamically calling setContentsScale on a CAOpenGLLayer for which
744 // setAsynchronous is dynamically toggled can result in flashes of corrupt
745 // content. Work around this by replacing the entire layer when the scale
746 // factor changes.
747 if (compositing_iosurface_layer_) {
748 [compositing_iosurface_layer_ disableCompositing];
749 compositing_iosurface_layer_.reset();
750 CreateCompositedIOSurfaceLayer();
751 }
752
753 render_widget_host_->NotifyScreenInfoChanged();
732 } 754 }
733 755
734 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { 756 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const {
735 return render_widget_host_; 757 return render_widget_host_;
736 } 758 }
737 759
738 void RenderWidgetHostViewMac::WasShown() { 760 void RenderWidgetHostViewMac::WasShown() {
739 if (!render_widget_host_->is_hidden()) 761 if (!render_widget_host_->is_hidden())
740 return; 762 return;
741 763
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 web_event.type = WebInputEvent::MouseLeave; 1160 web_event.type = WebInputEvent::MouseLeave;
1139 ForwardMouseEvent(web_event); 1161 ForwardMouseEvent(web_event);
1140 } 1162 }
1141 1163
1142 bool RenderWidgetHostViewMac::IsPopup() const { 1164 bool RenderWidgetHostViewMac::IsPopup() const {
1143 return popup_type_ != blink::WebPopupTypeNone; 1165 return popup_type_ != blink::WebPopupTypeNone;
1144 } 1166 }
1145 1167
1146 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( 1168 BackingStore* RenderWidgetHostViewMac::AllocBackingStore(
1147 const gfx::Size& size) { 1169 const gfx::Size& size) {
1148 float scale = ScaleFactor(cocoa_view_); 1170 float scale = ScaleFactorForView(cocoa_view_);
1149 return new BackingStoreMac(render_widget_host_, size, scale); 1171 return new BackingStoreMac(render_widget_host_, size, scale);
1150 } 1172 }
1151 1173
1152 void RenderWidgetHostViewMac::CopyFromCompositingSurface( 1174 void RenderWidgetHostViewMac::CopyFromCompositingSurface(
1153 const gfx::Rect& src_subrect, 1175 const gfx::Rect& src_subrect,
1154 const gfx::Size& dst_size, 1176 const gfx::Size& dst_size,
1155 const base::Callback<void(bool, const SkBitmap&)>& callback, 1177 const base::Callback<void(bool, const SkBitmap&)>& callback,
1156 const SkBitmap::Config config) { 1178 const SkBitmap::Config config) {
1157 if (config != SkBitmap::kARGB_8888_Config) { 1179 if (config != SkBitmap::kARGB_8888_Config) {
1158 NOTIMPLEMENTED(); 1180 NOTIMPLEMENTED();
1159 callback.Run(false, SkBitmap()); 1181 callback.Run(false, SkBitmap());
1160 } 1182 }
1161 base::ScopedClosureRunner scoped_callback_runner( 1183 base::ScopedClosureRunner scoped_callback_runner(
1162 base::Bind(callback, false, SkBitmap())); 1184 base::Bind(callback, false, SkBitmap()));
1163 float scale = ScaleFactor(cocoa_view_); 1185 float scale = ScaleFactorForView(cocoa_view_);
1164 gfx::Size dst_pixel_size = gfx::ToFlooredSize( 1186 gfx::Size dst_pixel_size = gfx::ToFlooredSize(
1165 gfx::ScaleSize(dst_size, scale)); 1187 gfx::ScaleSize(dst_size, scale));
1166 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) { 1188 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) {
1167 ignore_result(scoped_callback_runner.Release()); 1189 ignore_result(scoped_callback_runner.Release());
1168 compositing_iosurface_->CopyTo(GetScaledOpenGLPixelRect(src_subrect), 1190 compositing_iosurface_->CopyTo(GetScaledOpenGLPixelRect(src_subrect),
1169 dst_pixel_size, 1191 dst_pixel_size,
1170 callback); 1192 callback);
1171 } else if (software_frame_manager_->HasCurrentFrame()) { 1193 } else if (software_frame_manager_->HasCurrentFrame()) {
1172 gfx::Rect src_pixel_rect = gfx::ToEnclosingRect(gfx::ScaleRect( 1194 gfx::Rect src_pixel_rect = gfx::ToEnclosingRect(gfx::ScaleRect(
1173 src_subrect, 1195 src_subrect,
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 // Un-bind the overlay view's OpenGL context, since its content will be 1483 // Un-bind the overlay view's OpenGL context, since its content will be
1462 // drawn by this context. Not doing this can result in corruption. 1484 // drawn by this context. Not doing this can result in corruption.
1463 // http://crbug.com/330701 1485 // http://crbug.com/330701
1464 overlay_view_->ClearBoundContextDrawable(); 1486 overlay_view_->ClearBoundContextDrawable();
1465 } 1487 }
1466 [compositing_iosurface_context_->nsgl_context() setView:cocoa_view_]; 1488 [compositing_iosurface_context_->nsgl_context() setView:cocoa_view_];
1467 1489
1468 gfx::Rect view_rect(NSRectToCGRect([cocoa_view_ frame])); 1490 gfx::Rect view_rect(NSRectToCGRect([cocoa_view_ frame]));
1469 if (!compositing_iosurface_->DrawIOSurface( 1491 if (!compositing_iosurface_->DrawIOSurface(
1470 compositing_iosurface_context_, view_rect, 1492 compositing_iosurface_context_, view_rect,
1471 scale_factor(), !has_overlay)) { 1493 ViewScaleFactor(), !has_overlay)) {
1472 return false; 1494 return false;
1473 } 1495 }
1474 1496
1475 if (has_overlay) { 1497 if (has_overlay) {
1476 overlay_view_->underlay_view_has_drawn_ = true; 1498 overlay_view_->underlay_view_has_drawn_ = true;
1477 gfx::Rect overlay_view_rect( 1499 gfx::Rect overlay_view_rect(
1478 NSRectToCGRect([overlay_view_->cocoa_view() frame])); 1500 NSRectToCGRect([overlay_view_->cocoa_view() frame]));
1479 overlay_view_rect.set_x(overlay_view_offset_.x()); 1501 overlay_view_rect.set_x(overlay_view_offset_.x());
1480 overlay_view_rect.set_y(view_rect.height() - 1502 overlay_view_rect.set_y(view_rect.height() -
1481 overlay_view_rect.height() - 1503 overlay_view_rect.height() -
1482 overlay_view_offset_.y()); 1504 overlay_view_offset_.y());
1483 if (!overlay_view_->compositing_iosurface_->DrawIOSurface( 1505 if (!overlay_view_->compositing_iosurface_->DrawIOSurface(
1484 compositing_iosurface_context_, overlay_view_rect, 1506 compositing_iosurface_context_, overlay_view_rect,
1485 overlay_view_->scale_factor(), true)) { 1507 overlay_view_->ViewScaleFactor(), true)) {
1486 return false; 1508 return false;
1487 } 1509 }
1488 } 1510 }
1489 1511
1490 SendPendingLatencyInfoToHost(); 1512 SendPendingLatencyInfoToHost();
1491 SendPendingSwapAck(); 1513 SendPendingSwapAck();
1492 return true; 1514 return true;
1493 } 1515 }
1494 1516
1495 void RenderWidgetHostViewMac::GotAcceleratedCompositingError() { 1517 void RenderWidgetHostViewMac::GotAcceleratedCompositingError() {
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 void RenderWidgetHostViewMac::GotAcceleratedFrame() { 1883 void RenderWidgetHostViewMac::GotAcceleratedFrame() {
1862 // Update the host with VSync parametrs. 1884 // Update the host with VSync parametrs.
1863 base::TimeTicks timebase; 1885 base::TimeTicks timebase;
1864 base::TimeDelta interval; 1886 base::TimeDelta interval;
1865 if (compositing_iosurface_context_ && 1887 if (compositing_iosurface_context_ &&
1866 compositing_iosurface_context_->display_link()->GetVSyncParameters( 1888 compositing_iosurface_context_->display_link()->GetVSyncParameters(
1867 &timebase, &interval)) { 1889 &timebase, &interval)) {
1868 render_widget_host_->UpdateVSyncParameters(timebase, interval); 1890 render_widget_host_->UpdateVSyncParameters(timebase, interval);
1869 } 1891 }
1870 1892
1871 // Update the scale factor of the layer to match the scale factor of the
1872 // IOSurface.
1873 [compositing_iosurface_layer_ updateScaleFactor];
1874
1875 if (!last_frame_was_accelerated_) { 1893 if (!last_frame_was_accelerated_) {
1876 last_frame_was_accelerated_ = true; 1894 last_frame_was_accelerated_ = true;
1877 1895
1878 if (!use_core_animation_) { 1896 if (!use_core_animation_) {
1879 // Need to wipe the software view with transparency to expose the GL 1897 // Need to wipe the software view with transparency to expose the GL
1880 // underlay. Invalidate the whole window to do that. 1898 // underlay. Invalidate the whole window to do that.
1881 [cocoa_view_ setNeedsDisplay:YES]; 1899 [cocoa_view_ setNeedsDisplay:YES];
1882 } 1900 }
1883 1901
1884 // Delete software backingstore. 1902 // Delete software backingstore.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 void RenderWidgetHostViewMac::OnStartPluginIme() { 2013 void RenderWidgetHostViewMac::OnStartPluginIme() {
1996 [cocoa_view_ setPluginImeActive:YES]; 2014 [cocoa_view_ setPluginImeActive:YES];
1997 } 2015 }
1998 2016
1999 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( 2017 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect(
2000 const gfx::Rect& rect) { 2018 const gfx::Rect& rect) {
2001 gfx::Rect src_gl_subrect = rect; 2019 gfx::Rect src_gl_subrect = rect;
2002 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); 2020 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom());
2003 2021
2004 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, 2022 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect,
2005 scale_factor())); 2023 ViewScaleFactor()));
2006 } 2024 }
2007 2025
2008 void RenderWidgetHostViewMac::AddPendingLatencyInfo( 2026 void RenderWidgetHostViewMac::AddPendingLatencyInfo(
2009 const std::vector<ui::LatencyInfo>& latency_info) { 2027 const std::vector<ui::LatencyInfo>& latency_info) {
2010 // If a screenshot is being taken when using CoreAnimation, send a few extra 2028 // If a screenshot is being taken when using CoreAnimation, send a few extra
2011 // calls to setNeedsDisplay and wait for their resulting display calls, 2029 // calls to setNeedsDisplay and wait for their resulting display calls,
2012 // before reporting that the frame has reached the screen. 2030 // before reporting that the frame has reached the screen.
2013 if (use_core_animation_) { 2031 if (use_core_animation_) {
2014 bool should_defer = false; 2032 bool should_defer = false;
2015 for (size_t i = 0; i < latency_info.size(); i++) { 2033 for (size_t i = 0; i < latency_info.size(); i++) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { 2120 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r {
2103 self = [super initWithFrame:NSZeroRect]; 2121 self = [super initWithFrame:NSZeroRect];
2104 if (self) { 2122 if (self) {
2105 self.acceptsTouchEvents = YES; 2123 self.acceptsTouchEvents = YES;
2106 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); 2124 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper);
2107 editCommand_helper_->AddEditingSelectorsToClass([self class]); 2125 editCommand_helper_->AddEditingSelectorsToClass([self class]);
2108 2126
2109 renderWidgetHostView_.reset(r); 2127 renderWidgetHostView_.reset(r);
2110 canBeKeyView_ = YES; 2128 canBeKeyView_ = YES;
2111 focusedPluginIdentifier_ = -1; 2129 focusedPluginIdentifier_ = -1;
2112 deviceScaleFactor_ = ScaleFactor(self); 2130 renderWidgetHostView_->backing_store_scale_factor_ =
2131 ScaleFactorForView(self);
2113 2132
2114 // OpenGL support: 2133 // OpenGL support:
2115 if ([self respondsToSelector: 2134 if ([self respondsToSelector:
2116 @selector(setWantsBestResolutionOpenGLSurface:)]) { 2135 @selector(setWantsBestResolutionOpenGLSurface:)]) {
2117 [self setWantsBestResolutionOpenGLSurface:YES]; 2136 [self setWantsBestResolutionOpenGLSurface:YES];
2118 } 2137 }
2119 handlingGlobalFrameDidChange_ = NO; 2138 handlingGlobalFrameDidChange_ = NO;
2120 [[NSNotificationCenter defaultCenter] 2139 [[NSNotificationCenter defaultCenter]
2121 addObserver:self 2140 addObserver:self
2122 selector:@selector(globalFrameDidChange:) 2141 selector:@selector(globalFrameDidChange:)
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
2764 object:newWindow]; 2783 object:newWindow];
2765 [notificationCenter 2784 [notificationCenter
2766 addObserver:self 2785 addObserver:self
2767 selector:@selector(windowChangedGlobalFrame:) 2786 selector:@selector(windowChangedGlobalFrame:)
2768 name:NSWindowDidEndLiveResizeNotification 2787 name:NSWindowDidEndLiveResizeNotification
2769 object:newWindow]; 2788 object:newWindow];
2770 } 2789 }
2771 } 2790 }
2772 2791
2773 - (void)updateTabBackingStoreScaleFactor { 2792 - (void)updateTabBackingStoreScaleFactor {
2774 if (!renderWidgetHostView_->render_widget_host_) 2793 renderWidgetHostView_->UpdateBackingStoreScaleFactor();
2775 return;
2776
2777 float scaleFactor = ScaleFactor(self);
2778 if (scaleFactor == deviceScaleFactor_)
2779 return;
2780 deviceScaleFactor_ = scaleFactor;
2781
2782 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>(
2783 renderWidgetHostView_->render_widget_host_->GetBackingStore(false));
2784 if (backingStore) // NULL in hardware path.
2785 backingStore->ScaleFactorChanged(scaleFactor);
2786
2787 [self updateSoftwareLayerScaleFactor];
2788 renderWidgetHostView_->render_widget_host_->NotifyScreenInfoChanged();
2789 } 2794 }
2790 2795
2791 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a pple_ref/doc/uid/TP40012302-CH10-SW4 2796 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a pple_ref/doc/uid/TP40012302-CH10-SW4
2792 - (void)windowDidChangeBackingProperties:(NSNotification*)notification { 2797 - (void)windowDidChangeBackingProperties:(NSNotification*)notification {
2793 NSWindow* window = (NSWindow*)[notification object]; 2798 NSWindow* window = (NSWindow*)[notification object];
2794 2799
2795 CGFloat newBackingScaleFactor = [window backingScaleFactor]; 2800 CGFloat newBackingScaleFactor = [window backingScaleFactor];
2796 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>( 2801 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>(
2797 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey]) 2802 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey])
2798 doubleValue]; 2803 doubleValue];
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after
4046 return; 4051 return;
4047 4052
4048 currentCursor_.reset([cursor retain]); 4053 currentCursor_.reset([cursor retain]);
4049 [[self window] invalidateCursorRectsForView:self]; 4054 [[self window] invalidateCursorRectsForView:self];
4050 } 4055 }
4051 4056
4052 - (void)popupWindowWillClose:(NSNotification *)notification { 4057 - (void)popupWindowWillClose:(NSNotification *)notification {
4053 renderWidgetHostView_->KillSelf(); 4058 renderWidgetHostView_->KillSelf();
4054 } 4059 }
4055 4060
4056 - (void)updateSoftwareLayerScaleFactor {
4057 if (![renderWidgetHostView_->software_layer_
4058 respondsToSelector:@selector(setContentsScale:)])
4059 return;
4060
4061 ScopedCAActionDisabler disabler;
4062 [renderWidgetHostView_->software_layer_ setContentsScale:deviceScaleFactor_];
4063 }
4064
4065 // Delegate methods for the software CALayer 4061 // Delegate methods for the software CALayer
4066 - (void)drawLayer:(CALayer*)layer 4062 - (void)drawLayer:(CALayer*)layer
4067 inContext:(CGContextRef)context { 4063 inContext:(CGContextRef)context {
4068 TRACE_EVENT0("browser", "CompositingIOSurfaceLayer::drawLayer"); 4064 TRACE_EVENT0("browser", "CompositingIOSurfaceLayer::drawLayer");
4069 4065
4070 DCHECK(renderWidgetHostView_->use_core_animation_); 4066 DCHECK(renderWidgetHostView_->use_core_animation_);
4071 DCHECK([layer isEqual:renderWidgetHostView_->software_layer_]); 4067 DCHECK([layer isEqual:renderWidgetHostView_->software_layer_]);
4072 4068
4073 CGRect clipRect = CGContextGetClipBoundingBox(context); 4069 CGRect clipRect = CGContextGetClipBoundingBox(context);
4074 4070
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4131 return YES; 4127 return YES;
4132 } 4128 }
4133 4129
4134 - (BOOL)isOpaque { 4130 - (BOOL)isOpaque {
4135 if (renderWidgetHostView_->use_core_animation_) 4131 if (renderWidgetHostView_->use_core_animation_)
4136 return YES; 4132 return YES;
4137 return [super isOpaque]; 4133 return [super isOpaque];
4138 } 4134 }
4139 4135
4140 @end 4136 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698