OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #include "ui/aura/window_observer.h" | 27 #include "ui/aura/window_observer.h" |
28 #include "ui/base/animation/multi_animation.h" | 28 #include "ui/base/animation/multi_animation.h" |
29 #include "ui/compositor/compositor.h" | 29 #include "ui/compositor/compositor.h" |
30 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
31 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
32 #include "ui/gfx/path.h" | 32 #include "ui/gfx/path.h" |
33 #include "ui/gfx/screen.h" | 33 #include "ui/gfx/screen.h" |
34 | 34 |
35 namespace aura { | 35 namespace aura { |
36 | 36 |
37 namespace { | |
38 | |
39 void MailboxReleaseCallback(scoped_ptr<base::SharedMemory> shared_memory, | |
40 unsigned sync_point, bool lost_resource) { | |
41 shared_memory.reset(NULL); | |
piman
2013/06/07 01:26:28
nit: same as in RWHVA you actually don't need this
slavi
2013/06/07 21:49:21
Done.
| |
42 } | |
43 | |
44 } // namespace | |
45 | |
37 Window::Window(WindowDelegate* delegate) | 46 Window::Window(WindowDelegate* delegate) |
38 : type_(client::WINDOW_TYPE_UNKNOWN), | 47 : type_(client::WINDOW_TYPE_UNKNOWN), |
39 owned_by_parent_(true), | 48 owned_by_parent_(true), |
40 delegate_(delegate), | 49 delegate_(delegate), |
41 parent_(NULL), | 50 parent_(NULL), |
42 transient_parent_(NULL), | 51 transient_parent_(NULL), |
43 visible_(false), | 52 visible_(false), |
44 id_(-1), | 53 id_(-1), |
45 transparent_(false), | 54 transparent_(false), |
46 user_data_(NULL), | 55 user_data_(NULL), |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 Env::GetInstance()->NotifyWindowInitialized(this); | 147 Env::GetInstance()->NotifyWindowInitialized(this); |
139 } | 148 } |
140 | 149 |
141 ui::Layer* Window::RecreateLayer() { | 150 ui::Layer* Window::RecreateLayer() { |
142 // Disconnect the old layer, but don't delete it. | 151 // Disconnect the old layer, but don't delete it. |
143 ui::Layer* old_layer = AcquireLayer(); | 152 ui::Layer* old_layer = AcquireLayer(); |
144 if (!old_layer) | 153 if (!old_layer) |
145 return NULL; | 154 return NULL; |
146 | 155 |
147 old_layer->set_delegate(NULL); | 156 old_layer->set_delegate(NULL); |
157 float mailbox_scale_factor; | |
158 cc::TextureMailbox old_mailbox = | |
159 old_layer->GetTextureMailbox(&mailbox_scale_factor); | |
148 scoped_refptr<ui::Texture> old_texture = old_layer->external_texture(); | 160 scoped_refptr<ui::Texture> old_texture = old_layer->external_texture(); |
149 if (delegate_ && old_texture) | 161 if (delegate_ && old_texture) |
150 old_layer->SetExternalTexture(delegate_->CopyTexture()); | 162 old_layer->SetExternalTexture(delegate_->CopyTexture()); |
151 | 163 |
152 layer_ = new ui::Layer(old_layer->type()); | 164 layer_ = new ui::Layer(old_layer->type()); |
153 layer_owner_.reset(layer_); | 165 layer_owner_.reset(layer_); |
154 layer_->SetVisible(old_layer->visible()); | 166 layer_->SetVisible(old_layer->visible()); |
155 layer_->set_scale_content(old_layer->scale_content()); | 167 layer_->set_scale_content(old_layer->scale_content()); |
156 layer_->set_delegate(this); | 168 layer_->set_delegate(this); |
157 layer_->SetMasksToBounds(old_layer->GetMasksToBounds()); | 169 layer_->SetMasksToBounds(old_layer->GetMasksToBounds()); |
158 // Move the original texture to the new layer if the old layer has a | 170 // Move the original texture to the new layer if the old layer has a |
159 // texture and we could copy it into the old layer, | 171 // texture and we could copy it into the old layer, |
160 // crbug.com/175211. | 172 // crbug.com/175211. |
161 if (delegate_ && old_texture) | 173 if (delegate_ && old_texture) { |
162 layer_->SetExternalTexture(old_texture); | 174 layer_->SetExternalTexture(old_texture); |
175 } else if (old_mailbox.IsSharedMemory()) { | |
176 base::SharedMemory* old_buffer = old_mailbox.shared_memory(); | |
177 const size_t size = old_mailbox.shared_memory_size_in_bytes(); | |
178 | |
179 scoped_ptr<base::SharedMemory> new_buffer(new base::SharedMemory); | |
180 new_buffer->CreateAndMapAnonymous(size); | |
181 | |
182 if (old_buffer->memory() && new_buffer->memory()) { | |
183 memcpy(new_buffer->memory(), old_buffer->memory(), size); | |
184 base::SharedMemory* new_buffer_raw_ptr = new_buffer.get(); | |
185 cc::TextureMailbox::ReleaseCallback callback = | |
186 base::Bind(MailboxReleaseCallback, Passed(new_buffer.Pass())); | |
187 cc::TextureMailbox new_mailbox(new_buffer_raw_ptr, | |
188 old_mailbox.shared_memory_size(), | |
189 callback); | |
190 layer_->SetTextureMailbox(new_mailbox, mailbox_scale_factor); | |
191 } | |
192 } | |
163 | 193 |
164 UpdateLayerName(name_); | 194 UpdateLayerName(name_); |
165 layer_->SetFillsBoundsOpaquely(!transparent_); | 195 layer_->SetFillsBoundsOpaquely(!transparent_); |
166 // Install new layer as a sibling of the old layer, stacked below it. | 196 // Install new layer as a sibling of the old layer, stacked below it. |
167 if (old_layer->parent()) { | 197 if (old_layer->parent()) { |
168 old_layer->parent()->Add(layer_); | 198 old_layer->parent()->Add(layer_); |
169 old_layer->parent()->StackBelow(layer_, old_layer); | 199 old_layer->parent()->StackBelow(layer_, old_layer); |
170 } | 200 } |
171 // Migrate all the child layers over to the new layer. Copy the list because | 201 // Migrate all the child layers over to the new layer. Copy the list because |
172 // the items are removed during iteration. | 202 // the items are removed during iteration. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 return layer_->bounds(); | 336 return layer_->bounds(); |
307 } | 337 } |
308 | 338 |
309 void Window::SchedulePaintInRect(const gfx::Rect& rect) { | 339 void Window::SchedulePaintInRect(const gfx::Rect& rect) { |
310 if (layer_->SchedulePaint(rect)) { | 340 if (layer_->SchedulePaint(rect)) { |
311 FOR_EACH_OBSERVER( | 341 FOR_EACH_OBSERVER( |
312 WindowObserver, observers_, OnWindowPaintScheduled(this, rect)); | 342 WindowObserver, observers_, OnWindowPaintScheduled(this, rect)); |
313 } | 343 } |
314 } | 344 } |
315 | 345 |
316 void Window::SetExternalTexture(ui::Texture* texture) { | |
317 layer_->SetExternalTexture(texture); | |
318 } | |
319 | |
320 void Window::SetDefaultParentByRootWindow(RootWindow* root_window, | 346 void Window::SetDefaultParentByRootWindow(RootWindow* root_window, |
321 const gfx::Rect& bounds_in_screen) { | 347 const gfx::Rect& bounds_in_screen) { |
322 DCHECK(root_window); | 348 DCHECK(root_window); |
323 | 349 |
324 // Stacking clients are mandatory on RootWindow objects. | 350 // Stacking clients are mandatory on RootWindow objects. |
325 client::StackingClient* client = client::GetStackingClient(root_window); | 351 client::StackingClient* client = client::GetStackingClient(root_window); |
326 DCHECK(client); | 352 DCHECK(client); |
327 | 353 |
328 aura::Window* default_parent = client->GetDefaultParent( | 354 aura::Window* default_parent = client->GetDefaultParent( |
329 root_window, this, bounds_in_screen); | 355 root_window, this, bounds_in_screen); |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1106 bool contains_mouse = false; | 1132 bool contains_mouse = false; |
1107 if (IsVisible()) { | 1133 if (IsVisible()) { |
1108 RootWindow* root_window = GetRootWindow(); | 1134 RootWindow* root_window = GetRootWindow(); |
1109 contains_mouse = root_window && | 1135 contains_mouse = root_window && |
1110 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); | 1136 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); |
1111 } | 1137 } |
1112 return contains_mouse; | 1138 return contains_mouse; |
1113 } | 1139 } |
1114 | 1140 |
1115 } // namespace aura | 1141 } // namespace aura |
OLD | NEW |