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

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

Issue 2093113003: Clean up the RWHVMac to ui::Compositor interface (phase 1 of 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up destroy, rebase Created 4 years, 5 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 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 "content/browser/renderer_host/delegated_frame_host.h"
11 #include "ui/compositor/compositor.h" 12 #include "ui/compositor/compositor.h"
12 #include "ui/compositor/compositor_observer.h" 13 #include "ui/compositor/compositor_observer.h"
13 14
14 namespace ui { 15 namespace ui {
15 class AcceleratedWidgetMac; 16 class AcceleratedWidgetMac;
17 class AcceleratedWidgetMacNSView;
16 } 18 }
17 19
18 namespace content { 20 namespace content {
19 21
20 // A ui::Compositor and a gfx::AcceleratedWidget (and helper) that it draws 22 class RecyclableCompositorMac;
21 // into. This structure is used to efficiently recycle these structures across 23
22 // tabs (because creating a new ui::Compositor for each tab would be expensive 24
23 // in terms of time and resources). 25 // This class owns a DelegatedFrameHost, and will dynamically attach and
24 class BrowserCompositorMac : public ui::CompositorObserver { 26 // detach it from a ui::Compositor as needed. The ui::Compositor will be
27 // detached from the DelegatedFrameHost when the following conditions are
28 // all met:
29 // - There are no outstanding copy requests
30 // - The RenderWidgetHostImpl providing frames to the DelegatedFrameHost
31 // is visible.
32 // - The RenderWidgetHostViewMac that is used to display these frames is
33 // attached to the NSView hierarchy of an NSWindow.
34 class BrowserCompositorMac {
25 public: 35 public:
26 virtual ~BrowserCompositorMac(); 36 BrowserCompositorMac(
37 ui::AcceleratedWidgetMacNSView* accelerated_widget_mac_ns_view,
38 DelegatedFrameHostClient* delegated_frame_host_client,
39 bool render_widget_host_is_hidden,
40 bool ns_view_attached_to_window);
41 ~BrowserCompositorMac();
27 42
28 // Create a compositor, or recycle a preexisting one. 43 // This must be called before the destructor.
29 static std::unique_ptr<BrowserCompositorMac> Create(); 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();
30 48
31 // Delete a compositor, or allow it to be recycled. 49 // These will not return nullptr until Destroy is called.
32 static void Recycle(std::unique_ptr<BrowserCompositorMac> compositor); 50 ui::Layer* GetRootLayer();
51 DelegatedFrameHost* GetDelegatedFrameHost();
52
53 // This may return nullptr, if this has detached itself from its
54 // ui::Compositor.
55 ui::AcceleratedWidgetMac* GetAcceleratedWidgetMac();
56
57 void SwapCompositorFrame(uint32_t output_surface_id,
58 cc::CompositorFrame frame,
59 bool render_widget_host_is_hidden);
60 void SetHasTransparentBackground(bool transparent);
61 void UpdateVSyncParameters(const base::TimeTicks& timebase,
62 const base::TimeDelta& interval);
63
64 // This is used to ensure that the ui::Compositor be attached to the
65 // DelegatedFrameHost while the RWHImpl is visible.
66 // 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
68 // initiate copies occur before the ui::Compositor be detached.
69 void SetRenderWidgetHostIsHidden(bool hidden);
70
71 // 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
73 // hidden (e.g, because it is occluded by another window).
74 void SetNSViewAttachedToWindow(bool attached);
75
76 // These functions will track the number of outstanding copy requests, and
77 // will not allow the ui::Compositor to be detached until all outstanding
78 // copies have returned.
79 void CopyFromCompositingSurface(const gfx::Rect& src_subrect,
80 const gfx::Size& dst_size,
81 const ReadbackRequestCallback& callback,
82 SkColorType preferred_color_type);
83 void CopyFromCompositingSurfaceToVideoFrame(
84 const gfx::Rect& src_subrect,
85 const scoped_refptr<media::VideoFrame>& target,
86 const base::Callback<void(const gfx::Rect&, bool)>& callback);
33 87
34 // Indicate that the recyclable compositor should be destroyed, and no future 88 // Indicate that the recyclable compositor should be destroyed, and no future
35 // compositors should be recycled. 89 // compositors should be recycled.
36 static void DisableRecyclingForShutdown(); 90 static void DisableRecyclingForShutdown();
37 91
38 ui::Compositor* compositor() { return &compositor_; } 92 private:
39 ui::AcceleratedWidgetMac* accelerated_widget_mac() { 93 // The state of |delegated_frame_host_| and |recyclable_compositor_| to
40 return accelerated_widget_mac_.get(); 94 // manage being visible, hidden, or occluded.
41 } 95 enum State {
96 // Effects:
97 // - |recyclable_compositor_| exists and is attached to
98 // |delegated_frame_host_|.
99 // Happens when:
100 // - |render_widet_host_| is in the visible state, or there are
101 // outstanding copy requests.
102 HasAttachedCompositor,
103 // Effects:
104 // - |recyclable_compositor_| exists, but |delegated_frame_host_| is
105 // hidden and detached from it.
106 // Happens when:
107 // - The |render_widget_host_| is hidden, but |cocoa_view_| is still in the
108 // NSWindow hierarchy (e.g, when the window is occluded or offscreen).
109 // - Note: In this state, |recyclable_compositor_| and its CALayers are kept
110 // around so that we will have content to show when we are un-occluded. If
111 // we had a way to keep the CALayers attached to the NSView while
112 // detaching the ui::Compositor, then there would be no need for this
113 HasDetachedCompositor,
114 // Effects:
115 // - |recyclable_compositor_| has been recycled and |delegated_frame_host_|
116 // is hidden and detached from it.
117 // Happens when:
118 // - The |render_widget_host_| hidden or gone, and |cocoa_view_| is not
119 // attached to an NSWindow.
120 // - This happens for backgrounded tabs.
121 HasNoCompositor,
122 };
123 State state_ = HasNoCompositor;
124 void UpdateState();
125 void TransitionToState(State new_state);
42 126
43 // Suspend will prevent the compositor from producing new frames. This should 127 static void CopyCompleted(
44 // be called to avoid creating spurious frames while changing state. 128 base::WeakPtr<BrowserCompositorMac> browser_compositor,
45 // Compositors are created as suspended. 129 const ReadbackRequestCallback& callback,
46 void Suspend(); 130 const SkBitmap& bitmap,
47 void Unsuspend(); 131 ReadbackResponse response);
132 static void CopyToVideoFrameCompleted(
133 base::WeakPtr<BrowserCompositorMac> browser_compositor,
134 const base::Callback<void(const gfx::Rect&, bool)>& callback,
135 const gfx::Rect& rect,
136 bool result);
137 uint64_t outstanding_copy_count_ = 0;
48 138
49 private: 139 bool render_widget_host_is_hidden_ = true;
50 BrowserCompositorMac(); 140 bool ns_view_attached_to_window_ = false;
51 141
52 // ui::CompositorObserver implementation: 142 ui::AcceleratedWidgetMacNSView* accelerated_widget_mac_ns_view_ = nullptr;
53 void OnCompositingDidCommit(ui::Compositor* compositor) override; 143 std::unique_ptr<RecyclableCompositorMac> recyclable_compositor_;
54 void OnCompositingStarted(ui::Compositor* compositor,
55 base::TimeTicks start_time) override {}
56 void OnCompositingEnded(ui::Compositor* compositor) override {}
57 void OnCompositingAborted(ui::Compositor* compositor) override {}
58 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {}
59 void OnCompositingShuttingDown(ui::Compositor* compositor) override {}
60 144
61 std::unique_ptr<ui::AcceleratedWidgetMac> accelerated_widget_mac_; 145 std::unique_ptr<DelegatedFrameHost> delegated_frame_host_;
62 ui::Compositor compositor_; 146 std::unique_ptr<ui::Layer> root_layer_;
63 scoped_refptr<ui::CompositorLock> compositor_suspended_lock_;
64 147
65 DISALLOW_COPY_AND_ASSIGN(BrowserCompositorMac); 148 bool has_transparent_background_ = false;
66 };
67 149
68 // A class to keep around whenever a BrowserCompositorMac may be created. 150 bool has_been_destroyed_ = false;
69 // While at least one instance of this class exists, a spare
70 // BrowserCompositorViewCocoa will be kept around to be recycled so that the
71 // next BrowserCompositorMac to be created will be be created quickly.
72 class BrowserCompositorMacPlaceholder {
73 public:
74 BrowserCompositorMacPlaceholder();
75 ~BrowserCompositorMacPlaceholder();
76 151
77 private: 152 base::WeakPtrFactory<BrowserCompositorMac> weak_factory_;
78 DISALLOW_COPY_AND_ASSIGN(BrowserCompositorMacPlaceholder);
79 }; 153 };
80 154
81 } // namespace content 155 } // namespace content
82 156
83 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_COMPOSITOR_VIEW_MAC_H_ 157 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_COMPOSITOR_VIEW_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698