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

Commit d8fccf01 authored by Kevin Schoedel's avatar Kevin Schoedel
Browse files

Add DVR API for scroll event injection.

Bug: 62226675
Test: manual, vrcore build
Change-Id: Ic7d329eba8003b0e294b3a11a83ed5f868b801f8
parent cf614601
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
#include <errno.h>
#include <utils/Log.h>

#include <algorithm>

// Headers from libdvr
#include <dvr/dvr_buffer.h>
#include <dvr/dvr_buffer_queue.h>
@@ -23,15 +25,20 @@ int dvrGetApi(void* api, size_t struct_size, int version) {
  ALOGI("dvrGetApi: api=%p struct_size=%zu version=%d", api, struct_size,
        version);
  if (version == 1) {
    if (struct_size != sizeof(DvrApi_v1)) {
      ALOGE("dvrGetApi: Size mismatch: expected %zu; actual %zu",
            sizeof(DvrApi_v1), struct_size);
      return -EINVAL;
    }
    // New entry points are added at the end. If the caller's struct and
    // this library have different sizes, we define the entry points in common.
    // The caller is expected to handle unset entry points if necessary.
    size_t clamped_struct_size = std::min(struct_size, sizeof(DvrApi_v1));
    DvrApi_v1* dvr_api = static_cast<DvrApi_v1*>(api);

// Defines an API entry for V1 (no version suffix).
#define DVR_V1_API_ENTRY(name) dvr_api->name = dvr##name
#define DVR_V1_API_ENTRY(name)                                 \
  do {                                                         \
    if ((offsetof(DvrApi_v1, name) + sizeof(dvr_api->name)) <= \
        clamped_struct_size) {                                 \
      dvr_api->name = dvr##name;                               \
    }                                                          \
  } while (0)

#include "include/dvr/dvr_api_entries.h"

+2 −0
Original line number Diff line number Diff line
@@ -238,6 +238,8 @@ typedef int (*DvrVirtualTouchpadTouchPtr)(DvrVirtualTouchpad* client,
                                          float pressure);
typedef int (*DvrVirtualTouchpadButtonStatePtr)(DvrVirtualTouchpad* client,
                                                int touchpad, int buttons);
typedef int (*DvrVirtualTouchpadScrollPtr)(DvrVirtualTouchpad* client,
                                           int touchpad, float x, float y);

// dvr_hardware_composer_client.h
typedef struct DvrHwcClient DvrHwcClient;
+6 −0
Original line number Diff line number Diff line
@@ -141,3 +141,9 @@ DVR_V1_API_ENTRY(HwcFrameGetLayerNumVisibleRegions);
DVR_V1_API_ENTRY(HwcFrameGetLayerVisibleRegion);
DVR_V1_API_ENTRY(HwcFrameGetLayerNumDamagedRegions);
DVR_V1_API_ENTRY(HwcFrameGetLayerDamagedRegion);

// New entries added at the end to allow the DVR platform library API
// to be updated before updating VrCore.

// Virtual touchpad client
DVR_V1_API_ENTRY(VirtualTouchpadScroll);
+5 −0
Original line number Diff line number Diff line
@@ -40,6 +40,11 @@ int dvrVirtualTouchpadButtonState(DvrVirtualTouchpad* client, int touchpad,
  return FromC(client)->ButtonState(touchpad, buttons);
}

int dvrVirtualTouchpadScroll(DvrVirtualTouchpad* client, int touchpad, float x,
                             float y) {
  return FromC(client)->Scroll(touchpad, x, y);
}

#ifdef __cplusplus
}  // extern "C"
#endif
+23 −0
Original line number Diff line number Diff line
@@ -168,6 +168,25 @@ int EvdevInjector::ConfigureAbsSlots(int slots) {
  return ConfigureAbs(ABS_MT_SLOT, 0, slots, 0, 0);
}

int EvdevInjector::ConfigureRel(uint16_t rel_type) {
  ALOGV("ConfigureRel 0x%" PRIX16 "", rel_type);
  if (rel_type < 0 || rel_type >= REL_CNT) {
    ALOGE("EV_REL type 0x%" PRIX16 " out of range [0,0x%X)", rel_type, REL_CNT);
    return Error(ERROR_REL_RANGE);
  }
  if (const int status = RequireState(State::CONFIGURING)) {
    return status;
  }
  if (const int status = EnableEventType(EV_REL)) {
    return status;
  }
  if (const int status = uinput_->IoctlSetInt(UI_SET_RELBIT, rel_type)) {
    ALOGE("failed to enable EV_REL 0x%" PRIX16 "", rel_type);
    return Error(status);
  }
  return 0;
}

int EvdevInjector::ConfigureEnd() {
  ALOGV("ConfigureEnd:");
  ALOGV("  name=\"%s\"", uidev_.name);
@@ -236,6 +255,10 @@ int EvdevInjector::SendAbs(uint16_t code, int32_t value) {
  return Send(EV_ABS, code, value);
}

int EvdevInjector::SendRel(uint16_t code, int32_t value) {
  return Send(EV_REL, code, value);
}

int EvdevInjector::SendMultiTouchSlot(int32_t slot) {
  if (latest_slot_ != slot) {
    if (const int status = SendAbs(ABS_MT_SLOT, slot)) {
Loading