Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1851)

Side by Side Diff: content/browser/compositor/browser_compositor_view_mac.mm

Issue 745453002: Create an AcceleratedWidgetMac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "content/browser/compositor/browser_compositor_view_mac.h" 5 #include "content/browser/compositor/browser_compositor_view_mac.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "content/browser/compositor/browser_compositor_ca_layer_tree_mac.h"
9 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 10 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
10 #include "content/browser/compositor/browser_compositor_ca_layer_tree_mac.h" 11 #include "content/browser/renderer_host/render_widget_resize_helper.h"
11 #include "content/common/gpu/gpu_messages.h" 12 #include "content/common/gpu/gpu_messages.h"
13 #include "content/public/browser/context_factory.h"
12 14
13 //////////////////////////////////////////////////////////////////////////////// 15 ////////////////////////////////////////////////////////////////////////////////
14 // BrowserCompositorViewMac 16 // BrowserCompositorMac
15 17
16 namespace content { 18 namespace content {
19
17 namespace { 20 namespace {
18 21
19 // The number of placeholder objects allocated. If this reaches zero, then 22 // The number of placeholder objects allocated. If this reaches zero, then
20 // the BrowserCompositorCALayerTreeMac being held on to for recycling, 23 // the BrowserCompositorMac being held on to for recycling,
21 // |g_recyclable_ca_layer_tree|, will be freed. 24 // |g_recyclable_browser_compositor|, will be freed.
22 uint32 g_placeholder_count = 0; 25 uint32 g_placeholder_count = 0;
23 26
24 // A spare BrowserCompositorCALayerTreeMac kept around for recycling. 27 // A spare BrowserCompositorMac kept around for recycling.
25 base::LazyInstance<scoped_ptr<BrowserCompositorCALayerTreeMac>> 28 base::LazyInstance<scoped_ptr<BrowserCompositorMac>>
26 g_recyclable_ca_layer_tree; 29 g_recyclable_browser_compositor;
27 30
28 } // namespace 31 } // namespace
29 32
30 BrowserCompositorViewMac::BrowserCompositorViewMac( 33 BrowserCompositorMac::BrowserCompositorMac()
31 BrowserCompositorViewMacClient* client, 34 : compositor_(
32 NSView* native_view, 35 accelerated_widget_mac_.accelerated_widget(),
33 ui::Layer* ui_root_layer) 36 content::GetContextFactory(),
34 : client_(client), 37 RenderWidgetResizeHelper::Get()->task_runner()) {
35 native_view_(native_view), 38 compositor_.SetVisible(false);
36 ui_root_layer_(ui_root_layer) {
37 // Try to use the recyclable BrowserCompositorCALayerTreeMac if there is one,
38 // otherwise allocate a new one.
39 // TODO(ccameron): If there exists a frame in flight (swap has been called
40 // by the compositor, but the frame has not arrived from the GPU process
41 // yet), then that frame may inappropriately flash in the new view.
42 ca_layer_tree_ = g_recyclable_ca_layer_tree.Get().Pass();
43 if (!ca_layer_tree_)
44 ca_layer_tree_.reset(new BrowserCompositorCALayerTreeMac);
45 ca_layer_tree_->SetView(this);
46 } 39 }
47 40
48 BrowserCompositorViewMac::~BrowserCompositorViewMac() { 41 // static
49 // Make this BrowserCompositorCALayerTreeMac recyclable for future instances. 42 void BrowserCompositorMac::AcquireCompositor(
50 ca_layer_tree_->ResetView(); 43 BrowserCompositorMac** compositor) {
51 g_recyclable_ca_layer_tree.Get() = ca_layer_tree_.Pass(); 44 if (g_recyclable_browser_compositor.Get())
45 *compositor = g_recyclable_browser_compositor.Get().release();
46 else
47 *compositor = new BrowserCompositorMac;
48 }
49
50 // static
51 void BrowserCompositorMac::ReleaseCompositor(
52 BrowserCompositorMac** compositor) {
53 // Make this BrowserCompositorMac recyclable for future instances.
54 g_recyclable_browser_compositor.Get().reset(*compositor);
55 *compositor = NULL;
52 56
53 // If there are no placeholders allocated, destroy the recyclable 57 // If there are no placeholders allocated, destroy the recyclable
54 // BrowserCompositorCALayerTreeMac that we just populated. 58 // BrowserCompositorMac that we just populated.
55 if (!g_placeholder_count) 59 if (!g_placeholder_count)
56 g_recyclable_ca_layer_tree.Get().reset(); 60 g_recyclable_browser_compositor.Get().reset();
57 } 61 }
58 62
59 ui::Compositor* BrowserCompositorViewMac::GetCompositor() const { 63 ui::Compositor* BrowserCompositorMac::compositor() {
60 DCHECK(ca_layer_tree_); 64 return &compositor_;
61 return ca_layer_tree_->compositor();
62 } 65 }
63 66
64 bool BrowserCompositorViewMac::HasFrameOfSize( 67 AcceleratedWidgetMac*
65 const gfx::Size& dip_size) const { 68 BrowserCompositorMac::accelerated_widget_mac() {
66 if (ca_layer_tree_) 69 return &accelerated_widget_mac_;
67 return ca_layer_tree_->HasFrameOfSize(dip_size);
68 return false;
69 } 70 }
70 71
71 void BrowserCompositorViewMac::BeginPumpingFrames() {
72 if (ca_layer_tree_)
73 ca_layer_tree_->BeginPumpingFrames();
74 }
75
76 void BrowserCompositorViewMac::EndPumpingFrames() {
77 if (ca_layer_tree_)
78 ca_layer_tree_->EndPumpingFrames();
79 }
80 72
81 //////////////////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////////////////
82 // BrowserCompositorViewPlaceholderMac 74 // BrowserCompositorMacPlaceholder
83 75
84 BrowserCompositorViewPlaceholderMac::BrowserCompositorViewPlaceholderMac() { 76 BrowserCompositorMacPlaceholder::BrowserCompositorMacPlaceholder() {
85 g_placeholder_count += 1; 77 g_placeholder_count += 1;
86 } 78 }
87 79
88 BrowserCompositorViewPlaceholderMac::~BrowserCompositorViewPlaceholderMac() { 80 BrowserCompositorMacPlaceholder::~BrowserCompositorMacPlaceholder() {
89 DCHECK_GT(g_placeholder_count, 0u); 81 DCHECK_GT(g_placeholder_count, 0u);
90 g_placeholder_count -= 1; 82 g_placeholder_count -= 1;
91 83
92 // If there are no placeholders allocated, destroy the recyclable 84 // If there are no placeholders allocated, destroy the recyclable
93 // BrowserCompositorCALayerTreeMac. 85 // BrowserCompositorMac.
94 if (!g_placeholder_count) 86 if (!g_placeholder_count)
95 g_recyclable_ca_layer_tree.Get().reset(); 87 g_recyclable_browser_compositor.Get().reset();
96 } 88 }
97 89
98 } // namespace content 90 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698