| 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 #ifndef CC_BASE_SYNCED_PROPERTY_H_ | 5 #ifndef CC_BASE_SYNCED_PROPERTY_H_ |
| 6 #define CC_BASE_SYNCED_PROPERTY_H_ | 6 #define CC_BASE_SYNCED_PROPERTY_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Returns the difference between the last value that was committed and | 53 // Returns the difference between the last value that was committed and |
| 54 // activated from the main thread, and the current total value. | 54 // activated from the main thread, and the current total value. |
| 55 typename T::ValueType Delta() const { return active_delta_.get(); } | 55 typename T::ValueType Delta() const { return active_delta_.get(); } |
| 56 | 56 |
| 57 // Returns the latest active tree delta and also makes a note that this value | 57 // Returns the latest active tree delta and also makes a note that this value |
| 58 // was sent to the main thread. | 58 // was sent to the main thread. |
| 59 typename T::ValueType PullDeltaForMainThread() { | 59 typename T::ValueType PullDeltaForMainThread() { |
| 60 sent_delta_ = active_delta_; | 60 reflected_delta_in_main_tree_ = PendingDelta(); |
| 61 return active_delta_.get(); | 61 return reflected_delta_in_main_tree_.get(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Push the latest value from the main thread onto pending tree-associated | 64 // Push the latest value from the main thread onto pending tree-associated |
| 65 // state. Returns true if this had any effect. | 65 // state. Returns true if this had any effect. |
| 66 bool PushFromMainThread(typename T::ValueType main_thread_value) { | 66 bool PushFromMainThread(typename T::ValueType main_thread_value) { |
| 67 if (pending_base_.get() == main_thread_value) | 67 bool changed = pending_base_.get() != main_thread_value; |
| 68 return false; | |
| 69 | 68 |
| 69 reflected_delta_in_pending_tree_ = reflected_delta_in_main_tree_; |
| 70 reflected_delta_in_main_tree_ = T::Identity(); |
| 70 pending_base_ = T(main_thread_value); | 71 pending_base_ = T(main_thread_value); |
| 71 | 72 |
| 72 return true; | 73 return changed; |
| 73 } | 74 } |
| 74 | 75 |
| 75 // Push the value associated with the pending tree to be the active base | 76 // Push the value associated with the pending tree to be the active base |
| 76 // value. As part of this, subtract the last sent value from the active tree | 77 // value. As part of this, subtract the delta reflected in the pending tree |
| 77 // delta (which will make the delta zero at steady state, or make it contain | 78 // from the active tree delta (which will make the delta zero at steady state, |
| 78 // only the difference since the last send). | 79 // or make it contain only the difference since the last send). |
| 79 bool PushPendingToActive() { | 80 bool PushPendingToActive() { |
| 80 if (active_base_.get() == pending_base_.get() && | 81 bool changed = active_base_.get() != pending_base_.get() || |
| 81 sent_delta_.get() == T::Identity().get()) | 82 active_delta_.get() != PendingDelta().get(); |
| 82 return false; | |
| 83 | 83 |
| 84 active_base_ = pending_base_; | 84 active_base_ = pending_base_; |
| 85 active_delta_ = PendingDelta(); | 85 active_delta_ = PendingDelta(); |
| 86 sent_delta_ = T::Identity(); | 86 reflected_delta_in_pending_tree_ = T::Identity(); |
| 87 clobber_active_value_ = false; | 87 clobber_active_value_ = false; |
| 88 | 88 |
| 89 return true; | 89 return changed; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // This simulates the consequences of the sent value getting committed and | 92 // This simulates the consequences of the sent value getting committed and |
| 93 // activated. The value sent to the main thread ends up combined with the | 93 // activated. |
| 94 // active value, and the sent_delta is subtracted from the delta. | |
| 95 void AbortCommit() { | 94 void AbortCommit() { |
| 96 active_base_ = active_base_.Combine(sent_delta_); | 95 pending_base_ = pending_base_.Combine(reflected_delta_in_main_tree_); |
| 97 active_delta_ = PendingDelta(); | 96 active_base_ = active_base_.Combine(reflected_delta_in_main_tree_); |
| 98 sent_delta_ = T::Identity(); | 97 active_delta_ = active_delta_.InverseCombine(reflected_delta_in_main_tree_); |
| 98 reflected_delta_in_main_tree_ = T::Identity(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Values as last pushed to the pending or active tree respectively, with no | 101 // Values as last pushed to the pending or active tree respectively, with no |
| 102 // impl-thread delta applied. | 102 // impl-thread delta applied. |
| 103 typename T::ValueType PendingBase() const { return pending_base_.get(); } | 103 typename T::ValueType PendingBase() const { return pending_base_.get(); } |
| 104 typename T::ValueType ActiveBase() const { return active_base_.get(); } | 104 typename T::ValueType ActiveBase() const { return active_base_.get(); } |
| 105 | 105 |
| 106 // The new delta we would use if we decide to activate now. This delta | 106 // The new delta we would use if we decide to activate now. This delta |
| 107 // excludes the amount that we expect the main thread to reflect back at the | 107 // excludes the amount that we know is reflected in the pending tree. |
| 108 // impl thread during the commit. | |
| 109 T PendingDelta() const { | 108 T PendingDelta() const { |
| 110 if (clobber_active_value_) | 109 if (clobber_active_value_) |
| 111 return T::Identity(); | 110 return T::Identity(); |
| 112 return active_delta_.InverseCombine(sent_delta_); | 111 return active_delta_.InverseCombine(reflected_delta_in_pending_tree_); |
| 113 } | 112 } |
| 114 | 113 |
| 115 void set_clobber_active_value() { clobber_active_value_ = true; } | 114 void set_clobber_active_value() { clobber_active_value_ = true; } |
| 116 bool clobber_active_value() const { return clobber_active_value_; } | 115 bool clobber_active_value() const { return clobber_active_value_; } |
| 117 | 116 |
| 118 private: | 117 private: |
| 119 // Value last committed to the pending tree. | 118 // Value last committed to the pending tree. |
| 120 T pending_base_; | 119 T pending_base_; |
| 121 // Value last committed to the active tree (on the last activation). | 120 // Value last committed to the active tree on the last activation. |
| 122 T active_base_; | 121 T active_base_; |
| 123 // The difference between the active_base_ and the user-perceived value. | 122 // The difference between |active_base_| and the user-perceived value. |
| 124 T active_delta_; | 123 T active_delta_; |
| 125 // The value sent to the main thread (on the last BeginFrame); this is always | 124 // The value sent to the main thread on the last BeginMainFrame. This is |
| 126 // identity outside of the BeginFrame-to-activation interval. | 125 // always identity outside of the BeginMainFrame to (aborted)commit interval. |
| 127 T sent_delta_; | 126 T reflected_delta_in_main_tree_; |
| 127 // The value that was sent to the main thread for BeginMainFrame for the |
| 128 // current pending tree. This is always identity outside of the |
| 129 // BeginMainFrame to activation interval. |
| 130 T reflected_delta_in_pending_tree_; |
| 128 // When true the pending delta is always identity so that it does not change | 131 // When true the pending delta is always identity so that it does not change |
| 129 // and will clobber the active value on push. | 132 // and will clobber the active value on push. |
| 130 bool clobber_active_value_; | 133 bool clobber_active_value_; |
| 131 | 134 |
| 132 friend class base::RefCounted<SyncedProperty<T>>; | 135 friend class base::RefCounted<SyncedProperty<T>>; |
| 133 ~SyncedProperty() {} | 136 ~SyncedProperty() {} |
| 134 }; | 137 }; |
| 135 | 138 |
| 136 // SyncedProperty's delta-based conflict resolution logic makes sense for any | 139 // SyncedProperty's delta-based conflict resolution logic makes sense for any |
| 137 // mathematical group. In practice, there are two that are useful: | 140 // mathematical group. In practice, there are two that are useful: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return ScaleGroup(value_ / p.value_); | 182 return ScaleGroup(value_ / p.value_); |
| 180 } | 183 } |
| 181 | 184 |
| 182 private: | 185 private: |
| 183 float value_; | 186 float value_; |
| 184 }; | 187 }; |
| 185 | 188 |
| 186 } // namespace cc | 189 } // namespace cc |
| 187 | 190 |
| 188 #endif // CC_BASE_SYNCED_PROPERTY_H_ | 191 #endif // CC_BASE_SYNCED_PROPERTY_H_ |
| OLD | NEW |