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

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: Fix compile Created 6 years 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/gpu/gpu_process_host_ui_shim.h"
10 #include "content/browser/compositor/browser_compositor_ca_layer_tree_mac.h" 9 #include "content/browser/compositor/browser_compositor_ca_layer_tree_mac.h"
11 #include "content/common/gpu/gpu_messages.h" 10 #include "content/browser/renderer_host/render_widget_resize_helper.h"
11 #include "content/public/browser/context_factory.h"
12 12
13 //////////////////////////////////////////////////////////////////////////////// 13 ////////////////////////////////////////////////////////////////////////////////
14 // BrowserCompositorViewMac 14 // BrowserCompositorMac
15 15
16 namespace content { 16 namespace content {
17
17 namespace { 18 namespace {
18 19
19 // The number of placeholder objects allocated. If this reaches zero, then 20 // The number of placeholder objects allocated. If this reaches zero, then
20 // the BrowserCompositorCALayerTreeMac being held on to for recycling, 21 // the BrowserCompositorMac being held on to for recycling,
21 // |g_recyclable_ca_layer_tree|, will be freed. 22 // |g_recyclable_browser_compositor|, will be freed.
22 uint32 g_placeholder_count = 0; 23 uint32 g_placeholder_count = 0;
23 24
24 // A spare BrowserCompositorCALayerTreeMac kept around for recycling. 25 // A spare BrowserCompositorMac kept around for recycling.
25 base::LazyInstance<scoped_ptr<BrowserCompositorCALayerTreeMac>> 26 base::LazyInstance<scoped_ptr<BrowserCompositorMac>>
26 g_recyclable_ca_layer_tree; 27 g_recyclable_browser_compositor;
27 28
28 } // namespace 29 } // namespace
29 30
30 BrowserCompositorViewMac::BrowserCompositorViewMac( 31 BrowserCompositorMac::BrowserCompositorMac()
31 BrowserCompositorViewMacClient* client, 32 : compositor_(
32 NSView* native_view, 33 accelerated_widget_mac_.accelerated_widget(),
33 ui::Layer* ui_root_layer) 34 content::GetContextFactory(),
34 : client_(client), 35 RenderWidgetResizeHelper::Get()->task_runner()) {
35 native_view_(native_view), 36 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 } 37 }
47 38
48 BrowserCompositorViewMac::~BrowserCompositorViewMac() { 39 // static
49 // Make this BrowserCompositorCALayerTreeMac recyclable for future instances. 40 scoped_ptr<BrowserCompositorMac> BrowserCompositorMac::Create() {
50 ca_layer_tree_->ResetView(); 41 if (g_recyclable_browser_compositor.Get())
51 g_recyclable_ca_layer_tree.Get() = ca_layer_tree_.Pass(); 42 return g_recyclable_browser_compositor.Get().Pass();
43 return scoped_ptr<BrowserCompositorMac>(new BrowserCompositorMac).Pass();
44 }
45
46 // static
47 void BrowserCompositorMac::Recycle(
48 scoped_ptr<BrowserCompositorMac> compositor) {
49 DCHECK(compositor);
50
51 // Make this BrowserCompositorMac recyclable for future instances.
52 g_recyclable_browser_compositor.Get().swap(compositor);
52 53
53 // If there are no placeholders allocated, destroy the recyclable 54 // If there are no placeholders allocated, destroy the recyclable
54 // BrowserCompositorCALayerTreeMac that we just populated. 55 // BrowserCompositorMac that we just populated.
55 if (!g_placeholder_count) 56 if (!g_placeholder_count)
56 g_recyclable_ca_layer_tree.Get().reset(); 57 g_recyclable_browser_compositor.Get().reset();
57 }
58
59 ui::Compositor* BrowserCompositorViewMac::GetCompositor() const {
60 DCHECK(ca_layer_tree_);
61 return ca_layer_tree_->compositor();
62 }
63
64 bool BrowserCompositorViewMac::HasFrameOfSize(
65 const gfx::Size& dip_size) const {
66 if (ca_layer_tree_)
67 return ca_layer_tree_->HasFrameOfSize(dip_size);
68 return false;
69 }
70
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 } 58 }
80 59
81 //////////////////////////////////////////////////////////////////////////////// 60 ////////////////////////////////////////////////////////////////////////////////
82 // BrowserCompositorViewPlaceholderMac 61 // BrowserCompositorMacPlaceholder
83 62
84 BrowserCompositorViewPlaceholderMac::BrowserCompositorViewPlaceholderMac() { 63 BrowserCompositorMacPlaceholder::BrowserCompositorMacPlaceholder() {
85 g_placeholder_count += 1; 64 g_placeholder_count += 1;
86 } 65 }
87 66
88 BrowserCompositorViewPlaceholderMac::~BrowserCompositorViewPlaceholderMac() { 67 BrowserCompositorMacPlaceholder::~BrowserCompositorMacPlaceholder() {
89 DCHECK_GT(g_placeholder_count, 0u); 68 DCHECK_GT(g_placeholder_count, 0u);
90 g_placeholder_count -= 1; 69 g_placeholder_count -= 1;
91 70
92 // If there are no placeholders allocated, destroy the recyclable 71 // If there are no placeholders allocated, destroy the recyclable
93 // BrowserCompositorCALayerTreeMac. 72 // BrowserCompositorMac.
94 if (!g_placeholder_count) 73 if (!g_placeholder_count)
95 g_recyclable_ca_layer_tree.Get().reset(); 74 g_recyclable_browser_compositor.Get().reset();
96 } 75 }
97 76
98 } // namespace content 77 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/compositor/browser_compositor_view_mac.h ('k') | content/browser/compositor/io_surface_layer_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698