• 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 namespace android {
20 namespace uirenderer {
21 
reportFrameMetrics(const int64_t * stats,bool hasPresentTime,uint64_t frameNumber,int32_t surfaceControlId)22 void FrameMetricsReporter::reportFrameMetrics(const int64_t* stats, bool hasPresentTime,
23                                               uint64_t frameNumber, int32_t surfaceControlId) {
24     FatVector<sp<FrameMetricsObserver>, 10> copy;
25     {
26         std::lock_guard lock(mObserversLock);
27         copy.reserve(mObservers.size());
28         for (size_t i = 0; i < mObservers.size(); i++) {
29             auto observer = mObservers[i];
30 
31             if (CC_UNLIKELY(surfaceControlId < observer->attachedSurfaceControlId())) {
32                 // Don't notify if the metrics are from a frame that was run on an old
33                 // surface (one from before the observer was attached).
34                 ALOGV("skipped reporting metrics from old surface %d", surfaceControlId);
35                 continue;
36             } else if (CC_UNLIKELY(surfaceControlId == observer->attachedSurfaceControlId() &&
37                                    frameNumber < observer->attachedFrameNumber())) {
38                 // Don't notify if the metrics are from a frame that was queued by the
39                 // BufferQueueProducer on the render thread before the observer was attached.
40                 ALOGV("skipped reporting metrics from old frame %ld", (long)frameNumber);
41                 continue;
42             }
43 
44             const bool wantsPresentTime = observer->waitForPresentTime();
45             if (hasPresentTime == wantsPresentTime) {
46                 copy.push_back(observer);
47             }
48         }
49     }
50     for (size_t i = 0; i < copy.size(); i++) {
51         copy[i]->notify(stats);
52     }
53 }
54 
55 }  // namespace uirenderer
56 }  // namespace android
57