Loading libs/vr/libbufferhubqueue/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ cc_library { cflags = [ "-DLOGTAG=\"libbufferhubqueue\"" ], srcs: sourceFiles, export_include_dirs: includeFiles, export_static_lib_headers: staticLibraries, static_libs: staticLibraries, shared_libs: sharedLibraries, } Loading libs/vr/libdisplay/display_client.cpp +14 −10 Original line number Diff line number Diff line Loading @@ -148,18 +148,22 @@ void DisplaySurfaceClient::SetAttributes( } } std::shared_ptr<BufferProducer> DisplaySurfaceClient::AllocateBuffer( uint32_t* buffer_index) { auto status = InvokeRemoteMethod<DisplayRPC::AllocateBuffer>(); std::shared_ptr<ProducerQueue> DisplaySurfaceClient::GetProducerQueue() { if (producer_queue_ == nullptr) { // Create producer queue through DisplayRPC auto status = InvokeRemoteMethod<DisplayRPC::CreateBufferQueue>(); if (!status) { ALOGE("DisplaySurfaceClient::AllocateBuffer: Failed to allocate buffer: %s", ALOGE( "DisplaySurfaceClient::GetProducerQueue: failed to create producer " "queue: %s", status.GetErrorMessage().c_str()); return nullptr; } if (buffer_index) *buffer_index = status.get().first; return BufferProducer::Import(status.take().second); producer_queue_ = ProducerQueue::Import<DisplaySurfaceMetadata>(status.take()); } return producer_queue_; } volatile DisplaySurfaceMetadata* DisplaySurfaceClient::GetMetadataBufferPtr() { Loading libs/vr/libdisplay/include/private/dvr/display_client.h +7 −7 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include <pdx/client.h> #include <pdx/file_handle.h> #include <private/dvr/buffer_hub_client.h> #include <private/dvr/buffer_hub_queue_client.h> #include <private/dvr/display_rpc.h> namespace android { Loading Loading @@ -62,13 +63,9 @@ class DisplaySurfaceClient void SetBlurBehind(bool blur_behind); void SetAttributes(const DisplaySurfaceAttributes& attributes); // |out_buffer_index| will receive a unique index for this buffer within the // surface. The first buffer gets 0, second gets 1, and so on. This index // can be used to deliver metadata for buffers that are queued for display. std::shared_ptr<BufferProducer> AllocateBuffer(uint32_t* out_buffer_index); std::shared_ptr<BufferProducer> AllocateBuffer() { return AllocateBuffer(nullptr); } // Get the producer end of the buffer queue that transports graphics buffer // from the application side to the compositor side. std::shared_ptr<ProducerQueue> GetProducerQueue(); // Get the shared memory metadata buffer for this display surface. If it is // not yet allocated, this will allocate it. Loading @@ -93,6 +90,9 @@ class DisplaySurfaceClient bool blur_behind_; DisplaySurfaceMetadata* mapped_metadata_buffer_; // TODO(jwcai) Add support for multiple queues. std::shared_ptr<ProducerQueue> producer_queue_; DisplaySurfaceClient(const DisplaySurfaceClient&) = delete; void operator=(const DisplaySurfaceClient&) = delete; }; Loading libs/vr/libdisplay/include/private/dvr/display_rpc.h +3 −3 Original line number Diff line number Diff line Loading @@ -212,7 +212,7 @@ struct DisplayRPC { kOpGetMetrics = 0, kOpGetEdsCapture, kOpCreateSurface, kOpAllocateBuffer, kOpCreateBufferQueue, kOpSetAttributes, kOpGetMetadataBuffer, kOpCreateVideoMeshSurface, Loading @@ -233,8 +233,8 @@ struct DisplayRPC { PDX_REMOTE_METHOD(CreateSurface, kOpCreateSurface, int(int width, int height, int format, int usage, DisplaySurfaceFlags flags)); PDX_REMOTE_METHOD(AllocateBuffer, kOpAllocateBuffer, std::pair<std::uint32_t, LocalChannelHandle>(Void)); PDX_REMOTE_METHOD(CreateBufferQueue, kOpCreateBufferQueue, LocalChannelHandle(Void)); PDX_REMOTE_METHOD(SetAttributes, kOpSetAttributes, int(const DisplaySurfaceAttributes& attributes)); PDX_REMOTE_METHOD(GetMetadataBuffer, kOpGetMetadataBuffer, Loading libs/vr/libdisplay/include/private/dvr/native_buffer_queue.h +8 −38 Original line number Diff line number Diff line Loading @@ -14,57 +14,27 @@ namespace android { namespace dvr { // NativeBufferQueue manages a queue of NativeBufferProducers allocated from a // DisplaySurfaceClient. Buffers are automatically re-enqueued when released by // the consumer side. // A wrapper over dvr::ProducerQueue that caches EGLImage. class NativeBufferQueue { public: // Create a queue with the given number of free buffers. NativeBufferQueue(const std::shared_ptr<DisplaySurfaceClient>& surface, size_t capacity); NativeBufferQueue(EGLDisplay display, const std::shared_ptr<DisplaySurfaceClient>& surface, size_t capacity); ~NativeBufferQueue(); std::shared_ptr<DisplaySurfaceClient> surface() const { return surface_; } size_t GetQueueCapacity() const { return producer_queue_->capacity(); } // Dequeue a buffer from the free queue, blocking until one is available. NativeBufferProducer* Dequeue(); // Enqueue a buffer at the end of the free queue. void Enqueue(NativeBufferProducer* buf); // Get the number of free buffers in the queue. size_t GetFreeBufferCount() const; // Get the total number of buffers managed by this queue. size_t GetQueueCapacity() const; // Accessors for display surface buffer attributes. int width() const { return surface_->width(); } int height() const { return surface_->height(); } int format() const { return surface_->format(); } int usage() const { return surface_->usage(); } // An noop here to keep Vulkan path in GraphicsContext happy. // TODO(jwcai, cort) Move Vulkan path into GVR/Google3. void Enqueue(NativeBufferProducer* buffer) {} private: // Wait for buffers to be released and enqueue them. bool WaitForBuffers(); std::shared_ptr<DisplaySurfaceClient> surface_; // A list of strong pointers to the buffers, used for managing buffer // lifetime. std::vector<android::sp<NativeBufferProducer>> buffers_; // Used to implement queue semantics. RingBuffer<NativeBufferProducer*> buffer_queue_; // Epoll fd used to wait for BufferHub events. int epoll_fd_; NativeBufferQueue(const NativeBufferQueue&) = delete; void operator=(NativeBufferQueue&) = delete; EGLDisplay display_; std::shared_ptr<ProducerQueue> producer_queue_; std::vector<sp<NativeBufferProducer>> buffers_; }; } // namespace dvr Loading Loading
libs/vr/libbufferhubqueue/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ cc_library { cflags = [ "-DLOGTAG=\"libbufferhubqueue\"" ], srcs: sourceFiles, export_include_dirs: includeFiles, export_static_lib_headers: staticLibraries, static_libs: staticLibraries, shared_libs: sharedLibraries, } Loading
libs/vr/libdisplay/display_client.cpp +14 −10 Original line number Diff line number Diff line Loading @@ -148,18 +148,22 @@ void DisplaySurfaceClient::SetAttributes( } } std::shared_ptr<BufferProducer> DisplaySurfaceClient::AllocateBuffer( uint32_t* buffer_index) { auto status = InvokeRemoteMethod<DisplayRPC::AllocateBuffer>(); std::shared_ptr<ProducerQueue> DisplaySurfaceClient::GetProducerQueue() { if (producer_queue_ == nullptr) { // Create producer queue through DisplayRPC auto status = InvokeRemoteMethod<DisplayRPC::CreateBufferQueue>(); if (!status) { ALOGE("DisplaySurfaceClient::AllocateBuffer: Failed to allocate buffer: %s", ALOGE( "DisplaySurfaceClient::GetProducerQueue: failed to create producer " "queue: %s", status.GetErrorMessage().c_str()); return nullptr; } if (buffer_index) *buffer_index = status.get().first; return BufferProducer::Import(status.take().second); producer_queue_ = ProducerQueue::Import<DisplaySurfaceMetadata>(status.take()); } return producer_queue_; } volatile DisplaySurfaceMetadata* DisplaySurfaceClient::GetMetadataBufferPtr() { Loading
libs/vr/libdisplay/include/private/dvr/display_client.h +7 −7 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ #include <pdx/client.h> #include <pdx/file_handle.h> #include <private/dvr/buffer_hub_client.h> #include <private/dvr/buffer_hub_queue_client.h> #include <private/dvr/display_rpc.h> namespace android { Loading Loading @@ -62,13 +63,9 @@ class DisplaySurfaceClient void SetBlurBehind(bool blur_behind); void SetAttributes(const DisplaySurfaceAttributes& attributes); // |out_buffer_index| will receive a unique index for this buffer within the // surface. The first buffer gets 0, second gets 1, and so on. This index // can be used to deliver metadata for buffers that are queued for display. std::shared_ptr<BufferProducer> AllocateBuffer(uint32_t* out_buffer_index); std::shared_ptr<BufferProducer> AllocateBuffer() { return AllocateBuffer(nullptr); } // Get the producer end of the buffer queue that transports graphics buffer // from the application side to the compositor side. std::shared_ptr<ProducerQueue> GetProducerQueue(); // Get the shared memory metadata buffer for this display surface. If it is // not yet allocated, this will allocate it. Loading @@ -93,6 +90,9 @@ class DisplaySurfaceClient bool blur_behind_; DisplaySurfaceMetadata* mapped_metadata_buffer_; // TODO(jwcai) Add support for multiple queues. std::shared_ptr<ProducerQueue> producer_queue_; DisplaySurfaceClient(const DisplaySurfaceClient&) = delete; void operator=(const DisplaySurfaceClient&) = delete; }; Loading
libs/vr/libdisplay/include/private/dvr/display_rpc.h +3 −3 Original line number Diff line number Diff line Loading @@ -212,7 +212,7 @@ struct DisplayRPC { kOpGetMetrics = 0, kOpGetEdsCapture, kOpCreateSurface, kOpAllocateBuffer, kOpCreateBufferQueue, kOpSetAttributes, kOpGetMetadataBuffer, kOpCreateVideoMeshSurface, Loading @@ -233,8 +233,8 @@ struct DisplayRPC { PDX_REMOTE_METHOD(CreateSurface, kOpCreateSurface, int(int width, int height, int format, int usage, DisplaySurfaceFlags flags)); PDX_REMOTE_METHOD(AllocateBuffer, kOpAllocateBuffer, std::pair<std::uint32_t, LocalChannelHandle>(Void)); PDX_REMOTE_METHOD(CreateBufferQueue, kOpCreateBufferQueue, LocalChannelHandle(Void)); PDX_REMOTE_METHOD(SetAttributes, kOpSetAttributes, int(const DisplaySurfaceAttributes& attributes)); PDX_REMOTE_METHOD(GetMetadataBuffer, kOpGetMetadataBuffer, Loading
libs/vr/libdisplay/include/private/dvr/native_buffer_queue.h +8 −38 Original line number Diff line number Diff line Loading @@ -14,57 +14,27 @@ namespace android { namespace dvr { // NativeBufferQueue manages a queue of NativeBufferProducers allocated from a // DisplaySurfaceClient. Buffers are automatically re-enqueued when released by // the consumer side. // A wrapper over dvr::ProducerQueue that caches EGLImage. class NativeBufferQueue { public: // Create a queue with the given number of free buffers. NativeBufferQueue(const std::shared_ptr<DisplaySurfaceClient>& surface, size_t capacity); NativeBufferQueue(EGLDisplay display, const std::shared_ptr<DisplaySurfaceClient>& surface, size_t capacity); ~NativeBufferQueue(); std::shared_ptr<DisplaySurfaceClient> surface() const { return surface_; } size_t GetQueueCapacity() const { return producer_queue_->capacity(); } // Dequeue a buffer from the free queue, blocking until one is available. NativeBufferProducer* Dequeue(); // Enqueue a buffer at the end of the free queue. void Enqueue(NativeBufferProducer* buf); // Get the number of free buffers in the queue. size_t GetFreeBufferCount() const; // Get the total number of buffers managed by this queue. size_t GetQueueCapacity() const; // Accessors for display surface buffer attributes. int width() const { return surface_->width(); } int height() const { return surface_->height(); } int format() const { return surface_->format(); } int usage() const { return surface_->usage(); } // An noop here to keep Vulkan path in GraphicsContext happy. // TODO(jwcai, cort) Move Vulkan path into GVR/Google3. void Enqueue(NativeBufferProducer* buffer) {} private: // Wait for buffers to be released and enqueue them. bool WaitForBuffers(); std::shared_ptr<DisplaySurfaceClient> surface_; // A list of strong pointers to the buffers, used for managing buffer // lifetime. std::vector<android::sp<NativeBufferProducer>> buffers_; // Used to implement queue semantics. RingBuffer<NativeBufferProducer*> buffer_queue_; // Epoll fd used to wait for BufferHub events. int epoll_fd_; NativeBufferQueue(const NativeBufferQueue&) = delete; void operator=(NativeBufferQueue&) = delete; EGLDisplay display_; std::shared_ptr<ProducerQueue> producer_queue_; std::vector<sp<NativeBufferProducer>> buffers_; }; } // namespace dvr Loading