summaryrefslogtreecommitdiff
path: root/libs/hwui/renderthread/CanvasContext.h
diff options
context:
space:
mode:
authorSiarhei Vishniakou <svv@google.com>2021-07-03 02:22:12 +0000
committerSiarhei Vishniakou <svv@google.com>2021-07-09 00:32:29 +0000
commit07d35cb7dcb6e078968f72c831de555b060424a3 (patch)
tree0a51f5bcde952717e835a767e5f974c144a95da5 /libs/hwui/renderthread/CanvasContext.h
parentc701a4c904600cb5457d0ebc2821d7e837e26f96 (diff)
Properly protect mFrameMetricsReporter
This field actually requires a special lock, mFrameMetricsReporterMutex. But there isn't a GUARDED_BY annotation for it. And even if there was, the compiler feature of -Wthread-safety was not active in this code, so this error would not have been caught. To fix this, enable the compiler annotation and add GUARDED_BY annotation to mFrameMetricsReporter. And finally, use this lock to properly protect this field. Bug: 192330836 Test: atest hwui_unit_tests Change-Id: I76950bfa01bbd7ccdc54c4e8c114430b5aeddf1a
Diffstat (limited to 'libs/hwui/renderthread/CanvasContext.h')
-rw-r--r--libs/hwui/renderthread/CanvasContext.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index 85af3e4fb0b6..6dbfcc349d50 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -160,6 +160,7 @@ public:
void setContentDrawBounds(const Rect& bounds) { mContentDrawBounds = bounds; }
void addFrameMetricsObserver(FrameMetricsObserver* observer) {
+ std::scoped_lock lock(mFrameMetricsReporterMutex);
if (mFrameMetricsReporter.get() == nullptr) {
mFrameMetricsReporter.reset(new FrameMetricsReporter());
}
@@ -168,10 +169,10 @@ public:
}
void removeFrameMetricsObserver(FrameMetricsObserver* observer) {
+ std::scoped_lock lock(mFrameMetricsReporterMutex);
if (mFrameMetricsReporter.get() != nullptr) {
mFrameMetricsReporter->removeObserver(observer);
if (!mFrameMetricsReporter->hasObservers()) {
- std::lock_guard lock(mFrameMetricsReporterMutex);
mFrameMetricsReporter.reset(nullptr);
}
}
@@ -245,6 +246,8 @@ private:
*/
void reportMetricsWithPresentTime();
+ FrameInfo* getFrameInfoFromLast4(uint64_t frameNumber);
+
// The same type as Frame.mWidth and Frame.mHeight
int32_t mLastFrameWidth = 0;
int32_t mLastFrameHeight = 0;
@@ -305,7 +308,8 @@ private:
std::string mName;
JankTracker mJankTracker;
FrameInfoVisualizer mProfiler;
- std::unique_ptr<FrameMetricsReporter> mFrameMetricsReporter;
+ std::unique_ptr<FrameMetricsReporter> mFrameMetricsReporter
+ GUARDED_BY(mFrameMetricsReporterMutex);
std::mutex mFrameMetricsReporterMutex;
std::set<RenderNode*> mPrefetchedLayers;