Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 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 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 22 | #include "FrameInfo.h" |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 23 | #include "FrameMetricsObserver.h" |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 24 | |
| 25 | #include <string.h> |
| 26 | #include <vector> |
| 27 | |
| 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 31 | class FrameMetricsReporter { |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 32 | public: |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 33 | FrameMetricsReporter() {} |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 34 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 35 | void addObserver(FrameMetricsObserver* observer) { |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 36 | mObservers.push_back(observer); |
| 37 | } |
| 38 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 39 | bool removeObserver(FrameMetricsObserver* observer) { |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 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 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 53 | void reportFrameMetrics(const int64_t* stats) { |
Andres Morales | 11f02d7 | 2016-02-12 18:19:52 -0800 | [diff] [blame] | 54 | for (size_t i = 0; i < mObservers.size(); i++) { |
| 55 | mObservers[i]->notify(stats); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 59 | private: |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 60 | std::vector< sp<FrameMetricsObserver> > mObservers; |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | }; // namespace uirenderer |
| 64 | }; // namespace android |
| 65 | |