Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / compositor / browser_compositor_view_mac.h
blob28b824eedc9c80e6720012ac63285e7e9fec9564
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 "ui/accelerated_widget_mac/accelerated_widget_mac.h"
9 #include "ui/compositor/compositor.h"
10 #include "ui/compositor/compositor_observer.h"
12 namespace content {
14 // A ui::Compositor and a gfx::AcceleratedWidget (and helper) that it draws
15 // into. This structure is used to efficiently recycle these structures across
16 // tabs (because creating a new ui::Compositor for each tab would be expensive
17 // in terms of time and resources).
18 class BrowserCompositorMac : public ui::CompositorObserver {
19 public:
20 virtual ~BrowserCompositorMac();
22 // Create a compositor, or recycle a preexisting one.
23 static scoped_ptr<BrowserCompositorMac> Create();
25 // Delete a compositor, or allow it to be recycled.
26 static void Recycle(scoped_ptr<BrowserCompositorMac> compositor);
28 // Indicate that the recyclable compositor should be destroyed, and no future
29 // compositors should be recycled.
30 static void DisableRecyclingForShutdown();
32 ui::Compositor* compositor() { return &compositor_; }
33 ui::AcceleratedWidgetMac* accelerated_widget_mac() {
34 return accelerated_widget_mac_.get();
37 // Suspend will prevent the compositor from producing new frames. This should
38 // be called to avoid creating spurious frames while changing state.
39 // Compositors are created as suspended.
40 void Suspend();
41 void Unsuspend();
43 private:
44 BrowserCompositorMac();
46 // ui::CompositorObserver implementation:
47 void OnCompositingDidCommit(ui::Compositor* compositor) override;
48 void OnCompositingStarted(ui::Compositor* compositor,
49 base::TimeTicks start_time) override {}
50 void OnCompositingEnded(ui::Compositor* compositor) override {}
51 void OnCompositingAborted(ui::Compositor* compositor) override {}
52 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {}
53 void OnCompositingShuttingDown(ui::Compositor* compositor) override {}
55 scoped_ptr<ui::AcceleratedWidgetMac> accelerated_widget_mac_;
56 ui::Compositor compositor_;
57 scoped_refptr<ui::CompositorLock> compositor_suspended_lock_;
59 DISALLOW_COPY_AND_ASSIGN(BrowserCompositorMac);
62 // A class to keep around whenever a BrowserCompositorMac may be created.
63 // While at least one instance of this class exists, a spare
64 // BrowserCompositorViewCocoa will be kept around to be recycled so that the
65 // next BrowserCompositorMac to be created will be be created quickly.
66 class BrowserCompositorMacPlaceholder {
67 public:
68 BrowserCompositorMacPlaceholder();
69 ~BrowserCompositorMacPlaceholder();
71 private:
72 DISALLOW_COPY_AND_ASSIGN(BrowserCompositorMacPlaceholder);
75 } // namespace content
77 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_