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

Commit a09147e1 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ib07fd160,I54c34d9f

* changes:
  Add importBuffer to BufferHubBinderService
  Add duplicate to BufferClient
parents eb3e8440 3a96ccd1
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ class BpBufferClient : public BpInterface<IBufferClient> {
      : BpInterface<IBufferClient>(impl) {}

  bool isValid() override;

  status_t duplicate(uint64_t* outToken) override;
};

IMPLEMENT_META_INTERFACE(BufferClient, "android.dvr.IBufferClient");
@@ -17,6 +19,7 @@ IMPLEMENT_META_INTERFACE(BufferClient, "android.dvr.IBufferClient");
// Transaction code
enum {
  IS_VALID = IBinder::FIRST_CALL_TRANSACTION,
  DUPLICATE,
};

bool BpBufferClient::isValid() {
@@ -38,13 +41,42 @@ bool BpBufferClient::isValid() {
  }
}

status_t BpBufferClient::duplicate(uint64_t* outToken) {
  Parcel data, reply;
  status_t ret =
      data.writeInterfaceToken(IBufferClient::getInterfaceDescriptor());
  if (ret != NO_ERROR) {
    ALOGE("BpBufferClient::duplicate: failed to write into parcel; errno=%d",
          ret);
    return ret;
  }

  ret = remote()->transact(DUPLICATE, data, &reply);
  if (ret == NO_ERROR) {
    *outToken = reply.readUint64();
    return NO_ERROR;
  } else {
    ALOGE("BpBufferClient::duplicate: failed to transact; errno=%d", ret);
    return ret;
  }
}

status_t BnBufferClient::onTransact(uint32_t code, const Parcel& data,
                                    Parcel* reply, uint32_t flags) {
  switch (code) {
    case IS_VALID: {
      CHECK_INTERFACE(IBufferClient, data, reply);
      return reply->writeBool(isValid());
    } break;
    }
    case DUPLICATE: {
      CHECK_INTERFACE(IBufferClient, data, reply);
      uint64_t token = 0;
      status_t ret = duplicate(&token);
      if (ret != NO_ERROR) {
        return ret;
      }
      return reply->writeUint64(token);
    }
    default:
      // Should not reach except binder defined transactions such as dumpsys
      return BBinder::onTransact(code, data, reply, flags);
+4 −0
Original line number Diff line number Diff line
@@ -14,6 +14,10 @@ class IBufferClient : public IInterface {

  // Checks if the buffer node is valid.
  virtual bool isValid() = 0;

  // Duplicates the client. Token_out will be set to a new token when succeed,
  // and not changed when failed.
  virtual status_t duplicate(uint64_t* outToken) = 0;
};

// BnInterface for IBufferClient. Should only be created in bufferhub service.
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ cc_library_static {
    name: "libbufferhubd",
    srcs: [
        "buffer_channel.cpp",
        "buffer_client.cpp",
        "buffer_hub.cpp",
        "buffer_hub_binder.cpp",
        "buffer_node.cpp",
+36 −1
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ class BpBufferHub : public BpInterface<IBufferHub> {
                                 uint32_t layer_count, uint32_t format,
                                 uint64_t usage,
                                 uint64_t user_metadata_size) override;

  status_t importBuffer(uint64_t token, sp<IBufferClient>* outClient) override;
};

IMPLEMENT_META_INTERFACE(BufferHub, "android.dvr.IBufferHub");
@@ -20,6 +22,7 @@ IMPLEMENT_META_INTERFACE(BufferHub, "android.dvr.IBufferHub");
// Transaction code
enum {
  CREATE_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
  IMPORT_BUFFER,
};

sp<IBufferClient> BpBufferHub::createBuffer(uint32_t width, uint32_t height,
@@ -50,6 +53,27 @@ sp<IBufferClient> BpBufferHub::createBuffer(uint32_t width, uint32_t height,
  }
}

status_t BpBufferHub::importBuffer(uint64_t token,
                                   sp<IBufferClient>* outClient) {
  Parcel data, reply;
  status_t ret = NO_ERROR;
  ret |= data.writeInterfaceToken(IBufferHub::getInterfaceDescriptor());
  ret |= data.writeUint64(token);
  if (ret != NO_ERROR) {
    ALOGE("BpBufferHub::importBuffer: failed to write into parcel");
    return ret;
  }

  ret = remote()->transact(IMPORT_BUFFER, data, &reply);
  if (ret == NO_ERROR) {
    *outClient = interface_cast<IBufferClient>(reply.readStrongBinder());
    return NO_ERROR;
  } else {
    ALOGE("BpBufferHub::importBuffer: failed to transact; errno=%d", ret);
    return ret;
  }
}

status_t BnBufferHub::onTransact(uint32_t code, const Parcel& data,
                                 Parcel* reply, uint32_t flags) {
  switch (code) {
@@ -64,7 +88,18 @@ status_t BnBufferHub::onTransact(uint32_t code, const Parcel& data,
      sp<IBufferClient> ret = createBuffer(width, height, layer_count, format,
                                           usage, user_metadata_size);
      return reply->writeStrongBinder(IInterface::asBinder(ret));
    } break;
    }
    case IMPORT_BUFFER: {
      CHECK_INTERFACE(IBufferHub, data, reply);
      uint64_t token = data.readUint64();
      sp<IBufferClient> client;
      status_t ret = importBuffer(token, &client);
      if (ret == NO_ERROR) {
        return reply->writeStrongBinder(IInterface::asBinder(client));
      } else {
        return ret;
      }
    }
    default:
      // Should not reach except binder defined transactions such as dumpsys
      return BBinder::onTransact(code, data, reply, flags);
+18 −0
Original line number Diff line number Diff line
#include <private/dvr/buffer_client.h>
#include <private/dvr/buffer_hub_binder.h>

namespace android {
namespace dvr {

status_t BufferClient::duplicate(uint64_t* outToken) {
  if (!buffer_node_) {
    // Should never happen
    ALOGE("BufferClient::duplicate: node is missing.");
    return UNEXPECTED_NULL;
  }
  return service_->registerToken(std::weak_ptr<BufferNode>(buffer_node_),
                                 outToken);
}

}  // namespace dvr
}  // namespace android
 No newline at end of file
Loading