blob: 647f51c4492d0832fa1b01469a7257bc5a6d7f9a [file] [log] [blame]
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "jni.h"
#include "core_jni_helpers.h"
#include "android_os_MessageQueue.h"
#include <FrameInfo.h>
#include <FrameMetricsObserver.h>
namespace android {
/*
* Implements JNI layer for hwui frame metrics reporting.
*/
class FrameMetricsObserverProxy : public uirenderer::FrameMetricsObserver {
public:
FrameMetricsObserverProxy(JavaVM *vm, jobject observer);
~FrameMetricsObserverProxy();
jweak getObserverReference() {
return mObserverWeak;
}
bool getNextBuffer(JNIEnv* env, jlongArray sink, int* dropCount);
virtual void notify(const int64_t* stats);
private:
static const int kBufferSize = static_cast<int>(uirenderer::FrameInfoIndex::NumIndexes);
static constexpr int kRingSize = 3;
class FrameMetricsNotification {
public:
FrameMetricsNotification() : hasData(false) {}
std::atomic_bool hasData;
int64_t buffer[kBufferSize];
int dropCount = 0;
};
JavaVM* const mVm;
jweak mObserverWeak;
sp<MessageQueue> mMessageQueue;
sp<MessageHandler> mMessageHandler;
Message mMessage;
int mNextFree = 0;
int mNextInQueue = 0;
FrameMetricsNotification mRingBuffer[kRingSize];
int mDroppedReports = 0;
};
} // namespace android