Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "cc/layers/surface_layer_impl.h" | 11 #include "cc/layers/surface_layer_impl.h" |
| 12 #include "cc/output/swap_promise.h" | 12 #include "cc/output/swap_promise.h" |
| 13 #include "cc/surfaces/surface_sequence_generator.h" | 13 #include "cc/surfaces/surface_sequence_generator.h" |
| 14 #include "cc/trees/layer_tree_host.h" | 14 #include "cc/trees/layer_tree_host.h" |
| 15 #include "cc/trees/swap_promise_manager.h" | 15 #include "cc/trees/swap_promise_manager.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 class SatisfySwapPromise : public SwapPromise { | 19 class SatisfySwapPromise : public SwapPromise { |
| 20 public: | 20 public: |
| 21 SatisfySwapPromise(SurfaceSequence sequence, | 21 explicit SatisfySwapPromise(SurfaceRefPtr surface_ref) |
| 22 const SurfaceLayer::SatisfyCallback& satisfy_callback) | 22 : surface_ref_(std::move(surface_ref)) {} |
| 23 : sequence_(sequence), satisfy_callback_(satisfy_callback) {} | |
| 24 | 23 |
| 25 ~SatisfySwapPromise() override {} | 24 ~SatisfySwapPromise() override {} |
| 26 | 25 |
| 27 private: | 26 private: |
| 28 void DidActivate() override {} | 27 void DidActivate() override {} |
| 29 void DidSwap(CompositorFrameMetadata* metadata) override { | 28 void DidSwap(CompositorFrameMetadata* metadata) override { |
| 30 metadata->satisfies_sequences.push_back(sequence_.sequence); | 29 surface_ref_->Destroy(metadata); |
| 31 } | 30 } |
| 32 | 31 |
| 33 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override { | 32 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override { |
| 34 satisfy_callback_.Run(sequence_); | 33 surface_ref_->Destroy(); |
| 35 return DidNotSwapAction::BREAK_PROMISE; | 34 return DidNotSwapAction::BREAK_PROMISE; |
| 36 } | 35 } |
| 37 int64_t TraceId() const override { return 0; } | 36 int64_t TraceId() const override { return 0; } |
| 38 | 37 |
| 39 SurfaceSequence sequence_; | 38 SurfaceRefPtr surface_ref_; |
| 40 SurfaceLayer::SatisfyCallback satisfy_callback_; | |
| 41 | 39 |
| 42 DISALLOW_COPY_AND_ASSIGN(SatisfySwapPromise); | 40 DISALLOW_COPY_AND_ASSIGN(SatisfySwapPromise); |
| 43 }; | 41 }; |
| 44 | 42 |
| 45 scoped_refptr<SurfaceLayer> SurfaceLayer::Create( | 43 scoped_refptr<SurfaceLayer> SurfaceLayer::Create() { |
| 46 const SatisfyCallback& satisfy_callback, | 44 return make_scoped_refptr(new SurfaceLayer()); |
| 47 const RequireCallback& require_callback) { | |
| 48 return make_scoped_refptr( | |
| 49 new SurfaceLayer(satisfy_callback, require_callback)); | |
| 50 } | 45 } |
| 51 | 46 |
| 52 SurfaceLayer::SurfaceLayer(const SatisfyCallback& satisfy_callback, | 47 scoped_refptr<SurfaceLayer> SurfaceLayer::Create( |
| 53 const RequireCallback& require_callback) | 48 SurfaceEmbeddingPtr surface_ref) { |
| 54 : surface_scale_(1.f), | 49 return make_scoped_refptr(new SurfaceLayer(std::move(surface_ref))); |
| 55 satisfy_callback_(satisfy_callback), | 50 } |
| 56 require_callback_(require_callback) {} | 51 |
| 52 SurfaceLayer::SurfaceLayer() {} | |
| 53 | |
| 54 SurfaceLayer::SurfaceLayer(SurfaceEmbeddingPtr surface_ref) { | |
| 55 SetSurfaceEmbedding(std::move(surface_ref)); | |
| 56 } | |
| 57 | 57 |
| 58 SurfaceLayer::~SurfaceLayer() { | 58 SurfaceLayer::~SurfaceLayer() { |
| 59 DCHECK(!layer_tree_host()); | 59 DCHECK(!layer_tree_host()); |
| 60 DCHECK(!destroy_sequence_.is_valid()); | |
| 61 } | 60 } |
| 62 | 61 |
| 63 void SurfaceLayer::SetSurfaceId(const SurfaceId& surface_id, | 62 void SurfaceLayer::SetSurfaceEmbedding(SurfaceEmbeddingPtr surface_ref) { |
| 64 float scale, | 63 RemoveCurrentReference(); |
| 65 const gfx::Size& size) { | 64 surface_emb_ = std::move(surface_ref); |
| 66 SatisfyDestroySequence(); | 65 if (layer_tree_host()) |
| 67 surface_id_ = surface_id; | 66 current_ref_ = surface_emb_->CreateReference(layer_tree_host()); |
|
Fady Samuel
2016/12/12 16:11:59
if (layer_tree_host())
surface_embedding_->Bind(
| |
| 68 surface_size_ = size; | |
| 69 surface_scale_ = scale; | |
| 70 CreateNewDestroySequence(); | |
| 71 | |
| 72 UpdateDrawsContent(HasDrawableContent()); | 67 UpdateDrawsContent(HasDrawableContent()); |
| 73 SetNeedsPushProperties(); | 68 SetNeedsPushProperties(); |
| 74 } | 69 } |
| 75 | 70 |
| 76 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( | 71 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( |
| 77 LayerTreeImpl* tree_impl) { | 72 LayerTreeImpl* tree_impl) { |
| 78 return SurfaceLayerImpl::Create(tree_impl, id()); | 73 return SurfaceLayerImpl::Create(tree_impl, id()); |
| 79 } | 74 } |
| 80 | 75 |
| 81 bool SurfaceLayer::HasDrawableContent() const { | 76 bool SurfaceLayer::HasDrawableContent() const { |
| 82 return surface_id_.is_valid() && Layer::HasDrawableContent(); | 77 return surface_emb_->id().is_valid() && Layer::HasDrawableContent(); |
| 83 } | 78 } |
| 84 | 79 |
| 85 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { | 80 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 86 if (layer_tree_host() == host) { | 81 if (layer_tree_host() == host) { |
| 87 Layer::SetLayerTreeHost(host); | 82 Layer::SetLayerTreeHost(host); |
| 88 return; | 83 return; |
| 89 } | 84 } |
| 90 | 85 RemoveCurrentReference(); |
| 91 SatisfyDestroySequence(); | |
| 92 Layer::SetLayerTreeHost(host); | 86 Layer::SetLayerTreeHost(host); |
| 93 CreateNewDestroySequence(); | 87 if (surface_emb_ && layer_tree_host()) |
| 88 current_ref_ = surface_emb_->CreateReference(layer_tree_host()); | |
|
Fady Samuel
2016/12/12 16:11:59
surface_embedding_ = surface_embedding_->CloneSurf
| |
| 94 } | 89 } |
| 95 | 90 |
| 96 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { | 91 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { |
| 97 Layer::PushPropertiesTo(layer); | 92 Layer::PushPropertiesTo(layer); |
| 98 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); | 93 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); |
| 99 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); | 94 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); |
| 100 | 95 layer_impl->SetSurfaceInfo(surface_emb_->info()); |
| 101 layer_impl->SetSurfaceId(surface_id_); | |
| 102 layer_impl->SetSurfaceSize(surface_size_); | |
| 103 layer_impl->SetSurfaceScale(surface_scale_); | |
| 104 } | 96 } |
| 105 | 97 |
| 106 void SurfaceLayer::CreateNewDestroySequence() { | 98 void SurfaceLayer::RemoveCurrentReference() { |
| 107 DCHECK(!destroy_sequence_.is_valid()); | 99 if (!current_ref_) |
| 108 if (layer_tree_host()) { | |
| 109 destroy_sequence_ = layer_tree_host() | |
| 110 ->GetSurfaceSequenceGenerator() | |
| 111 ->CreateSurfaceSequence(); | |
| 112 require_callback_.Run(surface_id_, destroy_sequence_); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 void SurfaceLayer::SatisfyDestroySequence() { | |
| 117 if (!layer_tree_host()) | |
| 118 return; | 100 return; |
| 119 DCHECK(destroy_sequence_.is_valid()); | |
| 120 std::unique_ptr<SatisfySwapPromise> satisfy( | 101 std::unique_ptr<SatisfySwapPromise> satisfy( |
| 121 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_)); | 102 new SatisfySwapPromise(std::move(current_ref_))); |
|
Fady Samuel
2016/12/12 16:11:59
Have this take in a SurfaceEmbedding.
| |
| 122 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( | 103 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( |
| 123 std::move(satisfy)); | 104 std::move(satisfy)); |
| 124 destroy_sequence_ = SurfaceSequence(); | |
| 125 } | 105 } |
| 126 | 106 |
| 127 } // namespace cc | 107 } // namespace cc |
| OLD | NEW |