Index: ui/aura/window.cc |
diff --git a/ui/aura/window.cc b/ui/aura/window.cc |
index 5160bf6c34fbd23f33c5f943d2a8fa9b325b5ba3..dac14057a2ed506e9fb059dfaf420076174123cb 100644 |
--- a/ui/aura/window.cc |
+++ b/ui/aura/window.cc |
@@ -34,6 +34,15 @@ |
namespace aura { |
+namespace { |
+ |
+void MailboxReleaseCallback(scoped_ptr<base::SharedMemory> shared_memory, |
+ unsigned sync_point, bool lost_resource) { |
+ // NOTE: shared_memory will get released when we go out of scope. |
+} |
+ |
+} // namespace |
+ |
Window::Window(WindowDelegate* delegate) |
: type_(client::WINDOW_TYPE_UNKNOWN), |
owned_by_parent_(true), |
@@ -145,6 +154,9 @@ ui::Layer* Window::RecreateLayer() { |
return NULL; |
old_layer->set_delegate(NULL); |
+ float mailbox_scale_factor; |
+ cc::TextureMailbox old_mailbox = |
+ old_layer->GetTextureMailbox(&mailbox_scale_factor); |
scoped_refptr<ui::Texture> old_texture = old_layer->external_texture(); |
if (delegate_ && old_texture) |
old_layer->SetExternalTexture(delegate_->CopyTexture()); |
@@ -158,8 +170,26 @@ ui::Layer* Window::RecreateLayer() { |
// Move the original texture to the new layer if the old layer has a |
// texture and we could copy it into the old layer, |
// crbug.com/175211. |
- if (delegate_ && old_texture) |
+ if (delegate_ && old_texture) { |
layer_->SetExternalTexture(old_texture); |
+ } else if (old_mailbox.IsSharedMemory()) { |
+ base::SharedMemory* old_buffer = old_mailbox.shared_memory(); |
+ const size_t size = old_mailbox.shared_memory_size_in_bytes(); |
+ |
+ scoped_ptr<base::SharedMemory> new_buffer(new base::SharedMemory); |
+ new_buffer->CreateAndMapAnonymous(size); |
+ |
+ if (old_buffer->memory() && new_buffer->memory()) { |
+ memcpy(new_buffer->memory(), old_buffer->memory(), size); |
+ base::SharedMemory* new_buffer_raw_ptr = new_buffer.get(); |
+ cc::TextureMailbox::ReleaseCallback callback = |
+ base::Bind(MailboxReleaseCallback, Passed(&new_buffer)); |
+ cc::TextureMailbox new_mailbox(new_buffer_raw_ptr, |
+ old_mailbox.shared_memory_size(), |
+ callback); |
+ layer_->SetTextureMailbox(new_mailbox, mailbox_scale_factor); |
+ } |
+ } |
UpdateLayerName(name_); |
layer_->SetFillsBoundsOpaquely(!transparent_); |
@@ -313,10 +343,6 @@ void Window::SchedulePaintInRect(const gfx::Rect& rect) { |
} |
} |
-void Window::SetExternalTexture(ui::Texture* texture) { |
- layer_->SetExternalTexture(texture); |
-} |
- |
void Window::SetDefaultParentByRootWindow(RootWindow* root_window, |
const gfx::Rect& bounds_in_screen) { |
DCHECK(root_window); |