diff options
| author | 2022-01-24 20:10:35 +0000 | |
|---|---|---|
| committer | 2022-01-24 20:10:35 +0000 | |
| commit | 63fcbac38195980a2c6ab6265ce02d525772d0a7 (patch) | |
| tree | 820ec97e1255e9e6de743d2fe301300ec5599836 /services/surfaceflinger/SurfaceFlinger.cpp | |
| parent | 582c98b9be21d1bef49b8a7c8d5138c22c36b3ed (diff) | |
| parent | b64a3b46c2870ab7ded787ea317cc84db4e255c3 (diff) | |
Merge changes I693c514a,Ibfdf403d,Ie260fb09,If07953b4
* changes:
SF: Pass timestamps into layer tracing
SF: Commit created layers without using transactions
SF: Only create a starting entry if there are starting states
SF: Allow privileged clients to create layers offscreen
Diffstat (limited to 'services/surfaceflinger/SurfaceFlinger.cpp')
| -rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 137 |
1 files changed, 56 insertions, 81 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 88317e98fe..f7b243a8ac 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2139,7 +2139,8 @@ bool SurfaceFlinger::commit(nsecs_t frameTime, int64_t vsyncId, nsecs_t expected bool needsTraversal = false; if (clearTransactionFlags(eTransactionFlushNeeded)) { - needsTraversal = flushTransactionQueues(vsyncId); + needsTraversal |= commitCreatedLayers(); + needsTraversal |= flushTransactionQueues(vsyncId); } const bool shouldCommit = @@ -2181,6 +2182,11 @@ bool SurfaceFlinger::commit(nsecs_t frameTime, int64_t vsyncId, nsecs_t expected updateCursorAsync(); updateInputFlinger(); + if (mLayerTracingEnabled && !mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { + // This will block and tracing should only be enabled for debugging. + mLayerTracing.notify(mVisibleRegionsDirty, frameTime); + } + MAIN_THREAD_GUARD(persistDisplayBrightness(mustComposite)); return mustComposite && CC_LIKELY(mBootStage != BootStage::BOOTLOADER); @@ -2282,13 +2288,9 @@ void SurfaceFlinger::composite(nsecs_t frameTime) { modulateVsync(&VsyncModulator::onDisplayRefresh, usedGpuComposition); mLayersWithQueuedFrames.clear(); - if (mLayerTracingEnabled) { + if (mLayerTracingEnabled && mLayerTracing.flagIsSet(LayerTracing::TRACE_COMPOSITION)) { // This will block and should only be used for debugging. - if (mVisibleRegionsDirty) { - mLayerTracing.notify("visibleRegionsDirty"); - } else if (mLayerTracing.flagIsSet(LayerTracing::TRACE_BUFFERS)) { - mLayerTracing.notify("bufferLatched"); - } + mLayerTracing.notify(mVisibleRegionsDirty, frameTime); } mVisibleRegionsWereDirtyThisFrame = mVisibleRegionsDirty; // Cache value for use in post-comp @@ -3605,7 +3607,7 @@ bool SurfaceFlinger::latchBuffers() { } status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, const sp<IBinder>& handle, - const sp<Layer>& lbc, const wp<Layer>& parent, + const sp<Layer>& layer, const wp<Layer>& parent, bool addToRoot, uint32_t* outTransformHint) { if (mNumLayers >= ISurfaceComposer::MAX_LAYERS) { ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(), @@ -3613,31 +3615,22 @@ status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, const sp<IBind return NO_MEMORY; } - setLayerCreatedState(handle, lbc, parent, addToRoot); - - // Create a transaction includes the initial parent and producer. - Vector<ComposerState> states; - Vector<DisplayState> displays; - - ComposerState composerState; - composerState.state.what = layer_state_t::eLayerCreated; - composerState.state.surface = handle; - states.add(composerState); + { + std::scoped_lock<std::mutex> lock(mCreatedLayersLock); + mCreatedLayers.emplace_back(layer, parent, addToRoot); + } - lbc->updateTransformHint(mActiveDisplayTransformHint); + layer->updateTransformHint(mActiveDisplayTransformHint); if (outTransformHint) { *outTransformHint = mActiveDisplayTransformHint; } // attach this layer to the client if (client != nullptr) { - client->attachLayer(handle, lbc); + client->attachLayer(handle, layer); } - int64_t transactionId = (((int64_t)mPid) << 32) | mUniqueTransactionId++; - return setTransactionState(FrameTimelineInfo{}, states, displays, 0 /* flags */, nullptr, - InputWindowCommands{}, -1 /* desiredPresentTime */, - true /* isAutoTimestamp */, {}, false /* hasListenerCallbacks */, {}, - transactionId); + setTransactionFlags(eTransactionNeeded); + return NO_ERROR; } uint32_t SurfaceFlinger::getTransactionFlags() const { @@ -4222,15 +4215,7 @@ uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTime uint32_t flags = 0; sp<Layer> layer = nullptr; if (s.surface) { - if (what & layer_state_t::eLayerCreated) { - layer = handleLayerCreatedLocked(s.surface); - if (layer) { - flags |= eTransactionNeeded | eTraversalNeeded; - mLayersAdded = true; - } - } else { - layer = fromHandle(s.surface).promote(); - } + layer = fromHandle(s.surface).promote(); } else { // The client may provide us a null handle. Treat it as if the layer was removed. ALOGW("Attempt to set client state with a null layer handle"); @@ -4574,7 +4559,7 @@ status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args, args.name, mirrorFrom->sequence); } return addClientLayer(args.client, *outHandle, mirrorLayer /* layer */, nullptr /* parent */, - false /* addAsRoot */, nullptr /* outTransformHint */); + false /* addToRoot */, nullptr /* outTransformHint */); } status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, sp<IBinder>* outHandle, @@ -4614,7 +4599,7 @@ status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, sp<IBinder>* outHa return result; } - bool addToRoot = callingThreadHasUnscopedSurfaceFlingerAccess(); + bool addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess(); wp<Layer> parent(parentHandle != nullptr ? fromHandle(parentHandle) : parentLayer); if (parentHandle != nullptr && parent == nullptr) { ALOGE("Invalid parent handle %p.", parentHandle.get()); @@ -4641,7 +4626,6 @@ status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, sp<IBinder>* outHa return result; } - setTransactionFlags(eTransactionNeeded); *outLayerId = layer->sequence; return result; } @@ -5794,12 +5778,18 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r } case 1025: { // Set layer tracing n = data.readInt32(); + int64_t fixedStartingTime = data.readInt64(); bool tracingEnabledChanged; if (n) { ALOGD("LayerTracing enabled"); tracingEnabledChanged = mLayerTracing.enable(); if (tracingEnabledChanged) { - mScheduler->schedule([&]() MAIN_THREAD { mLayerTracing.notify("start"); }) + int64_t startingTime = + (fixedStartingTime) ? fixedStartingTime : systemTime(); + mScheduler + ->schedule([&]() MAIN_THREAD { + mLayerTracing.notify("start", startingTime); + }) .wait(); } } else { @@ -7100,53 +7090,19 @@ void TransactionState::traverseStatesWithBuffers( } } -void SurfaceFlinger::setLayerCreatedState(const sp<IBinder>& handle, const wp<Layer>& layer, - const wp<Layer> parent, bool addToRoot) { - Mutex::Autolock lock(mCreatedLayersLock); - mCreatedLayers[handle->localBinder()] = - std::make_unique<LayerCreatedState>(layer, parent, addToRoot); -} - -auto SurfaceFlinger::getLayerCreatedState(const sp<IBinder>& handle) { - Mutex::Autolock lock(mCreatedLayersLock); - BBinder* b = nullptr; - if (handle) { - b = handle->localBinder(); - } - - if (b == nullptr) { - return std::unique_ptr<LayerCreatedState>(nullptr); - } - - auto it = mCreatedLayers.find(b); - if (it == mCreatedLayers.end()) { - ALOGE("Can't find layer from handle %p", handle.get()); - return std::unique_ptr<LayerCreatedState>(nullptr); - } - - auto state = std::move(it->second); - mCreatedLayers.erase(it); - return state; -} - -sp<Layer> SurfaceFlinger::handleLayerCreatedLocked(const sp<IBinder>& handle) { - const auto& state = getLayerCreatedState(handle); - if (!state) { - return nullptr; - } - - sp<Layer> layer = state->layer.promote(); +void SurfaceFlinger::handleLayerCreatedLocked(const LayerCreatedState& state) { + sp<Layer> layer = state.layer.promote(); if (!layer) { - ALOGE("Invalid layer %p", state->layer.unsafe_get()); - return nullptr; + ALOGD("Layer was destroyed soon after creation %p", state.layer.unsafe_get()); + return; } sp<Layer> parent; - bool addToRoot = state->addToRoot; - if (state->initialParent != nullptr) { - parent = state->initialParent.promote(); + bool addToRoot = state.addToRoot; + if (state.initialParent != nullptr) { + parent = state.initialParent.promote(); if (parent == nullptr) { - ALOGE("Invalid parent %p", state->initialParent.unsafe_get()); + ALOGD("Parent was destroyed soon after creation %p", state.initialParent.unsafe_get()); addToRoot = false; } } @@ -7166,7 +7122,6 @@ sp<Layer> SurfaceFlinger::handleLayerCreatedLocked(const sp<IBinder>& handle) { layer->updateTransformHint(mActiveDisplayTransformHint); mInterceptor->saveSurfaceCreation(layer); - return layer; } void SurfaceFlinger::sample() { @@ -7248,6 +7203,26 @@ std::shared_ptr<renderengine::ExternalTexture> SurfaceFlinger::getExternalTextur layerName); return buffer; } + +bool SurfaceFlinger::commitCreatedLayers() { + std::vector<LayerCreatedState> createdLayers; + { + std::scoped_lock<std::mutex> lock(mCreatedLayersLock); + createdLayers = std::move(mCreatedLayers); + mCreatedLayers.clear(); + if (createdLayers.size() == 0) { + return false; + } + } + + Mutex::Autolock _l(mStateLock); + for (const auto& createdLayer : createdLayers) { + handleLayerCreatedLocked(createdLayer); + } + createdLayers.clear(); + mLayersAdded = true; + return true; +} } // namespace android #if defined(__gl_h_) |