Implement blur region in RenderEngine
Blur regions should be be piped through SurfaceFlinger
all the way down to the compositor, in order to render
blurs.
It's also necessary to cache them if multiple regions require
the same blur radius.
Test: manual
Test: atest SurfaceInterceptor_test
Test: atest OutputUpdateAndWriteCompositionStateTest
Bug: 159712515
Change-Id: Id4759f65eb2522a80e9328062fe641fe29786a30
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
index 77400eb..5a3b9ac 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
@@ -20,6 +20,7 @@
#include <gui/HdrMetadata.h>
#include <math/mat4.h>
+#include <ui/BlurRegion.h>
#include <ui/FloatRect.h>
#include <ui/Rect.h>
#include <ui/Region.h>
@@ -118,6 +119,9 @@
// length of the shadow in screen space
float shadowRadius{0.f};
+ // List of regions that require blur
+ std::vector<BlurRegion> blurRegions;
+
/*
* Geometry state
*/
diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp
index c625b2e..3852f45 100644
--- a/services/surfaceflinger/CompositionEngine/src/Output.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp
@@ -669,7 +669,8 @@
compositionengine::OutputLayer* Output::findLayerRequestingBackgroundComposition() const {
compositionengine::OutputLayer* layerRequestingBgComposition = nullptr;
for (auto* layer : getOutputLayersOrderedByZ()) {
- if (layer->getLayerFE().getCompositionState()->backgroundBlurRadius > 0) {
+ if (layer->getLayerFE().getCompositionState()->backgroundBlurRadius > 0 ||
+ layer->getLayerFE().getCompositionState()->blurRegions.size() > 0) {
layerRequestingBgComposition = layer;
}
}
diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
index 3dd1839..9badb99 100644
--- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp
@@ -4014,6 +4014,34 @@
mOutput->updateAndWriteCompositionState(args);
}
+TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBlurRegionRequests) {
+ InjectedLayer layer1;
+ InjectedLayer layer2;
+ InjectedLayer layer3;
+
+ // Layer requesting blur, or below, should request client composition.
+ EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
+ EXPECT_CALL(*layer1.outputLayer, writeStateToHWC(false));
+ EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
+ EXPECT_CALL(*layer2.outputLayer, writeStateToHWC(false));
+ EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
+ EXPECT_CALL(*layer3.outputLayer, writeStateToHWC(false));
+
+ BlurRegion region;
+ layer2.layerFEState.blurRegions.push_back(region);
+
+ injectOutputLayer(layer1);
+ injectOutputLayer(layer2);
+ injectOutputLayer(layer3);
+
+ mOutput->editState().isEnabled = true;
+
+ CompositionRefreshArgs args;
+ args.updatingGeometryThisFrame = false;
+ args.devOptForceClientComposition = false;
+ mOutput->updateAndWriteCompositionState(args);
+}
+
TEST_F(GenerateClientCompositionRequestsTest, handlesLandscapeModeSplitScreenRequests) {
// In split-screen landscape mode, the screen is rotated 90 degrees, with
// one layer on the left covering the left side of the output, and one layer
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index f657a00..57493d2 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -482,6 +482,7 @@
compositionState->blendMode = static_cast<Hwc2::IComposerClient::BlendMode>(blendMode);
compositionState->alpha = alpha;
compositionState->backgroundBlurRadius = drawingState.backgroundBlurRadius;
+ compositionState->blurRegions = drawingState.blurRegions;
}
void Layer::prepareGeometryCompositionState() {
@@ -550,7 +551,8 @@
isOpaque(drawingState) && !usesRoundedCorners && getAlpha() == 1.0_hf;
// Force client composition for special cases known only to the front-end.
- if (isHdrY410() || usesRoundedCorners || drawShadows()) {
+ if (isHdrY410() || usesRoundedCorners || drawShadows() ||
+ getDrawingState().blurRegions.size() > 0) {
compositionState->forceClientComposition = true;
}
}
@@ -646,6 +648,7 @@
layerSettings.alpha = alpha;
layerSettings.sourceDataspace = getDataSpace();
layerSettings.backgroundBlurRadius = getBackgroundBlurRadius();
+ layerSettings.blurRegions = getBlurRegions();
return layerSettings;
}
@@ -1285,6 +1288,14 @@
return true;
}
+bool Layer::setBlurRegions(const std::vector<BlurRegion>& blurRegions) {
+ mCurrentState.sequence++;
+ mCurrentState.blurRegions = blurRegions;
+ mCurrentState.modified = true;
+ setTransactionFlags(eTransactionNeeded);
+ return true;
+}
+
bool Layer::setFlags(uint8_t flags, uint8_t mask) {
const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
if (mCurrentState.flags == newFlags) return false;
@@ -2172,6 +2183,10 @@
return getDrawingState().backgroundBlurRadius;
}
+const std::vector<BlurRegion>& Layer::getBlurRegions() const {
+ return getDrawingState().blurRegions;
+}
+
Layer::RoundedCornerState Layer::getRoundedCornerState() const {
const auto& p = mDrawingParent.promote();
if (p != nullptr) {
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index 7112cbc..5d6c7ea 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -26,6 +26,7 @@
#include <renderengine/Mesh.h>
#include <renderengine/Texture.h>
#include <sys/types.h>
+#include <ui/BlurRegion.h>
#include <ui/FloatRect.h>
#include <ui/FrameStats.h>
#include <ui/GraphicBuffer.h>
@@ -255,6 +256,9 @@
// be rendered around the layer.
float shadowRadius;
+ // Layer regions that are made of custom materials, like frosted glass
+ std::vector<BlurRegion> blurRegions;
+
// Priority of the layer assigned by Window Manager.
int32_t frameRateSelectionPriority;
@@ -391,6 +395,7 @@
// When non-zero, everything below this layer will be blurred by backgroundBlurRadius, which
// is specified in pixels.
virtual bool setBackgroundBlurRadius(int backgroundBlurRadius);
+ virtual bool setBlurRegions(const std::vector<BlurRegion>& effectRegions);
virtual bool setTransparentRegionHint(const Region& transparent);
virtual bool setFlags(uint8_t flags, uint8_t mask);
virtual bool setLayerStack(uint32_t layerStack);
@@ -1110,6 +1115,9 @@
// final shadow radius for this layer. If a shadow is specified for a layer, then effective
// shadow radius is the set shadow radius, otherwise its the parent's shadow radius.
float mEffectiveShadowRadius = 0.f;
+
+ // A list of regions on this layer that should have blurs.
+ const std::vector<BlurRegion>& getBlurRegions() const;
};
} // namespace android
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 3977e2b..fa15d60 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -3684,6 +3684,9 @@
if (what & layer_state_t::eBackgroundBlurRadiusChanged && !mDisableBlurs && mSupportsBlur) {
if (layer->setBackgroundBlurRadius(s.backgroundBlurRadius)) flags |= eTraversalNeeded;
}
+ if (what & layer_state_t::eBlurRegionsChanged) {
+ if (layer->setBlurRegions(s.blurRegions)) flags |= eTraversalNeeded;
+ }
if (what & layer_state_t::eLayerStackChanged) {
ssize_t idx = mCurrentState.layersSortedByZ.indexOf(layer);
// We only allow setting layer stacks for top level layers,
diff --git a/services/surfaceflinger/SurfaceInterceptor.cpp b/services/surfaceflinger/SurfaceInterceptor.cpp
index 2d5566f..3548923 100644
--- a/services/surfaceflinger/SurfaceInterceptor.cpp
+++ b/services/surfaceflinger/SurfaceInterceptor.cpp
@@ -140,6 +140,7 @@
addCropLocked(transaction, layerId, layer->mCurrentState.crop_legacy);
addCornerRadiusLocked(transaction, layerId, layer->mCurrentState.cornerRadius);
addBackgroundBlurRadiusLocked(transaction, layerId, layer->mCurrentState.backgroundBlurRadius);
+ addBlurRegionsLocked(transaction, layerId, layer->mCurrentState.blurRegions);
if (layer->mCurrentState.barrierLayer_legacy != nullptr) {
addDeferTransactionLocked(transaction, layerId,
layer->mCurrentState.barrierLayer_legacy.promote(),
@@ -361,6 +362,25 @@
blurRadiusChange->set_background_blur_radius(backgroundBlurRadius);
}
+void SurfaceInterceptor::addBlurRegionsLocked(Transaction* transaction, int32_t layerId,
+ const std::vector<BlurRegion>& blurRegions) {
+ SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId));
+ BlurRegionsChange* blurRegionsChange(change->mutable_blur_regions());
+ for (const auto blurRegion : blurRegions) {
+ const auto blurRegionChange = blurRegionsChange->add_blur_regions();
+ blurRegionChange->set_blur_radius(blurRegion.blurRadius);
+ blurRegionChange->set_corner_radius_tl(blurRegion.cornerRadiusTL);
+ blurRegionChange->set_corner_radius_tr(blurRegion.cornerRadiusTR);
+ blurRegionChange->set_corner_radius_bl(blurRegion.cornerRadiusBL);
+ blurRegionChange->set_corner_radius_br(blurRegion.cornerRadiusBR);
+ blurRegionChange->set_alpha(blurRegion.alpha);
+ blurRegionChange->set_left(blurRegion.left);
+ blurRegionChange->set_top(blurRegion.top);
+ blurRegionChange->set_right(blurRegion.right);
+ blurRegionChange->set_bottom(blurRegion.bottom);
+ }
+}
+
void SurfaceInterceptor::addDeferTransactionLocked(Transaction* transaction, int32_t layerId,
const sp<const Layer>& layer, uint64_t frameNumber)
{
@@ -456,6 +476,9 @@
if (state.what & layer_state_t::eBackgroundBlurRadiusChanged) {
addBackgroundBlurRadiusLocked(transaction, layerId, state.backgroundBlurRadius);
}
+ if (state.what & layer_state_t::eBlurRegionsChanged) {
+ addBlurRegionsLocked(transaction, layerId, state.blurRegions);
+ }
if (state.what & layer_state_t::eDeferTransaction_legacy) {
sp<Layer> otherLayer = nullptr;
if (state.barrierSurfaceControl_legacy != nullptr) {
diff --git a/services/surfaceflinger/SurfaceInterceptor.h b/services/surfaceflinger/SurfaceInterceptor.h
index 97ff547..3df79c6 100644
--- a/services/surfaceflinger/SurfaceInterceptor.h
+++ b/services/surfaceflinger/SurfaceInterceptor.h
@@ -165,6 +165,8 @@
void addCornerRadiusLocked(Transaction* transaction, int32_t layerId, float cornerRadius);
void addBackgroundBlurRadiusLocked(Transaction* transaction, int32_t layerId,
int32_t backgroundBlurRadius);
+ void addBlurRegionsLocked(Transaction* transaction, int32_t layerId,
+ const std::vector<BlurRegion>& effectRegions);
void addDeferTransactionLocked(Transaction* transaction, int32_t layerId,
const sp<const Layer>& layer, uint64_t frameNumber);
void addSurfaceChangesLocked(Transaction* transaction, const layer_state_t& state);
diff --git a/services/surfaceflinger/layerproto/layers.proto b/services/surfaceflinger/layerproto/layers.proto
index f3f5626..9f25674 100644
--- a/services/surfaceflinger/layerproto/layers.proto
+++ b/services/surfaceflinger/layerproto/layers.proto
@@ -125,6 +125,9 @@
int32 background_blur_radius = 52;
uint32 owner_uid = 53;
+
+ // Regions of a layer, where blur should be applied.
+ repeated BlurRegion blur_regions = 54;
}
message PositionProto {
@@ -211,3 +214,16 @@
// This will be a 4x4 matrix of float values
repeated float val = 1;
}
+
+message BlurRegion {
+ uint32 blur_radius = 1;
+ uint32 corner_radius_tl = 2;
+ uint32 corner_radius_tr = 3;
+ uint32 corner_radius_bl = 4;
+ float corner_radius_br = 5;
+ float alpha = 6;
+ int32 left = 7;
+ int32 top = 8;
+ int32 right = 9;
+ int32 bottom = 10;
+}
\ No newline at end of file
diff --git a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
index a5a569b..81e648a 100644
--- a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
+++ b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
@@ -51,6 +51,7 @@
constexpr float POSITION_UPDATE = 121;
const Rect CROP_UPDATE(16, 16, 32, 32);
const float SHADOW_RADIUS_UPDATE = 35.0f;
+std::vector<BlurRegion> BLUR_REGIONS_UPDATE;
const String8 DISPLAY_NAME("SurfaceInterceptor Display Test");
constexpr auto TEST_BG_SURFACE_NAME = "BG Interceptor Test Surface";
@@ -181,6 +182,7 @@
bool cornerRadiusUpdateFound(const SurfaceChange& change, bool foundCornerRadius);
bool backgroundBlurRadiusUpdateFound(const SurfaceChange& change,
bool foundBackgroundBlurRadius);
+ bool blurRegionsUpdateFound(const SurfaceChange& change, bool foundBlurRegions);
bool matrixUpdateFound(const SurfaceChange& change, bool foundMatrix);
bool scalingModeUpdateFound(const SurfaceChange& change, bool foundScalingMode);
bool transparentRegionHintUpdateFound(const SurfaceChange& change, bool foundTransparentRegion);
@@ -219,6 +221,7 @@
void cropUpdate(Transaction&);
void cornerRadiusUpdate(Transaction&);
void backgroundBlurRadiusUpdate(Transaction&);
+ void blurRegionsUpdate(Transaction&);
void matrixUpdate(Transaction&);
void transparentRegionHintUpdate(Transaction&);
void layerStackUpdate(Transaction&);
@@ -357,6 +360,12 @@
t.setBackgroundBlurRadius(mBGSurfaceControl, BACKGROUND_BLUR_RADIUS_UPDATE);
}
+void SurfaceInterceptorTest::blurRegionsUpdate(Transaction& t) {
+ BLUR_REGIONS_UPDATE.empty();
+ BLUR_REGIONS_UPDATE.push_back(BlurRegion());
+ t.setBlurRegions(mBGSurfaceControl, BLUR_REGIONS_UPDATE);
+}
+
void SurfaceInterceptorTest::layerUpdate(Transaction& t) {
t.setLayer(mBGSurfaceControl, LAYER_UPDATE);
}
@@ -430,6 +439,7 @@
runInTransaction(&SurfaceInterceptorTest::alphaUpdate);
runInTransaction(&SurfaceInterceptorTest::cornerRadiusUpdate);
runInTransaction(&SurfaceInterceptorTest::backgroundBlurRadiusUpdate);
+ runInTransaction(&SurfaceInterceptorTest::blurRegionsUpdate);
runInTransaction(&SurfaceInterceptorTest::layerUpdate);
runInTransaction(&SurfaceInterceptorTest::cropUpdate);
runInTransaction(&SurfaceInterceptorTest::matrixUpdate);
@@ -518,6 +528,17 @@
return foundBackgroundBlur;
}
+bool SurfaceInterceptorTest::blurRegionsUpdateFound(const SurfaceChange& change,
+ bool foundBlurRegions) {
+ bool hasBlurRegions(change.blur_regions().blur_regions_size() == BLUR_REGIONS_UPDATE.size());
+ if (hasBlurRegions && !foundBlurRegions) {
+ foundBlurRegions = true;
+ } else if (hasBlurRegions && foundBlurRegions) {
+ []() { FAIL(); }();
+ }
+ return foundBlurRegions;
+}
+
bool SurfaceInterceptorTest::layerUpdateFound(const SurfaceChange& change, bool foundLayer) {
bool hasLayer(change.layer().layer() == LAYER_UPDATE);
if (hasLayer && !foundLayer) {
@@ -706,6 +727,9 @@
case SurfaceChange::SurfaceChangeCase::kBackgroundBlurRadius:
foundUpdate = backgroundBlurRadiusUpdateFound(change, foundUpdate);
break;
+ case SurfaceChange::SurfaceChangeCase::kBlurRegions:
+ foundUpdate = blurRegionsUpdateFound(change, foundUpdate);
+ break;
case SurfaceChange::SurfaceChangeCase::kMatrix:
foundUpdate = matrixUpdateFound(change, foundUpdate);
break;
@@ -889,6 +913,11 @@
SurfaceChange::SurfaceChangeCase::kBackgroundBlurRadius);
}
+TEST_F(SurfaceInterceptorTest, InterceptBlurRegionsUpdateWorks) {
+ captureTest(&SurfaceInterceptorTest::blurRegionsUpdate,
+ SurfaceChange::SurfaceChangeCase::kBlurRegions);
+}
+
TEST_F(SurfaceInterceptorTest, InterceptMatrixUpdateWorks) {
captureTest(&SurfaceInterceptorTest::matrixUpdate, SurfaceChange::SurfaceChangeCase::kMatrix);
}