| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 #ifndef CC_BLIMP_SYNCED_PROPERTY_REMOTE_H_ |
| 6 #define CC_BLIMP_SYNCED_PROPERTY_REMOTE_H_ |
| 7 |
| 8 #include "cc/base/synced_property.h" |
| 9 |
| 10 namespace cc { |
| 11 |
| 12 // This class is heavily inspired from SyncedProperty and is the equivalent of |
| 13 // SyncedProperty for synchronizing state between the engine and client in |
| 14 // remote mode. There are effectively 2 trees on the main thread, the LayerTree |
| 15 // on the main thread on the engine, and the tree on the main thread on the |
| 16 // client. |
| 17 // |
| 18 // The client main thread tree receives deltas from the impl thread, but must |
| 19 // synchronize them with the engine main thread before applying them onto the |
| 20 // the main thread associated state. At the same time there are different sets |
| 21 // of deltas, the value that was received from the impl thread but has not yet |
| 22 // been reported to the engine main thread, and the value that has been sent |
| 23 // to the engine main thread, but a state update with the application of these |
| 24 // deltas has not been received from the engine. The purpose of this class is to |
| 25 // track these deltas for deciding what needs to be reported to the main thread |
| 26 // on the engine, and providing the impl thread with the delta that it should |
| 27 // apply to its associated state since it could not be reflected in the local |
| 28 // BeginMainFrame on the client main thread. |
| 29 // |
| 30 // Instances of this class are held on the client main thread and have a 1:1 |
| 31 // mapping with their corresponding SyncedProperty instances. |
| 32 |
| 33 // Note: This class currently supports only one set of deltas to be in flight to |
| 34 // the engine. |
| 35 template <typename T> |
| 36 class SyncedPropertyRemote { |
| 37 public: |
| 38 SyncedPropertyRemote() = default; |
| 39 |
| 40 SyncedPropertyRemote(SyncedPropertyRemote&& other) = default; |
| 41 |
| 42 SyncedPropertyRemote& operator=(SyncedPropertyRemote&& other) = default; |
| 43 |
| 44 // Push the main thread state from the engine onto the client main thread |
| 45 // associated state. |
| 46 void PushFromEngineMainThread( |
| 47 typename T::ValueType engine_main_thread_value) { |
| 48 engine_main_base_ = T(engine_main_thread_value); |
| 49 } |
| 50 |
| 51 // Called when an update for changes made on the impl thread was received on |
| 52 // the client main thread. |
| 53 // |main_thread_value| holds the updated value on the client main thread. |
| 54 void UpdateDeltaFromImplThread(typename T::ValueType main_thread_value) { |
| 55 T delta_from_impl_thread = |
| 56 T(main_thread_value).InverseCombine(engine_main_base_); |
| 57 unsent_delta_from_impl_thread_ = |
| 58 unsent_delta_from_impl_thread_.Combine(delta_from_impl_thread); |
| 59 } |
| 60 |
| 61 // Pull deltas for changes tracked on the client main thread to be sent to the |
| 62 // engine main thread. |
| 63 // Each call to this must be followed with a call to DidApplySentDeltaOnEngine |
| 64 // before another set of deltas can be pulled. |
| 65 typename T::ValueType PullDeltaForEngineUpdate() { |
| 66 DCHECK(sent_but_unapplied_delta_from_impl_thread_.get() == |
| 67 T::Identity().get()); |
| 68 |
| 69 T delta_to_send = unsent_delta_from_impl_thread_; |
| 70 sent_but_unapplied_delta_from_impl_thread_ = delta_to_send; |
| 71 unsent_delta_from_impl_thread_ = T::Identity(); |
| 72 return delta_to_send.get(); |
| 73 } |
| 74 |
| 75 // Called when deltas sent to the engine were applied to the main thread state |
| 76 // on the engine. |
| 77 void DidApplySentDeltaOnEngine() { |
| 78 // Pre-emptively apply the deltas that were sent. This is necessary since |
| 79 // the engine may not send a frame update if the deltas were simply |
| 80 // reflected back by the engine main thread (equivalent to |
| 81 // BeginMainFrameAborted between the main and impl thread). |
| 82 // If the engine did send a frame, we expect the frame to come with the ack |
| 83 // for the deltas, so the value will be over-written with the engine update |
| 84 // before being pushed to the impl thread. |
| 85 engine_main_base_ = |
| 86 engine_main_base_.Combine(sent_but_unapplied_delta_from_impl_thread_); |
| 87 sent_but_unapplied_delta_from_impl_thread_ = T::Identity(); |
| 88 } |
| 89 |
| 90 // Returns the delta that was reported to the main thread on the client but |
| 91 // has not yet been applied to the main thread on the engine. |
| 92 typename T::ValueType DeltaNotAppliedOnEngine() { |
| 93 T total_delta_on_client = unsent_delta_from_impl_thread_.Combine( |
| 94 sent_but_unapplied_delta_from_impl_thread_); |
| 95 return total_delta_on_client.get(); |
| 96 } |
| 97 |
| 98 typename T::ValueType EngineMain() { return engine_main_base_.get(); } |
| 99 |
| 100 private: |
| 101 // The delta that was applied to the state on the impl thread and received on |
| 102 // the main thread on the client during BeginMainFrame, but has not yet been |
| 103 // reported to the main thread on the engine. |
| 104 T unsent_delta_from_impl_thread_; |
| 105 |
| 106 // The delta that was applied to the state on the impl thread and has been |
| 107 // sent to the main thread on the engine, but has not yet been applied to the |
| 108 // main thread on the engine. |
| 109 T sent_but_unapplied_delta_from_impl_thread_; |
| 110 |
| 111 // The value as last received from the main thread on the engine. The value on |
| 112 // the main thread state on the client should always be set to this value, |
| 113 // outside of the interval when deltas from the impl thread are reported to |
| 114 // the main thread on the client. |
| 115 T engine_main_base_; |
| 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(SyncedPropertyRemote); |
| 118 }; |
| 119 |
| 120 } // namespace cc |
| 121 |
| 122 #endif // CC_BLIMP_SYNCED_PROPERTY_REMOTE_H_ |
| OLD | NEW |