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

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

Issue 294023012: Use a separate NSView to draw browser composited content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments, clean-u Created 6 years, 7 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
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 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/mac/scoped_nsobject.h" 15 #include "base/mac/scoped_nsobject.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "content/browser/compositor/delegated_frame_host.h" 19 #include "content/browser/compositor/delegated_frame_host.h"
20 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
20 #include "content/browser/renderer_host/display_link_mac.h" 21 #include "content/browser/renderer_host/display_link_mac.h"
21 #include "content/browser/renderer_host/render_widget_host_view_base.h" 22 #include "content/browser/renderer_host/render_widget_host_view_base.h"
22 #include "content/browser/renderer_host/software_frame_manager.h" 23 #include "content/browser/renderer_host/software_frame_manager.h"
23 #include "content/common/content_export.h" 24 #include "content/common/content_export.h"
24 #include "content/common/cursors/webcursor.h" 25 #include "content/common/cursors/webcursor.h"
25 #include "content/common/edit_command.h" 26 #include "content/common/edit_command.h"
26 #import "content/public/browser/render_widget_host_view_mac_base.h" 27 #import "content/public/browser/render_widget_host_view_mac_base.h"
27 #include "ipc/ipc_sender.h" 28 #include "ipc/ipc_sender.h"
28 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 29 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
29 #include "ui/base/cocoa/base_view.h" 30 #include "ui/base/cocoa/base_view.h"
30 31
31 namespace content { 32 namespace content {
32 class CompositingIOSurfaceMac; 33 class CompositingIOSurfaceMac;
33 class CompositingIOSurfaceContext; 34 class CompositingIOSurfaceContext;
34 class RenderWidgetHostViewMac; 35 class RenderWidgetHostViewMac;
35 class RenderWidgetHostViewMacEditCommandHelper; 36 class RenderWidgetHostViewMacEditCommandHelper;
36 class WebContents; 37 class WebContents;
37 } 38 }
38 39
39 namespace ui { 40 namespace ui {
40 class Compositor; 41 class Compositor;
41 class Layer; 42 class Layer;
42 } 43 }
43 44
45 @class BrowserCompositorViewMac;
44 @class CompositingIOSurfaceLayer; 46 @class CompositingIOSurfaceLayer;
45 @class FullscreenWindowManager; 47 @class FullscreenWindowManager;
46 @protocol RenderWidgetHostViewMacDelegate; 48 @protocol RenderWidgetHostViewMacDelegate;
49 @class SoftwareLayer;
47 @class ToolTip; 50 @class ToolTip;
48 51
49 @protocol RenderWidgetHostViewMacOwner 52 @protocol RenderWidgetHostViewMacOwner
50 - (content::RenderWidgetHostViewMac*)renderWidgetHostViewMac; 53 - (content::RenderWidgetHostViewMac*)renderWidgetHostViewMac;
51 @end 54 @end
52 55
53 // This is the view that lives in the Cocoa view hierarchy. In Windows-land, 56 // This is the view that lives in the Cocoa view hierarchy. In Windows-land,
54 // RenderWidgetHostViewWin is both the view and the delegate. We split the roles 57 // RenderWidgetHostViewWin is both the view and the delegate. We split the roles
55 // but that means that the view needs to own the delegate and will dispose of it 58 // but that means that the view needs to own the delegate and will dispose of it
56 // when it's removed from the view system. 59 // when it's removed from the view system.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // Updates the current plugin focus state. 182 // Updates the current plugin focus state.
180 - (void)pluginFocusChanged:(BOOL)focused forPlugin:(int)pluginId; 183 - (void)pluginFocusChanged:(BOOL)focused forPlugin:(int)pluginId;
181 // Evaluates the event in the context of plugin IME, if plugin IME is enabled. 184 // Evaluates the event in the context of plugin IME, if plugin IME is enabled.
182 // Returns YES if the event was handled. 185 // Returns YES if the event was handled.
183 - (BOOL)postProcessEventForPluginIme:(NSEvent*)event; 186 - (BOOL)postProcessEventForPluginIme:(NSEvent*)event;
184 - (void)updateCursor:(NSCursor*)cursor; 187 - (void)updateCursor:(NSCursor*)cursor;
185 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange 188 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange
186 actualRange:(NSRangePointer)actualRange; 189 actualRange:(NSRangePointer)actualRange;
187 @end 190 @end
188 191
189 @interface SoftwareLayer : CALayer
190
191 - (id)init;
192
193 - (void)setContentsToData:(const void *)data
194 withRowBytes:(size_t)rowBytes
195 withPixelSize:(gfx::Size)pixelSize
196 withScaleFactor:(float)scaleFactor;
197
198 // Remove the layer from the layer hierarchy.
199 - (void)disableRendering;
200
201 @end
202
203 namespace content { 192 namespace content {
204 class RenderWidgetHostImpl; 193 class RenderWidgetHostImpl;
205 194
206 /////////////////////////////////////////////////////////////////////////////// 195 ///////////////////////////////////////////////////////////////////////////////
207 // RenderWidgetHostViewMac 196 // RenderWidgetHostViewMac
208 // 197 //
209 // An object representing the "View" of a rendered web page. This object is 198 // An object representing the "View" of a rendered web page. This object is
210 // responsible for displaying the content of the web page, and integrating with 199 // responsible for displaying the content of the web page, and integrating with
211 // the Cocoa view system. It is the implementation of the RenderWidgetHostView 200 // the Cocoa view system. It is the implementation of the RenderWidgetHostView
212 // that the cross-platform RenderWidgetHost object uses 201 // that the cross-platform RenderWidgetHost object uses
213 // to display the data. 202 // to display the data.
214 // 203 //
215 // Comment excerpted from render_widget_host.h: 204 // Comment excerpted from render_widget_host.h:
216 // 205 //
217 // "The lifetime of the RenderWidgetHost* is tied to the render process. 206 // "The lifetime of the RenderWidgetHost* is tied to the render process.
218 // If the render process dies, the RenderWidgetHost* goes away and all 207 // If the render process dies, the RenderWidgetHost* goes away and all
219 // references to it must become NULL." 208 // references to it must become NULL."
220 // 209 //
221 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h. 210 // RenderWidgetHostView class hierarchy described in render_widget_host_view.h.
222 class CONTENT_EXPORT RenderWidgetHostViewMac 211 class CONTENT_EXPORT RenderWidgetHostViewMac
223 : public RenderWidgetHostViewBase, 212 : public RenderWidgetHostViewBase,
224 public DelegatedFrameHostClient, 213 public DelegatedFrameHostClient,
225 public IPC::Sender, 214 public IPC::Sender,
226 public SoftwareFrameManagerClient { 215 public SoftwareFrameManagerClient,
216 public CompositingIOSurfaceLayerClient {
227 public: 217 public:
228 // The view will associate itself with the given widget. The native view must 218 // The view will associate itself with the given widget. The native view must
229 // be hooked up immediately to the view hierarchy, or else when it is 219 // be hooked up immediately to the view hierarchy, or else when it is
230 // deleted it will delete this out from under the caller. 220 // deleted it will delete this out from under the caller.
231 explicit RenderWidgetHostViewMac(RenderWidgetHost* widget); 221 explicit RenderWidgetHostViewMac(RenderWidgetHost* widget);
232 virtual ~RenderWidgetHostViewMac(); 222 virtual ~RenderWidgetHostViewMac();
233 223
234 RenderWidgetHostViewCocoa* cocoa_view() const { return cocoa_view_; } 224 RenderWidgetHostViewCocoa* cocoa_view() const { return cocoa_view_; }
235 225
236 // |delegate| is used to separate out the logic from the NSResponder delegate. 226 // |delegate| is used to separate out the logic from the NSResponder delegate.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // IPC::Sender implementation. 336 // IPC::Sender implementation.
347 virtual bool Send(IPC::Message* message) OVERRIDE; 337 virtual bool Send(IPC::Message* message) OVERRIDE;
348 338
349 // SoftwareFrameManagerClient implementation: 339 // SoftwareFrameManagerClient implementation:
350 virtual void SoftwareFrameWasFreed( 340 virtual void SoftwareFrameWasFreed(
351 uint32 output_surface_id, unsigned frame_id) OVERRIDE; 341 uint32 output_surface_id, unsigned frame_id) OVERRIDE;
352 virtual void ReleaseReferencesToSoftwareFrame() OVERRIDE; 342 virtual void ReleaseReferencesToSoftwareFrame() OVERRIDE;
353 343
354 virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE; 344 virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE;
355 345
346 // CompositingIOSurfaceLayerClient implementation.
347 virtual void AcceleratedLayerDidDrawFrame(bool succeeded) OVERRIDE;
348 virtual bool AcceleratedLayerHasNotAckedPendingFrame() const OVERRIDE;
349
356 // Forwards the mouse event to the renderer. 350 // Forwards the mouse event to the renderer.
357 void ForwardMouseEvent(const blink::WebMouseEvent& event); 351 void ForwardMouseEvent(const blink::WebMouseEvent& event);
358 352
359 void KillSelf(); 353 void KillSelf();
360 354
361 void SetTextInputActive(bool active); 355 void SetTextInputActive(bool active);
362 356
363 // Sends completed plugin IME notification and text back to the renderer. 357 // Sends completed plugin IME notification and text back to the renderer.
364 void PluginImeCompositionCompleted(const base::string16& text, int plugin_id); 358 void PluginImeCompositionCompleted(const base::string16& text, int plugin_id);
365 359
366 const std::string& selected_text() const { return selected_text_; } 360 const std::string& selected_text() const { return selected_text_; }
367 361
368 // Update the IOSurface to be drawn and call setNeedsDisplay on 362 // Update the IOSurface to be drawn and call setNeedsDisplay on
369 // |cocoa_view_|. 363 // |cocoa_view_|.
370 void CompositorSwapBuffers(uint64 surface_handle, 364 void CompositorSwapBuffers(uint64 surface_handle,
371 const gfx::Size& size, 365 const gfx::Size& size,
372 float scale_factor, 366 float scale_factor,
373 const std::vector<ui::LatencyInfo>& latency_info); 367 const std::vector<ui::LatencyInfo>& latency_info);
374 368
375 void GotBrowserCompositorSoftwareFrame(cc::SoftwareFrameData* frame_data,
376 float scale_factor,
377 SkCanvas* canvas);
378
379 // Draw the IOSurface by making its context current to this view. 369 // Draw the IOSurface by making its context current to this view.
380 void DrawIOSurfaceWithoutCoreAnimation(); 370 void DrawIOSurfaceWithoutCoreAnimation();
381 371
382 // Called when a GPU error is detected. Posts a task to destroy all 372 // Called when a GPU error is detected. Posts a task to destroy all
383 // compositing state. 373 // compositing state.
384 void GotAcceleratedCompositingError(); 374 void GotAcceleratedCompositingError();
385 375
386 // Sets the overlay view, which should be drawn in the same IOSurface 376 // Sets the overlay view, which should be drawn in the same IOSurface
387 // atop of this view, if both views are drawing accelerated content. 377 // atop of this view, if both views are drawing accelerated content.
388 // Overlay is stored as a weak ptr. 378 // Overlay is stored as a weak ptr.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // The compositing or software layers will be added as sublayers to this. 434 // The compositing or software layers will be added as sublayers to this.
445 base::scoped_nsobject<CALayer> background_layer_; 435 base::scoped_nsobject<CALayer> background_layer_;
446 436
447 // The CoreAnimation layer for software compositing. This should be NULL 437 // The CoreAnimation layer for software compositing. This should be NULL
448 // when software compositing is not in use. 438 // when software compositing is not in use.
449 base::scoped_nsobject<SoftwareLayer> software_layer_; 439 base::scoped_nsobject<SoftwareLayer> software_layer_;
450 440
451 // Accelerated compositing structures. These may be dynamically created and 441 // Accelerated compositing structures. These may be dynamically created and
452 // destroyed together in Create/DestroyCompositedIOSurfaceAndLayer. 442 // destroyed together in Create/DestroyCompositedIOSurfaceAndLayer.
453 base::scoped_nsobject<CompositingIOSurfaceLayer> compositing_iosurface_layer_; 443 base::scoped_nsobject<CompositingIOSurfaceLayer> compositing_iosurface_layer_;
454 scoped_ptr<CompositingIOSurfaceMac> compositing_iosurface_; 444 scoped_refptr<CompositingIOSurfaceMac> compositing_iosurface_;
455 scoped_refptr<CompositingIOSurfaceContext> compositing_iosurface_context_; 445 scoped_refptr<CompositingIOSurfaceContext> compositing_iosurface_context_;
456 446
457 // Timer used to dynamically transition the compositing layer in and out of
458 // asynchronous mode.
459 base::DelayTimer<RenderWidgetHostViewMac>
460 compositing_iosurface_layer_async_timer_;
461
462 // Delegated frame management and compositior. 447 // Delegated frame management and compositior.
448 base::scoped_nsobject<BrowserCompositorViewMac> browser_compositor_view_;
463 scoped_ptr<DelegatedFrameHost> delegated_frame_host_; 449 scoped_ptr<DelegatedFrameHost> delegated_frame_host_;
464 scoped_ptr<ui::Compositor> compositor_;
465 scoped_ptr<ui::Layer> root_layer_; 450 scoped_ptr<ui::Layer> root_layer_;
466 451
467 // This holds the current software compositing framebuffer, if any. 452 // This holds the current software compositing framebuffer, if any.
468 scoped_ptr<SoftwareFrameManager> software_frame_manager_; 453 scoped_ptr<SoftwareFrameManager> software_frame_manager_;
469 454
470 // Whether to allow overlapping views. 455 // Whether to allow overlapping views.
471 bool allow_overlapping_views_; 456 bool allow_overlapping_views_;
472 457
473 // Whether to use the CoreAnimation path to draw content. 458 // Whether to use the CoreAnimation path to draw content.
474 bool use_core_animation_; 459 bool use_core_animation_;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 void SendPendingSwapAck(); 506 void SendPendingSwapAck();
522 507
523 void PauseForPendingResizeOrRepaintsAndDraw(); 508 void PauseForPendingResizeOrRepaintsAndDraw();
524 509
525 // The geometric arrangement of the layers depends on cocoa_view's size, the 510 // The geometric arrangement of the layers depends on cocoa_view's size, the
526 // compositing IOSurface's rounded size, and the software frame size. Update 511 // compositing IOSurface's rounded size, and the software frame size. Update
527 // all of them using this function when any of those parameters changes. Also 512 // all of them using this function when any of those parameters changes. Also
528 // update the scale factor of the layers. 513 // update the scale factor of the layers.
529 void LayoutLayers(); 514 void LayoutLayers();
530 515
531 bool HasPendingSwapAck() const { return pending_swap_ack_; }
532
533 // DelegatedFrameHostClient implementation. 516 // DelegatedFrameHostClient implementation.
534 virtual ui::Compositor* GetCompositor() const OVERRIDE; 517 virtual ui::Compositor* GetCompositor() const OVERRIDE;
535 virtual ui::Layer* GetLayer() OVERRIDE; 518 virtual ui::Layer* GetLayer() OVERRIDE;
536 virtual RenderWidgetHostImpl* GetHost() OVERRIDE; 519 virtual RenderWidgetHostImpl* GetHost() OVERRIDE;
537 virtual void SchedulePaintInRect( 520 virtual void SchedulePaintInRect(
538 const gfx::Rect& damage_rect_in_dip) OVERRIDE; 521 const gfx::Rect& damage_rect_in_dip) OVERRIDE;
539 virtual bool IsVisible() OVERRIDE; 522 virtual bool IsVisible() OVERRIDE;
540 virtual scoped_ptr<ResizeLock> CreateResizeLock( 523 virtual scoped_ptr<ResizeLock> CreateResizeLock(
541 bool defer_compositor_lock) OVERRIDE; 524 bool defer_compositor_lock) OVERRIDE;
542 virtual gfx::Size DesiredFrameSize() OVERRIDE; 525 virtual gfx::Size DesiredFrameSize() OVERRIDE;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 571
589 // Unbind the GL context (if any) that is bound to |cocoa_view_|. 572 // Unbind the GL context (if any) that is bound to |cocoa_view_|.
590 void ClearBoundContextDrawable(); 573 void ClearBoundContextDrawable();
591 574
592 // Called when a GPU SwapBuffers is received. 575 // Called when a GPU SwapBuffers is received.
593 void GotAcceleratedFrame(); 576 void GotAcceleratedFrame();
594 577
595 // Called when a software DIB is received. 578 // Called when a software DIB is received.
596 void GotSoftwareFrame(); 579 void GotSoftwareFrame();
597 580
598 // Called if it has been a quarter-second since a GPU SwapBuffers has been
599 // received. In this case, switch from polling for frames to pushing them.
600 void TimerSinceGotAcceleratedFrameFired();
601
602 // IPC message handlers. 581 // IPC message handlers.
603 void OnPluginFocusChanged(bool focused, int plugin_id); 582 void OnPluginFocusChanged(bool focused, int plugin_id);
604 void OnStartPluginIme(); 583 void OnStartPluginIme();
605 void OnDidChangeScrollbarsForMainFrame(bool has_horizontal_scrollbar, 584 void OnDidChangeScrollbarsForMainFrame(bool has_horizontal_scrollbar,
606 bool has_vertical_scrollbar); 585 bool has_vertical_scrollbar);
607 586
608 // Convert |rect| from the views coordinate (upper-left origin) into 587 // Convert |rect| from the views coordinate (upper-left origin) into
609 // the OpenGL coordinate (lower-left origin) and scale for HiDPI displays. 588 // the OpenGL coordinate (lower-left origin) and scale for HiDPI displays.
610 gfx::Rect GetScaledOpenGLPixelRect(const gfx::Rect& rect); 589 gfx::Rect GetScaledOpenGLPixelRect(const gfx::Rect& rect);
611 590
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_; 652 scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_;
674 653
675 base::WeakPtrFactory<RenderWidgetHostViewMac> 654 base::WeakPtrFactory<RenderWidgetHostViewMac>
676 software_frame_weak_ptr_factory_; 655 software_frame_weak_ptr_factory_;
677 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewMac); 656 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewMac);
678 }; 657 };
679 658
680 } // namespace content 659 } // namespace content
681 660
682 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_ 661 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698