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/libs/gui/BufferQueueConsumer.cpp b/libs/gui/BufferQueueConsumer.cpp
index cd8e696..5e5de44 100644
--- a/libs/gui/BufferQueueConsumer.cpp
+++ b/libs/gui/BufferQueueConsumer.cpp
@@ -709,6 +709,14 @@
return NO_ERROR;
}
+status_t BufferQueueConsumer::setConsumerIsProtected(bool isProtected) {
+ ATRACE_CALL();
+ BQ_LOGV("setConsumerIsProtected: %s", isProtected ? "true" : "false");
+ Mutex::Autolock lock(mCore->mMutex);
+ mCore->mConsumerIsProtected = isProtected;
+ return NO_ERROR;
+}
+
status_t BufferQueueConsumer::setTransformHint(uint32_t hint) {
ATRACE_CALL();
BQ_LOGV("setTransformHint: %#x", hint);
diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp
index cd94253..cfb25e0 100644
--- a/libs/gui/BufferQueueCore.cpp
+++ b/libs/gui/BufferQueueCore.cpp
@@ -59,6 +59,7 @@
mConsumerName(getUniqueName()),
mConsumerListener(),
mConsumerUsageBits(0),
+ mConsumerIsProtected(false),
mConnectedApi(NO_CONNECTED_API),
mLinkedToDeath(),
mConnectedProducerListener(),
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index cddb1fd..8159aef 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -1105,6 +1105,9 @@
value = static_cast<int32_t>(mCore->mBufferAge);
}
break;
+ case NATIVE_WINDOW_CONSUMER_IS_PROTECTED:
+ value = static_cast<int32_t>(mCore->mConsumerIsProtected);
+ break;
default:
return BAD_VALUE;
}
diff --git a/libs/gui/IGraphicBufferConsumer.cpp b/libs/gui/IGraphicBufferConsumer.cpp
index 568c318..a573bee 100644
--- a/libs/gui/IGraphicBufferConsumer.cpp
+++ b/libs/gui/IGraphicBufferConsumer.cpp
@@ -46,6 +46,7 @@
SET_DEFAULT_BUFFER_FORMAT,
SET_DEFAULT_BUFFER_DATA_SPACE,
SET_CONSUMER_USAGE_BITS,
+ SET_CONSUMER_IS_PROTECTED,
SET_TRANSFORM_HINT,
GET_SIDEBAND_STREAM,
GET_OCCUPANCY_HISTORY,
@@ -136,6 +137,11 @@
return callRemote<Signature>(Tag::SET_CONSUMER_USAGE_BITS, usage);
}
+ status_t setConsumerIsProtected(bool isProtected) override {
+ using Signature = decltype(&IGraphicBufferConsumer::setConsumerIsProtected);
+ return callRemote<Signature>(Tag::SET_CONSUMER_IS_PROTECTED, isProtected);
+ }
+
status_t setTransformHint(uint32_t hint) override {
using Signature = decltype(&IGraphicBufferConsumer::setTransformHint);
return callRemote<Signature>(Tag::SET_TRANSFORM_HINT, hint);
@@ -204,6 +210,8 @@
return callLocal(data, reply, &IGraphicBufferConsumer::setDefaultBufferDataSpace);
case Tag::SET_CONSUMER_USAGE_BITS:
return callLocal(data, reply, &IGraphicBufferConsumer::setConsumerUsageBits);
+ case Tag::SET_CONSUMER_IS_PROTECTED:
+ return callLocal(data, reply, &IGraphicBufferConsumer::setConsumerIsProtected);
case Tag::SET_TRANSFORM_HINT:
return callLocal(data, reply, &IGraphicBufferConsumer::setTransformHint);
case Tag::GET_SIDEBAND_STREAM:
diff --git a/libs/nativewindow/include/system/window.h b/libs/nativewindow/include/system/window.h
index fb67a51..45110c4 100644
--- a/libs/nativewindow/include/system/window.h
+++ b/libs/nativewindow/include/system/window.h
@@ -192,6 +192,12 @@
* present info, 0 if it won't.
*/
NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18,
+
+ /*
+ * The consumer end is capable of handling protected buffers, i.e. buffer
+ * with GRALLOC_USAGE_PROTECTED usage bits on.
+ */
+ NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19,
};
/* Valid operations for the (*perform)() hook.