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

Commit 8f51ec64 authored by Jiwen 'Steve' Cai's avatar Jiwen 'Steve' Cai
Browse files

Move detached buffer to libui

Move it into libui early so that new modifications towards it can be
coded in the libui style

This CL only moves the file and updates Android.bp with proper
dependencies. Will re-format the coding style in a follow up CL. The
reason behind this is to keep this CL small enough so that the "git
mv" operation will be considered as an renaming rather than a complete
rewrite.

Note that DetachedBuffer is not exposed to VNDK, so that we won't
need to worry about ABI compatibility. Also, it temporarily introduces
some clang warning exceptions, we should be able to remove them very
soon once pdx to binder refactor is done for detached buffer.

Bug: 112010261
Test: atest BufferHubMetadata_test
Change-Id: I63659b9a9b7cb56f30fc2ae8cc5b87977d79b59c
parent 89e2fdc2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@
#include <gui/BufferHubProducer.h>
#include <inttypes.h>
#include <log/log.h>
#include <private/dvr/detached_buffer.h>
#include <system/window.h>
#include <ui/BufferHubBuffer.h>
#include <ui/DetachedBufferHandle.h>

namespace android {
+22 −0
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ cc_library_shared {

    srcs: [
        "ColorSpace.cpp",
        "BufferHubBuffer.cpp",
        "BufferHubMetadata.cpp",
        "DebugUtils.cpp",
        "Fence.cpp",
        "FenceTime.cpp",
@@ -91,6 +93,7 @@ cc_library_shared {
        "libutils",
        "libutilscallstack",
        "liblog",
        "libpdx_default_transport",  // TODO(b/112338294): Remove this once BufferHub moved to use Binder.
    ],

    export_shared_lib_headers: [
@@ -103,8 +106,27 @@ cc_library_shared {
        "libmath",
    ],

    // bufferhub is not used when building libgui for vendors
    target: {
        vendor: {
            exclude_srcs: [
                "BufferHubBuffer.cpp",
                "BufferHubMetadata.cpp",
            ],
            exclude_header_libs: [
                "libbufferhub_headers",
                "libdvr_headers",
            ],
            exclude_shared_libs: [
                "libpdx_default_transport",
            ],
        },
    },

    header_libs: [
        "libbase_headers",
        "libbufferhub_headers",
        "libdvr_headers",
        "libnativebase_headers",
        "libhardware_headers",
        "libui_headers",
+50 −17
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.
 */

// 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 <pdx/default_transport/client_channel.h>
#include <pdx/default_transport/client_channel_factory.h>
#include <pdx/file_handle.h>
#include <private/dvr/bufferhub_rpc.h>
#include <private/dvr/detached_buffer.h>
#pragma clang diagnostic pop

#include <ui/BufferHubBuffer.h>
#include <ui/DetachedBufferHandle.h>

#include <poll.h>

using android::dvr::BufferHubMetadata;
using android::dvr::BufferTraits;
using android::dvr::DetachedBufferRPC;
using android::dvr::NativeHandleWrapper;
using android::pdx::LocalChannelHandle;
using android::pdx::LocalHandle;
using android::pdx::Status;
@@ -14,7 +52,6 @@ using android::pdx::default_transport::ClientChannel;
using android::pdx::default_transport::ClientChannelFactory;

namespace android {
namespace dvr {

namespace {

@@ -30,6 +67,8 @@ BufferHubClient::BufferHubClient()
BufferHubClient::BufferHubClient(LocalChannelHandle channel_handle)
    : Client(ClientChannel::Create(std::move(channel_handle))) {}

BufferHubClient::~BufferHubClient() {}

bool BufferHubClient::IsValid() const {
  return IsConnected() && GetChannelHandle().valid();
}
@@ -46,9 +85,8 @@ DetachedBuffer::DetachedBuffer(uint32_t width, uint32_t height,
                               uint32_t layer_count, uint32_t format,
                               uint64_t usage, size_t user_metadata_size) {
  ATRACE_NAME("DetachedBuffer::DetachedBuffer");
  ALOGD_IF(TRACE,
           "DetachedBuffer::DetachedBuffer: width=%u height=%u layer_count=%u, "
           "format=%u usage=%" PRIx64 " user_metadata_size=%zu",
  ALOGD("DetachedBuffer::DetachedBuffer: width=%u height=%u layer_count=%u, format=%u "
        "usage=%" PRIx64 " user_metadata_size=%zu",
        width, height, layer_count, format, usage, user_metadata_size);

  auto status = client_.InvokeRemoteMethod<DetachedBufferRPC::Create>(
@@ -113,8 +151,8 @@ int DetachedBuffer::ImportGraphicBuffer() {
    return -ENOMEM;
  }

  size_t metadata_buf_size = buffer_traits.metadata_size();
  if (metadata_buf_size < BufferHubDefs::kMetadataHeaderSize) {
  size_t metadata_buf_size = static_cast<size_t>(buffer_traits.metadata_size());
  if (metadata_buf_size < dvr::BufferHubDefs::kMetadataHeaderSize) {
    ALOGE("DetachedBuffer::ImportGraphicBuffer: metadata too small: %zu",
          metadata_buf_size);
    return -EINVAL;
@@ -129,12 +167,8 @@ int DetachedBuffer::ImportGraphicBuffer() {
  buffer_state_bit_ = buffer_traits.buffer_state_bit();

  // TODO(b/112012161) Set up shared fences.
  ALOGD_IF(TRACE,
           "DetachedBuffer::ImportGraphicBuffer: id=%d, buffer_state=%" PRIx64
           ".",
           id(),
           metadata_.metadata_header()->buffer_state.load(
               std::memory_order_acquire));
  ALOGD("DetachedBuffer::ImportGraphicBuffer: id=%d, buffer_state=%" PRIx64 ".", id(),
        metadata_.metadata_header()->buffer_state.load(std::memory_order_acquire));
  return 0;
}

@@ -150,7 +184,7 @@ Status<LocalChannelHandle> DetachedBuffer::Promote() {
  return {};

  ATRACE_NAME("DetachedBuffer::Promote");
  ALOGD_IF(TRACE, "DetachedBuffer::Promote: id=%d.", id_);
  ALOGD("DetachedBuffer::Promote: id=%d.", id_);

  auto status_or_handle =
      client_.InvokeRemoteMethod<DetachedBufferRPC::Promote>();
@@ -166,7 +200,7 @@ Status<LocalChannelHandle> DetachedBuffer::Promote() {

Status<LocalChannelHandle> DetachedBuffer::Duplicate() {
  ATRACE_NAME("DetachedBuffer::Duplicate");
  ALOGD_IF(TRACE, "DetachedBuffer::Duplicate: id=%d.", id_);
  ALOGD("DetachedBuffer::Duplicate: id=%d.", id_);

  auto status_or_handle =
      client_.InvokeRemoteMethod<DetachedBufferRPC::Duplicate>();
@@ -178,5 +212,4 @@ Status<LocalChannelHandle> DetachedBuffer::Duplicate() {
  return status_or_handle;
}

}  // namespace dvr
}  // namespace android
+2 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@

#include <cutils/ashmem.h>
#include <log/log.h>
#include <private/dvr/buffer_hub_metadata.h>
#include <ui/BufferHubMetadata.h>

namespace android {
namespace dvr {
@@ -71,7 +71,7 @@ BufferHubMetadata BufferHubMetadata::Import(pdx::LocalHandle ashmem_handle) {
    return {};
  }

  size_t metadata_size = ashmem_get_size_region(ashmem_handle.Get());
  size_t metadata_size = static_cast<size_t>(ashmem_get_size_region(ashmem_handle.Get()));
  size_t user_metadata_size = metadata_size - kMetadataHeaderSize;

  // Note that here the buffer state is mapped from shared memory as an atomic
+24 −6
Original line number Diff line number Diff line
#ifndef ANDROID_DVR_DETACHED_BUFFER_H_
#define ANDROID_DVR_DETACHED_BUFFER_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 <pdx/client.h>
#include <private/dvr/buffer_hub_defs.h>
#include <private/dvr/buffer_hub_metadata.h>
#include <private/dvr/ion_buffer.h>
#include <private/dvr/native_handle_wrapper.h>
#include <pdx/client.h>
#pragma clang diagnostic pop

#include <ui/BufferHubMetadata.h>

namespace android {
namespace dvr {

class BufferHubClient : public pdx::Client {
 public:
  BufferHubClient();
  virtual ~BufferHubClient();
  explicit BufferHubClient(pdx::LocalChannelHandle channel_handle);

  bool IsValid() const;
@@ -107,17 +126,16 @@ class DetachedBuffer {
  uint64_t buffer_state_bit_;

  // Wrapps the gralloc buffer handle of this buffer.
  NativeHandleWrapper<pdx::LocalHandle> buffer_handle_;
  dvr::NativeHandleWrapper<pdx::LocalHandle> buffer_handle_;

  // An ashmem-based metadata object. The same shared memory are mapped to the
  // bufferhubd daemon and all buffer clients.
  BufferHubMetadata metadata_;
  dvr::BufferHubMetadata metadata_;

  // PDX backend.
  BufferHubClient client_;
};

}  // namespace dvr
}  // namespace android

#endif  // ANDROID_DVR_DETACHED_BUFFER_H_
Loading