Andres Morales | 910beb8 | 2016-02-02 16:19:40 -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 | package android.view; |
| 18 | |
| 19 | import android.annotation.NonNull; |
Derek Sollenberger | c4ef2c7 | 2019-12-09 12:38:59 -0500 | [diff] [blame^] | 20 | import android.graphics.HardwareRendererObserver; |
| 21 | import android.os.Handler; |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 22 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 23 | import java.lang.ref.WeakReference; |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Provides streaming access to frame stats information from the rendering |
| 27 | * subsystem to apps. |
| 28 | * |
| 29 | * @hide |
| 30 | */ |
Derek Sollenberger | c4ef2c7 | 2019-12-09 12:38:59 -0500 | [diff] [blame^] | 31 | public class FrameMetricsObserver |
| 32 | implements HardwareRendererObserver.OnFrameMetricsAvailableListener { |
| 33 | private final WeakReference<Window> mWindow; |
| 34 | private final FrameMetrics mFrameMetrics; |
| 35 | private final HardwareRendererObserver mObserver; |
| 36 | /*package*/ final Window.OnFrameMetricsAvailableListener mListener; |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Creates a FrameMetricsObserver |
| 40 | * |
Derek Sollenberger | c4ef2c7 | 2019-12-09 12:38:59 -0500 | [diff] [blame^] | 41 | * @param handler the Handler to use when invoking callbacks |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 42 | */ |
Derek Sollenberger | c4ef2c7 | 2019-12-09 12:38:59 -0500 | [diff] [blame^] | 43 | FrameMetricsObserver(@NonNull Window window, @NonNull Handler handler, |
Andres Morales | d908c62 | 2016-04-20 13:13:34 -0700 | [diff] [blame] | 44 | @NonNull Window.OnFrameMetricsAvailableListener listener) { |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 45 | mWindow = new WeakReference<>(window); |
| 46 | mListener = listener; |
Derek Sollenberger | c4ef2c7 | 2019-12-09 12:38:59 -0500 | [diff] [blame^] | 47 | mFrameMetrics = new FrameMetrics(); |
| 48 | mObserver = new HardwareRendererObserver(this, mFrameMetrics.mTimingData, handler); |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Derek Sollenberger | c4ef2c7 | 2019-12-09 12:38:59 -0500 | [diff] [blame^] | 51 | /** |
| 52 | * Implementation of OnFrameMetricsAvailableListener |
| 53 | * @param dropCountSinceLastInvocation the number of reports dropped since the last time |
| 54 | * @Override |
| 55 | */ |
| 56 | public void onFrameMetricsAvailable(int dropCountSinceLastInvocation) { |
| 57 | if (mWindow.get() != null) { |
| 58 | mListener.onFrameMetricsAvailable(mWindow.get(), mFrameMetrics, |
| 59 | dropCountSinceLastInvocation); |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 60 | } |
| 61 | } |
Derek Sollenberger | c4ef2c7 | 2019-12-09 12:38:59 -0500 | [diff] [blame^] | 62 | |
| 63 | /*package*/ HardwareRendererObserver getRendererObserver() { |
| 64 | return mObserver; |
| 65 | } |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 66 | } |