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

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

Merge "Use shared_ptr for EventEntry"

parents e0a064b6 a9a7ee88
Loading
Loading
Loading
Loading
+4 −20
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ VerifiedMotionEvent verifiedMotionEventFromMotionEntry(const MotionEntry& entry)

EventEntry::EventEntry(int32_t id, Type type, nsecs_t eventTime, uint32_t policyFlags)
      : id(id),
        refCount(1),
        type(type),
        eventTime(eventTime),
        policyFlags(policyFlags),
@@ -70,15 +69,6 @@ EventEntry::~EventEntry() {
    releaseInjectionState();
}

void EventEntry::release() {
    refCount -= 1;
    if (refCount == 0) {
        delete this;
    } else {
        ALOG_ASSERT(refCount > 0);
    }
}

void EventEntry::releaseInjectionState() {
    if (injectionState) {
        injectionState->release();
@@ -235,22 +225,16 @@ std::string MotionEntry::getDescription() const {

volatile int32_t DispatchEntry::sNextSeqAtomic;

DispatchEntry::DispatchEntry(EventEntry* eventEntry, int32_t targetFlags, ui::Transform transform,
                             float globalScaleFactor)
DispatchEntry::DispatchEntry(std::shared_ptr<EventEntry> eventEntry, int32_t targetFlags,
                             ui::Transform transform, float globalScaleFactor)
      : seq(nextSeq()),
        eventEntry(eventEntry),
        eventEntry(std::move(eventEntry)),
        targetFlags(targetFlags),
        transform(transform),
        globalScaleFactor(globalScaleFactor),
        deliveryTime(0),
        resolvedAction(0),
        resolvedFlags(0) {
    eventEntry->refCount += 1;
}

DispatchEntry::~DispatchEntry() {
    eventEntry->release();
}
        resolvedFlags(0) {}

uint32_t DispatchEntry::nextSeq() {
    // Sequence number 0 is reserved and will never be returned.
+6 −14
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ struct EventEntry {
    }

    int32_t id;
    mutable int32_t refCount;
    Type type;
    nsecs_t eventTime;
    uint32_t policyFlags;
@@ -79,13 +78,12 @@ struct EventEntry {
        return isInjected() || IdGenerator::getSource(id) != IdGenerator::Source::INPUT_READER;
    }

    void release();

    virtual std::string getDescription() const = 0;

protected:
    EventEntry(int32_t id, Type type, nsecs_t eventTime, uint32_t policyFlags);
    virtual ~EventEntry();

protected:
    void releaseInjectionState();
};

@@ -93,7 +91,6 @@ struct ConfigurationChangedEntry : EventEntry {
    explicit ConfigurationChangedEntry(int32_t id, nsecs_t eventTime);
    std::string getDescription() const override;

protected:
    virtual ~ConfigurationChangedEntry();
};

@@ -103,7 +100,6 @@ struct DeviceResetEntry : EventEntry {
    DeviceResetEntry(int32_t id, nsecs_t eventTime, int32_t deviceId);
    std::string getDescription() const override;

protected:
    virtual ~DeviceResetEntry();
};

@@ -116,7 +112,6 @@ struct FocusEntry : EventEntry {
               std::string_view reason);
    std::string getDescription() const override;

protected:
    virtual ~FocusEntry();
};

@@ -149,7 +144,6 @@ struct KeyEntry : EventEntry {
    std::string getDescription() const override;
    void recycle();

protected:
    virtual ~KeyEntry();
};

@@ -182,7 +176,6 @@ struct MotionEntry : EventEntry {
                float xOffset, float yOffset);
    std::string getDescription() const override;

protected:
    virtual ~MotionEntry();
};

@@ -190,7 +183,7 @@ protected:
struct DispatchEntry {
    const uint32_t seq; // unique sequence number, never 0

    EventEntry* eventEntry; // the event to dispatch
    std::shared_ptr<EventEntry> eventEntry; // the event to dispatch
    int32_t targetFlags;
    ui::Transform transform;
    float globalScaleFactor;
@@ -205,9 +198,8 @@ struct DispatchEntry {
    int32_t resolvedAction;
    int32_t resolvedFlags;

    DispatchEntry(EventEntry* eventEntry, int32_t targetFlags, ui::Transform transform,
                  float globalScaleFactor);
    ~DispatchEntry();
    DispatchEntry(std::shared_ptr<EventEntry> eventEntry, int32_t targetFlags,
                  ui::Transform transform, float globalScaleFactor);

    inline bool hasForegroundTarget() const { return targetFlags & InputTarget::FLAG_FOREGROUND; }

@@ -252,7 +244,7 @@ struct CommandEntry {
    // parameters for the command (usage varies by command)
    sp<Connection> connection;
    nsecs_t eventTime;
    KeyEntry* keyEntry;
    std::shared_ptr<KeyEntry> keyEntry;
    std::shared_ptr<InputApplicationHandle> inputApplicationHandle;
    std::string reason;
    int32_t userActivityEventType;
Loading