diff options
| -rw-r--r-- | cmds/surfacereplayer/proto/src/trace.proto | 5 | ||||
| -rw-r--r-- | cmds/surfacereplayer/replayer/Replayer.cpp | 8 | ||||
| -rw-r--r-- | cmds/surfacereplayer/replayer/Replayer.h | 2 | ||||
| -rw-r--r-- | services/surfaceflinger/Layer.cpp | 3 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceInterceptor.cpp | 11 | ||||
| -rw-r--r-- | services/surfaceflinger/SurfaceInterceptor.h | 1 | ||||
| -rw-r--r-- | services/surfaceflinger/layerproto/LayerProtoParser.cpp | 8 | ||||
| -rw-r--r-- | services/surfaceflinger/layerproto/include/layerproto/LayerProtoParser.h | 2 | ||||
| -rw-r--r-- | services/surfaceflinger/layerproto/layers.proto | 7 | ||||
| -rw-r--r-- | services/surfaceflinger/tests/SurfaceInterceptor_test.cpp | 27 |
10 files changed, 71 insertions, 3 deletions
diff --git a/cmds/surfacereplayer/proto/src/trace.proto b/cmds/surfacereplayer/proto/src/trace.proto index 792ff91dfa..7f2f94912e 100644 --- a/cmds/surfacereplayer/proto/src/trace.proto +++ b/cmds/surfacereplayer/proto/src/trace.proto @@ -51,6 +51,7 @@ message SurfaceChange { RelativeParentChange relative_parent = 18; DetachChildrenChange detach_children = 19; ReparentChildrenChange reparent_children = 20; + ShadowRadiusChange shadow_radius = 22; } } @@ -199,3 +200,7 @@ message RelativeParentChange { message DetachChildrenChange { required bool detach_children = 1; } + +message ShadowRadiusChange { + required float radius = 1; +}
\ No newline at end of file diff --git a/cmds/surfacereplayer/replayer/Replayer.cpp b/cmds/surfacereplayer/replayer/Replayer.cpp index a4a9b6a6f4..0d6c31ee2f 100644 --- a/cmds/surfacereplayer/replayer/Replayer.cpp +++ b/cmds/surfacereplayer/replayer/Replayer.cpp @@ -424,6 +424,9 @@ status_t Replayer::doSurfaceTransaction( case SurfaceChange::SurfaceChangeCase::kDetachChildren: setDetachChildrenChange(transaction, change.id(), change.detach_children()); break; + case SurfaceChange::SurfaceChangeCase::kShadowRadius: + setShadowRadiusChange(transaction, change.id(), change.shadow_radius()); + break; default: status = 1; break; @@ -724,3 +727,8 @@ void Replayer::setReparentChildrenChange(SurfaceComposerClient::Transaction& t, } t.reparentChildren(mLayers[id], mLayers[c.parent_id()]->getHandle()); } + +void Replayer::setShadowRadiusChange(SurfaceComposerClient::Transaction& t, + layer_id id, const ShadowRadiusChange& c) { + t.setShadowRadius(mLayers[id], c.radius()); +} diff --git a/cmds/surfacereplayer/replayer/Replayer.h b/cmds/surfacereplayer/replayer/Replayer.h index 3b94618acb..b5478344cb 100644 --- a/cmds/surfacereplayer/replayer/Replayer.h +++ b/cmds/surfacereplayer/replayer/Replayer.h @@ -118,6 +118,8 @@ class Replayer { layer_id id, const DetachChildrenChange& c); void setReparentChildrenChange(SurfaceComposerClient::Transaction& t, layer_id id, const ReparentChildrenChange& c); + void setShadowRadiusChange(SurfaceComposerClient::Transaction& t, + layer_id id, const ShadowRadiusChange& c); void setDisplaySurface(SurfaceComposerClient::Transaction& t, display_id id, const DispSurfaceChange& dsc); diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 35fc4be056..bb618ac0a3 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -1935,6 +1935,9 @@ void Layer::writeToProtoDrawingState(LayerProto* layerInfo, uint32_t traceFlags) [&]() { return layerInfo->mutable_source_bounds(); }); LayerProtoHelper::writeToProto(mScreenBounds, [&]() { return layerInfo->mutable_screen_bounds(); }); + LayerProtoHelper::writeToProto(getRoundedCornerState().cropRect, + [&]() { return layerInfo->mutable_corner_radius_crop(); }); + layerInfo->set_shadow_radius(mEffectiveShadowRadius); } } diff --git a/services/surfaceflinger/SurfaceInterceptor.cpp b/services/surfaceflinger/SurfaceInterceptor.cpp index 7e6c472d7f..5e8910a3c5 100644 --- a/services/surfaceflinger/SurfaceInterceptor.cpp +++ b/services/surfaceflinger/SurfaceInterceptor.cpp @@ -124,6 +124,7 @@ void SurfaceInterceptor::addInitialSurfaceStateLocked(Increment* increment, addRelativeParentLocked(transaction, layerId, getLayerIdFromWeakRef(layer->mCurrentState.zOrderRelativeOf), layer->mCurrentState.z); + addShadowRadiusLocked(transaction, layerId, layer->mCurrentState.shadowRadius); } void SurfaceInterceptor::addInitialDisplayStateLocked(Increment* increment, @@ -368,6 +369,13 @@ void SurfaceInterceptor::addRelativeParentLocked(Transaction* transaction, int32 overrideChange->set_z(z); } +void SurfaceInterceptor::addShadowRadiusLocked(Transaction* transaction, int32_t layerId, + float shadowRadius) { + SurfaceChange* change(createSurfaceChangeLocked(transaction, layerId)); + ShadowRadiusChange* overrideChange(change->mutable_shadow_radius()); + overrideChange->set_radius(shadowRadius); +} + void SurfaceInterceptor::addSurfaceChangesLocked(Transaction* transaction, const layer_state_t& state) { @@ -441,6 +449,9 @@ void SurfaceInterceptor::addSurfaceChangesLocked(Transaction* transaction, addRelativeParentLocked(transaction, layerId, getLayerIdFromHandle(state.relativeLayerHandle), state.z); } + if (state.what & layer_state_t::eShadowRadiusChanged) { + addShadowRadiusLocked(transaction, layerId, state.shadowRadius); + } } void SurfaceInterceptor::addDisplayChangesLocked(Transaction* transaction, diff --git a/services/surfaceflinger/SurfaceInterceptor.h b/services/surfaceflinger/SurfaceInterceptor.h index 72b734b8fd..c6f9e8a9a1 100644 --- a/services/surfaceflinger/SurfaceInterceptor.h +++ b/services/surfaceflinger/SurfaceInterceptor.h @@ -165,6 +165,7 @@ private: void addDetachChildrenLocked(Transaction* transaction, int32_t layerId, bool detached); void addRelativeParentLocked(Transaction* transaction, int32_t layerId, int32_t parentId, int z); + void addShadowRadiusLocked(Transaction* transaction, int32_t layerId, float shadowRadius); // Add display transactions to the trace DisplayChange* createDisplayChangeLocked(Transaction* transaction, int32_t sequenceId); diff --git a/services/surfaceflinger/layerproto/LayerProtoParser.cpp b/services/surfaceflinger/layerproto/LayerProtoParser.cpp index ef488bd881..ef27847e55 100644 --- a/services/surfaceflinger/layerproto/LayerProtoParser.cpp +++ b/services/surfaceflinger/layerproto/LayerProtoParser.cpp @@ -112,7 +112,8 @@ LayerProtoParser::Layer LayerProtoParser::generateLayer(const LayerProto& layerP outData.resize(dataStr.size()); memcpy(outData.data(), dataStr.data(), dataStr.size()); } - + layer.cornerRadiusCrop = generateFloatRect(layerProto.corner_radius_crop()); + layer.shadowRadius = layerProto.shadow_radius(); return layer; } @@ -307,8 +308,9 @@ std::string LayerProtoParser::Layer::to_string() const { first = false; result.append(metadata.itemToString(entry.first, ":")); } - result.append("}"); - + result.append("},"); + StringAppendF(&result, " cornerRadiusCrop=%s, ", cornerRadiusCrop.to_string().c_str()); + StringAppendF(&result, " shadowRadius=%.3f, ", shadowRadius); return result; } diff --git a/services/surfaceflinger/layerproto/include/layerproto/LayerProtoParser.h b/services/surfaceflinger/layerproto/include/layerproto/LayerProtoParser.h index 54e02cadee..774b0e15f0 100644 --- a/services/surfaceflinger/layerproto/include/layerproto/LayerProtoParser.h +++ b/services/surfaceflinger/layerproto/include/layerproto/LayerProtoParser.h @@ -111,6 +111,8 @@ public: bool isProtected; float cornerRadius; LayerMetadata metadata; + LayerProtoParser::FloatRect cornerRadiusCrop; + float shadowRadius; std::string to_string() const; }; diff --git a/services/surfaceflinger/layerproto/layers.proto b/services/surfaceflinger/layerproto/layers.proto index c7fbff37da..9ad9b91a9a 100644 --- a/services/surfaceflinger/layerproto/layers.proto +++ b/services/surfaceflinger/layerproto/layers.proto @@ -94,6 +94,13 @@ message LayerProto { FloatRectProto screen_bounds = 46; InputWindowInfoProto input_window_info = 47; + + // Crop used to draw the rounded corner. + FloatRectProto corner_radius_crop = 48; + + // length of the shadow to draw around the layer, it may be set on the + // layer or set by a parent layer. + float shadow_radius = 49; } message PositionProto { diff --git a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp index 59e9c00ae7..1fa426d14e 100644 --- a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp +++ b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp @@ -51,6 +51,7 @@ constexpr float ALPHA_UPDATE = 0.29f; constexpr float CORNER_RADIUS_UPDATE = 0.2f; constexpr float POSITION_UPDATE = 121; const Rect CROP_UPDATE(16, 16, 32, 32); +const float SHADOW_RADIUS_UPDATE = 35.0f; const String8 DISPLAY_NAME("SurfaceInterceptor Display Test"); constexpr auto TEST_BG_SURFACE_NAME = "BG Interceptor Test Surface"; @@ -190,6 +191,7 @@ public: bool relativeParentUpdateFound(const SurfaceChange& change, bool found); bool detachChildrenUpdateFound(const SurfaceChange& change, bool found); bool reparentChildrenUpdateFound(const SurfaceChange& change, bool found); + bool shadowRadiusUpdateFound(const SurfaceChange& change, bool found); bool surfaceUpdateFound(const Trace& trace, SurfaceChange::SurfaceChangeCase changeCase); // Find all of the updates in the single trace @@ -226,6 +228,7 @@ public: void relativeParentUpdate(Transaction&); void detachChildrenUpdate(Transaction&); void reparentChildrenUpdate(Transaction&); + void shadowRadiusUpdate(Transaction&); void surfaceCreation(Transaction&); void displayCreation(Transaction&); void displayDeletion(Transaction&); @@ -406,6 +409,10 @@ void SurfaceInterceptorTest::reparentChildrenUpdate(Transaction& t) { t.reparentChildren(mBGSurfaceControl, mFGSurfaceControl->getHandle()); } +void SurfaceInterceptorTest::shadowRadiusUpdate(Transaction& t) { + t.setShadowRadius(mBGSurfaceControl, SHADOW_RADIUS_UPDATE); +} + void SurfaceInterceptorTest::displayCreation(Transaction&) { sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, true); SurfaceComposerClient::destroyDisplay(testDisplay); @@ -435,6 +442,7 @@ void SurfaceInterceptorTest::runAllUpdates() { runInTransaction(&SurfaceInterceptorTest::reparentChildrenUpdate); runInTransaction(&SurfaceInterceptorTest::detachChildrenUpdate); runInTransaction(&SurfaceInterceptorTest::relativeParentUpdate); + runInTransaction(&SurfaceInterceptorTest::shadowRadiusUpdate); } void SurfaceInterceptorTest::surfaceCreation(Transaction&) { @@ -655,6 +663,17 @@ bool SurfaceInterceptorTest::reparentChildrenUpdateFound(const SurfaceChange& ch return found; } +bool SurfaceInterceptorTest::shadowRadiusUpdateFound(const SurfaceChange& change, + bool foundShadowRadius) { + bool hasShadowRadius(change.shadow_radius().radius() == SHADOW_RADIUS_UPDATE); + if (hasShadowRadius && !foundShadowRadius) { + foundShadowRadius = true; + } else if (hasShadowRadius && foundShadowRadius) { + []() { FAIL(); }(); + } + return foundShadowRadius; +} + bool SurfaceInterceptorTest::surfaceUpdateFound(const Trace& trace, SurfaceChange::SurfaceChangeCase changeCase) { bool foundUpdate = false; @@ -718,6 +737,9 @@ bool SurfaceInterceptorTest::surfaceUpdateFound(const Trace& trace, case SurfaceChange::SurfaceChangeCase::kDetachChildren: foundUpdate = detachChildrenUpdateFound(change, foundUpdate); break; + case SurfaceChange::SurfaceChangeCase::kShadowRadius: + foundUpdate = shadowRadiusUpdateFound(change, foundUpdate); + break; case SurfaceChange::SurfaceChangeCase::SURFACECHANGE_NOT_SET: break; } @@ -920,6 +942,11 @@ TEST_F(SurfaceInterceptorTest, InterceptDetachChildrenUpdateWorks) { SurfaceChange::SurfaceChangeCase::kDetachChildren); } +TEST_F(SurfaceInterceptorTest, InterceptShadowRadiusUpdateWorks) { + captureTest(&SurfaceInterceptorTest::shadowRadiusUpdate, + SurfaceChange::SurfaceChangeCase::kShadowRadius); +} + TEST_F(SurfaceInterceptorTest, InterceptAllUpdatesWorks) { captureTest(&SurfaceInterceptorTest::runAllUpdates, &SurfaceInterceptorTest::assertAllUpdatesFound); |