Chromium Code Reviews| 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/mus/window_port_mus.h" | 5 #include "ui/aura/mus/window_port_mus.h" |
| 6 | 6 |
| 7 #include "cc/surfaces/surface_reference_factory.h" | |
| 7 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 8 #include "ui/aura/client/transient_window_client.h" | 9 #include "ui/aura/client/transient_window_client.h" |
| 9 #include "ui/aura/mus/property_converter.h" | 10 #include "ui/aura/mus/property_converter.h" |
| 10 #include "ui/aura/mus/surface_id_handler.h" | 11 #include "ui/aura/mus/surface_id_handler.h" |
| 11 #include "ui/aura/mus/window_tree_client.h" | 12 #include "ui/aura/mus/window_tree_client.h" |
| 12 #include "ui/aura/mus/window_tree_client_delegate.h" | 13 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
| 15 #include "ui/aura/window_observer.h" | 16 #include "ui/aura/window_observer.h" |
| 16 #include "ui/aura/window_property.h" | 17 #include "ui/aura/window_property.h" |
| 17 | 18 |
| 18 namespace aura { | 19 namespace aura { |
| 20 namespace { | |
| 21 | |
| 22 // TODO(mfomitchev, samans): Remove these stub classes once the SurfaceReference | |
| 23 // work is complete. | |
| 24 class StubSurfaceReference : public cc::SurfaceReferenceBase { | |
| 25 public: | |
| 26 StubSurfaceReference(scoped_refptr<const cc::SurfaceReferenceFactory> factory) | |
| 27 : cc::SurfaceReferenceBase(factory) {} | |
| 28 | |
| 29 ~StubSurfaceReference() override { Destroy(); } | |
| 30 | |
| 31 private: | |
| 32 DISALLOW_COPY_AND_ASSIGN(StubSurfaceReference); | |
| 33 }; | |
| 34 | |
| 35 class StubSurfaceReferenceFactory : public cc::SurfaceReferenceFactory { | |
| 36 public: | |
| 37 StubSurfaceReferenceFactory() = default; | |
| 38 | |
| 39 // cc::SurfaceReferenceFactory: | |
| 40 std::unique_ptr<cc::SurfaceReferenceBase> CreateReference( | |
| 41 cc::SurfaceReferenceOwner* owner, | |
| 42 const cc::SurfaceId& surface_id) const override { | |
| 43 return base::MakeUnique<StubSurfaceReference>(make_scoped_refptr(this)); | |
| 44 } | |
| 45 | |
| 46 protected: | |
| 47 ~StubSurfaceReferenceFactory() override = default; | |
| 48 | |
| 49 private: | |
| 50 // cc::SurfaceReferenceFactory: | |
| 51 void DestroyReference(cc::SurfaceReferenceBase* surface_ref) const override {} | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(StubSurfaceReferenceFactory); | |
| 54 }; | |
| 55 | |
| 56 } // namespace | |
| 19 | 57 |
| 20 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; | 58 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; |
| 21 | 59 |
| 22 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; | 60 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; |
| 23 | 61 |
| 24 // static | 62 // static |
| 25 WindowMus* WindowMus::Get(Window* window) { | 63 WindowMus* WindowMus::Get(Window* window) { |
| 26 return WindowPortMus::Get(window); | 64 return WindowPortMus::Get(window); |
| 27 } | 65 } |
| 28 | 66 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 break; | 201 break; |
| 164 } | 202 } |
| 165 } | 203 } |
| 166 return iter; | 204 return iter; |
| 167 } | 205 } |
| 168 | 206 |
| 169 PropertyConverter* WindowPortMus::GetPropertyConverter() { | 207 PropertyConverter* WindowPortMus::GetPropertyConverter() { |
| 170 return window_tree_client_->delegate_->GetPropertyConverter(); | 208 return window_tree_client_->delegate_->GetPropertyConverter(); |
| 171 } | 209 } |
| 172 | 210 |
| 211 void WindowPortMus::UpdateSurfaceLayer(SurfaceInfo* surface_info) { | |
|
sky
2016/12/16 21:50:29
const SurfaceInfo?
mfomitchev
2016/12/23 00:03:49
Made it const reference.
| |
| 212 if (!surface_info) | |
|
sky
2016/12/16 21:50:29
When and why would null be passed in?
mfomitchev
2016/12/23 00:03:49
It is called with null from WindowPortMus's destru
| |
| 213 return; | |
| 214 | |
| 215 if (!surface_layer_) { | |
| 216 surface_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_TEXTURED); | |
| 217 surface_layer_->SetVisible(true); | |
| 218 // The frame provided by the parent window->layer() needs to show through | |
| 219 // the surface layer. | |
| 220 surface_layer_->SetFillsBoundsOpaquely(false); | |
| 221 | |
| 222 clipping_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_TEXTURED); | |
| 223 clipping_layer_->SetFillsBoundsOpaquely(false); | |
| 224 | |
| 225 clipping_layer_->Add(surface_layer_.get()); | |
| 226 window_->layer()->Add(clipping_layer_.get()); | |
| 227 | |
| 228 // Window's layer may contain content from this client (the embedder), e.g. | |
| 229 // this is the case with window decorations provided by Window Manager. | |
| 230 // This content should appear underneath the content of the embedded client. | |
| 231 window_->layer()->StackAtTop(clipping_layer_.get()); | |
| 232 | |
| 233 // We can't set this on window's layer, because that would clip the window | |
| 234 // shadow. | |
| 235 clipping_layer_->SetMasksToBounds(true); | |
| 236 } | |
| 237 | |
| 238 // TODO(mfomitchev): Currently the frame size may not match the window size. | |
| 239 // In the future the surface id will be created by Ash (and used with the | |
| 240 // surface layer) when the window resize happens, which will ensure that the | |
| 241 // surface size matches the window size (unless a timeout occurs). | |
| 242 gfx::Size frame_size = surface_info->frame_size; | |
| 243 surface_layer_->SetBounds( | |
| 244 gfx::Rect(0, 0, frame_size.width(), frame_size.height())); | |
| 245 // Clip to window bounds. | |
| 246 clipping_layer_->SetBounds( | |
| 247 gfx::Rect(0, 0, window_->bounds().width(), window_->bounds().height())); | |
| 248 | |
| 249 // TODO(mfomitchev, riajiang): Hopefully this is fixed after | |
| 250 // https://codereview.chromium.org/2547243002/ lands | |
| 251 float scale_factor = surface_info->device_scale_factor; | |
| 252 scale_factor = scale_factor ? scale_factor : 1; | |
| 253 | |
| 254 // TODO(mfomitchev, samans): Get rid of Aura's SurfaceInfo. | |
| 255 cc::SurfaceInfo cc_surface_info(surface_info->surface_id, scale_factor, | |
| 256 frame_size); | |
| 257 | |
| 258 surface_layer_->SetShowSurface( | |
| 259 cc_surface_info, make_scoped_refptr(new StubSurfaceReferenceFactory)); | |
| 260 } | |
| 261 | |
| 173 Window* WindowPortMus::GetWindow() { | 262 Window* WindowPortMus::GetWindow() { |
| 174 return window_; | 263 return window_; |
| 175 } | 264 } |
| 176 | 265 |
| 177 void WindowPortMus::AddChildFromServer(WindowMus* window) { | 266 void WindowPortMus::AddChildFromServer(WindowMus* window) { |
| 178 ServerChangeData data; | 267 ServerChangeData data; |
| 179 data.child_id = window->server_id(); | 268 data.child_id = window->server_id(); |
| 180 ScopedServerChange change(this, ServerChangeType::ADD, data); | 269 ScopedServerChange change(this, ServerChangeType::ADD, data); |
| 181 window_->AddChild(window->GetWindow()); | 270 window_->AddChild(window->GetWindow()); |
| 182 } | 271 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 if (surface_info_) { | 337 if (surface_info_) { |
| 249 const cc::SurfaceId& existing_surface_id = surface_info_->surface_id; | 338 const cc::SurfaceId& existing_surface_id = surface_info_->surface_id; |
| 250 cc::SurfaceId new_surface_id = | 339 cc::SurfaceId new_surface_id = |
| 251 surface_info ? surface_info->surface_id : cc::SurfaceId(); | 340 surface_info ? surface_info->surface_id : cc::SurfaceId(); |
| 252 if (existing_surface_id.is_valid() && | 341 if (existing_surface_id.is_valid() && |
| 253 existing_surface_id != new_surface_id) { | 342 existing_surface_id != new_surface_id) { |
| 254 // TODO(kylechar): Start return reference here? | 343 // TODO(kylechar): Start return reference here? |
| 255 } | 344 } |
| 256 } | 345 } |
| 257 WindowPortMus* parent = Get(window_->parent()); | 346 WindowPortMus* parent = Get(window_->parent()); |
| 347 // TODO(mfomitchev): This is unused. We probably don't need this. | |
| 258 if (parent && parent->surface_id_handler_) { | 348 if (parent && parent->surface_id_handler_) { |
| 259 parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, | 349 parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, |
| 260 &surface_info); | 350 &surface_info); |
| 261 } | 351 } |
| 352 | |
| 353 // The fact that SetSurfaceIdFromServer was called means that this window | |
| 354 // corresponds to an embedded client. Update the surface layer dedicated to | |
| 355 // holding the client's content. | |
| 356 UpdateSurfaceLayer(surface_info.get()); | |
| 357 | |
| 262 surface_info_ = std::move(surface_info); | 358 surface_info_ = std::move(surface_info); |
| 263 } | 359 } |
| 264 | 360 |
| 265 void WindowPortMus::DestroyFromServer() { | 361 void WindowPortMus::DestroyFromServer() { |
| 266 std::unique_ptr<ScopedServerChange> remove_from_parent_change; | 362 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
| 267 if (window_->parent()) { | 363 if (window_->parent()) { |
| 268 ServerChangeData data; | 364 ServerChangeData data; |
| 269 data.child_id = server_id(); | 365 data.child_id = server_id(); |
| 270 WindowPortMus* parent = Get(window_->parent()); | 366 WindowPortMus* parent = Get(window_->parent()); |
| 271 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( | 367 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 change_data.property_name = | 521 change_data.property_name = |
| 426 GetPropertyConverter()->GetTransportNameForPropertyKey(key); | 522 GetPropertyConverter()->GetTransportNameForPropertyKey(key); |
| 427 // TODO(sky): investigate to see if we need to compare data. In particular do | 523 // TODO(sky): investigate to see if we need to compare data. In particular do |
| 428 // we ever have a case where changing a property cascades into changing the | 524 // we ever have a case where changing a property cascades into changing the |
| 429 // same property? | 525 // same property? |
| 430 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 526 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 431 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); | 527 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); |
| 432 } | 528 } |
| 433 | 529 |
| 434 } // namespace aura | 530 } // namespace aura |
| OLD | NEW |