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/RefBase.h> 20 #include <utils/Log.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: 33 FrameMetricsReporter() {} 34 35 void addObserver(FrameMetricsObserver* observer) { 36 mObservers.push_back(observer); 37 } 38 39 bool removeObserver(FrameMetricsObserver* observer) { 40 for (size_t i = 0; i < mObservers.size(); i++) { 41 if (mObservers[i].get() == observer) { 42 mObservers.erase(mObservers.begin() + i); 43 return true; 44 } 45 } 46 return false; 47 } 48 49 bool hasObservers() { 50 return mObservers.size() > 0; 51 } 52 53 void reportFrameMetrics(const int64_t* stats) { 54 for (size_t i = 0; i < mObservers.size(); i++) { 55 mObservers[i]->notify(stats); 56 } 57 } 58 59 private: 60 std::vector< sp<FrameMetricsObserver> > mObservers; 61 }; 62 63 }; // namespace uirenderer 64 }; // namespace android 65 66