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

Commit 47709844 authored by Kevin DuBois's avatar Kevin DuBois Committed by Android (Google) Code Review
Browse files

Merge "[gui] Add {add,remove}RegionSamplingListener"

parents fba1d8d9 84ab9371
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -104,6 +104,7 @@ cc_library_shared {
        "IGraphicBufferConsumer.cpp",
        "IGraphicBufferConsumer.cpp",
        "IGraphicBufferProducer.cpp",
        "IGraphicBufferProducer.cpp",
        "IProducerListener.cpp",
        "IProducerListener.cpp",
        "IRegionSamplingListener.cpp",
        "ISurfaceComposer.cpp",
        "ISurfaceComposer.cpp",
        "ISurfaceComposerClient.cpp",
        "ISurfaceComposerClient.cpp",
        "ITransactionCompletedListener.cpp",
        "ITransactionCompletedListener.cpp",
+64 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2019 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.
 */

#define LOG_TAG "IRegionSamplingListener"
//#define LOG_NDEBUG 0

#include <gui/IRegionSamplingListener.h>

namespace android {

namespace { // Anonymous

enum class Tag : uint32_t {
    ON_SAMPLE_COLLECTED = IBinder::FIRST_CALL_TRANSACTION,
    LAST = ON_SAMPLE_COLLECTED,
};

} // Anonymous namespace

class BpRegionSamplingListener : public SafeBpInterface<IRegionSamplingListener> {
public:
    explicit BpRegionSamplingListener(const sp<IBinder>& impl)
          : SafeBpInterface<IRegionSamplingListener>(impl, "BpRegionSamplingListener") {}

    ~BpRegionSamplingListener() override;

    void onSampleCollected(float medianLuma) override {
        callRemoteAsync<decltype(
                &IRegionSamplingListener::onSampleCollected)>(Tag::ON_SAMPLE_COLLECTED, medianLuma);
    }
};

// Out-of-line virtual method definitions to trigger vtable emission in this translation unit (see
// clang warning -Wweak-vtables)
BpRegionSamplingListener::~BpRegionSamplingListener() = default;

IMPLEMENT_META_INTERFACE(RegionSamplingListener, "android.gui.IRegionSamplingListener");

status_t BnRegionSamplingListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
                                              uint32_t flags) {
    if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
        return BBinder::onTransact(code, data, reply, flags);
    }
    auto tag = static_cast<Tag>(code);
    switch (tag) {
        case Tag::ON_SAMPLE_COLLECTED:
            return callLocalAsync(data, reply, &IRegionSamplingListener::onSampleCollected);
    }
}

} // namespace android
+84 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@


#include <gui/IDisplayEventConnection.h>
#include <gui/IDisplayEventConnection.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/IRegionSamplingListener.h>
#include <gui/ISurfaceComposer.h>
#include <gui/ISurfaceComposer.h>
#include <gui/ISurfaceComposerClient.h>
#include <gui/ISurfaceComposerClient.h>
#include <gui/LayerDebugInfo.h>
#include <gui/LayerDebugInfo.h>
@@ -754,6 +755,57 @@ public:
        error = reply.readBool(outIsWideColorDisplay);
        error = reply.readBool(outIsWideColorDisplay);
        return error;
        return error;
    }
    }

    virtual status_t addRegionSamplingListener(const Rect& samplingArea,
                                               const sp<IBinder>& stopLayerHandle,
                                               const sp<IRegionSamplingListener>& listener) {
        Parcel data, reply;
        status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        if (error != NO_ERROR) {
            ALOGE("addRegionSamplingListener: Failed to write interface token");
            return error;
        }
        error = data.write(samplingArea);
        if (error != NO_ERROR) {
            ALOGE("addRegionSamplingListener: Failed to write sampling area");
            return error;
        }
        error = data.writeStrongBinder(stopLayerHandle);
        if (error != NO_ERROR) {
            ALOGE("addRegionSamplingListener: Failed to write stop layer handle");
            return error;
        }
        error = data.writeStrongBinder(IInterface::asBinder(listener));
        if (error != NO_ERROR) {
            ALOGE("addRegionSamplingListener: Failed to write listener");
            return error;
        }
        error = remote()->transact(BnSurfaceComposer::ADD_REGION_SAMPLING_LISTENER, data, &reply);
        if (error != NO_ERROR) {
            ALOGE("addRegionSamplingListener: Failed to transact");
        }
        return error;
    }

    virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) {
        Parcel data, reply;
        status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
        if (error != NO_ERROR) {
            ALOGE("addRegionSamplingListener: Failed to write interface token");
            return error;
        }
        error = data.writeStrongBinder(IInterface::asBinder(listener));
        if (error != NO_ERROR) {
            ALOGE("addRegionSamplingListener: Failed to write listener");
            return error;
        }
        error = remote()->transact(BnSurfaceComposer::REMOVE_REGION_SAMPLING_LISTENER, data,
                                   &reply);
        if (error != NO_ERROR) {
            ALOGE("addRegionSamplingListener: Failed to transact");
        }
        return error;
    }
};
};


// Out-of-line virtual method definition to trigger vtable emission in this
// Out-of-line virtual method definition to trigger vtable emission in this
@@ -1233,6 +1285,38 @@ status_t BnSurfaceComposer::onTransact(
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            return reply->writeUint64Vector(getPhysicalDisplayIds());
            return reply->writeUint64Vector(getPhysicalDisplayIds());
        }
        }
        case ADD_REGION_SAMPLING_LISTENER: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            Rect samplingArea;
            status_t result = data.read(samplingArea);
            if (result != NO_ERROR) {
                ALOGE("addRegionSamplingListener: Failed to read sampling area");
                return result;
            }
            sp<IBinder> stopLayerHandle;
            result = data.readNullableStrongBinder(&stopLayerHandle);
            if (result != NO_ERROR) {
                ALOGE("addRegionSamplingListener: Failed to read stop layer handle");
                return result;
            }
            sp<IRegionSamplingListener> listener;
            result = data.readNullableStrongBinder(&listener);
            if (result != NO_ERROR) {
                ALOGE("addRegionSamplingListener: Failed to read listener");
                return result;
            }
            return addRegionSamplingListener(samplingArea, stopLayerHandle, listener);
        }
        case REMOVE_REGION_SAMPLING_LISTENER: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            sp<IRegionSamplingListener> listener;
            status_t result = data.readNullableStrongBinder(&listener);
            if (result != NO_ERROR) {
                ALOGE("removeRegionSamplingListener: Failed to read listener");
                return result;
            }
            return removeRegionSamplingListener(listener);
        }
        default: {
        default: {
            return BBinder::onTransact(code, data, reply, flags);
            return BBinder::onTransact(code, data, reply, flags);
        }
        }
+43 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2019 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.
 */

#pragma once

#include <cstdint>
#include <vector>

#include <binder/IInterface.h>
#include <binder/SafeInterface.h>

namespace android {

class IRegionSamplingListener : public IInterface {
public:
    DECLARE_META_INTERFACE(RegionSamplingListener)

    virtual void onSampleCollected(float medianLuma) = 0;
};

class BnRegionSamplingListener : public SafeBnInterface<IRegionSamplingListener> {
public:
    BnRegionSamplingListener()
          : SafeBnInterface<IRegionSamplingListener>("BnRegionSamplingListener") {}

    status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
                        uint32_t flags = 0) override;
};

} // namespace android
+23 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ class HdrCapabilities;
class IDisplayEventConnection;
class IDisplayEventConnection;
class IGraphicBufferProducer;
class IGraphicBufferProducer;
class ISurfaceComposerClient;
class ISurfaceComposerClient;
class IRegionSamplingListener;
class Rect;
class Rect;
enum class FrameEvent;
enum class FrameEvent;


@@ -338,6 +339,26 @@ public:
     */
     */
    virtual status_t isWideColorDisplay(const sp<IBinder>& token,
    virtual status_t isWideColorDisplay(const sp<IBinder>& token,
                                        bool* outIsWideColorDisplay) const = 0;
                                        bool* outIsWideColorDisplay) const = 0;

    /* Registers a listener to stream median luma updates from SurfaceFlinger.
     *
     * 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.
     *
     * Requires the same permissions as captureLayers and captureScreen.
     */
    virtual status_t addRegionSamplingListener(const Rect& samplingArea,
                                               const sp<IBinder>& stopLayerHandle,
                                               const sp<IRegionSamplingListener>& listener) = 0;

    /*
     * Removes a listener that was streaming median luma updates from SurfaceFlinger.
     */
    virtual status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) = 0;
};
};


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@@ -383,6 +404,8 @@ public:
        IS_WIDE_COLOR_DISPLAY,
        IS_WIDE_COLOR_DISPLAY,
        GET_DISPLAY_NATIVE_PRIMARIES,
        GET_DISPLAY_NATIVE_PRIMARIES,
        GET_PHYSICAL_DISPLAY_IDS,
        GET_PHYSICAL_DISPLAY_IDS,
        ADD_REGION_SAMPLING_LISTENER,
        REMOVE_REGION_SAMPLING_LISTENER,
        // Always append new enum to the end.
        // Always append new enum to the end.
    };
    };


Loading