• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #pragma once
18 
19 #include <utils/Log.h>
20 #include <utils/RefBase.h>
21 
22 #include "FrameInfo.h"
23 #include "FrameMetricsObserver.h"
24 
25 #include <string.h>
26 #include <vector>
27 
28 namespace android {
29 namespace uirenderer {
30 
31 class FrameMetricsReporter {
32 public:
FrameMetricsReporter()33     FrameMetricsReporter() {}
34 
addObserver(FrameMetricsObserver * observer)35     void addObserver(FrameMetricsObserver* observer) { mObservers.push_back(observer); }
36 
removeObserver(FrameMetricsObserver * observer)37     bool removeObserver(FrameMetricsObserver* observer) {
38         for (size_t i = 0; i < mObservers.size(); i++) {
39             if (mObservers[i].get() == observer) {
40                 mObservers.erase(mObservers.begin() + i);
41                 return true;
42             }
43         }
44         return false;
45     }
46 
hasObservers()47     bool hasObservers() { return mObservers.size() > 0; }
48 
reportFrameMetrics(const int64_t * stats)49     void reportFrameMetrics(const int64_t* stats) {
50         for (size_t i = 0; i < mObservers.size(); i++) {
51             mObservers[i]->notify(stats);
52         }
53     }
54 
55 private:
56     std::vector<sp<FrameMetricsObserver> > mObservers;
57 };
58 
59 }  // namespace uirenderer
60 }  // namespace android
61