OLD | NEW |
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_view_private_mac.h" | 9 #include "content/browser/compositor/browser_compositor_view_private_mac.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 @end // NSView (BrowserCompositorView) | 33 @end // NSView (BrowserCompositorView) |
34 | 34 |
35 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
36 // BrowserCompositorViewMac | 36 // BrowserCompositorViewMac |
37 | 37 |
38 namespace content { | 38 namespace content { |
39 namespace { | 39 namespace { |
40 | 40 |
41 // The number of placeholder objects allocated. If this reaches zero, then | 41 // The number of placeholder objects allocated. If this reaches zero, then |
42 // the BrowserCompositorViewCocoa being held on to for recycling, | 42 // the BrowserCompositorViewCocoa being held on to for recycling, |
43 // |g_recyclable_cocoa_view|, will be freed. | 43 // |g_recyclable_internal_view|, will be freed. |
44 uint32 g_placeholder_count = 0; | 44 uint32 g_placeholder_count = 0; |
45 | 45 |
46 // A spare BrowserCompositorViewCocoa kept around for recycling. | 46 // A spare BrowserCompositorViewCocoa kept around for recycling. |
47 base::LazyInstance<base::scoped_nsobject<BrowserCompositorViewCocoa>> | 47 base::LazyInstance<scoped_ptr<BrowserCompositorViewMacInternal>> |
48 g_recyclable_cocoa_view; | 48 g_recyclable_internal_view; |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 BrowserCompositorViewMac::BrowserCompositorViewMac( | 52 BrowserCompositorViewMac::BrowserCompositorViewMac( |
53 BrowserCompositorViewMacClient* client) : client_(client) { | 53 BrowserCompositorViewMacClient* client) : client_(client) { |
54 // Try to use the recyclable BrowserCompositorViewCocoa if there is one, | 54 // Try to use the recyclable BrowserCompositorViewCocoa if there is one, |
55 // otherwise allocate a new one. | 55 // otherwise allocate a new one. |
56 // TODO(ccameron): If there exists a frame in flight (swap has been called | 56 // TODO(ccameron): If there exists a frame in flight (swap has been called |
57 // by the compositor, but the frame has not arrived from the GPU process | 57 // by the compositor, but the frame has not arrived from the GPU process |
58 // yet), then that frame may inappropriately flash in the new view. | 58 // yet), then that frame may inappropriately flash in the new view. |
59 swap(g_recyclable_cocoa_view.Get(), cocoa_view_); | 59 internal_view_ = g_recyclable_internal_view.Get().Pass(); |
60 if (!cocoa_view_) | 60 if (!internal_view_) |
61 cocoa_view_.reset([[BrowserCompositorViewCocoa alloc] init]); | 61 internal_view_.reset(new BrowserCompositorViewMacInternal); |
62 [cocoa_view_ setClient:client_]; | 62 internal_view_->SetClient(client_); |
63 } | 63 } |
64 | 64 |
65 BrowserCompositorViewMac::~BrowserCompositorViewMac() { | 65 BrowserCompositorViewMac::~BrowserCompositorViewMac() { |
66 // Make this BrowserCompositorViewCocoa recyclable for future instances. | 66 // Make this BrowserCompositorViewCocoa recyclable for future instances. |
67 [cocoa_view_ setClient:NULL]; | 67 internal_view_->ResetClient(); |
68 [g_recyclable_cocoa_view.Get() destroyCompositor]; | 68 g_recyclable_internal_view.Get() = internal_view_.Pass(); |
69 swap(g_recyclable_cocoa_view.Get(), cocoa_view_); | |
70 | 69 |
71 // If there are no placeholders allocated, destroy the recyclable | 70 // If there are no placeholders allocated, destroy the recyclable |
72 // BrowserCompositorViewCocoa that we just populated. | 71 // BrowserCompositorViewCocoa that we just populated. |
73 if (!g_placeholder_count) { | 72 if (!g_placeholder_count) |
74 [g_recyclable_cocoa_view.Get() destroyCompositor]; | 73 g_recyclable_internal_view.Get().reset(); |
75 g_recyclable_cocoa_view.Get().reset(); | |
76 } | |
77 } | 74 } |
78 | 75 |
79 ui::Compositor* BrowserCompositorViewMac::GetCompositor() const { | 76 ui::Compositor* BrowserCompositorViewMac::GetCompositor() const { |
80 DCHECK(cocoa_view_); | 77 DCHECK(internal_view_); |
81 return [cocoa_view_ compositor]; | 78 return internal_view_->compositor(); |
82 } | 79 } |
83 | 80 |
84 //////////////////////////////////////////////////////////////////////////////// | 81 //////////////////////////////////////////////////////////////////////////////// |
85 // BrowserCompositorViewPlaceholderMac | 82 // BrowserCompositorViewPlaceholderMac |
86 | 83 |
87 BrowserCompositorViewPlaceholderMac::BrowserCompositorViewPlaceholderMac() { | 84 BrowserCompositorViewPlaceholderMac::BrowserCompositorViewPlaceholderMac() { |
88 g_placeholder_count += 1; | 85 g_placeholder_count += 1; |
89 } | 86 } |
90 | 87 |
91 BrowserCompositorViewPlaceholderMac::~BrowserCompositorViewPlaceholderMac() { | 88 BrowserCompositorViewPlaceholderMac::~BrowserCompositorViewPlaceholderMac() { |
92 DCHECK_GT(g_placeholder_count, 0u); | 89 DCHECK_GT(g_placeholder_count, 0u); |
93 g_placeholder_count -= 1; | 90 g_placeholder_count -= 1; |
94 | 91 |
95 // If there are no placeholders allocated, destroy the recyclable | 92 // If there are no placeholders allocated, destroy the recyclable |
96 // BrowserCompositorViewCocoa. | 93 // BrowserCompositorViewCocoa. |
97 if (!g_placeholder_count) { | 94 if (!g_placeholder_count) |
98 [g_recyclable_cocoa_view.Get() destroyCompositor]; | 95 g_recyclable_internal_view.Get().reset(); |
99 g_recyclable_cocoa_view.Get().reset(); | |
100 } | |
101 } | 96 } |
102 | 97 |
103 } // namespace content | 98 } // namespace content |
OLD | NEW |