Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / layers / surface_layer.cc
blobdc88810dc8aefa2258505cee6e5de754af4c0ae3
1 // Copyright 2014 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.
5 #include "cc/layers/surface_layer.h"
7 #include "cc/layers/surface_layer_impl.h"
8 #include "cc/output/swap_promise.h"
9 #include "cc/trees/layer_tree_host.h"
11 namespace cc {
13 class SatisfySwapPromise : public SwapPromise {
14 public:
15 SatisfySwapPromise(SurfaceSequence sequence,
16 const SurfaceLayer::SatisfyCallback& satisfy_callback)
17 : sequence_(sequence), satisfy_callback_(satisfy_callback) {}
19 ~SatisfySwapPromise() override {}
21 private:
22 void DidActivate() override {}
23 void DidSwap(CompositorFrameMetadata* metadata) override {
24 metadata->satisfies_sequences.push_back(sequence_.sequence);
27 void DidNotSwap(DidNotSwapReason reason) override {
28 satisfy_callback_.Run(sequence_);
30 int64 TraceId() const override { return 0; }
32 SurfaceSequence sequence_;
33 SurfaceLayer::SatisfyCallback satisfy_callback_;
35 DISALLOW_COPY_AND_ASSIGN(SatisfySwapPromise);
38 scoped_refptr<SurfaceLayer> SurfaceLayer::Create(
39 const LayerSettings& settings,
40 const SatisfyCallback& satisfy_callback,
41 const RequireCallback& require_callback) {
42 return make_scoped_refptr(
43 new SurfaceLayer(settings, satisfy_callback, require_callback));
46 SurfaceLayer::SurfaceLayer(const LayerSettings& settings,
47 const SatisfyCallback& satisfy_callback,
48 const RequireCallback& require_callback)
49 : Layer(settings),
50 surface_scale_(1.f),
51 satisfy_callback_(satisfy_callback),
52 require_callback_(require_callback) {
55 SurfaceLayer::~SurfaceLayer() {
56 DCHECK(!layer_tree_host());
57 DCHECK(destroy_sequence_.is_null());
60 void SurfaceLayer::SetSurfaceId(SurfaceId surface_id,
61 float scale,
62 const gfx::Size& size) {
63 SatisfyDestroySequence();
64 surface_id_ = surface_id;
65 surface_size_ = size;
66 surface_scale_ = scale;
67 CreateNewDestroySequence();
69 UpdateDrawsContent(HasDrawableContent());
70 SetNeedsPushProperties();
73 scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
74 return SurfaceLayerImpl::Create(tree_impl, id());
77 bool SurfaceLayer::HasDrawableContent() const {
78 return !surface_id_.is_null() && Layer::HasDrawableContent();
81 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) {
82 if (layer_tree_host() == host) {
83 Layer::SetLayerTreeHost(host);
84 return;
87 SatisfyDestroySequence();
88 Layer::SetLayerTreeHost(host);
89 CreateNewDestroySequence();
92 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
93 Layer::PushPropertiesTo(layer);
94 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
96 layer_impl->SetSurfaceId(surface_id_);
99 void SurfaceLayer::CalculateContentsScale(float ideal_contents_scale,
100 float* contents_scale_x,
101 float* contents_scale_y,
102 gfx::Size* content_bounds) {
103 *content_bounds = surface_size_;
104 *contents_scale_x = surface_scale_;
105 *contents_scale_y = surface_scale_;
108 void SurfaceLayer::CreateNewDestroySequence() {
109 DCHECK(destroy_sequence_.is_null());
110 if (layer_tree_host()) {
111 destroy_sequence_ = layer_tree_host()->CreateSurfaceSequence();
112 require_callback_.Run(surface_id_, destroy_sequence_);
116 void SurfaceLayer::SatisfyDestroySequence() {
117 if (!layer_tree_host())
118 return;
119 DCHECK(!destroy_sequence_.is_null());
120 scoped_ptr<SatisfySwapPromise> satisfy(
121 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_));
122 layer_tree_host()->QueueSwapPromise(satisfy.Pass());
123 destroy_sequence_ = SurfaceSequence();
126 } // namespace cc