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"
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
{
19 ~BrowserCompositorMac();
21 // Create a compositor, or recycle a preexisting one.
22 static scoped_ptr
<BrowserCompositorMac
> Create();
24 // Delete a compositor, or allow it to be recycled.
25 static void Recycle(scoped_ptr
<BrowserCompositorMac
> compositor
);
27 // Indicate that the recyclable compositor should be destroyed, and no future
28 // compositors should be recycled.
29 static void DisableRecyclingForShutdown();
31 ui::Compositor
* compositor() { return &compositor_
; }
32 ui::AcceleratedWidgetMac
* accelerated_widget_mac() {
33 return accelerated_widget_mac_
.get();
36 // Suspend will prevent the compositor from producing new frames. This should
37 // be called to avoid creating spurious frames while changing state.
38 // Compositors are created as suspended.
43 BrowserCompositorMac();
45 scoped_ptr
<ui::AcceleratedWidgetMac
> accelerated_widget_mac_
;
46 ui::Compositor compositor_
;
47 scoped_refptr
<ui::CompositorLock
> compositor_suspended_lock_
;
49 DISALLOW_COPY_AND_ASSIGN(BrowserCompositorMac
);
52 // A class to keep around whenever a BrowserCompositorMac may be created.
53 // While at least one instance of this class exists, a spare
54 // BrowserCompositorViewCocoa will be kept around to be recycled so that the
55 // next BrowserCompositorMac to be created will be be created quickly.
56 class BrowserCompositorMacPlaceholder
{
58 BrowserCompositorMacPlaceholder();
59 ~BrowserCompositorMacPlaceholder();
62 DISALLOW_COPY_AND_ASSIGN(BrowserCompositorMacPlaceholder
);
65 } // namespace content
67 #endif // CONTENT_BROWSER_COMPOSITOR_BROWSER_COMPOSITOR_VIEW_MAC_H_