diff options
author | 2024-08-15 16:29:20 +0000 | |
---|---|---|
committer | 2024-09-10 02:25:14 +0000 | |
commit | dc83d4b7ba27a5096e19884b548eb05e432bc3f2 (patch) | |
tree | 4270c175f8ce617bf3bf3cc30f4e09b59f2192cf | |
parent | 812dcabff8b4ff8cdc9efa0414001be6d44a7df8 (diff) |
Remove legacy layer states!
Remove all the unused layer states. Buffer info, frame rate and a few
lingering states remain. But the intention is to completely remove the
legacy layer class and prevent it from being a catch all super class again.
Flag: EXEMPT flag removal
Bug: 330785038
Test: presubmit
Change-Id: I8ce0bf0b0bcc7c69c7d397d0ffb1639a6dc4979a
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 1904 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.h | 496 | ||||
-rw-r--r-- | services/surfaceflinger/LayerProtoHelper.cpp | 11 | ||||
-rw-r--r-- | services/surfaceflinger/LayerProtoHelper.h | 2 | ||||
-rw-r--r-- | services/surfaceflinger/LayerVector.cpp | 10 | ||||
-rw-r--r-- | services/surfaceflinger/RenderArea.h | 15 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 7 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 1 | ||||
-rw-r--r-- | services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h | 11 | ||||
-rw-r--r-- | services/surfaceflinger/tests/unittests/mock/MockLayer.h | 4 |
10 files changed, 24 insertions, 2437 deletions
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 3c8af19015..c8bb068fa9 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -60,9 +60,7 @@ #include <utils/StopWatch.h> #include <algorithm> -#include <mutex> #include <optional> -#include <sstream> #include "DisplayDevice.h" #include "DisplayHardware/HWComposer.h" @@ -72,7 +70,6 @@ #include "FrontEnd/LayerHandle.h" #include "Layer.h" #include "LayerProtoHelper.h" -#include "MutexUtils.h" #include "SurfaceFlinger.h" #include "TimeStats/TimeStats.h" #include "TransactionCallbackInvoker.h" @@ -89,18 +86,6 @@ constexpr int kDumpTableRowLength = 159; const ui::Transform kIdentityTransform; -ui::LogicalDisplayId toLogicalDisplayId(const ui::LayerStack& layerStack) { - return ui::LogicalDisplayId{static_cast<int32_t>(layerStack.id)}; -} - -bool assignTransform(ui::Transform* dst, ui::Transform& from) { - if (*dst == from) { - return false; - } - *dst = from; - return true; -} - TimeStats::SetFrameRateVote frameRateToSetFrameRateVotePayload(Layer::FrameRate frameRate) { using FrameRateCompatibility = TimeStats::SetFrameRateVote::FrameRateCompatibility; using Seamlessness = TimeStats::SetFrameRateVote::Seamlessness; @@ -149,24 +134,11 @@ Layer::Layer(const surfaceflinger::LayerCreationArgs& args) : sequence(args.sequence), mFlinger(sp<SurfaceFlinger>::fromExisting(args.flinger)), mName(base::StringPrintf("%s#%d", args.name.c_str(), sequence)), - mClientRef(args.client), mWindowType(static_cast<WindowInfo::Type>( - args.metadata.getInt32(gui::METADATA_WINDOW_TYPE, 0))), - mLayerCreationFlags(args.flags), - mLegacyLayerFE(args.flinger->getFactory().createLayerFE(mName, this)) { + args.metadata.getInt32(gui::METADATA_WINDOW_TYPE, 0))) { ALOGV("Creating Layer %s", getDebugName()); - uint32_t layerFlags = 0; - if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden; - if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque; - if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure; - if (args.flags & ISurfaceComposerClient::eSkipScreenshot) - layerFlags |= layer_state_t::eLayerSkipScreenshot; - mDrawingState.flags = layerFlags; mDrawingState.crop.makeInvalid(); - mDrawingState.z = 0; - mDrawingState.color.a = 1.0f; - mDrawingState.layerStack = ui::DEFAULT_LAYER_STACK; mDrawingState.sequence = 0; mDrawingState.transform.set(0, 0); mDrawingState.frameNumber = 0; @@ -179,33 +151,9 @@ Layer::Layer(const surfaceflinger::LayerCreationArgs& args) mDrawingState.acquireFence = sp<Fence>::make(-1); mDrawingState.acquireFenceTime = std::make_shared<FenceTime>(mDrawingState.acquireFence); mDrawingState.dataspace = ui::Dataspace::V0_SRGB; - mDrawingState.hdrMetadata.validTypes = 0; - mDrawingState.surfaceDamageRegion = Region::INVALID_REGION; - mDrawingState.cornerRadius = 0.0f; - mDrawingState.backgroundBlurRadius = 0; - mDrawingState.api = -1; - mDrawingState.hasColorTransform = false; - mDrawingState.colorSpaceAgnostic = false; - mDrawingState.frameRateSelectionPriority = PRIORITY_UNSET; mDrawingState.metadata = args.metadata; - mDrawingState.shadowRadius = 0.f; - mDrawingState.fixedTransformHint = ui::Transform::ROT_INVALID; mDrawingState.frameTimelineInfo = {}; mDrawingState.postTime = -1; - mDrawingState.destinationFrame.makeInvalid(); - mDrawingState.isTrustedOverlay = false; - mDrawingState.dropInputMode = gui::DropInputMode::NONE; - mDrawingState.dimmingEnabled = true; - mDrawingState.defaultFrameRateCompatibility = FrameRateCompatibility::Default; - mDrawingState.frameRateSelectionStrategy = FrameRateSelectionStrategy::Propagate; - - if (args.flags & ISurfaceComposerClient::eNoColorFill) { - // Set an invalid color so there is no color fill. - mDrawingState.color.r = -1.0_hf; - mDrawingState.color.g = -1.0_hf; - mDrawingState.color.b = -1.0_hf; - } - mFrameTracker.setDisplayRefreshPeriod( args.flinger->mScheduler->getPacesetterVsyncPeriod().ns()); @@ -213,14 +161,9 @@ Layer::Layer(const surfaceflinger::LayerCreationArgs& args) mOwnerPid = args.ownerPid; mOwnerAppId = mOwnerUid % PER_USER_RANGE; - mPremultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied); mPotentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow; - mProtectedByApp = args.flags & ISurfaceComposerClient::eProtectedByApp; - - mSnapshot->sequence = sequence; - mSnapshot->name = getDebugName(); - mSnapshot->premultipliedAlpha = mPremultipliedAlpha; - mSnapshot->parentTransform = {}; + mLayerFEs.emplace_back(frontend::LayerHierarchy::TraversalPath{static_cast<uint32_t>(sequence)}, + args.flinger->getFactory().createLayerFE(mName, this)); } void Layer::onFirstRef() { @@ -253,35 +196,8 @@ Layer::~Layer() { } // --------------------------------------------------------------------------- -// callbacks -// --------------------------------------------------------------------------- - -void Layer::removeRelativeZ(const std::vector<Layer*>& layersInTree) { - if (mDrawingState.zOrderRelativeOf == nullptr) { - return; - } - - sp<Layer> strongRelative = mDrawingState.zOrderRelativeOf.promote(); - if (strongRelative == nullptr) { - setZOrderRelativeOf(nullptr); - return; - } - - if (!std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) { - strongRelative->removeZOrderRelative(wp<Layer>::fromExisting(this)); - mFlinger->setTransactionFlags(eTraversalNeeded); - setZOrderRelativeOf(nullptr); - } -} - -// --------------------------------------------------------------------------- // set-up // --------------------------------------------------------------------------- - -bool Layer::getPremultipledAlpha() const { - return mPremultipliedAlpha; -} - sp<IBinder> Layer::getHandle() { Mutex::Autolock _l(mLock); if (mGetHandleCalled) { @@ -297,46 +213,6 @@ sp<IBinder> Layer::getHandle() { // h/w composer set-up // --------------------------------------------------------------------------- -static Rect reduce(const Rect& win, const Region& exclude) { - if (CC_LIKELY(exclude.isEmpty())) { - return win; - } - if (exclude.isRect()) { - return win.reduce(exclude.getBounds()); - } - return Region(win).subtract(exclude).getBounds(); -} - -static FloatRect reduce(const FloatRect& win, const Region& exclude) { - if (CC_LIKELY(exclude.isEmpty())) { - return win; - } - // Convert through Rect (by rounding) for lack of FloatRegion - return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect(); -} - -Rect Layer::getScreenBounds(bool reduceTransparentRegion) const { - if (!reduceTransparentRegion) { - return Rect{mScreenBounds}; - } - - FloatRect bounds = getBounds(); - ui::Transform t = getTransform(); - // Transform to screen space. - bounds = t.transform(bounds); - return Rect{bounds}; -} - -FloatRect Layer::getBounds() const { - const State& s(getDrawingState()); - return getBounds(getActiveTransparentRegion(s)); -} - -FloatRect Layer::getBounds(const Region& activeTransparentRegion) const { - // Subtract the transparent region and snap to the bounds. - return reduce(mBounds, activeTransparentRegion); -} - // No early returns. void Layer::updateTrustedPresentationState(const DisplayDevice* display, const frontend::LayerSnapshot* snapshot, @@ -438,57 +314,6 @@ bool Layer::computeTrustedPresentationState(const FloatRect& bounds, const Float return true; } -void Layer::computeBounds(FloatRect parentBounds, ui::Transform parentTransform, - float parentShadowRadius) { - const State& s(getDrawingState()); - - // Calculate effective layer transform - mEffectiveTransform = parentTransform * getActiveTransform(s); - - if (CC_UNLIKELY(!isTransformValid())) { - ALOGW("Stop computing bounds for %s because it has invalid transformation.", - getDebugName()); - return; - } - - // Transform parent bounds to layer space - parentBounds = getActiveTransform(s).inverse().transform(parentBounds); - - // Calculate source bounds - mSourceBounds = computeSourceBounds(parentBounds); - - // Calculate bounds by croping diplay frame with layer crop and parent bounds - FloatRect bounds = mSourceBounds; - const Rect layerCrop = getCrop(s); - if (!layerCrop.isEmpty()) { - bounds = mSourceBounds.intersect(layerCrop.toFloatRect()); - } - bounds = bounds.intersect(parentBounds); - - mBounds = bounds; - mScreenBounds = mEffectiveTransform.transform(mBounds); - - // Use the layer's own shadow radius if set. Otherwise get the radius from - // parent. - if (s.shadowRadius > 0.f) { - mEffectiveShadowRadius = s.shadowRadius; - } else { - mEffectiveShadowRadius = parentShadowRadius; - } - - // Shadow radius is passed down to only one layer so if the layer can draw shadows, - // don't pass it to its children. - const float childShadowRadius = canDrawShadows() ? 0.f : mEffectiveShadowRadius; - - for (const sp<Layer>& child : mDrawingChildren) { - child->computeBounds(mBounds, mEffectiveTransform, childShadowRadius); - } - - if (mPotentialCursor) { - prepareCursorCompositionState(); - } -} - Rect Layer::getCroppedBufferSize(const State& s) const { Rect size = getBufferSize(s); Rect crop = getCrop(s); @@ -500,180 +325,6 @@ Rect Layer::getCroppedBufferSize(const State& s) const { return size; } -void Layer::setupRoundedCornersCropCoordinates(Rect win, - const FloatRect& roundedCornersCrop) const { - // Translate win by the rounded corners rect coordinates, to have all values in - // layer coordinate space. - win.left -= roundedCornersCrop.left; - win.right -= roundedCornersCrop.left; - win.top -= roundedCornersCrop.top; - win.bottom -= roundedCornersCrop.top; -} - -void Layer::prepareBasicGeometryCompositionState() { - const auto& drawingState{getDrawingState()}; - const auto alpha = static_cast<float>(getAlpha()); - const bool opaque = isOpaque(drawingState); - const bool usesRoundedCorners = hasRoundedCorners(); - - auto blendMode = Hwc2::IComposerClient::BlendMode::NONE; - if (!opaque || alpha != 1.0f) { - blendMode = mPremultipliedAlpha ? Hwc2::IComposerClient::BlendMode::PREMULTIPLIED - : Hwc2::IComposerClient::BlendMode::COVERAGE; - } - - // Please keep in sync with LayerSnapshotBuilder - auto* snapshot = editLayerSnapshot(); - snapshot->outputFilter = getOutputFilter(); - snapshot->isVisible = isVisible(); - snapshot->isOpaque = opaque && !usesRoundedCorners && alpha == 1.f; - snapshot->shadowSettings.length = mEffectiveShadowRadius; - - snapshot->contentDirty = contentDirty; - contentDirty = false; - - snapshot->geomLayerBounds = mBounds; - snapshot->geomLayerTransform = getTransform(); - snapshot->geomInverseLayerTransform = snapshot->geomLayerTransform.inverse(); - snapshot->transparentRegionHint = getActiveTransparentRegion(drawingState); - snapshot->localTransform = getActiveTransform(drawingState); - snapshot->localTransformInverse = snapshot->localTransform.inverse(); - snapshot->blendMode = static_cast<Hwc2::IComposerClient::BlendMode>(blendMode); - snapshot->alpha = alpha; - snapshot->backgroundBlurRadius = getBackgroundBlurRadius(); - snapshot->blurRegions = getBlurRegions(); -} - -void Layer::prepareGeometryCompositionState() { - const auto& drawingState{getDrawingState()}; - auto* snapshot = editLayerSnapshot(); - - // Please keep in sync with LayerSnapshotBuilder - snapshot->geomBufferSize = getBufferSize(drawingState); - snapshot->geomContentCrop = getBufferCrop(); - snapshot->geomCrop = getCrop(drawingState); - snapshot->geomBufferTransform = getBufferTransform(); - snapshot->geomBufferUsesDisplayInverseTransform = getTransformToDisplayInverse(); - snapshot->geomUsesSourceCrop = usesSourceCrop(); - snapshot->isSecure = isSecure(); - - snapshot->metadata.clear(); - const auto& supportedMetadata = mFlinger->getHwComposer().getSupportedLayerGenericMetadata(); - for (const auto& [key, mandatory] : supportedMetadata) { - const auto& genericLayerMetadataCompatibilityMap = - mFlinger->getGenericLayerMetadataKeyMap(); - auto compatIter = genericLayerMetadataCompatibilityMap.find(key); - if (compatIter == std::end(genericLayerMetadataCompatibilityMap)) { - continue; - } - const uint32_t id = compatIter->second; - - auto it = drawingState.metadata.mMap.find(id); - if (it == std::end(drawingState.metadata.mMap)) { - continue; - } - - snapshot->metadata.emplace(key, - compositionengine::GenericLayerMetadataEntry{mandatory, - it->second}); - } -} - -void Layer::preparePerFrameCompositionState() { - const auto& drawingState{getDrawingState()}; - // Please keep in sync with LayerSnapshotBuilder - auto* snapshot = editLayerSnapshot(); - - snapshot->forceClientComposition = false; - - snapshot->isColorspaceAgnostic = isColorSpaceAgnostic(); - snapshot->dataspace = getDataSpace(); - snapshot->colorTransform = getColorTransform(); - snapshot->colorTransformIsIdentity = !hasColorTransform(); - snapshot->surfaceDamage = surfaceDamageRegion; - snapshot->hasProtectedContent = isProtected(); - snapshot->dimmingEnabled = isDimmingEnabled(); - snapshot->currentHdrSdrRatio = getCurrentHdrSdrRatio(); - snapshot->desiredHdrSdrRatio = getDesiredHdrSdrRatio(); - snapshot->cachingHint = getCachingHint(); - - const bool usesRoundedCorners = hasRoundedCorners(); - - snapshot->isOpaque = isOpaque(drawingState) && !usesRoundedCorners && getAlpha() == 1.0_hf; - - // Force client composition for special cases known only to the front-end. - // Rounded corners no longer force client composition, since we may use a - // hole punch so that the layer will appear to have rounded corners. - if (drawShadows() || snapshot->stretchEffect.hasEffect()) { - snapshot->forceClientComposition = true; - } - // If there are no visible region changes, we still need to update blur parameters. - snapshot->blurRegions = getBlurRegions(); - snapshot->backgroundBlurRadius = getBackgroundBlurRadius(); - - // Layer framerate is used in caching decisions. - // Retrieve it from the scheduler which maintains an instance of LayerHistory, and store it in - // LayerFECompositionState where it would be visible to Flattener. - snapshot->fps = mFlinger->getLayerFramerate(systemTime(), getSequence()); - - if (hasBufferOrSidebandStream()) { - preparePerFrameBufferCompositionState(); - } else { - preparePerFrameEffectsCompositionState(); - } -} - -void Layer::preparePerFrameBufferCompositionState() { - // Please keep in sync with LayerSnapshotBuilder - auto* snapshot = editLayerSnapshot(); - // Sideband layers - if (snapshot->sidebandStream.get() && !snapshot->sidebandStreamHasFrame) { - snapshot->compositionType = - aidl::android::hardware::graphics::composer3::Composition::SIDEBAND; - return; - } else if ((mDrawingState.flags & layer_state_t::eLayerIsDisplayDecoration) != 0) { - snapshot->compositionType = - aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION; - } else if ((mDrawingState.flags & layer_state_t::eLayerIsRefreshRateIndicator) != 0) { - snapshot->compositionType = - aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR; - } else { - // Normal buffer layers - snapshot->hdrMetadata = mBufferInfo.mHdrMetadata; - snapshot->compositionType = mPotentialCursor - ? aidl::android::hardware::graphics::composer3::Composition::CURSOR - : aidl::android::hardware::graphics::composer3::Composition::DEVICE; - } - - snapshot->buffer = getBuffer(); - snapshot->acquireFence = mBufferInfo.mFence; - snapshot->frameNumber = mBufferInfo.mFrameNumber; - snapshot->sidebandStreamHasFrame = false; -} - -void Layer::preparePerFrameEffectsCompositionState() { - // Please keep in sync with LayerSnapshotBuilder - auto* snapshot = editLayerSnapshot(); - snapshot->color = getColor(); - snapshot->compositionType = - aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR; -} - -void Layer::prepareCursorCompositionState() { - const State& drawingState{getDrawingState()}; - // Please keep in sync with LayerSnapshotBuilder - auto* snapshot = editLayerSnapshot(); - - // Apply the layer's transform, followed by the display's global transform - // Here we're guaranteed that the layer's transform preserves rects - Rect win = getCroppedBufferSize(drawingState); - // Subtract the transparent region and snap to the bounds - Rect bounds = reduce(win, getActiveTransparentRegion(drawingState)); - Rect frame(getTransform().transform(bounds)); - - snapshot->cursorFrame = frame; -} - const char* Layer::getDebugName() const { return mName.c_str(); } @@ -701,45 +352,18 @@ aidl::android::hardware::graphics::composer3::Composition Layer::getCompositionT } // ---------------------------------------------------------------------------- -// local state -// ---------------------------------------------------------------------------- - -bool Layer::isSecure() const { - const State& s(mDrawingState); - if (s.flags & layer_state_t::eLayerSecure) { - return true; - } - - const auto p = mDrawingParent.promote(); - return (p != nullptr) ? p->isSecure() : false; -} - -// ---------------------------------------------------------------------------- // transaction // ---------------------------------------------------------------------------- uint32_t Layer::doTransaction(uint32_t flags) { SFTRACE_CALL(); - // TODO: This is unfortunate. - mDrawingStateModified = mDrawingState.modified; - mDrawingState.modified = false; - const State& s(getDrawingState()); - if (updateGeometry()) { - // invalidate and recompute the visible regions if needed - flags |= Layer::eVisibleRegion; - } - if (s.sequence != mLastCommittedTxSequence) { // invalidate and recompute the visible regions if needed mLastCommittedTxSequence = s.sequence; flags |= eVisibleRegion; - this->contentDirty = true; - - // we may use linear filtering, if the matrix scales us - mNeedsFiltering = getActiveTransform(s).needsBilinearFiltering(); } if (!mPotentialCursor && (flags & Layer::eVisibleRegion)) { @@ -775,208 +399,11 @@ void Layer::setTransactionFlags(uint32_t mask) { mTransactionFlags |= mask; } -bool Layer::setLayer(int32_t z) { - if (mDrawingState.z == z && !usingRelativeZ(LayerVector::StateSet::Current)) return false; - mDrawingState.sequence++; - mDrawingState.z = z; - mDrawingState.modified = true; - - mFlinger->mSomeChildrenChanged = true; - - // Discard all relative layering. - if (mDrawingState.zOrderRelativeOf != nullptr) { - sp<Layer> strongRelative = mDrawingState.zOrderRelativeOf.promote(); - if (strongRelative != nullptr) { - strongRelative->removeZOrderRelative(wp<Layer>::fromExisting(this)); - } - setZOrderRelativeOf(nullptr); - } - setTransactionFlags(eTransactionNeeded); - return true; -} - -void Layer::removeZOrderRelative(const wp<Layer>& relative) { - mDrawingState.zOrderRelatives.remove(relative); - mDrawingState.sequence++; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); -} - -void Layer::addZOrderRelative(const wp<Layer>& relative) { - mDrawingState.zOrderRelatives.add(relative); - mDrawingState.modified = true; - mDrawingState.sequence++; - setTransactionFlags(eTransactionNeeded); -} - -void Layer::setZOrderRelativeOf(const wp<Layer>& relativeOf) { - mDrawingState.zOrderRelativeOf = relativeOf; - mDrawingState.sequence++; - mDrawingState.modified = true; - mDrawingState.isRelativeOf = relativeOf != nullptr; - - setTransactionFlags(eTransactionNeeded); -} - -bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ) { - sp<Layer> relative = LayerHandle::getLayer(relativeToHandle); - if (relative == nullptr) { - return false; - } - - if (mDrawingState.z == relativeZ && usingRelativeZ(LayerVector::StateSet::Current) && - mDrawingState.zOrderRelativeOf == relative) { - return false; - } - - if (CC_UNLIKELY(relative->usingRelativeZ(LayerVector::StateSet::Drawing)) && - (relative->mDrawingState.zOrderRelativeOf == this)) { - ALOGE("Detected relative layer loop between %s and %s", - mName.c_str(), relative->mName.c_str()); - ALOGE("Ignoring new call to set relative layer"); - return false; - } - - mFlinger->mSomeChildrenChanged = true; - - mDrawingState.sequence++; - mDrawingState.modified = true; - mDrawingState.z = relativeZ; - - auto oldZOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote(); - if (oldZOrderRelativeOf != nullptr) { - oldZOrderRelativeOf->removeZOrderRelative(wp<Layer>::fromExisting(this)); - } - setZOrderRelativeOf(relative); - relative->addZOrderRelative(wp<Layer>::fromExisting(this)); - - setTransactionFlags(eTransactionNeeded); - - return true; -} - -bool Layer::setTrustedOverlay(bool isTrustedOverlay) { - if (mDrawingState.isTrustedOverlay == isTrustedOverlay) return false; - mDrawingState.isTrustedOverlay = isTrustedOverlay; - mDrawingState.modified = true; - mFlinger->mUpdateInputInfo = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::isTrustedOverlay() const { - if (getDrawingState().isTrustedOverlay) { - return true; - } - const auto& p = mDrawingParent.promote(); - return (p != nullptr) && p->isTrustedOverlay(); -} - -bool Layer::setAlpha(float alpha) { - if (mDrawingState.color.a == alpha) return false; - mDrawingState.sequence++; - mDrawingState.color.a = alpha; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setCornerRadius(float cornerRadius) { - if (mDrawingState.cornerRadius == cornerRadius) return false; - - mDrawingState.sequence++; - mDrawingState.cornerRadius = cornerRadius; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setBackgroundBlurRadius(int backgroundBlurRadius) { - if (mDrawingState.backgroundBlurRadius == backgroundBlurRadius) return false; - // If we start or stop drawing blur then the layer's visibility state may change so increment - // the magic sequence number. - if (mDrawingState.backgroundBlurRadius == 0 || backgroundBlurRadius == 0) { - mDrawingState.sequence++; - } - mDrawingState.backgroundBlurRadius = backgroundBlurRadius; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setTransparentRegionHint(const Region& transparent) { - mDrawingState.sequence++; - mDrawingState.transparentRegionHint = transparent; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setBlurRegions(const std::vector<BlurRegion>& blurRegions) { - // If we start or stop drawing blur then the layer's visibility state may change so increment - // the magic sequence number. - if (mDrawingState.blurRegions.size() == 0 || blurRegions.size() == 0) { - mDrawingState.sequence++; - } - mDrawingState.blurRegions = blurRegions; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setFlags(uint32_t flags, uint32_t mask) { - const uint32_t newFlags = (mDrawingState.flags & ~mask) | (flags & mask); - if (mDrawingState.flags == newFlags) return false; - mDrawingState.sequence++; - mDrawingState.flags = newFlags; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - bool Layer::setCrop(const Rect& crop) { if (mDrawingState.crop == crop) return false; mDrawingState.sequence++; mDrawingState.crop = crop; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setMetadata(const LayerMetadata& data) { - if (!mDrawingState.metadata.merge(data, true /* eraseEmpty */)) return false; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setLayerStack(ui::LayerStack layerStack) { - if (mDrawingState.layerStack == layerStack) return false; - mDrawingState.sequence++; - mDrawingState.layerStack = layerStack; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setColorSpaceAgnostic(const bool agnostic) { - if (mDrawingState.colorSpaceAgnostic == agnostic) { - return false; - } - mDrawingState.sequence++; - mDrawingState.colorSpaceAgnostic = agnostic; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setDimmingEnabled(const bool dimmingEnabled) { - if (mDrawingState.dimmingEnabled == dimmingEnabled) return false; - - mDrawingState.sequence++; - mDrawingState.dimmingEnabled = dimmingEnabled; - mDrawingState.modified = true; setTransactionFlags(eTransactionNeeded); return true; } @@ -985,52 +412,6 @@ bool Layer::isLayerFocusedBasedOnPriority(int32_t priority) { return priority == PRIORITY_FOCUSED_WITH_MODE || priority == PRIORITY_FOCUSED_WITHOUT_MODE; }; -ui::LayerStack Layer::getLayerStack(LayerVector::StateSet state) const { - bool useDrawing = state == LayerVector::StateSet::Drawing; - const auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote(); - if (parent) { - return parent->getLayerStack(); - } - return getDrawingState().layerStack; -} - -bool Layer::setShadowRadius(float shadowRadius) { - if (mDrawingState.shadowRadius == shadowRadius) { - return false; - } - - mDrawingState.sequence++; - mDrawingState.shadowRadius = shadowRadius; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint) { - if (mDrawingState.fixedTransformHint == fixedTransformHint) { - return false; - } - - mDrawingState.sequence++; - mDrawingState.fixedTransformHint = fixedTransformHint; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setStretchEffect(const StretchEffect& effect) { - StretchEffect temp = effect; - temp.sanitize(); - if (mDrawingState.stretchEffect == temp) { - return false; - } - mDrawingState.sequence++; - mDrawingState.stretchEffect = temp; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - void Layer::setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode) { mDrawingState.postTime = postTime; @@ -1059,7 +440,6 @@ void Layer::setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInf gui::GameMode gameMode) { mDrawingState.frameTimelineInfo = info; mDrawingState.postTime = postTime; - mDrawingState.modified = true; setTransactionFlags(eTransactionNeeded); if (const auto& bufferSurfaceFrameTX = mDrawingState.bufferSurfaceFrameTX; @@ -1181,40 +561,6 @@ Layer::FrameRate Layer::getFrameRateForLayerTree() const { return getDrawingState().frameRateForLayerTree; } -bool Layer::isHiddenByPolicy() const { - const State& s(mDrawingState); - const auto& parent = mDrawingParent.promote(); - if (parent != nullptr && parent->isHiddenByPolicy()) { - return true; - } - if (usingRelativeZ(LayerVector::StateSet::Drawing)) { - auto zOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote(); - if (zOrderRelativeOf != nullptr) { - if (zOrderRelativeOf->isHiddenByPolicy()) { - return true; - } - } - } - if (CC_UNLIKELY(!isTransformValid())) { - ALOGW("Hide layer %s because it has invalid transformation.", getDebugName()); - return true; - } - return s.flags & layer_state_t::eLayerHidden; -} - -uint32_t Layer::getEffectiveUsage(uint32_t usage) const { - // TODO: should we do something special if mSecure is set? - if (mProtectedByApp) { - // need a hardware-protected path to external video sink - usage |= GraphicBuffer::USAGE_PROTECTED; - } - if (mPotentialCursor) { - usage |= GraphicBuffer::USAGE_CURSOR; - } - usage |= GraphicBuffer::USAGE_HW_COMPOSER; - return usage; -} - // ---------------------------------------------------------------------------- // debugging // ---------------------------------------------------------------------------- @@ -1293,248 +639,12 @@ void Layer::getFrameStats(FrameStats* outStats) const { mFrameTracker.getStats(outStats); } -void Layer::dumpOffscreenDebugInfo(std::string& result) const { - std::string hasBuffer = hasBufferOrSidebandStream() ? " (contains buffer)" : ""; - StringAppendF(&result, "Layer %s%s pid:%d uid:%d%s\n", getName().c_str(), hasBuffer.c_str(), - mOwnerPid, mOwnerUid, isHandleAlive() ? " handleAlive" : ""); -} - void Layer::onDisconnect() { const int32_t layerId = getSequence(); mFlinger->mTimeStats->onDestroy(layerId); mFlinger->mFrameTracer->onDestroy(layerId); } -void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) { - for (const sp<Layer>& child : mDrawingChildren) { - child->mDrawingParent = newParent; - const float parentShadowRadius = - newParent->canDrawShadows() ? 0.f : newParent->mEffectiveShadowRadius; - child->computeBounds(newParent->mBounds, newParent->mEffectiveTransform, - parentShadowRadius); - } -} - -bool Layer::setColorTransform(const mat4& matrix) { - static const mat4 identityMatrix = mat4(); - - if (mDrawingState.colorTransform == matrix) { - return false; - } - ++mDrawingState.sequence; - mDrawingState.colorTransform = matrix; - mDrawingState.hasColorTransform = matrix != identityMatrix; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -mat4 Layer::getColorTransform() const { - mat4 colorTransform = mat4(getDrawingState().colorTransform); - if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) { - colorTransform = parent->getColorTransform() * colorTransform; - } - return colorTransform; -} - -bool Layer::hasColorTransform() const { - bool hasColorTransform = getDrawingState().hasColorTransform; - if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) { - hasColorTransform = hasColorTransform || parent->hasColorTransform(); - } - return hasColorTransform; -} - -bool Layer::isLegacyDataSpace() const { - // return true when no higher bits are set - return !(getDataSpace() & - (ui::Dataspace::STANDARD_MASK | ui::Dataspace::TRANSFER_MASK | - ui::Dataspace::RANGE_MASK)); -} - -void Layer::setParent(const sp<Layer>& layer) { - mCurrentParent = layer; -} - -int32_t Layer::getZ(LayerVector::StateSet) const { - return mDrawingState.z; -} - -bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) const { - const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; - const State& state = useDrawing ? mDrawingState : mDrawingState; - return state.isRelativeOf; -} - -__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList( - LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) { - LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid, - "makeTraversalList received invalid stateSet"); - const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; - const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; - const State& state = useDrawing ? mDrawingState : mDrawingState; - - if (state.zOrderRelatives.size() == 0) { - *outSkipRelativeZUsers = true; - return children; - } - - LayerVector traverse(stateSet); - for (const wp<Layer>& weakRelative : state.zOrderRelatives) { - sp<Layer> strongRelative = weakRelative.promote(); - if (strongRelative != nullptr) { - traverse.add(strongRelative); - } - } - - for (const sp<Layer>& child : children) { - if (child->usingRelativeZ(stateSet)) { - continue; - } - traverse.add(child); - } - - return traverse; -} - -ui::Transform Layer::getTransform() const { - return mEffectiveTransform; -} - -bool Layer::isTransformValid() const { - float transformDet = getTransform().det(); - return transformDet != 0 && !isinf(transformDet) && !isnan(transformDet); -} - -half Layer::getAlpha() const { - const auto& p = mDrawingParent.promote(); - - half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf; - return parentAlpha * getDrawingState().color.a; -} - -ui::Transform::RotationFlags Layer::getFixedTransformHint() const { - ui::Transform::RotationFlags fixedTransformHint = mDrawingState.fixedTransformHint; - if (fixedTransformHint != ui::Transform::ROT_INVALID) { - return fixedTransformHint; - } - const auto& p = mCurrentParent.promote(); - if (!p) return fixedTransformHint; - return p->getFixedTransformHint(); -} - -half4 Layer::getColor() const { - const half4 color(getDrawingState().color); - return half4(color.r, color.g, color.b, getAlpha()); -} - -int32_t Layer::getBackgroundBlurRadius() const { - if (getDrawingState().backgroundBlurRadius == 0) { - return 0; - } - - const auto& p = mDrawingParent.promote(); - half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf; - return parentAlpha * getDrawingState().backgroundBlurRadius; -} - -const std::vector<BlurRegion> Layer::getBlurRegions() const { - auto regionsCopy(getDrawingState().blurRegions); - float layerAlpha = getAlpha(); - for (auto& region : regionsCopy) { - region.alpha = region.alpha * layerAlpha; - } - return regionsCopy; -} - -RoundedCornerState Layer::getRoundedCornerState() const { - // Today's DPUs cannot do rounded corners. If RenderEngine cannot render - // protected content, remove rounded corners from protected content so it - // can be rendered by the DPU. - if (isProtected() && !mFlinger->getRenderEngine().supportsProtectedContent()) { - return {}; - } - - // Get parent settings - RoundedCornerState parentSettings; - const auto& parent = mDrawingParent.promote(); - if (parent != nullptr) { - parentSettings = parent->getRoundedCornerState(); - if (parentSettings.hasRoundedCorners()) { - ui::Transform t = getActiveTransform(getDrawingState()); - t = t.inverse(); - parentSettings.cropRect = t.transform(parentSettings.cropRect); - parentSettings.radius.x *= t.getScaleX(); - parentSettings.radius.y *= t.getScaleY(); - } - } - - // Get layer settings - Rect layerCropRect = getCroppedBufferSize(getDrawingState()); - const vec2 radius(getDrawingState().cornerRadius, getDrawingState().cornerRadius); - RoundedCornerState layerSettings(layerCropRect.toFloatRect(), radius); - const bool layerSettingsValid = layerSettings.hasRoundedCorners() && layerCropRect.isValid(); - - if (layerSettingsValid && parentSettings.hasRoundedCorners()) { - // If the parent and the layer have rounded corner settings, use the parent settings if the - // parent crop is entirely inside the layer crop. - // This has limitations and cause rendering artifacts. See b/200300845 for correct fix. - if (parentSettings.cropRect.left > layerCropRect.left && - parentSettings.cropRect.top > layerCropRect.top && - parentSettings.cropRect.right < layerCropRect.right && - parentSettings.cropRect.bottom < layerCropRect.bottom) { - return parentSettings; - } else { - return layerSettings; - } - } else if (layerSettingsValid) { - return layerSettings; - } else if (parentSettings.hasRoundedCorners()) { - return parentSettings; - } - return {}; -} - -bool Layer::findInHierarchy(const sp<Layer>& l) { - if (l == this) { - return true; - } - for (auto& child : mDrawingChildren) { - if (child->findInHierarchy(l)) { - return true; - } - } - return false; -} - -void Layer::setInputInfo(const WindowInfo& info) { - mDrawingState.inputInfo = info; - mDrawingState.touchableRegionCrop = - LayerHandle::getLayer(info.touchableRegionCropHandle.promote()); - mDrawingState.modified = true; - mFlinger->mUpdateInputInfo = true; - setTransactionFlags(eTransactionNeeded); -} - -perfetto::protos::LayerProto* Layer::writeToProto(perfetto::protos::LayersProto& layersProto, - uint32_t traceFlags) { - perfetto::protos::LayerProto* layerProto = layersProto.add_layers(); - writeToProtoDrawingState(layerProto); - writeToProtoCommonState(layerProto, LayerVector::StateSet::Drawing, traceFlags); - - if (traceFlags & LayerTracing::TRACE_COMPOSITION) { - ui::LayerStack layerStack = - (mSnapshot) ? mSnapshot->outputFilter.layerStack : ui::INVALID_LAYER_STACK; - writeCompositionStateToProto(layerProto, layerStack); - } - - for (const sp<Layer>& layer : mDrawingChildren) { - layer->writeToProto(layersProto, traceFlags); - } - - return layerProto; -} - void Layer::writeCompositionStateToProto(perfetto::protos::LayerProto* layerProto, ui::LayerStack layerStack) { ftl::FakeGuard guard(mFlinger->mStateLock); // Called from the main thread. @@ -1550,352 +660,6 @@ void Layer::writeCompositionStateToProto(perfetto::protos::LayerProto* layerProt } } -void Layer::writeToProtoDrawingState(perfetto::protos::LayerProto* layerInfo) { - const ui::Transform transform = getTransform(); - auto buffer = getExternalTexture(); - if (buffer != nullptr) { - LayerProtoHelper::writeToProto(*buffer, - [&]() { return layerInfo->mutable_active_buffer(); }); - LayerProtoHelper::writeToProtoDeprecated(ui::Transform(getBufferTransform()), - layerInfo->mutable_buffer_transform()); - } - layerInfo->set_invalidate(contentDirty); - layerInfo->set_is_protected(isProtected()); - layerInfo->set_dataspace(dataspaceDetails(static_cast<android_dataspace>(getDataSpace()))); - layerInfo->set_queued_frames(getQueuedFrameCount()); - layerInfo->set_curr_frame(mCurrentFrameNumber); - layerInfo->set_requested_corner_radius(getDrawingState().cornerRadius); - layerInfo->set_corner_radius( - (getRoundedCornerState().radius.x + getRoundedCornerState().radius.y) / 2.0); - layerInfo->set_background_blur_radius(getBackgroundBlurRadius()); - layerInfo->set_is_trusted_overlay(isTrustedOverlay()); - LayerProtoHelper::writeToProtoDeprecated(transform, layerInfo->mutable_transform()); - LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(), - [&]() { return layerInfo->mutable_position(); }); - LayerProtoHelper::writeToProto(mBounds, [&]() { return layerInfo->mutable_bounds(); }); - LayerProtoHelper::writeToProto(surfaceDamageRegion, - [&]() { return layerInfo->mutable_damage_region(); }); - - if (hasColorTransform()) { - LayerProtoHelper::writeToProto(getColorTransform(), layerInfo->mutable_color_transform()); - } - - LayerProtoHelper::writeToProto(mSourceBounds, - [&]() { 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); -} - -void Layer::writeToProtoCommonState(perfetto::protos::LayerProto* layerInfo, - LayerVector::StateSet stateSet, uint32_t traceFlags) { - const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; - const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; - const State& state = useDrawing ? mDrawingState : mDrawingState; - - ui::Transform requestedTransform = state.transform; - - layerInfo->set_id(sequence); - layerInfo->set_name(getName().c_str()); - layerInfo->set_type(getType()); - - for (const auto& child : children) { - layerInfo->add_children(child->sequence); - } - - for (const wp<Layer>& weakRelative : state.zOrderRelatives) { - sp<Layer> strongRelative = weakRelative.promote(); - if (strongRelative != nullptr) { - layerInfo->add_relatives(strongRelative->sequence); - } - } - - LayerProtoHelper::writeToProto(state.transparentRegionHint, - [&]() { return layerInfo->mutable_transparent_region(); }); - - layerInfo->set_layer_stack(getLayerStack().id); - layerInfo->set_z(state.z); - - LayerProtoHelper::writePositionToProto(requestedTransform.tx(), requestedTransform.ty(), [&]() { - return layerInfo->mutable_requested_position(); - }); - - LayerProtoHelper::writeToProto(state.crop, [&]() { return layerInfo->mutable_crop(); }); - - layerInfo->set_is_opaque(isOpaque(state)); - - layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat())); - LayerProtoHelper::writeToProto(getColor(), [&]() { return layerInfo->mutable_color(); }); - LayerProtoHelper::writeToProto(state.color, - [&]() { return layerInfo->mutable_requested_color(); }); - layerInfo->set_flags(state.flags); - - LayerProtoHelper::writeToProtoDeprecated(requestedTransform, - layerInfo->mutable_requested_transform()); - - auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote(); - if (parent != nullptr) { - layerInfo->set_parent(parent->sequence); - } - - auto zOrderRelativeOf = state.zOrderRelativeOf.promote(); - if (zOrderRelativeOf != nullptr) { - layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence); - } - - layerInfo->set_is_relative_of(state.isRelativeOf); - - layerInfo->set_owner_uid(mOwnerUid); - - if ((traceFlags & LayerTracing::TRACE_INPUT) && needsInputInfo()) { - WindowInfo info; - if (useDrawing) { - info = fillInputInfo( - InputDisplayArgs{.transform = &kIdentityTransform, .isSecure = true}); - } else { - info = state.inputInfo; - } - - LayerProtoHelper::writeToProto(info, state.touchableRegionCrop, - [&]() { return layerInfo->mutable_input_window_info(); }); - } - - if (traceFlags & LayerTracing::TRACE_EXTRA) { - auto protoMap = layerInfo->mutable_metadata(); - for (const auto& entry : state.metadata.mMap) { - (*protoMap)[entry.first] = std::string(entry.second.cbegin(), entry.second.cend()); - } - } - - LayerProtoHelper::writeToProto(state.destinationFrame, - [&]() { return layerInfo->mutable_destination_frame(); }); -} - -// Applies the given transform to the region, while protecting against overflows caused by any -// offsets. If applying the offset in the transform to any of the Rects in the region would result -// in an overflow, they are not added to the output Region. -static Region transformTouchableRegionSafely(const ui::Transform& t, const Region& r, - const std::string& debugWindowName) { - // Round the translation using the same rounding strategy used by ui::Transform. - const auto tx = static_cast<int32_t>(t.tx() + 0.5); - const auto ty = static_cast<int32_t>(t.ty() + 0.5); - - ui::Transform transformWithoutOffset = t; - transformWithoutOffset.set(0.f, 0.f); - - const Region transformed = transformWithoutOffset.transform(r); - - // Apply the translation to each of the Rects in the region while discarding any that overflow. - Region ret; - for (const auto& rect : transformed) { - Rect newRect; - if (__builtin_add_overflow(rect.left, tx, &newRect.left) || - __builtin_add_overflow(rect.top, ty, &newRect.top) || - __builtin_add_overflow(rect.right, tx, &newRect.right) || - __builtin_add_overflow(rect.bottom, ty, &newRect.bottom)) { - ALOGE("Applying transform to touchable region of window '%s' resulted in an overflow.", - debugWindowName.c_str()); - continue; - } - ret.orSelf(newRect); - } - return ret; -} - -void Layer::fillInputFrameInfo(WindowInfo& info, const ui::Transform& screenToDisplay) { - auto [inputBounds, inputBoundsValid] = getInputBounds(/*fillParentBounds=*/false); - if (!inputBoundsValid) { - info.touchableRegion.clear(); - } - - info.frame = getInputBoundsInDisplaySpace(inputBounds, screenToDisplay); - - ui::Transform inputToLayer; - inputToLayer.set(inputBounds.left, inputBounds.top); - const ui::Transform layerToScreen = getInputTransform(); - const ui::Transform inputToDisplay = screenToDisplay * layerToScreen * inputToLayer; - - // InputDispatcher expects a display-to-input transform. - info.transform = inputToDisplay.inverse(); - - // The touchable region is specified in the input coordinate space. Change it to display space. - info.touchableRegion = - transformTouchableRegionSafely(inputToDisplay, info.touchableRegion, mName); -} - -void Layer::fillTouchOcclusionMode(WindowInfo& info) { - sp<Layer> p = sp<Layer>::fromExisting(this); - while (p != nullptr && !p->hasInputInfo()) { - p = p->mDrawingParent.promote(); - } - if (p != nullptr) { - info.touchOcclusionMode = p->mDrawingState.inputInfo.touchOcclusionMode; - } -} - -gui::DropInputMode Layer::getDropInputMode() const { - gui::DropInputMode mode = mDrawingState.dropInputMode; - if (mode == gui::DropInputMode::ALL) { - return mode; - } - sp<Layer> parent = mDrawingParent.promote(); - if (parent) { - gui::DropInputMode parentMode = parent->getDropInputMode(); - if (parentMode != gui::DropInputMode::NONE) { - return parentMode; - } - } - return mode; -} - -void Layer::handleDropInputMode(gui::WindowInfo& info) const { - if (mDrawingState.inputInfo.inputConfig.test(WindowInfo::InputConfig::NO_INPUT_CHANNEL)) { - return; - } - - // Check if we need to drop input unconditionally - gui::DropInputMode dropInputMode = getDropInputMode(); - if (dropInputMode == gui::DropInputMode::ALL) { - info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT; - ALOGV("Dropping input for %s as requested by policy.", getDebugName()); - return; - } - - // Check if we need to check if the window is obscured by parent - if (dropInputMode != gui::DropInputMode::OBSCURED) { - return; - } - - // Check if the parent has set an alpha on the layer - sp<Layer> parent = mDrawingParent.promote(); - if (parent && parent->getAlpha() != 1.0_hf) { - info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT; - ALOGV("Dropping input for %s as requested by policy because alpha=%f", getDebugName(), - static_cast<float>(getAlpha())); - } - - // Check if the parent has cropped the buffer - Rect bufferSize = getCroppedBufferSize(getDrawingState()); - if (!bufferSize.isValid()) { - info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT_IF_OBSCURED; - return; - } - - // Screenbounds are the layer bounds cropped by parents, transformed to screenspace. - // To check if the layer has been cropped, we take the buffer bounds, apply the local - // layer crop and apply the same set of transforms to move to screenspace. If the bounds - // match then the layer has not been cropped by its parents. - Rect bufferInScreenSpace(getTransform().transform(bufferSize)); - bool croppedByParent = bufferInScreenSpace != Rect{mScreenBounds}; - - if (croppedByParent) { - info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT; - ALOGV("Dropping input for %s as requested by policy because buffer is cropped by parent", - getDebugName()); - } else { - // If the layer is not obscured by its parents (by setting an alpha or crop), then only drop - // input if the window is obscured. This check should be done in surfaceflinger but the - // logic currently resides in inputflinger. So pass the if_obscured check to input to only - // drop input events if the window is obscured. - info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT_IF_OBSCURED; - } -} - -WindowInfo Layer::fillInputInfo(const InputDisplayArgs& displayArgs) { - if (!hasInputInfo()) { - mDrawingState.inputInfo.name = getName(); - mDrawingState.inputInfo.ownerUid = gui::Uid{mOwnerUid}; - mDrawingState.inputInfo.ownerPid = gui::Pid{mOwnerPid}; - mDrawingState.inputInfo.inputConfig |= WindowInfo::InputConfig::NO_INPUT_CHANNEL; - mDrawingState.inputInfo.displayId = toLogicalDisplayId(getLayerStack()); - } - - const ui::Transform& displayTransform = - displayArgs.transform != nullptr ? *displayArgs.transform : kIdentityTransform; - - WindowInfo info = mDrawingState.inputInfo; - info.id = sequence; - info.displayId = toLogicalDisplayId(getLayerStack()); - - fillInputFrameInfo(info, displayTransform); - - if (displayArgs.transform == nullptr) { - // Do not let the window receive touches if it is not associated with a valid display - // transform. We still allow the window to receive keys and prevent ANRs. - info.inputConfig |= WindowInfo::InputConfig::NOT_TOUCHABLE; - } - - info.setInputConfig(WindowInfo::InputConfig::NOT_VISIBLE, !isVisibleForInput()); - - info.alpha = getAlpha(); - fillTouchOcclusionMode(info); - handleDropInputMode(info); - - // If the window will be blacked out on a display because the display does not have the secure - // flag and the layer has the secure flag set, then drop input. - if (!displayArgs.isSecure && isSecure()) { - info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT; - } - - sp<Layer> cropLayer = mDrawingState.touchableRegionCrop.promote(); - if (info.replaceTouchableRegionWithCrop) { - Rect inputBoundsInDisplaySpace; - if (!cropLayer) { - FloatRect inputBounds = getInputBounds(/*fillParentBounds=*/true).first; - inputBoundsInDisplaySpace = getInputBoundsInDisplaySpace(inputBounds, displayTransform); - } else { - FloatRect inputBounds = cropLayer->getInputBounds(/*fillParentBounds=*/true).first; - inputBoundsInDisplaySpace = - cropLayer->getInputBoundsInDisplaySpace(inputBounds, displayTransform); - } - info.touchableRegion = Region(inputBoundsInDisplaySpace); - } else if (cropLayer != nullptr) { - FloatRect inputBounds = cropLayer->getInputBounds(/*fillParentBounds=*/true).first; - Rect inputBoundsInDisplaySpace = - cropLayer->getInputBoundsInDisplaySpace(inputBounds, displayTransform); - info.touchableRegion = info.touchableRegion.intersect(inputBoundsInDisplaySpace); - } - - // Inherit the trusted state from the parent hierarchy, but don't clobber the trusted state - // if it was set by WM for a known system overlay - if (isTrustedOverlay()) { - info.inputConfig |= WindowInfo::InputConfig::TRUSTED_OVERLAY; - } - - Rect bufferSize = getBufferSize(getDrawingState()); - info.contentSize = Size(bufferSize.width(), bufferSize.height()); - - return info; -} - -Rect Layer::getInputBoundsInDisplaySpace(const FloatRect& inputBounds, - const ui::Transform& screenToDisplay) { - // InputDispatcher works in the display device's coordinate space. Here, we calculate the - // frame and transform used for the layer, which determines the bounds and the coordinate space - // within which the layer will receive input. - - // Coordinate space definitions: - // - display: The display device's coordinate space. Correlates to pixels on the display. - // - screen: The post-rotation coordinate space for the display, a.k.a. logical display space. - // - layer: The coordinate space of this layer. - // - input: The coordinate space in which this layer will receive input events. This could be - // different than layer space if a surfaceInset is used, which changes the origin - // of the input space. - - // Crop the input bounds to ensure it is within the parent's bounds. - const FloatRect croppedInputBounds = mBounds.intersect(inputBounds); - const ui::Transform layerToScreen = getInputTransform(); - const ui::Transform layerToDisplay = screenToDisplay * layerToScreen; - return Rect{layerToDisplay.transform(croppedInputBounds)}; -} - -bool Layer::hasInputInfo() const { - return mDrawingState.inputInfo.token != nullptr || - mDrawingState.inputInfo.inputConfig.test(WindowInfo::InputConfig::NO_INPUT_CHANNEL); -} - compositionengine::OutputLayer* Layer::findOutputLayerForDisplay( const DisplayDevice* display) const { if (!display) return nullptr; @@ -1930,24 +694,6 @@ Region Layer::getVisibleRegion(const DisplayDevice* display) const { return outputLayer ? outputLayer->getState().visibleRegion : Region(); } -bool Layer::isInternalDisplayOverlay() const { - const State& s(mDrawingState); - if (s.flags & layer_state_t::eLayerSkipScreenshot) { - return true; - } - - sp<Layer> parent = mDrawingParent.promote(); - return parent && parent->isInternalDisplayOverlay(); -} - -bool Layer::setDropInputMode(gui::DropInputMode mode) { - if (mDrawingState.dropInputMode == mode) { - return false; - } - mDrawingState.dropInputMode = mode; - return true; -} - void Layer::callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener, const sp<GraphicBuffer>& buffer, uint64_t framenumber, const sp<Fence>& releaseFence) { @@ -2106,17 +852,9 @@ void Layer::releasePendingBuffer(nsecs_t dequeueReadyTime) { mDrawingState.callbackHandles = {}; } -bool Layer::willPresentCurrentTransaction() const { - // Returns true if the most recent Transaction applied to CurrentState will be presented. - return (getSidebandStreamChanged() || getAutoRefresh() || - (mDrawingState.modified && - (mDrawingState.buffer != nullptr || mDrawingState.bgColorLayer != nullptr))); -} - bool Layer::setTransform(uint32_t transform) { if (mDrawingState.bufferTransform == transform) return false; mDrawingState.bufferTransform = transform; - mDrawingState.modified = true; setTransactionFlags(eTransactionNeeded); return true; } @@ -2125,7 +863,6 @@ bool Layer::setTransformToDisplayInverse(bool transformToDisplayInverse) { if (mDrawingState.transformToDisplayInverse == transformToDisplayInverse) return false; mDrawingState.sequence++; mDrawingState.transformToDisplayInverse = transformToDisplayInverse; - mDrawingState.modified = true; setTransactionFlags(eTransactionNeeded); return true; } @@ -2136,100 +873,10 @@ bool Layer::setBufferCrop(const Rect& bufferCrop) { mDrawingState.sequence++; mDrawingState.bufferCrop = bufferCrop; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setDestinationFrame(const Rect& destinationFrame) { - if (mDrawingState.destinationFrame == destinationFrame) return false; - - mDrawingState.sequence++; - mDrawingState.destinationFrame = destinationFrame; - - mDrawingState.modified = true; setTransactionFlags(eTransactionNeeded); return true; } -// Translate destination frame into scale and position. If a destination frame is not set, use the -// provided scale and position -bool Layer::updateGeometry() { - if ((mDrawingState.flags & layer_state_t::eIgnoreDestinationFrame) || - mDrawingState.destinationFrame.isEmpty()) { - // If destination frame is not set, use the requested transform set via - // Layer::setPosition and Layer::setMatrix. - return assignTransform(&mDrawingState.transform, mRequestedTransform); - } - - Rect destRect = mDrawingState.destinationFrame; - int32_t destW = destRect.width(); - int32_t destH = destRect.height(); - if (destRect.left < 0) { - destRect.left = 0; - destRect.right = destW; - } - if (destRect.top < 0) { - destRect.top = 0; - destRect.bottom = destH; - } - - if (!mDrawingState.buffer) { - ui::Transform t; - t.set(destRect.left, destRect.top); - return assignTransform(&mDrawingState.transform, t); - } - - uint32_t bufferWidth = mDrawingState.buffer->getWidth(); - uint32_t bufferHeight = mDrawingState.buffer->getHeight(); - // Undo any transformations on the buffer. - if (mDrawingState.bufferTransform & ui::Transform::ROT_90) { - std::swap(bufferWidth, bufferHeight); - } - uint32_t invTransform = SurfaceFlinger::getActiveDisplayRotationFlags(); - if (mDrawingState.transformToDisplayInverse) { - if (invTransform & ui::Transform::ROT_90) { - std::swap(bufferWidth, bufferHeight); - } - } - - float sx = destW / static_cast<float>(bufferWidth); - float sy = destH / static_cast<float>(bufferHeight); - ui::Transform t; - t.set(sx, 0, 0, sy); - t.set(destRect.left, destRect.top); - return assignTransform(&mDrawingState.transform, t); -} - -bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) { - if (mRequestedTransform.dsdx() == matrix.dsdx && mRequestedTransform.dtdy() == matrix.dtdy && - mRequestedTransform.dtdx() == matrix.dtdx && mRequestedTransform.dsdy() == matrix.dsdy) { - return false; - } - - mRequestedTransform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); - - mDrawingState.sequence++; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - - return true; -} - -bool Layer::setPosition(float x, float y) { - if (mRequestedTransform.tx() == x && mRequestedTransform.ty() == y) { - return false; - } - - mRequestedTransform.set(x, y); - - mDrawingState.sequence++; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - - return true; -} - void Layer::releasePreviousBuffer() { mReleasePreviousBuffer = true; if (!mBufferInfo.mBuffer || @@ -2293,7 +940,6 @@ bool Layer::setBuffer(std::shared_ptr<renderengine::ExternalTexture>& buffer, mDrawingState.isAutoTimestamp = isAutoTimestamp; mDrawingState.latchedVsyncId = info.vsyncId; mDrawingState.useVsyncIdForRefreshRateSelection = info.useForRefreshRateSelection; - mDrawingState.modified = true; if (!buffer) { resetDrawingStateBufferInfo(); setTransactionFlags(eTransactionNeeded); @@ -2441,7 +1087,6 @@ void Layer::recordLayerHistoryAnimationTx(const scheduler::LayerProps& layerProp bool Layer::setDataspace(ui::Dataspace dataspace) { if (mDrawingState.dataspace == dataspace) return false; mDrawingState.dataspace = dataspace; - mDrawingState.modified = true; setTransactionFlags(eTransactionNeeded); return true; } @@ -2452,7 +1097,6 @@ bool Layer::setExtendedRangeBrightness(float currentBufferRatio, float desiredRa return false; mDrawingState.currentHdrSdrRatio = currentBufferRatio; mDrawingState.desiredHdrSdrRatio = desiredRatio; - mDrawingState.modified = true; setTransactionFlags(eTransactionNeeded); return true; } @@ -2460,40 +1104,6 @@ bool Layer::setExtendedRangeBrightness(float currentBufferRatio, float desiredRa bool Layer::setDesiredHdrHeadroom(float desiredRatio) { if (mDrawingState.desiredHdrSdrRatio == desiredRatio) return false; mDrawingState.desiredHdrSdrRatio = desiredRatio; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setCachingHint(gui::CachingHint cachingHint) { - if (mDrawingState.cachingHint == cachingHint) return false; - mDrawingState.cachingHint = cachingHint; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setHdrMetadata(const HdrMetadata& hdrMetadata) { - if (mDrawingState.hdrMetadata == hdrMetadata) return false; - mDrawingState.hdrMetadata = hdrMetadata; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::setSurfaceDamageRegion(const Region& surfaceDamage) { - if (mDrawingState.surfaceDamageRegion.hasSameRects(surfaceDamage)) return false; - mDrawingState.surfaceDamageRegion = surfaceDamage; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - setIsSmallDirty(surfaceDamage, getTransform()); - return true; -} - -bool Layer::setApi(int32_t api) { - if (mDrawingState.api == api) return false; - mDrawingState.api = api; - mDrawingState.modified = true; setTransactionFlags(eTransactionNeeded); return true; } @@ -2509,7 +1119,6 @@ bool Layer::setSidebandStream(const sp<NativeHandle>& sidebandStream, const Fram } mDrawingState.sidebandStream = sidebandStream; - mDrawingState.modified = true; if (sidebandStream != nullptr && mDrawingState.buffer != nullptr) { releasePreviousBuffer(); resetDrawingStateBufferInfo(); @@ -2606,14 +1215,6 @@ Rect Layer::getBufferSize(const State& /*s*/) const { return Rect(0, 0, static_cast<int32_t>(bufWidth), static_cast<int32_t>(bufHeight)); } -FloatRect Layer::computeSourceBounds(const FloatRect& parentBounds) const { - if (mBufferInfo.mBuffer == nullptr) { - return parentBounds; - } - - return getBufferSize(getDrawingState()).toFloatRect(); -} - bool Layer::fenceHasSignaled() const { if (SurfaceFlinger::enableLatchUnsignaledConfig != LatchUnsignaledConfig::Disabled) { return true; @@ -2635,37 +1236,21 @@ void Layer::onPreComposition(nsecs_t refreshStartTime) { } } -void Layer::setAutoRefresh(bool autoRefresh) { - mDrawingState.autoRefresh = autoRefresh; -} - bool Layer::latchSidebandStream(bool& recomputeVisibleRegions) { - // We need to update the sideband stream if the layer has both a buffer and a sideband stream. - auto* snapshot = editLayerSnapshot(); - snapshot->sidebandStreamHasFrame = hasFrameUpdate() && mSidebandStream.get(); - if (mSidebandStreamChanged.exchange(false)) { const State& s(getDrawingState()); // mSidebandStreamChanged was true mSidebandStream = s.sidebandStream; - snapshot->sidebandStream = mSidebandStream; if (mSidebandStream != nullptr) { setTransactionFlags(eTransactionNeeded); mFlinger->setTransactionFlags(eTraversalNeeded); } recomputeVisibleRegions = true; - return true; } return false; } -bool Layer::hasFrameUpdate() const { - const State& c(getDrawingState()); - return (mDrawingStateModified || mDrawingState.modified) && - (c.buffer != nullptr || c.bgColorLayer != nullptr); -} - void Layer::updateTexImage(nsecs_t latchTime, bool bgColorOnly) { const State& s(getDrawingState()); @@ -2712,8 +1297,6 @@ void Layer::updateTexImage(nsecs_t latchTime, bool bgColorOnly) { mFlinger->getTransactionCallbackInvoker() .addOnCommitCallbackHandles(mDrawingState.callbackHandles, remainingHandles); mDrawingState.callbackHandles = remainingHandles; - - mDrawingStateModified = false; } void Layer::gatherBufferInfo() { @@ -2737,7 +1320,6 @@ void Layer::gatherBufferInfo() { mBufferInfo.mFrameLatencyNeeded = true; mBufferInfo.mDesiredPresentTime = mDrawingState.desiredPresentTime; mBufferInfo.mFenceTime = std::make_shared<FenceTime>(mDrawingState.acquireFence); - mBufferInfo.mFence = mDrawingState.acquireFence; mBufferInfo.mTransform = mDrawingState.bufferTransform; auto lastDataspace = mBufferInfo.mDataspace; mBufferInfo.mDataspace = translateDataspace(mDrawingState.dataspace); @@ -2785,10 +1367,6 @@ void Layer::gatherBufferInfo() { mFlinger->mHdrLayerInfoChanged = true; } mBufferInfo.mCrop = computeBufferCrop(mDrawingState); - mBufferInfo.mScaleMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW; - mBufferInfo.mSurfaceDamage = mDrawingState.surfaceDamageRegion; - mBufferInfo.mHdrMetadata = mDrawingState.hdrMetadata; - mBufferInfo.mApi = mDrawingState.api; mBufferInfo.mTransformToDisplayInverse = mDrawingState.transformToDisplayInverse; } @@ -2813,294 +1391,6 @@ void Layer::tracePendingBufferCount(int32_t pendingBuffers) { SFTRACE_INT(mBlastTransactionName.c_str(), pendingBuffers); } -/* - * We don't want to send the layer's transform to input, but rather the - * parent's transform. This is because Layer's transform is - * information about how the buffer is placed on screen. The parent's - * transform makes more sense to send since it's information about how the - * layer is placed on screen. This transform is used by input to determine - * how to go from screen space back to window space. - */ -ui::Transform Layer::getInputTransform() const { - if (!hasBufferOrSidebandStream()) { - return getTransform(); - } - sp<Layer> parent = mDrawingParent.promote(); - if (parent == nullptr) { - return ui::Transform(); - } - - return parent->getTransform(); -} - -/** - * Returns the bounds used to fill the input frame and the touchable region. - * - * Similar to getInputTransform, we need to update the bounds to include the transform. - * This is because bounds don't include the buffer transform, where the input assumes - * that's already included. - */ -std::pair<FloatRect, bool> Layer::getInputBounds(bool fillParentBounds) const { - Rect croppedBufferSize = getCroppedBufferSize(getDrawingState()); - FloatRect inputBounds = croppedBufferSize.toFloatRect(); - if (hasBufferOrSidebandStream() && croppedBufferSize.isValid() && - mDrawingState.transform.getType() != ui::Transform::IDENTITY) { - inputBounds = mDrawingState.transform.transform(inputBounds); - } - - bool inputBoundsValid = croppedBufferSize.isValid(); - if (!inputBoundsValid) { - /** - * Input bounds are based on the layer crop or buffer size. But if we are using - * the layer bounds as the input bounds (replaceTouchableRegionWithCrop flag) then - * we can use the parent bounds as the input bounds if the layer does not have buffer - * or a crop. We want to unify this logic but because of compat reasons we cannot always - * use the parent bounds. A layer without a buffer can get input. So when a window is - * initially added, its touchable region can fill its parent layer bounds and that can - * have negative consequences. - */ - inputBounds = fillParentBounds ? mBounds : FloatRect{}; - } - - // Clamp surface inset to the input bounds. - const float inset = static_cast<float>(mDrawingState.inputInfo.surfaceInset); - const float xSurfaceInset = std::clamp(inset, 0.f, inputBounds.getWidth() / 2.f); - const float ySurfaceInset = std::clamp(inset, 0.f, inputBounds.getHeight() / 2.f); - - // Apply the insets to the input bounds. - inputBounds.left += xSurfaceInset; - inputBounds.top += ySurfaceInset; - inputBounds.right -= xSurfaceInset; - inputBounds.bottom -= ySurfaceInset; - - return {inputBounds, inputBoundsValid}; -} - -bool Layer::isSimpleBufferUpdate(const layer_state_t& s) const { - const uint64_t requiredFlags = layer_state_t::eBufferChanged; - - const uint64_t deniedFlags = layer_state_t::eProducerDisconnect | layer_state_t::eLayerChanged | - layer_state_t::eRelativeLayerChanged | layer_state_t::eTransparentRegionChanged | - layer_state_t::eFlagsChanged | layer_state_t::eBlurRegionsChanged | - layer_state_t::eLayerStackChanged | layer_state_t::eReparent | - (FlagManager::getInstance().latch_unsignaled_with_auto_refresh_changed() - ? 0 - : layer_state_t::eAutoRefreshChanged); - - if ((s.what & requiredFlags) != requiredFlags) { - SFTRACE_FORMAT_INSTANT("%s: false [missing required flags 0x%" PRIx64 "]", __func__, - (s.what | requiredFlags) & ~s.what); - return false; - } - - if (s.what & deniedFlags) { - SFTRACE_FORMAT_INSTANT("%s: false [has denied flags 0x%" PRIx64 "]", __func__, - s.what & deniedFlags); - return false; - } - - if (s.what & layer_state_t::ePositionChanged) { - if (mRequestedTransform.tx() != s.x || mRequestedTransform.ty() != s.y) { - SFTRACE_FORMAT_INSTANT("%s: false [ePositionChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eAlphaChanged) { - if (mDrawingState.color.a != s.color.a) { - SFTRACE_FORMAT_INSTANT("%s: false [eAlphaChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eColorTransformChanged) { - if (mDrawingState.colorTransform != s.colorTransform) { - SFTRACE_FORMAT_INSTANT("%s: false [eColorTransformChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eBackgroundColorChanged) { - if (mDrawingState.bgColorLayer || s.bgColor.a != 0) { - SFTRACE_FORMAT_INSTANT("%s: false [eBackgroundColorChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eMatrixChanged) { - if (mRequestedTransform.dsdx() != s.matrix.dsdx || - mRequestedTransform.dtdy() != s.matrix.dtdy || - mRequestedTransform.dtdx() != s.matrix.dtdx || - mRequestedTransform.dsdy() != s.matrix.dsdy) { - SFTRACE_FORMAT_INSTANT("%s: false [eMatrixChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eCornerRadiusChanged) { - if (mDrawingState.cornerRadius != s.cornerRadius) { - SFTRACE_FORMAT_INSTANT("%s: false [eCornerRadiusChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eBackgroundBlurRadiusChanged) { - if (mDrawingState.backgroundBlurRadius != static_cast<int>(s.backgroundBlurRadius)) { - SFTRACE_FORMAT_INSTANT("%s: false [eBackgroundBlurRadiusChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eBufferTransformChanged) { - if (mDrawingState.bufferTransform != s.bufferTransform) { - SFTRACE_FORMAT_INSTANT("%s: false [eBufferTransformChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eTransformToDisplayInverseChanged) { - if (mDrawingState.transformToDisplayInverse != s.transformToDisplayInverse) { - SFTRACE_FORMAT_INSTANT("%s: false [eTransformToDisplayInverseChanged changed]", - __func__); - return false; - } - } - - if (s.what & layer_state_t::eCropChanged) { - if (mDrawingState.crop != s.crop) { - SFTRACE_FORMAT_INSTANT("%s: false [eCropChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eDataspaceChanged) { - if (mDrawingState.dataspace != s.dataspace) { - SFTRACE_FORMAT_INSTANT("%s: false [eDataspaceChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eHdrMetadataChanged) { - if (mDrawingState.hdrMetadata != s.hdrMetadata) { - SFTRACE_FORMAT_INSTANT("%s: false [eHdrMetadataChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eSidebandStreamChanged) { - if (mDrawingState.sidebandStream != s.sidebandStream) { - SFTRACE_FORMAT_INSTANT("%s: false [eSidebandStreamChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eColorSpaceAgnosticChanged) { - if (mDrawingState.colorSpaceAgnostic != s.colorSpaceAgnostic) { - SFTRACE_FORMAT_INSTANT("%s: false [eColorSpaceAgnosticChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eShadowRadiusChanged) { - if (mDrawingState.shadowRadius != s.shadowRadius) { - SFTRACE_FORMAT_INSTANT("%s: false [eShadowRadiusChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eFixedTransformHintChanged) { - if (mDrawingState.fixedTransformHint != s.fixedTransformHint) { - SFTRACE_FORMAT_INSTANT("%s: false [eFixedTransformHintChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eTrustedOverlayChanged) { - if (mDrawingState.isTrustedOverlay != (s.trustedOverlay == gui::TrustedOverlay::ENABLED)) { - SFTRACE_FORMAT_INSTANT("%s: false [eTrustedOverlayChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eStretchChanged) { - StretchEffect temp = s.stretchEffect; - temp.sanitize(); - if (mDrawingState.stretchEffect != temp) { - SFTRACE_FORMAT_INSTANT("%s: false [eStretchChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eBufferCropChanged) { - if (mDrawingState.bufferCrop != s.bufferCrop) { - SFTRACE_FORMAT_INSTANT("%s: false [eBufferCropChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eDestinationFrameChanged) { - if (mDrawingState.destinationFrame != s.destinationFrame) { - SFTRACE_FORMAT_INSTANT("%s: false [eDestinationFrameChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eDimmingEnabledChanged) { - if (mDrawingState.dimmingEnabled != s.dimmingEnabled) { - SFTRACE_FORMAT_INSTANT("%s: false [eDimmingEnabledChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eExtendedRangeBrightnessChanged) { - if (mDrawingState.currentHdrSdrRatio != s.currentHdrSdrRatio || - mDrawingState.desiredHdrSdrRatio != s.desiredHdrSdrRatio) { - SFTRACE_FORMAT_INSTANT("%s: false [eExtendedRangeBrightnessChanged changed]", __func__); - return false; - } - } - - if (s.what & layer_state_t::eDesiredHdrHeadroomChanged) { - if (mDrawingState.desiredHdrSdrRatio != s.desiredHdrSdrRatio) { - SFTRACE_FORMAT_INSTANT("%s: false [eDesiredHdrHeadroomChanged changed]", __func__); - return false; - } - } - - return true; -} - -sp<LayerFE> Layer::getCompositionEngineLayerFE() const { - // There's no need to get a CE Layer if the layer isn't going to draw anything. - return hasSomethingToDraw() ? mLegacyLayerFE : nullptr; -} - -const LayerSnapshot* Layer::getLayerSnapshot() const { - return mSnapshot.get(); -} - -LayerSnapshot* Layer::editLayerSnapshot() { - return mSnapshot.get(); -} - -std::unique_ptr<frontend::LayerSnapshot> Layer::stealLayerSnapshot() { - return std::move(mSnapshot); -} - -void Layer::updateLayerSnapshot(std::unique_ptr<frontend::LayerSnapshot> snapshot) { - mSnapshot = std::move(snapshot); -} - -const compositionengine::LayerFECompositionState* Layer::getCompositionState() const { - return mSnapshot.get(); -} - -sp<LayerFE> Layer::copyCompositionEngineLayerFE() const { - auto result = mFlinger->getFactory().createLayerFE(mName, this); - result->mSnapshot = std::make_unique<LayerSnapshot>(*mSnapshot); - return result; -} - sp<LayerFE> Layer::getCompositionEngineLayerFE( const frontend::LayerHierarchy::TraversalPath& path) { for (auto& [p, layerFE] : mLayerFEs) { @@ -3113,55 +1403,6 @@ sp<LayerFE> Layer::getCompositionEngineLayerFE( return layerFE; } -void Layer::useSurfaceDamage() { - if (mFlinger->mForceFullDamage) { - surfaceDamageRegion = Region::INVALID_REGION; - } else { - surfaceDamageRegion = mBufferInfo.mSurfaceDamage; - } -} - -void Layer::useEmptyDamage() { - surfaceDamageRegion.clear(); -} - -bool Layer::isOpaque(const Layer::State& s) const { - // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the - // layer's opaque flag. - if (!hasSomethingToDraw()) { - return false; - } - - // if the layer has the opaque flag, then we're always opaque - if ((s.flags & layer_state_t::eLayerOpaque) == layer_state_t::eLayerOpaque) { - return true; - } - - // If the buffer has no alpha channel, then we are opaque - if (hasBufferOrSidebandStream() && LayerSnapshot::isOpaqueFormat(getPixelFormat())) { - return true; - } - - // Lastly consider the layer opaque if drawing a color with alpha == 1.0 - return fillsColor() && getAlpha() == 1.0_hf; -} - -bool Layer::canReceiveInput() const { - return !isHiddenByPolicy() && (mBufferInfo.mBuffer == nullptr || getAlpha() > 0.0f); -} - -bool Layer::isVisible() const { - if (!hasSomethingToDraw()) { - return false; - } - - if (isHiddenByPolicy()) { - return false; - } - - return getAlpha() > 0.0f || hasBlur(); -} - void Layer::onCompositionPresented(const DisplayDevice* display, const std::shared_ptr<FenceTime>& glDoneFence, const std::shared_ptr<FenceTime>& presentFence, @@ -3254,11 +1495,6 @@ bool Layer::willReleaseBufferOnLatch() const { return !mDrawingState.buffer && mBufferInfo.mBuffer; } -bool Layer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime) { - const bool bgColorOnly = mDrawingState.bgColorLayer != nullptr; - return latchBufferImpl(recomputeVisibleRegions, latchTime, bgColorOnly); -} - bool Layer::latchBufferImpl(bool& recomputeVisibleRegions, nsecs_t latchTime, bool bgColorOnly) { SFTRACE_FORMAT_INSTANT("latchBuffer %s - %" PRIu64, getDebugName(), getDrawingState().frameNumber); @@ -3280,7 +1516,6 @@ bool Layer::latchBufferImpl(bool& recomputeVisibleRegions, nsecs_t latchTime, bo // Capture the old state of the layer for comparisons later BufferInfo oldBufferInfo = mBufferInfo; - const bool oldOpacity = isOpaque(mDrawingState); mPreviousFrameNumber = mCurrentFrameNumber; mCurrentFrameNumber = mDrawingState.frameNumber; gatherBufferInfo(); @@ -3305,7 +1540,6 @@ bool Layer::latchBufferImpl(bool& recomputeVisibleRegions, nsecs_t latchTime, bo if ((mBufferInfo.mCrop != oldBufferInfo.mCrop) || (mBufferInfo.mTransform != oldBufferInfo.mTransform) || - (mBufferInfo.mScaleMode != oldBufferInfo.mScaleMode) || (mBufferInfo.mTransformToDisplayInverse != oldBufferInfo.mTransformToDisplayInverse)) { recomputeVisibleRegions = true; } @@ -3318,35 +1552,14 @@ bool Layer::latchBufferImpl(bool& recomputeVisibleRegions, nsecs_t latchTime, bo recomputeVisibleRegions = true; } } - - if (oldOpacity != isOpaque(mDrawingState)) { - recomputeVisibleRegions = true; - } - return true; } -bool Layer::hasReadyFrame() const { - return hasFrameUpdate() || getSidebandStreamChanged() || getAutoRefresh(); -} - bool Layer::isProtected() const { return (mBufferInfo.mBuffer != nullptr) && (mBufferInfo.mBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); } -void Layer::latchAndReleaseBuffer() { - if (hasReadyFrame()) { - bool ignored = false; - latchBuffer(ignored, systemTime()); - } - releasePendingBuffer(systemTime()); -} - -PixelFormat Layer::getPixelFormat() const { - return mBufferInfo.mPixelFormat; -} - bool Layer::getTransformToDisplayInverse() const { return mBufferInfo.mTransformToDisplayInverse; } @@ -3370,18 +1583,6 @@ uint32_t Layer::getBufferTransform() const { return mBufferInfo.mTransform; } -ui::Dataspace Layer::getDataSpace() const { - return hasBufferOrSidebandStream() ? mBufferInfo.mDataspace : mDrawingState.dataspace; -} - -bool Layer::isFrontBuffered() const { - if (mBufferInfo.mBuffer == nullptr) { - return false; - } - - return mBufferInfo.mBuffer->getUsage() & AHARDWAREBUFFER_USAGE_FRONT_BUFFER; -} - ui::Dataspace Layer::translateDataspace(ui::Dataspace dataspace) { ui::Dataspace updatedDataspace = dataspace; // translate legacy dataspaces to modern dataspaces @@ -3417,84 +1618,6 @@ sp<GraphicBuffer> Layer::getBuffer() const { return mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer() : nullptr; } -const std::shared_ptr<renderengine::ExternalTexture>& Layer::getExternalTexture() const { - return mBufferInfo.mBuffer; -} - -bool Layer::setColor(const half3& color) { - if (mDrawingState.color.rgb == color) { - return false; - } - - mDrawingState.sequence++; - mDrawingState.color.rgb = color; - mDrawingState.modified = true; - setTransactionFlags(eTransactionNeeded); - return true; -} - -bool Layer::fillsColor() const { - return !hasBufferOrSidebandStream() && mDrawingState.color.r >= 0.0_hf && - mDrawingState.color.g >= 0.0_hf && mDrawingState.color.b >= 0.0_hf; -} - -bool Layer::hasBlur() const { - return getBackgroundBlurRadius() > 0 || getDrawingState().blurRegions.size() > 0; -} - -void Layer::updateSnapshot(bool updateGeometry) { - if (!getCompositionEngineLayerFE()) { - return; - } - - auto* snapshot = editLayerSnapshot(); - if (updateGeometry) { - prepareBasicGeometryCompositionState(); - prepareGeometryCompositionState(); - snapshot->roundedCorner = getRoundedCornerState(); - snapshot->transformedBounds = mScreenBounds; - if (mEffectiveShadowRadius > 0.f) { - snapshot->shadowSettings = mFlinger->mDrawingState.globalShadowSettings; - - // Note: this preserves existing behavior of shadowing the entire layer and not cropping - // it if transparent regions are present. This may not be necessary since shadows are - // typically cast by layers without transparent regions. - snapshot->shadowSettings.boundaries = mBounds; - - const float casterAlpha = snapshot->alpha; - const bool casterIsOpaque = - ((mBufferInfo.mBuffer != nullptr) && isOpaque(mDrawingState)); - - // If the casting layer is translucent, we need to fill in the shadow underneath the - // layer. Otherwise the generated shadow will only be shown around the casting layer. - snapshot->shadowSettings.casterIsTranslucent = !casterIsOpaque || (casterAlpha < 1.0f); - snapshot->shadowSettings.ambientColor *= casterAlpha; - snapshot->shadowSettings.spotColor *= casterAlpha; - } - snapshot->shadowSettings.length = mEffectiveShadowRadius; - } - snapshot->contentOpaque = isOpaque(mDrawingState); - snapshot->layerOpaqueFlagSet = - (mDrawingState.flags & layer_state_t::eLayerOpaque) == layer_state_t::eLayerOpaque; - sp<Layer> p = mDrawingParent.promote(); - if (p != nullptr) { - snapshot->parentTransform = p->getTransform(); - } else { - snapshot->parentTransform.reset(); - } - snapshot->bufferSize = getBufferSize(mDrawingState); - snapshot->externalTexture = mBufferInfo.mBuffer; - snapshot->hasReadyFrame = hasReadyFrame(); - preparePerFrameCompositionState(); -} - -void Layer::updateChildrenSnapshots(bool updateGeometry) { - for (const sp<Layer>& child : mDrawingChildren) { - child->updateSnapshot(updateGeometry); - child->updateChildrenSnapshots(updateGeometry); - } -} - bool Layer::setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds, TrustedPresentationListener const& listener) { bool hadTrustedPresentationListener = hasTrustedPresentationListener(); @@ -3527,35 +1650,32 @@ void Layer::updateLastLatchTime(nsecs_t latchTime) { mLastLatchTime = latchTime; } -void Layer::setIsSmallDirty(const Region& damageRegion, - const ui::Transform& layerToDisplayTransform) { - mSmallDirty = false; +void Layer::setIsSmallDirty(frontend::LayerSnapshot* snapshot) { if (!mFlinger->mScheduler->supportSmallDirtyDetection(mOwnerAppId)) { + snapshot->isSmallDirty = false; return; } if (mWindowType != WindowInfo::Type::APPLICATION && mWindowType != WindowInfo::Type::BASE_APPLICATION) { + snapshot->isSmallDirty = false; return; } - Rect bounds = damageRegion.getBounds(); + Rect bounds = snapshot->surfaceDamage.getBounds(); if (!bounds.isValid()) { + snapshot->isSmallDirty = false; return; } // Transform to screen space. - bounds = layerToDisplayTransform.transform(bounds); + bounds = snapshot->localTransform.transform(bounds); // If the damage region is a small dirty, this could give the hint for the layer history that // it could suppress the heuristic rate when calculating. - mSmallDirty = mFlinger->mScheduler->isSmallDirtyArea(mOwnerAppId, - bounds.getWidth() * bounds.getHeight()); -} - -void Layer::setIsSmallDirty(frontend::LayerSnapshot* snapshot) { - setIsSmallDirty(snapshot->surfaceDamage, snapshot->localTransform); - snapshot->isSmallDirty = mSmallDirty; + snapshot->isSmallDirty = + mFlinger->mScheduler->isSmallDirtyArea(mOwnerAppId, + bounds.getWidth() * bounds.getHeight()); } } // namespace android diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 1e4f2dc296..9caa20cfb8 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -43,9 +43,7 @@ #include <scheduler/Fps.h> #include <scheduler/Seamlessness.h> -#include <chrono> #include <cstdint> -#include <list> #include <optional> #include <vector> @@ -56,7 +54,6 @@ #include "LayerVector.h" #include "Scheduler/LayerInfo.h" #include "SurfaceFlinger.h" -#include "Tracing/LayerTracing.h" #include "TransactionCallbackInvoker.h" using namespace android::surfaceflinger; @@ -97,42 +94,15 @@ public: eInputInfoChanged = 0x00000004 }; - struct Geometry { - uint32_t w; - uint32_t h; - ui::Transform transform; - - inline bool operator==(const Geometry& rhs) const { - return (w == rhs.w && h == rhs.h) && (transform.tx() == rhs.transform.tx()) && - (transform.ty() == rhs.transform.ty()); - } - inline bool operator!=(const Geometry& rhs) const { return !operator==(rhs); } - }; - using FrameRate = scheduler::LayerInfo::FrameRate; using FrameRateCompatibility = scheduler::FrameRateCompatibility; using FrameRateSelectionStrategy = scheduler::LayerInfo::FrameRateSelectionStrategy; struct State { - int32_t z; - ui::LayerStack layerStack; - uint32_t flags; int32_t sequence; // changes when visible regions can change - bool modified; // Crop is expressed in layer space coordinate. Rect crop; LayerMetadata metadata; - // If non-null, a Surface this Surface's Z-order is interpreted relative to. - wp<Layer> zOrderRelativeOf; - bool isRelativeOf{false}; - - // A list of surfaces whose Z-order is interpreted relative to ours. - SortedVector<wp<Layer>> zOrderRelatives; - half4 color; - float cornerRadius; - int backgroundBlurRadius; - gui::WindowInfo inputInfo; - wp<Layer> touchableRegionCrop; ui::Dataspace dataspace; @@ -154,52 +124,18 @@ public: std::shared_ptr<renderengine::ExternalTexture> buffer; sp<Fence> acquireFence; std::shared_ptr<FenceTime> acquireFenceTime; - HdrMetadata hdrMetadata; - Region surfaceDamageRegion; - int32_t api; sp<NativeHandle> sidebandStream; mat4 colorTransform; - bool hasColorTransform; - // pointer to background color layer that, if set, appears below the buffer state layer - // and the buffer state layer's children. Z order will be set to - // INT_MIN - sp<Layer> bgColorLayer; // The deque of callback handles for this frame. The back of the deque contains the most // recent callback handle. std::deque<sp<CallbackHandle>> callbackHandles; - bool colorSpaceAgnostic; nsecs_t desiredPresentTime = 0; bool isAutoTimestamp = true; - // Length of the cast shadow. If the radius is > 0, a shadow of length shadowRadius will - // 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; - - // Default frame rate compatibility used to set the layer refresh rate votetype. - FrameRateCompatibility defaultFrameRateCompatibility; - FrameRate frameRate; - // The combined frame rate of parents / children of this layer FrameRate frameRateForLayerTree; - FrameRateSelectionStrategy frameRateSelectionStrategy; - - // Set by window manager indicating the layer and all its children are - // in a different orientation than the display. The hint suggests that - // the graphic producers should receive a transform hint as if the - // display was in this orientation. When the display changes to match - // the layer orientation, the graphic producer may not need to allocate - // a buffer of a different size. ui::Transform::ROT_INVALID means the - // a fixed transform hint is not set. - ui::Transform::RotationFlags fixedTransformHint; - // The vsync info that was used to start the transaction FrameTimelineInfo frameTimelineInfo; @@ -219,21 +155,12 @@ public: // An arbitrary threshold for the number of BufferlessSurfaceFrames in the state. Used to // trigger a warning if the number of SurfaceFrames crosses the threshold. static constexpr uint32_t kStateSurfaceFramesThreshold = 25; - - // Stretch effect to apply to this layer - StretchEffect stretchEffect; - - // Whether or not this layer is a trusted overlay for input - bool isTrustedOverlay; Rect bufferCrop; Rect destinationFrame; sp<IBinder> releaseBufferEndpoint; - gui::DropInputMode dropInputMode; bool autoRefresh = false; - bool dimmingEnabled = true; float currentHdrSdrRatio = 1.f; float desiredHdrSdrRatio = -1.f; - gui::CachingHint cachingHint = gui::CachingHint::Enabled; int64_t latchedVsyncId = 0; bool useVsyncIdForRefreshRateSelection = false; }; @@ -245,15 +172,7 @@ public: static void miniDumpHeader(std::string& result); // Provide unique string for each class type in the Layer hierarchy - virtual const char* getType() const { return "Layer"; } - - // true if this layer is visible, false otherwise - virtual bool isVisible() const; - - // Set a 2x2 transformation matrix on the layer. This transform - // will be applied after parent transforms, but before any final - // producer specified transform. - bool setMatrix(const layer_state_t::matrix22_t& matrix); + const char* getType() const { return "Layer"; } // This second set of geometry attributes are controlled by // setGeometryAppliesWithResize, and their default mode is to be @@ -261,49 +180,9 @@ public: // while a resize is pending, then update of these attributes will // be delayed until the resize completes. - // setPosition operates in parent buffer space (pre parent-transform) or display - // space for top-level layers. - bool setPosition(float x, float y); // Buffer space bool setCrop(const Rect& crop); - // TODO(b/38182121): Could we eliminate the various latching modes by - // using the layer hierarchy? - // ----------------------------------------------------------------------- - virtual bool setLayer(int32_t z); - virtual bool setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ); - - virtual bool setAlpha(float alpha); - bool setColor(const half3& /*color*/); - - // Set rounded corner radius for this layer and its children. - // - // We only support 1 radius per layer in the hierarchy, where parent layers have precedence. - // The shape of the rounded corner rectangle is specified by the crop rectangle of the layer - // from which we inferred the rounded corner radius. - virtual bool setCornerRadius(float cornerRadius); - // 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); - bool setTransparentRegionHint(const Region& transparent); - virtual bool setTrustedOverlay(bool); - virtual bool setFlags(uint32_t flags, uint32_t mask); - virtual bool setLayerStack(ui::LayerStack); - virtual ui::LayerStack getLayerStack( - LayerVector::StateSet state = LayerVector::StateSet::Drawing) const; - - virtual bool setMetadata(const LayerMetadata& data); - virtual void setChildrenDrawingParent(const sp<Layer>&); - virtual bool setColorTransform(const mat4& matrix); - virtual mat4 getColorTransform() const; - virtual bool hasColorTransform() const; - virtual bool isColorSpaceAgnostic() const { return mDrawingState.colorSpaceAgnostic; } - virtual bool isDimmingEnabled() const { return getDrawingState().dimmingEnabled; } - float getDesiredHdrSdrRatio() const { return getDrawingState().desiredHdrSdrRatio; } - float getCurrentHdrSdrRatio() const { return getDrawingState().currentHdrSdrRatio; } - gui::CachingHint getCachingHint() const { return getDrawingState().cachingHint; } - bool setTransform(uint32_t /*transform*/); bool setTransformToDisplayInverse(bool /*transformToDisplayInverse*/); bool setBuffer(std::shared_ptr<renderengine::ExternalTexture>& /* buffer */, @@ -314,111 +193,34 @@ public: bool setDataspace(ui::Dataspace /*dataspace*/); bool setExtendedRangeBrightness(float currentBufferRatio, float desiredRatio); bool setDesiredHdrHeadroom(float desiredRatio); - bool setCachingHint(gui::CachingHint cachingHint); - bool setHdrMetadata(const HdrMetadata& /*hdrMetadata*/); - bool setSurfaceDamageRegion(const Region& /*surfaceDamage*/); - bool setApi(int32_t /*api*/); bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/, const FrameTimelineInfo& /* info*/, nsecs_t /* postTime */, gui::GameMode gameMode); bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& /*handles*/, bool willPresent); - virtual bool setColorSpaceAgnostic(const bool agnostic); - virtual bool setDimmingEnabled(const bool dimmingEnabled); - virtual bool setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint); - void setAutoRefresh(bool /* autoRefresh */); - bool setDropInputMode(gui::DropInputMode); - - ui::Dataspace getDataSpace() const; - virtual bool isFrontBuffered() const; - - virtual sp<LayerFE> getCompositionEngineLayerFE() const; - virtual sp<LayerFE> copyCompositionEngineLayerFE() const; sp<LayerFE> getCompositionEngineLayerFE(const frontend::LayerHierarchy::TraversalPath&); sp<LayerFE> getOrCreateCompositionEngineLayerFE(const frontend::LayerHierarchy::TraversalPath&); - const frontend::LayerSnapshot* getLayerSnapshot() const; - frontend::LayerSnapshot* editLayerSnapshot(); - std::unique_ptr<frontend::LayerSnapshot> stealLayerSnapshot(); - void updateLayerSnapshot(std::unique_ptr<frontend::LayerSnapshot> snapshot); - // If we have received a new buffer this frame, we will pass its surface // damage down to hardware composer. Otherwise, we must send a region with // one empty rect. - void useSurfaceDamage(); - void useEmptyDamage(); Region getVisibleRegion(const DisplayDevice*) const; void updateLastLatchTime(nsecs_t latchtime); /* - * isOpaque - true if this surface is opaque - * - * This takes into account the buffer format (i.e. whether or not the - * pixel format includes an alpha channel) and the "opaque" flag set - * on the layer. It does not examine the current plane alpha value. - */ - bool isOpaque(const Layer::State&) const; - - /* - * Returns whether this layer can receive input. - */ - bool canReceiveInput() const; - - /* - * Whether or not the layer should be considered visible for input calculations. - */ - virtual bool isVisibleForInput() const { - // For compatibility reasons we let layers which can receive input - // receive input before they have actually submitted a buffer. Because - // of this we use canReceiveInput instead of isVisible to check the - // policy-visibility, ignoring the buffer state. However for layers with - // hasInputInfo()==false we can use the real visibility state. - // We are just using these layers for occlusion detection in - // InputDispatcher, and obviously if they aren't visible they can't occlude - // anything. - return hasInputInfo() ? canReceiveInput() : isVisible(); - } - - /* * isProtected - true if the layer may contain protected contents in the * GRALLOC_USAGE_PROTECTED sense. */ bool isProtected() const; - - /* - * isFixedSize - true if content has a fixed size - */ - virtual bool isFixedSize() const { return true; } - /* * usesSourceCrop - true if content should use a source crop */ bool usesSourceCrop() const { return hasBufferOrSidebandStream(); } - // Most layers aren't created from the main thread, and therefore need to - // grab the SF state lock to access HWC, but ContainerLayer does, so we need - // to avoid grabbing the lock again to avoid deadlock - virtual bool isCreatedFromMainThread() const { return false; } - - ui::Transform getActiveTransform(const Layer::State& s) const { return s.transform; } - Region getActiveTransparentRegion(const Layer::State& s) const { - return s.transparentRegionHint; - } Rect getCrop(const Layer::State& s) const { return s.crop; } bool needsFiltering(const DisplayDevice*) const; - // True if this layer requires filtering - // This method is distinct from needsFiltering() in how the filter - // requirement is computed. needsFiltering() compares displayFrame and crop, - // where as this method transforms the displayFrame to layer-stack space - // first. This method should be used if there is no physical display to - // project onto when taking screenshots, as the filtering requirements are - // different. - // If the parent transform needs to be undone when capturing the layer, then - // the inverse parent transform is also required. - bool needsFilteringForScreenshots(const DisplayDevice*, const ui::Transform&) const; - // from graphics API static ui::Dataspace translateDataspace(ui::Dataspace dataspace); uint64_t mPreviousFrameNumber = 0; @@ -437,8 +239,6 @@ public: * operation, so this should be set only if needed). Typically this is used * to figure out if the content or size of a surface has changed. */ - bool latchBuffer(bool& /*recomputeVisibleRegions*/, nsecs_t /*latchTime*/); - bool latchBufferImpl(bool& /*recomputeVisibleRegions*/, nsecs_t /*latchTime*/, bool bgColorOnly); @@ -449,14 +249,6 @@ public: bool willReleaseBufferOnLatch() const; /* - * Calls latchBuffer if the buffer has a frame queued and then releases the buffer. - * This is used if the buffer is just latched and releases to free up the buffer - * and will not be shown on screen. - * Should only be called on the main thread. - */ - void latchAndReleaseBuffer(); - - /* * returns the rectangle that crops the content of the layer and scales it * to the layer's size. */ @@ -468,15 +260,6 @@ public: uint32_t getBufferTransform() const; sp<GraphicBuffer> getBuffer() const; - const std::shared_ptr<renderengine::ExternalTexture>& getExternalTexture() const; - - /* - * Returns if a frame is ready - */ - bool hasReadyFrame() const; - - virtual int32_t getQueuedFrameCount() const { return 0; } - /** * Returns active buffer size in the correct orientation. Buffer size is determined by undoing * any buffer transformations. Returns Rect::INVALID_RECT if the layer has no buffer or the @@ -484,33 +267,10 @@ public: */ Rect getBufferSize(const Layer::State&) const; - /** - * Returns the source bounds. If the bounds are not defined, it is inferred from the - * buffer size. Failing that, the bounds are determined from the passed in parent bounds. - * For the root layer, this is the display viewport size. - */ - FloatRect computeSourceBounds(const FloatRect& parentBounds) const; - virtual FrameRate getFrameRateForLayerTree() const; + FrameRate getFrameRateForLayerTree() const; bool getTransformToDisplayInverse() const; - // Returns how rounded corners should be drawn for this layer. - // A layer can override its parent's rounded corner settings if the parent's rounded - // corner crop does not intersect with its own rounded corner crop. - virtual frontend::RoundedCornerState getRoundedCornerState() const; - - bool hasRoundedCorners() const { return getRoundedCornerState().hasRoundedCorners(); } - - PixelFormat getPixelFormat() const; - /** - * Return whether this layer needs an input info. We generate InputWindowHandles for all - * non-cursor buffered layers regardless of whether they have an InputChannel. This is to enable - * the InputDispatcher to do PID based occlusion detection. - */ - bool needsInputInfo() const { - return (hasInputInfo() || hasBufferOrSidebandStream()) && !mPotentialCursor; - } - // Implements RefBase. void onFirstRef() override; @@ -521,17 +281,11 @@ public: uint32_t mTransform{0}; ui::Dataspace mDataspace{ui::Dataspace::UNKNOWN}; Rect mCrop; - uint32_t mScaleMode{NATIVE_WINDOW_SCALING_MODE_FREEZE}; - Region mSurfaceDamage; - HdrMetadata mHdrMetadata; - int mApi; PixelFormat mPixelFormat{PIXEL_FORMAT_NONE}; bool mTransformToDisplayInverse{false}; - std::shared_ptr<renderengine::ExternalTexture> mBuffer; uint64_t mFrameNumber; sp<IBinder> mReleaseBufferEndpoint; - bool mFrameLatencyNeeded{false}; float mDesiredHdrSdrRatio = -1.f; }; @@ -539,8 +293,6 @@ public: BufferInfo mBufferInfo; std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> mBufferReleaseChannel; - // implements compositionengine::LayerFE - const compositionengine::LayerFECompositionState* getCompositionState() const; bool fenceHasSignaled() const; void onPreComposition(nsecs_t refreshStartTime); void onLayerDisplayed(ftl::SharedFuture<FenceResult>, ui::LayerStack layerStack, @@ -561,15 +313,6 @@ public: const char* getDebugName() const; - bool setShadowRadius(float shadowRadius); - - // Before color management is introduced, contents on Android have to be - // desaturated in order to match what they appears like visually. - // With color management, these contents will appear desaturated, thus - // needed to be saturated so that they match what they are designed for - // visually. - bool isLegacyDataSpace() const; - uint32_t getTransactionFlags() const { return mTransactionFlags; } static bool computeTrustedPresentationState(const FloatRect& bounds, @@ -592,14 +335,6 @@ public: // Clears and returns the masked bits. uint32_t clearTransactionFlags(uint32_t mask); - FloatRect getBounds(const Region& activeTransparentRegion) const; - FloatRect getBounds() const; - Rect getInputBoundsInDisplaySpace(const FloatRect& insetBounds, - const ui::Transform& displayTransform); - - // Compute bounds for the layer and cache the results. - void computeBounds(FloatRect parentBounds, ui::Transform parentTransform, float shadowRadius); - int32_t getSequence() const { return sequence; } // For tracing. @@ -610,90 +345,35 @@ public: // only used within a single layer. uint64_t getCurrentBufferId() const { return getBuffer() ? getBuffer()->getId() : 0; } - /* - * isSecure - true if this surface is secure, that is if it prevents - * screenshots or VNC servers. A surface can be set to be secure by the - * application, being secure doesn't mean the surface has DRM contents. - */ - bool isSecure() const; - - /* - * isHiddenByPolicy - true if this layer has been forced invisible. - * just because this is false, doesn't mean isVisible() is true. - * For example if this layer has no active buffer, it may not be hidden by - * policy, but it still can not be visible. - */ - bool isHiddenByPolicy() const; - - // True if the layer should be skipped in screenshots, screen recordings, - // and mirroring to external or virtual displays. - bool isInternalDisplayOverlay() const; - - ui::LayerFilter getOutputFilter() const { - return {getLayerStack(), isInternalDisplayOverlay()}; - } - - perfetto::protos::LayerProto* writeToProto(perfetto::protos::LayersProto& layersProto, - uint32_t traceFlags); void writeCompositionStateToProto(perfetto::protos::LayerProto* layerProto, ui::LayerStack layerStack); - // Write states that are modified by the main thread. This includes drawing - // state as well as buffer data. This should be called in the main or tracing - // thread. - void writeToProtoDrawingState(perfetto::protos::LayerProto* layerInfo); - // Write drawing or current state. If writing current state, the caller should hold the - // external mStateLock. If writing drawing state, this function should be called on the - // main or tracing thread. - void writeToProtoCommonState(perfetto::protos::LayerProto* layerInfo, LayerVector::StateSet, - uint32_t traceFlags = LayerTracing::TRACE_ALL); - gui::WindowInfo::Type getWindowType() const { return mWindowType; } /* * doTransaction - process the transaction. This is a good place to figure * out which attributes of the surface have changed. */ - virtual uint32_t doTransaction(uint32_t transactionFlags); - - /* - * Remove relative z for the layer if its relative parent is not part of the - * provided layer tree. - */ - void removeRelativeZ(const std::vector<Layer*>& layersInTree); + uint32_t doTransaction(uint32_t transactionFlags); inline const State& getDrawingState() const { return mDrawingState; } inline State& getDrawingState() { return mDrawingState; } void miniDump(std::string& result, const frontend::LayerSnapshot&, const DisplayDevice&) const; void dumpFrameStats(std::string& result) const; - void dumpOffscreenDebugInfo(std::string& result) const; void clearFrameStats(); void logFrameStats(); void getFrameStats(FrameStats* outStats) const; void onDisconnect(); ui::Transform getTransform() const; - bool isTransformValid() const; - // Returns the Alpha of the Surface, accounting for the Alpha - // of parent Surfaces in the hierarchy (alpha's will be multiplied - // down the hierarchy). - half getAlpha() const; half4 getColor() const; int32_t getBackgroundBlurRadius() const; bool drawShadows() const { return mEffectiveShadowRadius > 0.f; }; - // Returns the transform hint set by Window Manager on the layer or one of its parents. - // This traverses the current state because the data is needed when creating - // the layer(off drawing thread) and the hint should be available before the producer - // is ready to acquire a buffer. - ui::Transform::RotationFlags getFixedTransformHint() const; - bool isHandleAlive() const { return mHandleAlive; } bool onHandleDestroyed() { return mHandleAlive = false; } - Rect getScreenBounds(bool reduceTransparentRegion = true) const; - int32_t getZ(LayerVector::StateSet) const; /** * Returns the cropped buffer size or the layer crop if the layer has no buffer. Return @@ -703,7 +383,7 @@ public: */ Rect getCroppedBufferSize(const Layer::State& s) const; - virtual void setFrameTimelineInfoForBuffer(const FrameTimelineInfo& /*info*/) {} + void setFrameTimelineInfoForBuffer(const FrameTimelineInfo& /*info*/) {} void setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, nsecs_t postTime, gui::GameMode gameMode); void setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info, @@ -732,31 +412,14 @@ public: // this to be called once. sp<IBinder> getHandle(); const std::string& getName() const { return mName; } - bool getPremultipledAlpha() const; void setInputInfo(const gui::WindowInfo& info); - struct InputDisplayArgs { - const ui::Transform* transform = nullptr; - bool isSecure = false; - }; - gui::WindowInfo fillInputInfo(const InputDisplayArgs& displayArgs); - - /** - * Returns whether this layer has an explicitly set input-info. - */ - bool hasInputInfo() const; - virtual uid_t getOwnerUid() const { return mOwnerUid; } pid_t getOwnerPid() { return mOwnerPid; } int32_t getOwnerAppId() { return mOwnerAppId; } - mutable bool contentDirty{false}; - Region surfaceDamageRegion; - - // True when the surfaceDamageRegion is recognized as a small area update. - bool mSmallDirty{false}; // Used to check if mUsedVsyncIdForRefreshRateSelection should be expired when it stop updating. nsecs_t mMaxTimeForUseVsyncId = 0; // True when DrawState.useVsyncIdForRefreshRateSelection previously set to true during updating @@ -770,35 +433,11 @@ public: bool mPendingHWCDestroy{false}; - bool backpressureEnabled() const { - return mDrawingState.flags & layer_state_t::eEnableBackpressure; - } - - bool setStretchEffect(const StretchEffect& effect); - bool setBufferCrop(const Rect& /* bufferCrop */); - bool setDestinationFrame(const Rect& /* destinationFrame */); // See mPendingBufferTransactions void decrementPendingBufferCount(); std::atomic<int32_t>* getPendingBufferCounter() { return &mPendingBufferTransactions; } std::string getPendingBufferCounterName() { return mBlastTransactionName; } - bool updateGeometry(); - - bool isSimpleBufferUpdate(const layer_state_t& s) const; - - static bool isOpaqueFormat(PixelFormat format); - - // Updates the LayerSnapshot. This must be called prior to sending layer data to - // CompositionEngine or RenderEngine (i.e. before calling CompositionEngine::present or - // LayerFE::prepareClientComposition). - // - // TODO(b/238781169) Remove direct calls to RenderEngine::drawLayers that don't go through - // CompositionEngine to create a single path for composing layers. - void updateSnapshot(bool updateGeometry); - void updateChildrenSnapshots(bool updateGeometry); - - bool willPresentCurrentTransaction() const; - void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener, const sp<GraphicBuffer>& buffer, uint64_t framenumber, const sp<Fence>& releaseFence); @@ -844,7 +483,6 @@ public: const sp<SurfaceFlinger> mFlinger; // Check if the damage region is a small dirty. - void setIsSmallDirty(const Region& damageRegion, const ui::Transform& layerToDisplayTransform); void setIsSmallDirty(frontend::LayerSnapshot* snapshot); protected: @@ -856,52 +494,16 @@ protected: friend class TransactionFrameTracerTest; friend class TransactionSurfaceFrameTest; - void preparePerFrameCompositionState(); - void preparePerFrameBufferCompositionState(); - void preparePerFrameEffectsCompositionState(); void gatherBufferInfo(); - void prepareBasicGeometryCompositionState(); - void prepareGeometryCompositionState(); - void prepareCursorCompositionState(); - - uint32_t getEffectiveUsage(uint32_t usage) const; - - /** - * Setup rounded corners coordinates of this layer, taking into account the layer bounds and - * crop coordinates, transforming them into layer space. - */ - void setupRoundedCornersCropCoordinates(Rect win, const FloatRect& roundedCornersCrop) const; - void setParent(const sp<Layer>&); - LayerVector makeTraversalList(LayerVector::StateSet, bool* outSkipRelativeZUsers); - void addZOrderRelative(const wp<Layer>& relative); - void removeZOrderRelative(const wp<Layer>& relative); compositionengine::OutputLayer* findOutputLayerForDisplay(const DisplayDevice*) const; compositionengine::OutputLayer* findOutputLayerForDisplay( const DisplayDevice*, const frontend::LayerHierarchy::TraversalPath& path) const; - bool usingRelativeZ(LayerVector::StateSet) const; - - virtual ui::Transform getInputTransform() const; - /** - * Get the bounds in layer space within which this layer can receive input. - * - * These bounds are used to: - * - Determine the input frame for the layer to be used for occlusion detection; and - * - Determine the coordinate space within which the layer will receive input. The top-left of - * this rect will be the origin of the coordinate space that the input events sent to the - * layer will be in (prior to accounting for surface insets). - * - * The layer can still receive touch input if these bounds are invalid if - * "replaceTouchableRegionWithCrop" is specified. In this case, the layer will receive input - * in this layer's space, regardless of the specified crop layer. - */ - std::pair<FloatRect, bool> getInputBounds(bool fillParentBounds) const; - bool mPremultipliedAlpha{true}; const std::string mName; const std::string mTransactionName{"TX - " + mName}; - // These are only accessed by the main thread or the tracing thread. + // These are only accessed by the main thread. State mDrawingState; TrustedPresentationThresholds mTrustedPresentationThresholds; @@ -921,34 +523,16 @@ protected: // main thread sp<NativeHandle> mSidebandStream; - // False if the buffer and its contents have been previously used for GPU - // composition, true otherwise. - bool mIsActiveBufferUpdatedForGpu = true; // We encode unset as -1. std::atomic<uint64_t> mCurrentFrameNumber{0}; - // Whether filtering is needed b/c of the drawingstate - bool mNeedsFiltering{false}; - - std::atomic<bool> mRemovedFromDrawingState{false}; - - // page-flip thread (currently main thread) - bool mProtectedByApp{false}; // application requires protected path to external sink // protected by mLock mutable Mutex mLock; - const wp<Client> mClientRef; - // This layer can be a cursor on some displays. bool mPotentialCursor{false}; - LayerVector mCurrentChildren{LayerVector::StateSet::Current}; - LayerVector mDrawingChildren{LayerVector::StateSet::Drawing}; - - wp<Layer> mCurrentParent; - wp<Layer> mDrawingParent; - // Window types from WindowManager.LayoutParams const gui::WindowInfo::Type mWindowType; @@ -966,8 +550,6 @@ protected: // Used in buffer stuffing analysis in FrameTimeline. nsecs_t mLastLatchTime = 0; - mutable bool mDrawingStateModified = false; - sp<Fence> mLastClientCompositionFence; bool mClearClientCompositionFenceOnLayerDisplayed = false; private: @@ -979,44 +561,20 @@ private: friend class TransactionFrameTracerTest; friend class TransactionSurfaceFrameTest; - bool getAutoRefresh() const { return mDrawingState.autoRefresh; } bool getSidebandStreamChanged() const { return mSidebandStreamChanged; } std::atomic<bool> mSidebandStreamChanged{false}; - // Returns true if the layer can draw shadows on its border. - virtual bool canDrawShadows() const { return true; } - aidl::android::hardware::graphics::composer3::Composition getCompositionType( const DisplayDevice&) const; aidl::android::hardware::graphics::composer3::Composition getCompositionType( const compositionengine::OutputLayer*) const; - bool propagateFrameRateForLayerTree(FrameRate parentFrameRate, bool overrideChildren, - bool* transactionNeeded); - void setZOrderRelativeOf(const wp<Layer>& relativeOf); - bool isTrustedOverlay() const; - gui::DropInputMode getDropInputMode() const; - void handleDropInputMode(gui::WindowInfo& info) const; - - // Finds the top most layer in the hierarchy. This will find the root Layer where the parent is - // null. - sp<Layer> getRootLayer(); - - // Fills in the touch occlusion mode of the first parent (including this layer) that - // hasInputInfo() or no-op if no such parent is found. - void fillTouchOcclusionMode(gui::WindowInfo& info); - - // Fills in the frame and transform info for the gui::WindowInfo. - void fillInputFrameInfo(gui::WindowInfo&, const ui::Transform& screenToDisplay); - inline void tracePendingBufferCount(int32_t pendingBuffers); // Latch sideband stream and returns true if the dirty region should be updated. bool latchSidebandStream(bool& recomputeVisibleRegions); - bool hasFrameUpdate() const; - void updateTexImage(nsecs_t latchTime, bool bgColorOnly = false); // Crop that applies to the buffer @@ -1027,15 +585,6 @@ private: const sp<Fence>& releaseFence, uint32_t currentMaxAcquiredBufferCount); - // Returns true if the transformed buffer size does not match the layer size and we need - // to apply filtering. - bool bufferNeedsFiltering() const; - - // Returns true if there is a valid color to fill. - bool fillsColor() const; - // Returns true if this layer has a blur value. - bool hasBlur() const; - bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); } bool hasBufferOrSidebandStream() const { return ((mSidebandStream != nullptr) || (mBufferInfo.mBuffer != nullptr)); } @@ -1044,33 +593,6 @@ private: return ((mDrawingState.sidebandStream != nullptr) || (mDrawingState.buffer != nullptr)); } - bool hasSomethingToDraw() const { return hasEffect() || hasBufferOrSidebandStream(); } - - bool shouldOverrideChildrenFrameRate() const { - return getDrawingState().frameRateSelectionStrategy == - FrameRateSelectionStrategy::OverrideChildren; - } - - bool shouldPropagateFrameRate() const { - return getDrawingState().frameRateSelectionStrategy != FrameRateSelectionStrategy::Self; - } - - // Cached properties computed from drawing state - // Effective transform taking into account parent transforms and any parent scaling, which is - // a transform from the current layer coordinate space to display(screen) coordinate space. - ui::Transform mEffectiveTransform; - - // Bounds of the layer before any transformation is applied and before it has been cropped - // by its parents. - FloatRect mSourceBounds; - - // Bounds of the layer in layer space. This is the mSourceBounds cropped by its layer crop and - // its parent bounds. - FloatRect mBounds; - - // Layer bounds in screen space. - FloatRect mScreenBounds; - bool mGetHandleCalled = false; // The inherited shadow radius after taking into account the layer hierarchy. This is the @@ -1081,15 +603,10 @@ private: // Game mode for the layer. Set by WindowManagerShell and recorded by SurfaceFlingerStats. gui::GameMode mGameMode = gui::GameMode::Unsupported; - // A list of regions on this layer that should have blurs. - const std::vector<BlurRegion> getBlurRegions() const; - bool mIsAtRoot = false; uint32_t mLayerCreationFlags; - bool findInHierarchy(const sp<Layer>&); - void releasePreviousBuffer(); void resetDrawingStateBufferInfo(); @@ -1122,10 +639,7 @@ private: // not specify a destination frame. ui::Transform mRequestedTransform; - sp<LayerFE> mLegacyLayerFE; std::vector<std::pair<frontend::LayerHierarchy::TraversalPath, sp<LayerFE>>> mLayerFEs; - std::unique_ptr<frontend::LayerSnapshot> mSnapshot = - std::make_unique<frontend::LayerSnapshot>(); bool mHandleAlive = false; }; diff --git a/services/surfaceflinger/LayerProtoHelper.cpp b/services/surfaceflinger/LayerProtoHelper.cpp index 885c3d3460..5eea45b436 100644 --- a/services/surfaceflinger/LayerProtoHelper.cpp +++ b/services/surfaceflinger/LayerProtoHelper.cpp @@ -178,7 +178,7 @@ void LayerProtoHelper::writeToProto( } void LayerProtoHelper::writeToProto( - const WindowInfo& inputInfo, const wp<Layer>& touchableRegionBounds, + const WindowInfo& inputInfo, std::function<perfetto::protos::InputWindowInfoProto*()> getInputWindowInfoProto) { if (inputInfo.token == nullptr) { return; @@ -208,13 +208,6 @@ void LayerProtoHelper::writeToProto( proto->set_global_scale_factor(inputInfo.globalScaleFactor); LayerProtoHelper::writeToProtoDeprecated(inputInfo.transform, proto->mutable_transform()); proto->set_replace_touchable_region_with_crop(inputInfo.replaceTouchableRegionWithCrop); - auto cropLayer = touchableRegionBounds.promote(); - if (cropLayer != nullptr) { - proto->set_crop_layer_id(cropLayer->sequence); - LayerProtoHelper::writeToProto(cropLayer->getScreenBounds( - false /* reduceTransparentRegion */), - [&]() { return proto->mutable_touchable_region_crop(); }); - } } void LayerProtoHelper::writeToProto(const mat4 matrix, @@ -482,7 +475,7 @@ void LayerProtoHelper::writeSnapshotToProto(perfetto::protos::LayerProto* layerI layerInfo->set_owner_uid(requestedState.ownerUid.val()); if ((traceFlags & LayerTracing::TRACE_INPUT) && snapshot.hasInputInfo()) { - LayerProtoHelper::writeToProto(snapshot.inputInfo, {}, + LayerProtoHelper::writeToProto(snapshot.inputInfo, [&]() { return layerInfo->mutable_input_window_info(); }); } diff --git a/services/surfaceflinger/LayerProtoHelper.h b/services/surfaceflinger/LayerProtoHelper.h index c0198b62ec..41ea68420f 100644 --- a/services/surfaceflinger/LayerProtoHelper.h +++ b/services/surfaceflinger/LayerProtoHelper.h @@ -62,7 +62,7 @@ public: const renderengine::ExternalTexture& buffer, std::function<perfetto::protos::ActiveBufferProto*()> getActiveBufferProto); static void writeToProto( - const gui::WindowInfo& inputInfo, const wp<Layer>& touchableRegionBounds, + const gui::WindowInfo& inputInfo, std::function<perfetto::protos::InputWindowInfoProto*()> getInputWindowInfoProto); static void writeToProto(const mat4 matrix, perfetto::protos::ColorTransformProto* colorTransformProto); diff --git a/services/surfaceflinger/LayerVector.cpp b/services/surfaceflinger/LayerVector.cpp index ff0a955ad6..13e054e249 100644 --- a/services/surfaceflinger/LayerVector.cpp +++ b/services/surfaceflinger/LayerVector.cpp @@ -45,16 +45,6 @@ int LayerVector::do_compare(const void* lhs, const void* rhs) const const auto& lState = l->getDrawingState(); const auto& rState = r->getDrawingState(); - const auto ls = lState.layerStack; - const auto rs = rState.layerStack; - if (ls != rs) - return (ls > rs) ? 1 : -1; - - int32_t lz = lState.z; - int32_t rz = rState.z; - if (lz != rz) - return (lz > rz) ? 1 : -1; - if (l->sequence == r->sequence) return 0; diff --git a/services/surfaceflinger/RenderArea.h b/services/surfaceflinger/RenderArea.h index 034e467be9..aa66ccf172 100644 --- a/services/surfaceflinger/RenderArea.h +++ b/services/surfaceflinger/RenderArea.h @@ -39,21 +39,6 @@ public: mReqDataSpace(reqDataSpace), mCaptureFill(captureFill) {} - static std::function<std::vector<std::pair<Layer*, sp<LayerFE>>>()> fromTraverseLayersLambda( - std::function<void(const LayerVector::Visitor&)> traverseLayers) { - return [traverseLayers = std::move(traverseLayers)]() { - std::vector<std::pair<Layer*, sp<LayerFE>>> layers; - traverseLayers([&](Layer* layer) { - // Layer::prepareClientComposition uses the layer's snapshot to populate the - // resulting LayerSettings. Calling Layer::updateSnapshot ensures that LayerSettings - // are generated with the layer's current buffer and geometry. - layer->updateSnapshot(true /* updateGeometry */); - layers.emplace_back(layer, layer->copyCompositionEngineLayerFE()); - }); - return layers; - }; - } - virtual ~RenderArea() = default; // Returns true if the render area is secure. A secure layer should be diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 00e32e2dfb..adb5ab1bd7 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2751,7 +2751,8 @@ CompositeResultsPerDisplay SurfaceFlinger::composite( if (!FlagManager::getInstance().ce_fence_promise()) { refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); for (auto& [layer, _] : mLayersWithQueuedFrames) { - if (const auto& layerFE = layer->getCompositionEngineLayerFE()) + if (const auto& layerFE = layer->getCompositionEngineLayerFE( + {static_cast<uint32_t>(layer->sequence)})) refreshArgs.layersWithQueuedFrames.push_back(layerFE); } } @@ -2827,7 +2828,8 @@ CompositeResultsPerDisplay SurfaceFlinger::composite( refreshArgs.layersWithQueuedFrames.reserve(mLayersWithQueuedFrames.size()); for (auto& [layer, _] : mLayersWithQueuedFrames) { - if (const auto& layerFE = layer->getCompositionEngineLayerFE()) { + if (const auto& layerFE = layer->getCompositionEngineLayerFE( + {static_cast<uint32_t>(layer->sequence)})) { refreshArgs.layersWithQueuedFrames.push_back(layerFE); // Some layers are not displayed and do not yet have a future release fence if (layerFE->getReleaseFencePromiseStatus() == @@ -3923,7 +3925,6 @@ void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { // Commit display transactions. const bool displayTransactionNeeded = transactionFlags & eDisplayTransactionNeeded; mFrontEndDisplayInfosChanged = displayTransactionNeeded; - mForceTransactionDisplayChange = displayTransactionNeeded; if (mSomeChildrenChanged) { mVisibleRegionsDirty = true; diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 459fd5ad46..7c7cf35c96 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -1230,7 +1230,6 @@ private: // TODO: Also move visibleRegions over to a boolean system. bool mUpdateInputInfo = false; bool mSomeChildrenChanged; - bool mForceTransactionDisplayChange = false; bool mUpdateAttachedChoreographer = false; struct LayerIntHash { diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index 710b5cc623..22d7b242f2 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -335,13 +335,6 @@ public: return mFlinger->mLegacyLayers[layerId]->findOutputLayerForDisplay(display.get()); } - static void setLayerSidebandStream(const sp<Layer>& layer, - const sp<NativeHandle>& sidebandStream) { - layer->mDrawingState.sidebandStream = sidebandStream; - layer->mSidebandStream = sidebandStream; - layer->editLayerSnapshot()->sidebandStream = sidebandStream; - } - void setLayerCompositionType(const sp<Layer>& layer, aidl::android::hardware::graphics::composer3::Composition type) { auto outputLayer = findOutputLayerForDisplay(static_cast<uint32_t>(layer->sequence), @@ -352,10 +345,6 @@ public: (*state.hwc).hwcCompositionType = type; } - static void setLayerDrawingParent(const sp<Layer>& layer, const sp<Layer>& drawingParent) { - layer->mDrawingParent = drawingParent; - } - /* ------------------------------------------------------------------------ * Forwarding for functions being tested */ diff --git a/services/surfaceflinger/tests/unittests/mock/MockLayer.h b/services/surfaceflinger/tests/unittests/mock/MockLayer.h index fdb6f4dafe..45f86fa1a8 100644 --- a/services/surfaceflinger/tests/unittests/mock/MockLayer.h +++ b/services/surfaceflinger/tests/unittests/mock/MockLayer.h @@ -31,15 +31,11 @@ public: explicit MockLayer(SurfaceFlinger* flinger) : MockLayer(flinger, "TestLayer") {} - MOCK_CONST_METHOD0(getType, const char*()); MOCK_METHOD0(getFrameSelectionPriority, int32_t()); - MOCK_CONST_METHOD0(isVisible, bool()); MOCK_METHOD0(createClone, sp<Layer>()); MOCK_CONST_METHOD0(getFrameRateForLayerTree, FrameRate()); MOCK_CONST_METHOD0(getDefaultFrameRateCompatibility, scheduler::FrameRateCompatibility()); MOCK_CONST_METHOD0(getOwnerUid, uid_t()); - MOCK_CONST_METHOD0(getDataSpace, ui::Dataspace()); - MOCK_METHOD(bool, isFrontBuffered, (), (const, override)); }; } // namespace android::mock |