blob: c1cd0a9224b601013103a1d6b161496ca085d83a [file] [log] [blame]
Andres Morales06f5bc72015-12-15 15:21:31 -08001/*
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
Andres Morales06f5bc72015-12-15 15:21:31 -080022#include "FrameInfo.h"
Andres Morales910beb82016-02-02 16:19:40 -080023#include "FrameMetricsObserver.h"
Andres Morales06f5bc72015-12-15 15:21:31 -080024
25#include <string.h>
26#include <vector>
27
28namespace android {
29namespace uirenderer {
30
Andres Morales910beb82016-02-02 16:19:40 -080031class FrameMetricsReporter {
Andres Morales06f5bc72015-12-15 15:21:31 -080032public:
Andres Morales11f02d72016-02-12 18:19:52 -080033 FrameMetricsReporter() {}
Andres Morales06f5bc72015-12-15 15:21:31 -080034
Andres Morales910beb82016-02-02 16:19:40 -080035 void addObserver(FrameMetricsObserver* observer) {
Andres Morales06f5bc72015-12-15 15:21:31 -080036 mObservers.push_back(observer);
37 }
38
Andres Morales910beb82016-02-02 16:19:40 -080039 bool removeObserver(FrameMetricsObserver* observer) {
Andres Morales06f5bc72015-12-15 15:21:31 -080040 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
Andres Morales910beb82016-02-02 16:19:40 -080053 void reportFrameMetrics(const int64_t* stats) {
Andres Morales11f02d72016-02-12 18:19:52 -080054 for (size_t i = 0; i < mObservers.size(); i++) {
55 mObservers[i]->notify(stats);
Andres Morales06f5bc72015-12-15 15:21:31 -080056 }
57 }
58
Andres Morales06f5bc72015-12-15 15:21:31 -080059private:
Andres Morales910beb82016-02-02 16:19:40 -080060 std::vector< sp<FrameMetricsObserver> > mObservers;
Andres Morales06f5bc72015-12-15 15:21:31 -080061};
62
63}; // namespace uirenderer
64}; // namespace android
65