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() { | |
73 window_->layer()->Remove(clip_layer_.get()); | |
sky
2017/01/03 23:25:05
I believe the destruction order is:
~Window
De
mfomitchev
2017/01/03 23:41:12
Would it be okay to do port_owner_.reset() before
| |
74 } | |
75 | |
76 void ClientSurfaceEmbedder::UpdateSurface(const SurfaceInfo& surface_info) { | |
77 // TODO(mfomitchev): Currently the frame size may not match the window size. | |
78 // In the future the surface id will be created by Ash (and used with the | |
79 // surface layer) when the window resize happens, which will ensure that the | |
80 // surface size matches the window size (unless a timeout occurs). | |
81 gfx::Size frame_size = surface_info.frame_size; | |
82 surface_layer_->SetBounds( | |
83 gfx::Rect(0, 0, frame_size.width(), frame_size.height())); | |
84 // Clip to window bounds. | |
85 clip_layer_->SetBounds( | |
86 gfx::Rect(0, 0, window_->bounds().width(), window_->bounds().height())); | |
87 | |
88 // TODO(mfomitchev, samans): Get rid of Aura's SurfaceInfo. | |
89 cc::SurfaceInfo cc_surface_info(surface_info.surface_id, | |
Fady Samuel
2017/01/04 12:34:18
This should be fixed now. Please rebase.
mfomitchev
2017/01/04 20:45:30
Done.
| |
90 surface_info.device_scale_factor, frame_size); | |
91 | |
92 surface_layer_->SetShowSurface( | |
93 cc_surface_info, make_scoped_refptr(new StubSurfaceReferenceFactory)); | |
94 } | |
95 | |
96 } // namespace aura | |
OLD | NEW |