diff options
Diffstat (limited to 'chromium/content/browser/renderer_host/render_widget_host_view_mac.h')
-rw-r--r-- | chromium/content/browser/renderer_host/render_widget_host_view_mac.h | 278 |
1 files changed, 142 insertions, 136 deletions
diff --git a/chromium/content/browser/renderer_host/render_widget_host_view_mac.h b/chromium/content/browser/renderer_host/render_widget_host_view_mac.h index b6825b07ab5..8fb2e4a5fe8 100644 --- a/chromium/content/browser/renderer_host/render_widget_host_view_mac.h +++ b/chromium/content/browser/renderer_host/render_widget_host_view_mac.h @@ -6,6 +6,7 @@ #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_MAC_H_ #import <Cocoa/Cocoa.h> +#include <IOSurface/IOSurfaceAPI.h> #include <list> #include <map> #include <string> @@ -16,26 +17,40 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" -#include "content/browser/accessibility/browser_accessibility_delegate_mac.h" +#include "content/browser/compositor/browser_compositor_view_mac.h" +#include "content/browser/compositor/delegated_frame_host.h" +#include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" +#include "content/browser/renderer_host/display_link_mac.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/renderer_host/software_frame_manager.h" +#include "content/common/content_export.h" +#include "content/common/cursors/webcursor.h" #include "content/common/edit_command.h" #import "content/public/browser/render_widget_host_view_mac_base.h" #include "ipc/ipc_sender.h" #include "third_party/WebKit/public/web/WebCompositionUnderline.h" #include "ui/base/cocoa/base_view.h" -#include "webkit/common/cursors/webcursor.h" + +struct ViewHostMsg_TextInputState_Params; namespace content { class CompositingIOSurfaceMac; class CompositingIOSurfaceContext; class RenderWidgetHostViewMac; class RenderWidgetHostViewMacEditCommandHelper; +class WebContents; +} + +namespace ui { +class Compositor; +class Layer; } +@class BrowserCompositorViewMac; @class CompositingIOSurfaceLayer; @class FullscreenWindowManager; @protocol RenderWidgetHostViewMacDelegate; +@class SoftwareLayer; @class ToolTip; @protocol RenderWidgetHostViewMacOwner @@ -49,11 +64,12 @@ class RenderWidgetHostViewMacEditCommandHelper; @interface RenderWidgetHostViewCocoa : BaseView <RenderWidgetHostViewMacBase, RenderWidgetHostViewMacOwner, - NSTextInputClient, - BrowserAccessibilityDelegateCocoa> { + NSTextInputClient> { @private scoped_ptr<content::RenderWidgetHostViewMac> renderWidgetHostView_; - NSObject<RenderWidgetHostViewMacDelegate>* delegate_; // weak + // This ivar is the cocoa delegate of the NSResponder. + base::scoped_nsobject<NSObject<RenderWidgetHostViewMacDelegate>> + responderDelegate_; BOOL canBeKeyView_; BOOL takesFocusOnlyOnMouseDown_; BOOL closeOnDeactivate_; @@ -196,14 +212,24 @@ class RenderWidgetHostImpl; // references to it must become NULL." // // RenderWidgetHostView class hierarchy described in render_widget_host_view.h. -class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, - public IPC::Sender, - public SoftwareFrameManagerClient { +class CONTENT_EXPORT RenderWidgetHostViewMac + : public RenderWidgetHostViewBase, + public DelegatedFrameHostClient, + public IPC::Sender, + public SoftwareFrameManagerClient, + public CompositingIOSurfaceLayerClient { public: + // The view will associate itself with the given widget. The native view must + // be hooked up immediately to the view hierarchy, or else when it is + // deleted it will delete this out from under the caller. + explicit RenderWidgetHostViewMac(RenderWidgetHost* widget); virtual ~RenderWidgetHostViewMac(); RenderWidgetHostViewCocoa* cocoa_view() const { return cocoa_view_; } + // |delegate| is used to separate out the logic from the NSResponder delegate. + // |delegate| is retained by this class. + // |delegate| should be set at most once. CONTENT_EXPORT void SetDelegate( NSObject<RenderWidgetHostViewMacDelegate>* delegate); void SetAllowOverlappingViews(bool overlapping); @@ -233,9 +259,9 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, virtual void SpeakSelection() OVERRIDE; virtual bool IsSpeaking() const OVERRIDE; virtual void StopSpeaking() OVERRIDE; - virtual void SetBackground(const SkBitmap& background) OVERRIDE; + virtual void SetBackgroundOpaque(bool opaque) OVERRIDE; - // Implementation of RenderWidgetHostViewPort. + // Implementation of RenderWidgetHostViewBase. virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) OVERRIDE; virtual void InitAsFullscreen( @@ -243,24 +269,17 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, virtual void WasShown() OVERRIDE; virtual void WasHidden() OVERRIDE; virtual void MovePluginWindows( - const gfx::Vector2d& scroll_offset, const std::vector<WebPluginGeometry>& moves) OVERRIDE; virtual void Focus() OVERRIDE; virtual void Blur() OVERRIDE; virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE; virtual void SetIsLoading(bool is_loading) OVERRIDE; - virtual void TextInputTypeChanged(ui::TextInputType type, - ui::TextInputMode input_mode, - bool can_compose_inline) OVERRIDE; + virtual void TextInputStateChanged( + const ViewHostMsg_TextInputState_Params& params) OVERRIDE; virtual void ImeCancelComposition() OVERRIDE; virtual void ImeCompositionRangeChanged( const gfx::Range& range, const std::vector<gfx::Rect>& character_bounds) OVERRIDE; - virtual void DidUpdateBackingStore( - const gfx::Rect& scroll_rect, - const gfx::Vector2d& scroll_delta, - const std::vector<gfx::Rect>& copy_rects, - const ui::LatencyInfo& latency_info) OVERRIDE; virtual void RenderProcessGone(base::TerminationStatus status, int error_code) OVERRIDE; virtual void Destroy() OVERRIDE; @@ -271,11 +290,11 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, virtual void SelectionBoundsChanged( const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE; virtual void ScrollOffsetChanged() OVERRIDE; - virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; virtual void CopyFromCompositingSurface( const gfx::Rect& src_subrect, const gfx::Size& dst_size, - const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE; + const base::Callback<void(bool, const SkBitmap&)>& callback, + SkBitmap::Config config) OVERRIDE; virtual void CopyFromCompositingSurfaceToVideoFrame( const gfx::Rect& src_subrect, const scoped_refptr<media::VideoFrame>& target, @@ -287,12 +306,13 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, virtual void EndFrameSubscription() OVERRIDE; virtual void OnSwapCompositorFrame( uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) OVERRIDE; - virtual void OnAcceleratedCompositingStateChange() OVERRIDE; virtual void AcceleratedSurfaceInitialized(int host_id, int route_id) OVERRIDE; - virtual void OnAccessibilityEvents( - const std::vector<AccessibilityHostMsg_EventParams>& params - ) OVERRIDE; + virtual void CreateBrowserAccessibilityManagerIfNeeded() OVERRIDE; + virtual gfx::Point AccessibilityOriginInScreen(const gfx::Rect& bounds) + OVERRIDE; + virtual void OnAccessibilitySetFocus(int acc_obj_id) OVERRIDE; + virtual void AccessibilityShowMenu(int acc_obj_id) OVERRIDE; virtual bool PostProcessEventForPluginIme( const NativeWebKeyboardEvent& event) OVERRIDE; @@ -305,19 +325,14 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, virtual void AcceleratedSurfaceSuspend() OVERRIDE; virtual void AcceleratedSurfaceRelease() OVERRIDE; virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE; - virtual void AboutToWaitForBackingStoreMsg() OVERRIDE; virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE; virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE; virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE; - virtual void SetHasHorizontalScrollbar( - bool has_horizontal_scrollbar) OVERRIDE; - virtual void SetScrollOffsetPinning( - bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE; virtual bool LockMouse() OVERRIDE; virtual void UnlockMouse() OVERRIDE; - virtual void UnhandledWheelEvent( - const blink::WebMouseWheelEvent& event) OVERRIDE; + virtual void WheelEventAck(const blink::WebMouseWheelEvent& event, + InputEventAckState ack_result) OVERRIDE; // IPC::Sender implementation. virtual bool Send(IPC::Message* message) OVERRIDE; @@ -327,6 +342,11 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, uint32 output_surface_id, unsigned frame_id) OVERRIDE; virtual void ReleaseReferencesToSoftwareFrame() OVERRIDE; + virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE; + + // CompositingIOSurfaceLayerClient implementation. + virtual void AcceleratedLayerDidDrawFrame(bool succeeded) OVERRIDE; + // Forwards the mouse event to the renderer. void ForwardMouseEvent(const blink::WebMouseEvent& event); @@ -334,9 +354,6 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, void SetTextInputActive(bool active); - // Change this view to use CoreAnimation to draw. - void EnableCoreAnimation(); - // Sends completed plugin IME notification and text back to the renderer. void PluginImeCompositionCompleted(const base::string16& text, int plugin_id); @@ -344,15 +361,13 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, // Update the IOSurface to be drawn and call setNeedsDisplay on // |cocoa_view_|. - void CompositorSwapBuffers(uint64 surface_handle, + void CompositorSwapBuffers(IOSurfaceID surface_handle, const gfx::Size& size, float scale_factor, - const ui::LatencyInfo& latency_info); - - // Draw the IOSurface by making its context current to this view. - bool DrawIOSurfaceWithoutCoreAnimation(); + const std::vector<ui::LatencyInfo>& latency_info); - // Called when a GPU error is detected. Deletes all compositing state. + // Called when a GPU error is detected. Posts a task to destroy all + // compositing state. void GotAcceleratedCompositingError(); // Sets the overlay view, which should be drawn in the same IOSurface @@ -388,6 +403,8 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, gfx::Range ConvertCharacterRangeToCompositionRange( const gfx::Range& request_range); + WebContents* GetWebContents(); + // These member variables should be private, but the associated ObjC class // needs access to them and can't be made a friend. @@ -395,57 +412,35 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, // someone (other than superview) has retained |cocoa_view_|. RenderWidgetHostImpl* render_widget_host_; - // This is true when we are currently painting and thus should handle extra - // paint requests by expanding the invalid rect rather than actually painting. - bool about_to_validate_and_paint_; - - // This is true when we have already scheduled a call to - // |-callSetNeedsDisplayInRect:| but it has not been fulfilled yet. Used to - // prevent us from scheduling multiple calls. - bool call_set_needs_display_in_rect_pending_; - - // Whether last rendered frame was accelerated. - bool last_frame_was_accelerated_; - - // The invalid rect that needs to be painted by callSetNeedsDisplayInRect. - // This value is only meaningful when - // |call_set_needs_display_in_rect_pending_| is true. - NSRect invalid_rect_; - - // The time at which this view started displaying white pixels as a result of - // not having anything to paint (empty backing store from renderer). This - // value returns true for is_null() if we are not recording whiteout times. - base::TimeTicks whiteout_start_time_; - - // The time it took after this view was selected for it to be fully painted. - base::TimeTicks web_contents_switch_paint_time_; - // Current text input type. ui::TextInputType text_input_type_; bool can_compose_inline_; - base::scoped_nsobject<CALayer> software_layer_; + // The background CoreAnimation layer which is hosted by |cocoa_view_|. + // The compositing or software layers will be added as sublayers to this. + base::scoped_nsobject<CALayer> background_layer_; + + // The CoreAnimation layer for software compositing. This should be NULL + // when software compositing is not in use. + base::scoped_nsobject<SoftwareLayer> software_layer_; // Accelerated compositing structures. These may be dynamically created and // destroyed together in Create/DestroyCompositedIOSurfaceAndLayer. base::scoped_nsobject<CompositingIOSurfaceLayer> compositing_iosurface_layer_; - scoped_ptr<CompositingIOSurfaceMac> compositing_iosurface_; + scoped_refptr<CompositingIOSurfaceMac> compositing_iosurface_; scoped_refptr<CompositingIOSurfaceContext> compositing_iosurface_context_; + // Delegated frame management and compositior. + base::scoped_nsobject<BrowserCompositorViewMac> browser_compositor_view_; + scoped_ptr<DelegatedFrameHost> delegated_frame_host_; + scoped_ptr<ui::Layer> root_layer_; + // This holds the current software compositing framebuffer, if any. scoped_ptr<SoftwareFrameManager> software_frame_manager_; - // This is set when a new software frame is received and un-set when the - // frame's ack is sent back to the renderer. - bool software_frame_needs_to_send_ack_; - - // Whether to allow overlapping views. - bool allow_overlapping_views_; - - // Whether to use the CoreAnimation path to draw content. - bool use_core_animation_; - - ui::LatencyInfo software_latency_info_; + // Latency info to send back when the next frame appears on the + // screen. + std::vector<ui::LatencyInfo> pending_latency_info_; NSWindow* pepper_fullscreen_window() const { return pepper_fullscreen_window_; @@ -463,21 +458,61 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, int window_number() const; - float scale_factor() const; + // The scale factor for the screen that the view is currently on. + float ViewScaleFactor() const; - void FrameSwapped(); + // Update the scale factor for the backing store and for any CALayers. + void UpdateBackingStoreScaleFactor(); + + // Ensure that the display link is associated with the correct display. + void UpdateDisplayLink(); + + // The scale factor of the backing store. Note that this is updated based on + // ViewScaleFactor with some delay. + float backing_store_scale_factor_; + + void AddPendingLatencyInfo( + const std::vector<ui::LatencyInfo>& latency_info); + void SendPendingLatencyInfoToHost(); + + void SendPendingSwapAck(); + + void PauseForPendingResizeOrRepaintsAndDraw(); + + // The geometric arrangement of the layers depends on cocoa_view's size, the + // compositing IOSurface's rounded size, and the software frame size. Update + // all of them using this function when any of those parameters changes. Also + // update the scale factor of the layers. + void LayoutLayers(); + + // DelegatedFrameHostClient implementation. + virtual ui::Compositor* GetCompositor() const OVERRIDE; + virtual ui::Layer* GetLayer() OVERRIDE; + virtual RenderWidgetHostImpl* GetHost() OVERRIDE; + virtual void SchedulePaintInRect( + const gfx::Rect& damage_rect_in_dip) OVERRIDE; + virtual bool IsVisible() OVERRIDE; + virtual scoped_ptr<ResizeLock> CreateResizeLock( + bool defer_compositor_lock) OVERRIDE; + virtual gfx::Size DesiredFrameSize() OVERRIDE; + virtual float CurrentDeviceScaleFactor() OVERRIDE; + virtual gfx::Size ConvertViewSizeToPixel(const gfx::Size& size) OVERRIDE; + virtual DelegatedFrameHost* GetDelegatedFrameHost() const OVERRIDE; private: - friend class RenderWidgetHostView; friend class RenderWidgetHostViewMacTest; - void GetVSyncParameters( - base::TimeTicks* timebase, base::TimeDelta* interval); - - // The view will associate itself with the given widget. The native view must - // be hooked up immediately to the view hierarchy, or else when it is - // deleted it will delete this out from under the caller. - explicit RenderWidgetHostViewMac(RenderWidgetHost* widget); + struct PendingSwapAck { + PendingSwapAck(int32 route_id, int gpu_host_id, int32 renderer_id) + : route_id(route_id), + gpu_host_id(gpu_host_id), + renderer_id(renderer_id) {} + int32 route_id; + int gpu_host_id; + int32 renderer_id; + }; + scoped_ptr<PendingSwapAck> pending_swap_ack_; + void AddPendingSwapAck(int32 route_id, int gpu_host_id, int32 renderer_id); // Returns whether this render view is a popup (autocomplete window). bool IsPopup() const; @@ -486,17 +521,20 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, // invoke it from the message loop. void ShutdownHost(); - bool CreateCompositedIOSurface(); - bool CreateCompositedIOSurfaceLayer(); - enum DestroyContextBehavior { - kLeaveContextBoundToView, - kDestroyContext, + void EnsureSoftwareLayer(); + void DestroySoftwareLayer(); + + bool EnsureCompositedIOSurface() WARN_UNUSED_RESULT; + void EnsureCompositedIOSurfaceLayer(); + enum DestroyCompositedIOSurfaceLayerBehavior { + kLeaveLayerInHierarchy, + kRemoveLayerFromHierarchy, }; - void DestroyCompositedIOSurfaceAndLayer(DestroyContextBehavior - destroy_context_behavior); + void DestroyCompositedIOSurfaceLayer( + DestroyCompositedIOSurfaceLayerBehavior destroy_layer_behavior); + void DestroyCompositedIOSurfaceAndLayer(); - // Unbind the GL context (if any) that is bound to |cocoa_view_|. - void ClearBoundContextDrawable(); + void DestroyCompositingStateOnError(); // Called when a GPU SwapBuffers is received. void GotAcceleratedFrame(); @@ -504,32 +542,17 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, // Called when a software DIB is received. void GotSoftwareFrame(); - // Ack pending SwapBuffers requests, if any, to unblock the GPU process. Has - // no effect if there are no pending requests. - void AckPendingSwapBuffers(); - - // Ack pending SwapBuffers requests, but no more frequently than the vsync - // rate if the renderer is not throttling the swap rate. - void ThrottledAckPendingSwapBuffers(); - + // IPC message handlers. void OnPluginFocusChanged(bool focused, int plugin_id); void OnStartPluginIme(); - CONTENT_EXPORT void OnAcceleratedSurfaceSetIOSurface( - gfx::PluginWindowHandle window, - int32 width, - int32 height, - uint64 mach_port); - void OnAcceleratedSurfaceSetTransportDIB(gfx::PluginWindowHandle window, - int32 width, - int32 height, - TransportDIB::Handle transport_dib); - void OnAcceleratedSurfaceBuffersSwapped(gfx::PluginWindowHandle window, - uint64 surface_handle); // Convert |rect| from the views coordinate (upper-left origin) into // the OpenGL coordinate (lower-left origin) and scale for HiDPI displays. gfx::Rect GetScaledOpenGLPixelRect(const gfx::Rect& rect); + // Send updated vsync parameters to the renderer. + void SendVSyncParametersToRenderer(); + // The associated view. This is weak and is inserted into the view hierarchy // to own this RenderWidgetHostViewMac object. Set to nil at the start of the // destructor. @@ -556,39 +579,22 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase, // Our parent host view, if this is fullscreen. NULL otherwise. RenderWidgetHostViewMac* fullscreen_parent_host_view_; - // List of pending swaps for deferred acking: - // pairs of (route_id, gpu_host_id). - std::list<std::pair<int32, int32> > pending_swap_buffers_acks_; - - // Factory used to cancel outstanding throttled AckPendingSwapBuffers calls. - base::WeakPtrFactory<RenderWidgetHostViewMac> - pending_swap_buffers_acks_weak_factory_; - // The overlay view which is rendered above this one in the same // accelerated IOSurface. // Overlay view has |underlay_view_| set to this view. base::WeakPtr<RenderWidgetHostViewMac> overlay_view_; - // Offset at which overlay view should be rendered. - gfx::Point overlay_view_offset_; - // The underlay view which this view is rendered above in the same // accelerated IOSurface. // Underlay view has |overlay_view_| set to this view. base::WeakPtr<RenderWidgetHostViewMac> underlay_view_; - // Set to true when |underlay_view_| has drawn this view. After that point, - // this view should not draw again until |underlay_view_| is changed. - bool underlay_view_has_drawn_; - // Factory used to safely reference overlay view set in SetOverlayView. base::WeakPtrFactory<RenderWidgetHostViewMac> overlay_view_weak_factory_; - // The earliest time at which the next swap ack may be sent. Only relevant - // when swaps are not being throttled by the renderer (when threaded - // compositing is off). - base::Time next_swap_ack_time_; + // Display link for getting vsync info. + scoped_refptr<DisplayLinkMac> display_link_; // The current composition character range and its bounds. gfx::Range composition_range_; |