Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: ui/aura/window.cc

Issue 23444051: Move the content-dependent RecreateLayer logic from aura::Window to RWHVA (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/test/test_window_delegate.cc ('k') | ui/aura/window_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
27 #include "ui/aura/window_tracker.h" 27 #include "ui/aura/window_tracker.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 // NOTE: shared_memory will get released when we go out of scope.
42 }
43
44 } // namespace
45
46 Window::Window(WindowDelegate* delegate) 37 Window::Window(WindowDelegate* delegate)
47 : type_(client::WINDOW_TYPE_UNKNOWN), 38 : type_(client::WINDOW_TYPE_UNKNOWN),
48 owned_by_parent_(true), 39 owned_by_parent_(true),
49 delegate_(delegate), 40 delegate_(delegate),
50 parent_(NULL), 41 parent_(NULL),
51 transient_parent_(NULL), 42 transient_parent_(NULL),
52 visible_(false), 43 visible_(false),
53 id_(-1), 44 id_(-1),
54 transparent_(false), 45 transparent_(false),
55 user_data_(NULL), 46 user_data_(NULL),
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 Env::GetInstance()->NotifyWindowInitialized(this); 138 Env::GetInstance()->NotifyWindowInitialized(this);
148 } 139 }
149 140
150 ui::Layer* Window::RecreateLayer() { 141 ui::Layer* Window::RecreateLayer() {
151 // Disconnect the old layer, but don't delete it. 142 // Disconnect the old layer, but don't delete it.
152 ui::Layer* old_layer = AcquireLayer(); 143 ui::Layer* old_layer = AcquireLayer();
153 if (!old_layer) 144 if (!old_layer)
154 return NULL; 145 return NULL;
155 146
156 old_layer->set_delegate(NULL); 147 old_layer->set_delegate(NULL);
157 float mailbox_scale_factor;
158 cc::TextureMailbox old_mailbox =
159 old_layer->GetTextureMailbox(&mailbox_scale_factor);
160 scoped_refptr<ui::Texture> old_texture = old_layer->external_texture();
161 if (delegate_ && old_texture.get())
162 old_layer->SetExternalTexture(delegate_->CopyTexture().get());
163 148
164 layer_ = new ui::Layer(old_layer->type()); 149 layer_ = new ui::Layer(old_layer->type());
165 layer_owner_.reset(layer_); 150 layer_owner_.reset(layer_);
166 layer_->SetVisible(old_layer->visible()); 151 layer_->SetVisible(old_layer->visible());
167 layer_->set_scale_content(old_layer->scale_content()); 152 layer_->set_scale_content(old_layer->scale_content());
168 layer_->set_delegate(this); 153 layer_->set_delegate(this);
169 layer_->SetMasksToBounds(old_layer->GetMasksToBounds()); 154 layer_->SetMasksToBounds(old_layer->GetMasksToBounds());
170 // Move the original texture to the new layer if the old layer has a
171 // texture and we could copy it into the old layer,
172 // crbug.com/175211.
173 if (delegate_ && old_texture.get()) {
174 layer_->SetExternalTexture(old_texture.get());
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 155
179 scoped_ptr<base::SharedMemory> new_buffer(new base::SharedMemory); 156 if (delegate_)
180 new_buffer->CreateAndMapAnonymous(size); 157 delegate_->DidRecreateLayer(old_layer, layer_);
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));
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 }
193 158
194 UpdateLayerName(name_); 159 UpdateLayerName(name_);
195 layer_->SetFillsBoundsOpaquely(!transparent_); 160 layer_->SetFillsBoundsOpaquely(!transparent_);
196 // Install new layer as a sibling of the old layer, stacked below it. 161 // Install new layer as a sibling of the old layer, stacked below it.
197 if (old_layer->parent()) { 162 if (old_layer->parent()) {
198 old_layer->parent()->Add(layer_); 163 old_layer->parent()->Add(layer_);
199 old_layer->parent()->StackBelow(layer_, old_layer); 164 old_layer->parent()->StackBelow(layer_, old_layer);
200 } 165 }
201 // Migrate all the child layers over to the new layer. Copy the list because 166 // Migrate all the child layers over to the new layer. Copy the list because
202 // the items are removed during iteration. 167 // the items are removed during iteration.
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 bool contains_mouse = false; 1093 bool contains_mouse = false;
1129 if (IsVisible()) { 1094 if (IsVisible()) {
1130 RootWindow* root_window = GetRootWindow(); 1095 RootWindow* root_window = GetRootWindow();
1131 contains_mouse = root_window && 1096 contains_mouse = root_window &&
1132 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); 1097 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot());
1133 } 1098 }
1134 return contains_mouse; 1099 return contains_mouse;
1135 } 1100 }
1136 1101
1137 } // namespace aura 1102 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/test_window_delegate.cc ('k') | ui/aura/window_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698