Address some additional cleanup work needed for the component flash updates on Linux.
[chromium-blink-merge.git] / cc / layers / surface_layer.cc
blobe1862303caac1e4e6e02c8c70e119d722d8257ba
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_);
97 layer_impl->SetSurfaceSize(surface_size_);
98 layer_impl->SetSurfaceScale(surface_scale_);
101 void SurfaceLayer::CreateNewDestroySequence() {
102 DCHECK(destroy_sequence_.is_null());
103 if (layer_tree_host()) {
104 destroy_sequence_ = layer_tree_host()->CreateSurfaceSequence();
105 require_callback_.Run(surface_id_, destroy_sequence_);
109 void SurfaceLayer::SatisfyDestroySequence() {
110 if (!layer_tree_host())
111 return;
112 DCHECK(!destroy_sequence_.is_null());
113 scoped_ptr<SatisfySwapPromise> satisfy(
114 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_));
115 layer_tree_host()->QueueSwapPromise(satisfy.Pass());
116 destroy_sequence_ = SurfaceSequence();
119 } // namespace cc