| 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; |
| 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|. |
| 61 bool HasFrameOfSize(const gfx::Size& dip_size) const; | 58 bool HasFrameOfSize(const gfx::Size& dip_size) const; |
| 62 | 59 |
| 63 // Mark a bracket in which new frames are pumped in a restricted nested run | 60 // 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 | 61 // loop because the the target window is resizing or because the view is being |
| 65 // shown after previously being hidden. | 62 // shown after previously being hidden. |
| 66 void BeginPumpingFrames(); | 63 void BeginPumpingFrames(); |
| 67 void EndPumpingFrames(); | 64 void EndPumpingFrames(); |
| 68 | 65 |
| 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: | 66 private: |
| 81 BrowserCompositorViewMacClient* client_; | 67 BrowserCompositorViewMacClient* client_; |
| 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. |
| 82 scoped_ptr<BrowserCompositorCALayerTreeMac> ca_layer_tree_; | 76 scoped_ptr<BrowserCompositorCALayerTreeMac> ca_layer_tree_; |
| 83 }; | 77 }; |
| 84 | 78 |
| 85 // A class to keep around whenever a BrowserCompositorViewMac may be created. | 79 // A class to keep around whenever a BrowserCompositorViewMac may be created. |
| 86 // While at least one instance of this class exists, a spare | 80 // While at least one instance of this class exists, a spare |
| 87 // BrowserCompositorViewCocoa will be kept around to be recycled so that the | 81 // BrowserCompositorViewCocoa will be kept around to be recycled so that the |
| 88 // next BrowserCompositorViewMac to be created will be be created quickly. | 82 // next BrowserCompositorViewMac to be created will be be created quickly. |
| 89 class BrowserCompositorViewPlaceholderMac { | 83 class BrowserCompositorViewPlaceholderMac { |
| 90 public: | 84 public: |
| 91 BrowserCompositorViewPlaceholderMac(); | 85 BrowserCompositorViewPlaceholderMac(); |
| 92 ~BrowserCompositorViewPlaceholderMac(); | 86 ~BrowserCompositorViewPlaceholderMac(); |
| 93 }; | 87 }; |
| 94 | 88 |
| 95 } // namespace content | 89 } // namespace content |
| 96 | 90 |
| 97 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ | 91 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_ |
| OLD | NEW |