Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82694290 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Stabilize libgui RegionSamplingTests" into main

parents 799de38b f2d8a821
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -3020,6 +3020,20 @@ status_t SurfaceComposerClient::addRegionSamplingListener(
    return statusTFromBinderStatus(status);
}

status_t SurfaceComposerClient::addRegionSamplingListenerWithStopLayerId(
        const Rect& samplingArea, const int32_t stopLayerId,
        const sp<IRegionSamplingListener>& listener) {
    gui::ARect rect;
    rect.left = samplingArea.left;
    rect.top = samplingArea.top;
    rect.right = samplingArea.right;
    rect.bottom = samplingArea.bottom;
    binder::Status status =
            ComposerServiceAIDL::getComposerService()
                    ->addRegionSamplingListenerWithStopLayerId(rect, stopLayerId, listener);
    return statusTFromBinderStatus(status);
}

status_t SurfaceComposerClient::removeRegionSamplingListener(
        const sp<IRegionSamplingListener>& listener) {
    binder::Status status =
@@ -3027,6 +3041,13 @@ status_t SurfaceComposerClient::removeRegionSamplingListener(
    return statusTFromBinderStatus(status);
}

status_t SurfaceComposerClient::getRegionSamplingListeners(
        std::vector<gui::RegionSamplingDescriptor>* listeners) {
    binder::Status status =
            ComposerServiceAIDL::getComposerService()->getRegionSamplingListeners(listeners);
    return statusTFromBinderStatus(status);
}

status_t SurfaceComposerClient::addFpsListener(int32_t taskId,
                                               const sp<gui::IFpsListener>& listener) {
    binder::Status status =
+27 −3
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.gui.IJankListener;
import android.gui.LayerCaptureArgs;
import android.gui.OverlayProperties;
import android.gui.PullAtomData;
import android.gui.RegionSamplingDescriptor;
import android.gui.ScreenCaptureResults;
import android.gui.ARect;
import android.gui.SchedulingPolicy;
@@ -350,19 +351,42 @@ interface ISurfaceComposer {
     * The sampling area is bounded by both samplingArea and the given stopLayerHandle
     * (i.e., only layers behind the stop layer will be captured and sampled).
     *
     * Multiple listeners may be provided so long as they have independent listeners.
     * If multiple listeners are provided, the effective sampling region for each listener will
     * be bounded by whichever stop layer has a lower Z value.
     * Multiple listeners for the same sampling region may be provided so long as they have
     * independent IRegionSamplingListener objects. If multiple listeners are provided, the
     * effective sampling region for each listener will be bounded by whichever stop layer has
     * a lower Z-value.
     *
     * Requires the same permissions as captureLayers and captureScreen.
     */
    void addRegionSamplingListener(in ARect samplingArea, @nullable IBinder stopLayerHandle, IRegionSamplingListener listener);

    /**
     * Registers a listener by stopLayerId to stream median luma updates from SurfaceFlinger.
     *
     * The sampling area is bounded by both samplingArea and the given stopLayerId
     * (i.e., only layers behind the stop layer will be captured and sampled).
     *
     * Multiple listeners for the same sampling region may be provided so long as they have
     * independent IRegionSamplingListener objects. If multiple listeners are provided, the
     * effective sampling region for each listener will be bounded by whichever stop layer has
     * a lower Z-value.
     *
     * Requires the ACCESS_SURFACE_FLINGER permission.
     */
    void addRegionSamplingListenerWithStopLayerId(in ARect samplingArea, int stopLayerId, IRegionSamplingListener listener);

    /**
     * Removes a listener that was streaming median luma updates from SurfaceFlinger.
     */
    void removeRegionSamplingListener(IRegionSamplingListener listener);

    /**
     * Gets all listeners that are streaming median luma updates from SurfaceFlinger.
     *
     * Requires the ACCESS_SURFACE_FLINGER permission.
     */
    List<RegionSamplingDescriptor> getRegionSamplingListeners();

    /**
     * Registers a listener that streams fps updates from SurfaceFlinger.
     *
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

 package android.gui;

 import android.gui.ARect;
 import android.gui.IRegionSamplingListener;

 /** @hide */
parcelable RegionSamplingDescriptor {
    // Sampling area region
    ARect area;

    // All layers under this layer ID will be sampled from
    int stopLayerId;

    // Listener receiving median luma notifications
    IRegionSamplingListener listener;
}
+5 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@

#include <android/gui/BnJankListener.h>
#include <android/gui/ISurfaceComposerClient.h>
#include <android/gui/RegionSamplingDescriptor.h>

#include <gui/BufferReleaseChannel.h>
#include <gui/CpuConsumer.h>
@@ -838,7 +839,11 @@ public:
    static status_t addRegionSamplingListener(const Rect& samplingArea,
                                              const sp<IBinder>& stopLayerHandle,
                                              const sp<IRegionSamplingListener>& listener);
    static status_t addRegionSamplingListenerWithStopLayerId(
            const Rect& samplingArea, const int32_t stopLayerId,
            const sp<IRegionSamplingListener>& listener);
    static status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener);
    static status_t getRegionSamplingListeners(std::vector<gui::RegionSamplingDescriptor>*);
    static status_t addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener);
    static status_t removeFpsListener(const sp<gui::IFpsListener>& listener);
    static status_t addTunnelModeEnabledListener(
+18 −0
Original line number Diff line number Diff line
@@ -212,6 +212,23 @@ protected:
                .setPosition(mTopLayer, 0, 0)
                .show(mBackgroundLayer)
                .apply();

        // Cache any existing listeners that could impact luma sampling test results
        sp<gui::ISurfaceComposer> composer = ComposerServiceAIDL::getComposerService();
        composer->getRegionSamplingListeners(&mExistingListeners);
        for (const auto& descriptor : mExistingListeners) {
            composer->removeRegionSamplingListener(descriptor.listener);
        }
    }

    void TearDown() override {
        // Restore device state by re-adding listeners that were present prior to the test run
        sp<gui::ISurfaceComposer> composer = ComposerServiceAIDL::getComposerService();
        for (const auto& descriptor : mExistingListeners) {
            composer->addRegionSamplingListenerWithStopLayerId(descriptor.area,
                                                               descriptor.stopLayerId,
                                                               descriptor.listener);
        }
    }

    void fill_render(uint32_t rgba_value) {
@@ -234,6 +251,7 @@ protected:
    sp<SurfaceControl> mBackgroundLayer;
    sp<SurfaceControl> mContentLayer;
    sp<SurfaceControl> mTopLayer;
    std::vector<gui::RegionSamplingDescriptor> mExistingListeners;

    uint32_t const rgba_green = 0xFF00FF00;
    float const luma_green = 0.7152;
Loading