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 <vector> |
9 | 9 |
10 #include "cc/output/software_frame_data.h" | 10 #include "cc/output/software_frame_data.h" |
11 #include "skia/ext/platform_canvas.h" | 11 #include "skia/ext/platform_canvas.h" |
12 #include "ui/compositor/compositor.h" | 12 #include "ui/compositor/compositor.h" |
13 #include "ui/events/latency_info.h" | 13 #include "ui/events/latency_info.h" |
14 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 class BrowserCompositorCALayerTreeMac; | 18 class BrowserCompositorCALayerTreeMac; |
19 | 19 |
20 // The interface through which BrowserCompositorViewMac calls back into | 20 // The interface through which BrowserCompositorViewMac calls back into |
21 // RenderWidgetHostViewMac (or any other structure that wishes to draw a | 21 // RenderWidgetHostViewMac (or any other structure that wishes to draw a |
22 // NSView backed by a ui::Compositor). | 22 // NSView backed by a ui::Compositor). |
23 // TODO(ccameron): This interface should be in the ui namespace. | |
23 class BrowserCompositorViewMacClient { | 24 class BrowserCompositorViewMacClient { |
24 public: | 25 public: |
25 // Drawing is usually throttled by the rate at which CoreAnimation draws | 26 // Drawing is usually throttled by the rate at which CoreAnimation draws |
26 // frames to the screen. This can be used to disable throttling. | 27 // frames to the screen. This can be used to disable throttling. |
27 virtual bool BrowserCompositorViewShouldAckImmediately() const = 0; | 28 virtual bool BrowserCompositorViewShouldAckImmediately() const = 0; |
28 | 29 |
29 // Called when a frame is drawn, and used to pass latency info back to the | 30 // Called when a frame is drawn, and used to pass latency info back to the |
30 // renderer (if any). | 31 // renderer (if any). |
31 virtual void BrowserCompositorViewFrameSwapped( | 32 virtual void BrowserCompositorViewFrameSwapped( |
32 const std::vector<ui::LatencyInfo>& latency_info) = 0; | 33 const std::vector<ui::LatencyInfo>& latency_info) = 0; |
33 | |
34 // Used to install the ui::Compositor-backed NSView as a child of its parent | |
35 // view. | |
36 virtual NSView* BrowserCompositorSuperview() = 0; | |
37 | |
38 // Used to install the root ui::Layer into the ui::Compositor. | |
39 virtual ui::Layer* BrowserCompositorRootLayer() = 0; | |
40 }; | 34 }; |
41 | 35 |
42 // The class to hold a ui::Compositor-backed NSView. Because a ui::Compositor | 36 // The class to hold the ui::Compositor which is used to draw a NSView. |
43 // is expensive in terms of resources and re-allocating a ui::Compositor is | 37 // TODO(ccameron): This should implement an interface in the ui namespace. |
44 // expensive in terms of work, this class is largely used to manage recycled | |
45 // instances of BrowserCompositorViewCocoa, which actually is a NSView and | |
46 // has a ui::Compositor instance. | |
47 class BrowserCompositorViewMac { | 38 class BrowserCompositorViewMac { |
48 public: | 39 public: |
49 // This will install the NSView which is drawn by the ui::Compositor into | 40 // This will install the NSView which is drawn by the ui::Compositor into |
50 // the NSView provided by the client. | 41 // the NSView provided by the client. Note that |client|, |native_view|, and |
51 explicit BrowserCompositorViewMac(BrowserCompositorViewMacClient* client); | 42 // |ui_root_layer| outlive their BrowserCompositorViewMac object. |
43 BrowserCompositorViewMac( | |
44 BrowserCompositorViewMacClient* client, | |
45 NSView* native_view, | |
46 ui::Layer* ui_root_layer); | |
52 ~BrowserCompositorViewMac(); | 47 ~BrowserCompositorViewMac(); |
53 | 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 | |
54 // The ui::Compositor being used to render the NSView. | 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; | 55 ui::Compositor* GetCompositor() const; |
danakj
2014/10/17 00:30:33
I wanna make sure we're on the right path and i'm
ccameron
2014/10/17 00:40:14
The NSView that owns this will be calling SetSizeA
danakj
2014/10/17 00:44:14
OK. The NSView doesn't exist yet right? I guess it
ccameron
2014/10/17 01:06:38
Ah -- the NSView exists -- this class then goes in
danakj
2014/10/18 18:42:01
OK. Maybe it would make sense to do that messing a
| |
56 | 56 |
57 // The client (used by the BrowserCompositorViewCocoa to access the client). | |
58 BrowserCompositorViewMacClient* GetClient() const { return client_; } | |
59 | |
60 // Return true if the last frame swapped has a size in DIP of |dip_size|. | 57 // Return true if the last frame swapped has a size in DIP of |dip_size|. |
58 // TODO(ccameron): This should be in the ui namespace interface. | |
61 bool HasFrameOfSize(const gfx::Size& dip_size) const; | 59 bool HasFrameOfSize(const gfx::Size& dip_size) const; |
danakj
2014/10/17 00:30:33
Similarly can you give a brief example or handwavi
ccameron
2014/10/17 00:40:13
The frame pumping bit is useful for making sure th
danakj
2014/10/17 00:44:14
OK thanks. Ya I'd add it when we need it.
ccameron
2014/10/17 01:06:38
K -- removed the TODOs for these guys.
| |
62 | 60 |
63 // Mark a bracket in which new frames are pumped in a restricted nested run | 61 // Mark a bracket in which new frames are pumped in a restricted nested run |
64 // loop because the the target window is resizing or because the view is being | 62 // loop because the the target window is resizing or because the view is being |
65 // shown after previously being hidden. | 63 // shown after previously being hidden. |
64 // TODO(ccameron): This should be in the ui namespace interface. | |
66 void BeginPumpingFrames(); | 65 void BeginPumpingFrames(); |
67 void EndPumpingFrames(); | 66 void EndPumpingFrames(); |
68 | 67 |
69 static void GotAcceleratedFrame( | |
70 gfx::AcceleratedWidget widget, | |
71 uint64 surface_handle, int surface_id, | |
72 const std::vector<ui::LatencyInfo>& latency_info, | |
73 gfx::Size pixel_size, float scale_factor, | |
74 int gpu_host_id, int gpu_route_id); | |
75 | |
76 static void GotSoftwareFrame( | |
77 gfx::AcceleratedWidget widget, | |
78 cc::SoftwareFrameData* frame_data, float scale_factor, SkCanvas* canvas); | |
79 | |
80 private: | 68 private: |
81 BrowserCompositorViewMacClient* client_; | 69 BrowserCompositorViewMacClient* client_; |
70 NSView* native_view_; | |
71 ui::Layer* ui_root_layer_; | |
72 | |
73 // Because a ui::Compositor is expensive in terms of resources and | |
74 // re-allocating a ui::Compositor is expensive in terms of work, this class | |
75 // is largely used to manage recycled instances of | |
76 // BrowserCompositorCALayerTreeMac, which actually has a ui::Compositor | |
77 // instance and modifies the CALayers used to draw the NSView. | |
82 scoped_ptr<BrowserCompositorCALayerTreeMac> ca_layer_tree_; | 78 scoped_ptr<BrowserCompositorCALayerTreeMac> ca_layer_tree_; |
83 }; | 79 }; |
84 | 80 |
85 // A class to keep around whenever a BrowserCompositorViewMac may be created. | 81 // A class to keep around whenever a BrowserCompositorViewMac may be created. |
86 // While at least one instance of this class exists, a spare | 82 // While at least one instance of this class exists, a spare |
87 // BrowserCompositorViewCocoa will be kept around to be recycled so that the | 83 // BrowserCompositorViewCocoa will be kept around to be recycled so that the |
88 // next BrowserCompositorViewMac to be created will be be created quickly. | 84 // next BrowserCompositorViewMac to be created will be be created quickly. |
89 class BrowserCompositorViewPlaceholderMac { | 85 class BrowserCompositorViewPlaceholderMac { |
90 public: | 86 public: |
91 BrowserCompositorViewPlaceholderMac(); | 87 BrowserCompositorViewPlaceholderMac(); |
92 ~BrowserCompositorViewPlaceholderMac(); | 88 ~BrowserCompositorViewPlaceholderMac(); |
93 }; | 89 }; |
94 | 90 |
95 } // namespace content | 91 } // namespace content |
96 | 92 |
97 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ | 93 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ |
OLD | NEW |