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

Commit f103edb5 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Added IWindowInfosChangedListener interface" into sc-v2-dev

parents d44f6991 60c9d3e8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ cc_library_static {
        ":guiconstants_aidl",
        "android/gui/FocusRequest.aidl",
        "android/gui/InputApplicationInfo.aidl",
        "android/gui/IWindowInfosListener.aidl",
        "android/gui/WindowInfo.aidl",
        "WindowInfo.cpp",
    ],
@@ -195,6 +196,7 @@ cc_library_shared {
        "SyncFeatures.cpp",
        "TransactionTracing.cpp",
        "view/Surface.cpp",
        "WindowInfosListenerReporter.cpp",
        "bufferqueue/1.0/B2HProducerListener.cpp",
        "bufferqueue/1.0/H2BGraphicBufferProducer.cpp",
        "bufferqueue/2.0/B2HProducerListener.cpp",
+0 −1
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#include <gui/BufferQueueCore.h>
#include <gui/IConsumerListener.h>
#include <gui/IProducerListener.h>
#include <gui/ISurfaceComposer.h>
#include <private/gui/ComposerService.h>

#include <system/window.h>
+31 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@

namespace android {

using gui::IWindowInfosListener;
using ui::ColorMode;

class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
@@ -1227,6 +1228,22 @@ public:

        return reply.readInt32(buffers);
    }

    status_t addWindowInfosListener(
            const sp<IWindowInfosListener>& windowInfosListener) const override {
        Parcel data, reply;
        SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
        SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(windowInfosListener));
        return remote()->transact(BnSurfaceComposer::ADD_WINDOW_INFOS_LISTENER, data, &reply);
    }

    status_t removeWindowInfosListener(
            const sp<IWindowInfosListener>& windowInfosListener) const override {
        Parcel data, reply;
        SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
        SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(windowInfosListener));
        return remote()->transact(BnSurfaceComposer::REMOVE_WINDOW_INFOS_LISTENER, data, &reply);
    }
};

// Out-of-line virtual method definition to trigger vtable emission in this
@@ -2107,6 +2124,20 @@ status_t BnSurfaceComposer::onTransact(
            SAFE_PARCEL(reply->writeBool, success);
            return err;
        }
        case ADD_WINDOW_INFOS_LISTENER: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            sp<IWindowInfosListener> listener;
            SAFE_PARCEL(data.readStrongBinder, &listener);

            return addWindowInfosListener(listener);
        }
        case REMOVE_WINDOW_INFOS_LISTENER: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            sp<IWindowInfosListener> listener;
            SAFE_PARCEL(data.readStrongBinder, &listener);

            return removeWindowInfosListener(listener);
        }
        default: {
            return BBinder::onTransact(code, data, reply, flags);
        }
+17 −7
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <sys/types.h>

#include <android/gui/IWindowInfosListener.h>
#include <utils/Errors.h>
#include <utils/Log.h>
#include <utils/SortedVector.h>
@@ -54,6 +55,7 @@ namespace android {
using gui::FocusRequest;
using gui::WindowInfo;
using gui::WindowInfoHandle;
using gui::WindowInfosListener;
using ui::ColorMode;
// ---------------------------------------------------------------------------

@@ -95,6 +97,7 @@ bool ComposerService::connectLocked() {
    if (instance.mComposerService == nullptr) {
        if (ComposerService::getInstance().connectLocked()) {
            ALOGD("ComposerService reconnected");
            WindowInfosListenerReporter::getInstance()->reconnect(instance.mComposerService);
        }
    }
    return instance.mComposerService;
@@ -1781,15 +1784,10 @@ void SurfaceComposerClient::Transaction::setDisplaySize(const sp<IBinder>& token

// ---------------------------------------------------------------------------

SurfaceComposerClient::SurfaceComposerClient()
    : mStatus(NO_INIT)
{
}
SurfaceComposerClient::SurfaceComposerClient() : mStatus(NO_INIT) {}

SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& client)
    : mStatus(NO_ERROR), mClient(client)
{
}
      : mStatus(NO_ERROR), mClient(client) {}

void SurfaceComposerClient::onFirstRef() {
    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
@@ -2155,6 +2153,18 @@ int SurfaceComposerClient::getGPUContextPriority() {
    return ComposerService::getComposerService()->getGPUContextPriority();
}

status_t SurfaceComposerClient::addWindowInfosListener(
        const sp<WindowInfosListener>& windowInfosListener) {
    return WindowInfosListenerReporter::getInstance()
            ->addWindowInfosListener(windowInfosListener, ComposerService::getComposerService());
}

status_t SurfaceComposerClient::removeWindowInfosListener(
        const sp<WindowInfosListener>& windowInfosListener) {
    return WindowInfosListenerReporter::getInstance()
            ->removeWindowInfosListener(windowInfosListener, ComposerService::getComposerService());
}

// ----------------------------------------------------------------------------

status_t ScreenshotClient::captureDisplay(const DisplayCaptureArgs& captureArgs,
+92 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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.
 */

#include <gui/ISurfaceComposer.h>
#include <gui/WindowInfosListenerReporter.h>

namespace android {

using gui::WindowInfo;
using gui::WindowInfosListener;

sp<WindowInfosListenerReporter> WindowInfosListenerReporter::getInstance() {
    static sp<WindowInfosListenerReporter> sInstance = new WindowInfosListenerReporter;
    return sInstance;
}

status_t WindowInfosListenerReporter::addWindowInfosListener(
        const sp<WindowInfosListener>& windowInfosListener,
        const sp<ISurfaceComposer>& surfaceComposer) {
    status_t status = OK;
    {
        std::scoped_lock lock(mListenersMutex);
        if (mWindowInfosListeners.empty()) {
            status = surfaceComposer->addWindowInfosListener(this);
        }

        if (status == OK) {
            mWindowInfosListeners.insert(windowInfosListener);
        }
    }

    return status;
}

status_t WindowInfosListenerReporter::removeWindowInfosListener(
        const sp<WindowInfosListener>& windowInfosListener,
        const sp<ISurfaceComposer>& surfaceComposer) {
    status_t status = OK;
    {
        std::scoped_lock lock(mListenersMutex);
        if (mWindowInfosListeners.size() == 1) {
            status = surfaceComposer->removeWindowInfosListener(this);
        }

        if (status == OK) {
            mWindowInfosListeners.erase(windowInfosListener);
        }
    }

    return status;
}

binder::Status WindowInfosListenerReporter::onWindowInfosChanged(
        const std::vector<WindowInfo>& windowInfos) {
    std::unordered_set<sp<WindowInfosListener>, ISurfaceComposer::SpHash<WindowInfosListener>>
            windowInfosListeners;

    {
        std::scoped_lock lock(mListenersMutex);
        for (auto listener : mWindowInfosListeners) {
            windowInfosListeners.insert(listener);
        }
    }

    for (auto listener : windowInfosListeners) {
        listener->onWindowInfosChanged(windowInfos);
    }

    return binder::Status::ok();
}

void WindowInfosListenerReporter::reconnect(const sp<ISurfaceComposer>& composerService) {
    std::scoped_lock lock(mListenersMutex);
    if (!mWindowInfosListeners.empty()) {
        composerService->addWindowInfosListener(this);
    }
}

} // namespace android
 No newline at end of file
Loading