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

Commit ff675b71 authored by Jiwen 'Steve' Cai's avatar Jiwen 'Steve' Cai
Browse files

Format BufferHub{Buffer,Metadata}.{h,cpp} to match libui style

1/ Run clang-format
2/ Rename variables to use camel case
3/ 100 column per line
4/ Rename DetachedBuffer to BufferHubBuffer

Bug: 68273829
Bug: 112010261
Bug: 112940221
Test: BufferHubMetadata_test, buffer_hub-test
Change-Id: Iaf0dbbe797daf8b61864dc2e3ea1693703ef9d7f
parent 8f51ec64
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -400,14 +400,14 @@ status_t BufferHubProducer::attachBuffer(int* out_slot, const sp<GraphicBuffer>&
        ALOGE("attachBuffer: DetachedBufferHandle cannot be NULL.");
        return BAD_VALUE;
    }
    auto detached_buffer = DetachedBuffer::Import(std::move(detached_handle->handle()));
    auto detached_buffer = BufferHubBuffer::Import(std::move(detached_handle->handle()));
    if (detached_buffer == nullptr) {
        ALOGE("attachBuffer: DetachedBuffer cannot be NULL.");
        ALOGE("attachBuffer: BufferHubBuffer cannot be NULL.");
        return BAD_VALUE;
    }
    auto status_or_handle = detached_buffer->Promote();
    if (!status_or_handle.ok()) {
        ALOGE("attachBuffer: Failed to promote a DetachedBuffer into a BufferProducer, error=%d.",
        ALOGE("attachBuffer: Failed to promote a BufferHubBuffer into a BufferProducer, error=%d.",
              status_or_handle.error());
        return BAD_VALUE;
    }
+124 −128
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ using android::dvr::BufferHubMetadata;
using android::dvr::BufferTraits;
using android::dvr::DetachedBufferRPC;
using android::dvr::NativeHandleWrapper;

// TODO(b/112338294): Remove PDX dependencies from libui.
using android::pdx::LocalChannelHandle;
using android::pdx::LocalHandle;
using android::pdx::Status;
@@ -61,11 +63,10 @@ static constexpr char kBufferHubClientPath[] = "system/buffer_hub/client";

} // namespace

BufferHubClient::BufferHubClient()
    : Client(ClientChannelFactory::Create(kBufferHubClientPath)) {}
BufferHubClient::BufferHubClient() : Client(ClientChannelFactory::Create(kBufferHubClientPath)) {}

BufferHubClient::BufferHubClient(LocalChannelHandle channel_handle)
    : Client(ClientChannel::Create(std::move(channel_handle))) {}
BufferHubClient::BufferHubClient(LocalChannelHandle mChannelHandle)
      : Client(ClientChannel::Create(std::move(mChannelHandle))) {}

BufferHubClient::~BufferHubClient() {}

@@ -81,135 +82,130 @@ LocalChannelHandle BufferHubClient::TakeChannelHandle() {
    }
}

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("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);
BufferHubBuffer::BufferHubBuffer(uint32_t width, uint32_t height, uint32_t layerCount,
                                 uint32_t format, uint64_t usage, size_t mUserMetadataSize) {
    ATRACE_CALL();
    ALOGD("BufferHubBuffer::BufferHubBuffer: width=%u height=%u layerCount=%u, format=%u "
          "usage=%" PRIx64 " mUserMetadataSize=%zu",
          width, height, layerCount, format, usage, mUserMetadataSize);

  auto status = client_.InvokeRemoteMethod<DetachedBufferRPC::Create>(
      width, height, layer_count, format, usage, user_metadata_size);
    auto status =
            mClient.InvokeRemoteMethod<DetachedBufferRPC::Create>(width, height, layerCount, format,
                                                                  usage, mUserMetadataSize);
    if (!status) {
    ALOGE(
        "DetachedBuffer::DetachedBuffer: Failed to create detached buffer: %s",
        ALOGE("BufferHubBuffer::BufferHubBuffer: Failed to create detached buffer: %s",
              status.GetErrorMessage().c_str());
    client_.Close(-status.error());
        mClient.Close(-status.error());
    }

    const int ret = ImportGraphicBuffer();
    if (ret < 0) {
    ALOGE("DetachedBuffer::DetachedBuffer: Failed to import buffer: %s",
          strerror(-ret));
    client_.Close(ret);
        ALOGE("BufferHubBuffer::BufferHubBuffer: Failed to import buffer: %s", strerror(-ret));
        mClient.Close(ret);
    }
}

DetachedBuffer::DetachedBuffer(LocalChannelHandle channel_handle)
    : client_(std::move(channel_handle)) {
BufferHubBuffer::BufferHubBuffer(LocalChannelHandle mChannelHandle)
      : mClient(std::move(mChannelHandle)) {
    const int ret = ImportGraphicBuffer();
    if (ret < 0) {
    ALOGE("DetachedBuffer::DetachedBuffer: Failed to import buffer: %s",
          strerror(-ret));
    client_.Close(ret);
        ALOGE("BufferHubBuffer::BufferHubBuffer: Failed to import buffer: %s", strerror(-ret));
        mClient.Close(ret);
    }
}

int DetachedBuffer::ImportGraphicBuffer() {
  ATRACE_NAME("DetachedBuffer::ImportGraphicBuffer");
int BufferHubBuffer::ImportGraphicBuffer() {
    ATRACE_CALL();

  auto status = client_.InvokeRemoteMethod<DetachedBufferRPC::Import>();
    auto status = mClient.InvokeRemoteMethod<DetachedBufferRPC::Import>();
    if (!status) {
    ALOGE("DetachedBuffer::DetachedBuffer: Failed to import GraphicBuffer: %s",
        ALOGE("BufferHubBuffer::BufferHubBuffer: Failed to import GraphicBuffer: %s",
              status.GetErrorMessage().c_str());
        return -status.error();
    }

  BufferTraits<LocalHandle> buffer_traits = status.take();
  if (buffer_traits.id() < 0) {
    ALOGE("DetachedBuffer::DetachedBuffer: Received an invalid id!");
    BufferTraits<LocalHandle> bufferTraits = status.take();
    if (bufferTraits.id() < 0) {
        ALOGE("BufferHubBuffer::BufferHubBuffer: Received an invalid id!");
        return -EIO;
    }

  // Stash the buffer id to replace the value in id_.
  const int buffer_id = buffer_traits.id();
    // Stash the buffer id to replace the value in mId.
    const int bufferId = bufferTraits.id();

    // Import the metadata.
  metadata_ = BufferHubMetadata::Import(buffer_traits.take_metadata_handle());
    mMetadata = BufferHubMetadata::Import(bufferTraits.take_metadata_handle());

  if (!metadata_.IsValid()) {
    ALOGE("DetachedBuffer::ImportGraphicBuffer: invalid metadata.");
    if (!mMetadata.IsValid()) {
        ALOGE("BufferHubBuffer::ImportGraphicBuffer: invalid metadata.");
        return -ENOMEM;
    }

  if (metadata_.metadata_size() != buffer_traits.metadata_size()) {
    ALOGE(
        "DetachedBuffer::ImportGraphicBuffer: metadata buffer too small: "
    if (mMetadata.metadata_size() != bufferTraits.metadata_size()) {
        ALOGE("BufferHubBuffer::ImportGraphicBuffer: metadata buffer too small: "
              "%zu, expected: %" PRIu64 ".",
        metadata_.metadata_size(), buffer_traits.metadata_size());
              mMetadata.metadata_size(), bufferTraits.metadata_size());
        return -ENOMEM;
    }

  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);
    size_t metadataSize = static_cast<size_t>(bufferTraits.metadata_size());
    if (metadataSize < dvr::BufferHubDefs::kMetadataHeaderSize) {
        ALOGE("BufferHubBuffer::ImportGraphicBuffer: metadata too small: %zu", metadataSize);
        return -EINVAL;
    }

    // Import the buffer: We only need to hold on the native_handle_t here so that
    // GraphicBuffer instance can be created in future.
  buffer_handle_ = buffer_traits.take_buffer_handle();
    mBufferHandle = bufferTraits.take_buffer_handle();

    // If all imports succeed, replace the previous buffer and id.
  id_ = buffer_id;
  buffer_state_bit_ = buffer_traits.buffer_state_bit();
    mId = bufferId;
    mBfferStateBit = bufferTraits.buffer_state_bit();

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

int DetachedBuffer::Poll(int timeout_ms) {
  ATRACE_NAME("DetachedBuffer::Poll");
  pollfd p = {client_.event_fd(), POLLIN, 0};
  return poll(&p, 1, timeout_ms);
int BufferHubBuffer::Poll(int timeoutMs) {
    ATRACE_CALL();

    pollfd p = {mClient.event_fd(), POLLIN, 0};
    return poll(&p, 1, timeoutMs);
}

Status<LocalChannelHandle> DetachedBuffer::Promote() {
Status<LocalChannelHandle> BufferHubBuffer::Promote() {
    ATRACE_CALL();

    // TODO(b/112338294) remove after migrate producer buffer to binder
  ALOGW("DetachedBuffer::Promote: not supported operation during migration");
    ALOGW("BufferHubBuffer::Promote: not supported operation during migration");
    return {};

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

  auto status_or_handle =
      client_.InvokeRemoteMethod<DetachedBufferRPC::Promote>();
  if (status_or_handle.ok()) {
    auto statusOrHandle = mClient.InvokeRemoteMethod<DetachedBufferRPC::Promote>();
    if (statusOrHandle.ok()) {
        // Invalidate the buffer.
    buffer_handle_ = {};
        mBufferHandle = {};
    } else {
    ALOGE("DetachedBuffer::Promote: Failed to promote buffer (id=%d): %s.", id_,
          status_or_handle.GetErrorMessage().c_str());
        ALOGE("BufferHubBuffer::Promote: Failed to promote buffer (id=%d): %s.", mId,
              statusOrHandle.GetErrorMessage().c_str());
    }
  return status_or_handle;
    return statusOrHandle;
}

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

  auto status_or_handle =
      client_.InvokeRemoteMethod<DetachedBufferRPC::Duplicate>();
    auto statusOrHandle = mClient.InvokeRemoteMethod<DetachedBufferRPC::Duplicate>();

  if (!status_or_handle.ok()) {
    ALOGE("DetachedBuffer::Duplicate: Failed to duplicate buffer (id=%d): %s.",
          id_, status_or_handle.GetErrorMessage().c_str());
    if (!statusOrHandle.ok()) {
        ALOGE("BufferHubBuffer::Duplicate: Failed to duplicate buffer (id=%d): %s.", mId,
              statusOrHandle.GetErrorMessage().c_str());
    }
  return status_or_handle;
    return statusOrHandle;
}

} // namespace android
+61 −67
Original line number Diff line number Diff line
@@ -34,76 +34,70 @@ using BufferHubDefs::kMetadataHeaderSize;
using BufferHubDefs::MetadataHeader;

/* static */
BufferHubMetadata BufferHubMetadata::Create(size_t user_metadata_size) {
  // The size the of metadata buffer is used as the "width" parameter during
  // allocation. Thus it cannot overflow uint32_t.
  if (user_metadata_size >=
      (std::numeric_limits<uint32_t>::max() - kMetadataHeaderSize)) {
    ALOGE("BufferHubMetadata::Create: metadata size too big: %zu.",
          user_metadata_size);
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)) {
        ALOGE("BufferHubMetadata::Create: metadata size too big: %zu.", userMetadataSize);
        return {};
    }

  const size_t metadata_size = user_metadata_size + kMetadataHeaderSize;
  int fd = ashmem_create_region(/*name=*/"BufferHubMetadata", metadata_size);
    const size_t metadataSize = userMetadataSize + kMetadataHeaderSize;
    int fd = ashmem_create_region(/*name=*/"BufferHubMetadata", metadataSize);
    if (fd < 0) {
        ALOGE("BufferHubMetadata::Create: failed to create ashmem region.");
        return {};
    }

  // Hand over the ownership of the fd to a pdx::LocalHandle immediately after
  // the successful return of ashmem_create_region. The ashmem_handle is going
  // to own the fd and to prevent fd leaks during error handling.
  pdx::LocalHandle ashmem_handle{fd};
    // Hand over the ownership of the fd to a pdx::LocalHandle immediately after the successful
    // return of ashmem_create_region. The ashmemHandle is going to own the fd and to prevent fd
    // leaks during error handling.
    pdx::LocalHandle ashmemHandle{fd};

  if (ashmem_set_prot_region(ashmem_handle.Get(), kAshmemProt) != 0) {
    if (ashmem_set_prot_region(ashmemHandle.Get(), kAshmemProt) != 0) {
        ALOGE("BufferHubMetadata::Create: failed to set protect region.");
        return {};
    }

  return BufferHubMetadata::Import(std::move(ashmem_handle));
    return BufferHubMetadata::Import(std::move(ashmemHandle));
}

/* static */
BufferHubMetadata BufferHubMetadata::Import(pdx::LocalHandle ashmem_handle) {
  if (!ashmem_valid(ashmem_handle.Get())) {
BufferHubMetadata BufferHubMetadata::Import(pdx::LocalHandle ashmemHandle) {
    if (!ashmem_valid(ashmemHandle.Get())) {
        ALOGE("BufferHubMetadata::Import: invalid ashmem fd.");
        return {};
    }

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

  // Note that here the buffer state is mapped from shared memory as an atomic
  // object. The std::atomic's constructor will not be called so that the
  // original value stored in the memory region can be preserved.
  auto metadata_header = static_cast<MetadataHeader*>(
      mmap(nullptr, metadata_size, kAshmemProt, MAP_SHARED, ashmem_handle.Get(),
    // Note that here the buffer state is mapped from shared memory as an atomic object. The
    // std::atomic's constructor will not be called so that the original value stored in the memory
    // region can be preserved.
    auto metadataHeader = static_cast<MetadataHeader*>(mmap(nullptr, metadataSize, kAshmemProt,
                                                            MAP_SHARED, ashmemHandle.Get(),
                                                            /*offset=*/0));
  if (metadata_header == nullptr) {
    if (metadataHeader == nullptr) {
        ALOGE("BufferHubMetadata::Import: failed to map region.");
        return {};
    }

  return BufferHubMetadata(user_metadata_size, std::move(ashmem_handle),
                           metadata_header);
    return BufferHubMetadata(userMetadataSize, std::move(ashmemHandle), metadataHeader);
}

BufferHubMetadata::BufferHubMetadata(size_t user_metadata_size,
                                     pdx::LocalHandle ashmem_handle,
                                     MetadataHeader* metadata_header)
    : user_metadata_size_(user_metadata_size),
      ashmem_handle_(std::move(ashmem_handle)),
      metadata_header_(metadata_header) {}
BufferHubMetadata::BufferHubMetadata(size_t userMetadataSize, pdx::LocalHandle ashmemHandle,
                                     MetadataHeader* metadataHeader)
      : mUserMetadataSize(userMetadataSize),
        mAshmemHandle(std::move(ashmemHandle)),
        mMetadataHeader(metadataHeader) {}

BufferHubMetadata::~BufferHubMetadata() {
  if (metadata_header_ != nullptr) {
    int ret = munmap(metadata_header_, metadata_size());
    if (mMetadataHeader != nullptr) {
        int ret = munmap(mMetadataHeader, metadata_size());
        ALOGE_IF(ret != 0,
             "BufferHubMetadata::~BufferHubMetadata: failed to unmap ashmem, "
             "error=%d.",
             errno);
    metadata_header_ = nullptr;
                 "BufferHubMetadata::~BufferHubMetadata: failed to unmap ashmem, error=%d.", errno);
        mMetadataHeader = nullptr;
    }
}

+106 −98
Original line number Diff line number Diff line
#ifndef ANDROID_DVR_DETACHED_BUFFER_H_
#define ANDROID_DVR_DETACHED_BUFFER_H_
/*
 * 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_BUFFER_H_
#define ANDROID_BUFFER_HUB_BUFFER_H_

// We would eliminate the clang warnings introduced by libdpx.
// TODO(b/112338294): Remove those once BufferHub moved to use Binder
@@ -20,7 +36,6 @@
#include <pdx/client.h>
#include <private/dvr/buffer_hub_defs.h>
#include <private/dvr/native_handle_wrapper.h>
#include <pdx/client.h>
#pragma clang diagnostic pop

#include <ui/BufferHubMetadata.h>
@@ -31,7 +46,7 @@ class BufferHubClient : public pdx::Client {
public:
    BufferHubClient();
    virtual ~BufferHubClient();
  explicit BufferHubClient(pdx::LocalChannelHandle channel_handle);
    explicit BufferHubClient(pdx::LocalChannelHandle mChannelHandle);

    bool IsValid() const;
    pdx::LocalChannelHandle TakeChannelHandle();
@@ -42,100 +57,93 @@ class BufferHubClient : public pdx::Client {
    using pdx::Client::InvokeRemoteMethod;
};

class DetachedBuffer {
class BufferHubBuffer {
public:
  // Allocates a standalone DetachedBuffer not associated with any producer
  // consumer set.
  static std::unique_ptr<DetachedBuffer> Create(uint32_t width, uint32_t height,
                                                uint32_t layer_count,
                                                uint32_t format, uint64_t usage,
                                                size_t user_metadata_size) {
    return std::unique_ptr<DetachedBuffer>(new DetachedBuffer(
        width, height, layer_count, format, usage, user_metadata_size));
    // Allocates a standalone BufferHubBuffer not associated with any producer consumer set.
    static std::unique_ptr<BufferHubBuffer> Create(uint32_t width, uint32_t height,
                                                   uint32_t layerCount, uint32_t format,
                                                   uint64_t usage, size_t mUserMetadataSize) {
        return std::unique_ptr<BufferHubBuffer>(
                new BufferHubBuffer(width, height, layerCount, format, usage, mUserMetadataSize));
    }

  // Imports the given channel handle to a DetachedBuffer, taking ownership.
  static std::unique_ptr<DetachedBuffer> Import(
      pdx::LocalChannelHandle channel_handle) {
    return std::unique_ptr<DetachedBuffer>(
        new DetachedBuffer(std::move(channel_handle)));
    // Imports the given channel handle to a BufferHubBuffer, taking ownership.
    static std::unique_ptr<BufferHubBuffer> Import(pdx::LocalChannelHandle mChannelHandle) {
        return std::unique_ptr<BufferHubBuffer>(new BufferHubBuffer(std::move(mChannelHandle)));
    }

  DetachedBuffer(const DetachedBuffer&) = delete;
  void operator=(const DetachedBuffer&) = delete;
    BufferHubBuffer(const BufferHubBuffer&) = delete;
    void operator=(const BufferHubBuffer&) = delete;

  // Gets ID of the buffer client. All DetachedBuffer clients derived from the
  // same buffer in bufferhubd share the same buffer id.
  int id() const { return id_; }
    // Gets ID of the buffer client. All BufferHubBuffer clients derived from the same buffer in
    // bufferhubd share the same buffer id.
    int id() const { return mId; }

  const native_handle_t* DuplicateHandle() {
    return buffer_handle_.DuplicateHandle();
  }
    const native_handle_t* DuplicateHandle() { return mBufferHandle.DuplicateHandle(); }

    // Returns the current value of MetadataHeader::buffer_state.
    uint64_t buffer_state() {
    return metadata_.metadata_header()->buffer_state.load(
        std::memory_order_acquire);
        return mMetadata.metadata_header()->buffer_state.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.
  uint64_t buffer_state_bit() const { return buffer_state_bit_; }
    // A state mask which is unique to a buffer hub client among all its siblings sharing the same
    // concrete graphic buffer.
    uint64_t buffer_state_bit() const { return mBfferStateBit; }

  size_t user_metadata_size() const { return metadata_.user_metadata_size(); }
    size_t user_metadata_size() const { return mMetadata.user_metadata_size(); }

    // Returns true if the buffer holds an open PDX channels towards bufferhubd.
  bool IsConnected() const { return client_.IsValid(); }
    bool IsConnected() const { return mClient.IsValid(); }

  // Returns true if the buffer holds an valid native buffer handle that's
  // availble for the client to read from and/or write into.
  bool IsValid() const { return buffer_handle_.IsValid(); }
    // Returns true if the buffer holds an valid native buffer handle that's availble for the client
    // to read from and/or write into.
    bool IsValid() const { return mBufferHandle.IsValid(); }

  // Returns the event mask for all the events that are pending on this buffer
  // (see sys/poll.h for all possible bits).
    // Returns the event mask for all the events that are pending on this buffer (see sys/poll.h for
    // all possible bits).
    pdx::Status<int> GetEventMask(int events) {
    if (auto* channel = client_.GetChannel()) {
        if (auto* channel = mClient.GetChannel()) {
            return channel->GetEventMask(events);
        } else {
            return pdx::ErrorStatus(EINVAL);
        }
    }

  // Polls the fd for |timeout_ms| milliseconds (-1 for infinity).
  int Poll(int timeout_ms);
    // Polls the fd for |timeoutMs| milliseconds (-1 for infinity).
    int Poll(int timeoutMs);

  // Promotes a DetachedBuffer to become a ProducerBuffer. Once promoted the
  // DetachedBuffer channel will be closed automatically on successful IPC
  // return. Further IPCs towards this channel will return error.
    // Promotes a BufferHubBuffer to become a ProducerBuffer. Once promoted the BufferHubBuffer
    // channel will be closed automatically on successful IPC return. Further IPCs towards this
    // channel will return error.
    pdx::Status<pdx::LocalChannelHandle> Promote();

  // Creates a DetachedBuffer client from an existing one. The new client will
    // Creates a BufferHubBuffer client from an existing one. The new client will
    // share the same underlying gralloc buffer and ashmem region for metadata.
    pdx::Status<pdx::LocalChannelHandle> Duplicate();

private:
  DetachedBuffer(uint32_t width, uint32_t height, uint32_t layer_count,
                 uint32_t format, uint64_t usage, size_t user_metadata_size);
    BufferHubBuffer(uint32_t width, uint32_t height, uint32_t layerCount, uint32_t format,
                    uint64_t usage, size_t mUserMetadataSize);

  DetachedBuffer(pdx::LocalChannelHandle channel_handle);
    BufferHubBuffer(pdx::LocalChannelHandle mChannelHandle);

    int ImportGraphicBuffer();

    // Global id for the buffer that is consistent across processes.
  int id_;
  uint64_t buffer_state_bit_;
    int mId;
    uint64_t mBfferStateBit;

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

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

    // PDX backend.
  BufferHubClient client_;
    BufferHubClient mClient;
};

} // namespace android

#endif  // ANDROID_DVR_DETACHED_BUFFER_H_
#endif // ANDROID_BUFFER_HUB_BUFFER_H_
+55 −59

File changed.

Preview size limit exceeded, changes collapsed.

Loading