Merge "Fix use after free in InputClassifier"
diff --git a/cmds/installd/otapreopt_chroot.cpp b/cmds/installd/otapreopt_chroot.cpp
index 609ddaf..670abea 100644
--- a/cmds/installd/otapreopt_chroot.cpp
+++ b/cmds/installd/otapreopt_chroot.cpp
@@ -80,8 +80,6 @@
// system/apex/apexd/apexd_main.cpp.
//
// Only scan the APEX directory under /system (within the chroot dir).
- // Note that this leaves around the loop devices created and used by
- // libapexd's code, but this is fine, as we expect to reboot soon after.
apex::scanPackagesDirAndActivate(apex::kApexPackageSystemDir);
return apex::getActivePackages();
}
diff --git a/include/android/surface_control.h b/include/android/surface_control.h
index 0573187..0e79239 100644
--- a/include/android/surface_control.h
+++ b/include/android/surface_control.h
@@ -28,6 +28,7 @@
#include <sys/cdefs.h>
+#include <android/data_space.h>
#include <android/hardware_buffer.h>
#include <android/hdr_metadata.h>
#include <android/native_window.h>
@@ -316,6 +317,15 @@
ASurfaceControl* surface_control, float alpha)
__INTRODUCED_IN(29);
+/**
+ * Sets the data space of the surface_control's buffers.
+ *
+ * If no data space is set, the surface control defaults to ADATASPACE_SRGB.
+ */
+void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* transaction,
+ ASurfaceControl* surface_control, ADataSpace data_space)
+ __INTRODUCED_IN(29);
+
/*
* SMPTE ST 2086 "Mastering Display Color Volume" static metadata
*
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp
index 96ee295..cb0e08d 100644
--- a/libs/binder/Binder.cpp
+++ b/libs/binder/Binder.cpp
@@ -218,7 +218,7 @@
if (!e) return; // out of memory
}
- e->mRequestingSid = true;
+ e->mRequestingSid = requestingSid;
}
BBinder::~BBinder()
diff --git a/libs/binder/include/binder/IInterface.h b/libs/binder/include/binder/IInterface.h
index f6381f7..0d30560 100644
--- a/libs/binder/include/binder/IInterface.h
+++ b/libs/binder/include/binder/IInterface.h
@@ -54,6 +54,7 @@
virtual const String16& getInterfaceDescriptor() const;
protected:
+ typedef INTERFACE BaseInterface;
virtual IBinder* onAsBinder();
};
@@ -66,6 +67,7 @@
explicit BpInterface(const sp<IBinder>& remote);
protected:
+ typedef INTERFACE BaseInterface;
virtual IBinder* onAsBinder();
};
diff --git a/libs/graphicsenv/Android.bp b/libs/graphicsenv/Android.bp
index 280c14a..d940752 100644
--- a/libs/graphicsenv/Android.bp
+++ b/libs/graphicsenv/Android.bp
@@ -17,14 +17,17 @@
srcs: [
"GraphicsEnv.cpp",
+ "IGpuService.cpp"
],
cflags: ["-Wall", "-Werror"],
shared_libs: [
"libbase",
+ "libbinder",
"libcutils",
"liblog",
+ "libutils",
],
export_include_dirs: ["include"],
diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp
index 337308b..c20d54b 100644
--- a/libs/graphicsenv/GraphicsEnv.cpp
+++ b/libs/graphicsenv/GraphicsEnv.cpp
@@ -14,8 +14,11 @@
* limitations under the License.
*/
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+
//#define LOG_NDEBUG 1
#define LOG_TAG "GraphicsEnv"
+
#include <graphicsenv/GraphicsEnv.h>
#include <dlfcn.h>
@@ -25,15 +28,16 @@
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android/dlext.h>
+#include <binder/IServiceManager.h>
#include <cutils/properties.h>
+#include <graphicsenv/IGpuService.h>
#include <log/log.h>
#include <sys/prctl.h>
+#include <utils/Trace.h>
#include <memory>
#include <string>
-#include <dlfcn.h>
-
// TODO(b/37049319) Get this from a header once one exists
extern "C" {
android_namespace_t* android_get_exported_namespace(const char*);
@@ -155,9 +159,16 @@
void GraphicsEnv::setGpuStats(const std::string driverPackageName,
const std::string driverVersionName, const uint64_t driverVersionCode,
const std::string appPackageName) {
- ALOGV("setGpuStats: drvPkgName[%s], drvVerName[%s], drvVerCode[%lld], appPkgName[%s]",
- driverPackageName.c_str(), driverVersionName.c_str(), (long long)driverVersionCode,
- appPackageName.c_str());
+ ATRACE_CALL();
+
+ ALOGV("setGpuStats:\n"
+ "\tdriverPackageName[%s]\n"
+ "\tdriverVersionName[%s]\n"
+ "\tdriverVersionCode[%llu]\n"
+ "\tappPackageName[%s]\n",
+ driverPackageName.c_str(), driverVersionName.c_str(),
+ (unsigned long long)driverVersionCode, appPackageName.c_str());
+
mGpuStats = {
.driverPackageName = driverPackageName,
.driverVersionName = driverVersionName,
@@ -166,6 +177,32 @@
};
}
+void GraphicsEnv::sendGpuStats() {
+ ATRACE_CALL();
+
+ // Do not sendGpuStats for those skipping the GraphicsEnvironment setup
+ if (mGpuStats.appPackageName.empty()) return;
+
+ ALOGV("sendGpuStats:\n"
+ "\tdriverPackageName[%s]\n"
+ "\tdriverVersionName[%s]\n"
+ "\tdriverVersionCode[%llu]\n"
+ "\tappPackageName[%s]\n",
+ mGpuStats.driverPackageName.c_str(), mGpuStats.driverVersionName.c_str(),
+ (unsigned long long)mGpuStats.driverVersionCode, mGpuStats.appPackageName.c_str());
+
+ const sp<IBinder> binder = defaultServiceManager()->checkService(String16("gpu"));
+ if (!binder) {
+ ALOGE("Failed to get gpu service for [%s]", mGpuStats.appPackageName.c_str());
+ return;
+ }
+
+ interface_cast<IGpuService>(binder)->setGpuStats(mGpuStats.driverPackageName,
+ mGpuStats.driverVersionName,
+ mGpuStats.driverVersionCode,
+ mGpuStats.appPackageName);
+}
+
void* GraphicsEnv::loadLibrary(std::string name) {
const android_dlextinfo dlextinfo = {
.flags = ANDROID_DLEXT_USE_NAMESPACE,
diff --git a/libs/graphicsenv/IGpuService.cpp b/libs/graphicsenv/IGpuService.cpp
new file mode 100644
index 0000000..98a6395
--- /dev/null
+++ b/libs/graphicsenv/IGpuService.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright 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.
+ */
+
+#define LOG_TAG "GpuService"
+
+#include <graphicsenv/IGpuService.h>
+
+#include <binder/IResultReceiver.h>
+#include <binder/Parcel.h>
+
+namespace android {
+
+class BpGpuService : public BpInterface<IGpuService> {
+public:
+ explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}
+
+ virtual void setGpuStats(const std::string driverPackageName,
+ const std::string driverVersionName, const uint64_t driverVersionCode,
+ const std::string appPackageName) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
+
+ data.writeUtf8AsUtf16(driverPackageName);
+ data.writeUtf8AsUtf16(driverVersionName);
+ data.writeUint64(driverVersionCode);
+ data.writeUtf8AsUtf16(appPackageName);
+
+ remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply);
+ }
+};
+
+IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
+
+status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
+ uint32_t flags) {
+ ALOGV("onTransact code[0x%X]", code);
+
+ status_t status;
+ switch (code) {
+ case SET_GPU_STATS: {
+ CHECK_INTERFACE(IGpuService, data, reply);
+
+ std::string driverPackageName;
+ if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status;
+
+ std::string driverVersionName;
+ if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status;
+
+ uint64_t driverVersionCode;
+ if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
+
+ std::string appPackageName;
+ if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
+
+ setGpuStats(driverPackageName, driverVersionName, driverVersionCode, appPackageName);
+
+ return OK;
+ }
+ case SHELL_COMMAND_TRANSACTION: {
+ int in = data.readFileDescriptor();
+ int out = data.readFileDescriptor();
+ int err = data.readFileDescriptor();
+
+ std::vector<String16> args;
+ data.readString16Vector(&args);
+
+ sp<IBinder> unusedCallback;
+ if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status;
+
+ sp<IResultReceiver> resultReceiver;
+ if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status;
+
+ status = shellCommand(in, out, err, args);
+ if (resultReceiver != nullptr) resultReceiver->send(status);
+
+ return OK;
+ }
+ default:
+ return BBinder::onTransact(code, data, reply, flags);
+ }
+}
+
+} // namespace android
diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
index a247bec..d4edfa0 100644
--- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
+++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
@@ -49,6 +49,7 @@
android_namespace_t* getDriverNamespace();
void setGpuStats(const std::string driverPackageName, const std::string driverVersionName,
const uint64_t versionCode, const std::string appPackageName);
+ void sendGpuStats();
bool shouldUseAngle(std::string appName);
bool shouldUseAngle();
diff --git a/libs/graphicsenv/include/graphicsenv/IGpuService.h b/libs/graphicsenv/include/graphicsenv/IGpuService.h
new file mode 100644
index 0000000..c080c53
--- /dev/null
+++ b/libs/graphicsenv/include/graphicsenv/IGpuService.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright 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.
+ */
+
+#pragma once
+
+#include <binder/IInterface.h>
+#include <cutils/compiler.h>
+
+#include <vector>
+
+namespace android {
+
+/*
+ * This class defines the Binder IPC interface for GPU-related queries and
+ * control.
+ */
+class IGpuService : public IInterface {
+public:
+ DECLARE_META_INTERFACE(GpuService);
+
+ // set GPU stats from GraphicsEnvironment.
+ virtual void setGpuStats(const std::string driverPackageName,
+ const std::string driverVersionName, const uint64_t driverVersionCode,
+ const std::string appPackageName) = 0;
+};
+
+class BnGpuService : public BnInterface<IGpuService> {
+public:
+ enum IGpuServiceTag {
+ SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION,
+ // Always append new enum to the end.
+ };
+
+ status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
+ uint32_t flags = 0) override;
+
+protected:
+ virtual status_t shellCommand(int in, int out, int err, std::vector<String16>& args) = 0;
+};
+
+} // namespace android
diff --git a/libs/ui/BufferHubBuffer.cpp b/libs/ui/BufferHubBuffer.cpp
index c3144b9..cce35fd 100644
--- a/libs/ui/BufferHubBuffer.cpp
+++ b/libs/ui/BufferHubBuffer.cpp
@@ -24,12 +24,12 @@
#include <utils/Trace.h>
using ::android::base::unique_fd;
-using ::android::BufferHubDefs::AnyClientAcquired;
-using ::android::BufferHubDefs::AnyClientGained;
-using ::android::BufferHubDefs::IsClientAcquired;
-using ::android::BufferHubDefs::IsClientGained;
-using ::android::BufferHubDefs::IsClientPosted;
-using ::android::BufferHubDefs::IsClientReleased;
+using ::android::BufferHubDefs::isAnyClientAcquired;
+using ::android::BufferHubDefs::isAnyClientGained;
+using ::android::BufferHubDefs::isClientAcquired;
+using ::android::BufferHubDefs::isClientGained;
+using ::android::BufferHubDefs::isClientPosted;
+using ::android::BufferHubDefs::isClientReleased;
using ::android::frameworks::bufferhub::V1_0::BufferHubStatus;
using ::android::frameworks::bufferhub::V1_0::BufferTraits;
using ::android::frameworks::bufferhub::V1_0::IBufferClient;
@@ -39,22 +39,22 @@
namespace android {
-std::unique_ptr<BufferHubBuffer> BufferHubBuffer::Create(uint32_t width, uint32_t height,
+std::unique_ptr<BufferHubBuffer> BufferHubBuffer::create(uint32_t width, uint32_t height,
uint32_t layerCount, uint32_t format,
uint64_t usage, size_t userMetadataSize) {
auto buffer = std::unique_ptr<BufferHubBuffer>(
new BufferHubBuffer(width, height, layerCount, format, usage, userMetadataSize));
- return buffer->IsValid() ? std::move(buffer) : nullptr;
+ return buffer->isValid() ? std::move(buffer) : nullptr;
}
-std::unique_ptr<BufferHubBuffer> BufferHubBuffer::Import(const native_handle_t* token) {
+std::unique_ptr<BufferHubBuffer> BufferHubBuffer::import(const native_handle_t* token) {
if (token == nullptr) {
ALOGE("%s: token cannot be nullptr!", __FUNCTION__);
return nullptr;
}
auto buffer = std::unique_ptr<BufferHubBuffer>(new BufferHubBuffer(token));
- return buffer->IsValid() ? std::move(buffer) : nullptr;
+ return buffer->isValid() ? std::move(buffer) : nullptr;
}
BufferHubBuffer::BufferHubBuffer(uint32_t width, uint32_t height, uint32_t layerCount,
@@ -169,8 +169,8 @@
// Import fds. Dup fds because hidl_handle owns the fds.
unique_fd ashmemFd(fcntl(bufferTraits.bufferInfo->data[0], F_DUPFD_CLOEXEC, 0));
- mMetadata = BufferHubMetadata::Import(std::move(ashmemFd));
- if (!mMetadata.IsValid()) {
+ mMetadata = BufferHubMetadata::import(std::move(ashmemFd));
+ if (!mMetadata.isValid()) {
ALOGE("%s: Received an invalid metadata.", __FUNCTION__);
return -EINVAL;
}
@@ -196,23 +196,23 @@
uint32_t userMetadataSize;
memcpy(&userMetadataSize, &bufferTraits.bufferInfo->data[4], sizeof(userMetadataSize));
- if (mMetadata.user_metadata_size() != userMetadataSize) {
+ if (mMetadata.userMetadataSize() != userMetadataSize) {
ALOGE("%s: user metadata size not match: expected %u, actual %zu.", __FUNCTION__,
- userMetadataSize, mMetadata.user_metadata_size());
+ userMetadataSize, mMetadata.userMetadataSize());
return -EINVAL;
}
- size_t metadataSize = static_cast<size_t>(mMetadata.metadata_size());
+ size_t metadataSize = static_cast<size_t>(mMetadata.metadataSize());
if (metadataSize < BufferHubDefs::kMetadataHeaderSize) {
ALOGE("%s: metadata too small: %zu", __FUNCTION__, metadataSize);
return -EINVAL;
}
// Populate shortcuts to the atomics in metadata.
- auto metadata_header = mMetadata.metadata_header();
- mBufferState = &metadata_header->buffer_state;
- mFenceState = &metadata_header->fence_state;
- mActiveClientsBitMask = &metadata_header->active_clients_bit_mask;
+ auto metadataHeader = mMetadata.metadataHeader();
+ mBufferState = &metadataHeader->buffer_state;
+ mFenceState = &metadataHeader->fence_state;
+ mActiveClientsBitMask = &metadataHeader->active_clients_bit_mask;
// The C++ standard recommends (but does not require) that lock-free atomic operations are
// also address-free, that is, suitable for communication between processes using shared
// memory.
@@ -235,16 +235,16 @@
return 0;
}
-int BufferHubBuffer::Gain() {
+int BufferHubBuffer::gain() {
uint32_t currentBufferState = mBufferState->load(std::memory_order_acquire);
- if (IsClientGained(currentBufferState, mClientStateMask)) {
+ if (isClientGained(currentBufferState, mClientStateMask)) {
ALOGV("%s: Buffer is already gained by this client %" PRIx32 ".", __FUNCTION__,
mClientStateMask);
return 0;
}
do {
- if (AnyClientGained(currentBufferState & (~mClientStateMask)) ||
- AnyClientAcquired(currentBufferState)) {
+ if (isAnyClientGained(currentBufferState & (~mClientStateMask)) ||
+ isAnyClientAcquired(currentBufferState)) {
ALOGE("%s: Buffer is in use, id=%d mClientStateMask=%" PRIx32 " state=%" PRIx32 ".",
__FUNCTION__, mId, mClientStateMask, currentBufferState);
return -EBUSY;
@@ -258,11 +258,11 @@
return 0;
}
-int BufferHubBuffer::Post() {
+int BufferHubBuffer::post() {
uint32_t currentBufferState = mBufferState->load(std::memory_order_acquire);
uint32_t updatedBufferState = (~mClientStateMask) & BufferHubDefs::kHighBitsMask;
do {
- if (!IsClientGained(currentBufferState, mClientStateMask)) {
+ if (!isClientGained(currentBufferState, mClientStateMask)) {
ALOGE("%s: Cannot post a buffer that is not gained by this client. buffer_id=%d "
"mClientStateMask=%" PRIx32 " state=%" PRIx32 ".",
__FUNCTION__, mId, mClientStateMask, currentBufferState);
@@ -277,16 +277,16 @@
return 0;
}
-int BufferHubBuffer::Acquire() {
+int BufferHubBuffer::acquire() {
uint32_t currentBufferState = mBufferState->load(std::memory_order_acquire);
- if (IsClientAcquired(currentBufferState, mClientStateMask)) {
+ if (isClientAcquired(currentBufferState, mClientStateMask)) {
ALOGV("%s: Buffer is already acquired by this client %" PRIx32 ".", __FUNCTION__,
mClientStateMask);
return 0;
}
uint32_t updatedBufferState = 0U;
do {
- if (!IsClientPosted(currentBufferState, mClientStateMask)) {
+ if (!isClientPosted(currentBufferState, mClientStateMask)) {
ALOGE("%s: Cannot acquire a buffer that is not in posted state. buffer_id=%d "
"mClientStateMask=%" PRIx32 " state=%" PRIx32 ".",
__FUNCTION__, mId, mClientStateMask, currentBufferState);
@@ -301,9 +301,9 @@
return 0;
}
-int BufferHubBuffer::Release() {
+int BufferHubBuffer::release() {
uint32_t currentBufferState = mBufferState->load(std::memory_order_acquire);
- if (IsClientReleased(currentBufferState, mClientStateMask)) {
+ if (isClientReleased(currentBufferState, mClientStateMask)) {
ALOGV("%s: Buffer is already released by this client %" PRIx32 ".", __FUNCTION__,
mClientStateMask);
return 0;
@@ -318,17 +318,17 @@
return 0;
}
-bool BufferHubBuffer::IsReleased() const {
+bool BufferHubBuffer::isReleased() const {
return (mBufferState->load(std::memory_order_acquire) &
mActiveClientsBitMask->load(std::memory_order_acquire)) == 0;
}
-bool BufferHubBuffer::IsValid() const {
+bool BufferHubBuffer::isValid() const {
return mBufferHandle.getNativeHandle() != nullptr && mId >= 0 && mClientStateMask != 0U &&
- mEventFd.get() >= 0 && mMetadata.IsValid() && mBufferClient != nullptr;
+ mEventFd.get() >= 0 && mMetadata.isValid() && mBufferClient != nullptr;
}
-native_handle_t* BufferHubBuffer::Duplicate() {
+native_handle_t* BufferHubBuffer::duplicate() {
if (mBufferClient == nullptr) {
ALOGE("%s: missing BufferClient!", __FUNCTION__);
return nullptr;
diff --git a/libs/ui/BufferHubMetadata.cpp b/libs/ui/BufferHubMetadata.cpp
index 816707d..05bc7dd 100644
--- a/libs/ui/BufferHubMetadata.cpp
+++ b/libs/ui/BufferHubMetadata.cpp
@@ -34,7 +34,7 @@
using BufferHubDefs::MetadataHeader;
/* static */
-BufferHubMetadata BufferHubMetadata::Create(size_t userMetadataSize) {
+BufferHubMetadata BufferHubMetadata::create(size_t userMetadataSize) {
// The size the of metadata buffer is used as the "width" parameter during allocation. Thus it
// cannot overflow uint32_t.
if (userMetadataSize >= (std::numeric_limits<uint32_t>::max() - kMetadataHeaderSize)) {
@@ -59,11 +59,11 @@
return {};
}
- return BufferHubMetadata::Import(std::move(ashmemFd));
+ return BufferHubMetadata::import(std::move(ashmemFd));
}
/* static */
-BufferHubMetadata BufferHubMetadata::Import(unique_fd ashmemFd) {
+BufferHubMetadata BufferHubMetadata::import(unique_fd ashmemFd) {
if (!ashmem_valid(ashmemFd.get())) {
ALOGE("BufferHubMetadata::Import: invalid ashmem fd.");
return {};
@@ -94,7 +94,7 @@
BufferHubMetadata::~BufferHubMetadata() {
if (mMetadataHeader != nullptr) {
- int ret = munmap(mMetadataHeader, metadata_size());
+ int ret = munmap(mMetadataHeader, metadataSize());
ALOGE_IF(ret != 0,
"BufferHubMetadata::~BufferHubMetadata: failed to unmap ashmem, error=%d.", errno);
mMetadataHeader = nullptr;
diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp
index 41ae253..f487dfa 100644
--- a/libs/ui/GraphicBuffer.cpp
+++ b/libs/ui/GraphicBuffer.cpp
@@ -100,7 +100,7 @@
return;
}
- mInitCheck = initWithHandle(buffer->DuplicateHandle(), /*method=*/TAKE_UNREGISTERED_HANDLE,
+ mInitCheck = initWithHandle(buffer->duplicateHandle(), /*method=*/TAKE_UNREGISTERED_HANDLE,
buffer->desc().width, buffer->desc().height,
static_cast<PixelFormat>(buffer->desc().format),
buffer->desc().layers, buffer->desc().usage, buffer->desc().stride);
diff --git a/libs/ui/include/ui/BufferHubBuffer.h b/libs/ui/include/ui/BufferHubBuffer.h
index 06955e4..eac8c84 100644
--- a/libs/ui/include/ui/BufferHubBuffer.h
+++ b/libs/ui/include/ui/BufferHubBuffer.h
@@ -29,14 +29,14 @@
class BufferHubBuffer {
public:
// Allocates a standalone BufferHubBuffer.
- static std::unique_ptr<BufferHubBuffer> Create(uint32_t width, uint32_t height,
+ static std::unique_ptr<BufferHubBuffer> create(uint32_t width, uint32_t height,
uint32_t layerCount, uint32_t format,
uint64_t usage, size_t userMetadataSize);
// Imports the given token to a BufferHubBuffer. Not taking ownership of the token. Caller
// should close and destroy the token after calling this function regardless of output.
// TODO(b/122543147): use a movable wrapper for token
- static std::unique_ptr<BufferHubBuffer> Import(const native_handle_t* token);
+ static std::unique_ptr<BufferHubBuffer> import(const native_handle_t* token);
BufferHubBuffer(const BufferHubBuffer&) = delete;
void operator=(const BufferHubBuffer&) = delete;
@@ -52,51 +52,51 @@
// Duplicate the underlying Gralloc buffer handle. Caller is responsible to free the handle
// after use.
- native_handle_t* DuplicateHandle() {
+ native_handle_t* duplicateHandle() {
return native_handle_clone(mBufferHandle.getNativeHandle());
}
const BufferHubEventFd& eventFd() const { return mEventFd; }
// Returns the current value of MetadataHeader::buffer_state.
- uint32_t buffer_state() const { return mBufferState->load(std::memory_order_acquire); }
+ uint32_t bufferState() const { return mBufferState->load(std::memory_order_acquire); }
// A state mask which is unique to a buffer hub client among all its siblings sharing the same
// concrete graphic buffer.
- uint32_t client_state_mask() const { return mClientStateMask; }
+ uint32_t clientStateMask() const { return mClientStateMask; }
- size_t user_metadata_size() const { return mMetadata.user_metadata_size(); }
+ size_t userMetadataSize() const { return mMetadata.userMetadataSize(); }
// Returns true if the BufferClient is still alive.
- bool IsConnected() const { return mBufferClient->ping().isOk(); }
+ bool isConnected() const { return mBufferClient->ping().isOk(); }
// Returns true if the buffer is valid: non-null buffer handle, valid id, valid client bit mask,
// valid metadata and valid buffer client
- bool IsValid() const;
+ bool isValid() const;
// Gains the buffer for exclusive write permission. Read permission is implied once a buffer is
// gained.
// The buffer can be gained as long as there is no other client in acquired or gained state.
- int Gain();
+ int gain();
// Posts the gained buffer for other buffer clients to use the buffer.
// The buffer can be posted iff the buffer state for this client is gained.
// After posting the buffer, this client is put to released state and does not have access to
// the buffer for this cycle of the usage of the buffer.
- int Post();
+ int post();
// Acquires the buffer for shared read permission.
// The buffer can be acquired iff the buffer state for this client is posted.
- int Acquire();
+ int acquire();
// Releases the buffer.
// The buffer can be released from any buffer state.
// After releasing the buffer, this client no longer have any permissions to the buffer for the
// current cycle of the usage of the buffer.
- int Release();
+ int release();
// Returns whether the buffer is released by all active clients or not.
- bool IsReleased() const;
+ bool isReleased() const;
// Creates a token that stands for this BufferHubBuffer client and could be used for Import to
// create another BufferHubBuffer. The new BufferHubBuffer will share the same underlying
@@ -104,7 +104,7 @@
// should free it after use.
// Returns a valid token on success, nullptr on failure.
// TODO(b/122543147): use a movable wrapper for token
- native_handle_t* Duplicate();
+ native_handle_t* duplicate();
private:
BufferHubBuffer(uint32_t width, uint32_t height, uint32_t layerCount, uint32_t format,
diff --git a/libs/ui/include/ui/BufferHubDefs.h b/libs/ui/include/ui/BufferHubDefs.h
index ff970cb..722a060 100644
--- a/libs/ui/include/ui/BufferHubDefs.h
+++ b/libs/ui/include/ui/BufferHubDefs.h
@@ -63,19 +63,19 @@
static constexpr uint32_t kFirstClientBitMask = (1U << kMaxNumberOfClients) + 1U;
// Returns true if any of the client is in gained state.
-static inline bool AnyClientGained(uint32_t state) {
+static inline bool isAnyClientGained(uint32_t state) {
uint32_t high_bits = state >> kMaxNumberOfClients;
uint32_t low_bits = state & kLowbitsMask;
return high_bits == low_bits && low_bits != 0U;
}
// Returns true if the input client is in gained state.
-static inline bool IsClientGained(uint32_t state, uint32_t client_bit_mask) {
+static inline bool isClientGained(uint32_t state, uint32_t client_bit_mask) {
return state == client_bit_mask;
}
// Returns true if any of the client is in posted state.
-static inline bool AnyClientPosted(uint32_t state) {
+static inline bool isAnyClientPosted(uint32_t state) {
uint32_t high_bits = state >> kMaxNumberOfClients;
uint32_t low_bits = state & kLowbitsMask;
uint32_t posted_or_acquired = high_bits ^ low_bits;
@@ -83,7 +83,7 @@
}
// Returns true if the input client is in posted state.
-static inline bool IsClientPosted(uint32_t state, uint32_t client_bit_mask) {
+static inline bool isClientPosted(uint32_t state, uint32_t client_bit_mask) {
uint32_t client_bits = state & client_bit_mask;
if (client_bits == 0U) return false;
uint32_t low_bits = client_bits & kLowbitsMask;
@@ -91,7 +91,7 @@
}
// Return true if any of the client is in acquired state.
-static inline bool AnyClientAcquired(uint32_t state) {
+static inline bool isAnyClientAcquired(uint32_t state) {
uint32_t high_bits = state >> kMaxNumberOfClients;
uint32_t low_bits = state & kLowbitsMask;
uint32_t posted_or_acquired = high_bits ^ low_bits;
@@ -99,7 +99,7 @@
}
// Return true if the input client is in acquired state.
-static inline bool IsClientAcquired(uint32_t state, uint32_t client_bit_mask) {
+static inline bool isClientAcquired(uint32_t state, uint32_t client_bit_mask) {
uint32_t client_bits = state & client_bit_mask;
if (client_bits == 0U) return false;
uint32_t high_bits = client_bits & kHighBitsMask;
@@ -107,13 +107,13 @@
}
// Returns true if the input client is in released state.
-static inline bool IsClientReleased(uint32_t state, uint32_t client_bit_mask) {
+static inline bool isClientReleased(uint32_t state, uint32_t client_bit_mask) {
return (state & client_bit_mask) == 0U;
}
// Returns the next available buffer client's client_state_masks.
// @params union_bits. Union of all existing clients' client_state_masks.
-static inline uint32_t FindNextAvailableClientStateMask(uint32_t union_bits) {
+static inline uint32_t findNextAvailableClientStateMask(uint32_t union_bits) {
uint32_t low_union = union_bits & kLowbitsMask;
if (low_union == kLowbitsMask) return 0U;
uint32_t incremented = low_union + 1U;
diff --git a/libs/ui/include/ui/BufferHubMetadata.h b/libs/ui/include/ui/BufferHubMetadata.h
index 2121894..3482507 100644
--- a/libs/ui/include/ui/BufferHubMetadata.h
+++ b/libs/ui/include/ui/BufferHubMetadata.h
@@ -33,12 +33,12 @@
// @param userMetadataSize Size in bytes of the user defined metadata. The entire metadata
// shared memory region to be allocated is the size of canonical
// BufferHubDefs::MetadataHeader plus userMetadataSize.
- static BufferHubMetadata Create(size_t userMetadataSize);
+ static BufferHubMetadata create(size_t userMetadataSize);
// Imports an existing BufferHubMetadata from an ashmem FD.
//
// @param ashmemFd Ashmem file descriptor representing an ashmem region.
- static BufferHubMetadata Import(unique_fd ashmemFd);
+ static BufferHubMetadata import(unique_fd ashmemFd);
BufferHubMetadata() = default;
@@ -63,13 +63,13 @@
// Returns true if the metadata is valid, i.e. the metadata has a valid ashmem fd and the ashmem
// has been mapped into virtual address space.
- bool IsValid() const { return mAshmemFd.get() != -1 && mMetadataHeader != nullptr; }
+ bool isValid() const { return mAshmemFd.get() != -1 && mMetadataHeader != nullptr; }
- size_t user_metadata_size() const { return mUserMetadataSize; }
- size_t metadata_size() const { return mUserMetadataSize + BufferHubDefs::kMetadataHeaderSize; }
+ size_t userMetadataSize() const { return mUserMetadataSize; }
+ size_t metadataSize() const { return mUserMetadataSize + BufferHubDefs::kMetadataHeaderSize; }
- const unique_fd& ashmem_fd() const { return mAshmemFd; }
- BufferHubDefs::MetadataHeader* metadata_header() { return mMetadataHeader; }
+ const unique_fd& ashmemFd() const { return mAshmemFd; }
+ BufferHubDefs::MetadataHeader* metadataHeader() { return mMetadataHeader; }
private:
BufferHubMetadata(size_t userMetadataSize, unique_fd ashmemFd,
diff --git a/libs/ui/tests/BufferHubBuffer_test.cpp b/libs/ui/tests/BufferHubBuffer_test.cpp
index 4ad2c4c..3087a90 100644
--- a/libs/ui/tests/BufferHubBuffer_test.cpp
+++ b/libs/ui/tests/BufferHubBuffer_test.cpp
@@ -32,13 +32,13 @@
namespace {
-using ::android::BufferHubDefs::AnyClientAcquired;
-using ::android::BufferHubDefs::AnyClientGained;
-using ::android::BufferHubDefs::AnyClientPosted;
-using ::android::BufferHubDefs::IsClientAcquired;
-using ::android::BufferHubDefs::IsClientGained;
-using ::android::BufferHubDefs::IsClientPosted;
-using ::android::BufferHubDefs::IsClientReleased;
+using ::android::BufferHubDefs::isAnyClientAcquired;
+using ::android::BufferHubDefs::isAnyClientGained;
+using ::android::BufferHubDefs::isAnyClientPosted;
+using ::android::BufferHubDefs::isClientAcquired;
+using ::android::BufferHubDefs::isClientGained;
+using ::android::BufferHubDefs::isClientPosted;
+using ::android::BufferHubDefs::isClientReleased;
using ::android::BufferHubDefs::kMetadataHeaderSize;
using ::testing::IsNull;
using ::testing::NotNull;
@@ -81,88 +81,88 @@
};
void BufferHubBufferStateTransitionTest::CreateTwoClientsOfABuffer() {
- b1 = BufferHubBuffer::Create(kWidth, kHeight, kLayerCount, kFormat, kUsage, kUserMetadataSize);
+ b1 = BufferHubBuffer::create(kWidth, kHeight, kLayerCount, kFormat, kUsage, kUserMetadataSize);
ASSERT_THAT(b1, NotNull());
- b1ClientMask = b1->client_state_mask();
+ b1ClientMask = b1->clientStateMask();
ASSERT_NE(b1ClientMask, 0U);
- native_handle_t* token = b1->Duplicate();
+ native_handle_t* token = b1->duplicate();
ASSERT_THAT(token, NotNull());
// TODO(b/122543147): use a movalbe wrapper for token
- b2 = BufferHubBuffer::Import(token);
+ b2 = BufferHubBuffer::import(token);
native_handle_close(token);
native_handle_delete(token);
ASSERT_THAT(b2, NotNull());
- b2ClientMask = b2->client_state_mask();
+ b2ClientMask = b2->clientStateMask();
ASSERT_NE(b2ClientMask, 0U);
ASSERT_NE(b2ClientMask, b1ClientMask);
}
TEST_F(BufferHubBufferTest, CreateBufferFails) {
// Buffer Creation will fail: BLOB format requires height to be 1.
- auto b1 = BufferHubBuffer::Create(kWidth, /*height=*/2, kLayerCount,
+ auto b1 = BufferHubBuffer::create(kWidth, /*height=*/2, kLayerCount,
/*format=*/HAL_PIXEL_FORMAT_BLOB, kUsage, kUserMetadataSize);
EXPECT_THAT(b1, IsNull());
// Buffer Creation will fail: user metadata size too large.
- auto b2 = BufferHubBuffer::Create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
+ auto b2 = BufferHubBuffer::create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
/*userMetadataSize=*/std::numeric_limits<size_t>::max());
EXPECT_THAT(b2, IsNull());
// Buffer Creation will fail: user metadata size too large.
const size_t userMetadataSize = std::numeric_limits<size_t>::max() - kMetadataHeaderSize;
- auto b3 = BufferHubBuffer::Create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
+ auto b3 = BufferHubBuffer::create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
userMetadataSize);
EXPECT_THAT(b3, IsNull());
}
TEST_F(BufferHubBufferTest, CreateBuffer) {
- auto b1 = BufferHubBuffer::Create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
+ auto b1 = BufferHubBuffer::create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
kUserMetadataSize);
ASSERT_THAT(b1, NotNull());
- EXPECT_TRUE(b1->IsConnected());
- EXPECT_TRUE(b1->IsValid());
+ EXPECT_TRUE(b1->isConnected());
+ EXPECT_TRUE(b1->isValid());
EXPECT_TRUE(cmpAHardwareBufferDesc(b1->desc(), kDesc));
- EXPECT_EQ(b1->user_metadata_size(), kUserMetadataSize);
+ EXPECT_EQ(b1->userMetadataSize(), kUserMetadataSize);
}
TEST_F(BufferHubBufferTest, DuplicateAndImportBuffer) {
- auto b1 = BufferHubBuffer::Create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
+ auto b1 = BufferHubBuffer::create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
kUserMetadataSize);
ASSERT_THAT(b1, NotNull());
- EXPECT_TRUE(b1->IsValid());
+ EXPECT_TRUE(b1->isValid());
- native_handle_t* token = b1->Duplicate();
+ native_handle_t* token = b1->duplicate();
EXPECT_TRUE(token);
// The detached buffer should still be valid.
- EXPECT_TRUE(b1->IsConnected());
- EXPECT_TRUE(b1->IsValid());
+ EXPECT_TRUE(b1->isConnected());
+ EXPECT_TRUE(b1->isValid());
- std::unique_ptr<BufferHubBuffer> b2 = BufferHubBuffer::Import(token);
+ std::unique_ptr<BufferHubBuffer> b2 = BufferHubBuffer::import(token);
native_handle_close(token);
native_handle_delete(token);
ASSERT_THAT(b2, NotNull());
- EXPECT_TRUE(b2->IsValid());
+ EXPECT_TRUE(b2->isValid());
EXPECT_TRUE(cmpAHardwareBufferDesc(b1->desc(), b2->desc()));
- EXPECT_EQ(b1->user_metadata_size(), b2->user_metadata_size());
+ EXPECT_EQ(b1->userMetadataSize(), b2->userMetadataSize());
// These two buffer instances are based on the same physical buffer under the
// hood, so they should share the same id.
EXPECT_EQ(b1->id(), b2->id());
- // We use client_state_mask() to tell those two instances apart.
- EXPECT_NE(b1->client_state_mask(), b2->client_state_mask());
+ // We use clientStateMask() to tell those two instances apart.
+ EXPECT_NE(b1->clientStateMask(), b2->clientStateMask());
// Both buffer instances should be in released state currently.
- EXPECT_TRUE(b1->IsReleased());
- EXPECT_TRUE(b2->IsReleased());
+ EXPECT_TRUE(b1->isReleased());
+ EXPECT_TRUE(b2->isReleased());
// The event fd should behave like duped event fds.
const BufferHubEventFd& eventFd1 = b1->eventFd();
@@ -192,19 +192,19 @@
}
TEST_F(BufferHubBufferTest, ImportFreedBuffer) {
- auto b1 = BufferHubBuffer::Create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
+ auto b1 = BufferHubBuffer::create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
kUserMetadataSize);
ASSERT_THAT(b1, NotNull());
- EXPECT_TRUE(b1->IsValid());
+ EXPECT_TRUE(b1->isValid());
- native_handle_t* token = b1->Duplicate();
+ native_handle_t* token = b1->duplicate();
EXPECT_TRUE(token);
// Explicitly destroy b1. Backend buffer should be freed and token becomes invalid
b1.reset();
// TODO(b/122543147): use a movalbe wrapper for token
- std::unique_ptr<BufferHubBuffer> b2 = BufferHubBuffer::Import(token);
+ std::unique_ptr<BufferHubBuffer> b2 = BufferHubBuffer::import(token);
native_handle_close(token);
native_handle_delete(token);
@@ -214,7 +214,7 @@
// nullptr must not crash the service
TEST_F(BufferHubBufferTest, ImportNullToken) {
- auto b1 = BufferHubBuffer::Import(nullptr);
+ auto b1 = BufferHubBuffer::import(nullptr);
EXPECT_THAT(b1, IsNull());
}
@@ -222,185 +222,185 @@
native_handle_t* token = native_handle_create(/*numFds=*/0, /*numInts=*/1);
token->data[0] = 0;
- auto b1 = BufferHubBuffer::Import(token);
+ auto b1 = BufferHubBuffer::import(token);
native_handle_delete(token);
EXPECT_THAT(b1, IsNull());
}
TEST_F(BufferHubBufferStateTransitionTest, GainBuffer_fromReleasedState) {
- ASSERT_TRUE(b1->IsReleased());
+ ASSERT_TRUE(b1->isReleased());
// Successful gaining the buffer should change the buffer state bit of b1 to
// gained state, other client state bits to released state.
- EXPECT_EQ(b1->Gain(), 0);
- EXPECT_TRUE(IsClientGained(b1->buffer_state(), b1ClientMask));
+ EXPECT_EQ(b1->gain(), 0);
+ EXPECT_TRUE(isClientGained(b1->bufferState(), b1ClientMask));
}
TEST_F(BufferHubBufferStateTransitionTest, GainBuffer_fromGainedState) {
- ASSERT_EQ(b1->Gain(), 0);
- auto currentBufferState = b1->buffer_state();
- ASSERT_TRUE(IsClientGained(currentBufferState, b1ClientMask));
+ ASSERT_EQ(b1->gain(), 0);
+ auto currentBufferState = b1->bufferState();
+ ASSERT_TRUE(isClientGained(currentBufferState, b1ClientMask));
// Gaining from gained state by the same client should not return error.
- EXPECT_EQ(b1->Gain(), 0);
+ EXPECT_EQ(b1->gain(), 0);
// Gaining from gained state by another client should return error.
- EXPECT_EQ(b2->Gain(), -EBUSY);
+ EXPECT_EQ(b2->gain(), -EBUSY);
}
TEST_F(BufferHubBufferStateTransitionTest, GainBuffer_fromAcquiredState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_EQ(b2->Acquire(), 0);
- ASSERT_TRUE(AnyClientAcquired(b1->buffer_state()));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_EQ(b2->acquire(), 0);
+ ASSERT_TRUE(isAnyClientAcquired(b1->bufferState()));
// Gaining from acquired state should fail.
- EXPECT_EQ(b1->Gain(), -EBUSY);
- EXPECT_EQ(b2->Gain(), -EBUSY);
+ EXPECT_EQ(b1->gain(), -EBUSY);
+ EXPECT_EQ(b2->gain(), -EBUSY);
}
TEST_F(BufferHubBufferStateTransitionTest, GainBuffer_fromOtherClientInPostedState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_TRUE(AnyClientPosted(b1->buffer_state()));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_TRUE(isAnyClientPosted(b1->bufferState()));
// Gaining a buffer who has other posted client should succeed.
- EXPECT_EQ(b1->Gain(), 0);
+ EXPECT_EQ(b1->gain(), 0);
}
TEST_F(BufferHubBufferStateTransitionTest, GainBuffer_fromSelfInPostedState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_TRUE(AnyClientPosted(b1->buffer_state()));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_TRUE(isAnyClientPosted(b1->bufferState()));
// A posted client should be able to gain the buffer when there is no other clients in
// acquired state.
- EXPECT_EQ(b2->Gain(), 0);
+ EXPECT_EQ(b2->gain(), 0);
}
TEST_F(BufferHubBufferStateTransitionTest, PostBuffer_fromOtherInGainedState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_TRUE(IsClientGained(b1->buffer_state(), b1ClientMask));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_TRUE(isClientGained(b1->bufferState(), b1ClientMask));
- EXPECT_EQ(b2->Post(), -EBUSY);
+ EXPECT_EQ(b2->post(), -EBUSY);
}
TEST_F(BufferHubBufferStateTransitionTest, PostBuffer_fromSelfInGainedState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_TRUE(IsClientGained(b1->buffer_state(), b1ClientMask));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_TRUE(isClientGained(b1->bufferState(), b1ClientMask));
- EXPECT_EQ(b1->Post(), 0);
- auto currentBufferState = b1->buffer_state();
- EXPECT_TRUE(IsClientReleased(currentBufferState, b1ClientMask));
- EXPECT_TRUE(IsClientPosted(currentBufferState, b2ClientMask));
+ EXPECT_EQ(b1->post(), 0);
+ auto currentBufferState = b1->bufferState();
+ EXPECT_TRUE(isClientReleased(currentBufferState, b1ClientMask));
+ EXPECT_TRUE(isClientPosted(currentBufferState, b2ClientMask));
}
TEST_F(BufferHubBufferStateTransitionTest, PostBuffer_fromPostedState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_TRUE(AnyClientPosted(b1->buffer_state()));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_TRUE(isAnyClientPosted(b1->bufferState()));
// Post from posted state should fail.
- EXPECT_EQ(b1->Post(), -EBUSY);
- EXPECT_EQ(b2->Post(), -EBUSY);
+ EXPECT_EQ(b1->post(), -EBUSY);
+ EXPECT_EQ(b2->post(), -EBUSY);
}
TEST_F(BufferHubBufferStateTransitionTest, PostBuffer_fromAcquiredState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_EQ(b2->Acquire(), 0);
- ASSERT_TRUE(AnyClientAcquired(b1->buffer_state()));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_EQ(b2->acquire(), 0);
+ ASSERT_TRUE(isAnyClientAcquired(b1->bufferState()));
// Posting from acquired state should fail.
- EXPECT_EQ(b1->Post(), -EBUSY);
- EXPECT_EQ(b2->Post(), -EBUSY);
+ EXPECT_EQ(b1->post(), -EBUSY);
+ EXPECT_EQ(b2->post(), -EBUSY);
}
TEST_F(BufferHubBufferStateTransitionTest, PostBuffer_fromReleasedState) {
- ASSERT_TRUE(b1->IsReleased());
+ ASSERT_TRUE(b1->isReleased());
// Posting from released state should fail.
- EXPECT_EQ(b1->Post(), -EBUSY);
- EXPECT_EQ(b2->Post(), -EBUSY);
+ EXPECT_EQ(b1->post(), -EBUSY);
+ EXPECT_EQ(b2->post(), -EBUSY);
}
TEST_F(BufferHubBufferStateTransitionTest, AcquireBuffer_fromSelfInPostedState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_TRUE(IsClientPosted(b1->buffer_state(), b2ClientMask));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_TRUE(isClientPosted(b1->bufferState(), b2ClientMask));
// Acquire from posted state should pass.
- EXPECT_EQ(b2->Acquire(), 0);
+ EXPECT_EQ(b2->acquire(), 0);
}
TEST_F(BufferHubBufferStateTransitionTest, AcquireBuffer_fromOtherInPostedState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_TRUE(IsClientPosted(b1->buffer_state(), b2ClientMask));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_TRUE(isClientPosted(b1->bufferState(), b2ClientMask));
// Acquire from released state should fail, although there are other clients
// in posted state.
- EXPECT_EQ(b1->Acquire(), -EBUSY);
+ EXPECT_EQ(b1->acquire(), -EBUSY);
}
TEST_F(BufferHubBufferStateTransitionTest, AcquireBuffer_fromSelfInAcquiredState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_EQ(b2->Acquire(), 0);
- auto currentBufferState = b1->buffer_state();
- ASSERT_TRUE(IsClientAcquired(currentBufferState, b2ClientMask));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_EQ(b2->acquire(), 0);
+ auto currentBufferState = b1->bufferState();
+ ASSERT_TRUE(isClientAcquired(currentBufferState, b2ClientMask));
// Acquiring from acquired state by the same client should not error out.
- EXPECT_EQ(b2->Acquire(), 0);
+ EXPECT_EQ(b2->acquire(), 0);
}
TEST_F(BufferHubBufferStateTransitionTest, AcquireBuffer_fromReleasedState) {
- ASSERT_TRUE(b1->IsReleased());
+ ASSERT_TRUE(b1->isReleased());
// Acquiring form released state should fail.
- EXPECT_EQ(b1->Acquire(), -EBUSY);
- EXPECT_EQ(b2->Acquire(), -EBUSY);
+ EXPECT_EQ(b1->acquire(), -EBUSY);
+ EXPECT_EQ(b2->acquire(), -EBUSY);
}
TEST_F(BufferHubBufferStateTransitionTest, AcquireBuffer_fromGainedState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_TRUE(AnyClientGained(b1->buffer_state()));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_TRUE(isAnyClientGained(b1->bufferState()));
// Acquiring from gained state should fail.
- EXPECT_EQ(b1->Acquire(), -EBUSY);
- EXPECT_EQ(b2->Acquire(), -EBUSY);
+ EXPECT_EQ(b1->acquire(), -EBUSY);
+ EXPECT_EQ(b2->acquire(), -EBUSY);
}
TEST_F(BufferHubBufferStateTransitionTest, ReleaseBuffer_fromSelfInReleasedState) {
- ASSERT_TRUE(b1->IsReleased());
+ ASSERT_TRUE(b1->isReleased());
- EXPECT_EQ(b1->Release(), 0);
+ EXPECT_EQ(b1->release(), 0);
}
TEST_F(BufferHubBufferStateTransitionTest, ReleaseBuffer_fromSelfInGainedState) {
- ASSERT_TRUE(b1->IsReleased());
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_TRUE(AnyClientGained(b1->buffer_state()));
+ ASSERT_TRUE(b1->isReleased());
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_TRUE(isAnyClientGained(b1->bufferState()));
- EXPECT_EQ(b1->Release(), 0);
+ EXPECT_EQ(b1->release(), 0);
}
TEST_F(BufferHubBufferStateTransitionTest, ReleaseBuffer_fromSelfInPostedState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_TRUE(AnyClientPosted(b1->buffer_state()));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_TRUE(isAnyClientPosted(b1->bufferState()));
- EXPECT_EQ(b2->Release(), 0);
+ EXPECT_EQ(b2->release(), 0);
}
TEST_F(BufferHubBufferStateTransitionTest, ReleaseBuffer_fromSelfInAcquiredState) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_EQ(b2->Acquire(), 0);
- ASSERT_TRUE(AnyClientAcquired(b1->buffer_state()));
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_EQ(b2->acquire(), 0);
+ ASSERT_TRUE(isAnyClientAcquired(b1->bufferState()));
- EXPECT_EQ(b2->Release(), 0);
+ EXPECT_EQ(b2->release(), 0);
}
TEST_F(BufferHubBufferStateTransitionTest, BasicUsage) {
@@ -408,60 +408,60 @@
// Test if this set of basic operation succeed:
// Producer post three times to the consumer, and released by consumer.
for (int i = 0; i < 3; ++i) {
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
- ASSERT_EQ(b2->Acquire(), 0);
- ASSERT_EQ(b2->Release(), 0);
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ ASSERT_EQ(b2->acquire(), 0);
+ ASSERT_EQ(b2->release(), 0);
}
}
TEST_F(BufferHubBufferTest, createNewConsumerAfterGain) {
// Create a poducer buffer and gain.
std::unique_ptr<BufferHubBuffer> b1 =
- BufferHubBuffer::Create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
+ BufferHubBuffer::create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
kUserMetadataSize);
ASSERT_THAT(b1, NotNull());
- ASSERT_EQ(b1->Gain(), 0);
+ ASSERT_EQ(b1->gain(), 0);
// Create a consumer of the buffer and test if the consumer can acquire the
// buffer if producer posts.
// TODO(b/122543147): use a movalbe wrapper for token
- native_handle_t* token = b1->Duplicate();
+ native_handle_t* token = b1->duplicate();
ASSERT_TRUE(token);
- std::unique_ptr<BufferHubBuffer> b2 = BufferHubBuffer::Import(token);
+ std::unique_ptr<BufferHubBuffer> b2 = BufferHubBuffer::import(token);
native_handle_close(token);
native_handle_delete(token);
ASSERT_THAT(b2, NotNull());
- ASSERT_NE(b1->client_state_mask(), b2->client_state_mask());
+ ASSERT_NE(b1->clientStateMask(), b2->clientStateMask());
- ASSERT_EQ(b1->Post(), 0);
- EXPECT_EQ(b2->Acquire(), 0);
+ ASSERT_EQ(b1->post(), 0);
+ EXPECT_EQ(b2->acquire(), 0);
}
TEST_F(BufferHubBufferTest, createNewConsumerAfterPost) {
// Create a poducer buffer and post.
std::unique_ptr<BufferHubBuffer> b1 =
- BufferHubBuffer::Create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
+ BufferHubBuffer::create(kWidth, kHeight, kLayerCount, kFormat, kUsage,
kUserMetadataSize);
- ASSERT_EQ(b1->Gain(), 0);
- ASSERT_EQ(b1->Post(), 0);
+ ASSERT_EQ(b1->gain(), 0);
+ ASSERT_EQ(b1->post(), 0);
// Create a consumer of the buffer and test if the consumer can acquire the
// buffer if producer posts.
// TODO(b/122543147): use a movalbe wrapper for token
- native_handle_t* token = b1->Duplicate();
+ native_handle_t* token = b1->duplicate();
ASSERT_TRUE(token);
- std::unique_ptr<BufferHubBuffer> b2 = BufferHubBuffer::Import(token);
+ std::unique_ptr<BufferHubBuffer> b2 = BufferHubBuffer::import(token);
native_handle_close(token);
native_handle_delete(token);
ASSERT_THAT(b2, NotNull());
- ASSERT_NE(b1->client_state_mask(), b2->client_state_mask());
+ ASSERT_NE(b1->clientStateMask(), b2->clientStateMask());
- EXPECT_EQ(b2->Acquire(), 0);
+ EXPECT_EQ(b2->acquire(), 0);
}
} // namespace
diff --git a/libs/ui/tests/BufferHubMetadata_test.cpp b/libs/ui/tests/BufferHubMetadata_test.cpp
index b7f0b4b..f02c4fc 100644
--- a/libs/ui/tests/BufferHubMetadata_test.cpp
+++ b/libs/ui/tests/BufferHubMetadata_test.cpp
@@ -25,74 +25,73 @@
class BufferHubMetadataTest : public ::testing::Test {};
TEST_F(BufferHubMetadataTest, Create_UserMetdataSizeTooBig) {
- BufferHubMetadata m1 =
- BufferHubMetadata::Create(std::numeric_limits<uint32_t>::max());
- EXPECT_FALSE(m1.IsValid());
+ BufferHubMetadata m1 = BufferHubMetadata::create(std::numeric_limits<uint32_t>::max());
+ EXPECT_FALSE(m1.isValid());
}
TEST_F(BufferHubMetadataTest, Create_Success) {
- BufferHubMetadata m1 = BufferHubMetadata::Create(kEmptyUserMetadataSize);
- EXPECT_TRUE(m1.IsValid());
- EXPECT_NE(m1.metadata_header(), nullptr);
+ BufferHubMetadata m1 = BufferHubMetadata::create(kEmptyUserMetadataSize);
+ EXPECT_TRUE(m1.isValid());
+ EXPECT_NE(m1.metadataHeader(), nullptr);
}
TEST_F(BufferHubMetadataTest, Import_Success) {
- BufferHubMetadata m1 = BufferHubMetadata::Create(kEmptyUserMetadataSize);
- EXPECT_TRUE(m1.IsValid());
- EXPECT_NE(m1.metadata_header(), nullptr);
+ BufferHubMetadata m1 = BufferHubMetadata::create(kEmptyUserMetadataSize);
+ EXPECT_TRUE(m1.isValid());
+ EXPECT_NE(m1.metadataHeader(), nullptr);
- unique_fd h2 = unique_fd(dup(m1.ashmem_fd().get()));
- EXPECT_NE(h2.get(), -1);
+ unique_fd h2 = unique_fd(dup(m1.ashmemFd().get()));
+ EXPECT_NE(h2.get(), -1);
- BufferHubMetadata m2 = BufferHubMetadata::Import(std::move(h2));
- EXPECT_EQ(h2.get(), -1);
- EXPECT_TRUE(m1.IsValid());
- BufferHubDefs::MetadataHeader* mh1 = m1.metadata_header();
- EXPECT_NE(mh1, nullptr);
+ BufferHubMetadata m2 = BufferHubMetadata::import(std::move(h2));
+ EXPECT_EQ(h2.get(), -1);
+ EXPECT_TRUE(m1.isValid());
+ BufferHubDefs::MetadataHeader* mh1 = m1.metadataHeader();
+ EXPECT_NE(mh1, nullptr);
- // Check if the newly allocated buffer is initialized in released state (i.e.
- // state equals to 0U).
- EXPECT_TRUE(mh1->buffer_state.load() == 0U);
+ // Check if the newly allocated buffer is initialized in released state (i.e.
+ // state equals to 0U).
+ EXPECT_TRUE(mh1->buffer_state.load() == 0U);
- EXPECT_TRUE(m2.IsValid());
- BufferHubDefs::MetadataHeader* mh2 = m2.metadata_header();
- EXPECT_NE(mh2, nullptr);
+ EXPECT_TRUE(m2.isValid());
+ BufferHubDefs::MetadataHeader* mh2 = m2.metadataHeader();
+ EXPECT_NE(mh2, nullptr);
- // Check if the newly allocated buffer is initialized in released state (i.e.
- // state equals to 0U).
- EXPECT_TRUE(mh2->buffer_state.load() == 0U);
+ // Check if the newly allocated buffer is initialized in released state (i.e.
+ // state equals to 0U).
+ EXPECT_TRUE(mh2->buffer_state.load() == 0U);
}
TEST_F(BufferHubMetadataTest, MoveMetadataInvalidatesOldOne) {
- BufferHubMetadata m1 = BufferHubMetadata::Create(sizeof(int));
- EXPECT_TRUE(m1.IsValid());
- EXPECT_NE(m1.metadata_header(), nullptr);
- EXPECT_NE(m1.ashmem_fd().get(), -1);
- EXPECT_EQ(m1.user_metadata_size(), sizeof(int));
+ BufferHubMetadata m1 = BufferHubMetadata::create(sizeof(int));
+ EXPECT_TRUE(m1.isValid());
+ EXPECT_NE(m1.metadataHeader(), nullptr);
+ EXPECT_NE(m1.ashmemFd().get(), -1);
+ EXPECT_EQ(m1.userMetadataSize(), sizeof(int));
- BufferHubMetadata m2 = std::move(m1);
+ BufferHubMetadata m2 = std::move(m1);
- // After the move, the metadata header (a raw pointer) should be reset in the older buffer.
- EXPECT_EQ(m1.metadata_header(), nullptr);
- EXPECT_NE(m2.metadata_header(), nullptr);
+ // After the move, the metadata header (a raw pointer) should be reset in the older buffer.
+ EXPECT_EQ(m1.metadataHeader(), nullptr);
+ EXPECT_NE(m2.metadataHeader(), nullptr);
- EXPECT_EQ(m1.ashmem_fd().get(), -1);
- EXPECT_NE(m2.ashmem_fd().get(), -1);
+ EXPECT_EQ(m1.ashmemFd().get(), -1);
+ EXPECT_NE(m2.ashmemFd().get(), -1);
- EXPECT_EQ(m1.user_metadata_size(), 0U);
- EXPECT_EQ(m2.user_metadata_size(), sizeof(int));
+ EXPECT_EQ(m1.userMetadataSize(), 0U);
+ EXPECT_EQ(m2.userMetadataSize(), sizeof(int));
- BufferHubMetadata m3{std::move(m2)};
+ BufferHubMetadata m3{std::move(m2)};
- // After the move, the metadata header (a raw pointer) should be reset in the older buffer.
- EXPECT_EQ(m2.metadata_header(), nullptr);
- EXPECT_NE(m3.metadata_header(), nullptr);
+ // After the move, the metadata header (a raw pointer) should be reset in the older buffer.
+ EXPECT_EQ(m2.metadataHeader(), nullptr);
+ EXPECT_NE(m3.metadataHeader(), nullptr);
- EXPECT_EQ(m2.ashmem_fd().get(), -1);
- EXPECT_NE(m3.ashmem_fd().get(), -1);
+ EXPECT_EQ(m2.ashmemFd().get(), -1);
+ EXPECT_NE(m3.ashmemFd().get(), -1);
- EXPECT_EQ(m2.user_metadata_size(), 0U);
- EXPECT_EQ(m3.user_metadata_size(), sizeof(int));
+ EXPECT_EQ(m2.userMetadataSize(), 0U);
+ EXPECT_EQ(m3.userMetadataSize(), sizeof(int));
}
} // namespace dvr
diff --git a/libs/ui/tests/GraphicBuffer_test.cpp b/libs/ui/tests/GraphicBuffer_test.cpp
index 5b46454..c767ce0 100644
--- a/libs/ui/tests/GraphicBuffer_test.cpp
+++ b/libs/ui/tests/GraphicBuffer_test.cpp
@@ -37,10 +37,10 @@
TEST_F(GraphicBufferTest, CreateFromBufferHubBuffer) {
std::unique_ptr<BufferHubBuffer> b1 =
- BufferHubBuffer::Create(kTestWidth, kTestHeight, kTestLayerCount, kTestFormat,
+ BufferHubBuffer::create(kTestWidth, kTestHeight, kTestLayerCount, kTestFormat,
kTestUsage, /*userMetadataSize=*/0);
ASSERT_NE(b1, nullptr);
- EXPECT_TRUE(b1->IsValid());
+ EXPECT_TRUE(b1->isValid());
sp<GraphicBuffer> gb(new GraphicBuffer(std::move(b1)));
EXPECT_TRUE(gb->isBufferHubBuffer());
@@ -61,10 +61,10 @@
TEST_F(GraphicBufferTest, BufferIdMatchesBufferHubBufferId) {
std::unique_ptr<BufferHubBuffer> b1 =
- BufferHubBuffer::Create(kTestWidth, kTestHeight, kTestLayerCount, kTestFormat,
+ BufferHubBuffer::create(kTestWidth, kTestHeight, kTestLayerCount, kTestFormat,
kTestUsage, /*userMetadataSize=*/0);
EXPECT_NE(b1, nullptr);
- EXPECT_TRUE(b1->IsValid());
+ EXPECT_TRUE(b1->isValid());
int b1_id = b1->id();
EXPECT_GE(b1_id, 0);
diff --git a/libs/vr/libbufferhub/buffer_hub-test.cpp b/libs/vr/libbufferhub/buffer_hub-test.cpp
index 527a27d..27ab024 100644
--- a/libs/vr/libbufferhub/buffer_hub-test.cpp
+++ b/libs/vr/libbufferhub/buffer_hub-test.cpp
@@ -20,12 +20,12 @@
return result; \
})()
-using android::BufferHubDefs::AnyClientAcquired;
-using android::BufferHubDefs::AnyClientGained;
-using android::BufferHubDefs::AnyClientPosted;
-using android::BufferHubDefs::IsClientAcquired;
-using android::BufferHubDefs::IsClientPosted;
-using android::BufferHubDefs::IsClientReleased;
+using android::BufferHubDefs::isAnyClientAcquired;
+using android::BufferHubDefs::isAnyClientGained;
+using android::BufferHubDefs::isAnyClientPosted;
+using android::BufferHubDefs::isClientAcquired;
+using android::BufferHubDefs::isClientPosted;
+using android::BufferHubDefs::isClientReleased;
using android::BufferHubDefs::kFirstClientBitMask;
using android::dvr::ConsumerBuffer;
using android::dvr::ProducerBuffer;
@@ -268,7 +268,7 @@
// Post in gained state should succeed.
EXPECT_EQ(0, p->PostAsync(&metadata, invalid_fence));
EXPECT_EQ(p->buffer_state(), c->buffer_state());
- EXPECT_TRUE(AnyClientPosted(p->buffer_state()));
+ EXPECT_TRUE(isAnyClientPosted(p->buffer_state()));
// Post and gain in posted state should fail.
EXPECT_EQ(-EBUSY, p->PostAsync(&metadata, invalid_fence));
@@ -280,7 +280,7 @@
EXPECT_EQ(0, c->AcquireAsync(&metadata, &invalid_fence));
EXPECT_FALSE(invalid_fence.IsValid());
EXPECT_EQ(p->buffer_state(), c->buffer_state());
- EXPECT_TRUE(AnyClientAcquired(p->buffer_state()));
+ EXPECT_TRUE(isAnyClientAcquired(p->buffer_state()));
// Acquire, post, and gain in acquired state should fail.
EXPECT_EQ(-EBUSY, c->AcquireAsync(&metadata, &invalid_fence));
@@ -304,7 +304,7 @@
EXPECT_EQ(0, p->GainAsync(&metadata, &invalid_fence));
EXPECT_FALSE(invalid_fence.IsValid());
EXPECT_EQ(p->buffer_state(), c->buffer_state());
- EXPECT_TRUE(AnyClientGained(p->buffer_state()));
+ EXPECT_TRUE(isAnyClientGained(p->buffer_state()));
// Acquire and gain in gained state should fail.
EXPECT_EQ(-EBUSY, c->AcquireAsync(&metadata, &invalid_fence));
@@ -329,7 +329,7 @@
ASSERT_TRUE(c.get() != nullptr);
ASSERT_EQ(0, p->GainAsync());
ASSERT_EQ(0, p->Post(LocalHandle()));
- ASSERT_TRUE(AnyClientPosted(p->buffer_state()));
+ ASSERT_TRUE(isAnyClientPosted(p->buffer_state()));
// Gain in posted state should only succeed with gain_posted_buffer = true.
LocalHandle invalid_fence;
@@ -346,7 +346,7 @@
ASSERT_TRUE(c.get() != nullptr);
ASSERT_EQ(0, p->GainAsync());
ASSERT_EQ(0, p->Post(LocalHandle()));
- ASSERT_TRUE(AnyClientPosted(p->buffer_state()));
+ ASSERT_TRUE(isAnyClientPosted(p->buffer_state()));
// GainAsync in posted state should only succeed with gain_posted_buffer
// equals true.
@@ -364,9 +364,9 @@
ASSERT_EQ(0, p->Post(LocalHandle()));
// Producer state bit is in released state after post, other clients shall be
// in posted state although there is no consumer of this buffer yet.
- ASSERT_TRUE(IsClientReleased(p->buffer_state(), p->client_state_mask()));
+ ASSERT_TRUE(isClientReleased(p->buffer_state(), p->client_state_mask()));
ASSERT_TRUE(p->is_released());
- ASSERT_TRUE(AnyClientPosted(p->buffer_state()));
+ ASSERT_TRUE(isAnyClientPosted(p->buffer_state()));
// Gain in released state should succeed.
LocalHandle invalid_fence;
@@ -393,14 +393,14 @@
// Post the producer should trigger all consumers to be available.
EXPECT_EQ(0, p->PostAsync(&metadata, invalid_fence));
- EXPECT_TRUE(IsClientReleased(p->buffer_state(), p->client_state_mask()));
+ EXPECT_TRUE(isClientReleased(p->buffer_state(), p->client_state_mask()));
for (size_t i = 0; i < kMaxConsumerCount; ++i) {
EXPECT_TRUE(
- IsClientPosted(cs[i]->buffer_state(), cs[i]->client_state_mask()));
+ isClientPosted(cs[i]->buffer_state(), cs[i]->client_state_mask()));
EXPECT_LT(0, RETRY_EINTR(PollBufferEvent(cs[i])));
EXPECT_EQ(0, cs[i]->AcquireAsync(&metadata, &invalid_fence));
EXPECT_TRUE(
- IsClientAcquired(p->buffer_state(), cs[i]->client_state_mask()));
+ isClientAcquired(p->buffer_state(), cs[i]->client_state_mask()));
}
// All consumers have to release before the buffer is considered to be
@@ -424,22 +424,22 @@
kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
ASSERT_TRUE(p.get() != nullptr);
EXPECT_EQ(0, p->GainAsync());
- EXPECT_TRUE(AnyClientGained(p->buffer_state()));
+ EXPECT_TRUE(isAnyClientGained(p->buffer_state()));
std::unique_ptr<ConsumerBuffer> c =
ConsumerBuffer::Import(p->CreateConsumer());
ASSERT_TRUE(c.get() != nullptr);
- EXPECT_TRUE(AnyClientGained(c->buffer_state()));
+ EXPECT_TRUE(isAnyClientGained(c->buffer_state()));
DvrNativeBufferMetadata metadata;
LocalHandle invalid_fence;
// Post the gained buffer should signal already created consumer.
EXPECT_EQ(0, p->PostAsync(&metadata, invalid_fence));
- EXPECT_TRUE(AnyClientPosted(p->buffer_state()));
+ EXPECT_TRUE(isAnyClientPosted(p->buffer_state()));
EXPECT_LT(0, RETRY_EINTR(PollBufferEvent(c)));
EXPECT_EQ(0, c->AcquireAsync(&metadata, &invalid_fence));
- EXPECT_TRUE(AnyClientAcquired(c->buffer_state()));
+ EXPECT_TRUE(isAnyClientAcquired(c->buffer_state()));
}
TEST_F(LibBufferHubTest, TestCreateTheFirstConsumerAfterPostingBuffer) {
@@ -447,7 +447,7 @@
kWidth, kHeight, kFormat, kUsage, sizeof(uint64_t));
ASSERT_TRUE(p.get() != nullptr);
EXPECT_EQ(0, p->GainAsync());
- EXPECT_TRUE(AnyClientGained(p->buffer_state()));
+ EXPECT_TRUE(isAnyClientGained(p->buffer_state()));
DvrNativeBufferMetadata metadata;
LocalHandle invalid_fence;
@@ -462,7 +462,7 @@
std::unique_ptr<ConsumerBuffer> c =
ConsumerBuffer::Import(p->CreateConsumer());
ASSERT_TRUE(c.get() != nullptr);
- EXPECT_TRUE(IsClientPosted(c->buffer_state(), c->client_state_mask()));
+ EXPECT_TRUE(isClientPosted(c->buffer_state(), c->client_state_mask()));
EXPECT_EQ(0, c->AcquireAsync(&metadata, &invalid_fence));
}
@@ -500,7 +500,7 @@
EXPECT_TRUE(p->is_released());
EXPECT_EQ(0, p->GainAsync(&metadata, &invalid_fence));
- EXPECT_TRUE(AnyClientGained(p->buffer_state()));
+ EXPECT_TRUE(isAnyClientGained(p->buffer_state()));
}
TEST_F(LibBufferHubTest, TestWithCustomMetadata) {
diff --git a/libs/vr/libbufferhub/consumer_buffer.cpp b/libs/vr/libbufferhub/consumer_buffer.cpp
index b6ca64e..115e866 100644
--- a/libs/vr/libbufferhub/consumer_buffer.cpp
+++ b/libs/vr/libbufferhub/consumer_buffer.cpp
@@ -38,7 +38,7 @@
// The buffer can be acquired iff the buffer state for this client is posted.
uint32_t current_buffer_state =
buffer_state_->load(std::memory_order_acquire);
- if (!BufferHubDefs::IsClientPosted(current_buffer_state,
+ if (!BufferHubDefs::isClientPosted(current_buffer_state,
client_state_mask())) {
ALOGE(
"%s: Failed to acquire the buffer. The buffer is not posted, id=%d "
@@ -58,7 +58,7 @@
" when trying to acquire the buffer and modify the buffer state to "
"%" PRIx32 ". About to try again if the buffer is still posted.",
__FUNCTION__, current_buffer_state, updated_buffer_state);
- if (!BufferHubDefs::IsClientPosted(current_buffer_state,
+ if (!BufferHubDefs::isClientPosted(current_buffer_state,
client_state_mask())) {
ALOGE(
"%s: Failed to acquire the buffer. The buffer is no longer posted, "
@@ -144,7 +144,7 @@
// released state.
uint32_t current_buffer_state =
buffer_state_->load(std::memory_order_acquire);
- if (BufferHubDefs::IsClientReleased(current_buffer_state,
+ if (BufferHubDefs::isClientReleased(current_buffer_state,
client_state_mask())) {
return 0;
}
diff --git a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h
index bab7367..e610e18 100644
--- a/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h
+++ b/libs/vr/libbufferhub/include/private/dvr/buffer_hub_defs.h
@@ -27,38 +27,38 @@
static constexpr uint32_t kFirstClientBitMask =
android::BufferHubDefs::kFirstClientBitMask;
-static inline bool AnyClientGained(uint32_t state) {
- return android::BufferHubDefs::AnyClientGained(state);
+static inline bool isAnyClientGained(uint32_t state) {
+ return android::BufferHubDefs::isAnyClientGained(state);
}
-static inline bool IsClientGained(uint32_t state, uint32_t client_bit_mask) {
- return android::BufferHubDefs::IsClientGained(state, client_bit_mask);
+static inline bool isClientGained(uint32_t state, uint32_t client_bit_mask) {
+ return android::BufferHubDefs::isClientGained(state, client_bit_mask);
}
-static inline bool AnyClientPosted(uint32_t state) {
- return android::BufferHubDefs::AnyClientPosted(state);
+static inline bool isAnyClientPosted(uint32_t state) {
+ return android::BufferHubDefs::isAnyClientPosted(state);
}
-static inline bool IsClientPosted(uint32_t state, uint32_t client_bit_mask) {
- return android::BufferHubDefs::IsClientPosted(state, client_bit_mask);
+static inline bool isClientPosted(uint32_t state, uint32_t client_bit_mask) {
+ return android::BufferHubDefs::isClientPosted(state, client_bit_mask);
}
-static inline bool AnyClientAcquired(uint32_t state) {
- return android::BufferHubDefs::AnyClientAcquired(state);
+static inline bool isAnyClientAcquired(uint32_t state) {
+ return android::BufferHubDefs::isAnyClientAcquired(state);
}
-static inline bool IsClientAcquired(uint32_t state, uint32_t client_bit_mask) {
- return android::BufferHubDefs::IsClientAcquired(state, client_bit_mask);
+static inline bool isClientAcquired(uint32_t state, uint32_t client_bit_mask) {
+ return android::BufferHubDefs::isClientAcquired(state, client_bit_mask);
}
-static inline bool IsClientReleased(uint32_t state, uint32_t client_bit_mask) {
- return android::BufferHubDefs::IsClientReleased(state, client_bit_mask);
+static inline bool isClientReleased(uint32_t state, uint32_t client_bit_mask) {
+ return android::BufferHubDefs::isClientReleased(state, client_bit_mask);
}
// Returns the next available buffer client's client_state_masks.
// @params union_bits. Union of all existing clients' client_state_masks.
-static inline uint32_t FindNextAvailableClientStateMask(uint32_t union_bits) {
- return android::BufferHubDefs::FindNextAvailableClientStateMask(union_bits);
+static inline uint32_t findNextAvailableClientStateMask(uint32_t union_bits) {
+ return android::BufferHubDefs::findNextAvailableClientStateMask(union_bits);
}
using MetadataHeader = android::BufferHubDefs::MetadataHeader;
diff --git a/libs/vr/libbufferhub/producer_buffer.cpp b/libs/vr/libbufferhub/producer_buffer.cpp
index edfdddf..3d88ba5 100644
--- a/libs/vr/libbufferhub/producer_buffer.cpp
+++ b/libs/vr/libbufferhub/producer_buffer.cpp
@@ -82,7 +82,7 @@
// The buffer can be posted iff the buffer state for this client is gained.
uint32_t current_buffer_state =
buffer_state_->load(std::memory_order_acquire);
- if (!BufferHubDefs::IsClientGained(current_buffer_state,
+ if (!BufferHubDefs::isClientGained(current_buffer_state,
client_state_mask())) {
ALOGE("%s: not gained, id=%d state=%" PRIx32 ".", __FUNCTION__, id(),
current_buffer_state);
@@ -103,7 +103,7 @@
"%" PRIx32
". About to try again if the buffer is still gained by this client.",
__FUNCTION__, current_buffer_state, updated_buffer_state);
- if (!BufferHubDefs::IsClientGained(current_buffer_state,
+ if (!BufferHubDefs::isClientGained(current_buffer_state,
client_state_mask())) {
ALOGE(
"%s: Failed to post the buffer. The buffer is no longer gained, "
@@ -166,14 +166,14 @@
ALOGD_IF(TRACE, "%s: buffer=%d, state=%" PRIx32 ".", __FUNCTION__, id(),
current_buffer_state);
- if (BufferHubDefs::IsClientGained(current_buffer_state,
+ if (BufferHubDefs::isClientGained(current_buffer_state,
client_state_mask())) {
ALOGV("%s: already gained id=%d.", __FUNCTION__, id());
return 0;
}
- if (BufferHubDefs::AnyClientAcquired(current_buffer_state) ||
- BufferHubDefs::AnyClientGained(current_buffer_state) ||
- (BufferHubDefs::AnyClientPosted(
+ if (BufferHubDefs::isAnyClientAcquired(current_buffer_state) ||
+ BufferHubDefs::isAnyClientGained(current_buffer_state) ||
+ (BufferHubDefs::isAnyClientPosted(
current_buffer_state &
active_clients_bit_mask_->load(std::memory_order_acquire)) &&
!gain_posted_buffer)) {
@@ -195,9 +195,9 @@
"clients.",
__FUNCTION__, current_buffer_state, updated_buffer_state);
- if (BufferHubDefs::AnyClientAcquired(current_buffer_state) ||
- BufferHubDefs::AnyClientGained(current_buffer_state) ||
- (BufferHubDefs::AnyClientPosted(
+ if (BufferHubDefs::isAnyClientAcquired(current_buffer_state) ||
+ BufferHubDefs::isAnyClientGained(current_buffer_state) ||
+ (BufferHubDefs::isAnyClientPosted(
current_buffer_state &
active_clients_bit_mask_->load(std::memory_order_acquire)) &&
!gain_posted_buffer)) {
@@ -291,7 +291,7 @@
// TODO(b/112338294) Keep here for reference. Remove it after new logic is
// written.
/* uint32_t buffer_state = buffer_state_->load(std::memory_order_acquire);
- if (!BufferHubDefs::IsClientGained(
+ if (!BufferHubDefs::isClientGained(
buffer_state, BufferHubDefs::kFirstClientStateMask)) {
// Can only detach a ProducerBuffer when it's in gained state.
ALOGW("ProducerBuffer::Detach: The buffer (id=%d, state=0x%" PRIx32
diff --git a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp
index d7833f3..2d3fa4a 100644
--- a/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp
+++ b/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp
@@ -532,7 +532,7 @@
Status<size_t> ProducerQueue::InsertBuffer(
const std::shared_ptr<ProducerBuffer>& buffer) {
if (buffer == nullptr ||
- !BufferHubDefs::IsClientGained(buffer->buffer_state(),
+ !BufferHubDefs::isClientGained(buffer->buffer_state(),
buffer->client_state_mask())) {
ALOGE(
"ProducerQueue::InsertBuffer: Can only insert a buffer when it's in "
@@ -638,7 +638,7 @@
static_cast<int>(*slot));
return ErrorStatus(EIO);
}
- if (!BufferHubDefs::AnyClientAcquired(buffer->buffer_state())) {
+ if (!BufferHubDefs::isAnyClientAcquired(buffer->buffer_state())) {
*slot = *iter;
unavailable_buffers_slot_.erase(iter);
unavailable_buffers_slot_.push_back(*slot);
diff --git a/opengl/libagl/Android.bp b/opengl/libagl/Android.bp
new file mode 100644
index 0000000..6ec24b3
--- /dev/null
+++ b/opengl/libagl/Android.bp
@@ -0,0 +1,99 @@
+//
+// Build the software OpenGL ES library
+//
+
+cc_defaults {
+ name: "libGLES_android_defaults",
+
+ cflags: [
+ "-DLOG_TAG=\"libagl\"",
+ "-DGL_GLEXT_PROTOTYPES",
+ "-DEGL_EGLEXT_PROTOTYPES",
+ "-fvisibility=hidden",
+ "-Wall",
+ "-Werror",
+ ],
+
+ shared_libs: [
+ "libcutils",
+ "libhardware",
+ "libutils",
+ "liblog",
+ "libpixelflinger",
+ "libETC1",
+ "libui",
+ "libnativewindow",
+ ],
+
+ // we need to access the private Bionic header <bionic_tls.h>
+ include_dirs: ["bionic/libc/private"],
+
+ arch: {
+ arm: {
+ cflags: ["-fstrict-aliasing"],
+ },
+
+ mips: {
+ cflags: [
+ "-fstrict-aliasing",
+ // The graphics code can generate division by zero
+ "-mno-check-zero-division",
+ ],
+ },
+ },
+}
+
+cc_library_shared {
+ name: "libGLES_android",
+ defaults: ["libGLES_android_defaults"],
+
+ whole_static_libs: ["libGLES_android_arm"],
+
+ srcs: [
+ "egl.cpp",
+ "state.cpp",
+ "texture.cpp",
+ "Tokenizer.cpp",
+ "TokenManager.cpp",
+ "TextureObjectManager.cpp",
+ "BufferObjectManager.cpp",
+ ],
+
+ arch: {
+ arm: {
+ srcs: [
+ "fixed_asm.S",
+ "iterators.S",
+ ],
+ },
+
+ mips: {
+ rev6: {
+ srcs: ["arch-mips/fixed_asm.S"],
+ },
+ },
+ },
+
+ relative_install_path: "egl",
+}
+
+cc_library_static {
+ name: "libGLES_android_arm",
+ defaults: ["libGLES_android_defaults"],
+
+ srcs: [
+ "array.cpp",
+ "fp.cpp",
+ "light.cpp",
+ "matrix.cpp",
+ "mipmap.cpp",
+ "primitives.cpp",
+ "vertex.cpp",
+ ],
+
+ arch: {
+ arm: {
+ instruction_set: "arm",
+ },
+ },
+}
diff --git a/opengl/libagl/Android.mk b/opengl/libagl/Android.mk
deleted file mode 100644
index 15a12e4..0000000
--- a/opengl/libagl/Android.mk
+++ /dev/null
@@ -1,49 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-#
-# Build the software OpenGL ES library
-#
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- egl.cpp \
- state.cpp \
- texture.cpp \
- Tokenizer.cpp \
- TokenManager.cpp \
- TextureObjectManager.cpp \
- BufferObjectManager.cpp \
- array.cpp.arm \
- fp.cpp.arm \
- light.cpp.arm \
- matrix.cpp.arm \
- mipmap.cpp.arm \
- primitives.cpp.arm \
- vertex.cpp.arm
-
-LOCAL_CFLAGS += -DLOG_TAG=\"libagl\"
-LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
-LOCAL_CFLAGS += -fvisibility=hidden
-
-LOCAL_SHARED_LIBRARIES := libcutils libhardware libutils liblog libpixelflinger libETC1 libui libnativewindow
-
-LOCAL_SRC_FILES_arm += fixed_asm.S iterators.S
-LOCAL_CFLAGS_arm += -fstrict-aliasing
-
-ifndef ARCH_MIPS_REV6
-LOCAL_SRC_FILES_mips += arch-mips/fixed_asm.S
-endif
-LOCAL_CFLAGS_mips += -fstrict-aliasing
-# The graphics code can generate division by zero
-LOCAL_CFLAGS_mips += -mno-check-zero-division
-
-LOCAL_CFLAGS += -Wall -Werror
-
-# we need to access the private Bionic header <bionic_tls.h>
-LOCAL_C_INCLUDES += bionic/libc/private
-
-LOCAL_MODULE_RELATIVE_PATH := egl
-LOCAL_MODULE:= libGLES_android
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp
index 8a409ae..4cafe2b 100644
--- a/opengl/libs/EGL/Loader.cpp
+++ b/opengl/libs/EGL/Loader.cpp
@@ -255,6 +255,8 @@
LOG_ALWAYS_FATAL_IF(!cnx->libGles2 || !cnx->libGles1,
"couldn't load system OpenGL ES wrapper libraries");
+ android::GraphicsEnv::getInstance().sendGpuStats();
+
return (void*)hnd;
}
diff --git a/services/bufferhub/BufferHubService.cpp b/services/bufferhub/BufferHubService.cpp
index 6b802fb..90ac1c2 100644
--- a/services/bufferhub/BufferHubService.cpp
+++ b/services/bufferhub/BufferHubService.cpp
@@ -53,7 +53,7 @@
std::make_shared<BufferNode>(desc.width, desc.height, desc.layers, desc.format,
desc.usage, userMetadataSize,
BufferHubIdGenerator::getInstance().getId());
- if (node == nullptr || !node->IsValid()) {
+ if (node == nullptr || !node->isValid()) {
ALOGE("%s: creating BufferNode failed.", __FUNCTION__);
_hidl_cb(/*status=*/BufferHubStatus::ALLOCATION_FAILED, /*bufferClient=*/nullptr,
/*bufferTraits=*/{});
@@ -70,11 +70,11 @@
NATIVE_HANDLE_DECLARE_STORAGE(bufferInfoStorage, BufferHubDefs::kBufferInfoNumFds,
BufferHubDefs::kBufferInfoNumInts);
hidl_handle bufferInfo =
- buildBufferInfo(bufferInfoStorage, node->id(), node->AddNewActiveClientsBitToMask(),
- node->user_metadata_size(), node->metadata().ashmem_fd(),
+ buildBufferInfo(bufferInfoStorage, node->id(), node->addNewActiveClientsBitToMask(),
+ node->userMetadataSize(), node->metadata().ashmemFd(),
node->eventFd().get());
BufferTraits bufferTraits = {/*bufferDesc=*/description,
- /*bufferHandle=*/hidl_handle(node->buffer_handle()),
+ /*bufferHandle=*/hidl_handle(node->bufferHandle()),
/*bufferInfo=*/std::move(bufferInfo)};
_hidl_cb(/*status=*/BufferHubStatus::NO_ERROR, /*bufferClient=*/client,
@@ -141,7 +141,7 @@
}
sp<BufferClient> client = new BufferClient(*originClient);
- uint32_t clientStateMask = client->getBufferNode()->AddNewActiveClientsBitToMask();
+ uint32_t clientStateMask = client->getBufferNode()->addNewActiveClientsBitToMask();
if (clientStateMask == 0U) {
// Reach max client count
ALOGE("%s: import failed, BufferNode#%u reached maximum clients.", __FUNCTION__,
@@ -157,17 +157,17 @@
std::shared_ptr<BufferNode> node = client->getBufferNode();
HardwareBufferDescription bufferDesc;
- memcpy(&bufferDesc, &node->buffer_desc(), sizeof(HardwareBufferDescription));
+ memcpy(&bufferDesc, &node->bufferDesc(), sizeof(HardwareBufferDescription));
// Allocate memory for bufferInfo of type hidl_handle on the stack. See
// http://aosp/286282 for the usage of NATIVE_HANDLE_DECLARE_STORAGE.
NATIVE_HANDLE_DECLARE_STORAGE(bufferInfoStorage, BufferHubDefs::kBufferInfoNumFds,
BufferHubDefs::kBufferInfoNumInts);
hidl_handle bufferInfo = buildBufferInfo(bufferInfoStorage, node->id(), clientStateMask,
- node->user_metadata_size(),
- node->metadata().ashmem_fd(), node->eventFd().get());
+ node->userMetadataSize(), node->metadata().ashmemFd(),
+ node->eventFd().get());
BufferTraits bufferTraits = {/*bufferDesc=*/bufferDesc,
- /*bufferHandle=*/hidl_handle(node->buffer_handle()),
+ /*bufferHandle=*/hidl_handle(node->bufferHandle()),
/*bufferInfo=*/std::move(bufferInfo)};
_hidl_cb(/*status=*/BufferHubStatus::NO_ERROR, /*bufferClient=*/client,
@@ -231,10 +231,10 @@
for (auto iter = clientCount.begin(); iter != clientCount.end(); ++iter) {
const std::shared_ptr<BufferNode> node = std::move(iter->second.first);
const uint32_t clientCount = iter->second.second;
- AHardwareBuffer_Desc desc = node->buffer_desc();
+ AHardwareBuffer_Desc desc = node->bufferDesc();
MetadataHeader* metadataHeader =
- const_cast<BufferHubMetadata*>(&node->metadata())->metadata_header();
+ const_cast<BufferHubMetadata*>(&node->metadata())->metadataHeader();
const uint32_t state = metadataHeader->buffer_state.load(std::memory_order_acquire);
const uint64_t index = metadataHeader->queue_index;
diff --git a/services/bufferhub/BufferNode.cpp b/services/bufferhub/BufferNode.cpp
index dfa2de0..1efb27e 100644
--- a/services/bufferhub/BufferNode.cpp
+++ b/services/bufferhub/BufferNode.cpp
@@ -11,10 +11,10 @@
namespace V1_0 {
namespace implementation {
-void BufferNode::InitializeMetadata() {
+void BufferNode::initializeMetadata() {
// Using placement new here to reuse shared memory instead of new allocation
// Initialize the atomic variables to zero.
- BufferHubDefs::MetadataHeader* metadataHeader = mMetadata.metadata_header();
+ BufferHubDefs::MetadataHeader* metadataHeader = mMetadata.metadataHeader();
mBufferState = new (&metadataHeader->buffer_state) std::atomic<uint32_t>(0);
mFenceState = new (&metadataHeader->fence_state) std::atomic<uint32_t>(0);
mActiveClientsBitMask = new (&metadataHeader->active_clients_bit_mask) std::atomic<uint32_t>(0);
@@ -28,17 +28,17 @@
}
// Allocates a new BufferNode.
-BufferNode::BufferNode(uint32_t width, uint32_t height, uint32_t layer_count, uint32_t format,
- uint64_t usage, size_t user_metadata_size, int id)
+BufferNode::BufferNode(uint32_t width, uint32_t height, uint32_t layerCount, uint32_t format,
+ uint64_t usage, size_t userMetadataSize, int id)
: mId(id) {
- uint32_t out_stride = 0;
+ uint32_t outStride = 0;
// graphicBufferId is not used in GraphicBufferAllocator::allocate
// TODO(b/112338294) After move to the service folder, stop using the
// hardcoded service name "bufferhub".
- int ret = GraphicBufferAllocator::get().allocate(width, height, format, layer_count, usage,
+ int ret = GraphicBufferAllocator::get().allocate(width, height, format, layerCount, usage,
const_cast<const native_handle_t**>(
&mBufferHandle),
- &out_stride,
+ &outStride,
/*graphicBufferId=*/0,
/*requestor=*/"bufferhub");
@@ -49,17 +49,17 @@
mBufferDesc.width = width;
mBufferDesc.height = height;
- mBufferDesc.layers = layer_count;
+ mBufferDesc.layers = layerCount;
mBufferDesc.format = format;
mBufferDesc.usage = usage;
- mBufferDesc.stride = out_stride;
+ mBufferDesc.stride = outStride;
- mMetadata = BufferHubMetadata::Create(user_metadata_size);
- if (!mMetadata.IsValid()) {
+ mMetadata = BufferHubMetadata::create(userMetadataSize);
+ if (!mMetadata.isValid()) {
ALOGE("%s: Failed to allocate metadata.", __FUNCTION__);
return;
}
- InitializeMetadata();
+ initializeMetadata();
}
BufferNode::~BufferNode() {
@@ -77,32 +77,32 @@
}
}
-uint32_t BufferNode::GetActiveClientsBitMask() const {
+uint32_t BufferNode::getActiveClientsBitMask() const {
return mActiveClientsBitMask->load(std::memory_order_acquire);
}
-uint32_t BufferNode::AddNewActiveClientsBitToMask() {
- uint32_t currentActiveClientsBitMask = GetActiveClientsBitMask();
- uint32_t client_state_mask = 0U;
+uint32_t BufferNode::addNewActiveClientsBitToMask() {
+ uint32_t currentActiveClientsBitMask = getActiveClientsBitMask();
+ uint32_t clientStateMask = 0U;
uint32_t updatedActiveClientsBitMask = 0U;
do {
- client_state_mask =
- BufferHubDefs::FindNextAvailableClientStateMask(currentActiveClientsBitMask);
- if (client_state_mask == 0U) {
+ clientStateMask =
+ BufferHubDefs::findNextAvailableClientStateMask(currentActiveClientsBitMask);
+ if (clientStateMask == 0U) {
ALOGE("%s: reached the maximum number of channels per buffer node: %d.", __FUNCTION__,
BufferHubDefs::kMaxNumberOfClients);
errno = E2BIG;
return 0U;
}
- updatedActiveClientsBitMask = currentActiveClientsBitMask | client_state_mask;
+ updatedActiveClientsBitMask = currentActiveClientsBitMask | clientStateMask;
} while (!(mActiveClientsBitMask->compare_exchange_weak(currentActiveClientsBitMask,
updatedActiveClientsBitMask,
std::memory_order_acq_rel,
std::memory_order_acquire)));
- return client_state_mask;
+ return clientStateMask;
}
-void BufferNode::RemoveClientsBitFromMask(const uint32_t& value) {
+void BufferNode::removeClientsBitFromMask(const uint32_t& value) {
mActiveClientsBitMask->fetch_and(~value);
}
diff --git a/services/bufferhub/include/bufferhub/BufferClient.h b/services/bufferhub/include/bufferhub/BufferClient.h
index 66ed4bd..644b403 100644
--- a/services/bufferhub/include/bufferhub/BufferClient.h
+++ b/services/bufferhub/include/bufferhub/BufferClient.h
@@ -72,4 +72,4 @@
} // namespace frameworks
} // namespace android
-#endif
\ No newline at end of file
+#endif
diff --git a/services/bufferhub/include/bufferhub/BufferNode.h b/services/bufferhub/include/bufferhub/BufferNode.h
index 112a21c..62a8d63 100644
--- a/services/bufferhub/include/bufferhub/BufferNode.h
+++ b/services/bufferhub/include/bufferhub/BufferNode.h
@@ -16,21 +16,21 @@
class BufferNode {
public:
// Allocates a new BufferNode.
- BufferNode(uint32_t width, uint32_t height, uint32_t layer_count, uint32_t format,
- uint64_t usage, size_t user_metadata_size, int id = -1);
+ BufferNode(uint32_t width, uint32_t height, uint32_t layerCount, uint32_t format,
+ uint64_t usage, size_t userMetadataSize, int id = -1);
~BufferNode();
// Returns whether the object holds a valid metadata.
- bool IsValid() const { return mMetadata.IsValid(); }
+ bool isValid() const { return mMetadata.isValid(); }
int id() const { return mId; }
- size_t user_metadata_size() const { return mMetadata.user_metadata_size(); }
+ size_t userMetadataSize() const { return mMetadata.userMetadataSize(); }
// Accessors of the buffer description and handle
- const native_handle_t* buffer_handle() const { return mBufferHandle; }
- const AHardwareBuffer_Desc& buffer_desc() const { return mBufferDesc; }
+ const native_handle_t* bufferHandle() const { return mBufferHandle; }
+ const AHardwareBuffer_Desc& bufferDesc() const { return mBufferDesc; }
// Accessor of event fd.
const BufferHubEventFd& eventFd() const { return mEventFd; }
@@ -41,24 +41,24 @@
// Gets the current value of mActiveClientsBitMask in mMetadata with
// std::memory_order_acquire, so that all previous releases of
// mActiveClientsBitMask from all threads will be returned here.
- uint32_t GetActiveClientsBitMask() const;
+ uint32_t getActiveClientsBitMask() const;
// Find and add a new client state mask to mActiveClientsBitMask in
// mMetadata.
// Return the new client state mask that is added to mActiveClientsBitMask.
// Return 0U if there are already 16 clients of the buffer.
- uint32_t AddNewActiveClientsBitToMask();
+ uint32_t addNewActiveClientsBitToMask();
// Removes the value from active_clients_bit_mask in mMetadata with
// std::memory_order_release, so that the change will be visible to any
// acquire of mActiveClientsBitMask in any threads after the succeed of
// this operation.
- void RemoveClientsBitFromMask(const uint32_t& value);
+ void removeClientsBitFromMask(const uint32_t& value);
private:
// Helper method for constructors to initialize atomic metadata header
// variables in shared memory.
- void InitializeMetadata();
+ void initializeMetadata();
// Gralloc buffer handles.
native_handle_t* mBufferHandle;
diff --git a/services/bufferhub/tests/BufferNode_test.cpp b/services/bufferhub/tests/BufferNode_test.cpp
index ccb1197..2dfd4fc 100644
--- a/services/bufferhub/tests/BufferNode_test.cpp
+++ b/services/bufferhub/tests/BufferNode_test.cpp
@@ -26,80 +26,78 @@
class BufferNodeTest : public ::testing::Test {
protected:
void SetUp() override {
- buffer_node =
+ mBufferNode =
new BufferNode(kWidth, kHeight, kLayerCount, kFormat, kUsage, kUserMetadataSize);
- ASSERT_TRUE(buffer_node->IsValid());
+ ASSERT_TRUE(mBufferNode->isValid());
}
void TearDown() override {
- if (buffer_node != nullptr) {
- delete buffer_node;
+ if (mBufferNode != nullptr) {
+ delete mBufferNode;
}
}
- BufferNode* buffer_node = nullptr;
+ BufferNode* mBufferNode = nullptr;
};
TEST_F(BufferNodeTest, TestCreateBufferNode) {
- EXPECT_EQ(buffer_node->user_metadata_size(), kUserMetadataSize);
+ EXPECT_EQ(mBufferNode->userMetadataSize(), kUserMetadataSize);
// Test the handle just allocated is good (i.e. able to be imported)
GraphicBufferMapper& mapper = GraphicBufferMapper::get();
const native_handle_t* outHandle;
status_t ret =
- mapper.importBuffer(buffer_node->buffer_handle(), buffer_node->buffer_desc().width,
- buffer_node->buffer_desc().height,
- buffer_node->buffer_desc().layers,
- buffer_node->buffer_desc().format, buffer_node->buffer_desc().usage,
- buffer_node->buffer_desc().stride, &outHandle);
+ mapper.importBuffer(mBufferNode->bufferHandle(), mBufferNode->bufferDesc().width,
+ mBufferNode->bufferDesc().height, mBufferNode->bufferDesc().layers,
+ mBufferNode->bufferDesc().format, mBufferNode->bufferDesc().usage,
+ mBufferNode->bufferDesc().stride, &outHandle);
EXPECT_EQ(ret, OK);
EXPECT_THAT(outHandle, NotNull());
}
-TEST_F(BufferNodeTest, TestAddNewActiveClientsBitToMask_twoNewClients) {
- uint32_t new_client_state_mask_1 = buffer_node->AddNewActiveClientsBitToMask();
- EXPECT_EQ(buffer_node->GetActiveClientsBitMask(), new_client_state_mask_1);
+TEST_F(BufferNodeTest, TestaddNewActiveClientsBitToMask_twoNewClients) {
+ uint32_t newClientStateMask1 = mBufferNode->addNewActiveClientsBitToMask();
+ EXPECT_EQ(mBufferNode->getActiveClientsBitMask(), newClientStateMask1);
// Request and add a new client_state_mask again.
// Active clients bit mask should be the union of the two new
// client_state_masks.
- uint32_t new_client_state_mask_2 = buffer_node->AddNewActiveClientsBitToMask();
- EXPECT_EQ(buffer_node->GetActiveClientsBitMask(),
- new_client_state_mask_1 | new_client_state_mask_2);
+ uint32_t newClientStateMask2 = mBufferNode->addNewActiveClientsBitToMask();
+ EXPECT_EQ(mBufferNode->getActiveClientsBitMask(), newClientStateMask1 | newClientStateMask2);
}
-TEST_F(BufferNodeTest, TestAddNewActiveClientsBitToMask_32NewClients) {
- uint32_t new_client_state_mask = 0U;
- uint32_t current_mask = 0U;
- uint32_t expected_mask = 0U;
+TEST_F(BufferNodeTest, TestaddNewActiveClientsBitToMask_32NewClients) {
+ uint32_t newClientStateMask = 0U;
+ uint32_t currentMask = 0U;
+ uint32_t expectedMask = 0U;
for (int i = 0; i < BufferHubDefs::kMaxNumberOfClients; ++i) {
- new_client_state_mask = buffer_node->AddNewActiveClientsBitToMask();
- EXPECT_NE(new_client_state_mask, 0U);
- EXPECT_FALSE(new_client_state_mask & current_mask);
- expected_mask = current_mask | new_client_state_mask;
- current_mask = buffer_node->GetActiveClientsBitMask();
- EXPECT_EQ(current_mask, expected_mask);
+ newClientStateMask = mBufferNode->addNewActiveClientsBitToMask();
+ EXPECT_NE(newClientStateMask, 0U);
+ EXPECT_FALSE(newClientStateMask & currentMask);
+ expectedMask = currentMask | newClientStateMask;
+ currentMask = mBufferNode->getActiveClientsBitMask();
+ EXPECT_EQ(currentMask, expectedMask);
}
// Method should fail upon requesting for more than maximum allowable clients.
- new_client_state_mask = buffer_node->AddNewActiveClientsBitToMask();
- EXPECT_EQ(new_client_state_mask, 0U);
+ newClientStateMask = mBufferNode->addNewActiveClientsBitToMask();
+ EXPECT_EQ(newClientStateMask, 0U);
EXPECT_EQ(errno, E2BIG);
}
TEST_F(BufferNodeTest, TestRemoveActiveClientsBitFromMask) {
- buffer_node->AddNewActiveClientsBitToMask();
- uint32_t current_mask = buffer_node->GetActiveClientsBitMask();
- uint32_t new_client_state_mask = buffer_node->AddNewActiveClientsBitToMask();
- EXPECT_NE(buffer_node->GetActiveClientsBitMask(), current_mask);
+ mBufferNode->addNewActiveClientsBitToMask();
+ uint32_t currentMask = mBufferNode->getActiveClientsBitMask();
+ uint32_t newClientStateMask = mBufferNode->addNewActiveClientsBitToMask();
+ EXPECT_NE(mBufferNode->getActiveClientsBitMask(), currentMask);
- buffer_node->RemoveClientsBitFromMask(new_client_state_mask);
- EXPECT_EQ(buffer_node->GetActiveClientsBitMask(), current_mask);
+ mBufferNode->removeClientsBitFromMask(newClientStateMask);
+ EXPECT_EQ(mBufferNode->getActiveClientsBitMask(), currentMask);
// Remove the test_mask again to the active client bit mask should not modify
// the value of active clients bit mask.
- buffer_node->RemoveClientsBitFromMask(new_client_state_mask);
- EXPECT_EQ(buffer_node->GetActiveClientsBitMask(), current_mask);
+ mBufferNode->removeClientsBitFromMask(newClientStateMask);
+ EXPECT_EQ(mBufferNode->getActiveClientsBitMask(), currentMask);
}
} // namespace
diff --git a/services/gpuservice/Android.bp b/services/gpuservice/Android.bp
index 47bed65..e21d8e7 100644
--- a/services/gpuservice/Android.bp
+++ b/services/gpuservice/Android.bp
@@ -30,6 +30,8 @@
],
shared_libs: [
"libbinder",
+ "libcutils",
+ "libgraphicsenv",
"liblog",
"libutils",
"libvulkan",
@@ -59,6 +61,7 @@
],
shared_libs: [
"libbinder",
+ "libcutils",
"liblog",
"libutils",
],
diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp
index 150896c..9906dea 100644
--- a/services/gpuservice/GpuService.cpp
+++ b/services/gpuservice/GpuService.cpp
@@ -14,48 +14,19 @@
* limitations under the License.
*/
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+
#include "GpuService.h"
#include <binder/IResultReceiver.h>
#include <binder/Parcel.h>
#include <utils/String8.h>
+#include <utils/Trace.h>
+
#include <vkjson.h>
namespace android {
-class BpGpuService : public BpInterface<IGpuService> {
-public:
- explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}
-};
-
-IMPLEMENT_META_INTERFACE(GpuService, "android.ui.IGpuService");
-
-status_t BnGpuService::onTransact(uint32_t code, const Parcel& data,
- Parcel* reply, uint32_t flags) {
- status_t status;
- switch (code) {
- case SHELL_COMMAND_TRANSACTION: {
- int in = data.readFileDescriptor();
- int out = data.readFileDescriptor();
- int err = data.readFileDescriptor();
- std::vector<String16> args;
- data.readString16Vector(&args);
- sp<IBinder> unusedCallback;
- sp<IResultReceiver> resultReceiver;
- if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK)
- return status;
- if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK)
- return status;
- status = shellCommand(in, out, err, args);
- if (resultReceiver != nullptr)
- resultReceiver->send(status);
- return OK;
- }
-
- default:
- return BBinder::onTransact(code, data, reply, flags);
- }
-}
namespace {
status_t cmd_help(int out);
@@ -66,9 +37,25 @@
GpuService::GpuService() = default;
-status_t GpuService::shellCommand(int /*in*/, int out, int err,
- std::vector<String16>& args) {
- ALOGV("GpuService::shellCommand");
+void GpuService::setGpuStats(const std::string driverPackageName,
+ const std::string driverVersionName, const uint64_t driverVersionCode,
+ const std::string appPackageName) {
+ ATRACE_CALL();
+
+ std::lock_guard<std::mutex> lock(mStateLock);
+ ALOGV("Received:\n"
+ "\tdriverPackageName[%s]\n"
+ "\tdriverVersionName[%s]\n"
+ "\tdriverVersionCode[%llu]\n"
+ "\tappPackageName[%s]\n",
+ driverPackageName.c_str(), driverVersionName.c_str(),
+ (unsigned long long)driverVersionCode, appPackageName.c_str());
+}
+
+status_t GpuService::shellCommand(int /*in*/, int out, int err, std::vector<String16>& args) {
+ ATRACE_CALL();
+
+ ALOGV("shellCommand");
for (size_t i = 0, n = args.size(); i < n; i++)
ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string());
diff --git a/services/gpuservice/GpuService.h b/services/gpuservice/GpuService.h
index e2b396e..edfd364 100644
--- a/services/gpuservice/GpuService.h
+++ b/services/gpuservice/GpuService.h
@@ -17,31 +17,15 @@
#ifndef ANDROID_GPUSERVICE_H
#define ANDROID_GPUSERVICE_H
-#include <vector>
-
#include <binder/IInterface.h>
#include <cutils/compiler.h>
+#include <graphicsenv/IGpuService.h>
+
+#include <mutex>
+#include <vector>
namespace android {
-/*
- * This class defines the Binder IPC interface for GPU-related queries and
- * control.
- */
-class IGpuService : public IInterface {
-public:
- DECLARE_META_INTERFACE(GpuService);
-};
-
-class BnGpuService: public BnInterface<IGpuService> {
-protected:
- virtual status_t shellCommand(int in, int out, int err,
- std::vector<String16>& args) = 0;
-
- status_t onTransact(uint32_t code, const Parcel& data,
- Parcel* reply, uint32_t flags = 0) override;
-};
-
class GpuService : public BnGpuService {
public:
static const char* const SERVICE_NAME ANDROID_API;
@@ -49,8 +33,15 @@
GpuService() ANDROID_API;
protected:
- status_t shellCommand(int in, int out, int err,
- std::vector<String16>& args) override;
+ status_t shellCommand(int in, int out, int err, std::vector<String16>& args) override;
+
+private:
+ // IGpuService interface
+ void setGpuStats(const std::string driverPackageName, const std::string driverVersionName,
+ const uint64_t driverVersionCode, const std::string appPackageName);
+
+ // GpuStats access must be protected by mStateLock
+ std::mutex mStateLock;
};
} // namespace android
diff --git a/services/surfaceflinger/BufferQueueLayer.cpp b/services/surfaceflinger/BufferQueueLayer.cpp
index 3915757..0313c32 100644
--- a/services/surfaceflinger/BufferQueueLayer.cpp
+++ b/services/surfaceflinger/BufferQueueLayer.cpp
@@ -232,7 +232,7 @@
getTransformToDisplayInverse(), mFreezeGeometryUpdates);
const nsecs_t expectedPresentTime = mFlinger->mUseScheduler
- ? mFlinger->mScheduler->mPrimaryDispSync->expectedPresentTime()
+ ? mFlinger->mScheduler->expectedPresentTime()
: mFlinger->mPrimaryDispSync->expectedPresentTime();
// updateTexImage() below might drop the some buffers at the head of the queue if there is a
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index b95cd2e..b0506fe 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -42,6 +42,7 @@
BufferStateLayer::BufferStateLayer(const LayerCreationArgs& args) : BufferLayer(args) {
mOverrideScalingMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
+ mCurrentState.dataspace = ui::Dataspace::V0_SRGB;
}
BufferStateLayer::~BufferStateLayer() = default;
diff --git a/services/surfaceflinger/Scheduler/PhaseOffsets.cpp b/services/surfaceflinger/Scheduler/PhaseOffsets.cpp
index a0a4455..ab1f460 100644
--- a/services/surfaceflinger/Scheduler/PhaseOffsets.cpp
+++ b/services/surfaceflinger/Scheduler/PhaseOffsets.cpp
@@ -59,10 +59,10 @@
const int highFpsEarlyGlAppOffsetNs = atoi(value);
// TODO(b/122905996): Define these in device.mk.
- property_get("debug.sf.high_fps_late_app_phase_offset_ns", value, "1000000");
+ property_get("debug.sf.high_fps_late_app_phase_offset_ns", value, "2000000");
const int highFpsLateAppOffsetNs = atoi(value);
- property_get("debug.sf.high_fps_late_sf_phase_offset_ns", value, "8000000");
+ property_get("debug.sf.high_fps_late_sf_phase_offset_ns", value, "1000000");
const int highFpsLateSfOffsetNs = atoi(value);
mDefaultRefreshRateOffsets.early = {earlySfOffsetNs != -1 ? earlySfOffsetNs
@@ -83,7 +83,7 @@
: highFpsLateAppOffsetNs,
highFpsEarlyGlAppOffsetNs != -1 ? highFpsEarlyGlAppOffsetNs
: highFpsLateSfOffsetNs};
- mHighRefreshRateOffsets.late = {highFpsLateAppOffsetNs, highFpsLateSfOffsetNs};
+ mHighRefreshRateOffsets.late = {highFpsLateSfOffsetNs, highFpsLateAppOffsetNs};
}
PhaseOffsets::Offsets PhaseOffsets::getCurrentOffsets() const {
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 2f581d2..5268c8c 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -69,7 +69,7 @@
mEventControlThread = std::make_unique<impl::EventControlThread>(function);
char value[PROPERTY_VALUE_MAX];
- property_get("debug.sf.set_idle_timer_ms", value, "30");
+ property_get("debug.sf.set_idle_timer_ms", value, "0");
mSetIdleTimerMs = atoi(value);
if (mSetIdleTimerMs > 0) {
@@ -238,6 +238,10 @@
mHWVsyncAvailable = makeAvailable;
}
+nsecs_t Scheduler::expectedPresentTime() {
+ return mPrimaryDispSync->expectedPresentTime();
+}
+
void Scheduler::addFramePresentTimeForLayer(const nsecs_t framePresentTime, bool isAutoTimestamp,
const std::string layerName) {
// This is V1 logic. It calculates the average FPS based on the timestamp frequency
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index 4abf027..089d579 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -109,6 +109,7 @@
void addPresentFence(const std::shared_ptr<FenceTime>& fenceTime);
void setIgnorePresentFences(bool ignore);
void makeHWSyncAvailable(bool makeAvailable);
+ nsecs_t expectedPresentTime();
// Adds the present time for given layer to the history of present times.
void addFramePresentTimeForLayer(const nsecs_t framePresentTime, bool isAutoTimestamp,
const std::string layerName);
@@ -142,9 +143,6 @@
// Function that is called when the timer expires.
void expiredTimerCallback();
- // TODO(b/113612090): Instead of letting BufferQueueLayer to access mDispSync directly, it
- // should make request to Scheduler to compute next refresh.
- friend class BufferQueueLayer;
// If fences from sync Framework are supported.
const bool mHasSyncFramework;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 5f8de83..6e21739 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -351,10 +351,6 @@
}
ALOGV("Primary Display Orientation is set to %2d.", SurfaceFlinger::primaryDisplayOrientation);
- mPrimaryDispSync =
- getFactory().createDispSync("PrimaryDispSync", SurfaceFlinger::hasSyncFramework,
- SurfaceFlinger::dispSyncPresentTimeOffset);
-
auto surfaceFlingerConfigsServiceV1_2 = V1_2::ISurfaceFlingerConfigs::getService();
if (surfaceFlingerConfigsServiceV1_2) {
surfaceFlingerConfigsServiceV1_2->getDisplayNativePrimaries(
@@ -400,6 +396,12 @@
property_get("debug.sf.use_scheduler", value, "0");
mUseScheduler = atoi(value);
+ if (!mUseScheduler) {
+ mPrimaryDispSync =
+ getFactory().createDispSync("PrimaryDispSync", SurfaceFlinger::hasSyncFramework,
+ SurfaceFlinger::dispSyncPresentTimeOffset);
+ }
+
const auto [early, gl, late] = mPhaseOffsets->getCurrentOffsets();
mVsyncModulator.setPhaseOffsets(early, gl, late);
@@ -719,8 +721,10 @@
}
}
- mEventControlThread = getFactory().createEventControlThread(
- [this](bool enabled) { setPrimaryVsyncEnabled(enabled); });
+ if (!mUseScheduler) {
+ mEventControlThread = getFactory().createEventControlThread(
+ [this](bool enabled) { setPrimaryVsyncEnabled(enabled); });
+ }
// initialize our drawing state
mDrawingState = mCurrentState;
@@ -822,14 +826,12 @@
return NO_ERROR;
}
-status_t SurfaceFlinger::getDisplayConfigs(const sp<IBinder>& displayToken,
- Vector<DisplayInfo>* configs) {
+status_t SurfaceFlinger::getDisplayConfigsLocked(const sp<IBinder>& displayToken,
+ Vector<DisplayInfo>* configs) {
if (!displayToken || !configs) {
return BAD_VALUE;
}
- ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId);
-
const auto displayId = getPhysicalDisplayIdLocked(displayToken);
if (!displayId) {
return NAME_NOT_FOUND;
@@ -957,22 +959,19 @@
return display->getActiveConfig();
}
-status_t SurfaceFlinger::setActiveConfig(const sp<IBinder>& displayToken, int mode) {
- ATRACE_NAME("setActiveConfigSync");
- postMessageSync(new LambdaMessage(
- [&]() NO_THREAD_SAFETY_ANALYSIS { setActiveConfigInternal(displayToken, mode); }));
- return NO_ERROR;
-}
+void SurfaceFlinger::setDesiredActiveConfig(const sp<IBinder>& displayToken, int mode) {
+ ATRACE_CALL();
-void SurfaceFlinger::setActiveConfigInternal(const sp<IBinder>& displayToken, int mode) {
Vector<DisplayInfo> configs;
- getDisplayConfigs(displayToken, &configs);
+ // Lock is acquired by setRefreshRateTo.
+ getDisplayConfigsLocked(displayToken, &configs);
if (mode < 0 || mode >= static_cast<int>(configs.size())) {
ALOGE("Attempt to set active config %d for display with %zu configs", mode, configs.size());
return;
}
- const auto display = getDisplayDevice(displayToken);
+ // Lock is acquired by setRefreshRateTo.
+ const auto display = getDisplayDeviceLocked(displayToken);
if (!display) {
ALOGE("Attempt to set active config %d for invalid display token %p", mode,
displayToken.get());
@@ -988,23 +987,95 @@
return;
}
- int currentMode = display->getActiveConfig();
- if (mode == currentMode) {
- // Don't update config if we are already running in the desired mode.
+ // Don't check against the current mode yet. Worst case we set the desired
+ // config twice.
+ {
+ std::lock_guard<std::mutex> lock(mActiveConfigLock);
+ mDesiredActiveConfig = ActiveConfigInfo{mode, displayToken};
+ }
+ // This will trigger HWC refresh without resetting the idle timer.
+ repaintEverythingForHWC();
+}
+
+status_t SurfaceFlinger::setActiveConfig(const sp<IBinder>& displayToken, int mode) {
+ ATRACE_CALL();
+ postMessageSync(new LambdaMessage(
+ [&]() NO_THREAD_SAFETY_ANALYSIS { setDesiredActiveConfig(displayToken, mode); }));
+ return NO_ERROR;
+}
+
+void SurfaceFlinger::setActiveConfigInHWC() {
+ ATRACE_CALL();
+
+ const auto display = getDisplayDevice(mUpcomingActiveConfig.displayToken);
+ if (!display) {
return;
}
- if (mUseScheduler) {
- mRefreshRateStats->setConfigMode(mode);
- }
-
const auto displayId = display->getId();
LOG_ALWAYS_FATAL_IF(!displayId);
- display->setActiveConfig(mode);
- getHwComposer().setActiveConfig(*displayId, mode);
+ ATRACE_INT("ActiveConfigModeHWC", mUpcomingActiveConfig.configId);
+ getHwComposer().setActiveConfig(*displayId, mUpcomingActiveConfig.configId);
+ mSetActiveConfigState = SetActiveConfigState::NOTIFIED_HWC;
+ ATRACE_INT("SetActiveConfigState", mSetActiveConfigState);
+}
- ATRACE_INT("ActiveConfigMode", mode);
+void SurfaceFlinger::setActiveConfigInternal() {
+ ATRACE_CALL();
+
+ std::lock_guard<std::mutex> lock(mActiveConfigLock);
+ if (mUseScheduler) {
+ mRefreshRateStats->setConfigMode(mUpcomingActiveConfig.configId);
+ }
+
+ const auto display = getDisplayDeviceLocked(mUpcomingActiveConfig.displayToken);
+ display->setActiveConfig(mUpcomingActiveConfig.configId);
+
+ mSetActiveConfigState = SetActiveConfigState::NONE;
+ ATRACE_INT("SetActiveConfigState", mSetActiveConfigState);
+
resyncToHardwareVsync(true, getVsyncPeriod());
+ ATRACE_INT("ActiveConfigMode", mUpcomingActiveConfig.configId);
+}
+
+bool SurfaceFlinger::updateSetActiveConfigStateMachine() NO_THREAD_SAFETY_ANALYSIS {
+ // Store the local variable to release the lock.
+ ActiveConfigInfo desiredActiveConfig;
+ {
+ std::lock_guard<std::mutex> lock(mActiveConfigLock);
+ desiredActiveConfig = mDesiredActiveConfig;
+ }
+
+ const auto display = getDisplayDevice(desiredActiveConfig.displayToken);
+ if (display) {
+ if (mSetActiveConfigState == SetActiveConfigState::NONE &&
+ display->getActiveConfig() != desiredActiveConfig.configId) {
+ // Step 1) Desired active config was set, it is different than the
+ // config currently in use. Notify HWC.
+ mUpcomingActiveConfig = desiredActiveConfig;
+ setActiveConfigInHWC();
+ } else if (mSetActiveConfigState == SetActiveConfigState::NOTIFIED_HWC) {
+ // Step 2) HWC was notified and we received refresh from it.
+ mSetActiveConfigState = SetActiveConfigState::REFRESH_RECEIVED;
+ ATRACE_INT("SetActiveConfigState", mSetActiveConfigState);
+ repaintEverythingForHWC();
+ // We do not want to give another frame to HWC while we are transitioning.
+ return false;
+ } else if (mSetActiveConfigState == SetActiveConfigState::REFRESH_RECEIVED &&
+ !(mPreviousPresentFence != Fence::NO_FENCE &&
+ (mPreviousPresentFence->getStatus() == Fence::Status::Unsignaled))) {
+ // Step 3) We received the present fence from the HWC, so we assume it
+ // successfully updated the config, hence we update SF.
+ setActiveConfigInternal();
+ // If the config changed again while we were transitioning, restart the
+ // process.
+ if (desiredActiveConfig != mUpcomingActiveConfig) {
+ mUpcomingActiveConfig = desiredActiveConfig;
+ setActiveConfigInHWC(); // sets the state to NOTIFY_HWC
+ }
+ }
+ }
+ return true;
}
status_t SurfaceFlinger::getDisplayColorModes(const sp<IBinder>& displayToken,
@@ -1332,6 +1403,7 @@
}
void SurfaceFlinger::enableHardwareVsync() {
+ assert(!mUseScheduler);
Mutex::Autolock _l(mHWVsyncLock);
if (!mPrimaryHWVsyncEnabled && mHWVsyncAvailable) {
mPrimaryDispSync->beginResync();
@@ -1374,6 +1446,7 @@
}
void SurfaceFlinger::disableHardwareVsync(bool makeUnavailable) {
+ assert(!mUseScheduler);
Mutex::Autolock _l(mHWVsyncLock);
if (mPrimaryHWVsyncEnabled) {
mEventControlThread->setVsyncEnabled(false);
@@ -1482,8 +1555,7 @@
// TODO(b/113612090): There should be a better way at determining which config
// has the right refresh rate.
if (std::abs(fps - newFps) <= 1) {
- setActiveConfigInternal(getInternalDisplayTokenLocked(), i);
- ATRACE_INT("FPS", newFps);
+ setDesiredActiveConfig(getInternalDisplayTokenLocked(), i);
}
}
}
@@ -1627,14 +1699,16 @@
ATRACE_CALL();
switch (what) {
case MessageQueue::INVALIDATE: {
+ if (!updateSetActiveConfigStateMachine()) {
+ break;
+ }
+
if (mUseScheduler) {
// This call is made each time SF wakes up and creates a new frame.
mScheduler->incrementFrameCounter();
}
- bool frameMissed = !mHadClientComposition &&
- mPreviousPresentFence != Fence::NO_FENCE &&
- (mPreviousPresentFence->getSignalTime() ==
- Fence::SIGNAL_TIME_PENDING);
+ bool frameMissed = !mHadClientComposition && mPreviousPresentFence != Fence::NO_FENCE &&
+ (mPreviousPresentFence->getStatus() == Fence::Status::Unsignaled);
mFrameMissedCount += frameMissed;
ATRACE_INT("FrameMissed", static_cast<int>(frameMissed));
if (frameMissed) {
@@ -3041,7 +3115,12 @@
void SurfaceFlinger::latchAndReleaseBuffer(const sp<Layer>& layer) {
if (layer->hasReadyFrame()) {
- const nsecs_t expectedPresentTime = mPrimaryDispSync->expectedPresentTime();
+ nsecs_t expectedPresentTime;
+ if (mUseScheduler) {
+ expectedPresentTime = mScheduler->expectedPresentTime();
+ } else {
+ expectedPresentTime = mPrimaryDispSync->expectedPresentTime();
+ }
if (layer->shouldPresentNow(expectedPresentTime)) {
bool ignored = false;
layer->latchBuffer(ignored, systemTime(), Fence::NO_FENCE);
@@ -3273,7 +3352,12 @@
mDrawingState.traverseInZOrder([&](Layer* layer) {
if (layer->hasReadyFrame()) {
frameQueued = true;
- const nsecs_t expectedPresentTime = mPrimaryDispSync->expectedPresentTime();
+ nsecs_t expectedPresentTime;
+ if (mUseScheduler) {
+ expectedPresentTime = mScheduler->expectedPresentTime();
+ } else {
+ expectedPresentTime = mPrimaryDispSync->expectedPresentTime();
+ }
if (layer->shouldPresentNow(expectedPresentTime)) {
mLayersWithQueuedFrames.push_back(layer);
} else {
@@ -3614,7 +3698,12 @@
bool SurfaceFlinger::transactionIsReadyToBeApplied(int64_t desiredPresentTime,
const Vector<ComposerState>& states) {
- const nsecs_t expectedPresentTime = mPrimaryDispSync->expectedPresentTime();
+ nsecs_t expectedPresentTime;
+ if (mUseScheduler) {
+ expectedPresentTime = mScheduler->expectedPresentTime();
+ } else {
+ expectedPresentTime = mPrimaryDispSync->expectedPresentTime();
+ }
// Do not present if the desiredPresentTime has not passed unless it is more than one second
// in the future. We ignore timestamps more than 1 second in the future for stability reasons.
if (desiredPresentTime >= 0 && desiredPresentTime >= expectedPresentTime &&
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 6546973..a748bc5 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -437,7 +437,12 @@
const Rect& sourceCrop, float frameScale, bool childrenOnly) override;
status_t getDisplayStats(const sp<IBinder>& displayToken, DisplayStatInfo* stats) override;
status_t getDisplayConfigs(const sp<IBinder>& displayToken,
- Vector<DisplayInfo>* configs) override;
+ Vector<DisplayInfo>* configs) override {
+ Mutex::Autolock _l(mStateLock);
+ return getDisplayConfigsLocked(displayToken, configs);
+ }
+ status_t getDisplayConfigsLocked(const sp<IBinder>& displayToken, Vector<DisplayInfo>* configs)
+ REQUIRES(mStateLock);
int getActiveConfig(const sp<IBinder>& displayToken) override;
status_t getDisplayColorModes(const sp<IBinder>& displayToken,
Vector<ui::ColorMode>* configs) override;
@@ -503,8 +508,18 @@
// called on the main thread in response to initializeDisplays()
void onInitializeDisplays() REQUIRES(mStateLock);
- // called on the main thread in response to setActiveConfig()
- void setActiveConfigInternal(const sp<IBinder>& displayToken, int mode) REQUIRES(mStateLock);
+ // Sets the desired active config bit. It obtains the lock, and sets mDesiredActiveConfig.
+ void setDesiredActiveConfig(const sp<IBinder>& displayToken, int mode) REQUIRES(mStateLock);
+ // Calls setActiveConfig in HWC.
+ void setActiveConfigInHWC();
+ // Once HWC has returned the present fence, this sets the active config and a new refresh
+ // rate in SF. It also triggers HWC vsync.
+ void setActiveConfigInternal() REQUIRES(mStateLock);
+ // Active config is updated on INVALIDATE call in a state machine-like manner. When the
+ // desired config was set, HWC needs to update the pannel on the next refresh, and when
+ // we receive the fence back, we know that the process was complete. It returns whether
+ // the invalidate process should continue.
+ bool updateSetActiveConfigStateMachine();
// called on the main thread in response to setPowerMode()
void setPowerModeInternal(const sp<DisplayDevice>& display, int mode) REQUIRES(mStateLock);
@@ -1084,6 +1099,34 @@
sp<Scheduler::ConnectionHandle> mSfConnectionHandle;
std::unique_ptr<scheduler::RefreshRateStats> mRefreshRateStats;
+ // The following structs are used for configuring active config state at a desired time,
+ // which is once per vsync at invalidate time.
+ enum SetActiveConfigState {
+ NONE, // not in progress
+ NOTIFIED_HWC, // call to HWC has been made
+ REFRESH_RECEIVED // onRefresh was received from HWC
+ };
+ std::atomic<SetActiveConfigState> mSetActiveConfigState = SetActiveConfigState::NONE;
+
+ struct ActiveConfigInfo {
+ int configId;
+ sp<IBinder> displayToken;
+
+ bool operator!=(const ActiveConfigInfo& other) const {
+ if (configId != other.configId) {
+ return true;
+ }
+ return (displayToken != other.displayToken);
+ }
+ };
+ std::mutex mActiveConfigLock;
+ // This bit is set once we start setting the config. We read from this bit during the
+ // process. If at the end, this bit is different than mDesiredActiveConfig, we restart
+ // the process.
+ ActiveConfigInfo mUpcomingActiveConfig; // Always read and written on the main thread.
+ // This bit can be set at any point in time when the system wants the new config.
+ ActiveConfigInfo mDesiredActiveConfig GUARDED_BY(mActiveConfigLock);
+
/* ------------------------------------------------------------------------ */
sp<IInputFlinger> mInputFlinger;
diff --git a/services/vr/bufferhubd/producer_channel.cpp b/services/vr/bufferhubd/producer_channel.cpp
index 164d9e6..f3e54a0 100644
--- a/services/vr/bufferhubd/producer_channel.cpp
+++ b/services/vr/bufferhubd/producer_channel.cpp
@@ -253,7 +253,7 @@
uint32_t current_active_clients_bit_mask =
active_clients_bit_mask_->load(std::memory_order_acquire);
uint32_t consumer_state_mask =
- BufferHubDefs::FindNextAvailableClientStateMask(
+ BufferHubDefs::findNextAvailableClientStateMask(
current_active_clients_bit_mask | orphaned_consumer_bit_mask_);
if (consumer_state_mask == 0U) {
ALOGE("%s: reached the maximum mumber of consumers per producer: 63.",
@@ -279,7 +279,7 @@
"condition.",
__FUNCTION__, updated_active_clients_bit_mask,
current_active_clients_bit_mask);
- consumer_state_mask = BufferHubDefs::FindNextAvailableClientStateMask(
+ consumer_state_mask = BufferHubDefs::findNextAvailableClientStateMask(
current_active_clients_bit_mask | orphaned_consumer_bit_mask_);
if (consumer_state_mask == 0U) {
ALOGE("%s: reached the maximum mumber of consumers per producer: %d.",
@@ -337,13 +337,13 @@
// consumer to a buffer that is available to producer (a.k.a a fully-released
// buffer) or a gained buffer.
if (current_buffer_state == 0U ||
- BufferHubDefs::AnyClientGained(current_buffer_state)) {
+ BufferHubDefs::isAnyClientGained(current_buffer_state)) {
return {status.take()};
}
// Signal the new consumer when adding it to a posted producer.
bool update_buffer_state = true;
- if (!BufferHubDefs::IsClientPosted(current_buffer_state,
+ if (!BufferHubDefs::isClientPosted(current_buffer_state,
consumer_state_mask)) {
uint32_t updated_buffer_state =
current_buffer_state ^
@@ -360,7 +360,7 @@
"released.",
__FUNCTION__, current_buffer_state, updated_buffer_state);
if (current_buffer_state == 0U ||
- BufferHubDefs::AnyClientGained(current_buffer_state)) {
+ BufferHubDefs::isAnyClientGained(current_buffer_state)) {
ALOGI("%s: buffer is gained or fully released, state=%" PRIx32 ".",
__FUNCTION__, current_buffer_state);
update_buffer_state = false;
@@ -371,7 +371,7 @@
(consumer_state_mask & BufferHubDefs::kHighBitsMask);
}
}
- if (update_buffer_state || BufferHubDefs::IsClientPosted(
+ if (update_buffer_state || BufferHubDefs::isClientPosted(
buffer_state_->load(std::memory_order_acquire),
consumer_state_mask)) {
consumer->OnProducerPosted();
@@ -457,7 +457,7 @@
buffer_id());
uint32_t buffer_state = buffer_state_->load(std::memory_order_acquire);
- if (!BufferHubDefs::IsClientGained(
+ if (!BufferHubDefs::isClientGained(
buffer_state, BufferHubDefs::kFirstClientStateMask)) {
// Can only detach a ProducerBuffer when it's in gained state.
ALOGW(
@@ -616,9 +616,9 @@
const uint32_t current_buffer_state =
buffer_state_->load(std::memory_order_acquire);
- if (BufferHubDefs::IsClientPosted(current_buffer_state,
+ if (BufferHubDefs::isClientPosted(current_buffer_state,
consumer_state_mask) ||
- BufferHubDefs::IsClientAcquired(current_buffer_state,
+ BufferHubDefs::isClientAcquired(current_buffer_state,
consumer_state_mask)) {
// The consumer client is being destoryed without releasing. This could
// happen in corner cases when the consumer crashes. Here we mark it
@@ -627,9 +627,9 @@
return;
}
- if (BufferHubDefs::IsClientReleased(current_buffer_state,
+ if (BufferHubDefs::isClientReleased(current_buffer_state,
consumer_state_mask) ||
- BufferHubDefs::AnyClientGained(current_buffer_state)) {
+ BufferHubDefs::isAnyClientGained(current_buffer_state)) {
// The consumer is being close while it is suppose to signal a release
// fence. Signal the dummy fence here.
if (fence_state_->load(std::memory_order_acquire) & consumer_state_mask) {
diff --git a/services/vr/bufferhubd/producer_queue_channel.cpp b/services/vr/bufferhubd/producer_queue_channel.cpp
index 6b33f50..004dc7c 100644
--- a/services/vr/bufferhubd/producer_queue_channel.cpp
+++ b/services/vr/bufferhubd/producer_queue_channel.cpp
@@ -323,7 +323,7 @@
// memory to indicate which client is the last producer of the buffer.
// Currently, the first client is the only producer to the buffer.
// Thus, it checks whether the first client gains the buffer below.
- if (!BufferHubDefs::IsClientGained(buffer_state,
+ if (!BufferHubDefs::isClientGained(buffer_state,
BufferHubDefs::kFirstClientBitMask)) {
// Rejects the request if the requested buffer is not in Gained state.
ALOGE(
diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp
index 421f727..3a8e34e 100644
--- a/vulkan/libvulkan/driver.cpp
+++ b/vulkan/libvulkan/driver.cpp
@@ -254,6 +254,8 @@
return true;
}
+ android::GraphicsEnv::getInstance().sendGpuStats();
+
hwvulkan_device_t* device;
ATRACE_BEGIN("hwvulkan module open");
result =