| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BROWSER_COMPOSITOR_VIEW_MAC_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_BROWSER_COMPOSITOR_VIEW_MAC_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_BROWSER_COMPOSITOR_VIEW_MAC_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_BROWSER_COMPOSITOR_VIEW_MAC_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "cc/scheduler/begin_frame_source.h" |
| 11 #include "content/browser/renderer_host/delegated_frame_host.h" | 12 #include "content/browser/renderer_host/delegated_frame_host.h" |
| 12 #include "ui/compositor/compositor.h" | 13 #include "ui/compositor/compositor.h" |
| 13 #include "ui/compositor/compositor_observer.h" | 14 #include "ui/compositor/compositor_observer.h" |
| 14 | 15 |
| 15 namespace ui { | 16 namespace ui { |
| 16 class AcceleratedWidgetMac; | 17 class AcceleratedWidgetMac; |
| 17 class AcceleratedWidgetMacNSView; | 18 class AcceleratedWidgetMacNSView; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 class RecyclableCompositorMac; | 23 class RecyclableCompositorMac; |
| 23 | 24 |
| 25 class BrowserCompositorMacClient { |
| 26 public: |
| 27 virtual NSView* BrowserCompositorMacGetNSView() const = 0; |
| 28 virtual SkColor BrowserCompositorMacGetGutterColor(SkColor color) const = 0; |
| 29 virtual void BrowserCompositorMacSendCompositorSwapAck( |
| 30 int output_surface_id, |
| 31 const cc::CompositorFrameAck& ack) = 0; |
| 32 virtual void BrowserCompositorMacSendReclaimCompositorResources( |
| 33 int output_surface_id, |
| 34 const cc::CompositorFrameAck& ack) = 0; |
| 35 virtual void BrowserCompositorMacOnLostCompositorResources() = 0; |
| 36 virtual void BrowserCompositorMacUpdateVSyncParameters( |
| 37 const base::TimeTicks& timebase, |
| 38 const base::TimeDelta& interval) = 0; |
| 39 virtual void BrowserCompositorMacSendBeginFrame( |
| 40 const cc::BeginFrameArgs& args) = 0; |
| 41 }; |
| 24 | 42 |
| 25 // This class owns a DelegatedFrameHost, and will dynamically attach and | 43 // This class owns a DelegatedFrameHost, and will dynamically attach and |
| 26 // detach it from a ui::Compositor as needed. The ui::Compositor will be | 44 // detach it from a ui::Compositor as needed. The ui::Compositor will be |
| 27 // detached from the DelegatedFrameHost when the following conditions are | 45 // detached from the DelegatedFrameHost when the following conditions are |
| 28 // all met: | 46 // all met: |
| 29 // - There are no outstanding copy requests | 47 // - There are no outstanding copy requests |
| 30 // - The RenderWidgetHostImpl providing frames to the DelegatedFrameHost | 48 // - The RenderWidgetHostImpl providing frames to the DelegatedFrameHost |
| 31 // is visible. | 49 // is visible. |
| 32 // - The RenderWidgetHostViewMac that is used to display these frames is | 50 // - The RenderWidgetHostViewMac that is used to display these frames is |
| 33 // attached to the NSView hierarchy of an NSWindow. | 51 // attached to the NSView hierarchy of an NSWindow. |
| 34 class BrowserCompositorMac { | 52 class BrowserCompositorMac : public cc::BeginFrameObserver, |
| 53 public DelegatedFrameHostClient { |
| 35 public: | 54 public: |
| 36 BrowserCompositorMac( | 55 BrowserCompositorMac( |
| 37 ui::AcceleratedWidgetMacNSView* accelerated_widget_mac_ns_view, | 56 ui::AcceleratedWidgetMacNSView* accelerated_widget_mac_ns_view, |
| 38 DelegatedFrameHostClient* delegated_frame_host_client, | 57 BrowserCompositorMacClient* client, |
| 39 bool render_widget_host_is_hidden, | 58 bool render_widget_host_is_hidden, |
| 40 bool ns_view_attached_to_window); | 59 bool ns_view_attached_to_window); |
| 41 ~BrowserCompositorMac(); | 60 ~BrowserCompositorMac() override; |
| 42 | |
| 43 // This must be called before the destructor. | |
| 44 // TODO(ccameron): This is because the RWHVMac is still the | |
| 45 // DelegatedFrameHostClient. When that is cleaned up, this can be rolled | |
| 46 // into the destructor. | |
| 47 void Destroy(); | |
| 48 | 61 |
| 49 // These will not return nullptr until Destroy is called. | 62 // These will not return nullptr until Destroy is called. |
| 50 ui::Layer* GetRootLayer(); | |
| 51 DelegatedFrameHost* GetDelegatedFrameHost(); | 63 DelegatedFrameHost* GetDelegatedFrameHost(); |
| 52 | 64 |
| 53 // This may return nullptr, if this has detached itself from its | 65 // This may return nullptr, if this has detached itself from its |
| 54 // ui::Compositor. | 66 // ui::Compositor. |
| 55 ui::AcceleratedWidgetMac* GetAcceleratedWidgetMac(); | 67 ui::AcceleratedWidgetMac* GetAcceleratedWidgetMac(); |
| 56 | 68 |
| 57 void SwapCompositorFrame(uint32_t output_surface_id, | 69 void SwapCompositorFrame(uint32_t output_surface_id, |
| 58 cc::CompositorFrame frame); | 70 cc::CompositorFrame frame); |
| 59 void SetHasTransparentBackground(bool transparent); | 71 void SetHasTransparentBackground(bool transparent); |
| 60 void UpdateVSyncParameters(const base::TimeTicks& timebase, | 72 void UpdateVSyncParameters(const base::TimeTicks& timebase, |
| 61 const base::TimeDelta& interval); | 73 const base::TimeDelta& interval); |
| 74 void SetNeedsBeginFrames(bool needs_begin_frames); |
| 62 | 75 |
| 63 // This is used to ensure that the ui::Compositor be attached to the | 76 // This is used to ensure that the ui::Compositor be attached to the |
| 64 // DelegatedFrameHost while the RWHImpl is visible. | 77 // DelegatedFrameHost while the RWHImpl is visible. |
| 65 // Note: This should be called before the RWHImpl is made visible and after | 78 // Note: This should be called before the RWHImpl is made visible and after |
| 66 // it has been hidden, in order to ensure that thumbnailer notifications to | 79 // it has been hidden, in order to ensure that thumbnailer notifications to |
| 67 // initiate copies occur before the ui::Compositor be detached. | 80 // initiate copies occur before the ui::Compositor be detached. |
| 68 void SetRenderWidgetHostIsHidden(bool hidden); | 81 void SetRenderWidgetHostIsHidden(bool hidden); |
| 69 | 82 |
| 70 // This is used to ensure that the ui::Compositor be attached to this | 83 // This is used to ensure that the ui::Compositor be attached to this |
| 71 // NSView while its contents may be visible on-screen, even if the RWHImpl is | 84 // NSView while its contents may be visible on-screen, even if the RWHImpl is |
| 72 // hidden (e.g, because it is occluded by another window). | 85 // hidden (e.g, because it is occluded by another window). |
| 73 void SetNSViewAttachedToWindow(bool attached); | 86 void SetNSViewAttachedToWindow(bool attached); |
| 74 | 87 |
| 75 // These functions will track the number of outstanding copy requests, and | 88 // These functions will track the number of outstanding copy requests, and |
| 76 // will not allow the ui::Compositor to be detached until all outstanding | 89 // will not allow the ui::Compositor to be detached until all outstanding |
| 77 // copies have returned. | 90 // copies have returned. |
| 78 void CopyFromCompositingSurface(const gfx::Rect& src_subrect, | 91 void CopyFromCompositingSurface(const gfx::Rect& src_subrect, |
| 79 const gfx::Size& dst_size, | 92 const gfx::Size& dst_size, |
| 80 const ReadbackRequestCallback& callback, | 93 const ReadbackRequestCallback& callback, |
| 81 SkColorType preferred_color_type); | 94 SkColorType preferred_color_type); |
| 82 void CopyFromCompositingSurfaceToVideoFrame( | 95 void CopyFromCompositingSurfaceToVideoFrame( |
| 83 const gfx::Rect& src_subrect, | 96 const gfx::Rect& src_subrect, |
| 84 const scoped_refptr<media::VideoFrame>& target, | 97 const scoped_refptr<media::VideoFrame>& target, |
| 85 const base::Callback<void(const gfx::Rect&, bool)>& callback); | 98 const base::Callback<void(const gfx::Rect&, bool)>& callback); |
| 86 | 99 |
| 87 // Indicate that the recyclable compositor should be destroyed, and no future | 100 // Indicate that the recyclable compositor should be destroyed, and no future |
| 88 // compositors should be recycled. | 101 // compositors should be recycled. |
| 89 static void DisableRecyclingForShutdown(); | 102 static void DisableRecyclingForShutdown(); |
| 90 | 103 |
| 104 // DelegatedFrameHostClient implementation. |
| 105 ui::Layer* DelegatedFrameHostGetLayer() const override; |
| 106 bool DelegatedFrameHostIsVisible() const override; |
| 107 SkColor DelegatedFrameHostGetGutterColor(SkColor color) const override; |
| 108 gfx::Size DelegatedFrameHostDesiredSizeInDIP() const override; |
| 109 bool DelegatedFrameCanCreateResizeLock() const override; |
| 110 std::unique_ptr<ResizeLock> DelegatedFrameHostCreateResizeLock( |
| 111 bool defer_compositor_lock) override; |
| 112 void DelegatedFrameHostResizeLockWasReleased() override; |
| 113 void DelegatedFrameHostSendCompositorSwapAck( |
| 114 int output_surface_id, |
| 115 const cc::CompositorFrameAck& ack) override; |
| 116 void DelegatedFrameHostSendReclaimCompositorResources( |
| 117 int output_surface_id, |
| 118 const cc::CompositorFrameAck& ack) override; |
| 119 void DelegatedFrameHostOnLostCompositorResources() override; |
| 120 void DelegatedFrameHostUpdateVSyncParameters( |
| 121 const base::TimeTicks& timebase, |
| 122 const base::TimeDelta& interval) override; |
| 123 void SetBeginFrameSource(cc::BeginFrameSource* source) override; |
| 124 |
| 125 // cc::BeginFrameObserver implementation. |
| 126 void OnBeginFrame(const cc::BeginFrameArgs& args) override; |
| 127 const cc::BeginFrameArgs& LastUsedBeginFrameArgs() const override; |
| 128 void OnBeginFrameSourcePausedChanged(bool paused) override; |
| 129 |
| 91 private: | 130 private: |
| 92 // The state of |delegated_frame_host_| and |recyclable_compositor_| to | 131 // The state of |delegated_frame_host_| and |recyclable_compositor_| to |
| 93 // manage being visible, hidden, or occluded. | 132 // manage being visible, hidden, or occluded. |
| 94 enum State { | 133 enum State { |
| 95 // Effects: | 134 // Effects: |
| 96 // - |recyclable_compositor_| exists and is attached to | 135 // - |recyclable_compositor_| exists and is attached to |
| 97 // |delegated_frame_host_|. | 136 // |delegated_frame_host_|. |
| 98 // Happens when: | 137 // Happens when: |
| 99 // - |render_widet_host_| is in the visible state, or there are | 138 // - |render_widet_host_| is in the visible state, or there are |
| 100 // outstanding copy requests. | 139 // outstanding copy requests. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 131 static void CopyToVideoFrameCompleted( | 170 static void CopyToVideoFrameCompleted( |
| 132 base::WeakPtr<BrowserCompositorMac> browser_compositor, | 171 base::WeakPtr<BrowserCompositorMac> browser_compositor, |
| 133 const base::Callback<void(const gfx::Rect&, bool)>& callback, | 172 const base::Callback<void(const gfx::Rect&, bool)>& callback, |
| 134 const gfx::Rect& rect, | 173 const gfx::Rect& rect, |
| 135 bool result); | 174 bool result); |
| 136 uint64_t outstanding_copy_count_ = 0; | 175 uint64_t outstanding_copy_count_ = 0; |
| 137 | 176 |
| 138 bool render_widget_host_is_hidden_ = true; | 177 bool render_widget_host_is_hidden_ = true; |
| 139 bool ns_view_attached_to_window_ = false; | 178 bool ns_view_attached_to_window_ = false; |
| 140 | 179 |
| 180 BrowserCompositorMacClient* client_ = nullptr; |
| 141 ui::AcceleratedWidgetMacNSView* accelerated_widget_mac_ns_view_ = nullptr; | 181 ui::AcceleratedWidgetMacNSView* accelerated_widget_mac_ns_view_ = nullptr; |
| 142 std::unique_ptr<RecyclableCompositorMac> recyclable_compositor_; | 182 std::unique_ptr<RecyclableCompositorMac> recyclable_compositor_; |
| 143 | 183 |
| 144 std::unique_ptr<DelegatedFrameHost> delegated_frame_host_; | 184 std::unique_ptr<DelegatedFrameHost> delegated_frame_host_; |
| 145 std::unique_ptr<ui::Layer> root_layer_; | 185 std::unique_ptr<ui::Layer> root_layer_; |
| 146 | 186 |
| 147 bool has_transparent_background_ = false; | 187 bool has_transparent_background_ = false; |
| 148 | 188 |
| 149 bool has_been_destroyed_ = false; | 189 // The begin frame source being observed. Null if none. |
| 190 cc::BeginFrameSource* begin_frame_source_ = nullptr; |
| 191 cc::BeginFrameArgs last_begin_frame_args_; |
| 192 bool needs_begin_frames_ = false; |
| 150 | 193 |
| 151 base::WeakPtrFactory<BrowserCompositorMac> weak_factory_; | 194 base::WeakPtrFactory<BrowserCompositorMac> weak_factory_; |
| 152 }; | 195 }; |
| 153 | 196 |
| 154 } // namespace content | 197 } // namespace content |
| 155 | 198 |
| 156 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_COMPOSITOR_VIEW_MAC_H_ | 199 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_COMPOSITOR_VIEW_MAC_H_ |
| OLD | NEW |