OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/aura/mus/client_surface_embedder.h" | |
6 | |
7 #include "cc/surfaces/surface_reference_factory.h" | |
8 #include "ui/aura/mus/surface_id_handler.h" | |
9 #include "ui/aura/window.h" | |
10 | |
11 namespace aura { | |
12 namespace { | |
13 | |
14 // TODO(mfomitchev, samans): Remove these stub classes once the SurfaceReference | |
15 // work is complete. | |
16 class StubSurfaceReference : public cc::SurfaceReferenceBase { | |
17 public: | |
18 StubSurfaceReference(scoped_refptr<const cc::SurfaceReferenceFactory> factory) | |
19 : cc::SurfaceReferenceBase(factory) {} | |
20 | |
21 ~StubSurfaceReference() override { Destroy(); } | |
22 | |
23 private: | |
24 DISALLOW_COPY_AND_ASSIGN(StubSurfaceReference); | |
25 }; | |
26 | |
27 class StubSurfaceReferenceFactory : public cc::SurfaceReferenceFactory { | |
28 public: | |
29 StubSurfaceReferenceFactory() = default; | |
30 | |
31 // cc::SurfaceReferenceFactory: | |
32 std::unique_ptr<cc::SurfaceReferenceBase> CreateReference( | |
33 cc::SurfaceReferenceOwner* owner, | |
34 const cc::SurfaceId& surface_id) const override { | |
35 return base::MakeUnique<StubSurfaceReference>(make_scoped_refptr(this)); | |
36 } | |
37 | |
38 protected: | |
39 ~StubSurfaceReferenceFactory() override = default; | |
40 | |
41 private: | |
42 // cc::SurfaceReferenceFactory: | |
43 void DestroyReference(cc::SurfaceReferenceBase* surface_ref) const override {} | |
44 | |
45 DISALLOW_COPY_AND_ASSIGN(StubSurfaceReferenceFactory); | |
46 }; | |
47 } // namespace | |
48 | |
49 ClientSurfaceEmbedder::ClientSurfaceEmbedder(Window* window) : window_(window) { | |
50 surface_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_TEXTURED); | |
51 surface_layer_->SetVisible(true); | |
52 // The frame provided by the parent window->layer() needs to show through | |
53 // the surface layer. | |
54 surface_layer_->SetFillsBoundsOpaquely(false); | |
55 | |
56 clip_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_NOT_DRAWN); | |
57 clip_layer_->SetFillsBoundsOpaquely(false); | |
58 | |
59 clip_layer_->Add(surface_layer_.get()); | |
60 window_->layer()->Add(clip_layer_.get()); | |
61 | |
62 // Window's layer may contain content from this client (the embedder), e.g. | |
63 // this is the case with window decorations provided by Window Manager. | |
64 // This content should appear underneath the content of the embedded client. | |
65 window_->layer()->StackAtTop(clip_layer_.get()); | |
66 | |
67 // We can't set this on window's layer, because that would clip the window | |
68 // shadow. | |
69 clip_layer_->SetMasksToBounds(true); | |
70 } | |
71 | |
72 ClientSurfaceEmbedder::~ClientSurfaceEmbedder() = default; | |
73 | |
74 void ClientSurfaceEmbedder::UpdateSurface(const cc::SurfaceInfo& surface_info) { | |
75 // TODO(mfomitchev): Currently the frame size may not match the window size. | |
76 // In the future the surface id will be created by Ash (and used with the | |
77 // surface layer) when the window resize happens, which will ensure that the | |
78 // surface size matches the window size (unless a timeout occurs). | |
79 gfx::Size frame_size = surface_info.size_in_pixels(); | |
80 surface_layer_->SetBounds( | |
81 gfx::Rect(0, 0, frame_size.width(), frame_size.height())); | |
82 // Clip to window bounds. | |
83 clip_layer_->SetBounds( | |
84 gfx::Rect(0, 0, window_->bounds().width(), window_->bounds().height())); | |
85 | |
86 surface_layer_->SetShowSurface( | |
87 surface_info, make_scoped_refptr(new StubSurfaceReferenceFactory)); | |
88 } | |
89 | |
90 } // namespace aura | |
OLD | NEW |