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

Commit a339d0ad authored by Huihong Luo's avatar Huihong Luo
Browse files

Consolidate SpHash to a separate header file

Remove duplicates and avoid circular dependency issues when migrating to AIDL.

Bug: 211037638
Test: manual
Change-Id: I37dd03d06e7bd6346d3b93e3acc61e7d481fda9f
parent f24d8d6d
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -68,8 +68,7 @@ status_t WindowInfosListenerReporter::removeWindowInfosListener(
binder::Status WindowInfosListenerReporter::onWindowInfosChanged(
        const std::vector<WindowInfo>& windowInfos, const std::vector<DisplayInfo>& displayInfos,
        const sp<IWindowInfosReportedListener>& windowInfosReportedListener) {
    std::unordered_set<sp<WindowInfosListener>, ISurfaceComposer::SpHash<WindowInfosListener>>
            windowInfosListeners;
    std::unordered_set<sp<WindowInfosListener>, SpHash<WindowInfosListener>> windowInfosListeners;

    {
        std::scoped_lock lock(mListenersMutex);
+2 −5
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <ftl/Flags.h>
#include <gui/FrameTimelineInfo.h>
#include <gui/ITransactionCompletedListener.h>
#include <gui/SpHash.h>
#include <math/vec4.h>
#include <stdint.h>
#include <sys/types.h>
@@ -70,6 +71,7 @@ enum class FrameEvent;
using gui::IDisplayEventConnection;
using gui::IRegionSamplingListener;
using gui::IScreenCaptureListener;
using gui::SpHash;

namespace ui {

@@ -118,11 +120,6 @@ public:

    using EventRegistrationFlags = Flags<EventRegistration>;

    template <typename T>
    struct SpHash {
        size_t operator()(const sp<T>& k) const { return std::hash<T*>()(k.get()); }
    };

    /*
     * Create a connection with SurfaceFlinger.
     */
+2 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@

#include <gui/ISurfaceComposer.h>
#include <gui/LayerMetadata.h>
#include <gui/SpHash.h>
#include <gui/SurfaceControl.h>
#include <gui/WindowInfo.h>
#include <math/vec3.h>
@@ -412,7 +413,7 @@ struct DisplayCaptureArgs : CaptureArgs {

struct LayerCaptureArgs : CaptureArgs {
    sp<IBinder> layerHandle;
    std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>> excludeHandles;
    std::unordered_set<sp<IBinder>, SpHash<IBinder>> excludeHandles;
    bool childrenOnly{false};

    status_t write(Parcel& output) const override;
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 <stdint.h>
#include <sys/types.h>

#include <functional>

namespace android::gui {

template <typename T>
struct SpHash {
    size_t operator()(const sp<T>& k) const { return std::hash<T*>()(k.get()); }
};

}; // namespace android::gui
+3 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <android/gui/IWindowInfosReportedListener.h>
#include <binder/IBinder.h>
#include <gui/ISurfaceComposer.h>
#include <gui/SpHash.h>
#include <gui/WindowInfosListener.h>
#include <unordered_set>

@@ -41,8 +42,7 @@ public:

private:
    std::mutex mListenersMutex;
    std::unordered_set<sp<gui::WindowInfosListener>,
                       ISurfaceComposer::SpHash<gui::WindowInfosListener>>
    std::unordered_set<sp<gui::WindowInfosListener>, SpHash<gui::WindowInfosListener>>
            mWindowInfosListeners GUARDED_BY(mListenersMutex);
};
} // namespace android
Loading