OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/aura/window_port_local.h" | 5 #include "ui/aura/local/window_port_local.h" |
6 | 6 |
| 7 #include "cc/output/compositor_frame_sink.h" |
| 8 #include "cc/surfaces/surface_manager.h" |
7 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
8 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/local/compositor_frame_sink_local.h" |
9 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
10 #include "ui/aura/window_delegate.h" | 13 #include "ui/aura/window_delegate.h" |
11 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
12 #include "ui/display/screen.h" | 15 #include "ui/display/screen.h" |
13 | 16 |
14 namespace aura { | 17 namespace aura { |
15 namespace { | 18 namespace { |
16 | 19 |
17 class ScopedCursorHider { | 20 class ScopedCursorHider { |
18 public: | 21 public: |
(...skipping 29 matching lines...) Expand all Loading... |
48 | 51 |
49 private: | 52 private: |
50 Window* window_; | 53 Window* window_; |
51 bool hid_cursor_; | 54 bool hid_cursor_; |
52 | 55 |
53 DISALLOW_COPY_AND_ASSIGN(ScopedCursorHider); | 56 DISALLOW_COPY_AND_ASSIGN(ScopedCursorHider); |
54 }; | 57 }; |
55 | 58 |
56 } // namespace | 59 } // namespace |
57 | 60 |
58 WindowPortLocal::WindowPortLocal(Window* window) : window_(window) {} | 61 WindowPortLocal::WindowPortLocal(Window* window) |
| 62 : window_(window), weak_factory_(this) {} |
59 | 63 |
60 WindowPortLocal::~WindowPortLocal() {} | 64 WindowPortLocal::~WindowPortLocal() {} |
61 | 65 |
62 void WindowPortLocal::OnPreInit(Window* window) {} | 66 void WindowPortLocal::OnPreInit(Window* window) {} |
63 | 67 |
64 void WindowPortLocal::OnDeviceScaleFactorChanged(float device_scale_factor) { | 68 void WindowPortLocal::OnDeviceScaleFactorChanged(float device_scale_factor) { |
65 ScopedCursorHider hider(window_); | 69 ScopedCursorHider hider(window_); |
66 if (window_->delegate()) | 70 if (window_->delegate()) |
67 window_->delegate()->OnDeviceScaleFactorChanged(device_scale_factor); | 71 window_->delegate()->OnDeviceScaleFactorChanged(device_scale_factor); |
68 } | 72 } |
(...skipping 13 matching lines...) Expand all Loading... |
82 std::unique_ptr<ui::PropertyData> WindowPortLocal::OnWillChangeProperty( | 86 std::unique_ptr<ui::PropertyData> WindowPortLocal::OnWillChangeProperty( |
83 const void* key) { | 87 const void* key) { |
84 return nullptr; | 88 return nullptr; |
85 } | 89 } |
86 | 90 |
87 void WindowPortLocal::OnPropertyChanged( | 91 void WindowPortLocal::OnPropertyChanged( |
88 const void* key, | 92 const void* key, |
89 int64_t old_value, | 93 int64_t old_value, |
90 std::unique_ptr<ui::PropertyData> data) {} | 94 std::unique_ptr<ui::PropertyData> data) {} |
91 | 95 |
| 96 std::unique_ptr<cc::CompositorFrameSink> |
| 97 WindowPortLocal::OnCreateCompositorFrameSink() { |
| 98 DCHECK(!frame_sink_id_.is_valid()); |
| 99 auto* context_factory_private = |
| 100 aura::Env::GetInstance()->context_factory_private(); |
| 101 frame_sink_id_ = context_factory_private->AllocateFrameSinkId(); |
| 102 auto frame_sink = base::MakeUnique<CompositorFrameSinkLocal>( |
| 103 frame_sink_id_, context_factory_private->GetSurfaceManager()); |
| 104 frame_sink->SetSurfaceChangedCallback(base::Bind( |
| 105 &WindowPortLocal::OnSurfaceChanged, weak_factory_.GetWeakPtr())); |
| 106 return std::move(frame_sink); |
| 107 } |
| 108 |
| 109 void WindowPortLocal::OnWindowAddedToRootWindow() { |
| 110 if (frame_sink_id_.is_valid()) |
| 111 window_->layer()->GetCompositor()->AddFrameSink(frame_sink_id_); |
| 112 } |
| 113 |
| 114 void WindowPortLocal::OnWindowRemovingFromRootWindow() { |
| 115 if (frame_sink_id_.is_valid()) |
| 116 window_->layer()->GetCompositor()->RemoveFrameSink(frame_sink_id_); |
| 117 } |
| 118 |
| 119 void WindowPortLocal::OnSurfaceChanged(const cc::SurfaceId& surface_id, |
| 120 const gfx::Size& surface_size) { |
| 121 // The bounds must be updated before switching to the new surface, because |
| 122 // the layer may be mirrored, in which case a surface change causes the |
| 123 // mirror layer to update its surface using the latest bounds. |
| 124 window_->layer()->SetBounds( |
| 125 gfx::Rect(window_->layer()->bounds().origin(), surface_size)); |
| 126 window_->layer()->SetShowPrimarySurface( |
| 127 cc::SurfaceInfo(surface_id, 1.0f, surface_size), |
| 128 aura::Env::GetInstance() |
| 129 ->context_factory_private() |
| 130 ->GetSurfaceManager() |
| 131 ->reference_factory()); |
| 132 } |
| 133 |
92 } // namespace aura | 134 } // namespace aura |
OLD | NEW |