summaryrefslogtreecommitdiff
path: root/libs/vr/libbufferhubqueue/buffer_hub_queue_client.cpp
AgeCommit message (Collapse)Author
2019-02-08Fix non camelCase function namesTianyu Jiang
Android Framework C++ Code Style Guidelines says that function names should be camelCase: http://go/droidcppstyle Test: m, mma in frameworks/native Bug: 68273829 Change-Id: I2f661c06b31b2e72cd0eee3d91b95531b60ec939
2019-01-02Rename Buffer{Producer, Consumer} to {Producer, Consumer}BufferJiwen 'Steve' Cai
Bug: 116855254 Test: Build Change-Id: Ief03795d2093f817f135d33eb252e1e040e150f7
2018-12-03Change the definition of buffer state and client state bits.Tianyu
Please refer to go/bufferhub-buffer-state-redesign for more information. In this change: 1. Every clients takes up two bits in the buffer_state. One from the higher 32 bits, one from the lower 32 bits. For details: go/bufferhub-buffer-state-redesign 2. Upon the creation of a new buffer, the buffer is in released state. Previously, only producer creates buffer, and upon creation, the buffer was in gained state. Now, producer needs to specifically gain the buffer before trying to produce and post it. 3. If there is no other clients when a client post a buffer, the buffer will actually be in released state instead of posted state. This is because the posted buffer does not have readers and can be reused immediately. 4. If a new client is added to the buffer when the buffer is in acquired or posted state, the buffer state of the new client will be set to posted state and able to acquire the same buffer content as posted. In the next change: variables of type std::atomic<uint64_t> in metadata header in shared memory will be replaced by std::atomic<uint32_t> Test: marlin-eng passing AHardwareBufferTest BufferHubBuffer_test BufferHubMetadata_test buffer_hub_binder_service-test buffer_hub_queue_producer-test dvr_api-test libgui_test libsensor_test vrflinger_test buffer_hub-test dvr_buffer_queue-test dvr_display-test buffer_hub_queue-test Test: smartphone VR works on blueline-eng Test: vega_xr passing AHardwareBufferTest BufferHubBuffer_test BufferHubMetadata_test buffer_hub_queue_producer-test buffer_hub-test buffer_hub_queue-test dvr_buffer_queue-test dvr_api-test Cherrypicking this changelist to oc-dr1-daydream-dev branch requires ag/5514563 to be merged at the same time to make Vega actually work. Bug: 112007999 Change-Id: I86393818ad922a91c709fe22f8e99b0667d2e9ef
2018-11-11Change the sequence between moving a struct and accessing a field inside the ↵Tianyu Jiang
struct. Accessing to a field of size_t in a move()d struct works but not so reasonable because fields of a move()d object is considered as invalid. Test: buffer_hub_queue-test still pass Bug: None Change-Id: I799ba61e6535c021b9061fa299167cba0c630cde
2018-11-08Let producer gain posted buffer if no released buffer exist.Tianyu Jiang
ProducerQueue::Dequeue functionality does not change with the default param gain_posted_buffer = false. It does the following otherwise: 1. try to gain a released buffer and return. 2. try to find the oldest posted buffer and return. Bug: 80164475 Test: on Taimen with the following tests buffer_hub-test buffer_hub_queue-test buffer_hub_queue_producer-test dvr_api-test dvr_buffer_queue-test dvr_display-test Change-Id: I6b27740388e53348024054396b784dbc6c08ca7e
2018-09-28Break up and rename buffer_hub_cilent.{h, cpp}Jiwen 'Steve' Cai
Code in buffer_hub_cilent.{h,cpp} was the main client side implementation of bufferhub. With years of developements, the content of it was complicated enough to deserved separated files. Also rename stuff for clarification. old names: +-------------------+ | BufferHubBuffer | +---------^---------+ | +------------------+ | +------------------+ | BufferProducer +----+-----+ BufferConsumer | +------------------+ +------------------+ new names: +-----------------+ | BufferHubBase | +--------^--------+ | +------------------+ | +------------------+ | ProducerBuffer +----+-----+ ConsumerBuffer | +------------------+ +------------------+ Rename rationale: 1/ BufferProducer was originally poorly named and gets easily confused with IGraphicBufferProducer. Actually, BufferProducer is a single buffer that can produce (i.e. write) data into a buffer, but it doesn't produce buffer. On the other hand, IGraphicBufferProducer is the producer end of a BufferQueue and it is used to produce buffers. 2/ BufferConsumer was originally poorly named and gets easily confused with IGraphicBufferConsumer. Actually, BufferConsumer is a single buffer that can consume (i.e. read) data from a buffer, but it doesn't consume buffer. On the other hand, IGraphicBufferConsumer is the consumer end of a BufferQueue and it is used to consume buffers. 3/ BufferHubBuffer is a pure base class and cannot be used standalone. The old name suggests that it's a buffer object backed by BufferHub, which might leads to confusion. Also, this rename is in preparation of rename DetachedBuffer to BufferHubBuffer. Bug: 116855254 Test: Build system Change-Id: Id545648f5bdc7660e58f7bb49722651ae3bcca70
2018-09-20Return error when error occurs in buffer allocation.Tianyu
Previously, the allocate buffer does not return error if it runs out of memory. This change adds the error in returned status. Test: buffer_hub_queue-test passes on Vega on oc-dr1-daydream-dev branch. Test: build and visually check on Vega on oc-dr1-daydream-dev branch. Test: buffer_hub_queue-test passes on Marlin on master branch. Change-Id: Ie226e506ff47d122cd4eef6071b44abedcd4be56
2018-09-14Revert "Fix return error"Tianyu Jiang
This reverts commit 3be4ebb025c6a21547aec7bb79c144a8b000bc46. Reason for revert: crash on Vega on oc-dr1-daydream-dev branch Change-Id: I939c87ca66ad62dbeb8b696c08a2d539180dfe7c
2018-09-13Fix return errorTianyu
Previously, the allocate buffer does not return error if it runs out of memory. This change adds the error in return. Test: buffer_hub_queue-test passes on Vega on oc-dr1-daydream-dev branch Test: buffer_hub_queue-test passes on Marlin on master branch Bug: None Change-Id: I2a37fd3221cf54c92d4f53e577e5f0055ef77b13
2018-09-13Revert "Fix return error."Tianyu Jiang
This reverts commit 9ce7bfa352e9338c2fb2c627be4d6d902a441654. Reason for revert: should check whether the allocated buffer count is the same as requested buffer count, rather than not equals zero. This is because there is a use case when bufferhub queue is created without allocated buffers. Bug: 115573986 Change-Id: I5a0dc67e6631248a019f3af95b801e2bb7f6d6be
2018-09-12Fix return error.Tianyu
Bug: None Test: None Change-Id: Ia1f292d30c3027d8432b4f8560a913f79c753437
2018-05-17Implement BufferHubProducer::attachBufferJiwen 'Steve' Cai
1/ Introduce new kOpProducerQueueInsertBuffer operation to insert a standalone ProducerChannel into a ProducerQueueChannel. 2/ Introduce some PDX security check against channel_id spoofing. Bug: 69981968 Bug: 79224574 Test: buffer_hub_queue-test, libgui_test Change-Id: I3c13e2897476c34e6e939756b079fe3440937236
2018-02-13Add BufferHub-based IGBC implementationJiwen 'Steve' Cai
This is mostly a placeholder to create an IGBC/IGBP pair based on BufferHub for testing purpose. A fully functional implementation will be filled in later. Bug: 72972441 Bug: 70046255 Test: libgui_test Change-Id: I2215bd78da1d0104f2cbb9599f874c810898be56
2017-12-07Fix flaky ConsumerQueue::Dequeue after importJiwen 'Steve' Cai
We recently noticed some flakiness around buffer_hub_queue-test's BufferHubQueueTest.TestAllocateBuffer test case. After digging deep here is the actual sympton: There are two consecutive ConsumerQueue::Dequeue() calls in the test, right after the consumer queue get created. The second call gets a certain chance to fail and it appears that the queue logic is dequeuing the same (i.e. the first) buffer again. Since the buffer already acquired during the first Dequeue() call, the second Dequeue() will eventually fail due to invalid buffer state transition. The problem here is that we Enqueue() the first buffer twice: (1) During buffer import, we always check whether the buffer has been signaled. If so, we Enqueue() it, then Acquire it asynchronously during Dequeue(). (2) During Dequeue(), the buffer's event_fd is already in the ConsumerQeue's epoll set and is will **possibly** trigger the same buffer being Enqueue()'d the second time. Note that this may not happened if the AcquireAsync in step (1) race ahead of the epoll_wait and clears the buffer available signal. We had the logic described in step (1) as a safe guard to explicitly catch the cases where buffers are already available when added into an epoll set. Under this assuption (1) and (2) should happen exclusively: either a buffer is available on import, thus edge triggered epoll won't fire and we should only trigger (1); or the buffer is not available on import, but becomes available later, which should only trigger (2). However, this is not how epoll/eventfd works. We found though unit test on epoll that adding a already signaled event_fd into a epoll set will always trigger the epoll fd no matter whether the event_fd is already signaled when being added into the epoll set. We verified this on Android and mainline Linux kernel. Thus, the check in step (1) is redundant and should be removed. Once (1) is removed, we will always catch new buffer events through the same edge-triggered epoll_wait in (2). Since it is edge triggered, it will be trigged only once when the buffer becomes available, so it's resilient to the race condition related to AcquireAsync(). Bug: 70306222 Test: buffer_hub_queue-test, buffer_hub-test Change-Id: Ic24188ad84664bc102b85ca93ed24c354cb5c5a3
2017-11-13Make BufferHubQueue binder parcelableJiwen 'Steve' Cai
The goal of this CL is to enable sending BufferHubQueue clients over binder, so that ANativeWindow/Surface backed by BufferHub can be send over binder just like the current binder BufferQueue based implementation. To enable PDX clients to be binder parcelable, this CL introduced new DPX interface: pdx::ChannelParcelable with UDS-backed implementation. Note that the ChannelParcelable interface is only exposed to each implementation of PDX client (BufferHubQueue clients in this CL) through protected pdx::Client interface. The reason for doing that is each client implementation may require different custom clean up logic between the client can be safely exported to another process. Thus, we don't want to expose this export-to-binder becomes a pdx-Client level feature, but let each client implement their own. In addition, there is no immediate need for all types of pdx::Client implementation being binder parcelable, thus we only implemented the logic for BufferHubQueue. This is the first of a seriers of CLs to eventually enable binder parcelable ANativeSurface backed by BufferHub. Bug: 37517761 Bug: 63909629 Test: buffer_hub_queue-test Change-Id: I41c8a710af3095312db823ff01bc5aa526775edd
2017-10-11Revert "Revert PDX tracing."Corey Tabaka
This reverts commit 05cd77c494aa7042fca7978e1b934855598b765e. Bug: 65455724 Test: make -j30 Change-Id: Id531101cc35b661f02291eed0c044e96f5a91a12
2017-10-11Revert PDX tracing.Michael Wright
This broke full-eng / docs / m_e_arm-eng builds. Test: lunch full-eng && m-j8 Change-Id: I79b0176738e4de35cca25e9618e64aa2bd4c4316
2017-10-10Add shared memory based buffer metadataCorey Tabaka
This CLs reduces BufferHub CPU consumption by adding asynchronous state transition so that out-of-process VR composition can run on 2016 pixel devices smoothly. In addition, this CL addresses a couple corner cases in the existing bufferhub logic, which fixes various blackscreen issues. 1/ Tracks buffer transition states (gained, posted, acquired, released) from the client side via atomic shared memory and adds PostAsync/AcquireAsync/ReleaseAsync/GainAsync with metadata and fence support. 2/ Adds dequeue order guarantee for buffers enqueued with dvrWriteBufferQueuePostBuffer. 3/ Synchronous BuffeHub operations are still supported. 4/ Bump up the bufferhubd's soft limit of open file descriptor. 5/ Handle orphaned consumer in acquired state. This is a corner case that consumer process goes aways (most likely due to a crash) leaving buffer stuck in acquired state with inconsistent buffer state. 6/ Fixes a race condition for released buffer to be Gain'ed and Acquire'd when a new consumer is created in released state. 7/ Improve silent consumer queue efficiency: Silent queues no longer import buffers or receive signals about new buffers and they are limited to only spawning other consumers and notifications about producers hanging up. 8/ Modify PDX/UDS channel event signaling to work around epoll behavior. PDX UDS uses a combination of an eventfd and an epoll set to simulate the original PDX transport channel events. An odd behavior discovered in the kernel implementation of epoll was found that causes the epoll fd to "unsignal" itself whenever epoll_wait() is called on it, regardless of whether it should still be pending. This breaks the edge triggerd behavior in nested epoll sets that channel events depend on. Since this is unlikely to ever be fixed in the kernel we work around the behavior by using the epoll set only as a logical OR of two eventfds and never calling epoll_wait() on it. When polling is required we use regluar poll() with the eventfds and data fd to avoid the bad behavior in epoll_wait(). 9/ Keep reading data after PDX hangup signal. UDS will signal hangup when the other end of the socket closes. However, data could still be in the kerenl buffer and should be consumed. Fix an issue where the service misses an impulse sent right before the socket is closed. Bug: 65455724 Bug: 65458354 Bug: 65458312 Bug: 64027135 Bug: 67424527 Test: libpdx_uds_tests bufferhub_tests buffer_hub_queue-test buffer_hub_queue_producer-test dvr_api-test Change-Id: Id07db1f206ccf4e06f7ee3c671193334408971ca
2017-08-07BufferHubQueueProducer reset buffers on disconnectJiwen 'Steve' Cai
When Surface.cpp disconnects a IGraphicBufferProducer, it clears up all the buffer cache it holds. Thus our implementation should do the same. New tests: 1/ BufferHubQueueProducerTest.ConnectDisconnectReconnect: tests IGraphicBufferProducer to behave proper after disconnect and re-connect. 2/ BufferHubQueueTest.TestFreeAllBuffers: tests BufferHubQueue handles FreeAllBuffers() properly under different producer/consumer state. Bug: 64402829 Test: Pause and resume GVR video player demo and observer no more fails around IGraphicBufferProducer::requestBuffer and Surface::dequeueBuffer. Change-Id: Ia61e3f991248135cecf22039045f6960226bda42
2017-07-28Fix missing check on buffer import.Corey Tabaka
Fix a missing check on the success of importing buffers into the ConsumerQueue. There is a race condition where the producer can invalidate its buffers, for example by resizing, before the consumer has a chance to import the previous buffers. The missing check causes a crash in SurfaceFlinger and VrCore, which are both consumers of application VR surface buffers. Also fix a missing lock around the consumer queues in VR surfaces found during the analysis of this bug. Bug: 64042620 Test: Ran test.apk before and after the fix. Observe stable operation after applying the fix. Change-Id: I416df3ca47978404dcdb53599ddeec9b4bd6fb1a
2017-07-12Fix ALOGE_IF log in bufferhubqueueJiwen 'Steve' Cai
Bug: 63636350 Test: system builds when with TRACE=1 override Change-Id: Icc1245191b90aafbb553a1d2b0bce3bae4d0a05a
2017-06-06buffer_hub_queue_client: Batch allocate buffersJiwen 'Steve' Cai
Bug: 36147743 Test: buffer_hub_queue-test, buffer_hub_queue_producer-test, dvr_api-test Change-Id: I40a9babfa8d28d4496e27a7ccecb7ae1b9bc7bd5
2017-05-25DvrBufferQueue: Add basic event callbacksJiwen 'Steve' Cai
Currently, there is no guarantee of thread safty and on which thread those callbacks are going to be fired. Three new DVR APIs introduced: 1/ dvrReadBufferQueueSetBufferAvailableCallback 2/ dvrReadBufferQueueSetBufferRemovedCallback 3/ dvrReadBufferQueueHandleEvents Bug: 36748012 Test: buffer_hub_queue-test, dvr_api-test Change-Id: I79900c9d205f1808b02400b379c79adb366a1104
2017-05-24BufferHubQueue rename DetachBuffer to RemoveBufferJiwen 'Steve' Cai
Test: buffer_hub_queue_producer-test, buffer_hub_queue-test, dvr_api-test Bug: 37164481 Change-Id: I05ba0f9f96cf60b64cb8b76482301440d40aa82a
2017-05-19Add more attribute when creating ProducerQueueJiwen 'Steve' Cai
Add `is_async`, `default_width`, `default_height` and `default_format`. Note that these attributes are currently treated as immutable after queue gets created. Bug: 38324405 Bug: 38430974 Bug: 36724099 Test: buffer_hub_queue_producer-test, buffer_hub_queue-test, dvr_api-test Change-Id: Id242a15388a1f1457ad89d11336f5643685e8361
2017-05-19Simplify ProducerQueue::CreateJiwen 'Steve' Cai
This is a preparation CL that simplifies ProducerQueue's constructor, Create(), and bufferhub_rpc::CreateProducerQueue prior to introducing more queue attributes (is_async, width, height, max_capacity, etc) on creation. 1/ Consolidate and/or remove unnecessary ProducerQueue::Create's overloading (we had way too many overloads of the create function and I figured it's awfully painful to introduce new attributes). 2/ Use UsagePolicy in ProducerQueue::Create. Also added default values for UsagePolicy, so that empty uniform initialization gives us a default policy. This helps us removing all ProducerQueue::Create overloading on whether default usage policy is needed. 3/ Move |meta_size_bytes| into ProducerQueueConfig. Bug: 38430974 Test: buffer_hub_queue_producer-test, buffer_hub_queue-test, dvr_api-test Change-Id: Ieba9f4d1bce2162bd1e6063989985afc8d014dc7
2017-05-15Clean up BufferHubQueue API and internal bookkeeping.Corey Tabaka
- Simplify buffer hangup accounting. - Add extra checks to gracefully handle the epoll set and slots array being out of sync. - Add tests for detaching buffers. - Switch to using Status<T> for all return/error values. - Fix minor bug in BufferHubQueueProducer from earlier Status<T> return value change. Bug: 36401174 Test: buffer_hub_queue-test passes. Change-Id: If7f86a45cc048dc77daa2ede56585d3f882dd24f
2017-05-08dvrapi: Pass layer_count downHendrik Wagenaar
* We were missing layer count, which would prevent multiview from working Bug: 37245304 Test: MultiLayerBufferQueue Change-Id: I88b41f1aa7665df01e89a7386cbc23b15c9a79b0
2017-05-08Remove slices from buffersHendrik Wagenaar
* code no longer required, as it will be handled in vrcore Bug: 38076195 Test: Manually ran testing Change-Id: Id28918a3bf73b99cbb57aad4c21251b7a9623074
2017-05-04Support multiple consumer queues.Corey Tabaka
- Add support for importing posted buffers when spawing a new consumer queue. - Correctly handle adding signaled buffers to epoll with edge triggered mode set. - Add test for multi-consumer behavior. Bug: 36401174 Test: buffer_hub_queue-test passes. Change-Id: Id09f01502a1b18bf80a0ae465c2941b548cde2e4
2017-05-04Return pdx::Status<T> from BufferHubQueue::Dequeue.Corey Tabaka
Switch to using Status<T> to return buffers or meaningful errors from BufferHubQueue::Dequeue. This enables determining whether an error is normal (e.g. timeout) or abnormal (e.g. disconnect). Bug: 36401174 Test: buffer_hub_queue-test passes. Change-Id: Ifef5f737a5e737b70d19bdbffd7544a993438e1c
2017-05-04Add support for consumer queue initial import and hangup.Corey Tabaka
- Add support for consumer queues to import buffers that are created before the consumer queue is created, making multi-consumer queue patterns possible. This is essential for VrFlinger operation. - Add support for notifying consumer queues when the producer queue hangs up. - Correct the epoll event loop to check for hangups even when buffers are available. - Add method to retrieve the event fd from a queue. - Add trace logging and minor cleanup. - Improve bufferhubd dump state output. Bug: 36401174 Test: build; bufferhub tests pass. Change-Id: Idd6f38a3341c048192062734e288d11de48bc4d4
2017-05-02Deprecate producer/consumer usage: Step 2Jiwen 'Steve' Cai
Clean up bufferhub_rpc, display_rpc and service side producer/consumer usage reference. Next (final) step is to remove all remaining client side reference to producer/consumer usage and update dvr_xxx API. This also fixes a minor typo in dvr_named_buffer-test Bug: 37881101 Test: Build, flash, ran particles.apk and buffer_hub_queue-test Change-Id: Ibae4376c1fd1ed964843d8b2ad2fb27204fe5e28
2017-04-07Update BufferHub service/client with support for gralloc1 usage.Corey Tabaka
- Add support for gralloc1 usage flags. - Mimic how GraphicBuffer supports gralloc0 usage flags: (usage, usage). - Move to using pdx::Status<T> since we're touching signatures everywhere. Bug: 36401174 Test: bufferhub_tests; buffer_hub_queue-test Change-Id: I0e5184197b21eda9806bbea44f63b546b030692a
2017-04-05Update BufferHubQueue in preparation for VrFlinger refactor.Corey Tabaka
- Expose buffer hub queue id to the client. This helpful as an id in queue enumeration in the DisplayManager API. - Address log convention deviations. - Clean up BufferHub service error paths. - Clean up queue importing logic to query the service for queue parameters to avoid accidental abuse. - Make spawning consumer queues more efficient in RPC only cases. - Clean up ConsumerQueue constructor logic; move to pdx::Client base class (through BufferHubQueue) instead of pdx::ClientBase. ConsumerQueue::Create doesn't make sense as a ConsumerQueue can only be created from another queue. Bug: 36401174 Test: build; run buffer_hub_queue-test Change-Id: I0530f64ecb514d0f37bb13f9ce201b6ff51502b6
2017-03-31libbufferhub: Fix compiler warning with printf format mismatchAlex Vakulenko
std::vector<bool>::at() does not return bool& but a special reference proxy class. Passing this class on the stack for "%d" printf specifier is unsafe. Compiler throws a warning to indicate this problem: format specifies type 'int' but the argument has type 'reference' (aka '__bit_reference<std::__1::vector<bool, std::__1::allocator<bool>>>') Fixed by explicitly casting to int before pushing the value onto the stack. Bug: None Test: `m -j32` = no more warning Change-Id: I7b3bc4908e4932c25be60fc350e0e0b439842b66
2017-03-20libbufferhubqueue: sanitize logs and Android.bpJiwen 'Steve' Cai
1/ Use ALOGD_IF(TRACE, "xxx") and proper clags to enable/display verbose debugging message. 2/ Make sure that tests targets are visible to Soong. Bug: 36446316 Test: Built and ran libbufferhubqueue_test, no more spam. Change-Id: I1b7fc5410dc0c07d8edb6d9cf788e6e5f97afd14
2017-03-16Expose acquire_fence though ConsumerQueue::DequeueJiwen 'Steve' Cai
The current compositor implementation will be refactored to use BufferHubQueue instead of ad-hoc BufferHub operations. We need this to expose release_fence to compositor so that it can wait for buffers to become avaiable by checking fence properly. Bug: 36033302 Bug: 36148608 Test: Built and ran buffer_hub_queue-test Change-Id: I75cfcb02e06a4b9e7e89b89690ca2d92ee09a678
2017-03-13BufferHubQueue: ClearAvailable on consumer importJiwen 'Steve' Cai
This fixes the issue that ConsumerQueue keeps receiving |OnBufferAllocated| events when using UDS based libpdx. It also hardens error handling during consumer imports. Bug: 34690159 Test: Build, flash, buffer_hub_queue-test pases Change-Id: I4f739a2869df851ed836f39122b3eba95697f3f6
2017-02-02Remove references to libchromeAlex Vakulenko
Removed dependencies on libchrome which was used mostly for logging and switched over to standard Android log macros. Bug: None Test: `m -j32` still succeeds Change-Id: I0a841c19c15c02f9a031af200e82837f9450d88a
2017-01-28Add DaydreamVR native libraries and servicesAlex Vakulenko
Upstreaming the main VR system components from master-dreamos-dev into goog/master. Bug: None Test: `m -j32` succeeds. Sailfish boots and basic_vr sample app works Change-Id: I853015872afc443aecee10411ef2d6b79184d051