BufferQueue: Add allocateBuffers method
This adds an allocateBuffers method to BufferQueue, which instructs
it to allocate up to the maximum number of buffers allowed by the
current configuration. The goal is that this method can be called
ahead of render time, which will prevent dequeueBuffers from blocking
in allocation and inducing jank.
This interface is also plumbed up to the native Surface (and, in
another change, up to the Java Surface and ThreadedRenderer).
Bug: 11792166
Change-Id: I4aa96b4351ea1c95ed5db228ca3ef98303229c74
diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp
index aa6acb9..8d9a800 100644
--- a/libs/gui/IGraphicBufferProducer.cpp
+++ b/libs/gui/IGraphicBufferProducer.cpp
@@ -45,6 +45,7 @@
CONNECT,
DISCONNECT,
SET_SIDEBAND_STREAM,
+ ALLOCATE_BUFFERS,
};
class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer>
@@ -252,6 +253,21 @@
}
return result;
}
+
+ virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
+ uint32_t format, uint32_t usage) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor());
+ data.writeInt32(static_cast<int32_t>(async));
+ data.writeInt32(static_cast<int32_t>(width));
+ data.writeInt32(static_cast<int32_t>(height));
+ data.writeInt32(static_cast<int32_t>(format));
+ data.writeInt32(static_cast<int32_t>(usage));
+ status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply);
+ if (result != NO_ERROR) {
+ ALOGE("allocateBuffers failed to transact: %d", result);
+ }
+ }
};
IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer");
@@ -394,6 +410,15 @@
reply->writeInt32(result);
return NO_ERROR;
} break;
+ case ALLOCATE_BUFFERS:
+ CHECK_INTERFACE(IGraphicBufferProducer, data, reply);
+ bool async = static_cast<bool>(data.readInt32());
+ uint32_t width = static_cast<uint32_t>(data.readInt32());
+ uint32_t height = static_cast<uint32_t>(data.readInt32());
+ uint32_t format = static_cast<uint32_t>(data.readInt32());
+ uint32_t usage = static_cast<uint32_t>(data.readInt32());
+ allocateBuffers(async, width, height, format, usage);
+ return NO_ERROR;
}
return BBinder::onTransact(code, data, reply, flags);
}