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

Commit 5bee715d authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12399304 from c420be83 to 25Q2-release

Change-Id: Ie860aa4badac1e531012390aa82cd075d30435c7
parents d763c35b c420be83
Loading
Loading
Loading
Loading
+61 −5
Original line number Diff line number Diff line
@@ -145,6 +145,9 @@ typedef struct ASurfaceTransactionStats ASurfaceTransactionStats;
 * Buffers which are replaced or removed from the scene in the transaction invoking
 * this callback may be reused after this point.
 *
 * Starting with API level 36, prefer using \a ASurfaceTransaction_OnBufferRelease to listen
 * to when a buffer is ready to be reused.
 *
 * \param context Optional context provided by the client that is passed into
 * the callback.
 *
@@ -157,8 +160,7 @@ typedef struct ASurfaceTransactionStats ASurfaceTransactionStats;
 * Available since API level 29.
 */
typedef void (*ASurfaceTransaction_OnComplete)(void* _Null_unspecified context,
                                               ASurfaceTransactionStats* _Nonnull stats)
        __INTRODUCED_IN(29);
                                               ASurfaceTransactionStats* _Nonnull stats);

/**
 * The ASurfaceTransaction_OnCommit callback is invoked when transaction is applied and the updates
@@ -186,8 +188,36 @@ typedef void (*ASurfaceTransaction_OnComplete)(void* _Null_unspecified context,
 * Available since API level 31.
 */
typedef void (*ASurfaceTransaction_OnCommit)(void* _Null_unspecified context,
                                             ASurfaceTransactionStats* _Nonnull stats)
        __INTRODUCED_IN(31);
                                             ASurfaceTransactionStats* _Nonnull stats);

/**
 * The ASurfaceTransaction_OnBufferRelease callback is invoked when a buffer that was passed in
 * ASurfaceTransaction_setBuffer is ready to be reused.
 *
 * This callback is guaranteed to be invoked if ASurfaceTransaction_setBuffer is called with a non
 * null buffer. If the buffer in the transaction is replaced via another call to
 * ASurfaceTransaction_setBuffer, the callback will be invoked immediately. Otherwise the callback
 * will be invoked before the ASurfaceTransaction_OnComplete callback after the buffer was
 * presented.
 *
 * If this callback is set, caller should not release the buffer using the
 * ASurfaceTransaction_OnComplete.
 *
 * \param context Optional context provided by the client that is passed into the callback.
 *
 * \param release_fence_fd Returns the fence file descriptor used to signal the release of buffer
 * associated with this callback. If this fence is valid (>=0), the buffer has not yet been released
 * and the fence will signal when the buffer has been released. If the fence is -1 , the buffer is
 * already released. The recipient of the callback takes ownership of the fence fd and is
 * responsible for closing it.
 *
 * THREADING
 * The callback can be invoked on any thread.
 *
 * Available since API level 36.
 */
typedef void (*ASurfaceTransaction_OnBufferRelease)(void* _Null_unspecified context,
                                                    int release_fence_fd);

/**
 * Returns the timestamp of when the frame was latched by the framework. Once a frame is
@@ -353,6 +383,9 @@ void ASurfaceTransaction_setZOrder(ASurfaceTransaction* _Nonnull transaction,
 * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE
 * as the surface control might be composited using the GPU.
 *
 * Starting with API level 36, prefer using \a ASurfaceTransaction_setBufferWithRelease to
 * set a buffer and a callback which will be invoked when the buffer is ready to be reused.
 *
 * Available since API level 29.
 */
void ASurfaceTransaction_setBuffer(ASurfaceTransaction* _Nonnull transaction,
@@ -360,6 +393,29 @@ void ASurfaceTransaction_setBuffer(ASurfaceTransaction* _Nonnull transaction,
                                   AHardwareBuffer* _Nonnull buffer, int acquire_fence_fd)
        __INTRODUCED_IN(29);

/**
 * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the
 * acquire_fence_fd should be a file descriptor that is signaled when all pending work
 * for the buffer is complete and the buffer can be safely read.
 *
 * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible
 * for closing it.
 *
 * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE
 * as the surface control might be composited using the GPU.
 *
 * When the buffer is ready to be reused, the ASurfaceTransaction_OnBufferRelease
 * callback will be invoked. If the buffer is null, the callback will not be invoked.
 *
 * Available since API level 36.
 */
void ASurfaceTransaction_setBufferWithRelease(ASurfaceTransaction* _Nonnull transaction,
                                              ASurfaceControl* _Nonnull surface_control,
                                              AHardwareBuffer* _Nonnull buffer,
                                              int acquire_fence_fd, void* _Null_unspecified context,
                                              ASurfaceTransaction_OnBufferRelease _Nonnull func)
        __INTRODUCED_IN(36);

/**
 * Updates the color for \a surface_control.  This will make the background color for the
 * ASurfaceControl visible in transparent regions of the surface.  Colors \a r, \a g,
+35 −26
Original line number Diff line number Diff line
@@ -16,8 +16,12 @@

#pragma once

#include <map>
#include <memory>
#include <optional>

#include <input/Input.h>
#include <input/InputTransport.h>
#include <input/LooperInterface.h>
#include <input/Resampler.h>
#include <utils/Looper.h>

@@ -36,7 +40,7 @@ public:
    /**
     * When you receive this callback, you must (eventually) call "consumeBatchedInputEvents".
     * If you don't want batching, then call "consumeBatchedInputEvents" immediately with
     * std::nullopt frameTime to receive the pending motion event(s).
     * std::nullopt requestedFrameTime to receive the pending motion event(s).
     * @param pendingBatchSource the source of the pending batch.
     */
    virtual void onBatchedInputEventPending(int32_t pendingBatchSource) = 0;
@@ -66,16 +70,6 @@ public:
 */
class InputConsumerNoResampling final {
public:
    /**
     * This constructor is exclusively for test code. Any real use of InputConsumerNoResampling must
     * use the constructor that takes an sp<Looper> parameter instead of
     * std::shared_ptr<LooperInterface>.
     */
    explicit InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel,
                                       std::shared_ptr<LooperInterface> looper,
                                       InputConsumerCallbacks& callbacks,
                                       std::unique_ptr<Resampler> resampler);

    /**
     * @param callbacks are used to interact with InputConsumerNoResampling. They're called whenever
     * the event is ready to consume.
@@ -96,15 +90,17 @@ public:
    void finishInputEvent(uint32_t seq, bool handled);
    void reportTimeline(int32_t inputEventId, nsecs_t gpuCompletedTime, nsecs_t presentTime);
    /**
     * If you want to consume all events immediately (disable batching), the you still must call
     * this. For frameTime, use a std::nullopt.
     * @param frameTime the time up to which consume the events. When there's double (or triple)
     * buffering, you may want to not consume all events currently available, because you could be
     * still working on an older frame, but there could already have been events that arrived that
     * are more recent.
     * If you want to consume all events immediately (disable batching), then you still must call
     * this. For requestedFrameTime, use a std::nullopt. It is not guaranteed that the consumption
     * will occur at requestedFrameTime. The resampling strategy may modify it.
     * @param requestedFrameTime the time up to which consume the events. When there's double (or
     * triple) buffering, you may want to not consume all events currently available, because you
     * could be still working on an older frame, but there could already have been events that
     * arrived that are more recent.
     * @return whether any events were actually consumed
     */
    bool consumeBatchedInputEvents(std::optional<nsecs_t> frameTime);
    bool consumeBatchedInputEvents(std::optional<nsecs_t> requestedFrameTime);

    /**
     * Returns true when there is *likely* a pending batch or a pending event in the channel.
     *
@@ -119,7 +115,7 @@ public:

private:
    std::shared_ptr<InputChannel> mChannel;
    std::shared_ptr<LooperInterface> mLooper;
    sp<Looper> mLooper;
    InputConsumerCallbacks& mCallbacks;
    std::unique_ptr<Resampler> mResampler;

@@ -200,20 +196,33 @@ private:
    /**
     * Batched InputMessages, per deviceId.
     * For each device, we are storing a queue of batched messages. These will all be collapsed into
     * a single MotionEvent (up to a specific frameTime) when the consumer calls
     * a single MotionEvent (up to a specific requestedFrameTime) when the consumer calls
     * `consumeBatchedInputEvents`.
     */
    std::map<DeviceId, std::queue<InputMessage>> mBatches;
    /**
     * Creates a MotionEvent by consuming samples from the provided queue. If one message has
     * eventTime > frameTime, all subsequent messages in the queue will be skipped. It is assumed
     * that messages are queued in chronological order. In other words, only events that occurred
     * prior to the requested frameTime will be consumed.
     * @param frameTime the time up to which to consume events
     * eventTime > adjustedFrameTime, all subsequent messages in the queue will be skipped. It is
     * assumed that messages are queued in chronological order. In other words, only events that
     * occurred prior to the adjustedFrameTime will be consumed.
     * @param requestedFrameTime the time up to which to consume events.
     * @param messages the queue of messages to consume from
     */
    std::pair<std::unique_ptr<MotionEvent>, std::optional<uint32_t>> createBatchedMotionEvent(
            const nsecs_t frameTime, std::queue<InputMessage>& messages);
            const nsecs_t requestedFrameTime, std::queue<InputMessage>& messages);

    /**
     * Consumes the batched input events, optionally allowing the caller to specify a device id
     * and/or requestedFrameTime threshold. It is not guaranteed that consumption will occur at
     * requestedFrameTime.
     * @param deviceId The device id from which to consume events. If std::nullopt, consumes events
     * from any device id.
     * @param requestedFrameTime The time up to which consume the events. If std::nullopt, consumes
     * input events with any timestamp.
     * @return Whether or not any events were consumed.
     */
    bool consumeBatchedInputEvents(std::optional<DeviceId> deviceId,
                                   std::optional<nsecs_t> requestedFrameTime);
    /**
     * A map from a single sequence number to several sequence numbers. This is needed because of
     * batching. When batching is enabled, a single MotionEvent will contain several samples. Each
+3 −3
Original line number Diff line number Diff line
@@ -126,9 +126,9 @@ public:
    bool getEvents(int32_t deviceId, const char16_t* chars, size_t numChars,
            Vector<KeyEvent>& outEvents) const;

    /* Maps an Android key code to another Android key code. This mapping is applied after scanCode
     * and usageCodes are mapped to corresponding Android Keycode */
    void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode);
    /* Maps some Android key code to another Android key code. This mapping is applied after
     * scanCode and usageCodes are mapped to corresponding Android Keycode */
    void setKeyRemapping(const std::map<int32_t, int32_t>& keyRemapping);

    /* Maps a scan code and usage code to a key code, in case this key map overrides
     * the mapping in some way. */

include/input/LooperInterface.h

deleted100644 → 0
+0 −39
Original line number Diff line number Diff line
/**
 * Copyright 2024 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 <utils/Looper.h>
#include <utils/StrongPointer.h>

namespace android {

/**
 * LooperInterface allows the use of TestLooper in InputConsumerNoResampling without reassigning to
 * Looper. LooperInterface is needed to control how InputConsumerNoResampling consumes and batches
 * InputMessages.
 */
class LooperInterface {
public:
    virtual ~LooperInterface() = default;

    virtual int addFd(int fd, int ident, int events, const sp<LooperCallback>& callback,
                      void* data) = 0;
    virtual int removeFd(int fd) = 0;

    virtual sp<Looper> getLooper() const = 0;
};
} // namespace android
+14 −6
Original line number Diff line number Diff line
@@ -35,9 +35,9 @@ struct Resampler {
    virtual ~Resampler() = default;

    /**
     * Tries to resample motionEvent at resampleTime. The provided resampleTime must be greater than
     * Tries to resample motionEvent at frameTime. The provided frameTime must be greater than
     * the latest sample time of motionEvent. It is not guaranteed that resampling occurs at
     * resampleTime. Interpolation may occur is futureSample is available. Otherwise, motionEvent
     * frameTime. Interpolation may occur is futureSample is available. Otherwise, motionEvent
     * may be resampled by another method, or not resampled at all. Furthermore, it is the
     * implementer's responsibility to guarantee the following:
     * - If resampling occurs, a single additional sample should be added to motionEvent. That is,
@@ -45,15 +45,21 @@ struct Resampler {
     * samples by the end of the resampling. No other field of motionEvent should be modified.
     * - If resampling does not occur, then motionEvent must not be modified in any way.
     */
    virtual void resampleMotionEvent(std::chrono::nanoseconds resampleTime,
                                     MotionEvent& motionEvent,
    virtual void resampleMotionEvent(std::chrono::nanoseconds frameTime, MotionEvent& motionEvent,
                                     const InputMessage* futureSample) = 0;

    /**
     * Returns resample latency. Resample latency is the time difference between frame time and
     * resample time. More precisely, let frameTime and resampleTime be two timestamps, and
     * frameTime > resampleTime. Resample latency is defined as frameTime - resampleTime.
     */
    virtual std::chrono::nanoseconds getResampleLatency() const = 0;
};

class LegacyResampler final : public Resampler {
public:
    /**
     * Tries to resample `motionEvent` at `resampleTime` by adding a resampled sample at the end of
     * Tries to resample `motionEvent` at `frameTime` by adding a resampled sample at the end of
     * `motionEvent` with eventTime equal to `resampleTime` and pointer coordinates determined by
     * linear interpolation or linear extrapolation. An earlier `resampleTime` will be used if
     * extrapolation takes place and `resampleTime` is too far in the future. If `futureSample` is
@@ -61,9 +67,11 @@ public:
     * data, LegacyResampler will extrapolate. Otherwise, no resampling takes place and
     * `motionEvent` is unmodified.
     */
    void resampleMotionEvent(std::chrono::nanoseconds resampleTime, MotionEvent& motionEvent,
    void resampleMotionEvent(std::chrono::nanoseconds frameTime, MotionEvent& motionEvent,
                             const InputMessage* futureSample) override;

    std::chrono::nanoseconds getResampleLatency() const override;

private:
    struct Pointer {
        PointerProperties properties;
Loading