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_private_mac.h" | 5 #include "content/browser/compositor/browser_compositor_view_private_mac.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 native_widget_ = reinterpret_cast<gfx::AcceleratedWidget>( | 53 native_widget_ = reinterpret_cast<gfx::AcceleratedWidget>( |
54 last_sequence_number); | 54 last_sequence_number); |
55 g_widget_to_internals_map.Pointer()->insert( | 55 g_widget_to_internals_map.Pointer()->insert( |
56 std::make_pair(native_widget_, this)); | 56 std::make_pair(native_widget_, this)); |
57 | 57 |
58 // Create a compositor to draw the contents of this view. | 58 // Create a compositor to draw the contents of this view. |
59 compositor_.reset(new ui::Compositor( | 59 compositor_.reset(new ui::Compositor( |
60 native_widget_, | 60 native_widget_, |
61 content::GetContextFactory(), | 61 content::GetContextFactory(), |
62 RenderWidgetResizeHelper::Get()->task_runner())); | 62 RenderWidgetResizeHelper::Get()->task_runner())); |
| 63 compositor_->SetVisible(false); |
63 } | 64 } |
64 | 65 |
65 BrowserCompositorViewMacInternal::~BrowserCompositorViewMacInternal() { | 66 BrowserCompositorViewMacInternal::~BrowserCompositorViewMacInternal() { |
66 DCHECK(!client_); | 67 DCHECK(!client_); |
67 g_widget_to_internals_map.Pointer()->erase(native_widget_); | 68 g_widget_to_internals_map.Pointer()->erase(native_widget_); |
68 } | 69 } |
69 | 70 |
70 void BrowserCompositorViewMacInternal::SetClient( | 71 void BrowserCompositorViewMacInternal::SetClient( |
71 BrowserCompositorViewMacClient* client) { | 72 BrowserCompositorViewMacClient* client) { |
72 // Disable the fade-in animation as the view is added. | 73 // Disable the fade-in animation as the view is added. |
73 ScopedCAActionDisabler disabler; | 74 ScopedCAActionDisabler disabler; |
74 | 75 |
75 DCHECK(client && !client_); | 76 DCHECK(client && !client_); |
76 client_ = client; | 77 client_ = client; |
77 compositor_->SetRootLayer(client_->BrowserCompositorRootLayer()); | 78 compositor_->SetRootLayer(client_->BrowserCompositorRootLayer()); |
78 | 79 |
79 CALayer* background_layer = [client_->BrowserCompositorSuperview() layer]; | 80 CALayer* background_layer = [client_->BrowserCompositorSuperview() layer]; |
80 DCHECK(background_layer); | 81 DCHECK(background_layer); |
81 [flipped_layer_ setBounds:[background_layer bounds]]; | 82 [flipped_layer_ setBounds:[background_layer bounds]]; |
82 [background_layer addSublayer:flipped_layer_]; | 83 [background_layer addSublayer:flipped_layer_]; |
| 84 compositor_->SetVisible(true); |
83 } | 85 } |
84 | 86 |
85 void BrowserCompositorViewMacInternal::ResetClient() { | 87 void BrowserCompositorViewMacInternal::ResetClient() { |
86 if (!client_) | 88 if (!client_) |
87 return; | 89 return; |
88 | 90 |
89 // Disable the fade-out animation as the view is removed. | 91 // Disable the fade-out animation as the view is removed. |
90 ScopedCAActionDisabler disabler; | 92 ScopedCAActionDisabler disabler; |
91 | 93 |
92 [flipped_layer_ removeFromSuperlayer]; | 94 [flipped_layer_ removeFromSuperlayer]; |
93 DestroyIOSurfaceLayer(io_surface_layer_); | 95 DestroyIOSurfaceLayer(io_surface_layer_); |
94 DestroyCAContextLayer(ca_context_layer_); | 96 DestroyCAContextLayer(ca_context_layer_); |
95 DestroySoftwareLayer(); | 97 DestroySoftwareLayer(); |
96 | 98 |
97 accelerated_output_surface_id_ = 0; | 99 accelerated_output_surface_id_ = 0; |
98 last_swap_size_dip_ = gfx::Size(); | 100 last_swap_size_dip_ = gfx::Size(); |
99 | 101 |
| 102 compositor_->SetVisible(false); |
100 compositor_->SetScaleAndSize(1.0, gfx::Size(0, 0)); | 103 compositor_->SetScaleAndSize(1.0, gfx::Size(0, 0)); |
101 compositor_->SetRootLayer(NULL); | 104 compositor_->SetRootLayer(NULL); |
102 client_ = NULL; | 105 client_ = NULL; |
103 } | 106 } |
104 | 107 |
105 bool BrowserCompositorViewMacInternal::HasFrameOfSize( | 108 bool BrowserCompositorViewMacInternal::HasFrameOfSize( |
106 const gfx::Size& dip_size) const { | 109 const gfx::Size& dip_size) const { |
107 return last_swap_size_dip_ == dip_size; | 110 return last_swap_size_dip_ == dip_size; |
108 } | 111 } |
109 | 112 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 g_widget_to_internals_map.Pointer()->find(widget); | 339 g_widget_to_internals_map.Pointer()->find(widget); |
337 // This can end up being accessed after the underlying widget has been | 340 // This can end up being accessed after the underlying widget has been |
338 // destroyed, but while the ui::Compositor is still being destroyed. | 341 // destroyed, but while the ui::Compositor is still being destroyed. |
339 // Return NULL in these cases. | 342 // Return NULL in these cases. |
340 if (found == g_widget_to_internals_map.Pointer()->end()) | 343 if (found == g_widget_to_internals_map.Pointer()->end()) |
341 return NULL; | 344 return NULL; |
342 return found->second; | 345 return found->second; |
343 } | 346 } |
344 | 347 |
345 } // namespace content | 348 } // namespace content |
OLD | NEW |