| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "cc/layers/surface_layer.h" | |
| 6 | |
| 7 #include "cc/layers/surface_layer_impl.h" | |
| 8 #include "cc/output/swap_promise.h" | |
| 9 #include "cc/trees/layer_tree_host.h" | |
| 10 | |
| 11 namespace cc { | |
| 12 | |
| 13 class SatisfySwapPromise : public SwapPromise { | |
| 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)); | |
| 42 } | |
| 43 | |
| 44 SurfaceLayer::SurfaceLayer(const SatisfyCallback& satisfy_callback, | |
| 45 const RequireCallback& require_callback) | |
| 46 : Layer(), | |
| 47 surface_scale_(1.f), | |
| 48 satisfy_callback_(satisfy_callback), | |
| 49 require_callback_(require_callback) { | |
| 50 } | |
| 51 | |
| 52 SurfaceLayer::~SurfaceLayer() { | |
| 53 DCHECK(!layer_tree_host()); | |
| 54 DCHECK(destroy_sequence_.is_null()); | |
| 55 } | |
| 56 | |
| 57 void SurfaceLayer::SetSurfaceId(SurfaceId surface_id, | |
| 58 float scale, | |
| 59 const gfx::Size& size) { | |
| 60 SatisfyDestroySequence(); | |
| 61 surface_id_ = surface_id; | |
| 62 surface_size_ = size; | |
| 63 surface_scale_ = scale; | |
| 64 CreateNewDestroySequence(); | |
| 65 | |
| 66 UpdateDrawsContent(HasDrawableContent()); | |
| 67 SetNeedsPushProperties(); | |
| 68 } | |
| 69 | |
| 70 scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | |
| 71 return SurfaceLayerImpl::Create(tree_impl, id()); | |
| 72 } | |
| 73 | |
| 74 bool SurfaceLayer::HasDrawableContent() const { | |
| 75 return !surface_id_.is_null() && Layer::HasDrawableContent(); | |
| 76 } | |
| 77 | |
| 78 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { | |
| 79 if (layer_tree_host() == host) { | |
| 80 Layer::SetLayerTreeHost(host); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 SatisfyDestroySequence(); | |
| 85 Layer::SetLayerTreeHost(host); | |
| 86 CreateNewDestroySequence(); | |
| 87 } | |
| 88 | |
| 89 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { | |
| 90 Layer::PushPropertiesTo(layer); | |
| 91 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); | |
| 92 | |
| 93 layer_impl->SetSurfaceId(surface_id_); | |
| 94 } | |
| 95 | |
| 96 void SurfaceLayer::CalculateContentsScale(float ideal_contents_scale, | |
| 97 float* contents_scale_x, | |
| 98 float* contents_scale_y, | |
| 99 gfx::Size* content_bounds) { | |
| 100 *content_bounds = surface_size_; | |
| 101 *contents_scale_x = surface_scale_; | |
| 102 *contents_scale_y = surface_scale_; | |
| 103 } | |
| 104 | |
| 105 void SurfaceLayer::CreateNewDestroySequence() { | |
| 106 DCHECK(destroy_sequence_.is_null()); | |
| 107 if (layer_tree_host()) { | |
| 108 destroy_sequence_ = layer_tree_host()->CreateSurfaceSequence(); | |
| 109 require_callback_.Run(surface_id_, destroy_sequence_); | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 void SurfaceLayer::SatisfyDestroySequence() { | |
| 114 if (!layer_tree_host()) | |
| 115 return; | |
| 116 DCHECK(!destroy_sequence_.is_null()); | |
| 117 scoped_ptr<SatisfySwapPromise> satisfy( | |
| 118 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_)); | |
| 119 layer_tree_host()->QueueSwapPromise(satisfy.Pass()); | |
| 120 destroy_sequence_ = SurfaceSequence(); | |
| 121 } | |
| 122 | |
| 123 } // namespace cc | |
| OLD | NEW |