@@ -2237,6 +2237,52 @@ TEST_F(SurfaceTest, BatchIllegalOperations) {
22372237 ASSERT_EQ (NO_ERROR, surface->disconnect (NATIVE_WINDOW_API_CPU));
22382238}
22392239
2240+ TEST_F (SurfaceTest, setMaxDequeuedBufferCount_setMaxAcquiredBufferCount_allocations) {
2241+ //
2242+ // Set up the consumer and producer--nothing fancy.
2243+ //
2244+ auto [consumer, surface] =
2245+ BufferItemConsumer::create (GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_RENDER);
2246+ sp<SurfaceListener> surfaceListener = sp<StubSurfaceListener>::make ();
2247+ surface->connect (NATIVE_WINDOW_API_CPU, surfaceListener);
2248+ sp<GraphicBuffer> buffer;
2249+ sp<Fence> fence;
2250+
2251+ //
2252+ // These values are independent. The consumer can dequeue 3 and the consumer can acquire 3 at
2253+ // the same time.
2254+ //
2255+ ASSERT_EQ (OK, consumer->setMaxAcquiredBufferCount (3 ));
2256+ ASSERT_EQ (OK, surface->setMaxDequeuedBufferCount (3 ));
2257+
2258+ //
2259+ // Take all three buffers out of the queue--a fourth can't be retrieved. Then queue them.
2260+ //
2261+ std::vector<Surface::BatchBuffer> dequeuedBuffers (3 );
2262+ EXPECT_EQ (OK, surface->dequeueBuffers (&dequeuedBuffers));
2263+ if (::com::android::graphics::libgui::flags::bq_always_use_max_dequeued_buffer_count ()) {
2264+ EXPECT_EQ (INVALID_OPERATION, surface->dequeueBuffer (&buffer, &fence));
2265+ }
2266+
2267+ for (auto & batchBuffer : dequeuedBuffers) {
2268+ EXPECT_EQ (OK,
2269+ surface->queueBuffer (GraphicBuffer::from (batchBuffer.buffer ),
2270+ sp<Fence>::make (batchBuffer.fenceFd )));
2271+ }
2272+ dequeuedBuffers.assign (3 , {});
2273+
2274+ //
2275+ // Acquire all three, then we should be able to dequeue 3 more.
2276+ //
2277+ std::vector<BufferItem> acquiredBuffers (3 );
2278+ for (auto & bufferItem : acquiredBuffers) {
2279+ EXPECT_EQ (OK, consumer->acquireBuffer (&bufferItem, 0 ));
2280+ }
2281+
2282+ EXPECT_EQ (OK, surface->dequeueBuffers (&dequeuedBuffers));
2283+ EXPECT_EQ (INVALID_OPERATION, surface->dequeueBuffer (&buffer, &fence));
2284+ }
2285+
22402286#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_PLATFORM_API_IMPROVEMENTS)
22412287
22422288TEST_F (SurfaceTest, PlatformBufferMethods) {
0 commit comments