BufferQueue: plumbing mConsumerIsProtected
This replaces current logic in BufferQueue that uses
GRALLOC_USAGE_PROTECTED to indicate whether an ANativeWindow is capable
of handling hardware protected gralloc buffers. Current logic is
problematic as it enforces producer to use protected buffer no matter
whether producer side is capable of writing into a protected buffer.
This new solution, however, introduces a new NATIVE_WINDOW_* flag that
consumer can set on IGraphicBufferConsumer to indicate its capacity,
which can then be queried by producer via Surface::query (or
IGraphicBufferProducer::query).
When consumer is capable of reading protected buffer (e.g. a protected
GL context), the producer can generate either a protected or unprotected
buffer.
When consumer is not capable of reading protected buffer, the producer
should only generate unprotected buffer.
Bug: 35726763
Test: videoplayer-nodrm-protected.apk and videoplayer-drm-protected.apk
both works.
Change-Id: I1bf6814c9f1f81f9e04f0e89646b0733ff1a4758
diff --git a/include/gui/BufferQueueConsumer.h b/include/gui/BufferQueueConsumer.h
index 1e22d28..b383056 100644
--- a/include/gui/BufferQueueConsumer.h
+++ b/include/gui/BufferQueueConsumer.h
@@ -129,6 +129,12 @@
// enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0.
virtual status_t setConsumerUsageBits(uint32_t usage);
+ // setConsumerIsProtected will turn on an internal bit that indicates whether
+ // the consumer can handle protected gralloc buffers (i.e. with
+ // GRALLOC_USAGE_PROTECTED set). IGraphicBufferProducer can query this
+ // capability using NATIVE_WINDOW_CONSUMER_IS_PROTECTED.
+ virtual status_t setConsumerIsProtected(bool isProtected);
+
// setTransformHint bakes in rotation to buffers so overlays can be used.
// The values are enumerated in window.h, e.g.
// NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform).
diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h
index cfe716f..dd8b992 100644
--- a/include/gui/BufferQueueCore.h
+++ b/include/gui/BufferQueueCore.h
@@ -172,6 +172,10 @@
// GraphicBuffers.
uint32_t mConsumerUsageBits;
+ // mConsumerIsProtected indicates the consumer is ready to handle protected
+ // buffer.
+ bool mConsumerIsProtected;
+
// mConnectedApi indicates the producer API that is currently connected
// to this BufferQueue. It defaults to NO_CONNECTED_API, and gets updated
// by the connect and disconnect methods.
diff --git a/include/gui/IGraphicBufferConsumer.h b/include/gui/IGraphicBufferConsumer.h
index 63254ed..57cce16 100644
--- a/include/gui/IGraphicBufferConsumer.h
+++ b/include/gui/IGraphicBufferConsumer.h
@@ -243,6 +243,12 @@
// Return of a value other than NO_ERROR means an unknown error has occurred.
virtual status_t setConsumerUsageBits(uint32_t usage) = 0;
+ // setConsumerIsProtected will turn on an internal bit that indicates whether
+ // the consumer can handle protected gralloc buffers (i.e. with
+ // GRALLOC_USAGE_PROTECTED set). IGraphicBufferProducer can query this
+ // capability using NATIVE_WINDOW_CONSUMER_IS_PROTECTED.
+ virtual status_t setConsumerIsProtected(bool isProtected) = 0;
+
// setTransformHint bakes in rotation to buffers so overlays can be used. The values are
// enumerated in window.h, e.g. NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0
// (no transform).