Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: cc/base/synced_property.h

Issue 2035543003: cc: Fix for synced property main thread updates with MFBA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/trees/layer_tree_host_unittest_scroll.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 sent_delta_ = PendingDelta();
61 return active_delta_.get(); 61 return sent_delta_.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 sent_delta_for_pending_tree_ = sent_delta_;
70 sent_delta_ = 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 last sent value from the active tree
77 // delta (which will make the delta zero at steady state, or make it contain 78 // delta (which will make the delta zero at steady state, or make it contain
78 // only the difference since the last send). 79 // 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 sent_delta_for_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. The value sent to the main thread ends up combined with the
94 // active value, and the sent_delta is subtracted from the delta. 94 // active value, and the sent_delta is subtracted from the delta.
95 void AbortCommit() { 95 void AbortCommit() {
96 pending_base_ = pending_base_.Combine(sent_delta_);
96 active_base_ = active_base_.Combine(sent_delta_); 97 active_base_ = active_base_.Combine(sent_delta_);
97 active_delta_ = PendingDelta(); 98 active_delta_ = active_delta_.InverseCombine(sent_delta_);
98 sent_delta_ = T::Identity(); 99 sent_delta_ = T::Identity();
99 } 100 }
100 101
101 // Values as last pushed to the pending or active tree respectively, with no 102 // Values as last pushed to the pending or active tree respectively, with no
102 // impl-thread delta applied. 103 // impl-thread delta applied.
103 typename T::ValueType PendingBase() const { return pending_base_.get(); } 104 typename T::ValueType PendingBase() const { return pending_base_.get(); }
104 typename T::ValueType ActiveBase() const { return active_base_.get(); } 105 typename T::ValueType ActiveBase() const { return active_base_.get(); }
105 106
106 // The new delta we would use if we decide to activate now. This delta 107 // 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 108 // excludes the amount that we expect the main thread to reflect back at the
108 // impl thread during the commit. 109 // impl thread during the commit.
109 T PendingDelta() const { 110 T PendingDelta() const {
110 if (clobber_active_value_) 111 if (clobber_active_value_)
111 return T::Identity(); 112 return T::Identity();
112 return active_delta_.InverseCombine(sent_delta_); 113 return active_delta_.InverseCombine(sent_delta_for_pending_tree_);
113 } 114 }
114 115
115 void set_clobber_active_value() { clobber_active_value_ = true; } 116 void set_clobber_active_value() { clobber_active_value_ = true; }
116 bool clobber_active_value() const { return clobber_active_value_; } 117 bool clobber_active_value() const { return clobber_active_value_; }
117 118
118 private: 119 private:
119 // Value last committed to the pending tree. 120 // Value last committed to the pending tree.
120 T pending_base_; 121 T pending_base_;
121 // Value last committed to the active tree (on the last activation). 122 // Value last committed to the active tree (on the last activation).
122 T active_base_; 123 T active_base_;
123 // The difference between the active_base_ and the user-perceived value. 124 // The difference between |active_base_| and the user-perceived value.
124 T active_delta_; 125 T active_delta_;
125 // The value sent to the main thread (on the last BeginFrame); this is always 126 // The value sent to the main thread (on the last BeginFrame); this is always
126 // identity outside of the BeginFrame-to-activation interval. 127 // identity outside of the BeginFrame-to-(aborted)commit interval.
127 T sent_delta_; 128 T sent_delta_;
aelias_OOO_until_Jul13 2016/06/09 00:46:13 How about switching the names to: "reflected_delta
sunnyps 2016/06/09 01:08:56 Done.
129 // The value that was sent to the main thread for BeginFrame for the current
130 // pending tree.
aelias_OOO_until_Jul13 2016/06/09 00:46:13 Please add comment: "This is always identity outsi
sunnyps 2016/06/09 01:08:56 Done. Also changed some of the other comments.
131 T sent_delta_for_pending_tree_;
128 // When true the pending delta is always identity so that it does not change 132 // When true the pending delta is always identity so that it does not change
129 // and will clobber the active value on push. 133 // and will clobber the active value on push.
130 bool clobber_active_value_; 134 bool clobber_active_value_;
131 135
132 friend class base::RefCounted<SyncedProperty<T>>; 136 friend class base::RefCounted<SyncedProperty<T>>;
133 ~SyncedProperty() {} 137 ~SyncedProperty() {}
134 }; 138 };
135 139
136 // SyncedProperty's delta-based conflict resolution logic makes sense for any 140 // SyncedProperty's delta-based conflict resolution logic makes sense for any
137 // mathematical group. In practice, there are two that are useful: 141 // mathematical group. In practice, there are two that are useful:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return ScaleGroup(value_ / p.value_); 183 return ScaleGroup(value_ / p.value_);
180 } 184 }
181 185
182 private: 186 private:
183 float value_; 187 float value_;
184 }; 188 };
185 189
186 } // namespace cc 190 } // namespace cc
187 191
188 #endif // CC_BASE_SYNCED_PROPERTY_H_ 192 #endif // CC_BASE_SYNCED_PROPERTY_H_
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_host_unittest_scroll.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698