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

Commit 3a726d50 authored by LuK1337's avatar LuK1337
Browse files

recovery: Add support for touch rotation

Change-Id: Ic72d8f902f8faeca7fc122e7ecb468e54fb8d2a4
parent e3cb6c12
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ static uint32_t gr_current = ~0;
// gr_draw is owned by backends.
static GRSurface* gr_draw = nullptr;
static GRRotation rotation = GRRotation::NONE;
static GRRotation touch_rotation = GRRotation::NONE;
static PixelFormat pixel_format = PixelFormat::UNKNOWN;
// The graphics backend list that provides fallback options for the default backend selection.
// For example, it will fist try DRM, then try FBDEV if DRM is unavailable.
@@ -474,6 +475,18 @@ int gr_init(std::initializer_list<GraphicsBackend> backends) {
    gr_rotate(GRRotation::NONE);
  }

  std::string touch_rotation_str =
      android::base::GetProperty("ro.minui.default_touch_rotation", "ROTATION_NONE");
  if (touch_rotation_str == "ROTATION_RIGHT") {
    gr_rotate_touch(GRRotation::RIGHT);
  } else if (touch_rotation_str == "ROTATION_DOWN") {
    gr_rotate_touch(GRRotation::DOWN);
  } else if (touch_rotation_str == "ROTATION_LEFT") {
    gr_rotate_touch(GRRotation::LEFT);
  } else {  // "ROTATION_NONE" or unknown string
    gr_rotate_touch(GRRotation::NONE);
  }

  if (gr_draw->pixel_bytes != 4) {
    printf("gr_init: Only 4-byte pixel formats supported\n");
  }
@@ -519,6 +532,10 @@ int gr_overscan_offset_y() {
  return overscan_offset_y;
}

GRRotation gr_touch_rotation() {
  return touch_rotation;
}

void gr_fb_blank(bool blank) {
  gr_backend->Blank(blank);
}
@@ -531,6 +548,10 @@ void gr_rotate(GRRotation rot) {
  rotation = rot;
}

void gr_rotate_touch(GRRotation rot) {
  touch_rotation = rot;
}

bool gr_has_multiple_connectors() {
  return gr_backend->HasMultipleConnectors();
}
+4 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ int gr_fb_width_real();
int gr_fb_height_real();
int gr_overscan_offset_x();
int gr_overscan_offset_y();
GRRotation gr_touch_rotation();

void gr_flip();
void gr_fb_blank(bool blank);
@@ -158,6 +159,9 @@ unsigned int gr_get_height(const GRSurface* surface);
// Sets rotation, flips gr_fb_width/height if 90 degree rotation difference
void gr_rotate(GRRotation rotation);

// Sets touch rotation
void gr_rotate_touch(GRRotation rotation);

// Returns the current PixelFormat being used.
PixelFormat gr_pixel_format();

+27 −1
Original line number Diff line number Diff line
@@ -1353,8 +1353,34 @@ int ScreenRecoveryUI::SelectMenu(int sel) {
}

int ScreenRecoveryUI::SelectMenu(const Point& p) {
  Point point;

  const auto scaleX = static_cast<double>(p.x()) / ScreenWidth();
  const auto scaleY = static_cast<double>(p.y()) / ScreenHeight();

  // Correct position for touch rotation
  switch (gr_touch_rotation()) {
    case GRRotation::NONE:
      point.x(ScreenWidth() * scaleX);
      point.y(ScreenHeight() * scaleY);
      break;
    case GRRotation::RIGHT:
      point.x(ScreenWidth() * scaleY);
      point.y(ScreenHeight() - (ScreenHeight() * scaleX));
      break;
    case GRRotation::DOWN:
      point.x(ScreenWidth() - (ScreenWidth() * scaleX));
      point.y(ScreenHeight() - (ScreenHeight() * scaleY));
      break;
    case GRRotation::LEFT:
      point.x(ScreenWidth() - (ScreenWidth() * scaleY));
      point.y(ScreenHeight() * scaleX);
      break;
  }

  // Correct position for overscan
  const Point point(p.x() - gr_overscan_offset_x(), p.y() - gr_overscan_offset_y());
  point.x(point.x() - gr_overscan_offset_x());
  point.y(point.y() - gr_overscan_offset_y());

  int new_sel = Device::kNoAction;
  std::lock_guard<std::mutex> lg(updateMutex);