• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "FrameMetricsReporter.h"
18 
19 #include "FrameInfo.h"
20 
21 namespace android {
22 namespace uirenderer {
23 
reportFrameMetrics(const FrameInfoBuffer & stats,bool hasPresentTime,uint64_t frameNumber,int32_t surfaceControlId)24 void FrameMetricsReporter::reportFrameMetrics(const FrameInfoBuffer& stats, bool hasPresentTime,
25                                               uint64_t frameNumber, int32_t surfaceControlId) {
26     FatVector<sp<FrameMetricsObserver>, 10> copy;
27     {
28         std::lock_guard lock(mObserversLock);
29         copy.reserve(mObservers.size());
30         for (size_t i = 0; i < mObservers.size(); i++) {
31             auto observer = mObservers[i];
32 
33             if (CC_UNLIKELY(surfaceControlId < observer->attachedSurfaceControlId())) {
34                 // Don't notify if the metrics are from a frame that was run on an old
35                 // surface (one from before the observer was attached).
36                 ALOGV("skipped reporting metrics from old surface %d", surfaceControlId);
37                 continue;
38             } else if (CC_UNLIKELY(surfaceControlId == observer->attachedSurfaceControlId() &&
39                                    frameNumber < observer->attachedFrameNumber())) {
40                 // Don't notify if the metrics are from a frame that was queued by the
41                 // BufferQueueProducer on the render thread before the observer was attached.
42                 ALOGV("skipped reporting metrics from old frame %ld", (long)frameNumber);
43                 continue;
44             }
45 
46             const bool wantsPresentTime = observer->waitForPresentTime();
47             if (hasPresentTime == wantsPresentTime) {
48                 copy.push_back(observer);
49             }
50         }
51     }
52     for (size_t i = 0; i < copy.size(); i++) {
53         copy[i]->notify(stats);
54     }
55 }
56 
57 }  // namespace uirenderer
58 }  // namespace android
59