OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "cc/layers/surface_layer.h" | 5 #include "cc/layers/surface_layer.h" |
6 | 6 |
| 7 #include "cc/base/swap_promise.h" |
7 #include "cc/layers/surface_layer_impl.h" | 8 #include "cc/layers/surface_layer_impl.h" |
| 9 #include "cc/trees/layer_tree_host.h" |
8 | 10 |
9 namespace cc { | 11 namespace cc { |
10 | 12 |
11 scoped_refptr<SurfaceLayer> SurfaceLayer::Create() { | 13 class SatisfySwapPromise : public SwapPromise { |
12 return make_scoped_refptr(new SurfaceLayer); | 14 public: |
| 15 SatisfySwapPromise(SurfaceSequence sequence, |
| 16 const SurfaceLayer::SatisfyCallback& satisfy_callback) |
| 17 : sequence_(sequence), satisfy_callback_(satisfy_callback) {} |
| 18 |
| 19 ~SatisfySwapPromise() override {} |
| 20 |
| 21 private: |
| 22 void DidSwap(CompositorFrameMetadata* metadata) override { |
| 23 metadata->satisfies_sequences.push_back(sequence_.sequence); |
| 24 } |
| 25 |
| 26 void DidNotSwap(DidNotSwapReason reason) override { |
| 27 satisfy_callback_.Run(sequence_); |
| 28 } |
| 29 int64 TraceId() const override { return 0; } |
| 30 |
| 31 SurfaceSequence sequence_; |
| 32 SurfaceLayer::SatisfyCallback satisfy_callback_; |
| 33 |
| 34 DISALLOW_COPY_AND_ASSIGN(SatisfySwapPromise); |
| 35 }; |
| 36 |
| 37 scoped_refptr<SurfaceLayer> SurfaceLayer::Create( |
| 38 const SatisfyCallback& satisfy_callback, |
| 39 const RequireCallback& require_callback) { |
| 40 return make_scoped_refptr( |
| 41 new SurfaceLayer(satisfy_callback, require_callback)); |
13 } | 42 } |
14 | 43 |
15 SurfaceLayer::SurfaceLayer() : Layer() { | 44 SurfaceLayer::SurfaceLayer(const SatisfyCallback& satisfy_callback, |
| 45 const RequireCallback& require_callback) |
| 46 : Layer(), |
| 47 satisfy_callback_(satisfy_callback), |
| 48 require_callback_(require_callback) { |
16 } | 49 } |
17 | 50 |
18 SurfaceLayer::~SurfaceLayer() {} | 51 SurfaceLayer::~SurfaceLayer() { |
| 52 DCHECK(!layer_tree_host()); |
| 53 DCHECK(destroy_sequence_.is_null()); |
| 54 } |
19 | 55 |
20 void SurfaceLayer::SetSurfaceId(SurfaceId surface_id) { | 56 void SurfaceLayer::SetSurfaceId(SurfaceId surface_id) { |
| 57 SatisfyDestroySequence(); |
21 surface_id_ = surface_id; | 58 surface_id_ = surface_id; |
| 59 CreateNewDestroySequence(); |
| 60 |
22 UpdateDrawsContent(HasDrawableContent()); | 61 UpdateDrawsContent(HasDrawableContent()); |
23 SetNeedsPushProperties(); | 62 SetNeedsPushProperties(); |
24 } | 63 } |
25 | 64 |
26 scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 65 scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
27 return SurfaceLayerImpl::Create(tree_impl, id()); | 66 return SurfaceLayerImpl::Create(tree_impl, id()); |
28 } | 67 } |
29 | 68 |
30 bool SurfaceLayer::HasDrawableContent() const { | 69 bool SurfaceLayer::HasDrawableContent() const { |
31 return !surface_id_.is_null() && Layer::HasDrawableContent(); | 70 return !surface_id_.is_null() && Layer::HasDrawableContent(); |
32 } | 71 } |
33 | 72 |
| 73 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 74 if (layer_tree_host() == host) { |
| 75 Layer::SetLayerTreeHost(host); |
| 76 return; |
| 77 } |
| 78 |
| 79 SatisfyDestroySequence(); |
| 80 Layer::SetLayerTreeHost(host); |
| 81 CreateNewDestroySequence(); |
| 82 } |
| 83 |
34 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { | 84 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { |
35 Layer::PushPropertiesTo(layer); | 85 Layer::PushPropertiesTo(layer); |
36 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); | 86 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); |
37 | 87 |
38 layer_impl->SetSurfaceId(surface_id_); | 88 layer_impl->SetSurfaceId(surface_id_); |
39 } | 89 } |
40 | 90 |
| 91 void SurfaceLayer::CreateNewDestroySequence() { |
| 92 DCHECK(destroy_sequence_.is_null()); |
| 93 if (layer_tree_host()) { |
| 94 destroy_sequence_ = layer_tree_host()->CreateSurfaceSequence(); |
| 95 require_callback_.Run(surface_id_, destroy_sequence_); |
| 96 } |
| 97 } |
| 98 |
| 99 void SurfaceLayer::SatisfyDestroySequence() { |
| 100 if (!layer_tree_host()) |
| 101 return; |
| 102 DCHECK(!destroy_sequence_.is_null()); |
| 103 scoped_ptr<SatisfySwapPromise> satisfy( |
| 104 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_)); |
| 105 layer_tree_host()->QueueSwapPromise(satisfy.Pass()); |
| 106 destroy_sequence_ = SurfaceSequence(); |
| 107 } |
| 108 |
41 } // namespace cc | 109 } // namespace cc |
OLD | NEW |