| 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); | |
| 64 } | 63 } |
| 65 | 64 |
| 66 BrowserCompositorViewMacInternal::~BrowserCompositorViewMacInternal() { | 65 BrowserCompositorViewMacInternal::~BrowserCompositorViewMacInternal() { |
| 67 DCHECK(!client_); | 66 DCHECK(!client_); |
| 68 g_widget_to_internals_map.Pointer()->erase(native_widget_); | 67 g_widget_to_internals_map.Pointer()->erase(native_widget_); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void BrowserCompositorViewMacInternal::SetClient( | 70 void BrowserCompositorViewMacInternal::SetClient( |
| 72 BrowserCompositorViewMacClient* client) { | 71 BrowserCompositorViewMacClient* client) { |
| 73 // Disable the fade-in animation as the view is added. | 72 // Disable the fade-in animation as the view is added. |
| 74 ScopedCAActionDisabler disabler; | 73 ScopedCAActionDisabler disabler; |
| 75 | 74 |
| 76 DCHECK(client && !client_); | 75 DCHECK(client && !client_); |
| 77 client_ = client; | 76 client_ = client; |
| 78 compositor_->SetRootLayer(client_->BrowserCompositorRootLayer()); | 77 compositor_->SetRootLayer(client_->BrowserCompositorRootLayer()); |
| 79 | 78 |
| 80 CALayer* background_layer = [client_->BrowserCompositorSuperview() layer]; | 79 CALayer* background_layer = [client_->BrowserCompositorSuperview() layer]; |
| 81 DCHECK(background_layer); | 80 DCHECK(background_layer); |
| 82 [flipped_layer_ setBounds:[background_layer bounds]]; | 81 [flipped_layer_ setBounds:[background_layer bounds]]; |
| 83 [background_layer addSublayer:flipped_layer_]; | 82 [background_layer addSublayer:flipped_layer_]; |
| 84 compositor_->SetVisible(true); | |
| 85 } | 83 } |
| 86 | 84 |
| 87 void BrowserCompositorViewMacInternal::ResetClient() { | 85 void BrowserCompositorViewMacInternal::ResetClient() { |
| 88 if (!client_) | 86 if (!client_) |
| 89 return; | 87 return; |
| 90 | 88 |
| 91 // Disable the fade-out animation as the view is removed. | 89 // Disable the fade-out animation as the view is removed. |
| 92 ScopedCAActionDisabler disabler; | 90 ScopedCAActionDisabler disabler; |
| 93 | 91 |
| 94 [flipped_layer_ removeFromSuperlayer]; | 92 [flipped_layer_ removeFromSuperlayer]; |
| 95 DestroyIOSurfaceLayer(io_surface_layer_); | 93 DestroyIOSurfaceLayer(io_surface_layer_); |
| 96 DestroyCAContextLayer(ca_context_layer_); | 94 DestroyCAContextLayer(ca_context_layer_); |
| 97 DestroySoftwareLayer(); | 95 DestroySoftwareLayer(); |
| 98 | 96 |
| 99 accelerated_output_surface_id_ = 0; | 97 accelerated_output_surface_id_ = 0; |
| 100 last_swap_size_dip_ = gfx::Size(); | 98 last_swap_size_dip_ = gfx::Size(); |
| 101 | 99 |
| 102 compositor_->SetVisible(false); | |
| 103 compositor_->SetScaleAndSize(1.0, gfx::Size(0, 0)); | 100 compositor_->SetScaleAndSize(1.0, gfx::Size(0, 0)); |
| 104 compositor_->SetRootLayer(NULL); | 101 compositor_->SetRootLayer(NULL); |
| 105 client_ = NULL; | 102 client_ = NULL; |
| 106 } | 103 } |
| 107 | 104 |
| 108 bool BrowserCompositorViewMacInternal::HasFrameOfSize( | 105 bool BrowserCompositorViewMacInternal::HasFrameOfSize( |
| 109 const gfx::Size& dip_size) const { | 106 const gfx::Size& dip_size) const { |
| 110 return last_swap_size_dip_ == dip_size; | 107 return last_swap_size_dip_ == dip_size; |
| 111 } | 108 } |
| 112 | 109 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 g_widget_to_internals_map.Pointer()->find(widget); | 336 g_widget_to_internals_map.Pointer()->find(widget); |
| 340 // This can end up being accessed after the underlying widget has been | 337 // This can end up being accessed after the underlying widget has been |
| 341 // destroyed, but while the ui::Compositor is still being destroyed. | 338 // destroyed, but while the ui::Compositor is still being destroyed. |
| 342 // Return NULL in these cases. | 339 // Return NULL in these cases. |
| 343 if (found == g_widget_to_internals_map.Pointer()->end()) | 340 if (found == g_widget_to_internals_map.Pointer()->end()) |
| 344 return NULL; | 341 return NULL; |
| 345 return found->second; | 342 return found->second; |
| 346 } | 343 } |
| 347 | 344 |
| 348 } // namespace content | 345 } // namespace content |
| OLD | NEW |