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/threading/thread_task_runner_handle.h" | |
| 10 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 11 #include "cc/layers/surface_layer_impl.h" | 12 #include "cc/layers/surface_layer_impl.h" |
| 12 #include "cc/output/swap_promise.h" | 13 #include "cc/output/swap_promise.h" |
| 13 #include "cc/surfaces/surface_sequence_generator.h" | 14 #include "cc/surfaces/surface_sequence_generator.h" |
| 14 #include "cc/trees/layer_tree_host.h" | 15 #include "cc/trees/layer_tree_host.h" |
| 15 #include "cc/trees/swap_promise_manager.h" | 16 #include "cc/trees/swap_promise_manager.h" |
| 16 | 17 |
| 17 namespace cc { | 18 namespace cc { |
| 18 | 19 |
| 20 namespace { | |
| 21 | |
| 22 // Some thread checkers fail if satisfy callback is not run on the main thread. | |
| 23 void PostSatisfyCallbackToMainThread( | |
| 24 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
| 25 SurfaceLayer::SatisfyCallback satisfy_callback, | |
| 26 SurfaceSequence sequence) { | |
| 27 main_task_runner->PostTask(FROM_HERE, base::Bind(satisfy_callback, sequence)); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 19 class SatisfySwapPromise : public SwapPromise { | 32 class SatisfySwapPromise : public SwapPromise { |
| 20 public: | 33 public: |
| 21 SatisfySwapPromise(SurfaceSequence sequence, | 34 SatisfySwapPromise( |
| 22 const SurfaceLayer::SatisfyCallback& satisfy_callback) | 35 const SurfaceSequence& sequence, |
| 23 : sequence_(sequence), satisfy_callback_(satisfy_callback) {} | 36 const SurfaceLayer::SatisfyCallback& satisfy_callback, |
| 37 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) | |
| 38 : sequence_(sequence), | |
| 39 satisfy_callback_(satisfy_callback), | |
| 40 main_task_runner_(std::move(main_task_runner)) {} | |
| 24 | 41 |
| 25 ~SatisfySwapPromise() override {} | 42 ~SatisfySwapPromise() override {} |
| 26 | 43 |
| 27 private: | 44 private: |
| 28 void DidActivate() override {} | 45 void DidActivate() override {} |
| 29 void DidSwap(CompositorFrameMetadata* metadata) override { | 46 void DidSwap(CompositorFrameMetadata* metadata) override { |
| 30 metadata->satisfies_sequences.push_back(sequence_.sequence); | 47 // This method is called before the swap is actually performed in order to |
| 48 // potentially add some stuff to compositor frame's metadata. | |
| 49 // By posting a task, we ensure that satisfy callback is not called until | |
| 50 // the swap is over. | |
| 51 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
|
Fady Samuel
2016/12/14 05:03:06
Not a huge fan of this, but if jbauman@ is OK with
danakj
2016/12/14 16:17:20
Hm.. this will ofc wait for a fresh callstack, but
| |
| 52 FROM_HERE, base::Bind(PostSatisfyCallbackToMainThread, | |
| 53 main_task_runner_, satisfy_callback_, sequence_)); | |
| 31 } | 54 } |
| 32 | 55 |
| 33 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override { | 56 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override { |
| 34 satisfy_callback_.Run(sequence_); | 57 main_task_runner_->PostTask(FROM_HERE, |
| 58 base::Bind(satisfy_callback_, sequence_)); | |
| 35 return DidNotSwapAction::BREAK_PROMISE; | 59 return DidNotSwapAction::BREAK_PROMISE; |
| 36 } | 60 } |
| 37 int64_t TraceId() const override { return 0; } | 61 int64_t TraceId() const override { return 0; } |
| 38 | 62 |
| 39 SurfaceSequence sequence_; | 63 SurfaceSequence sequence_; |
| 40 SurfaceLayer::SatisfyCallback satisfy_callback_; | 64 SurfaceLayer::SatisfyCallback satisfy_callback_; |
| 65 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
| 41 | 66 |
| 42 DISALLOW_COPY_AND_ASSIGN(SatisfySwapPromise); | 67 DISALLOW_COPY_AND_ASSIGN(SatisfySwapPromise); |
| 43 }; | 68 }; |
| 44 | 69 |
| 45 scoped_refptr<SurfaceLayer> SurfaceLayer::Create( | 70 scoped_refptr<SurfaceLayer> SurfaceLayer::Create( |
| 46 const SatisfyCallback& satisfy_callback, | 71 const SatisfyCallback& satisfy_callback, |
| 47 const RequireCallback& require_callback) { | 72 const RequireCallback& require_callback) { |
| 48 return make_scoped_refptr( | 73 return make_scoped_refptr( |
| 49 new SurfaceLayer(satisfy_callback, require_callback)); | 74 new SurfaceLayer(satisfy_callback, require_callback)); |
| 50 } | 75 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 ->GetSurfaceSequenceGenerator() | 135 ->GetSurfaceSequenceGenerator() |
| 111 ->CreateSurfaceSequence(); | 136 ->CreateSurfaceSequence(); |
| 112 require_callback_.Run(surface_id_, destroy_sequence_); | 137 require_callback_.Run(surface_id_, destroy_sequence_); |
| 113 } | 138 } |
| 114 } | 139 } |
| 115 | 140 |
| 116 void SurfaceLayer::SatisfyDestroySequence() { | 141 void SurfaceLayer::SatisfyDestroySequence() { |
| 117 if (!layer_tree_host()) | 142 if (!layer_tree_host()) |
| 118 return; | 143 return; |
| 119 DCHECK(destroy_sequence_.is_valid()); | 144 DCHECK(destroy_sequence_.is_valid()); |
| 120 std::unique_ptr<SatisfySwapPromise> satisfy( | 145 auto satisfy = |
| 121 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_)); | 146 base::MakeUnique<SatisfySwapPromise>(destroy_sequence_, satisfy_callback_, |
| 147 base::ThreadTaskRunnerHandle::Get()); | |
| 122 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( | 148 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( |
| 123 std::move(satisfy)); | 149 std::move(satisfy)); |
| 124 destroy_sequence_ = SurfaceSequence(); | 150 destroy_sequence_ = SurfaceSequence(); |
| 125 } | 151 } |
| 126 | 152 |
| 127 } // namespace cc | 153 } // namespace cc |
| OLD | NEW |