Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cfbe0745 authored by Fan Xu's avatar Fan Xu
Browse files

Move MetadataHeader to libui

To remove BufferHubMetadata off pdx dependency.

Note that the __attribute__(packed) is removed as part of this CL, as
it's not really needed and is triggering clang warnings.

Test: build passed. Not test needed as no behavior changes.
Bug: 118893702
Change-Id: Ifae94a143a2bedef68a653c57f089b95d166e6d7
parent faba0dc1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@

#include <android-base/unique_fd.h>
#include <ui/BufferHubBuffer.h>
#include <ui/BufferHubDefs.h>

using android::base::unique_fd;
using android::dvr::BufferTraits;
@@ -69,7 +70,6 @@ using dvr::BufferHubDefs::IsClientGained;
using dvr::BufferHubDefs::IsClientPosted;
using dvr::BufferHubDefs::IsClientReleased;
using dvr::BufferHubDefs::kHighBitsMask;
using dvr::BufferHubDefs::kMetadataHeaderSize;

} // namespace

@@ -161,7 +161,7 @@ int BufferHubBuffer::ImportGraphicBuffer() {
    }

    size_t metadataSize = static_cast<size_t>(bufferTraits.metadata_size());
    if (metadataSize < kMetadataHeaderSize) {
    if (metadataSize < BufferHubDefs::kMetadataHeaderSize) {
        ALOGE("BufferHubBuffer::ImportGraphicBuffer: metadata too small: %zu", metadataSize);
        return -EINVAL;
    }
+3 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include <errno.h>
#include <sys/mman.h>
#include <limits>

#include <cutils/ashmem.h>
#include <log/log.h>
@@ -29,8 +30,8 @@ static const int kAshmemProt = PROT_READ | PROT_WRITE;

} // namespace

using dvr::BufferHubDefs::kMetadataHeaderSize;
using dvr::BufferHubDefs::MetadataHeader;
using BufferHubDefs::kMetadataHeaderSize;
using BufferHubDefs::MetadataHeader;

/* static */
BufferHubMetadata BufferHubMetadata::Create(size_t userMetadataSize) {
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

#ifndef ANDROID_BUFFER_HUB_DEFS_H_
#define ANDROID_BUFFER_HUB_DEFS_H_

#include <atomic>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpacked"
// TODO(b/118893702): remove dependency once DvrNativeBufferMetadata moved out of libdvr
#include <dvr/dvr_api.h>
#pragma clang diagnostic pop

namespace android {

namespace BufferHubDefs {

struct __attribute__((aligned(8))) MetadataHeader {
    // Internal data format, which can be updated as long as the size, padding and field alignment
    // of the struct is consistent within the same ABI. As this part is subject for future updates,
    // it's not stable cross Android version, so don't have it visible from outside of the Android
    // platform (include Apps and vendor HAL).

    // Every client takes up one bit from the higher 32 bits and one bit from the lower 32 bits in
    // buffer_state.
    std::atomic<uint64_t> buffer_state;

    // Every client takes up one bit in fence_state. Only the lower 32 bits are valid. The upper 32
    // bits are there for easier manipulation, but the value should be ignored.
    std::atomic<uint64_t> fence_state;

    // Every client takes up one bit from the higher 32 bits and one bit from the lower 32 bits in
    // active_clients_bit_mask.
    std::atomic<uint64_t> active_clients_bit_mask;

    // The index of the buffer queue where the buffer belongs to.
    uint64_t queue_index;

    // Public data format, which should be updated with caution. See more details in dvr_api.h
    DvrNativeBufferMetadata metadata;
};

static_assert(sizeof(MetadataHeader) == 136, "Unexpected MetadataHeader size");
static constexpr size_t kMetadataHeaderSize = sizeof(MetadataHeader);

} // namespace BufferHubDefs

} // namespace android

#endif // ANDROID_BUFFER_HUB_DEFS_H_
+5 −25
Original line number Diff line number Diff line
@@ -17,26 +17,8 @@
#ifndef ANDROID_BUFFER_HUB_METADATA_H_
#define ANDROID_BUFFER_HUB_METADATA_H_

// We would eliminate the clang warnings introduced by libdpx.
// TODO(b/112338294): Remove those once BufferHub moved to use Binder
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
#pragma clang diagnostic ignored "-Wdouble-promotion"
#pragma clang diagnostic ignored "-Wgnu-case-range"
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#pragma clang diagnostic ignored "-Winconsistent-missing-destructor-override"
#pragma clang diagnostic ignored "-Wnested-anon-types"
#pragma clang diagnostic ignored "-Wpacked"
#pragma clang diagnostic ignored "-Wshadow"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wswitch-enum"
#pragma clang diagnostic ignored "-Wundefined-func-template"
#pragma clang diagnostic ignored "-Wunused-template"
#pragma clang diagnostic ignored "-Wweak-vtables"
#include <private/dvr/buffer_hub_defs.h>
#pragma clang diagnostic pop

#include <android-base/unique_fd.h>
#include <ui/BufferHubDefs.h>

namespace android {

@@ -84,23 +66,21 @@ public:
    bool IsValid() const { return mAshmemFd.get() != -1 && mMetadataHeader != nullptr; }

    size_t user_metadata_size() const { return mUserMetadataSize; }
    size_t metadata_size() const {
        return mUserMetadataSize + dvr::BufferHubDefs::kMetadataHeaderSize;
    }
    size_t metadata_size() const { return mUserMetadataSize + BufferHubDefs::kMetadataHeaderSize; }

    const unique_fd& ashmem_fd() const { return mAshmemFd; }
    dvr::BufferHubDefs::MetadataHeader* metadata_header() { return mMetadataHeader; }
    BufferHubDefs::MetadataHeader* metadata_header() { return mMetadataHeader; }

private:
    BufferHubMetadata(size_t userMetadataSize, unique_fd ashmemFd,
                      dvr::BufferHubDefs::MetadataHeader* metadataHeader);
                      BufferHubDefs::MetadataHeader* metadataHeader);

    BufferHubMetadata(const BufferHubMetadata&) = delete;
    void operator=(const BufferHubMetadata&) = delete;

    size_t mUserMetadataSize = 0;
    unique_fd mAshmemFd;
    dvr::BufferHubDefs::MetadataHeader* mMetadataHeader = nullptr;
    BufferHubDefs::MetadataHeader* mMetadataHeader = nullptr;
};

} // namespace android
+5 −2
Original line number Diff line number Diff line
@@ -73,10 +73,13 @@ cc_test {

cc_test {
    name: "BufferHubMetadata_test",
    header_libs: ["libbufferhub_headers", "libdvr_headers"],
    header_libs: [
        "libbufferhub_headers",
        "libdvr_headers",
        "libpdx_headers",
    ],
    shared_libs: [
        "libbase",
        "libpdx_default_transport",
        "libui",
        "libutils",
    ],
Loading