Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / compositor / browser_compositor_view_mac.h
blob619aef55eddff458c65bafc4b6e243abac507bf2
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_
6 #define CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_
8 #include <vector>
10 #include "cc/output/software_frame_data.h"
11 #include "skia/ext/platform_canvas.h"
12 #include "ui/compositor/compositor.h"
13 #include "ui/events/latency_info.h"
14 #include "ui/gfx/geometry/size.h"
16 namespace content {
18 class BrowserCompositorCALayerTreeMac;
20 // The interface through which BrowserCompositorViewMac calls back into
21 // RenderWidgetHostViewMac (or any other structure that wishes to draw a
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;
30 // Called when a frame is drawn, and used to pass latency info back to the
31 // renderer (if any).
32 virtual void BrowserCompositorViewFrameSwapped(
33 const std::vector<ui::LatencyInfo>& latency_info) = 0;
36 // The class to hold the ui::Compositor which is used to draw a NSView.
37 // TODO(ccameron): This should implement an interface in the ui namespace.
38 class BrowserCompositorViewMac {
39 public:
40 // This will install the NSView which is drawn by the ui::Compositor into
41 // the NSView provided by the client. Note that |client|, |native_view|, and
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();
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_; }
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;
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;
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();
66 private:
67 BrowserCompositorViewMacClient* client_;
68 NSView* native_view_;
69 ui::Layer* ui_root_layer_;
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_;
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();
89 } // namespace content
91 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_