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_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ | 5 #ifndef CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ |
6 #define CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ | 6 #define CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ |
7 | 7 |
8 #include <vector> | 8 #include "content/browser/compositor/browser_compositor_ca_layer_tree_mac.h" |
9 | |
10 #include "cc/output/software_frame_data.h" | |
11 #include "skia/ext/platform_canvas.h" | |
12 #include "ui/compositor/compositor.h" | 9 #include "ui/compositor/compositor.h" |
13 #include "ui/events/latency_info.h" | |
14 #include "ui/gfx/geometry/size.h" | |
15 | 10 |
16 namespace content { | 11 namespace content { |
17 | 12 |
18 class BrowserCompositorCALayerTreeMac; | 13 // A ui::Compositor and a gfx::AcceleratedWidget (and helper) that it draws |
14 // into. This structure is used to efficiently recycle these structures across | |
15 // tabs (because creating a new ui::Compositor for each tab would be expensive | |
16 // in terms of time and resources). | |
17 class BrowserCompositorMac { | |
18 public: | |
19 // Create a compositor, or recycle a preexisting one. | |
20 static BrowserCompositorMac* Create(); | |
tapted
2014/11/20 23:18:07
You can enforce the lifetime dealie by returning a
ccameron
2014/11/21 01:32:40
(hides head in shame). Done.
| |
19 | 21 |
20 // The interface through which BrowserCompositorViewMac calls back into | 22 // Delete a compositor, or allow it to be recycled. |
21 // RenderWidgetHostViewMac (or any other structure that wishes to draw a | 23 static void Recycle(BrowserCompositorMac* compositor); |
tapted
2014/11/20 23:18:07
and taking a scoped_ptr here (then see below)
ccameron
2014/11/21 01:32:40
(hides head further in shame). Done.
| |
22 // NSView backed by a ui::Compositor). | |
23 // TODO(ccameron): This interface should be in the ui namespace. | |
24 class BrowserCompositorViewMacClient { | |
25 public: | |
26 // Drawing is usually throttled by the rate at which CoreAnimation draws | |
27 // frames to the screen. This can be used to disable throttling. | |
28 virtual bool BrowserCompositorViewShouldAckImmediately() const = 0; | |
29 | 24 |
30 // Called when a frame is drawn, and used to pass latency info back to the | 25 ui::Compositor* compositor() { return &compositor_; } |
31 // renderer (if any). | 26 AcceleratedWidgetMac* accelerated_widget_mac() { |
32 virtual void BrowserCompositorViewFrameSwapped( | 27 return &accelerated_widget_mac_; |
33 const std::vector<ui::LatencyInfo>& latency_info) = 0; | 28 } |
29 | |
30 private: | |
31 BrowserCompositorMac(); | |
32 | |
33 AcceleratedWidgetMac accelerated_widget_mac_; | |
34 ui::Compositor compositor_; | |
35 | |
36 DISALLOW_COPY_AND_ASSIGN(BrowserCompositorMac); | |
34 }; | 37 }; |
35 | 38 |
36 // The class to hold the ui::Compositor which is used to draw a NSView. | 39 // A class to keep around whenever a BrowserCompositorMac may be created. |
37 // TODO(ccameron): This should implement an interface in the ui namespace. | 40 // While at least one instance of this class exists, a spare |
38 class BrowserCompositorViewMac { | 41 // BrowserCompositorViewCocoa will be kept around to be recycled so that the |
42 // next BrowserCompositorMac to be created will be be created quickly. | |
43 class BrowserCompositorMacPlaceholder { | |
39 public: | 44 public: |
40 // This will install the NSView which is drawn by the ui::Compositor into | 45 BrowserCompositorMacPlaceholder(); |
41 // the NSView provided by the client. Note that |client|, |native_view|, and | 46 ~BrowserCompositorMacPlaceholder(); |
42 // |ui_root_layer| outlive their BrowserCompositorViewMac object. | |
43 BrowserCompositorViewMac( | |
44 BrowserCompositorViewMacClient* client, | |
45 NSView* native_view, | |
46 ui::Layer* ui_root_layer); | |
47 ~BrowserCompositorViewMac(); | |
48 | |
49 BrowserCompositorViewMacClient* client() const { return client_; } | |
50 NSView* native_view() const { return native_view_; } | |
51 ui::Layer* ui_root_layer() const { return ui_root_layer_; } | |
52 | |
53 // The ui::Compositor being used to render the NSView. | |
54 // TODO(ccameron): This should be in the ui namespace interface. | |
55 ui::Compositor* GetCompositor() const; | |
56 | |
57 // Return true if the last frame swapped has a size in DIP of |dip_size|. | |
58 bool HasFrameOfSize(const gfx::Size& dip_size) const; | |
59 | |
60 // Mark a bracket in which new frames are pumped in a restricted nested run | |
61 // loop because the the target window is resizing or because the view is being | |
62 // shown after previously being hidden. | |
63 void BeginPumpingFrames(); | |
64 void EndPumpingFrames(); | |
65 | 47 |
66 private: | 48 private: |
67 BrowserCompositorViewMacClient* client_; | 49 DISALLOW_COPY_AND_ASSIGN(BrowserCompositorMacPlaceholder); |
68 NSView* native_view_; | |
69 ui::Layer* ui_root_layer_; | |
70 | |
71 // Because a ui::Compositor is expensive in terms of resources and | |
72 // re-allocating a ui::Compositor is expensive in terms of work, this class | |
73 // is largely used to manage recycled instances of | |
74 // BrowserCompositorCALayerTreeMac, which actually has a ui::Compositor | |
75 // instance and modifies the CALayers used to draw the NSView. | |
76 scoped_ptr<BrowserCompositorCALayerTreeMac> ca_layer_tree_; | |
77 }; | |
78 | |
79 // A class to keep around whenever a BrowserCompositorViewMac may be created. | |
80 // While at least one instance of this class exists, a spare | |
81 // BrowserCompositorViewCocoa will be kept around to be recycled so that the | |
82 // next BrowserCompositorViewMac to be created will be be created quickly. | |
83 class BrowserCompositorViewPlaceholderMac { | |
84 public: | |
85 BrowserCompositorViewPlaceholderMac(); | |
86 ~BrowserCompositorViewPlaceholderMac(); | |
87 }; | 50 }; |
88 | 51 |
89 } // namespace content | 52 } // namespace content |
90 | 53 |
91 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ | 54 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ |
OLD | NEW |