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

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: Remove unused method 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"
16 #import "base/memory/scoped_nsobject.h" 17 #import "base/memory/scoped_nsobject.h"
17 #include "base/message_loop.h" 18 #include "base/message_loop.h"
18 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
19 #include "base/string_util.h" 20 #include "base/string_util.h"
20 #include "base/stringprintf.h" 21 #include "base/stringprintf.h"
21 #include "base/strings/sys_string_conversions.h" 22 #include "base/strings/sys_string_conversions.h"
22 #include "base/sys_info.h" 23 #include "base/sys_info.h"
23 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
24 #import "content/browser/accessibility/browser_accessibility_cocoa.h" 25 #import "content/browser/accessibility/browser_accessibility_cocoa.h"
25 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" 26 #include "content/browser/accessibility/browser_accessibility_manager_mac.h"
26 #include "content/browser/renderer_host/backing_store_mac.h" 27 #include "content/browser/renderer_host/backing_store_mac.h"
27 #include "content/browser/renderer_host/backing_store_manager.h" 28 #include "content/browser/renderer_host/backing_store_manager.h"
29 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
30 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
28 #include "content/browser/renderer_host/compositing_iosurface_mac.h" 31 #include "content/browser/renderer_host/compositing_iosurface_mac.h"
29 #include "content/browser/renderer_host/render_view_host_impl.h" 32 #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" 33 #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" 34 #import "content/browser/renderer_host/text_input_client_mac.h"
32 #include "content/common/accessibility_messages.h" 35 #include "content/common/accessibility_messages.h"
33 #include "content/common/edit_command.h" 36 #include "content/common/edit_command.h"
34 #include "content/common/gpu/gpu_messages.h" 37 #include "content/common/gpu/gpu_messages.h"
35 #include "content/common/input_messages.h" 38 #include "content/common/input_messages.h"
36 #include "content/common/view_messages.h" 39 #include "content/common/view_messages.h"
37 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" 40 #include "content/port/browser/render_widget_host_view_frame_subscriber.h"
38 #include "content/public/browser/browser_thread.h" 41 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/native_web_keyboard_event.h" 42 #include "content/public/browser/native_web_keyboard_event.h"
40 #import "content/public/browser/render_widget_host_view_mac_delegate.h" 43 #import "content/public/browser/render_widget_host_view_mac_delegate.h"
44 #include "content/public/common/content_switches.h"
41 #include "skia/ext/platform_canvas.h" 45 #include "skia/ext/platform_canvas.h"
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
44 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h" 48 #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" 49 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebScreenInfoFact ory.h"
46 #import "third_party/mozilla/ComplexTextInputPanel.h" 50 #import "third_party/mozilla/ComplexTextInputPanel.h"
47 #import "ui/base/cocoa/fullscreen_window_manager.h" 51 #import "ui/base/cocoa/fullscreen_window_manager.h"
48 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" 52 #import "ui/base/cocoa/underlay_opengl_hosting_window.h"
49 #include "ui/base/keycodes/keyboard_codes.h" 53 #include "ui/base/keycodes/keyboard_codes.h"
50 #include "ui/base/layout.h" 54 #include "ui/base/layout.h"
51 #include "ui/gfx/point.h" 55 #include "ui/gfx/point.h"
52 #include "ui/gfx/rect_conversions.h" 56 #include "ui/gfx/rect_conversions.h"
53 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 57 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
54 #include "ui/gfx/size_conversions.h" 58 #include "ui/gfx/size_conversions.h"
55 #include "ui/surface/io_surface_support_mac.h" 59 #include "ui/surface/io_surface_support_mac.h"
60 #include "ui/base/cocoa/animation_utils.h"
Avi (use Gerrit) 2013/05/31 23:59:58 alphabetize
ccameron 2013/06/01 00:29:45 Done.
56 #include "webkit/plugins/npapi/webplugin.h" 61 #include "webkit/plugins/npapi/webplugin.h"
57 62
58 using content::BackingStoreMac; 63 using content::BackingStoreMac;
59 using content::BrowserAccessibility; 64 using content::BrowserAccessibility;
60 using content::BrowserAccessibilityManager; 65 using content::BrowserAccessibilityManager;
61 using content::EditCommand; 66 using content::EditCommand;
62 using content::NativeWebKeyboardEvent; 67 using content::NativeWebKeyboardEvent;
63 using content::RenderViewHostImpl; 68 using content::RenderViewHostImpl;
64 using content::RenderWidgetHostImpl; 69 using content::RenderWidgetHostImpl;
65 using content::RenderWidgetHostViewMac; 70 using content::RenderWidgetHostViewMac;
66 using content::RenderWidgetHostViewMacEditCommandHelper; 71 using content::RenderWidgetHostViewMacEditCommandHelper;
67 using content::TextInputClientMac; 72 using content::TextInputClientMac;
68 using WebKit::WebInputEvent; 73 using WebKit::WebInputEvent;
69 using WebKit::WebInputEventFactory; 74 using WebKit::WebInputEventFactory;
70 using WebKit::WebMouseEvent; 75 using WebKit::WebMouseEvent;
71 using WebKit::WebMouseWheelEvent; 76 using WebKit::WebMouseWheelEvent;
72 77
73 // These are not documented, so use only after checking -respondsToSelector:. 78 // These are not documented, so use only after checking -respondsToSelector:.
74 @interface NSApplication (UndocumentedSpeechMethods) 79 @interface NSApplication (UndocumentedSpeechMethods)
75 - (void)speakString:(NSString*)string; 80 - (void)speakString:(NSString*)string;
76 - (void)stopSpeaking:(id)sender; 81 - (void)stopSpeaking:(id)sender;
77 - (BOOL)isSpeaking; 82 - (BOOL)isSpeaking;
78 @end 83 @end
79 84
85 @interface CALayer (LionAPI)
86 - (void)setContentsScale:(CGFloat)contentsScale;
87 @end
88
80 // Declare things that are part of the 10.7 SDK. 89 // Declare things that are part of the 10.7 SDK.
81 #if !defined(MAC_OS_X_VERSION_10_7) || \ 90 #if !defined(MAC_OS_X_VERSION_10_7) || \
82 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 91 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
83 enum { 92 enum {
84 NSEventPhaseNone = 0, // event not associated with a phase. 93 NSEventPhaseNone = 0, // event not associated with a phase.
85 NSEventPhaseBegan = 0x1 << 0, 94 NSEventPhaseBegan = 0x1 << 0,
86 NSEventPhaseStationary = 0x1 << 1, 95 NSEventPhaseStationary = 0x1 << 1,
87 NSEventPhaseChanged = 0x1 << 2, 96 NSEventPhaseChanged = 0x1 << 2,
88 NSEventPhaseEnded = 0x1 << 3, 97 NSEventPhaseEnded = 0x1 << 3,
89 NSEventPhaseCancelled = 0x1 << 4, 98 NSEventPhaseCancelled = 0x1 << 4,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 NSObject<RenderWidgetHostViewMacDelegate>* delegate; 146 NSObject<RenderWidgetHostViewMacDelegate>* delegate;
138 147
139 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; 148 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event;
140 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; 149 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r;
141 - (void)gotUnhandledWheelEvent; 150 - (void)gotUnhandledWheelEvent;
142 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; 151 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right;
143 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; 152 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar;
144 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; 153 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv;
145 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; 154 - (void)windowDidChangeBackingProperties:(NSNotification*)notification;
146 - (void)windowChangedGlobalFrame:(NSNotification*)notification; 155 - (void)windowChangedGlobalFrame:(NSNotification*)notification;
156 - (void)drawBackingStore:(BackingStoreMac*)backingStore
157 dirtyRect:(CGRect)dirtyRect
158 inContext:(CGContextRef)context;
159 - (void)updateSoftwareLayerScaleFactor;
147 - (void)checkForPluginImeCancellation; 160 - (void)checkForPluginImeCancellation;
148 - (void)updateTabBackingStoreScaleFactor; 161 - (void)updateTabBackingStoreScaleFactor;
149 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange 162 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange
150 actualRange:(NSRangePointer)actualRange; 163 actualRange:(NSRangePointer)actualRange;
151 @end 164 @end
152 165
153 // NSEvent subtype for scroll gestures events. 166 // NSEvent subtype for scroll gestures events.
154 static const short kIOHIDEventTypeScroll = 6; 167 static const short kIOHIDEventTypeScroll = 6;
155 168
156 // A window subclass that allows the fullscreen window to become main and gain 169 // 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: 372 // RenderWidgetHostViewMac, public:
360 373
361 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) 374 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget)
362 : render_widget_host_(RenderWidgetHostImpl::From(widget)), 375 : render_widget_host_(RenderWidgetHostImpl::From(widget)),
363 about_to_validate_and_paint_(false), 376 about_to_validate_and_paint_(false),
364 call_set_needs_display_in_rect_pending_(false), 377 call_set_needs_display_in_rect_pending_(false),
365 last_frame_was_accelerated_(false), 378 last_frame_was_accelerated_(false),
366 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 379 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
367 can_compose_inline_(true), 380 can_compose_inline_(true),
368 allow_overlapping_views_(false), 381 allow_overlapping_views_(false),
382 use_core_animation_(false),
369 is_loading_(false), 383 is_loading_(false),
370 is_hidden_(false), 384 is_hidden_(false),
371 weak_factory_(this), 385 weak_factory_(this),
372 fullscreen_parent_host_view_(NULL) { 386 fullscreen_parent_host_view_(NULL) {
387 use_core_animation_ = CommandLine::ForCurrentProcess()->HasSwitch(
388 switches::kUseCoreAnimation);
389
373 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| 390 // |cocoa_view_| owns us and we will be deleted when |cocoa_view_|
374 // goes away. Since we autorelease it, our caller must put 391 // goes away. Since we autorelease it, our caller must put
375 // |GetNativeView()| into the view hierarchy right after calling us. 392 // |GetNativeView()| into the view hierarchy right after calling us.
376 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] 393 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc]
377 initWithRenderWidgetHostViewMac:this] autorelease]; 394 initWithRenderWidgetHostViewMac:this] autorelease];
378 render_widget_host_->SetView(this); 395 render_widget_host_->SetView(this);
379 } 396 }
380 397
381 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { 398 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() {
382 AckPendingSwapBuffers(); 399 AckPendingSwapBuffers();
383 UnlockMouse(); 400 UnlockMouse();
401
402 // Make sure that the layer doesn't reach into the now-invalid object.
403 compositing_iosurface_.reset();
404 if (compositing_iosurface_layer_)
405 [compositing_iosurface_layer_ disableCompositing];
406 compositing_iosurface_layer_.reset();
407
384 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the 408 // 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 409 // RenderWidgetHost does we need to tell it not to hold a stale pointer to
386 // us. 410 // us.
387 if (render_widget_host_) 411 if (render_widget_host_)
388 render_widget_host_->SetView(NULL); 412 render_widget_host_->SetView(NULL);
389 } 413 }
390 414
391 void RenderWidgetHostViewMac::SetDelegate( 415 void RenderWidgetHostViewMac::SetDelegate(
392 NSObject<RenderWidgetHostViewMacDelegate>* delegate) { 416 NSObject<RenderWidgetHostViewMacDelegate>* delegate) {
393 [cocoa_view_ setDelegate:delegate]; 417 [cocoa_view_ setDelegate:delegate];
394 } 418 }
395 419
396 void RenderWidgetHostViewMac::SetAllowOverlappingViews(bool overlapping) { 420 void RenderWidgetHostViewMac::SetAllowOverlappingViews(bool overlapping) {
421 DCHECK(!overlapping || !use_core_animation_);
397 allow_overlapping_views_ = overlapping; 422 allow_overlapping_views_ = overlapping;
398 } 423 }
399 424
400 /////////////////////////////////////////////////////////////////////////////// 425 ///////////////////////////////////////////////////////////////////////////////
401 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: 426 // RenderWidgetHostViewMac, RenderWidgetHostView implementation:
402 427
403 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { 428 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) {
404 bool handled = true; 429 bool handled = true;
405 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) 430 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message)
406 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) 431 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 pepper_fullscreen_window_.reset(); 530 pepper_fullscreen_window_.reset();
506 } 531 }
507 532
508 int RenderWidgetHostViewMac::window_number() const { 533 int RenderWidgetHostViewMac::window_number() const {
509 NSWindow* window = [cocoa_view_ window]; 534 NSWindow* window = [cocoa_view_ window];
510 if (!window) 535 if (!window)
511 return -1; 536 return -1;
512 return [window windowNumber]; 537 return [window windowNumber];
513 } 538 }
514 539
540 float RenderWidgetHostViewMac::scale_factor() const {
541 return ScaleFactor(cocoa_view_);
542 }
543
515 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { 544 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const {
516 return render_widget_host_; 545 return render_widget_host_;
517 } 546 }
518 547
519 void RenderWidgetHostViewMac::WasShown() { 548 void RenderWidgetHostViewMac::WasShown() {
520 if (!is_hidden_) 549 if (!is_hidden_)
521 return; 550 return;
522 551
523 if (web_contents_switch_paint_time_.is_null()) 552 if (web_contents_switch_paint_time_.is_null())
524 web_contents_switch_paint_time_ = base::TimeTicks::Now(); 553 web_contents_switch_paint_time_ = base::TimeTicks::Now();
525 is_hidden_ = false; 554 is_hidden_ = false;
526 render_widget_host_->WasShown(); 555 render_widget_host_->WasShown();
527 556
528 // We're messing with the window, so do this to ensure no flashes. 557 // We're messing with the window, so do this to ensure no flashes.
529 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; 558 if (!use_core_animation_)
559 [[cocoa_view_ window] disableScreenUpdatesUntilFlush];
560
561 if (compositing_iosurface_layer_)
562 [compositing_iosurface_layer_ setNeedsDisplay];
530 } 563 }
531 564
532 void RenderWidgetHostViewMac::WasHidden() { 565 void RenderWidgetHostViewMac::WasHidden() {
533 if (is_hidden_) 566 if (is_hidden_)
534 return; 567 return;
535 568
536 // Send ACKs for any pending SwapBuffers (if any) since we won't be displaying 569 // Send ACKs for any pending SwapBuffers (if any) since we won't be displaying
537 // them and the GPU process is waiting. 570 // them and the GPU process is waiting.
538 AckPendingSwapBuffers(); 571 AckPendingSwapBuffers();
539 572
540 // If we receive any more paint messages while we are hidden, we want to 573 // If we receive any more paint messages while we are hidden, we want to
541 // ignore them so we don't re-allocate the backing store. We will paint 574 // ignore them so we don't re-allocate the backing store. We will paint
542 // everything again when we become selected again. 575 // everything again when we become selected again.
543 is_hidden_ = true; 576 is_hidden_ = true;
544 577
545 // If we have a renderer, then inform it that we are being hidden so it can 578 // If we have a renderer, then inform it that we are being hidden so it can
546 // reduce its resource utilization. 579 // reduce its resource utilization.
547 render_widget_host_->WasHidden(); 580 render_widget_host_->WasHidden();
548 581
549 // There can be a transparent flash as this view is removed and the next is 582 // There can be a transparent flash as this view is removed and the next is
550 // added, because of OSX windowing races between displaying the contents of 583 // added, because of OSX windowing races between displaying the contents of
551 // the NSView and its corresponding OpenGL context. 584 // the NSView and its corresponding OpenGL context.
552 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding 585 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding
553 // screen updates until the next tab draws. 586 // screen updates until the next tab draws.
554 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; 587 if (!use_core_animation_)
588 [[cocoa_view_ window] disableScreenUpdatesUntilFlush];
555 589
556 web_contents_switch_paint_time_ = base::TimeTicks(); 590 web_contents_switch_paint_time_ = base::TimeTicks();
557 } 591 }
558 592
559 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { 593 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) {
560 gfx::Rect rect = GetViewBounds(); 594 gfx::Rect rect = GetViewBounds();
561 rect.set_size(size); 595 rect.set_size(size);
562 SetBounds(rect); 596 SetBounds(rect);
563 } 597 }
564 598
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 } 1070 }
1037 1071
1038 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( 1072 void RenderWidgetHostViewMac::PluginImeCompositionCompleted(
1039 const string16& text, int plugin_id) { 1073 const string16& text, int plugin_id) {
1040 if (render_widget_host_) { 1074 if (render_widget_host_) {
1041 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( 1075 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted(
1042 render_widget_host_->GetRoutingID(), text, plugin_id)); 1076 render_widget_host_->GetRoutingID(), text, plugin_id));
1043 } 1077 }
1044 } 1078 }
1045 1079
1046 bool RenderWidgetHostViewMac::CompositorSwapBuffers(uint64 surface_handle, 1080 bool RenderWidgetHostViewMac::CompositorSwapBuffers(
1047 const gfx::Size& size, 1081 uint64 surface_handle, const gfx::Size& size, float surface_scale_factor) {
1048 float scale_factor) {
1049 if (is_hidden_) 1082 if (is_hidden_)
1050 return true; 1083 return true;
1051 1084
1052 NSWindow* window = [cocoa_view_ window]; 1085 NSWindow* window = [cocoa_view_ window];
1053 if (window_number() <= 0) { 1086 if (window_number() <= 0) {
1054 // There is no window to present so capturing during present won't work. 1087 // There is no window to present so capturing during present won't work.
1055 // We check if frame subscriber wants this frame and capture manually. 1088 // We check if frame subscriber wants this frame and capture manually.
1056 if (compositing_iosurface_.get() && frame_subscriber_) { 1089 if (compositing_iosurface_.get() && frame_subscriber_) {
1057 const base::Time present_time = base::Time::Now(); 1090 const base::Time present_time = base::Time::Now();
1058 scoped_refptr<media::VideoFrame> frame; 1091 scoped_refptr<media::VideoFrame> frame;
1059 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 1092 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
1060 if (frame_subscriber_->ShouldCaptureFrame(present_time, 1093 if (frame_subscriber_->ShouldCaptureFrame(present_time,
1061 &frame, &callback)) { 1094 &frame, &callback)) {
1062 compositing_iosurface_->SetIOSurface( 1095 compositing_iosurface_->SetIOSurface(
1063 surface_handle, size, scale_factor); 1096 surface_handle, size, surface_scale_factor);
1064 compositing_iosurface_->CopyToVideoFrame( 1097 compositing_iosurface_->CopyToVideoFrame(
1065 gfx::Rect(size), frame, 1098 gfx::Rect(size), frame,
1066 base::Bind(callback, present_time)); 1099 base::Bind(callback, present_time));
1067 return true; 1100 return true;
1068 } 1101 }
1069 } 1102 }
1070 1103
1071 // TODO(shess) If the view does not have a window, or the window 1104 // TODO(shess) If the view does not have a window, or the window
1072 // does not have backing, the IOSurface will log "invalid drawable" 1105 // does not have backing, the IOSurface will log "invalid drawable"
1073 // in -setView:. It is not clear how this code is reached with such 1106 // in -setView:. It is not clear how this code is reached with such
(...skipping 10 matching lines...) Expand all
1084 object_getClassName([window delegate]), 1117 object_getClassName([window delegate]),
1085 object_getClassName([window windowController])); 1118 object_getClassName([window windowController]));
1086 base::debug::SetCrashKeyValue(kCrashKey, value); 1119 base::debug::SetCrashKeyValue(kCrashKey, value);
1087 } 1120 }
1088 1121
1089 return true; 1122 return true;
1090 } 1123 }
1091 1124
1092 bool should_post_notification = false; 1125 bool should_post_notification = false;
1093 if (!compositing_iosurface_) { 1126 if (!compositing_iosurface_) {
1094 CompositingIOSurfaceMac::SurfaceOrder order = allow_overlapping_views_ ? 1127 if (use_core_animation_) {
1095 CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW : 1128 if (!compositing_iosurface_layer_) {
1096 CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW; 1129 compositing_iosurface_layer_.reset([[CompositingIOSurfaceLayer alloc]
1097 compositing_iosurface_.reset( 1130 initWithRenderWidgetHostViewMac:this]);
1098 CompositingIOSurfaceMac::Create(window_number(), order)); 1131 }
1132 if (!compositing_iosurface_layer_) {
1133 LOG(WARNING) << "Failed to create CALayer for IOSurface";
1134 return true;
1135 }
1136 if (![compositing_iosurface_layer_ ensureContext]) {
1137 LOG(WARNING) << "Failed to create context for IOSurface";
1138 return true;
1139 }
1140 compositing_iosurface_.reset(CompositingIOSurfaceMac::Create(
1141 [compositing_iosurface_layer_ context]));
1142 } else {
1143 CompositingIOSurfaceMac::SurfaceOrder order = allow_overlapping_views_ ?
1144 CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW :
1145 CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW;
1146 compositing_iosurface_.reset(
1147 CompositingIOSurfaceMac::Create(window_number(), order));
1148 }
1099 should_post_notification = true; 1149 should_post_notification = true;
1100 } 1150 }
1101 1151
1102 if (!compositing_iosurface_) 1152 if (!compositing_iosurface_) {
1153 LOG(WARNING) << "Failed to create CompositingIOSurfaceMac";
1103 return true; 1154 return true;
1155 }
1104 1156
1105 compositing_iosurface_->SetIOSurface(surface_handle, size, scale_factor); 1157 compositing_iosurface_->SetIOSurface(
1158 surface_handle, size, surface_scale_factor);
1159
1160 // TODO(ccameron): If we've failed to allocate the GL texture for the
1161 // IOSurface, or basically anything else along the way, we'll just display
1162 // a white out, potentially forever. Instead, kick the renderer back to
1163 // software mode (like a context lost or a GPU process death).
1106 1164
1107 GotAcceleratedFrame(); 1165 GotAcceleratedFrame();
1108 1166
1109 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); 1167 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size));
1110 if (window_size.IsEmpty()) { 1168 if (window_size.IsEmpty()) {
1111 // setNeedsDisplay will never display and we'll never ack if the window is 1169 // setNeedsDisplay will never display and we'll never ack if the window is
1112 // empty, so ack now and don't bother calling setNeedsDisplay below. 1170 // empty, so ack now and don't bother calling setNeedsDisplay below.
1113 return true; 1171 return true;
1114 } 1172 }
1115 1173
1116 // No need to draw the surface if we are inside a drawRect. It will be done 1174 // No need to draw the surface if we are inside a drawRect. It will be done
1117 // later. 1175 // later.
1118 if (!about_to_validate_and_paint_) { 1176 if (!about_to_validate_and_paint_) {
1119 CompositingIOSurfaceMac::SurfaceOrder order = allow_overlapping_views_ ? 1177 if (use_core_animation_) {
1120 CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW : 1178 DCHECK(compositing_iosurface_layer_);
1121 CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW; 1179 [compositing_iosurface_layer_ setNeedsDisplay];
1122 compositing_iosurface_->DrawIOSurface(cocoa_view_, 1180 } else {
1123 ScaleFactor(cocoa_view_), 1181 compositing_iosurface_->DrawIOSurface(this);
1124 window_number(), 1182 }
1125 order,
1126 frame_subscriber_.get());
1127 } 1183 }
1128 1184
1129 if (should_post_notification && [[cocoa_view_ delegate] 1185 if (should_post_notification && [[cocoa_view_ delegate]
1130 respondsToSelector:@selector(compositingIOSurfaceCreated)]) { 1186 respondsToSelector:@selector(compositingIOSurfaceCreated)]) {
1131 [[cocoa_view_ delegate] compositingIOSurfaceCreated]; 1187 [[cocoa_view_ delegate] compositingIOSurfaceCreated];
1132 } 1188 }
1133 1189
1190 // Don't ack the new frame until it is drawn.
1191 if (use_core_animation_)
1192 return false;
1193
1134 return true; 1194 return true;
1135 } 1195 }
1136 1196
1137 void RenderWidgetHostViewMac::AckPendingSwapBuffers() { 1197 void RenderWidgetHostViewMac::AckPendingSwapBuffers() {
1138 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::AckPendingSwapBuffers"); 1198 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::AckPendingSwapBuffers");
1139 while (!pending_swap_buffers_acks_.empty()) { 1199 while (!pending_swap_buffers_acks_.empty()) {
1140 if (pending_swap_buffers_acks_.front().first != 0) { 1200 if (pending_swap_buffers_acks_.front().first != 0) {
1141 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; 1201 AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
1142 ack_params.sync_point = 0; 1202 ack_params.sync_point = 0;
1143 if (compositing_iosurface_) 1203 if (compositing_iosurface_)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 AckPendingSwapBuffers(); 1394 AckPendingSwapBuffers();
1335 } 1395 }
1336 1396
1337 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() { 1397 void RenderWidgetHostViewMac::AcceleratedSurfaceSuspend() {
1338 if (compositing_iosurface_) 1398 if (compositing_iosurface_)
1339 compositing_iosurface_->UnrefIOSurface(); 1399 compositing_iosurface_->UnrefIOSurface();
1340 } 1400 }
1341 1401
1342 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() { 1402 void RenderWidgetHostViewMac::AcceleratedSurfaceRelease() {
1343 compositing_iosurface_.reset(); 1403 compositing_iosurface_.reset();
1404 if (compositing_iosurface_layer_)
1405 [compositing_iosurface_layer_ disableCompositing];
1406 compositing_iosurface_layer_.reset();
1344 } 1407 }
1345 1408
1346 bool RenderWidgetHostViewMac::HasAcceleratedSurface( 1409 bool RenderWidgetHostViewMac::HasAcceleratedSurface(
1347 const gfx::Size& desired_size) { 1410 const gfx::Size& desired_size) {
1348 return last_frame_was_accelerated_ && 1411 return last_frame_was_accelerated_ &&
1349 compositing_iosurface_.get() && 1412 compositing_iosurface_.get() &&
1350 compositing_iosurface_->HasIOSurface() && 1413 compositing_iosurface_->HasIOSurface() &&
1351 (desired_size.IsEmpty() || 1414 (desired_size.IsEmpty() ||
1352 compositing_iosurface_->dip_io_surface_size() == desired_size); 1415 compositing_iosurface_->dip_io_surface_size() == desired_size);
1353 } 1416 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 } 1500 }
1438 1501
1439 1502
1440 void RenderWidgetHostViewMac::ShutdownHost() { 1503 void RenderWidgetHostViewMac::ShutdownHost() {
1441 weak_factory_.InvalidateWeakPtrs(); 1504 weak_factory_.InvalidateWeakPtrs();
1442 render_widget_host_->Shutdown(); 1505 render_widget_host_->Shutdown();
1443 // Do not touch any members at this point, |this| has been deleted. 1506 // Do not touch any members at this point, |this| has been deleted.
1444 } 1507 }
1445 1508
1446 void RenderWidgetHostViewMac::GotAcceleratedFrame() { 1509 void RenderWidgetHostViewMac::GotAcceleratedFrame() {
1510 // Update the scale factor of the layer to match the scale factor of the
1511 // IOSurface.
1512 if (compositing_iosurface_layer_)
1513 [compositing_iosurface_layer_ updateScaleFactor];
1514
1447 if (!last_frame_was_accelerated_) { 1515 if (!last_frame_was_accelerated_) {
1448 last_frame_was_accelerated_ = true; 1516 last_frame_was_accelerated_ = true;
1449 1517
1450 // Need to wipe the software view with transparency to expose the GL 1518 if (!use_core_animation_) {
1451 // underlay. Invalidate the whole window to do that. 1519 // Need to wipe the software view with transparency to expose the GL
1452 [cocoa_view_ setNeedsDisplay:YES]; 1520 // underlay. Invalidate the whole window to do that.
1521 [cocoa_view_ setNeedsDisplay:YES];
1522 }
1453 1523
1454 // Delete software backingstore. 1524 // Delete software backingstore.
1455 BackingStoreManager::RemoveBackingStore(render_widget_host_); 1525 BackingStoreManager::RemoveBackingStore(render_widget_host_);
1456 } 1526 }
1457 } 1527 }
1458 1528
1459 void RenderWidgetHostViewMac::GotSoftwareFrame() { 1529 void RenderWidgetHostViewMac::GotSoftwareFrame() {
1460 if (last_frame_was_accelerated_) { 1530 if (last_frame_was_accelerated_) {
1461 last_frame_was_accelerated_ = false; 1531 last_frame_was_accelerated_ = false;
1462 1532
1463 AckPendingSwapBuffers(); 1533 AckPendingSwapBuffers();
1464 1534
1465 // Forget IOSurface since we are drawing a software frame now. 1535 // Forget IOSurface since we are drawing a software frame now.
1466 if (compositing_iosurface_.get() && 1536 if (use_core_animation_) {
1467 compositing_iosurface_->HasIOSurface()) { 1537 compositing_iosurface_.reset();
1468 compositing_iosurface_->ClearDrawable(); 1538 if (compositing_iosurface_layer_)
1539 [compositing_iosurface_layer_ disableCompositing];
1540 compositing_iosurface_layer_.reset();
1541 }
1542 else {
1543 if (compositing_iosurface_.get() &&
sail 2013/05/31 23:59:14 don't need the .get()
ccameron 2013/06/01 00:29:45 Removed all instances of compositing_iosurface_.ge
1544 compositing_iosurface_->HasIOSurface()) {
1545 compositing_iosurface_->ClearDrawable();
1546 }
1469 } 1547 }
1470 } 1548 }
1471 } 1549 }
1472 1550
1473 void RenderWidgetHostViewMac::SetActive(bool active) { 1551 void RenderWidgetHostViewMac::SetActive(bool active) {
1474 if (render_widget_host_) { 1552 if (render_widget_host_) {
1475 render_widget_host_->SetActive(active); 1553 render_widget_host_->SetActive(active);
1476 if (active) { 1554 if (active) {
1477 if (HasFocus()) 1555 if (HasFocus())
1478 render_widget_host_->Focus(); 1556 render_widget_host_->Focus();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 void RenderWidgetHostViewMac::OnStartPluginIme() { 1656 void RenderWidgetHostViewMac::OnStartPluginIme() {
1579 [cocoa_view_ setPluginImeActive:YES]; 1657 [cocoa_view_ setPluginImeActive:YES];
1580 } 1658 }
1581 1659
1582 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect( 1660 gfx::Rect RenderWidgetHostViewMac::GetScaledOpenGLPixelRect(
1583 const gfx::Rect& rect) { 1661 const gfx::Rect& rect) {
1584 gfx::Rect src_gl_subrect = rect; 1662 gfx::Rect src_gl_subrect = rect;
1585 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom()); 1663 src_gl_subrect.set_y(GetViewBounds().height() - rect.bottom());
1586 1664
1587 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect, 1665 return gfx::ToEnclosingRect(gfx::ScaleRect(src_gl_subrect,
1588 ScaleFactor(cocoa_view_))); 1666 scale_factor()));
1589 } 1667 }
1590 1668
1591 } // namespace content 1669 } // namespace content
1592 1670
1593 // RenderWidgetHostViewCocoa --------------------------------------------------- 1671 // RenderWidgetHostViewCocoa ---------------------------------------------------
1594 1672
1595 @implementation RenderWidgetHostViewCocoa 1673 @implementation RenderWidgetHostViewCocoa
1596 1674
1597 @synthesize selectedRange = selectedRange_; 1675 @synthesize selectedRange = selectedRange_;
1598 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; 1676 @synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_;
1599 @synthesize markedRange = markedRange_; 1677 @synthesize markedRange = markedRange_;
1600 @synthesize delegate = delegate_; 1678 @synthesize delegate = delegate_;
1601 1679
1602 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { 1680 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r {
1603 self = [super initWithFrame:NSZeroRect]; 1681 self = [super initWithFrame:NSZeroRect];
1604 if (self) { 1682 if (self) {
1605 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); 1683 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper);
1606 editCommand_helper_->AddEditingSelectorsToClass([self class]); 1684 editCommand_helper_->AddEditingSelectorsToClass([self class]);
1607 1685
1608 renderWidgetHostView_.reset(r); 1686 renderWidgetHostView_.reset(r);
1609 canBeKeyView_ = YES; 1687 canBeKeyView_ = YES;
1610 focusedPluginIdentifier_ = -1; 1688 focusedPluginIdentifier_ = -1;
1611 deviceScaleFactor_ = ScaleFactor(self); 1689 deviceScaleFactor_ = ScaleFactor(self);
1612 1690
1691 if (renderWidgetHostView_->use_core_animation_) {
1692 CALayer* layer = [CALayer layer];
1693 layer.backgroundColor = CGColorGetConstantColor(kCGColorWhite);
1694 [self setLayer:layer];
1695 [self setWantsLayer:YES];
1696
1697 softwareLayer_.reset([[CALayer alloc] init]);
1698 [softwareLayer_ setDelegate:self];
1699 [softwareLayer_ setAutoresizingMask:kCALayerWidthSizable |
1700 kCALayerHeightSizable];
1701 [softwareLayer_ setContentsGravity:kCAGravityTopLeft];
1702 [[self layer] addSublayer:softwareLayer_];
1703 [self updateSoftwareLayerScaleFactor];
1704 }
1705
1613 // OpenGL support: 1706 // OpenGL support:
1614 if ([self respondsToSelector: 1707 if ([self respondsToSelector:
1615 @selector(setWantsBestResolutionOpenGLSurface:)]) { 1708 @selector(setWantsBestResolutionOpenGLSurface:)]) {
1616 [self setWantsBestResolutionOpenGLSurface:YES]; 1709 [self setWantsBestResolutionOpenGLSurface:YES];
1617 } 1710 }
1618 handlingGlobalFrameDidChange_ = NO; 1711 handlingGlobalFrameDidChange_ = NO;
1619 [[NSNotificationCenter defaultCenter] 1712 [[NSNotificationCenter defaultCenter]
1620 addObserver:self 1713 addObserver:self
1621 selector:@selector(globalFrameDidChange:) 1714 selector:@selector(globalFrameDidChange:)
1622 name:NSViewGlobalFrameDidChangeNotification 1715 name:NSViewGlobalFrameDidChangeNotification
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 const WebMouseWheelEvent& webEvent = 2217 const WebMouseWheelEvent& webEvent =
2125 WebInputEventFactory::mouseWheelEvent(event, self); 2218 WebInputEventFactory::mouseWheelEvent(event, self);
2126 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent); 2219 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(webEvent);
2127 } 2220 }
2128 } 2221 }
2129 2222
2130 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { 2223 - (void)viewWillMoveToWindow:(NSWindow*)newWindow {
2131 // We're messing with the window, so do this to ensure no flashes. This one 2224 // We're messing with the window, so do this to ensure no flashes. This one
2132 // prevents a flash when the current tab is closed. 2225 // prevents a flash when the current tab is closed.
2133 NSWindow* oldWindow = [self window]; 2226 NSWindow* oldWindow = [self window];
2134 [oldWindow disableScreenUpdatesUntilFlush]; 2227
2228 if (!renderWidgetHostView_->use_core_animation_)
2229 [oldWindow disableScreenUpdatesUntilFlush];
2135 2230
2136 NSNotificationCenter* notificationCenter = 2231 NSNotificationCenter* notificationCenter =
2137 [NSNotificationCenter defaultCenter]; 2232 [NSNotificationCenter defaultCenter];
2138 if (oldWindow) { 2233 if (oldWindow) {
2139 [notificationCenter 2234 [notificationCenter
2140 removeObserver:self 2235 removeObserver:self
2141 name:NSWindowDidChangeBackingPropertiesNotification 2236 name:NSWindowDidChangeBackingPropertiesNotification
2142 object:oldWindow]; 2237 object:oldWindow];
2143 [notificationCenter 2238 [notificationCenter
2144 removeObserver:self 2239 removeObserver:self
(...skipping 30 matching lines...) Expand all
2175 float scaleFactor = ScaleFactor(self); 2270 float scaleFactor = ScaleFactor(self);
2176 if (scaleFactor == deviceScaleFactor_) 2271 if (scaleFactor == deviceScaleFactor_)
2177 return; 2272 return;
2178 deviceScaleFactor_ = scaleFactor; 2273 deviceScaleFactor_ = scaleFactor;
2179 2274
2180 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( 2275 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>(
2181 renderWidgetHostView_->render_widget_host_->GetBackingStore(false)); 2276 renderWidgetHostView_->render_widget_host_->GetBackingStore(false));
2182 if (backingStore) // NULL in hardware path. 2277 if (backingStore) // NULL in hardware path.
2183 backingStore->ScaleFactorChanged(scaleFactor); 2278 backingStore->ScaleFactorChanged(scaleFactor);
2184 2279
2280 [self updateSoftwareLayerScaleFactor];
2185 renderWidgetHostView_->render_widget_host_->NotifyScreenInfoChanged(); 2281 renderWidgetHostView_->render_widget_host_->NotifyScreenInfoChanged();
2186 } 2282 }
2187 2283
2188 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a pple_ref/doc/uid/TP40012302-CH10-SW4 2284 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a pple_ref/doc/uid/TP40012302-CH10-SW4
2189 - (void)windowDidChangeBackingProperties:(NSNotification*)notification { 2285 - (void)windowDidChangeBackingProperties:(NSNotification*)notification {
2190 NSWindow* window = (NSWindow*)[notification object]; 2286 NSWindow* window = (NSWindow*)[notification object];
2191 2287
2192 CGFloat newBackingScaleFactor = [window backingScaleFactor]; 2288 CGFloat newBackingScaleFactor = [window backingScaleFactor];
2193 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>( 2289 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>(
2194 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey]) 2290 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey])
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2231 renderWidgetHostView_->render_widget_host_->WasResized(); 2327 renderWidgetHostView_->render_widget_host_->WasResized();
2232 } 2328 }
2233 } 2329 }
2234 2330
2235 - (void)callSetNeedsDisplayInRect { 2331 - (void)callSetNeedsDisplayInRect {
2236 DCHECK([NSThread isMainThread]); 2332 DCHECK([NSThread isMainThread]);
2237 DCHECK(renderWidgetHostView_->call_set_needs_display_in_rect_pending_); 2333 DCHECK(renderWidgetHostView_->call_set_needs_display_in_rect_pending_);
2238 [self setNeedsDisplayInRect:renderWidgetHostView_->invalid_rect_]; 2334 [self setNeedsDisplayInRect:renderWidgetHostView_->invalid_rect_];
2239 renderWidgetHostView_->call_set_needs_display_in_rect_pending_ = false; 2335 renderWidgetHostView_->call_set_needs_display_in_rect_pending_ = false;
2240 renderWidgetHostView_->invalid_rect_ = NSZeroRect; 2336 renderWidgetHostView_->invalid_rect_ = NSZeroRect;
2337
2338 if (renderWidgetHostView_->compositing_iosurface_layer_)
2339 [renderWidgetHostView_->compositing_iosurface_layer_ setNeedsDisplay];
2241 } 2340 }
2242 2341
2243 // Fills with white the parts of the area to the right and bottom for |rect| 2342 // Fills with white the parts of the area to the right and bottom for |rect|
2244 // that intersect |damagedRect|. 2343 // that intersect |damagedRect|.
2245 - (void)fillBottomRightRemainderOfRect:(gfx::Rect)rect 2344 - (void)fillBottomRightRemainderOfRect:(gfx::Rect)rect
2246 dirtyRect:(gfx::Rect)damagedRect { 2345 dirtyRect:(gfx::Rect)damagedRect
2346 inContext:(CGContextRef)context {
2247 if (damagedRect.right() > rect.right()) { 2347 if (damagedRect.right() > rect.right()) {
2248 int x = std::max(rect.right(), damagedRect.x()); 2348 int x = std::max(rect.right(), damagedRect.x());
2249 int y = std::min(rect.bottom(), damagedRect.bottom()); 2349 int y = std::min(rect.bottom(), damagedRect.bottom());
2250 int width = damagedRect.right() - x; 2350 int width = damagedRect.right() - x;
2251 int height = damagedRect.y() - y; 2351 int height = damagedRect.y() - y;
2252 2352
2253 // Extra fun to get around the fact that gfx::Rects can't have 2353 // Extra fun to get around the fact that gfx::Rects can't have
2254 // negative sizes. 2354 // negative sizes.
2255 if (width < 0) { 2355 if (width < 0) {
2256 x += width; 2356 x += width;
2257 width = -width; 2357 width = -width;
2258 } 2358 }
2259 if (height < 0) { 2359 if (height < 0) {
2260 y += height; 2360 y += height;
2261 height = -height; 2361 height = -height;
2262 } 2362 }
2263 2363
2264 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; 2364 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)];
2265 [[NSColor whiteColor] set]; 2365 CGContextSetFillColorWithColor(context,
2266 NSRectFill(r); 2366 CGColorGetConstantColor(kCGColorWhite));
2367 CGContextFillRect(context, NSRectToCGRect(r));
2267 } 2368 }
2268 if (damagedRect.bottom() > rect.bottom()) { 2369 if (damagedRect.bottom() > rect.bottom()) {
2269 int x = damagedRect.x(); 2370 int x = damagedRect.x();
2270 int y = damagedRect.bottom(); 2371 int y = damagedRect.bottom();
2271 int width = damagedRect.right() - x; 2372 int width = damagedRect.right() - x;
2272 int height = std::max(rect.bottom(), damagedRect.y()) - y; 2373 int height = std::max(rect.bottom(), damagedRect.y()) - y;
2273 2374
2274 // Extra fun to get around the fact that gfx::Rects can't have 2375 // Extra fun to get around the fact that gfx::Rects can't have
2275 // negative sizes. 2376 // negative sizes.
2276 if (width < 0) { 2377 if (width < 0) {
2277 x += width; 2378 x += width;
2278 width = -width; 2379 width = -width;
2279 } 2380 }
2280 if (height < 0) { 2381 if (height < 0) {
2281 y += height; 2382 y += height;
2282 height = -height; 2383 height = -height;
2283 } 2384 }
2284 2385
2285 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; 2386 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)];
2286 [[NSColor whiteColor] set]; 2387 CGContextSetFillColorWithColor(context,
2287 NSRectFill(r); 2388 CGColorGetConstantColor(kCGColorWhite));
2389 CGContextFillRect(context, NSRectToCGRect(r));
2288 } 2390 }
2289 } 2391 }
2290 2392
2291 - (void)drawRect:(NSRect)dirtyRect { 2393 - (void)drawRect:(NSRect)dirtyRect {
2292 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); 2394 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect");
2395 DCHECK(!renderWidgetHostView_->use_core_animation_);
2396
2293 if (!renderWidgetHostView_->render_widget_host_) { 2397 if (!renderWidgetHostView_->render_widget_host_) {
2294 // TODO(shess): Consider using something more noticable? 2398 // TODO(shess): Consider using something more noticable?
2295 [[NSColor whiteColor] set]; 2399 [[NSColor whiteColor] set];
2296 NSRectFill(dirtyRect); 2400 NSRectFill(dirtyRect);
2297 return; 2401 return;
2298 } 2402 }
2299 2403
2300 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); 2404 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_);
2301 2405
2302 // GetBackingStore works for both software and accelerated frames. If a 2406 // GetBackingStore works for both software and accelerated frames. If a
(...skipping 15 matching lines...) Expand all
2318 "h", damagedRect.height()); 2422 "h", damagedRect.height());
2319 // NSRectFill is extremely slow (15ms for a window on a fast MacPro), so 2423 // NSRectFill is extremely slow (15ms for a window on a fast MacPro), so
2320 // this is only done when it's a real invalidation from window damage (not 2424 // this is only done when it's a real invalidation from window damage (not
2321 // when a BuffersSwapped was received). Note that even a 1x1 NSRectFill 2425 // when a BuffersSwapped was received). Note that even a 1x1 NSRectFill
2322 // can take many milliseconds sometimes (!) so this is skipped completely 2426 // can take many milliseconds sometimes (!) so this is skipped completely
2323 // for drawRects that are triggered by BuffersSwapped messages. 2427 // for drawRects that are triggered by BuffersSwapped messages.
2324 [[NSColor clearColor] set]; 2428 [[NSColor clearColor] set];
2325 NSRectFill(dirtyRect); 2429 NSRectFill(dirtyRect);
2326 } 2430 }
2327 2431
2328 content::CompositingIOSurfaceMac::SurfaceOrder order =
2329 renderWidgetHostView_->allow_overlapping_views_
2330 ? content::CompositingIOSurfaceMac::SURFACE_ORDER_BELOW_WINDOW
2331 : content::CompositingIOSurfaceMac::SURFACE_ORDER_ABOVE_WINDOW;
2332 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( 2432 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(
2333 self, 2433 renderWidgetHostView_.get());
2334 ScaleFactor(self),
2335 renderWidgetHostView_->window_number(),
2336 order,
2337 renderWidgetHostView_->frame_subscriber());
2338 return; 2434 return;
2339 } 2435 }
2340 2436
2437 CGContextRef context = static_cast<CGContextRef>(
2438 [[NSGraphicsContext currentContext] graphicsPort]);
2439 [self drawBackingStore:backingStore
2440 dirtyRect:NSRectToCGRect(dirtyRect)
2441 inContext:context];
2442 }
2443
2444 - (void)drawBackingStore:(BackingStoreMac*)backingStore
2445 dirtyRect:(CGRect)dirtyRect
2446 inContext:(CGContextRef)context {
2447
sail 2013/05/31 23:59:14 remove new line?
Avi (use Gerrit) 2013/05/31 23:59:58 no blank line
ccameron 2013/06/01 00:29:45 Done.
2341 if (backingStore) { 2448 if (backingStore) {
2342 // Note: All coordinates are in view units, not pixels. 2449 // Note: All coordinates are in view units, not pixels.
2343 gfx::Rect bitmapRect(0, 0, 2450 gfx::Rect bitmapRect(0, 0,
2344 backingStore->size().width(), 2451 backingStore->size().width(),
2345 backingStore->size().height()); 2452 backingStore->size().height());
2346 2453
2347 // Specify the proper y offset to ensure that the view is rooted to the 2454 // Specify the proper y offset to ensure that the view is rooted to the
2348 // upper left corner. This can be negative, if the window was resized 2455 // upper left corner. This can be negative, if the window was resized
2349 // smaller and the renderer hasn't yet repainted. 2456 // smaller and the renderer hasn't yet repainted.
2350 int yOffset = NSHeight([self bounds]) - backingStore->size().height(); 2457 int yOffset = NSHeight([self bounds]) - backingStore->size().height();
2351 2458
2459 NSRect nsDirtyRect = NSMakeRect(dirtyRect.origin.x,
2460 dirtyRect.origin.y,
2461 dirtyRect.size.width,
2462 dirtyRect.size.height);
2463 const gfx::Rect damagedRect([self flipNSRectToRect:nsDirtyRect]);
2464
2352 gfx::Rect paintRect = gfx::IntersectRects(bitmapRect, damagedRect); 2465 gfx::Rect paintRect = gfx::IntersectRects(bitmapRect, damagedRect);
2353 if (!paintRect.IsEmpty()) { 2466 if (!paintRect.IsEmpty()) {
2354 // if we have a CGLayer, draw that into the window 2467 // if we have a CGLayer, draw that into the window
2355 if (backingStore->cg_layer()) { 2468 if (backingStore->cg_layer()) {
2356 CGContextRef context = static_cast<CGContextRef>(
2357 [[NSGraphicsContext currentContext] graphicsPort]);
2358
2359 // TODO: add clipping to dirtyRect if it improves drawing performance. 2469 // TODO: add clipping to dirtyRect if it improves drawing performance.
2360 CGContextDrawLayerAtPoint(context, CGPointMake(0.0, yOffset), 2470 CGContextDrawLayerAtPoint(context, CGPointMake(0.0, yOffset),
2361 backingStore->cg_layer()); 2471 backingStore->cg_layer());
2362 } else { 2472 } else {
2363 // if we haven't created a layer yet, draw the cached bitmap into 2473 // if we haven't created a layer yet, draw the cached bitmap into
2364 // the window. The CGLayer will be created the next time the renderer 2474 // the window. The CGLayer will be created the next time the renderer
2365 // paints. 2475 // paints.
2366 CGContextRef context = static_cast<CGContextRef>(
2367 [[NSGraphicsContext currentContext] graphicsPort]);
2368 base::mac::ScopedCFTypeRef<CGImageRef> image( 2476 base::mac::ScopedCFTypeRef<CGImageRef> image(
2369 CGBitmapContextCreateImage(backingStore->cg_bitmap())); 2477 CGBitmapContextCreateImage(backingStore->cg_bitmap()));
2370 CGRect imageRect = bitmapRect.ToCGRect(); 2478 CGRect imageRect = bitmapRect.ToCGRect();
2371 imageRect.origin.y = yOffset; 2479 imageRect.origin.y = yOffset;
2372 CGContextDrawImage(context, imageRect, image); 2480 CGContextDrawImage(context, imageRect, image);
2373 } 2481 }
2374 } 2482 }
2375 2483
2376 // Fill the remaining portion of the damagedRect with white 2484 // Fill the remaining portion of the damagedRect with white
2377 [self fillBottomRightRemainderOfRect:bitmapRect dirtyRect:damagedRect]; 2485 [self fillBottomRightRemainderOfRect:bitmapRect
2486 dirtyRect:damagedRect
2487 inContext:context];
2378 2488
2379 if (!renderWidgetHostView_->whiteout_start_time_.is_null()) { 2489 if (!renderWidgetHostView_->whiteout_start_time_.is_null()) {
2380 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - 2490 base::TimeDelta whiteout_duration = base::TimeTicks::Now() -
2381 renderWidgetHostView_->whiteout_start_time_; 2491 renderWidgetHostView_->whiteout_start_time_;
2382 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); 2492 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration);
2383 2493
2384 // Reset the start time to 0 so that we start recording again the next 2494 // Reset the start time to 0 so that we start recording again the next
2385 // time the backing store is NULL... 2495 // time the backing store is NULL...
2386 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks(); 2496 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks();
2387 } 2497 }
2388 if (!renderWidgetHostView_->web_contents_switch_paint_time_.is_null()) { 2498 if (!renderWidgetHostView_->web_contents_switch_paint_time_.is_null()) {
2389 base::TimeDelta web_contents_switch_paint_duration = 2499 base::TimeDelta web_contents_switch_paint_duration =
2390 base::TimeTicks::Now() - 2500 base::TimeTicks::Now() -
2391 renderWidgetHostView_->web_contents_switch_paint_time_; 2501 renderWidgetHostView_->web_contents_switch_paint_time_;
2392 UMA_HISTOGRAM_TIMES("MPArch.RWH_TabSwitchPaintDuration", 2502 UMA_HISTOGRAM_TIMES("MPArch.RWH_TabSwitchPaintDuration",
2393 web_contents_switch_paint_duration); 2503 web_contents_switch_paint_duration);
2394 // Reset contents_switch_paint_time_ to 0 so future tab selections are 2504 // Reset contents_switch_paint_time_ to 0 so future tab selections are
2395 // recorded. 2505 // recorded.
2396 renderWidgetHostView_->web_contents_switch_paint_time_ = 2506 renderWidgetHostView_->web_contents_switch_paint_time_ =
2397 base::TimeTicks(); 2507 base::TimeTicks();
2398 } 2508 }
2399 } else { 2509 } else {
2400 [[NSColor whiteColor] set]; 2510 CGContextSetFillColorWithColor(context,
2401 NSRectFill(dirtyRect); 2511 CGColorGetConstantColor(kCGColorWhite));
2512 CGContextFillRect(context, dirtyRect);
2402 if (renderWidgetHostView_->whiteout_start_time_.is_null()) 2513 if (renderWidgetHostView_->whiteout_start_time_.is_null())
2403 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks::Now(); 2514 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks::Now();
2404 } 2515 }
2405 } 2516 }
2406 2517
2407 - (BOOL)canBecomeKeyView { 2518 - (BOOL)canBecomeKeyView {
2408 if (!renderWidgetHostView_->render_widget_host_) 2519 if (!renderWidgetHostView_->render_widget_host_)
2409 return NO; 2520 return NO;
2410 2521
2411 return canBeKeyView_; 2522 return canBeKeyView_;
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
3364 return; 3475 return;
3365 3476
3366 currentCursor_.reset([cursor retain]); 3477 currentCursor_.reset([cursor retain]);
3367 [[self window] invalidateCursorRectsForView:self]; 3478 [[self window] invalidateCursorRectsForView:self];
3368 } 3479 }
3369 3480
3370 - (void)popupWindowWillClose:(NSNotification *)notification { 3481 - (void)popupWindowWillClose:(NSNotification *)notification {
3371 renderWidgetHostView_->KillSelf(); 3482 renderWidgetHostView_->KillSelf();
3372 } 3483 }
3373 3484
3485 - (void)updateSoftwareLayerScaleFactor {
3486 if (![softwareLayer_ respondsToSelector:@selector(setContentsScale:)])
3487 return;
3488
3489 ScopedCAActionDisabler disabler;
3490 [softwareLayer_ setContentsScale:deviceScaleFactor_];
3491 }
3492
3493 // Delegate methods for the software CALayer
3494 - (void)drawLayer:(CALayer*)layer
3495 inContext:(CGContextRef)context {
3496 DCHECK(renderWidgetHostView_->use_core_animation_);
3497 DCHECK([layer isEqual:softwareLayer_]);
3498
3499 CGRect clipRect = CGContextGetClipBoundingBox(context);
3500
3501 if (!renderWidgetHostView_->render_widget_host_ ||
3502 renderWidgetHostView_->is_hidden()) {
3503 CGContextSetFillColorWithColor(context,
3504 CGColorGetConstantColor(kCGColorWhite));
3505 CGContextFillRect(context, clipRect);
3506 return;
3507 }
3508
3509 renderWidgetHostView_->about_to_validate_and_paint_ = true;
3510 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>(
3511 renderWidgetHostView_->render_widget_host_->GetBackingStore(true));
3512 renderWidgetHostView_->about_to_validate_and_paint_ = false;
3513
3514 [self drawBackingStore:backingStore
3515 dirtyRect:clipRect
3516 inContext:context];
3517 }
3518
3519 - (void)setNeedsDisplay:(BOOL)flag {
3520 [softwareLayer_ setNeedsDisplay];
3521 [super setNeedsDisplay:flag];
3522 }
3523
3524 - (void)setNeedsDisplayInRect:(NSRect)rect {
3525 [softwareLayer_ setNeedsDisplayInRect:NSRectToCGRect(rect)];
3526 [super setNeedsDisplayInRect:rect];
3527 }
3528
3374 @end 3529 @end
3375 3530
3376 // 3531 //
3377 // Supporting application services 3532 // Supporting application services
3378 // 3533 //
3379 @implementation RenderWidgetHostViewCocoa(NSServicesRequests) 3534 @implementation RenderWidgetHostViewCocoa(NSServicesRequests)
3380 3535
3381 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard 3536 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard
3382 types:(NSArray*)types { 3537 types:(NSArray*)types {
3383 const std::string& str = renderWidgetHostView_->selected_text(); 3538 const std::string& str = renderWidgetHostView_->selected_text();
(...skipping 10 matching lines...) Expand all
3394 NSString *string = [pboard stringForType:NSStringPboardType]; 3549 NSString *string = [pboard stringForType:NSStringPboardType];
3395 if (!string) return NO; 3550 if (!string) return NO;
3396 3551
3397 // If the user is currently using an IME, confirm the IME input, 3552 // If the user is currently using an IME, confirm the IME input,
3398 // and then insert the text from the service, the same as TextEdit and Safari. 3553 // and then insert the text from the service, the same as TextEdit and Safari.
3399 [self confirmComposition]; 3554 [self confirmComposition];
3400 [self insertText:string]; 3555 [self insertText:string];
3401 return YES; 3556 return YES;
3402 } 3557 }
3403 3558
3559 - (BOOL)isOpaque {
3560 if (renderWidgetHostView_->use_core_animation_)
3561 return YES;
3562 return [super isOpaque];
3563 }
3564
3404 @end 3565 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698