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

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

Merge "Add a new InputClassifier stage"

parents c82e9ec1 473174ea
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -35,6 +35,14 @@ public:
            mWidth(width), mHeight(height), mData(std::move(data)), mTimestamp(timestamp) {
    }

    bool operator==(const TouchVideoFrame& rhs) const {
        return mWidth == rhs.mWidth
                && mHeight == rhs.mHeight
                && mData == rhs.mData
                && mTimestamp.tv_sec == rhs.mTimestamp.tv_sec
                && mTimestamp.tv_usec == rhs.mTimestamp.tv_usec;
    }

    /**
     * Width of the frame
     */
+7 −1
Original line number Diff line number Diff line
@@ -16,21 +16,25 @@ cc_library_shared {
    name: "libinputflinger",

    srcs: [
        "InputClassifier.cpp",
        "InputDispatcher.cpp",
        "InputManager.cpp",
    ],

    shared_libs: [
        "android.hardware.input.classifier@1.0",
        "libinputflinger_base",
        "libinputreporter",
        "libinputreader",
        "libbase",
        "libbinder",
        "libcutils",
        "libhidlbase",
        "libinput",
        "liblog",
        "libutils",
        "libui",
        "server_configurable_flags",
    ],

    cflags: [
@@ -38,7 +42,9 @@ cc_library_shared {
        "-Wextra",
        "-Werror",
        "-Wno-unused-parameter",
        // TODO: Move inputflinger to its own process and mark it hidden
        // TODO(b/123097103): annotate InputDispatcher and uncomment the following line
        //"-Wthread-safety",
        // TODO(b/23084678): Move inputflinger to its own process and mark it hidden
        //-fvisibility=hidden
    ],

+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.
 */

#ifndef _UI_INPUT_BLOCKING_QUEUE_H
#define _UI_INPUT_BLOCKING_QUEUE_H

#include <condition_variable>
#include <mutex>
#include <vector>

namespace android {

/**
 * A FIFO queue that stores up to <i>capacity</i> objects.
 * Objects can always be added. Objects are added immediately.
 * If the queue is full, new objects cannot be added.
 *
 * The action of retrieving an object will block until an element is available.
 */
template <class T>
class BlockingQueue {
public:
    BlockingQueue(size_t capacity) : mCapacity(capacity) {
        mQueue.reserve(mCapacity);
    };

    /**
     * Retrieve and remove the oldest object.
     * Blocks execution while queue is empty.
     */
    T pop() {
        std::unique_lock<std::mutex> lock(mLock);
        mHasElements.wait(lock, [this]{ return !this->mQueue.empty(); });
        T t = std::move(mQueue.front());
        mQueue.erase(mQueue.begin());
        return std::move(t);
    };

    /**
     * Add a new object to the queue.
     * Does not block.
     * Return true if an element was successfully added.
     * Return false if the queue is full.
     */
    bool push(T&& t) {
        std::unique_lock<std::mutex> lock(mLock);
        if (mQueue.size() == mCapacity) {
            return false;
        }
        mQueue.push_back(std::move(t));
        mHasElements.notify_one();
        return true;
    };

    void erase(const std::function<bool(const T&)>& lambda) {
        std::unique_lock<std::mutex> lock(mLock);
        mQueue.erase(std::remove_if(mQueue.begin(), mQueue.end(),
                [&lambda](const T& t) { return lambda(t); }), mQueue.end());
    }

    /**
     * Remove all elements.
     * Does not block.
     */
    void clear() {
        std::scoped_lock lock(mLock);
        mQueue.clear();
    };

private:
    size_t mCapacity;
    /**
     * Used to signal that mQueue is non-empty.
     */
    std::condition_variable mHasElements;
    /**
     * Lock for accessing and waiting on elements.
     */
    std::mutex mLock;
    std::vector<T> mQueue; //GUARDED_BY(mLock)
};


} // namespace android
#endif
Loading