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