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

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

Issue 16189012: Add a path to use CALayers to display content (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve again Created 7 years, 6 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 | Annotate | Revision Log
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 #include <QuartzCore/QuartzCore.h> 7 #include <QuartzCore/QuartzCore.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h"
11 #include "base/debug/crash_logging.h" 12 #include "base/debug/crash_logging.h"
12 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/mac/mac_util.h" 15 #include "base/mac/mac_util.h"
15 #include "base/mac/scoped_cftyperef.h" 16 #include "base/mac/scoped_cftyperef.h"
17 #include "base/mac/sdk_forward_declarations.h"
16 #import "base/memory/scoped_nsobject.h" 18 #import "base/memory/scoped_nsobject.h"
17 #include "base/message_loop.h" 19 #include "base/message_loop.h"
18 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
19 #include "base/string_util.h" 21 #include "base/string_util.h"
20 #include "base/stringprintf.h" 22 #include "base/stringprintf.h"
21 #include "base/strings/sys_string_conversions.h" 23 #include "base/strings/sys_string_conversions.h"
22 #include "base/sys_info.h" 24 #include "base/sys_info.h"
23 #include "base/utf_string_conversions.h" 25 #include "base/utf_string_conversions.h"
24 #import "content/browser/accessibility/browser_accessibility_cocoa.h" 26 #import "content/browser/accessibility/browser_accessibility_cocoa.h"
25 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" 27 #include "content/browser/accessibility/browser_accessibility_manager_mac.h"
26 #include "content/browser/renderer_host/backing_store_mac.h" 28 #include "content/browser/renderer_host/backing_store_mac.h"
27 #include "content/browser/renderer_host/backing_store_manager.h" 29 #include "content/browser/renderer_host/backing_store_manager.h"
30 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
31 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
28 #include "content/browser/renderer_host/compositing_iosurface_mac.h" 32 #include "content/browser/renderer_host/compositing_iosurface_mac.h"
29 #include "content/browser/renderer_host/render_view_host_impl.h" 33 #include "content/browser/renderer_host/render_view_host_impl.h"
30 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h" 34 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h"
31 #import "content/browser/renderer_host/text_input_client_mac.h" 35 #import "content/browser/renderer_host/text_input_client_mac.h"
32 #include "content/common/accessibility_messages.h" 36 #include "content/common/accessibility_messages.h"
33 #include "content/common/edit_command.h" 37 #include "content/common/edit_command.h"
34 #include "content/common/gpu/gpu_messages.h" 38 #include "content/common/gpu/gpu_messages.h"
35 #include "content/common/input_messages.h" 39 #include "content/common/input_messages.h"
36 #include "content/common/view_messages.h" 40 #include "content/common/view_messages.h"
37 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" 41 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
38 #include "content/public/browser/browser_thread.h" 42 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/native_web_keyboard_event.h" 43 #include "content/public/browser/native_web_keyboard_event.h"
40 #import "content/public/browser/render_widget_host_view_mac_delegate.h" 44 #import "content/public/browser/render_widget_host_view_mac_delegate.h"
45 #include "content/public/common/content_switches.h"
41 #include "skia/ext/platform_canvas.h" 46 #include "skia/ext/platform_canvas.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
44 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h" 49 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h"
45 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFact ory.h" 50 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFact ory.h"
46 #import "third_party/mozilla/ComplexTextInputPanel.h" 51 #import "third_party/mozilla/ComplexTextInputPanel.h"
52 #include "ui/base/cocoa/animation_utils.h"
47 #import "ui/base/cocoa/fullscreen_window_manager.h" 53 #import "ui/base/cocoa/fullscreen_window_manager.h"
48 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" 54 #import "ui/base/cocoa/underlay_opengl_hosting_window.h"
49 #include "ui/base/keycodes/keyboard_codes.h" 55 #include "ui/base/keycodes/keyboard_codes.h"
50 #include "ui/base/layout.h" 56 #include "ui/base/layout.h"
51 #include "ui/gfx/point.h" 57 #include "ui/gfx/point.h"
52 #include "ui/gfx/rect_conversions.h" 58 #include "ui/gfx/rect_conversions.h"
53 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 59 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
54 #include "ui/gfx/size_conversions.h" 60 #include "ui/gfx/size_conversions.h"
55 #include "ui/surface/io_surface_support_mac.h" 61 #include "ui/surface/io_surface_support_mac.h"
56 #include "webkit/plugins/npapi/webplugin.h" 62 #include "webkit/plugins/npapi/webplugin.h"
(...skipping 16 matching lines...) Expand all
73 // These are not documented, so use only after checking -respondsToSelector:. 79 // These are not documented, so use only after checking -respondsToSelector:.
74 @interface NSApplication (UndocumentedSpeechMethods) 80 @interface NSApplication (UndocumentedSpeechMethods)
75 - (void)speakString:(NSString*)string; 81 - (void)speakString:(NSString*)string;
76 - (void)stopSpeaking:(id)sender; 82 - (void)stopSpeaking:(id)sender;
77 - (BOOL)isSpeaking; 83 - (BOOL)isSpeaking;
78 @end 84 @end
79 85
80 // Declare things that are part of the 10.7 SDK. 86 // Declare things that are part of the 10.7 SDK.
81 #if !defined(MAC_OS_X_VERSION_10_7) || \ 87 #if !defined(MAC_OS_X_VERSION_10_7) || \
82 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 88 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
83 enum {
84 NSEventPhaseNone = 0, // event not associated with a phase.
85 NSEventPhaseBegan = 0x1 << 0,
86 NSEventPhaseStationary = 0x1 << 1,
87 NSEventPhaseChanged = 0x1 << 2,
88 NSEventPhaseEnded = 0x1 << 3,
89 NSEventPhaseCancelled = 0x1 << 4,
90 };
91 typedef NSUInteger NSEventPhase;
92 89
93 @interface NSEvent (LionAPI) 90 @interface NSEvent (LionAPI)
94 - (NSEventPhase)phase; 91 - (NSEventPhase)phase;
95 @end 92 @end
96 93
97 @interface NSWindow (LionAPI) 94 @interface NSWindow (LionAPI)
98 - (CGFloat)backingScaleFactor; 95 - (CGFloat)backingScaleFactor;
99 @end 96 @end
100 97
101 @interface NSView (NSOpenGLSurfaceResolutionLionAPI) 98 @interface NSView (NSOpenGLSurfaceResolutionLionAPI)
102 - (void)setWantsBestResolutionOpenGLSurface:(BOOL)flag; 99 - (void)setWantsBestResolutionOpenGLSurface:(BOOL)flag;
103 @end 100 @end
104 101
105 static NSString* const NSWindowDidChangeBackingPropertiesNotification = 102 static NSString* const NSWindowDidChangeBackingPropertiesNotification =
106 @"NSWindowDidChangeBackingPropertiesNotification"; 103 @"NSWindowDidChangeBackingPropertiesNotification";
107 static NSString* const NSBackingPropertyOldScaleFactorKey = 104 static NSString* const NSBackingPropertyOldScaleFactorKey =
108 @"NSBackingPropertyOldScaleFactorKey"; 105 @"NSBackingPropertyOldScaleFactorKey";
109 // Note: Apple's example code (linked from the comment above 106 // Note: Apple's example code (linked from the comment above
110 // -windowDidChangeBackingProperties:) uses 107 // -windowDidChangeBackingProperties:) uses
111 // @"NSWindowBackingPropertiesChangeOldBackingScaleFactorKey", but that always 108 // @"NSWindowBackingPropertiesChangeOldBackingScaleFactorKey", but that always
112 // returns an old scale of 0. @"NSBackingPropertyOldScaleFactorKey" seems to 109 // returns an old scale of 0. @"NSBackingPropertyOldScaleFactorKey" seems to
113 // work in practice, and it's what's used in Apple's WebKit port 110 // work in practice, and it's what's used in Apple's WebKit port
114 // (WebKit/mac/WebView/WebView.mm). 111 // (WebKit/mac/WebView/WebView.mm).
115 112
116 #endif // 10.7 113 #endif // 10.7
117 114
118
119 static inline int ToWebKitModifiers(NSUInteger flags) { 115 static inline int ToWebKitModifiers(NSUInteger flags) {
120 int modifiers = 0; 116 int modifiers = 0;
121 if (flags & NSControlKeyMask) modifiers |= WebInputEvent::ControlKey; 117 if (flags & NSControlKeyMask) modifiers |= WebInputEvent::ControlKey;
122 if (flags & NSShiftKeyMask) modifiers |= WebInputEvent::ShiftKey; 118 if (flags & NSShiftKeyMask) modifiers |= WebInputEvent::ShiftKey;
123 if (flags & NSAlternateKeyMask) modifiers |= WebInputEvent::AltKey; 119 if (flags & NSAlternateKeyMask) modifiers |= WebInputEvent::AltKey;
124 if (flags & NSCommandKeyMask) modifiers |= WebInputEvent::MetaKey; 120 if (flags & NSCommandKeyMask) modifiers |= WebInputEvent::MetaKey;
125 return modifiers; 121 return modifiers;
126 } 122 }
127 123
128 static float ScaleFactor(NSView* view) { 124 static float ScaleFactor(NSView* view) {
129 return ui::GetScaleFactorScale(ui::GetScaleFactorForNativeView(view)); 125 return ui::GetScaleFactorScale(ui::GetScaleFactorForNativeView(view));
130 } 126 }
131 127
132 // Private methods: 128 // Private methods:
133 @interface RenderWidgetHostViewCocoa () 129 @interface RenderWidgetHostViewCocoa ()
134 @property(nonatomic, assign) NSRange selectedRange; 130 @property(nonatomic, assign) NSRange selectedRange;
135 @property(nonatomic, assign) NSRange markedRange; 131 @property(nonatomic, assign) NSRange markedRange;
136 @property(nonatomic, assign) 132 @property(nonatomic, assign)
137 NSObject<RenderWidgetHostViewMacDelegate>* delegate; 133 NSObject<RenderWidgetHostViewMacDelegate>* delegate;
138 134
139 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; 135 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event;
140 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; 136 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r;
141 - (void)gotUnhandledWheelEvent; 137 - (void)gotUnhandledWheelEvent;
142 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; 138 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right;
143 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; 139 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar;
144 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; 140 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv;
145 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; 141 - (void)windowDidChangeBackingProperties:(NSNotification*)notification;
146 - (void)windowChangedGlobalFrame:(NSNotification*)notification; 142 - (void)windowChangedGlobalFrame:(NSNotification*)notification;
143 - (void)drawBackingStore:(BackingStoreMac*)backingStore
144 dirtyRect:(CGRect)dirtyRect
145 inContext:(CGContextRef)context;
146 - (void)updateSoftwareLayerScaleFactor;
147 - (void)checkForPluginImeCancellation; 147 - (void)checkForPluginImeCancellation;
148 - (void)updateTabBackingStoreScaleFactor; 148 - (void)updateTabBackingStoreScaleFactor;
149 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange 149 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange
150 actualRange:(NSRangePointer)actualRange; 150 actualRange:(NSRangePointer)actualRange;
151 @end 151 @end
152 152
153 // NSEvent subtype for scroll gestures events. 153 // NSEvent subtype for scroll gestures events.
154 static const short kIOHIDEventTypeScroll = 6; 154 static const short kIOHIDEventTypeScroll = 6;
155 155
156 // A window subclass that allows the fullscreen window to become main and gain 156 // A window subclass that allows the fullscreen window to become main and gain
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 // RenderWidgetHostViewMac, public: 359 // RenderWidgetHostViewMac, public:
360 360
361 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) 361 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget)
362 : render_widget_host_(RenderWidgetHostImpl::From(widget)), 362 : render_widget_host_(RenderWidgetHostImpl::From(widget)),
363 about_to_validate_and_paint_(false), 363 about_to_validate_and_paint_(false),
364 call_set_needs_display_in_rect_pending_(false), 364 call_set_needs_display_in_rect_pending_(false),
365 last_frame_was_accelerated_(false), 365 last_frame_was_accelerated_(false),
366 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 366 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
367 can_compose_inline_(true), 367 can_compose_inline_(true),
368 allow_overlapping_views_(false), 368 allow_overlapping_views_(false),
369 use_core_animation_(false),
369 is_loading_(false), 370 is_loading_(false),
370 is_hidden_(false), 371 is_hidden_(false),
371 weak_factory_(this), 372 weak_factory_(this),
372 fullscreen_parent_host_view_(NULL) { 373 fullscreen_parent_host_view_(NULL) {
373 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| 374 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_|
374 // goes away. Since we autorelease it, our caller must put 375 // goes away. Since we autorelease it, our caller must put
375 // |GetNativeView()| into the view hierarchy right after calling us. 376 // |GetNativeView()| into the view hierarchy right after calling us.
376 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] 377 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc]
377 initWithRenderWidgetHostViewMac:this] autorelease]; 378 initWithRenderWidgetHostViewMac:this] autorelease];
379 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseCoreAnimation))
380 EnableCoreAnimation();
378 render_widget_host_->SetView(this); 381 render_widget_host_->SetView(this);
379 } 382 }
380 383
381 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { 384 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() {
382 AckPendingSwapBuffers(); 385 AckPendingSwapBuffers();
383 UnlockMouse(); 386 UnlockMouse();
387
388 // Make sure that the layer doesn't reach into the now-invalid object.
389 compositing_iosurface_.reset();
390 if (compositing_iosurface_layer_)
391 [compositing_iosurface_layer_ disableCompositing];
392 compositing_iosurface_layer_.reset();
393
384 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the 394 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the
385 // RenderWidgetHost does we need to tell it not to hold a stale pointer to 395 // RenderWidgetHost does we need to tell it not to hold a stale pointer to
386 // us. 396 // us.
387 if (render_widget_host_) 397 if (render_widget_host_)
388 render_widget_host_->SetView(NULL); 398 render_widget_host_->SetView(NULL);
389 } 399 }
390 400
391 void RenderWidgetHostViewMac::SetDelegate( 401 void RenderWidgetHostViewMac::SetDelegate(
392 NSObject<RenderWidgetHostViewMacDelegate>* delegate) { 402 NSObject<RenderWidgetHostViewMacDelegate>* delegate) {
393 [cocoa_view_ setDelegate:delegate]; 403 [cocoa_view_ setDelegate:delegate];
394 } 404 }
395 405
396 void RenderWidgetHostViewMac::SetAllowOverlappingViews(bool overlapping) { 406 void RenderWidgetHostViewMac::SetAllowOverlappingViews(bool overlapping) {
407 if (use_core_animation_)
408 return;
397 if (allow_overlapping_views_ == overlapping) 409 if (allow_overlapping_views_ == overlapping)
398 return; 410 return;
399 allow_overlapping_views_ = overlapping; 411 allow_overlapping_views_ = overlapping;
400 [cocoa_view_ setNeedsDisplay:YES]; 412 [cocoa_view_ setNeedsDisplay:YES];
401 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; 413 [[cocoa_view_ window] disableScreenUpdatesUntilFlush];
402 } 414 }
403 415
404 /////////////////////////////////////////////////////////////////////////////// 416 ///////////////////////////////////////////////////////////////////////////////
405 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: 417 // RenderWidgetHostViewMac, RenderWidgetHostView implementation:
406 418
419 void RenderWidgetHostViewMac::EnableCoreAnimation() {
420 if (use_core_animation_)
421 return;
422 use_core_animation_ = true;
423
424 software_layer_.reset([[CALayer alloc] init]);
425 [software_layer_ setDelegate:cocoa_view_];
426 [software_layer_ setAutoresizingMask:kCALayerWidthSizable |
427 kCALayerHeightSizable];
428 [software_layer_ setContentsGravity:kCAGravityTopLeft];
429 [cocoa_view_ updateSoftwareLayerScaleFactor];
430 [cocoa_view_ setLayer:software_layer_];
431 [cocoa_view_ setWantsLayer:YES];
432 }
433
407 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { 434 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) {
408 bool handled = true; 435 bool handled = true;
409 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) 436 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message)
410 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) 437 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged)
411 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) 438 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme)
412 IPC_MESSAGE_UNHANDLED(handled = false) 439 IPC_MESSAGE_UNHANDLED(handled = false)
413 IPC_END_MESSAGE_MAP() 440 IPC_END_MESSAGE_MAP()
414 return handled; 441 return handled;
415 } 442 }
416 443
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 pepper_fullscreen_window_.reset(); 536 pepper_fullscreen_window_.reset();
510 } 537 }
511 538
512 int RenderWidgetHostViewMac::window_number() const { 539 int RenderWidgetHostViewMac::window_number() const {
513 NSWindow* window = [cocoa_view_ window]; 540 NSWindow* window = [cocoa_view_ window];
514 if (!window) 541 if (!window)
515 return -1; 542 return -1;
516 return [window windowNumber]; 543 return [window windowNumber];
517 } 544 }
518 545
546 float RenderWidgetHostViewMac::scale_factor() const {
547 return ScaleFactor(cocoa_view_);
548 }
549
519 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { 550 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const {
520 return render_widget_host_; 551 return render_widget_host_;
521 } 552 }
522 553
523 void RenderWidgetHostViewMac::WasShown() { 554 void RenderWidgetHostViewMac::WasShown() {
524 if (!is_hidden_) 555 if (!is_hidden_)
525 return; 556 return;
526 557
527 if (web_contents_switch_paint_time_.is_null()) 558 if (web_contents_switch_paint_time_.is_null())
528 web_contents_switch_paint_time_ = base::TimeTicks::Now(); 559 web_contents_switch_paint_time_ = base::TimeTicks::Now();
529 is_hidden_ = false; 560 is_hidden_ = false;
530 render_widget_host_->WasShown(); 561 render_widget_host_->WasShown();
531 562
532 // We're messing with the window, so do this to ensure no flashes. 563 // We're messing with the window, so do this to ensure no flashes.
533 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; 564 if (!use_core_animation_)
565 [[cocoa_view_ window] disableScreenUpdatesUntilFlush];
566
567 if (compositing_iosurface_layer_)
568 [compositing_iosurface_layer_ setNeedsDisplay];
534 } 569 }
535 570
536 void RenderWidgetHostViewMac::WasHidden() { 571 void RenderWidgetHostViewMac::WasHidden() {
537 if (is_hidden_) 572 if (is_hidden_)
538 return; 573 return;
539 574
540 // Send ACKs for any pending SwapBuffers (if any) since we won't be displaying 575 // Send ACKs for any pending SwapBuffers (if any) since we won't be displaying
541 // them and the GPU process is waiting. 576 // them and the GPU process is waiting.
542 AckPendingSwapBuffers(); 577 AckPendingSwapBuffers();
543 578
544 // If we receive any more paint messages while we are hidden, we want to 579 // If we receive any more paint messages while we are hidden, we want to
545 // ignore them so we don't re-allocate the backing store. We will paint 580 // ignore them so we don't re-allocate the backing store. We will paint
546 // everything again when we become selected again. 581 // everything again when we become selected again.
547 is_hidden_ = true; 582 is_hidden_ = true;
548 583
549 // If we have a renderer, then inform it that we are being hidden so it can 584 // If we have a renderer, then inform it that we are being hidden so it can
550 // reduce its resource utilization. 585 // reduce its resource utilization.
551 render_widget_host_->WasHidden(); 586 render_widget_host_->WasHidden();
552 587
553 // There can be a transparent flash as this view is removed and the next is 588 // There can be a transparent flash as this view is removed and the next is
554 // added, because of OSX windowing races between displaying the contents of 589 // added, because of OSX windowing races between displaying the contents of
555 // the NSView and its corresponding OpenGL context. 590 // the NSView and its corresponding OpenGL context.
556 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding 591 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding
557 // screen updates until the next tab draws. 592 // screen updates until the next tab draws.
558 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; 593 if (!use_core_animation_)
594 [[cocoa_view_ window] disableScreenUpdatesUntilFlush];
559 595
560 web_contents_switch_paint_time_ = base::TimeTicks(); 596 web_contents_switch_paint_time_ = base::TimeTicks();
561 } 597 }
562 598
563 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { 599 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) {
564 gfx::Rect rect = GetViewBounds(); 600 gfx::Rect rect = GetViewBounds();
565 rect.set_size(size); 601 rect.set_size(size);
566 SetBounds(rect); 602 SetBounds(rect);
567 } 603 }
568 604
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 UnlockMouse(); 676 UnlockMouse();
641 [[cocoa_view_ window] makeFirstResponder:nil]; 677 [[cocoa_view_ window] makeFirstResponder:nil];
642 } 678 }
643 679
644 bool RenderWidgetHostViewMac::HasFocus() const { 680 bool RenderWidgetHostViewMac::HasFocus() const {
645 return [[cocoa_view_ window] firstResponder] == cocoa_view_; 681 return [[cocoa_view_ window] firstResponder] == cocoa_view_;
646 } 682 }
647 683
648 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const { 684 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const {
649 return !!render_widget_host_->GetBackingStore(false) || 685 return !!render_widget_host_->GetBackingStore(false) ||
650 (compositing_iosurface_.get() && compositing_iosurface_->HasIOSurface()); 686 (compositing_iosurface_ && compositing_iosurface_->HasIOSurface());
651 } 687 }
652 688
653 void RenderWidgetHostViewMac::Show() { 689 void RenderWidgetHostViewMac::Show() {
654 [cocoa_view_ setHidden:NO]; 690 [cocoa_view_ setHidden:NO];
655 691
656 WasShown(); 692 WasShown();
657 } 693 }
658 694
659 void RenderWidgetHostViewMac::Hide() { 695 void RenderWidgetHostViewMac::Hide() {
660 [cocoa_view_ setHidden:YES]; 696 [cocoa_view_ setHidden:YES];
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 float scale = ScaleFactor(cocoa_view_); 965 float scale = ScaleFactor(cocoa_view_);
930 return new BackingStoreMac(render_widget_host_, size, scale); 966 return new BackingStoreMac(render_widget_host_, size, scale);
931 } 967 }
932 968
933 void RenderWidgetHostViewMac::CopyFromCompositingSurface( 969 void RenderWidgetHostViewMac::CopyFromCompositingSurface(
934 const gfx::Rect& src_subrect, 970 const gfx::Rect& src_subrect,
935 const gfx::Size& dst_size, 971 const gfx::Size& dst_size,
936 const base::Callback<void(bool, const SkBitmap&)>& callback) { 972 const base::Callback<void(bool, const SkBitmap&)>& callback) {
937 base::ScopedClosureRunner scoped_callback_runner( 973 base::ScopedClosureRunner scoped_callback_runner(
938 base::Bind(callback, false, SkBitmap())); 974 base::Bind(callback, false, SkBitmap()));
939 if (!compositing_iosurface_.get() || 975 if (!compositing_iosurface_ ||
940 !compositing_iosurface_->HasIOSurface()) 976 !compositing_iosurface_->HasIOSurface())
941 return; 977 return;
942 978
943 float scale = ScaleFactor(cocoa_view_); 979 float scale = ScaleFactor(cocoa_view_);
944 gfx::Size dst_pixel_size = gfx::ToFlooredSize( 980 gfx::Size dst_pixel_size = gfx::ToFlooredSize(
945 gfx::ScaleSize(dst_size, scale)); 981 gfx::ScaleSize(dst_size, scale));
946 982
947 scoped_callback_runner.Release(); 983 scoped_callback_runner.Release();
948 984
949 compositing_iosurface_->CopyTo(GetScaledOpenGLPixelRect(src_subrect), 985 compositing_iosurface_->CopyTo(GetScaledOpenGLPixelRect(src_subrect),
950 dst_pixel_size, 986 dst_pixel_size,
951 callback); 987 callback);
952 } 988 }
953 989
954 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( 990 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame(
955 const gfx::Rect& src_subrect, 991 const gfx::Rect& src_subrect,
956 const scoped_refptr<media::VideoFrame>& target, 992 const scoped_refptr<media::VideoFrame>& target,
957 const base::Callback<void(bool)>& callback) { 993 const base::Callback<void(bool)>& callback) {
958 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); 994 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false));
959 if (!render_widget_host_->is_accelerated_compositing_active() || 995 if (!render_widget_host_->is_accelerated_compositing_active() ||
960 !compositing_iosurface_.get() || 996 !compositing_iosurface_ ||
961 !compositing_iosurface_->HasIOSurface()) 997 !compositing_iosurface_->HasIOSurface())
962 return; 998 return;
963 999
964 if (!target) { 1000 if (!target) {
965 NOTREACHED(); 1001 NOTREACHED();
966 return; 1002 return;
967 } 1003 }
968 1004
969 if (target->format() != media::VideoFrame::YV12 && 1005 if (target->format() != media::VideoFrame::YV12 &&
970 target->format() != media::VideoFrame::I420) { 1006 target->format() != media::VideoFrame::I420) {
971 NOTREACHED(); 1007 NOTREACHED();
972 return; 1008 return;
973 } 1009 }
974 1010
975 if (src_subrect.IsEmpty()) 1011 if (src_subrect.IsEmpty())
976 return; 1012 return;
977 1013
978 scoped_callback_runner.Release(); 1014 scoped_callback_runner.Release();
979 compositing_iosurface_->CopyToVideoFrame( 1015 compositing_iosurface_->CopyToVideoFrame(
980 GetScaledOpenGLPixelRect(src_subrect), 1016 GetScaledOpenGLPixelRect(src_subrect),
981 target, 1017 target,
982 callback); 1018 callback);
983 } 1019 }
984 1020
985 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { 1021 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const {
986 return (!render_widget_host_->GetBackingStore(false) && 1022 return (!render_widget_host_->GetBackingStore(false) &&
987 render_widget_host_->is_accelerated_compositing_active() && 1023 render_widget_host_->is_accelerated_compositing_active() &&
988 compositing_iosurface_.get() && 1024 compositing_iosurface_ &&
989 compositing_iosurface_->HasIOSurface()); 1025 compositing_iosurface_->HasIOSurface());
990 } 1026 }
991 1027
992 bool RenderWidgetHostViewMac::CanSubscribeFrame() const { 1028 bool RenderWidgetHostViewMac::CanSubscribeFrame() const {
993 return true; 1029 return true;
994 } 1030 }
995 1031
996 void RenderWidgetHostViewMac::BeginFrameSubscription( 1032 void RenderWidgetHostViewMac::BeginFrameSubscription(
997 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { 1033 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) {
998 frame_subscriber_ = subscriber.Pass(); 1034 frame_subscriber_ = subscriber.Pass();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 const string16& text, int plugin_id) { 1079 const string16& text, int plugin_id) {
1044 if (render_widget_host_) { 1080 if (render_widget_host_) {
1045 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( 1081 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted(
1046 render_widget_host_->GetRoutingID(), text, plugin_id)); 1082 render_widget_host_->GetRoutingID(), text, plugin_id));
1047 } 1083 }
1048 } 1084 }
1049 1085
1050 bool RenderWidgetHostViewMac::CompositorSwapBuffers( 1086 bool RenderWidgetHostViewMac::CompositorSwapBuffers(
1051 uint64 surface_handle, 1087 uint64 surface_handle,
1052 const gfx::Size& size, 1088 const gfx::Size& size,
1053 float scale_factor, 1089 float surface_scale_factor,
1054 const ui::LatencyInfo& latency_info) { 1090 const ui::LatencyInfo& latency_info) {
1055 if (is_hidden_) 1091 if (is_hidden_)
1056 return true; 1092 return true;
1057 1093
1058 NSWindow* window = [cocoa_view_ window]; 1094 NSWindow* window = [cocoa_view_ window];
1059 if (window_number() <= 0) { 1095 if (window_number() <= 0) {
1060 // There is no window to present so capturing during present won't work. 1096 // There is no window to present so capturing during present won't work.
1061 // We check if frame subscriber wants this frame and capture manually. 1097 // We check if frame subscriber wants this frame and capture manually.
1062 if (compositing_iosurface_.get() && frame_subscriber_) { 1098 if (compositing_iosurface_ && frame_subscriber_) {
1063 const base::Time present_time = base::Time::Now(); 1099 const base::Time present_time = base::Time::Now();
1064 scoped_refptr<media::VideoFrame> frame; 1100 scoped_refptr<media::VideoFrame> frame;
1065 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 1101 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
1066 if (frame_subscriber_->ShouldCaptureFrame(present_time, 1102 if (frame_subscriber_->ShouldCaptureFrame(present_time,
1067 &frame, &callback)) { 1103 &frame, &callback)) {
1068 compositing_iosurface_->SetIOSurface( 1104 compositing_iosurface_->SetIOSurface(
1069 surface_handle, size, scale_factor, latency_info); 1105 surface_handle, size, surface_scale_factor, latency_info);
1070 compositing_iosurface_->CopyToVideoFrame( 1106 compositing_iosurface_->CopyToVideoFrame(
1071 gfx::Rect(size), frame, 1107 gfx::Rect(size), frame,
1072 base::Bind(callback, present_time)); 1108 base::Bind(callback, present_time));
1073 return true; 1109 return true;
1074 } 1110 }
1075 } 1111 }
1076 1112
1077 // TODO(shess) If the view does not have a window, or the window 1113 // TODO(shess) If the view does not have a window, or the window
1078 // does not have backing, the IOSurface will log "invalid drawable" 1114 // does not have backing, the IOSurface will log "invalid drawable"
1079 // in -setView:. It is not clear how this code is reached with such 1115 // in -setView:. It is not clear how this code is reached with such
(...skipping 10 matching lines...) Expand all
1090 object_getClassName([window delegate]), 1126 object_getClassName([window delegate]),
1091 object_getClassName([window windowController])); 1127 object_getClassName([window windowController]));
1092 base::debug::SetCrashKeyValue(kCrashKey, value); 1128 base::debug::SetCrashKeyValue(kCrashKey, value);
1093 } 1129 }
1094 1130
1095 return true; 1131 return true;
1096 } 1132 }
1097 1133
1098 bool should_post_notification = false; 1134 bool should_post_notification = false;
1099 if (!compositing_iosurface_) { 1135 if (!compositing_iosurface_) {
1100 compositing_iosurface_.reset( 1136 if (use_core_animation_) {
1101 CompositingIOSurfaceMac::Create(window_number())); 1137 if (!compositing_iosurface_layer_) {
1138 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc]
1139 initWithRenderWidgetHostViewMac:this]);
1140 }
1141 if (!compositing_iosurface_layer_) {
1142 LOG(WARNING) << "Failed to create CALayer for IOSurface";
1143 return true;
1144 }
1145 if (![compositing_iosurface_layer_ ensureContext]) {
1146 LOG(WARNING) << "Failed to create context for IOSurface";
1147 return true;
1148 }
1149 compositing_iosurface_.reset(CompositingIOSurfaceMac::Create(
1150 [compositing_iosurface_layer_ context]));
1151 } else {
1152 compositing_iosurface_.reset(
1153 CompositingIOSurfaceMac::Create(window_number()));
1154 }
1102 should_post_notification = true; 1155 should_post_notification = true;
1103 } 1156 }
1104 1157
1105 if (!compositing_iosurface_) 1158 if (!compositing_iosurface_) {
1159 LOG(WARNING) << "Failed to create CompositingIOSurfaceMac";
1106 return true; 1160 return true;
1161 }
1107 1162
1108 compositing_iosurface_->SetIOSurface( 1163 compositing_iosurface_->SetIOSurface(
1109 surface_handle, size, scale_factor, latency_info); 1164 surface_handle, size, surface_scale_factor, latency_info);
1165
1166 // TODO(ccameron): If we've failed to allocate the GL texture for the
1167 // IOSurface, or basically anything else along the way, we'll just display
1168 // a white out, potentially forever. Instead, kick the renderer back to
1169 // software mode (like a context lost or a GPU process death).
1110 1170
1111 GotAcceleratedFrame(); 1171 GotAcceleratedFrame();
1112 1172
1113 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); 1173 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size));
1114 if (window_size.IsEmpty()) { 1174 if (window_size.IsEmpty()) {
1115 // setNeedsDisplay will never display and we'll never ack if the window is 1175 // setNeedsDisplay will never display and we'll never ack if the window is
1116 // empty, so ack now and don't bother calling setNeedsDisplay below. 1176 // empty, so ack now and don't bother calling setNeedsDisplay below.
1117 return true; 1177 return true;
1118 } 1178 }
1119 1179
1120 // No need to draw the surface if we are inside a drawRect. It will be done 1180 // No need to draw the surface if we are inside a drawRect. It will be done
1121 // later. 1181 // later.
1122 if (!about_to_validate_and_paint_) { 1182 if (!about_to_validate_and_paint_) {
1123 CompositingIOSurfaceMac::SurfaceOrder order = allow_overlapping_views_ ? 1183 if (use_core_animation_) {
1124 CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW : 1184 DCHECK(compositing_iosurface_layer_);
1125 CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW; 1185 [compositing_iosurface_layer_ setNeedsDisplay];
1126 compositing_iosurface_->DrawIOSurface(cocoa_view_, 1186 } else {
1127 ScaleFactor(cocoa_view_), 1187 compositing_iosurface_->DrawIOSurface(this);
1128 window_number(), 1188 }
1129 order,
1130 frame_subscriber_.get());
1131 } 1189 }
1132 1190
1133 if (should_post_notification && [[cocoa_view_ delegate] 1191 if (should_post_notification && [[cocoa_view_ delegate]
1134 respondsToSelector:@selector(compositingIOSurfaceCreated)]) { 1192 respondsToSelector:@selector(compositingIOSurfaceCreated)]) {
1135 [[cocoa_view_ delegate] compositingIOSurfaceCreated]; 1193 [[cocoa_view_ delegate] compositingIOSurfaceCreated];
1136 } 1194 }
1137 1195
1196 // Don't ack the new frame until it is drawn.
1197 if (use_core_animation_)
1198 return false;
1199
1138 return true; 1200 return true;
1139 } 1201 }
1140 1202
1141 void RenderWidgetHostViewMac::AckPendingSwapBuffers() { 1203 void RenderWidgetHostViewMac::AckPendingSwapBuffers() {
1142 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::AckPendingSwapBuffers"); 1204 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::AckPendingSwapBuffers");
1143 while (!pending_swap_buffers_acks_.empty()) { 1205 while (!pending_swap_buffers_acks_.empty()) {
1144 if (pending_swap_buffers_acks_.front().first != 0) { 1206 if (pending_swap_buffers_acks_.front().first != 0) {
1145 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; 1207 AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
1146 ack_params.sync_point = 0; 1208 ack_params.sync_point = 0;
1147 if (compositing_iosurface_) 1209 if (compositing_iosurface_)
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 AckPendingSwapBuffers(); 1402 AckPendingSwapBuffers();
1341 } 1403 }
1342 1404
1343 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { 1405 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() {
1344 if (compositing_iosurface_) 1406 if (compositing_iosurface_)
1345 compositing_iosurface_->UnrefIOSurface(); 1407 compositing_iosurface_->UnrefIOSurface();
1346 } 1408 }
1347 1409
1348 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() { 1410 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() {
1349 compositing_iosurface_.reset(); 1411 compositing_iosurface_.reset();
1412 if (compositing_iosurface_layer_)
1413 [compositing_iosurface_layer_ disableCompositing];
1414 compositing_iosurface_layer_.reset();
1350 } 1415 }
1351 1416
1352 bool RenderWidgetHostViewMac::HasAcceleratedSurface( 1417 bool RenderWidgetHostViewMac::HasAcceleratedSurface(
1353 const gfx::Size& desired_size) { 1418 const gfx::Size& desired_size) {
1354 return last_frame_was_accelerated_ && 1419 return last_frame_was_accelerated_ &&
1355 compositing_iosurface_.get() && 1420 compositing_iosurface_ &&
1356 compositing_iosurface_->HasIOSurface() && 1421 compositing_iosurface_->HasIOSurface() &&
1357 (desired_size.IsEmpty() || 1422 (desired_size.IsEmpty() ||
1358 compositing_iosurface_->dip_io_surface_size() == desired_size); 1423 compositing_iosurface_->dip_io_surface_size() == desired_size);
1359 } 1424 }
1360 1425
1361 void RenderWidgetHostViewMac::AboutToWaitForBackingStoreMsg() { 1426 void RenderWidgetHostViewMac::AboutToWaitForBackingStoreMsg() {
1362 AckPendingSwapBuffers(); 1427 AckPendingSwapBuffers();
1363 } 1428 }
1364 1429
1365 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { 1430 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 } 1508 }
1444 1509
1445 1510
1446 void RenderWidgetHostViewMac::ShutdownHost() { 1511 void RenderWidgetHostViewMac::ShutdownHost() {
1447 weak_factory_.InvalidateWeakPtrs(); 1512 weak_factory_.InvalidateWeakPtrs();
1448 render_widget_host_->Shutdown(); 1513 render_widget_host_->Shutdown();
1449 // Do not touch any members at this point, |this| has been deleted. 1514 // Do not touch any members at this point, |this| has been deleted.
1450 } 1515 }
1451 1516
1452 void RenderWidgetHostViewMac::GotAcceleratedFrame() { 1517 void RenderWidgetHostViewMac::GotAcceleratedFrame() {
1518 // Update the scale factor of the layer to match the scale factor of the
1519 // IOSurface.
1520 if (compositing_iosurface_layer_)
1521 [compositing_iosurface_layer_ updateScaleFactor];
1522
1453 if (!last_frame_was_accelerated_) { 1523 if (!last_frame_was_accelerated_) {
1454 last_frame_was_accelerated_ = true; 1524 last_frame_was_accelerated_ = true;
1455 1525
1456 // Need to wipe the software view with transparency to expose the GL 1526 if (!use_core_animation_) {
1457 // underlay. Invalidate the whole window to do that. 1527 // Need to wipe the software view with transparency to expose the GL
1458 [cocoa_view_ setNeedsDisplay:YES]; 1528 // underlay. Invalidate the whole window to do that.
1529 [cocoa_view_ setNeedsDisplay:YES];
1530 }
1459 1531
1460 // Delete software backingstore. 1532 // Delete software backingstore.
1461 BackingStoreManager::RemoveBackingStore(render_widget_host_); 1533 BackingStoreManager::RemoveBackingStore(render_widget_host_);
1462 } 1534 }
1463 } 1535 }
1464 1536
1465 void RenderWidgetHostViewMac::GotSoftwareFrame() { 1537 void RenderWidgetHostViewMac::GotSoftwareFrame() {
1466 if (last_frame_was_accelerated_) { 1538 if (last_frame_was_accelerated_) {
1467 last_frame_was_accelerated_ = false; 1539 last_frame_was_accelerated_ = false;
1468 1540
1469 AckPendingSwapBuffers(); 1541 AckPendingSwapBuffers();
1470 1542
1471 // Forget IOSurface since we are drawing a software frame now. 1543 // Forget IOSurface since we are drawing a software frame now.
1472 if (compositing_iosurface_.get() && 1544 if (use_core_animation_) {
1473 compositing_iosurface_->HasIOSurface()) { 1545 compositing_iosurface_.reset();
1474 compositing_iosurface_->ClearDrawable(); 1546 if (compositing_iosurface_layer_)
1547 [compositing_iosurface_layer_ disableCompositing];
1548 compositing_iosurface_layer_.reset();
1549 }
1550 else {
1551 if (compositing_iosurface_ &&
1552 compositing_iosurface_->HasIOSurface()) {
1553 compositing_iosurface_->ClearDrawable();
1554 }
1475 } 1555 }
1476 } 1556 }
1477 } 1557 }
1478 1558
1479 void RenderWidgetHostViewMac::SetActive(bool active) { 1559 void RenderWidgetHostViewMac::SetActive(bool active) {
1480 if (render_widget_host_) { 1560 if (render_widget_host_) {
1481 render_widget_host_->SetActive(active); 1561 render_widget_host_->SetActive(active);
1482 if (active) { 1562 if (active) {
1483 if (HasFocus()) 1563 if (HasFocus())
1484 render_widget_host_->Focus(); 1564 render_widget_host_->Focus();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 void RenderWidgetHostViewMac::OnStartPluginIme() { 1664 void RenderWidgetHostViewMac::OnStartPluginIme() {
1585 [cocoa_view_ setPluginImeActive:YES]; 1665 [cocoa_view_ setPluginImeActive:YES];
1586 } 1666 }
1587 1667
1588 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( 1668 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect(
1589 const gfx::Rect& rect) { 1669 const gfx::Rect& rect) {
1590 gfx::Rect src_gl_subrect = rect; 1670 gfx::Rect src_gl_subrect = rect;
1591 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); 1671 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom());
1592 1672
1593 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, 1673 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect,
1594 ScaleFactor(cocoa_view_))); 1674 scale_factor()));
1595 } 1675 }
1596 1676
1597 } // namespace content 1677 } // namespace content
1598 1678
1599 // RenderWidgetHostViewCocoa --------------------------------------------------- 1679 // RenderWidgetHostViewCocoa ---------------------------------------------------
1600 1680
1601 @implementation RenderWidgetHostViewCocoa 1681 @implementation RenderWidgetHostViewCocoa
1602 1682
1603 @synthesize selectedRange = selectedRange_; 1683 @synthesize selectedRange = selectedRange_;
1604 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; 1684 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_;
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2136 const WebMouseWheelEvent& webEvent = 2216 const WebMouseWheelEvent& webEvent =
2137 WebInputEventFactory::mouseWheelEvent(event, self); 2217 WebInputEventFactory::mouseWheelEvent(event, self);
2138 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent); 2218 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent);
2139 } 2219 }
2140 } 2220 }
2141 2221
2142 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { 2222 - (void)viewWillMoveToWindow:(NSWindow*)newWindow {
2143 // We're messing with the window, so do this to ensure no flashes. This one 2223 // We're messing with the window, so do this to ensure no flashes. This one
2144 // prevents a flash when the current tab is closed. 2224 // prevents a flash when the current tab is closed.
2145 NSWindow* oldWindow = [self window]; 2225 NSWindow* oldWindow = [self window];
2146 [oldWindow disableScreenUpdatesUntilFlush]; 2226
2227 if (!renderWidgetHostView_->use_core_animation_)
2228 [oldWindow disableScreenUpdatesUntilFlush];
2147 2229
2148 NSNotificationCenter* notificationCenter = 2230 NSNotificationCenter* notificationCenter =
2149 [NSNotificationCenter defaultCenter]; 2231 [NSNotificationCenter defaultCenter];
2150 if (oldWindow) { 2232 if (oldWindow) {
2151 [notificationCenter 2233 [notificationCenter
2152 removeObserver:self 2234 removeObserver:self
2153 name:NSWindowDidChangeBackingPropertiesNotification 2235 name:NSWindowDidChangeBackingPropertiesNotification
2154 object:oldWindow]; 2236 object:oldWindow];
2155 [notificationCenter 2237 [notificationCenter
2156 removeObserver:self 2238 removeObserver:self
(...skipping 30 matching lines...) Expand all
2187 float scaleFactor = ScaleFactor(self); 2269 float scaleFactor = ScaleFactor(self);
2188 if (scaleFactor == deviceScaleFactor_) 2270 if (scaleFactor == deviceScaleFactor_)
2189 return; 2271 return;
2190 deviceScaleFactor_ = scaleFactor; 2272 deviceScaleFactor_ = scaleFactor;
2191 2273
2192 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( 2274 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>(
2193 renderWidgetHostView_->render_widget_host_->GetBackingStore(false)); 2275 renderWidgetHostView_->render_widget_host_->GetBackingStore(false));
2194 if (backingStore) // NULL in hardware path. 2276 if (backingStore) // NULL in hardware path.
2195 backingStore->ScaleFactorChanged(scaleFactor); 2277 backingStore->ScaleFactorChanged(scaleFactor);
2196 2278
2279 [self updateSoftwareLayerScaleFactor];
2197 renderWidgetHostView_->render_widget_host_->NotifyScreenInfoChanged(); 2280 renderWidgetHostView_->render_widget_host_->NotifyScreenInfoChanged();
2198 } 2281 }
2199 2282
2200 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a pple_ref/doc/uid/TP40012302-CH10-SW4 2283 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a pple_ref/doc/uid/TP40012302-CH10-SW4
2201 - (void)windowDidChangeBackingProperties:(NSNotification*)notification { 2284 - (void)windowDidChangeBackingProperties:(NSNotification*)notification {
2202 NSWindow* window = (NSWindow*)[notification object]; 2285 NSWindow* window = (NSWindow*)[notification object];
2203 2286
2204 CGFloat newBackingScaleFactor = [window backingScaleFactor]; 2287 CGFloat newBackingScaleFactor = [window backingScaleFactor];
2205 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>( 2288 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>(
2206 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey]) 2289 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey])
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 renderWidgetHostView_->render_widget_host_->WasResized(); 2326 renderWidgetHostView_->render_widget_host_->WasResized();
2244 } 2327 }
2245 } 2328 }
2246 2329
2247 - (void)callSetNeedsDisplayInRect { 2330 - (void)callSetNeedsDisplayInRect {
2248 DCHECK([NSThread isMainThread]); 2331 DCHECK([NSThread isMainThread]);
2249 DCHECK(renderWidgetHostView_->call_set_needs_display_in_rect_pending_); 2332 DCHECK(renderWidgetHostView_->call_set_needs_display_in_rect_pending_);
2250 [self setNeedsDisplayInRect:renderWidgetHostView_->invalid_rect_]; 2333 [self setNeedsDisplayInRect:renderWidgetHostView_->invalid_rect_];
2251 renderWidgetHostView_->call_set_needs_display_in_rect_pending_ = false; 2334 renderWidgetHostView_->call_set_needs_display_in_rect_pending_ = false;
2252 renderWidgetHostView_->invalid_rect_ = NSZeroRect; 2335 renderWidgetHostView_->invalid_rect_ = NSZeroRect;
2336
2337 if (renderWidgetHostView_->compositing_iosurface_layer_)
2338 [renderWidgetHostView_->compositing_iosurface_layer_ setNeedsDisplay];
2253 } 2339 }
2254 2340
2255 // Fills with white the parts of the area to the right and bottom for |rect| 2341 // Fills with white the parts of the area to the right and bottom for |rect|
2256 // that intersect |damagedRect|. 2342 // that intersect |damagedRect|.
2257 - (void)fillBottomRightRemainderOfRect:(gfx::Rect)rect 2343 - (void)fillBottomRightRemainderOfRect:(gfx::Rect)rect
2258 dirtyRect:(gfx::Rect)damagedRect { 2344 dirtyRect:(gfx::Rect)damagedRect
2345 inContext:(CGContextRef)context {
2259 if (damagedRect.right() > rect.right()) { 2346 if (damagedRect.right() > rect.right()) {
2260 int x = std::max(rect.right(), damagedRect.x()); 2347 int x = std::max(rect.right(), damagedRect.x());
2261 int y = std::min(rect.bottom(), damagedRect.bottom()); 2348 int y = std::min(rect.bottom(), damagedRect.bottom());
2262 int width = damagedRect.right() - x; 2349 int width = damagedRect.right() - x;
2263 int height = damagedRect.y() - y; 2350 int height = damagedRect.y() - y;
2264 2351
2265 // Extra fun to get around the fact that gfx::Rects can't have 2352 // Extra fun to get around the fact that gfx::Rects can't have
2266 // negative sizes. 2353 // negative sizes.
2267 if (width < 0) { 2354 if (width < 0) {
2268 x += width; 2355 x += width;
2269 width = -width; 2356 width = -width;
2270 } 2357 }
2271 if (height < 0) { 2358 if (height < 0) {
2272 y += height; 2359 y += height;
2273 height = -height; 2360 height = -height;
2274 } 2361 }
2275 2362
2276 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; 2363 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)];
2277 [[NSColor whiteColor] set]; 2364 CGContextSetFillColorWithColor(context,
2278 NSRectFill(r); 2365 CGColorGetConstantColor(kCGColorWhite));
2366 CGContextFillRect(context, NSRectToCGRect(r));
2279 } 2367 }
2280 if (damagedRect.bottom() > rect.bottom()) { 2368 if (damagedRect.bottom() > rect.bottom()) {
2281 int x = damagedRect.x(); 2369 int x = damagedRect.x();
2282 int y = damagedRect.bottom(); 2370 int y = damagedRect.bottom();
2283 int width = damagedRect.right() - x; 2371 int width = damagedRect.right() - x;
2284 int height = std::max(rect.bottom(), damagedRect.y()) - y; 2372 int height = std::max(rect.bottom(), damagedRect.y()) - y;
2285 2373
2286 // Extra fun to get around the fact that gfx::Rects can't have 2374 // Extra fun to get around the fact that gfx::Rects can't have
2287 // negative sizes. 2375 // negative sizes.
2288 if (width < 0) { 2376 if (width < 0) {
2289 x += width; 2377 x += width;
2290 width = -width; 2378 width = -width;
2291 } 2379 }
2292 if (height < 0) { 2380 if (height < 0) {
2293 y += height; 2381 y += height;
2294 height = -height; 2382 height = -height;
2295 } 2383 }
2296 2384
2297 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; 2385 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)];
2298 [[NSColor whiteColor] set]; 2386 CGContextSetFillColorWithColor(context,
2299 NSRectFill(r); 2387 CGColorGetConstantColor(kCGColorWhite));
2388 CGContextFillRect(context, NSRectToCGRect(r));
2300 } 2389 }
2301 } 2390 }
2302 2391
2303 - (void)drawRect:(NSRect)dirtyRect { 2392 - (void)drawRect:(NSRect)dirtyRect {
2304 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); 2393 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect");
2394 DCHECK(!renderWidgetHostView_->use_core_animation_);
2395
2305 if (!renderWidgetHostView_->render_widget_host_) { 2396 if (!renderWidgetHostView_->render_widget_host_) {
2306 // TODO(shess): Consider using something more noticable? 2397 // TODO(shess): Consider using something more noticable?
2307 [[NSColor whiteColor] set]; 2398 [[NSColor whiteColor] set];
2308 NSRectFill(dirtyRect); 2399 NSRectFill(dirtyRect);
2309 return; 2400 return;
2310 } 2401 }
2311 2402
2312 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); 2403 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_);
2313 2404
2314 // GetBackingStore works for both software and accelerated frames. If a 2405 // GetBackingStore works for both software and accelerated frames. If a
2315 // SwapBuffers occurs while GetBackingStore is blocking, we will continue to 2406 // SwapBuffers occurs while GetBackingStore is blocking, we will continue to
2316 // blit the IOSurface below. 2407 // blit the IOSurface below.
2317 renderWidgetHostView_->about_to_validate_and_paint_ = true; 2408 renderWidgetHostView_->about_to_validate_and_paint_ = true;
2318 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( 2409 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>(
2319 renderWidgetHostView_->render_widget_host_->GetBackingStore(true)); 2410 renderWidgetHostView_->render_widget_host_->GetBackingStore(true));
2320 renderWidgetHostView_->about_to_validate_and_paint_ = false; 2411 renderWidgetHostView_->about_to_validate_and_paint_ = false;
2321 2412
2322 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); 2413 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]);
2323 2414
2324 if (renderWidgetHostView_->last_frame_was_accelerated_ && 2415 if (renderWidgetHostView_->last_frame_was_accelerated_ &&
2325 renderWidgetHostView_->compositing_iosurface_.get()) { 2416 renderWidgetHostView_->compositing_iosurface_) {
2326 if (renderWidgetHostView_->allow_overlapping_views_) { 2417 if (renderWidgetHostView_->allow_overlapping_views_) {
2327 // If overlapping views need to be allowed, punch a hole in the window 2418 // If overlapping views need to be allowed, punch a hole in the window
2328 // to expose the GL underlay. 2419 // to expose the GL underlay.
2329 TRACE_EVENT2("gpu", "NSRectFill clear", "w", damagedRect.width(), 2420 TRACE_EVENT2("gpu", "NSRectFill clear", "w", damagedRect.width(),
2330 "h", damagedRect.height()); 2421 "h", damagedRect.height());
2331 // NSRectFill is extremely slow (15ms for a window on a fast MacPro), so 2422 // NSRectFill is extremely slow (15ms for a window on a fast MacPro), so
2332 // this is only done when it's a real invalidation from window damage (not 2423 // this is only done when it's a real invalidation from window damage (not
2333 // when a BuffersSwapped was received). Note that even a 1x1 NSRectFill 2424 // when a BuffersSwapped was received). Note that even a 1x1 NSRectFill
2334 // can take many milliseconds sometimes (!) so this is skipped completely 2425 // can take many milliseconds sometimes (!) so this is skipped completely
2335 // for drawRects that are triggered by BuffersSwapped messages. 2426 // for drawRects that are triggered by BuffersSwapped messages.
2336 [[NSColor clearColor] set]; 2427 [[NSColor clearColor] set];
2337 NSRectFill(dirtyRect); 2428 NSRectFill(dirtyRect);
2338 } 2429 }
2339 2430
2340 content::CompositingIOSurfaceMac::SurfaceOrder order =
2341 renderWidgetHostView_->allow_overlapping_views_
2342 ? content::CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW
2343 : content::CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW;
2344 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( 2431 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(
2345 self, 2432 renderWidgetHostView_.get());
2346 ScaleFactor(self),
2347 renderWidgetHostView_->window_number(),
2348 order,
2349 renderWidgetHostView_->frame_subscriber());
2350 return; 2433 return;
2351 } 2434 }
2352 2435
2436 CGContextRef context = static_cast<CGContextRef>(
2437 [[NSGraphicsContext currentContext] graphicsPort]);
2438 [self drawBackingStore:backingStore
2439 dirtyRect:NSRectToCGRect(dirtyRect)
2440 inContext:context];
2441 }
2442
2443 - (void)drawBackingStore:(BackingStoreMac*)backingStore
2444 dirtyRect:(CGRect)dirtyRect
2445 inContext:(CGContextRef)context {
2353 if (backingStore) { 2446 if (backingStore) {
2354 // Note: All coordinates are in view units, not pixels. 2447 // Note: All coordinates are in view units, not pixels.
2355 gfx::Rect bitmapRect(0, 0, 2448 gfx::Rect bitmapRect(0, 0,
2356 backingStore->size().width(), 2449 backingStore->size().width(),
2357 backingStore->size().height()); 2450 backingStore->size().height());
2358 2451
2359 // Specify the proper y offset to ensure that the view is rooted to the 2452 // Specify the proper y offset to ensure that the view is rooted to the
2360 // upper left corner. This can be negative, if the window was resized 2453 // upper left corner. This can be negative, if the window was resized
2361 // smaller and the renderer hasn't yet repainted. 2454 // smaller and the renderer hasn't yet repainted.
2362 int yOffset = NSHeight([self bounds]) - backingStore->size().height(); 2455 int yOffset = NSHeight([self bounds]) - backingStore->size().height();
2363 2456
2457 NSRect nsDirtyRect = NSRectFromCGRect(dirtyRect);
2458 const gfx::Rect damagedRect([self flipNSRectToRect:nsDirtyRect]);
2459
2364 gfx::Rect paintRect = gfx::IntersectRects(bitmapRect, damagedRect); 2460 gfx::Rect paintRect = gfx::IntersectRects(bitmapRect, damagedRect);
2365 if (!paintRect.IsEmpty()) { 2461 if (!paintRect.IsEmpty()) {
2366 // if we have a CGLayer, draw that into the window 2462 // if we have a CGLayer, draw that into the window
2367 if (backingStore->cg_layer()) { 2463 if (backingStore->cg_layer()) {
2368 CGContextRef context = static_cast<CGContextRef>(
2369 [[NSGraphicsContext currentContext] graphicsPort]);
2370
2371 // TODO: add clipping to dirtyRect if it improves drawing performance. 2464 // TODO: add clipping to dirtyRect if it improves drawing performance.
2372 CGContextDrawLayerAtPoint(context, CGPointMake(0.0, yOffset), 2465 CGContextDrawLayerAtPoint(context, CGPointMake(0.0, yOffset),
2373 backingStore->cg_layer()); 2466 backingStore->cg_layer());
2374 } else { 2467 } else {
2375 // if we haven't created a layer yet, draw the cached bitmap into 2468 // if we haven't created a layer yet, draw the cached bitmap into
2376 // the window. The CGLayer will be created the next time the renderer 2469 // the window. The CGLayer will be created the next time the renderer
2377 // paints. 2470 // paints.
2378 CGContextRef context = static_cast<CGContextRef>(
2379 [[NSGraphicsContext currentContext] graphicsPort]);
2380 base::mac::ScopedCFTypeRef<CGImageRef> image( 2471 base::mac::ScopedCFTypeRef<CGImageRef> image(
2381 CGBitmapContextCreateImage(backingStore->cg_bitmap())); 2472 CGBitmapContextCreateImage(backingStore->cg_bitmap()));
2382 CGRect imageRect = bitmapRect.ToCGRect(); 2473 CGRect imageRect = bitmapRect.ToCGRect();
2383 imageRect.origin.y = yOffset; 2474 imageRect.origin.y = yOffset;
2384 CGContextDrawImage(context, imageRect, image); 2475 CGContextDrawImage(context, imageRect, image);
2385 } 2476 }
2386 } 2477 }
2387 2478
2388 // Fill the remaining portion of the damagedRect with white 2479 // Fill the remaining portion of the damagedRect with white
2389 [self fillBottomRightRemainderOfRect:bitmapRect dirtyRect:damagedRect]; 2480 [self fillBottomRightRemainderOfRect:bitmapRect
2481 dirtyRect:damagedRect
2482 inContext:context];
2390 2483
2391 if (!renderWidgetHostView_->whiteout_start_time_.is_null()) { 2484 if (!renderWidgetHostView_->whiteout_start_time_.is_null()) {
2392 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - 2485 base::TimeDelta whiteout_duration = base::TimeTicks::Now() -
2393 renderWidgetHostView_->whiteout_start_time_; 2486 renderWidgetHostView_->whiteout_start_time_;
2394 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); 2487 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration);
2395 2488
2396 // Reset the start time to 0 so that we start recording again the next 2489 // Reset the start time to 0 so that we start recording again the next
2397 // time the backing store is NULL... 2490 // time the backing store is NULL...
2398 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks(); 2491 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks();
2399 } 2492 }
2400 if (!renderWidgetHostView_->web_contents_switch_paint_time_.is_null()) { 2493 if (!renderWidgetHostView_->web_contents_switch_paint_time_.is_null()) {
2401 base::TimeDelta web_contents_switch_paint_duration = 2494 base::TimeDelta web_contents_switch_paint_duration =
2402 base::TimeTicks::Now() - 2495 base::TimeTicks::Now() -
2403 renderWidgetHostView_->web_contents_switch_paint_time_; 2496 renderWidgetHostView_->web_contents_switch_paint_time_;
2404 UMA_HISTOGRAM_TIMES("MPArch.RWH_TabSwitchPaintDuration", 2497 UMA_HISTOGRAM_TIMES("MPArch.RWH_TabSwitchPaintDuration",
2405 web_contents_switch_paint_duration); 2498 web_contents_switch_paint_duration);
2406 // Reset contents_switch_paint_time_ to 0 so future tab selections are 2499 // Reset contents_switch_paint_time_ to 0 so future tab selections are
2407 // recorded. 2500 // recorded.
2408 renderWidgetHostView_->web_contents_switch_paint_time_ = 2501 renderWidgetHostView_->web_contents_switch_paint_time_ =
2409 base::TimeTicks(); 2502 base::TimeTicks();
2410 } 2503 }
2411 } else { 2504 } else {
2412 [[NSColor whiteColor] set]; 2505 CGContextSetFillColorWithColor(context,
2413 NSRectFill(dirtyRect); 2506 CGColorGetConstantColor(kCGColorWhite));
2507 CGContextFillRect(context, dirtyRect);
2414 if (renderWidgetHostView_->whiteout_start_time_.is_null()) 2508 if (renderWidgetHostView_->whiteout_start_time_.is_null())
2415 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks::Now(); 2509 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks::Now();
2416 } 2510 }
2417 } 2511 }
2418 2512
2419 - (BOOL)canBecomeKeyView { 2513 - (BOOL)canBecomeKeyView {
2420 if (!renderWidgetHostView_->render_widget_host_) 2514 if (!renderWidgetHostView_->render_widget_host_)
2421 return NO; 2515 return NO;
2422 2516
2423 return canBeKeyView_; 2517 return canBeKeyView_;
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
3376 return; 3470 return;
3377 3471
3378 currentCursor_.reset([cursor retain]); 3472 currentCursor_.reset([cursor retain]);
3379 [[self window] invalidateCursorRectsForView:self]; 3473 [[self window] invalidateCursorRectsForView:self];
3380 } 3474 }
3381 3475
3382 - (void)popupWindowWillClose:(NSNotification *)notification { 3476 - (void)popupWindowWillClose:(NSNotification *)notification {
3383 renderWidgetHostView_->KillSelf(); 3477 renderWidgetHostView_->KillSelf();
3384 } 3478 }
3385 3479
3480 - (void)updateSoftwareLayerScaleFactor {
3481 if (![renderWidgetHostView_->software_layer_
3482 respondsToSelector:@selector(setContentsScale:)])
3483 return;
3484
3485 ScopedCAActionDisabler disabler;
3486 [renderWidgetHostView_->software_layer_ setContentsScale:deviceScaleFactor_];
3487 }
3488
3489 // Delegate methods for the software CALayer
3490 - (void)drawLayer:(CALayer*)layer
3491 inContext:(CGContextRef)context {
3492 DCHECK(renderWidgetHostView_->use_core_animation_);
3493 DCHECK([layer isEqual:renderWidgetHostView_->software_layer_]);
3494
3495 CGRect clipRect = CGContextGetClipBoundingBox(context);
3496
3497 if (!renderWidgetHostView_->render_widget_host_ ||
3498 renderWidgetHostView_->is_hidden()) {
3499 CGContextSetFillColorWithColor(context,
3500 CGColorGetConstantColor(kCGColorWhite));
3501 CGContextFillRect(context, clipRect);
3502 return;
3503 }
3504
3505 renderWidgetHostView_->about_to_validate_and_paint_ = true;
3506 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>(
3507 renderWidgetHostView_->render_widget_host_->GetBackingStore(true));
3508 renderWidgetHostView_->about_to_validate_and_paint_ = false;
3509
3510 [self drawBackingStore:backingStore
3511 dirtyRect:clipRect
3512 inContext:context];
3513 }
3514
3515 - (void)setNeedsDisplay:(BOOL)flag {
3516 [renderWidgetHostView_->software_layer_ setNeedsDisplay];
3517 [super setNeedsDisplay:flag];
3518 }
3519
3520 - (void)setNeedsDisplayInRect:(NSRect)rect {
3521 [renderWidgetHostView_->software_layer_
3522 setNeedsDisplayInRect:NSRectToCGRect(rect)];
3523 [super setNeedsDisplayInRect:rect];
3524 }
3525
3386 @end 3526 @end
3387 3527
3388 // 3528 //
3389 // Supporting application services 3529 // Supporting application services
3390 // 3530 //
3391 @implementation RenderWidgetHostViewCocoa(NSServicesRequests) 3531 @implementation RenderWidgetHostViewCocoa(NSServicesRequests)
3392 3532
3393 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard 3533 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard
3394 types:(NSArray*)types { 3534 types:(NSArray*)types {
3395 const std::string& str = renderWidgetHostView_->selected_text(); 3535 const std::string& str = renderWidgetHostView_->selected_text();
(...skipping 10 matching lines...) Expand all
3406 NSString *string = [pboard stringForType:NSStringPboardType]; 3546 NSString *string = [pboard stringForType:NSStringPboardType];
3407 if (!string) return NO; 3547 if (!string) return NO;
3408 3548
3409 // If the user is currently using an IME, confirm the IME input, 3549 // If the user is currently using an IME, confirm the IME input,
3410 // and then insert the text from the service, the same as TextEdit and Safari. 3550 // and then insert the text from the service, the same as TextEdit and Safari.
3411 [self confirmComposition]; 3551 [self confirmComposition];
3412 [self insertText:string]; 3552 [self insertText:string];
3413 return YES; 3553 return YES;
3414 } 3554 }
3415 3555
3556 - (BOOL)isOpaque {
3557 if (renderWidgetHostView_->use_core_animation_)
3558 return YES;
3559 return [super isOpaque];
3560 }
3561
3416 @end 3562 @end
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698