Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: cc/layers/surface_layer.cc

Issue 666163006: Allow layers to signal that additional sequences are needed before surface destruction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/surfaces/surface_manager.h"
10 #include "cc/trees/layer_tree_host.h"
8 11
9 namespace cc { 12 namespace cc {
10 13
11 scoped_refptr<SurfaceLayer> SurfaceLayer::Create() { 14 class SatisfySwapPromise : public SwapPromise {
12 return make_scoped_refptr(new SurfaceLayer); 15 public:
16 SatisfySwapPromise(SurfaceSequence sequence,
17 SurfaceLayer::SatisfyCallback satisfy_callback)
18 : sequence_(sequence), satisfy_callback_(satisfy_callback) {}
piman 2014/11/05 00:36:15 need a virtual destructor.
19
20 private:
21 void DidSwap(CompositorFrameMetadata* metadata) override {
piman 2014/11/05 00:36:15 Can we add a ThreadChecker in constructor/destruct
22 metadata->satisfies_sequences.push_back(sequence_.sequence);
23 }
24
25 void DidNotSwap(DidNotSwapReason reason) override {
26 satisfy_callback_.Run(sequence_);
27 }
28 int64 TraceId() const override { return 0; }
29
30 SurfaceSequence sequence_;
31 SurfaceLayer::SatisfyCallback satisfy_callback_;
piman 2014/11/05 00:36:15 nit: DISALLOW_COPY_AND_ASSIGN
32 };
33
34 scoped_refptr<SurfaceLayer> SurfaceLayer::Create(
35 SatisfyCallback satisfy_callback,
36 RequireCallback require_callback) {
37 return make_scoped_refptr(
38 new SurfaceLayer(satisfy_callback, require_callback));
13 } 39 }
14 40
15 SurfaceLayer::SurfaceLayer() : Layer() { 41 SurfaceLayer::SurfaceLayer(SatisfyCallback satisfy_callback,
42 RequireCallback require_callback)
43 : Layer(),
44 satisfy_callback_(satisfy_callback),
45 require_callback_(require_callback) {
16 } 46 }
17 47
18 SurfaceLayer::~SurfaceLayer() {} 48 SurfaceLayer::~SurfaceLayer() {
49 DCHECK(!layer_tree_host());
50 DCHECK(destroy_sequence_.is_null());
51 }
19 52
20 void SurfaceLayer::SetSurfaceId(SurfaceId surface_id) { 53 void SurfaceLayer::SetSurfaceId(SurfaceId surface_id) {
54 SatisfyDestroySequence();
21 surface_id_ = surface_id; 55 surface_id_ = surface_id;
56 CreateNewDestroySequence();
57
22 UpdateDrawsContent(HasDrawableContent()); 58 UpdateDrawsContent(HasDrawableContent());
23 SetNeedsPushProperties(); 59 SetNeedsPushProperties();
24 } 60 }
25 61
26 scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { 62 scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
27 return SurfaceLayerImpl::Create(tree_impl, id()); 63 return SurfaceLayerImpl::Create(tree_impl, id());
28 } 64 }
29 65
30 bool SurfaceLayer::HasDrawableContent() const { 66 bool SurfaceLayer::HasDrawableContent() const {
31 return !surface_id_.is_null() && Layer::HasDrawableContent(); 67 return !surface_id_.is_null() && Layer::HasDrawableContent();
32 } 68 }
33 69
70 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) {
71 if (layer_tree_host() == host) {
72 Layer::SetLayerTreeHost(host);
73 return;
74 }
75
76 SatisfyDestroySequence();
77 Layer::SetLayerTreeHost(host);
78 CreateNewDestroySequence();
79 }
80
34 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { 81 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
35 Layer::PushPropertiesTo(layer); 82 Layer::PushPropertiesTo(layer);
36 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); 83 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
37 84
38 layer_impl->SetSurfaceId(surface_id_); 85 layer_impl->SetSurfaceId(surface_id_);
39 } 86 }
40 87
88 void SurfaceLayer::CreateNewDestroySequence() {
89 DCHECK(destroy_sequence_.is_null());
90 if (layer_tree_host()) {
91 destroy_sequence_ = layer_tree_host()->CreateSurfaceSequence();
92 require_callback_.Run(surface_id_, destroy_sequence_);
93 }
94 }
95
96 void SurfaceLayer::SatisfyDestroySequence() {
97 if (!layer_tree_host())
98 return;
99 DCHECK(!destroy_sequence_.is_null());
100 scoped_ptr<SatisfySwapPromise> satisfy(
101 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_));
102 layer_tree_host()->QueueSwapPromise(satisfy.Pass());
103 destroy_sequence_ = SurfaceSequence();
104 }
105
41 } // namespace cc 106 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698