[SurfaceFlinger] Add GPU protected content support.
Switch to protected context when a layer with protected contents presents.
Previously we black out layers with protected contents, now that we add support
of protected contents in GPU composition, we can turn it on. In screenshot
cases for Recents, we still black out layers with protected contents.
BUG: 35315015
Test: Build, flash and boot
Test: Watch Youtube movie, verifed by force GPU composition.
Change-Id: I556bdd6f82c06c3d54ce62fab06a8c6f47599dcf
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index 2501fae..6badc73 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -125,9 +125,11 @@
bool BufferLayer::prepareClientLayer(const RenderArea& renderArea, const Region& clip,
bool useIdentityTransform, Region& clearRegion,
+ const bool supportProtectedContent,
renderengine::LayerSettings& layer) {
ATRACE_CALL();
- Layer::prepareClientLayer(renderArea, clip, useIdentityTransform, clearRegion, layer);
+ Layer::prepareClientLayer(renderArea, clip, useIdentityTransform, clearRegion,
+ supportProtectedContent, layer);
if (CC_UNLIKELY(mActiveBuffer == 0)) {
// the texture has not been created yet, this Layer has
// in fact never been drawn into. This happens frequently with
@@ -154,7 +156,8 @@
}
return false;
}
- bool blackOutLayer = isProtected() || (isSecure() && !renderArea.isSecure());
+ bool blackOutLayer =
+ (isProtected() && !supportProtectedContent) || (isSecure() && !renderArea.isSecure());
const State& s(getDrawingState());
if (!blackOutLayer) {
layer.source.buffer.buffer = mActiveBuffer;
diff --git a/services/surfaceflinger/BufferLayer.h b/services/surfaceflinger/BufferLayer.h
index e3b10fc..c48146f 100644
--- a/services/surfaceflinger/BufferLayer.h
+++ b/services/surfaceflinger/BufferLayer.h
@@ -168,7 +168,8 @@
// prepareClientLayer - constructs a RenderEngine layer for GPU composition.
bool prepareClientLayer(const RenderArea& renderArea, const Region& clip,
bool useIdentityTransform, Region& clearRegion,
- renderengine::LayerSettings& layer);
+ const bool supportProtectedContent,
+ renderengine::LayerSettings& layer) override;
private:
// Returns true if this layer requires filtering
diff --git a/services/surfaceflinger/ColorLayer.cpp b/services/surfaceflinger/ColorLayer.cpp
index 9ea0a46..2aeece7 100644
--- a/services/surfaceflinger/ColorLayer.cpp
+++ b/services/surfaceflinger/ColorLayer.cpp
@@ -50,8 +50,10 @@
bool ColorLayer::prepareClientLayer(const RenderArea& renderArea, const Region& clip,
bool useIdentityTransform, Region& clearRegion,
+ const bool supportProtectedContent,
renderengine::LayerSettings& layer) {
- Layer::prepareClientLayer(renderArea, clip, useIdentityTransform, clearRegion, layer);
+ Layer::prepareClientLayer(renderArea, clip, useIdentityTransform, clearRegion,
+ supportProtectedContent, layer);
half4 color(getColor());
half3 solidColor(color.r, color.g, color.b);
layer.source.solidColor = solidColor;
diff --git a/services/surfaceflinger/ColorLayer.h b/services/surfaceflinger/ColorLayer.h
index df0adac..9786419 100644
--- a/services/surfaceflinger/ColorLayer.h
+++ b/services/surfaceflinger/ColorLayer.h
@@ -42,9 +42,10 @@
protected:
FloatRect computeCrop(const sp<const DisplayDevice>& /*display*/) const override { return {}; }
- virtual bool prepareClientLayer(const RenderArea& renderArea, const Region& clip,
- bool useIdentityTransform, Region& clearRegion,
- renderengine::LayerSettings& layer);
+ bool prepareClientLayer(const RenderArea& renderArea, const Region& clip,
+ bool useIdentityTransform, Region& clearRegion,
+ const bool supportProtectedContent,
+ renderengine::LayerSettings& layer) override;
private:
std::shared_ptr<compositionengine::Layer> mCompositionLayer;
diff --git a/services/surfaceflinger/ContainerLayer.cpp b/services/surfaceflinger/ContainerLayer.cpp
index 22c40d7..738f4b6 100644
--- a/services/surfaceflinger/ContainerLayer.cpp
+++ b/services/surfaceflinger/ContainerLayer.cpp
@@ -26,7 +26,7 @@
ContainerLayer::~ContainerLayer() = default;
-bool ContainerLayer::prepareClientLayer(const RenderArea&, const Region&, bool, Region&,
+bool ContainerLayer::prepareClientLayer(const RenderArea&, const Region&, bool, Region&, const bool,
renderengine::LayerSettings&) {
return false;
}
diff --git a/services/surfaceflinger/ContainerLayer.h b/services/surfaceflinger/ContainerLayer.h
index c69997d..c7cfdcd 100644
--- a/services/surfaceflinger/ContainerLayer.h
+++ b/services/surfaceflinger/ContainerLayer.h
@@ -43,7 +43,8 @@
protected:
bool prepareClientLayer(const RenderArea& renderArea, const Region& clip,
bool useIdentityTransform, Region& clearRegion,
- renderengine::LayerSettings& layer);
+ const bool supportProtectedContent,
+ renderengine::LayerSettings& layer) override;
};
} // namespace android
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index b7aa5a5..4ac7a90 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -683,18 +683,21 @@
// ---------------------------------------------------------------------------
bool Layer::prepareClientLayer(const RenderArea& renderArea, const Region& clip,
- Region& clearRegion, renderengine::LayerSettings& layer) {
- return prepareClientLayer(renderArea, clip, false, clearRegion, layer);
+ Region& clearRegion, const bool supportProtectedContent,
+ renderengine::LayerSettings& layer) {
+ return prepareClientLayer(renderArea, clip, false, clearRegion, supportProtectedContent, layer);
}
bool Layer::prepareClientLayer(const RenderArea& renderArea, bool useIdentityTransform,
- Region& clearRegion, renderengine::LayerSettings& layer) {
+ Region& clearRegion, const bool supportProtectedContent,
+ renderengine::LayerSettings& layer) {
return prepareClientLayer(renderArea, Region(renderArea.getBounds()), useIdentityTransform,
- clearRegion, layer);
+ clearRegion, supportProtectedContent, layer);
}
bool Layer::prepareClientLayer(const RenderArea& /*renderArea*/, const Region& /*clip*/,
bool useIdentityTransform, Region& /*clearRegion*/,
+ const bool /*supportProtectedContent*/,
renderengine::LayerSettings& layer) {
FloatRect bounds = getBounds();
half alpha = getAlpha();
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index fcec262..5123e59 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -437,7 +437,8 @@
protected:
virtual bool prepareClientLayer(const RenderArea& renderArea, const Region& clip,
bool useIdentityTransform, Region& clearRegion,
- renderengine::LayerSettings& layer) = 0;
+ const bool supportProtectedContent,
+ renderengine::LayerSettings& layer);
public:
virtual void setDefaultBufferSize(uint32_t /*w*/, uint32_t /*h*/) {}
@@ -494,9 +495,10 @@
* false otherwise.
*/
bool prepareClientLayer(const RenderArea& renderArea, const Region& clip, Region& clearRegion,
- renderengine::LayerSettings& layer);
+ const bool supportProtectedContent, renderengine::LayerSettings& layer);
bool prepareClientLayer(const RenderArea& renderArea, bool useIdentityTransform,
- Region& clearRegion, renderengine::LayerSettings& layer);
+ Region& clearRegion, const bool supportProtectedContent,
+ renderengine::LayerSettings& layer);
/*
* doTransaction - process the transaction. This is a good place to figure
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index ad50f93..ae342be 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -288,6 +288,7 @@
mDebugRegion(0),
mDebugDisableHWC(0),
mDebugDisableTransformHint(0),
+ mDebugEnableProtectedContent(false),
mDebugInTransaction(0),
mLastTransactionTime(0),
mForceFullDamage(false),
@@ -3331,6 +3332,9 @@
auto display = displayDevice->getCompositionDisplay();
const auto& displayState = display->getState();
const auto displayId = display->getId();
+ auto& renderEngine = getRenderEngine();
+ const bool supportProtectedContent =
+ mDebugEnableProtectedContent && renderEngine.supportsProtectedContent();
const Region bounds(displayState.bounds);
const DisplayRenderArea renderArea(displayDevice);
@@ -3348,7 +3352,23 @@
if (hasClientComposition) {
ALOGV("hasClientComposition");
+ if (displayDevice->isPrimary() && supportProtectedContent) {
+ bool needsProtected = false;
+ for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) {
+ // If the layer is a protected layer, mark protected context is needed.
+ if (layer->isProtected()) {
+ needsProtected = true;
+ break;
+ }
+ }
+ if (needsProtected != renderEngine.isProtected() &&
+ renderEngine.useProtectedContext(needsProtected)) {
+ display->getRenderSurface()->setProtected(needsProtected);
+ }
+ }
+
buf = display->getRenderSurface()->dequeueBuffer(&fd);
+
if (buf == nullptr) {
ALOGW("Dequeuing buffer for display [%s] failed, bailing out of "
"client composition for this frame",
@@ -3420,8 +3440,9 @@
// guaranteed the FB is already cleared
renderengine::LayerSettings layerSettings;
Region dummyRegion;
- bool prepared = layer->prepareClientLayer(renderArea, clip, dummyRegion,
- layerSettings);
+ bool prepared =
+ layer->prepareClientLayer(renderArea, clip, dummyRegion,
+ supportProtectedContent, layerSettings);
if (prepared) {
layerSettings.source.buffer.buffer = nullptr;
@@ -3436,7 +3457,8 @@
case Hwc2::IComposerClient::Composition::CLIENT: {
renderengine::LayerSettings layerSettings;
bool prepared =
- layer->prepareClientLayer(renderArea, clip, clearRegion, layerSettings);
+ layer->prepareClientLayer(renderArea, clip, clearRegion,
+ supportProtectedContent, layerSettings);
if (prepared) {
clientCompositionLayers.push_back(layerSettings);
}
@@ -3467,8 +3489,8 @@
clientCompositionLayers.push_back(layerSettings);
}
}
- getRenderEngine().drawLayers(clientCompositionDisplay, clientCompositionLayers,
- buf->getNativeBuffer(), std::move(fd), readyFence);
+ renderEngine.drawLayers(clientCompositionDisplay, clientCompositionLayers,
+ buf->getNativeBuffer(), std::move(fd), readyFence);
}
return true;
}
@@ -4987,9 +5009,9 @@
code == IBinder::SYSPROPS_TRANSACTION) {
return OK;
}
- // Numbers from 1000 to 1031 are currently use for backdoors. The code
+ // Numbers from 1000 to 1032 are currently use for backdoors. The code
// in onTransact verifies that the user is root, and has access to use SF.
- if (code >= 1000 && code <= 1031) {
+ if (code >= 1000 && code <= 1032) {
ALOGV("Accessing SurfaceFlinger through backdoor code: %u", code);
return OK;
}
@@ -5267,6 +5289,11 @@
}
return NO_ERROR;
}
+ case 1032: {
+ n = data.readInt32();
+ mDebugEnableProtectedContent = n;
+ return NO_ERROR;
+ }
}
}
return err;
@@ -5648,7 +5675,7 @@
traverseLayers([&](Layer* layer) {
renderengine::LayerSettings layerSettings;
bool prepared = layer->prepareClientLayer(renderArea, useIdentityTransform, clearRegion,
- layerSettings);
+ false, layerSettings);
if (prepared) {
clientCompositionLayers.push_back(layerSettings);
}
@@ -5659,6 +5686,7 @@
// there is no need for synchronization with the GPU.
base::unique_fd bufferFence;
base::unique_fd drawFence;
+ getRenderEngine().useProtectedContext(false);
getRenderEngine().drawLayers(clientCompositionDisplay, clientCompositionLayers, buffer,
std::move(bufferFence), &drawFence);
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 29b3ab2..70a9e9f 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -988,6 +988,7 @@
int mDebugRegion;
int mDebugDisableHWC;
int mDebugDisableTransformHint;
+ bool mDebugEnableProtectedContent;
volatile nsecs_t mDebugInSwapBuffers;
volatile nsecs_t mDebugInTransaction;
nsecs_t mLastTransactionTime;