Loading libs/vr/libbufferhub/buffer_hub_client.cpp +37 −51 Original line number Diff line number Diff line Loading @@ -53,44 +53,36 @@ Status<LocalChannelHandle> BufferHubBuffer::CreateConsumer() { int BufferHubBuffer::ImportBuffer() { ATRACE_NAME("BufferHubBuffer::ImportBuffer"); Status<std::vector<NativeBufferHandle<LocalHandle>>> status = InvokeRemoteMethod<BufferHubRPC::GetBuffers>(); Status<NativeBufferHandle<LocalHandle>> status = InvokeRemoteMethod<BufferHubRPC::GetBuffer>(); if (!status) { ALOGE("BufferHubBuffer::ImportBuffer: Failed to get buffers: %s", ALOGE("BufferHubBuffer::ImportBuffer: Failed to get buffer: %s", status.GetErrorMessage().c_str()); return -status.error(); } else if (status.get().empty()) { } else if (status.get().id() >= 0) { ALOGE( "BufferHubBuffer::ImportBuffer: Expected to receive at least one " "buffer handle but got zero!"); "BufferHubBuffer::ImportBuffer: Expected to receive a buffer handle " "but got null!"); return -EIO; } auto buffer_handles = status.take(); auto buffer_handle = status.take(); // Stash the buffer id to replace the value in id_. All sub-buffers of a // buffer hub buffer have the same id. const int new_id = buffer_handles[0].id(); // Stash the buffer id to replace the value in id_. const int new_id = buffer_handle.id(); // Import all of the buffers. std::vector<IonBuffer> ion_buffers; for (auto& handle : buffer_handles) { const size_t i = &handle - buffer_handles.data(); // Import the buffer. IonBuffer ion_buffer; ALOGD_IF( TRACE, "BufferHubBuffer::ImportBuffer: i=%zu id=%d FdCount=%zu IntCount=%zu", i, handle.id(), handle.FdCount(), handle.IntCount()); TRACE, "BufferHubBuffer::ImportBuffer: id=%d FdCount=%zu IntCount=%zu", buffer_handle.id(), buffer_handle.FdCount(), buffer_handle.IntCount()); IonBuffer buffer; const int ret = handle.Import(&buffer); const int ret = buffer_handle.Import(&ion_buffer); if (ret < 0) return ret; ion_buffers.emplace_back(std::move(buffer)); } // If all imports succeed, replace the previous buffers and id. slices_ = std::move(ion_buffers); // If the import succeeds, replace the previous buffer and id. buffer_ = std::move(ion_buffer); id_ = new_id; return 0; } Loading @@ -102,11 +94,11 @@ int BufferHubBuffer::Poll(int timeout_ms) { } int BufferHubBuffer::Lock(int usage, int x, int y, int width, int height, void** address, size_t index) { return slices_[index].Lock(usage, x, y, width, height, address); void** address) { return buffer_.Lock(usage, x, y, width, height, address); } int BufferHubBuffer::Unlock(size_t index) { return slices_[index].Unlock(); } int BufferHubBuffer::Unlock() { return buffer_.Unlock(); } int BufferHubBuffer::GetBlobReadWritePointer(size_t size, void** addr) { int width = static_cast<int>(size); Loading Loading @@ -199,27 +191,24 @@ int BufferConsumer::SetIgnore(bool ignore) { } BufferProducer::BufferProducer(uint32_t width, uint32_t height, uint32_t format, uint32_t usage, size_t metadata_size, size_t slice_count) : BufferProducer(width, height, format, usage, usage, metadata_size, slice_count) {} uint32_t usage, size_t metadata_size) : BufferProducer(width, height, format, usage, usage, metadata_size) {} BufferProducer::BufferProducer(uint32_t width, uint32_t height, uint32_t format, uint64_t producer_usage, uint64_t consumer_usage, size_t metadata_size, size_t slice_count) size_t metadata_size) : BASE(BufferHubRPC::kClientPath) { ATRACE_NAME("BufferProducer::BufferProducer"); ALOGD_IF(TRACE, "BufferProducer::BufferProducer: fd=%d width=%u height=%u format=%u " "producer_usage=%" PRIx64 " consumer_usage=%" PRIx64 " metadata_size=%zu slice_count=%zu", " metadata_size=%zu", event_fd(), width, height, format, producer_usage, consumer_usage, metadata_size, slice_count); metadata_size); // (b/37881101) Deprecate producer/consumer usage auto status = InvokeRemoteMethod<BufferHubRPC::CreateBuffer>( width, height, format, (producer_usage | consumer_usage), metadata_size, slice_count); width, height, format, (producer_usage | consumer_usage), metadata_size); if (!status) { ALOGE( "BufferProducer::BufferProducer: Failed to create producer buffer: %s", Loading @@ -240,28 +229,27 @@ BufferProducer::BufferProducer(uint32_t width, uint32_t height, uint32_t format, BufferProducer::BufferProducer(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint32_t usage, size_t meta_size_bytes, size_t slice_count) size_t meta_size_bytes) : BufferProducer(name, user_id, group_id, width, height, format, usage, usage, meta_size_bytes, slice_count) {} usage, meta_size_bytes) {} BufferProducer::BufferProducer(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint64_t producer_usage, uint64_t consumer_usage, size_t meta_size_bytes, size_t slice_count) uint64_t consumer_usage, size_t meta_size_bytes) : BASE(BufferHubRPC::kClientPath) { ATRACE_NAME("BufferProducer::BufferProducer"); ALOGD_IF(TRACE, "BufferProducer::BufferProducer: fd=%d name=%s user_id=%d " "group_id=%d width=%u height=%u format=%u producer_usage=%" PRIx64 " consumer_usage=%" PRIx64 " meta_size_bytes=%zu slice_count=%zu", " consumer_usage=%" PRIx64 " meta_size_bytes=%zu", event_fd(), name.c_str(), user_id, group_id, width, height, format, producer_usage, consumer_usage, meta_size_bytes, slice_count); producer_usage, consumer_usage, meta_size_bytes); // (b/37881101) Deprecate producer/consumer usage auto status = InvokeRemoteMethod<BufferHubRPC::CreatePersistentBuffer>( name, user_id, group_id, width, height, format, (producer_usage | consumer_usage), meta_size_bytes, slice_count); (producer_usage | consumer_usage), meta_size_bytes); if (!status) { ALOGE( "BufferProducer::BufferProducer: Failed to create/get persistent " Loading Loading @@ -296,12 +284,11 @@ BufferProducer::BufferProducer(uint64_t producer_usage, uint64_t consumer_usage, const int height = 1; const int format = HAL_PIXEL_FORMAT_BLOB; const size_t meta_size_bytes = 0; const size_t slice_count = 1; // (b/37881101) Deprecate producer/consumer usage auto status = InvokeRemoteMethod<BufferHubRPC::CreateBuffer>( width, height, format, (producer_usage | consumer_usage), meta_size_bytes, slice_count); width, height, format, (producer_usage | consumer_usage), meta_size_bytes); if (!status) { ALOGE("BufferProducer::BufferProducer: Failed to create blob: %s", status.GetErrorMessage().c_str()); Loading Loading @@ -336,12 +323,11 @@ BufferProducer::BufferProducer(const std::string& name, int user_id, const int height = 1; const int format = HAL_PIXEL_FORMAT_BLOB; const size_t meta_size_bytes = 0; const size_t slice_count = 1; // (b/37881101) Deprecate producer/consumer usage auto status = InvokeRemoteMethod<BufferHubRPC::CreatePersistentBuffer>( name, user_id, group_id, width, height, format, (producer_usage | consumer_usage), meta_size_bytes, slice_count); (producer_usage | consumer_usage), meta_size_bytes); if (!status) { ALOGE( "BufferProducer::BufferProducer: Failed to create persistent " Loading libs/vr/libbufferhub/include/private/dvr/buffer_hub_client.h +18 −42 Original line number Diff line number Diff line Loading @@ -32,20 +32,11 @@ class BufferHubBuffer : public pdx::Client { // the usage is software then |addr| will be updated to point to the address // of the buffer in virtual memory. The caller should only access/modify the // pixels in the specified area. anything else is undefined behavior. int Lock(int usage, int x, int y, int width, int height, void** addr, size_t index); int Lock(int usage, int x, int y, int width, int height, void** addr); // Must be called after Lock() when the caller has finished changing the // buffer. int Unlock(size_t index); // Helper for when index is 0. int Lock(int usage, int x, int y, int width, int height, void** addr) { return Lock(usage, x, y, width, height, addr, 0); } // Helper for when index is 0. int Unlock() { return Unlock(0); } int Unlock(); // Gets a blob buffer that was created with BufferProducer::CreateBlob. // Locking and Unlocking is handled internally. There's no need to Unlock Loading Loading @@ -85,38 +76,27 @@ class BufferHubBuffer : public pdx::Client { } native_handle_t* native_handle() const { return const_cast<native_handle_t*>(slices_[0].handle()); return const_cast<native_handle_t*>(buffer_.handle()); } // If index is greater than or equal to slice_count(), the result is // undefined. native_handle_t* native_handle(size_t index) const { return const_cast<native_handle_t*>(slices_[index].handle()); } IonBuffer* buffer() { return &slices_[0]; } const IonBuffer* buffer() const { return &slices_[0]; } // If index is greater than or equal to slice_count(), the result is // undefined. IonBuffer* slice(size_t index) { return &slices_[index]; } const IonBuffer* slice(size_t index) const { return &slices_[index]; } IonBuffer* buffer() { return &buffer_; } const IonBuffer* buffer() const { return &buffer_; } int slice_count() const { return static_cast<int>(slices_.size()); } int id() const { return id_; } // The following methods return settings of the first buffer. Currently, // it is only possible to create multi-buffer BufferHubBuffers with the same // settings. uint32_t width() const { return slices_[0].width(); } uint32_t height() const { return slices_[0].height(); } uint32_t stride() const { return slices_[0].stride(); } uint32_t format() const { return slices_[0].format(); } uint32_t usage() const { return slices_[0].usage(); } uint32_t layer_count() const { return slices_[0].layer_count(); } uint32_t width() const { return buffer_.width(); } uint32_t height() const { return buffer_.height(); } uint32_t stride() const { return buffer_.stride(); } uint32_t format() const { return buffer_.format(); } uint32_t usage() const { return buffer_.usage(); } uint32_t layer_count() const { return buffer_.layer_count(); } // TODO(b/37881101) Clean up producer/consumer usage. uint64_t producer_usage() const { return slices_[0].usage(); } uint64_t consumer_usage() const { return slices_[0].usage(); } uint64_t producer_usage() const { return buffer_.usage(); } uint64_t consumer_usage() const { return buffer_.usage(); } protected: explicit BufferHubBuffer(LocalChannelHandle channel); Loading @@ -135,9 +115,7 @@ class BufferHubBuffer : public pdx::Client { // or any other functional purpose as a security precaution. int id_; // A BufferHubBuffer may contain multiple slices of IonBuffers with same // configurations. std::vector<IonBuffer> slices_; IonBuffer buffer_; }; // This represents a writable buffer. Calling Post notifies all clients and Loading Loading @@ -224,11 +202,10 @@ class BufferProducer : public pdx::ClientBase<BufferProducer, BufferHubBuffer> { // Constructs a buffer with the given geometry and parameters. BufferProducer(uint32_t width, uint32_t height, uint32_t format, uint32_t usage, size_t metadata_size = 0, size_t slice_count = 1); uint32_t usage, size_t metadata_size = 0); BufferProducer(uint32_t width, uint32_t height, uint32_t format, uint64_t producer_usage, uint64_t consumer_usage, size_t metadata_size, size_t slice_count); size_t metadata_size); // Constructs a persistent buffer with the given geometry and parameters and // binds it to |name| in one shot. If a persistent buffer with the same name Loading @@ -244,12 +221,11 @@ class BufferProducer : public pdx::ClientBase<BufferProducer, BufferHubBuffer> { // effective user or group id of the calling process. BufferProducer(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint32_t usage, size_t metadata_size = 0, size_t slice_count = 1); uint32_t usage, size_t metadata_size = 0); BufferProducer(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint64_t producer_usage, uint64_t consumer_usage, size_t metadata_size, size_t slice_count); size_t meta_size_bytes); // Constructs a blob (flat) buffer with the given usage flags. BufferProducer(uint32_t usage, size_t size); Loading libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h +4 −10 Original line number Diff line number Diff line Loading @@ -166,7 +166,6 @@ struct BufferHubRPC { kOpCreatePersistentBuffer, kOpGetPersistentBuffer, kOpGetBuffer, kOpGetBuffers, kOpNewConsumer, kOpProducerMakePersistent, kOpProducerRemovePersistence, Loading @@ -192,19 +191,15 @@ struct BufferHubRPC { // Methods. PDX_REMOTE_METHOD(CreateBuffer, kOpCreateBuffer, void(uint32_t width, uint32_t height, uint32_t format, uint64_t usage, size_t meta_size_bytes, size_t slice_count)); uint64_t usage, size_t meta_size_bytes)); PDX_REMOTE_METHOD(CreatePersistentBuffer, kOpCreatePersistentBuffer, void(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint64_t usage, size_t meta_size_bytes, size_t slice_count)); uint64_t usage, size_t meta_size_bytes)); PDX_REMOTE_METHOD(GetPersistentBuffer, kOpGetPersistentBuffer, void(const std::string& name)); PDX_REMOTE_METHOD(GetBuffer, kOpGetBuffer, NativeBufferHandle<LocalHandle>(unsigned index)); PDX_REMOTE_METHOD(GetBuffers, kOpGetBuffers, std::vector<NativeBufferHandle<LocalHandle>>(Void)); NativeBufferHandle<LocalHandle>(Void)); PDX_REMOTE_METHOD(NewConsumer, kOpNewConsumer, LocalChannelHandle(Void)); PDX_REMOTE_METHOD(ProducerMakePersistent, kOpProducerMakePersistent, void(const std::string& name, int user_id, int group_id)); Loading @@ -230,8 +225,7 @@ struct BufferHubRPC { kOpProducerQueueAllocateBuffers, std::vector<std::pair<LocalChannelHandle, size_t>>( uint32_t width, uint32_t height, uint32_t format, uint64_t usage, size_t slice_count, size_t buffer_count)); uint64_t usage, size_t buffer_count)); PDX_REMOTE_METHOD(ProducerQueueDetachBuffer, kOpProducerQueueDetachBuffer, void(size_t slot)); PDX_REMOTE_METHOD(ConsumerQueueImportBuffers, kOpConsumerQueueImportBuffers, Loading libs/vr/libbufferhub/include/private/dvr/native_buffer.h +4 −52 Original line number Diff line number Diff line Loading @@ -52,35 +52,6 @@ class NativeBuffer void operator=(NativeBuffer&) = delete; }; // NativeBufferProducerSlice is an implementation of ANativeWindowBuffer backed // by a buffer slice of a BufferProducer. class NativeBufferProducerSlice : public android::ANativeObjectBase< ANativeWindowBuffer, NativeBufferProducerSlice, android::LightRefBase<NativeBufferProducerSlice>> { public: NativeBufferProducerSlice(const std::shared_ptr<BufferProducer>& buffer, int buffer_index) : BASE(), buffer_(buffer) { ANativeWindowBuffer::width = buffer_->width(); ANativeWindowBuffer::height = buffer_->height(); ANativeWindowBuffer::stride = buffer_->stride(); ANativeWindowBuffer::format = buffer_->format(); ANativeWindowBuffer::usage = buffer_->usage(); handle = buffer_->native_handle(buffer_index); } virtual ~NativeBufferProducerSlice() {} private: friend class android::LightRefBase<NativeBufferProducerSlice>; std::shared_ptr<BufferProducer> buffer_; NativeBufferProducerSlice(const NativeBufferProducerSlice&) = delete; void operator=(NativeBufferProducerSlice&) = delete; }; // NativeBufferProducer is an implementation of ANativeWindowBuffer backed by a // BufferProducer. class NativeBufferProducer : public android::ANativeObjectBase< Loading @@ -101,19 +72,6 @@ class NativeBufferProducer : public android::ANativeObjectBase< ANativeWindowBuffer::format = buffer_->format(); ANativeWindowBuffer::usage = buffer_->usage(); handle = buffer_->native_handle(); for (int i = 0; i < buffer->slice_count(); ++i) { // display == null means don't create an EGL image. This is used by our // Vulkan code. slices_.push_back(new NativeBufferProducerSlice(buffer, i)); if (display_ != nullptr) { egl_images_.push_back(eglCreateImageKHR( display_, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, static_cast<ANativeWindowBuffer*>(slices_.back().get()), nullptr)); if (egl_images_.back() == EGL_NO_IMAGE_KHR) { ALOGE("NativeBufferProducer: eglCreateImageKHR failed"); } } } } explicit NativeBufferProducer(const std::shared_ptr<BufferProducer>& buffer) Loading Loading @@ -154,7 +112,6 @@ class NativeBufferProducer : public android::ANativeObjectBase< std::shared_ptr<BufferProducer> buffer_; pdx::LocalHandle release_fence_; std::vector<android::sp<NativeBufferProducerSlice>> slices_; std::vector<EGLImageKHR> egl_images_; uint32_t surface_buffer_index_; EGLDisplay display_; Loading @@ -171,21 +128,16 @@ class NativeBufferConsumer : public android::ANativeObjectBase< public: static constexpr int kEmptyFence = -1; explicit NativeBufferConsumer(const std::shared_ptr<BufferConsumer>& buffer, int index) explicit NativeBufferConsumer(const std::shared_ptr<BufferConsumer>& buffer) : BASE(), buffer_(buffer), acquire_fence_(kEmptyFence), sequence_(0) { ANativeWindowBuffer::width = buffer_->width(); ANativeWindowBuffer::height = buffer_->height(); ANativeWindowBuffer::stride = buffer_->stride(); ANativeWindowBuffer::format = buffer_->format(); ANativeWindowBuffer::usage = buffer_->usage(); LOG_ALWAYS_FATAL_IF(buffer_->slice_count() <= index); handle = buffer_->slice(index)->handle(); handle = buffer_->native_handle(); } explicit NativeBufferConsumer(const std::shared_ptr<BufferConsumer>& buffer) : NativeBufferConsumer(buffer, 0) {} virtual ~NativeBufferConsumer() {} std::shared_ptr<BufferConsumer> buffer() const { return buffer_; } Loading libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -2,8 +2,8 @@ #include <inttypes.h> #include <log/log.h> #include <sys/epoll.h> #include <poll.h> #include <sys/epoll.h> #include <array> Loading Loading @@ -390,7 +390,7 @@ ProducerQueue::ProducerQueue(size_t meta_size, uint64_t usage_set_mask, int ProducerQueue::AllocateBuffer(uint32_t width, uint32_t height, uint32_t format, uint64_t usage, size_t slice_count, size_t* out_slot) { size_t* out_slot) { if (out_slot == nullptr) { ALOGE("ProducerQueue::AllocateBuffer: Parameter out_slot cannot be null."); return -EINVAL; Loading @@ -405,7 +405,7 @@ int ProducerQueue::AllocateBuffer(uint32_t width, uint32_t height, const size_t kBufferCount = 1U; Status<std::vector<std::pair<LocalChannelHandle, size_t>>> status = InvokeRemoteMethod<BufferHubRPC::ProducerQueueAllocateBuffers>( width, height, format, usage, slice_count, kBufferCount); width, height, format, usage, kBufferCount); if (!status) { ALOGE("ProducerQueue::AllocateBuffer failed to create producer buffer: %s", status.GetErrorMessage().c_str()); Loading Loading
libs/vr/libbufferhub/buffer_hub_client.cpp +37 −51 Original line number Diff line number Diff line Loading @@ -53,44 +53,36 @@ Status<LocalChannelHandle> BufferHubBuffer::CreateConsumer() { int BufferHubBuffer::ImportBuffer() { ATRACE_NAME("BufferHubBuffer::ImportBuffer"); Status<std::vector<NativeBufferHandle<LocalHandle>>> status = InvokeRemoteMethod<BufferHubRPC::GetBuffers>(); Status<NativeBufferHandle<LocalHandle>> status = InvokeRemoteMethod<BufferHubRPC::GetBuffer>(); if (!status) { ALOGE("BufferHubBuffer::ImportBuffer: Failed to get buffers: %s", ALOGE("BufferHubBuffer::ImportBuffer: Failed to get buffer: %s", status.GetErrorMessage().c_str()); return -status.error(); } else if (status.get().empty()) { } else if (status.get().id() >= 0) { ALOGE( "BufferHubBuffer::ImportBuffer: Expected to receive at least one " "buffer handle but got zero!"); "BufferHubBuffer::ImportBuffer: Expected to receive a buffer handle " "but got null!"); return -EIO; } auto buffer_handles = status.take(); auto buffer_handle = status.take(); // Stash the buffer id to replace the value in id_. All sub-buffers of a // buffer hub buffer have the same id. const int new_id = buffer_handles[0].id(); // Stash the buffer id to replace the value in id_. const int new_id = buffer_handle.id(); // Import all of the buffers. std::vector<IonBuffer> ion_buffers; for (auto& handle : buffer_handles) { const size_t i = &handle - buffer_handles.data(); // Import the buffer. IonBuffer ion_buffer; ALOGD_IF( TRACE, "BufferHubBuffer::ImportBuffer: i=%zu id=%d FdCount=%zu IntCount=%zu", i, handle.id(), handle.FdCount(), handle.IntCount()); TRACE, "BufferHubBuffer::ImportBuffer: id=%d FdCount=%zu IntCount=%zu", buffer_handle.id(), buffer_handle.FdCount(), buffer_handle.IntCount()); IonBuffer buffer; const int ret = handle.Import(&buffer); const int ret = buffer_handle.Import(&ion_buffer); if (ret < 0) return ret; ion_buffers.emplace_back(std::move(buffer)); } // If all imports succeed, replace the previous buffers and id. slices_ = std::move(ion_buffers); // If the import succeeds, replace the previous buffer and id. buffer_ = std::move(ion_buffer); id_ = new_id; return 0; } Loading @@ -102,11 +94,11 @@ int BufferHubBuffer::Poll(int timeout_ms) { } int BufferHubBuffer::Lock(int usage, int x, int y, int width, int height, void** address, size_t index) { return slices_[index].Lock(usage, x, y, width, height, address); void** address) { return buffer_.Lock(usage, x, y, width, height, address); } int BufferHubBuffer::Unlock(size_t index) { return slices_[index].Unlock(); } int BufferHubBuffer::Unlock() { return buffer_.Unlock(); } int BufferHubBuffer::GetBlobReadWritePointer(size_t size, void** addr) { int width = static_cast<int>(size); Loading Loading @@ -199,27 +191,24 @@ int BufferConsumer::SetIgnore(bool ignore) { } BufferProducer::BufferProducer(uint32_t width, uint32_t height, uint32_t format, uint32_t usage, size_t metadata_size, size_t slice_count) : BufferProducer(width, height, format, usage, usage, metadata_size, slice_count) {} uint32_t usage, size_t metadata_size) : BufferProducer(width, height, format, usage, usage, metadata_size) {} BufferProducer::BufferProducer(uint32_t width, uint32_t height, uint32_t format, uint64_t producer_usage, uint64_t consumer_usage, size_t metadata_size, size_t slice_count) size_t metadata_size) : BASE(BufferHubRPC::kClientPath) { ATRACE_NAME("BufferProducer::BufferProducer"); ALOGD_IF(TRACE, "BufferProducer::BufferProducer: fd=%d width=%u height=%u format=%u " "producer_usage=%" PRIx64 " consumer_usage=%" PRIx64 " metadata_size=%zu slice_count=%zu", " metadata_size=%zu", event_fd(), width, height, format, producer_usage, consumer_usage, metadata_size, slice_count); metadata_size); // (b/37881101) Deprecate producer/consumer usage auto status = InvokeRemoteMethod<BufferHubRPC::CreateBuffer>( width, height, format, (producer_usage | consumer_usage), metadata_size, slice_count); width, height, format, (producer_usage | consumer_usage), metadata_size); if (!status) { ALOGE( "BufferProducer::BufferProducer: Failed to create producer buffer: %s", Loading @@ -240,28 +229,27 @@ BufferProducer::BufferProducer(uint32_t width, uint32_t height, uint32_t format, BufferProducer::BufferProducer(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint32_t usage, size_t meta_size_bytes, size_t slice_count) size_t meta_size_bytes) : BufferProducer(name, user_id, group_id, width, height, format, usage, usage, meta_size_bytes, slice_count) {} usage, meta_size_bytes) {} BufferProducer::BufferProducer(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint64_t producer_usage, uint64_t consumer_usage, size_t meta_size_bytes, size_t slice_count) uint64_t consumer_usage, size_t meta_size_bytes) : BASE(BufferHubRPC::kClientPath) { ATRACE_NAME("BufferProducer::BufferProducer"); ALOGD_IF(TRACE, "BufferProducer::BufferProducer: fd=%d name=%s user_id=%d " "group_id=%d width=%u height=%u format=%u producer_usage=%" PRIx64 " consumer_usage=%" PRIx64 " meta_size_bytes=%zu slice_count=%zu", " consumer_usage=%" PRIx64 " meta_size_bytes=%zu", event_fd(), name.c_str(), user_id, group_id, width, height, format, producer_usage, consumer_usage, meta_size_bytes, slice_count); producer_usage, consumer_usage, meta_size_bytes); // (b/37881101) Deprecate producer/consumer usage auto status = InvokeRemoteMethod<BufferHubRPC::CreatePersistentBuffer>( name, user_id, group_id, width, height, format, (producer_usage | consumer_usage), meta_size_bytes, slice_count); (producer_usage | consumer_usage), meta_size_bytes); if (!status) { ALOGE( "BufferProducer::BufferProducer: Failed to create/get persistent " Loading Loading @@ -296,12 +284,11 @@ BufferProducer::BufferProducer(uint64_t producer_usage, uint64_t consumer_usage, const int height = 1; const int format = HAL_PIXEL_FORMAT_BLOB; const size_t meta_size_bytes = 0; const size_t slice_count = 1; // (b/37881101) Deprecate producer/consumer usage auto status = InvokeRemoteMethod<BufferHubRPC::CreateBuffer>( width, height, format, (producer_usage | consumer_usage), meta_size_bytes, slice_count); width, height, format, (producer_usage | consumer_usage), meta_size_bytes); if (!status) { ALOGE("BufferProducer::BufferProducer: Failed to create blob: %s", status.GetErrorMessage().c_str()); Loading Loading @@ -336,12 +323,11 @@ BufferProducer::BufferProducer(const std::string& name, int user_id, const int height = 1; const int format = HAL_PIXEL_FORMAT_BLOB; const size_t meta_size_bytes = 0; const size_t slice_count = 1; // (b/37881101) Deprecate producer/consumer usage auto status = InvokeRemoteMethod<BufferHubRPC::CreatePersistentBuffer>( name, user_id, group_id, width, height, format, (producer_usage | consumer_usage), meta_size_bytes, slice_count); (producer_usage | consumer_usage), meta_size_bytes); if (!status) { ALOGE( "BufferProducer::BufferProducer: Failed to create persistent " Loading
libs/vr/libbufferhub/include/private/dvr/buffer_hub_client.h +18 −42 Original line number Diff line number Diff line Loading @@ -32,20 +32,11 @@ class BufferHubBuffer : public pdx::Client { // the usage is software then |addr| will be updated to point to the address // of the buffer in virtual memory. The caller should only access/modify the // pixels in the specified area. anything else is undefined behavior. int Lock(int usage, int x, int y, int width, int height, void** addr, size_t index); int Lock(int usage, int x, int y, int width, int height, void** addr); // Must be called after Lock() when the caller has finished changing the // buffer. int Unlock(size_t index); // Helper for when index is 0. int Lock(int usage, int x, int y, int width, int height, void** addr) { return Lock(usage, x, y, width, height, addr, 0); } // Helper for when index is 0. int Unlock() { return Unlock(0); } int Unlock(); // Gets a blob buffer that was created with BufferProducer::CreateBlob. // Locking and Unlocking is handled internally. There's no need to Unlock Loading Loading @@ -85,38 +76,27 @@ class BufferHubBuffer : public pdx::Client { } native_handle_t* native_handle() const { return const_cast<native_handle_t*>(slices_[0].handle()); return const_cast<native_handle_t*>(buffer_.handle()); } // If index is greater than or equal to slice_count(), the result is // undefined. native_handle_t* native_handle(size_t index) const { return const_cast<native_handle_t*>(slices_[index].handle()); } IonBuffer* buffer() { return &slices_[0]; } const IonBuffer* buffer() const { return &slices_[0]; } // If index is greater than or equal to slice_count(), the result is // undefined. IonBuffer* slice(size_t index) { return &slices_[index]; } const IonBuffer* slice(size_t index) const { return &slices_[index]; } IonBuffer* buffer() { return &buffer_; } const IonBuffer* buffer() const { return &buffer_; } int slice_count() const { return static_cast<int>(slices_.size()); } int id() const { return id_; } // The following methods return settings of the first buffer. Currently, // it is only possible to create multi-buffer BufferHubBuffers with the same // settings. uint32_t width() const { return slices_[0].width(); } uint32_t height() const { return slices_[0].height(); } uint32_t stride() const { return slices_[0].stride(); } uint32_t format() const { return slices_[0].format(); } uint32_t usage() const { return slices_[0].usage(); } uint32_t layer_count() const { return slices_[0].layer_count(); } uint32_t width() const { return buffer_.width(); } uint32_t height() const { return buffer_.height(); } uint32_t stride() const { return buffer_.stride(); } uint32_t format() const { return buffer_.format(); } uint32_t usage() const { return buffer_.usage(); } uint32_t layer_count() const { return buffer_.layer_count(); } // TODO(b/37881101) Clean up producer/consumer usage. uint64_t producer_usage() const { return slices_[0].usage(); } uint64_t consumer_usage() const { return slices_[0].usage(); } uint64_t producer_usage() const { return buffer_.usage(); } uint64_t consumer_usage() const { return buffer_.usage(); } protected: explicit BufferHubBuffer(LocalChannelHandle channel); Loading @@ -135,9 +115,7 @@ class BufferHubBuffer : public pdx::Client { // or any other functional purpose as a security precaution. int id_; // A BufferHubBuffer may contain multiple slices of IonBuffers with same // configurations. std::vector<IonBuffer> slices_; IonBuffer buffer_; }; // This represents a writable buffer. Calling Post notifies all clients and Loading Loading @@ -224,11 +202,10 @@ class BufferProducer : public pdx::ClientBase<BufferProducer, BufferHubBuffer> { // Constructs a buffer with the given geometry and parameters. BufferProducer(uint32_t width, uint32_t height, uint32_t format, uint32_t usage, size_t metadata_size = 0, size_t slice_count = 1); uint32_t usage, size_t metadata_size = 0); BufferProducer(uint32_t width, uint32_t height, uint32_t format, uint64_t producer_usage, uint64_t consumer_usage, size_t metadata_size, size_t slice_count); size_t metadata_size); // Constructs a persistent buffer with the given geometry and parameters and // binds it to |name| in one shot. If a persistent buffer with the same name Loading @@ -244,12 +221,11 @@ class BufferProducer : public pdx::ClientBase<BufferProducer, BufferHubBuffer> { // effective user or group id of the calling process. BufferProducer(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint32_t usage, size_t metadata_size = 0, size_t slice_count = 1); uint32_t usage, size_t metadata_size = 0); BufferProducer(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint64_t producer_usage, uint64_t consumer_usage, size_t metadata_size, size_t slice_count); size_t meta_size_bytes); // Constructs a blob (flat) buffer with the given usage flags. BufferProducer(uint32_t usage, size_t size); Loading
libs/vr/libbufferhub/include/private/dvr/bufferhub_rpc.h +4 −10 Original line number Diff line number Diff line Loading @@ -166,7 +166,6 @@ struct BufferHubRPC { kOpCreatePersistentBuffer, kOpGetPersistentBuffer, kOpGetBuffer, kOpGetBuffers, kOpNewConsumer, kOpProducerMakePersistent, kOpProducerRemovePersistence, Loading @@ -192,19 +191,15 @@ struct BufferHubRPC { // Methods. PDX_REMOTE_METHOD(CreateBuffer, kOpCreateBuffer, void(uint32_t width, uint32_t height, uint32_t format, uint64_t usage, size_t meta_size_bytes, size_t slice_count)); uint64_t usage, size_t meta_size_bytes)); PDX_REMOTE_METHOD(CreatePersistentBuffer, kOpCreatePersistentBuffer, void(const std::string& name, int user_id, int group_id, uint32_t width, uint32_t height, uint32_t format, uint64_t usage, size_t meta_size_bytes, size_t slice_count)); uint64_t usage, size_t meta_size_bytes)); PDX_REMOTE_METHOD(GetPersistentBuffer, kOpGetPersistentBuffer, void(const std::string& name)); PDX_REMOTE_METHOD(GetBuffer, kOpGetBuffer, NativeBufferHandle<LocalHandle>(unsigned index)); PDX_REMOTE_METHOD(GetBuffers, kOpGetBuffers, std::vector<NativeBufferHandle<LocalHandle>>(Void)); NativeBufferHandle<LocalHandle>(Void)); PDX_REMOTE_METHOD(NewConsumer, kOpNewConsumer, LocalChannelHandle(Void)); PDX_REMOTE_METHOD(ProducerMakePersistent, kOpProducerMakePersistent, void(const std::string& name, int user_id, int group_id)); Loading @@ -230,8 +225,7 @@ struct BufferHubRPC { kOpProducerQueueAllocateBuffers, std::vector<std::pair<LocalChannelHandle, size_t>>( uint32_t width, uint32_t height, uint32_t format, uint64_t usage, size_t slice_count, size_t buffer_count)); uint64_t usage, size_t buffer_count)); PDX_REMOTE_METHOD(ProducerQueueDetachBuffer, kOpProducerQueueDetachBuffer, void(size_t slot)); PDX_REMOTE_METHOD(ConsumerQueueImportBuffers, kOpConsumerQueueImportBuffers, Loading
libs/vr/libbufferhub/include/private/dvr/native_buffer.h +4 −52 Original line number Diff line number Diff line Loading @@ -52,35 +52,6 @@ class NativeBuffer void operator=(NativeBuffer&) = delete; }; // NativeBufferProducerSlice is an implementation of ANativeWindowBuffer backed // by a buffer slice of a BufferProducer. class NativeBufferProducerSlice : public android::ANativeObjectBase< ANativeWindowBuffer, NativeBufferProducerSlice, android::LightRefBase<NativeBufferProducerSlice>> { public: NativeBufferProducerSlice(const std::shared_ptr<BufferProducer>& buffer, int buffer_index) : BASE(), buffer_(buffer) { ANativeWindowBuffer::width = buffer_->width(); ANativeWindowBuffer::height = buffer_->height(); ANativeWindowBuffer::stride = buffer_->stride(); ANativeWindowBuffer::format = buffer_->format(); ANativeWindowBuffer::usage = buffer_->usage(); handle = buffer_->native_handle(buffer_index); } virtual ~NativeBufferProducerSlice() {} private: friend class android::LightRefBase<NativeBufferProducerSlice>; std::shared_ptr<BufferProducer> buffer_; NativeBufferProducerSlice(const NativeBufferProducerSlice&) = delete; void operator=(NativeBufferProducerSlice&) = delete; }; // NativeBufferProducer is an implementation of ANativeWindowBuffer backed by a // BufferProducer. class NativeBufferProducer : public android::ANativeObjectBase< Loading @@ -101,19 +72,6 @@ class NativeBufferProducer : public android::ANativeObjectBase< ANativeWindowBuffer::format = buffer_->format(); ANativeWindowBuffer::usage = buffer_->usage(); handle = buffer_->native_handle(); for (int i = 0; i < buffer->slice_count(); ++i) { // display == null means don't create an EGL image. This is used by our // Vulkan code. slices_.push_back(new NativeBufferProducerSlice(buffer, i)); if (display_ != nullptr) { egl_images_.push_back(eglCreateImageKHR( display_, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, static_cast<ANativeWindowBuffer*>(slices_.back().get()), nullptr)); if (egl_images_.back() == EGL_NO_IMAGE_KHR) { ALOGE("NativeBufferProducer: eglCreateImageKHR failed"); } } } } explicit NativeBufferProducer(const std::shared_ptr<BufferProducer>& buffer) Loading Loading @@ -154,7 +112,6 @@ class NativeBufferProducer : public android::ANativeObjectBase< std::shared_ptr<BufferProducer> buffer_; pdx::LocalHandle release_fence_; std::vector<android::sp<NativeBufferProducerSlice>> slices_; std::vector<EGLImageKHR> egl_images_; uint32_t surface_buffer_index_; EGLDisplay display_; Loading @@ -171,21 +128,16 @@ class NativeBufferConsumer : public android::ANativeObjectBase< public: static constexpr int kEmptyFence = -1; explicit NativeBufferConsumer(const std::shared_ptr<BufferConsumer>& buffer, int index) explicit NativeBufferConsumer(const std::shared_ptr<BufferConsumer>& buffer) : BASE(), buffer_(buffer), acquire_fence_(kEmptyFence), sequence_(0) { ANativeWindowBuffer::width = buffer_->width(); ANativeWindowBuffer::height = buffer_->height(); ANativeWindowBuffer::stride = buffer_->stride(); ANativeWindowBuffer::format = buffer_->format(); ANativeWindowBuffer::usage = buffer_->usage(); LOG_ALWAYS_FATAL_IF(buffer_->slice_count() <= index); handle = buffer_->slice(index)->handle(); handle = buffer_->native_handle(); } explicit NativeBufferConsumer(const std::shared_ptr<BufferConsumer>& buffer) : NativeBufferConsumer(buffer, 0) {} virtual ~NativeBufferConsumer() {} std::shared_ptr<BufferConsumer> buffer() const { return buffer_; } Loading
libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -2,8 +2,8 @@ #include <inttypes.h> #include <log/log.h> #include <sys/epoll.h> #include <poll.h> #include <sys/epoll.h> #include <array> Loading Loading @@ -390,7 +390,7 @@ ProducerQueue::ProducerQueue(size_t meta_size, uint64_t usage_set_mask, int ProducerQueue::AllocateBuffer(uint32_t width, uint32_t height, uint32_t format, uint64_t usage, size_t slice_count, size_t* out_slot) { size_t* out_slot) { if (out_slot == nullptr) { ALOGE("ProducerQueue::AllocateBuffer: Parameter out_slot cannot be null."); return -EINVAL; Loading @@ -405,7 +405,7 @@ int ProducerQueue::AllocateBuffer(uint32_t width, uint32_t height, const size_t kBufferCount = 1U; Status<std::vector<std::pair<LocalChannelHandle, size_t>>> status = InvokeRemoteMethod<BufferHubRPC::ProducerQueueAllocateBuffers>( width, height, format, usage, slice_count, kBufferCount); width, height, format, usage, kBufferCount); if (!status) { ALOGE("ProducerQueue::AllocateBuffer failed to create producer buffer: %s", status.GetErrorMessage().c_str()); Loading