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

Commit eb49c451 authored by Albert Chaulk's avatar Albert Chaulk
Browse files

vrwm: Fix controller input/rendering mismatch

This works for portrait mode only for now. Landscape phones present
some weird buffer sizes (1080x1080) that get scaled incorrectly for
input

This also removes all of our older hacks, such as swapping
width/height in SurfaceFlingerView and the swap + invert of touch
input. A global 90 degree rotation is applied to present the portrait
buffers in the correct orientation

vr_wm_ctl has a command to stack another rotation on top of the
existing ones in order to facilitate development for now. Apps will
likely show up rotated, "vr_wm_ctl rotate 1" will fix it, or -1 if
it needs to be rotated the other way.

Bug: None
Test: Manual with permissions and calculator

Change-Id: Ifd31b444b944fbf3085613349caae37e817538f6
parent e153b292
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25,5 +25,6 @@ interface IVrWindowManager {
    void exitVrMode() = 3;
    void setDebugMode(int mode) = 4;
    void set2DMode(int mode) = 5;
    void setRotation(int angle) = 6;
}
+16 −8
Original line number Diff line number Diff line
@@ -146,16 +146,18 @@ ViewMode CalculateVisibilityFromLayerConfig(const HwcCallback::Frame& frame,

DisplayView::DisplayView(uint32_t id, int touchpad_id)
    : id_(id), touchpad_id_(touchpad_id) {
  translate_ = Eigen::Translation3f(0, 0, -2.5f);
  translate_ = Eigen::Translation3f(0, 0, -5.0f);
  ime_translate_ = mat4(Eigen::Translation3f(0.0f, -0.5f, 0.25f));
  ime_top_left_ = vec2(0, 0);
  ime_size_ = vec2(0, 0);
  rotation_ = mat4::Identity();
}

DisplayView::~DisplayView() {}

void DisplayView::Recenter(const mat4& initial) {
  initial_head_matrix_ = initial;
  initial_head_matrix_ =
      initial * Eigen::AngleAxisf(M_PI * 0.5f, vec3::UnitZ());
}

void DisplayView::SetPrograms(ShaderProgram* program,
@@ -248,7 +250,7 @@ base::unique_fd DisplayView::OnFrame(std::unique_ptr<HwcCallback::Frame> frame,
bool DisplayView::IsHit(const vec3& view_location, const vec3& view_direction,
                        vec3* hit_location, vec2* hit_location_in_window_coord,
                        bool test_ime) {
  mat4 m = initial_head_matrix_ * translate_;
  mat4 m = GetStandardTransform();
  if (test_ime)
    m = m * ime_translate_;
  mat4 inverse = (m * scale_).inverse();
@@ -314,8 +316,7 @@ void DisplayView::DrawOverlays(const mat4& perspective, const mat4& eye_matrix,
    mat4 layer_transform =
        GetLayerTransform(texture_layer, size_.x(), size_.y());

    mat4 transform =
        initial_head_matrix_ * translate_ * scale_ * layer_transform;
    mat4 transform = GetStandardTransform() * scale_ * layer_transform;
    DrawWithTransform(transform, *program_);

    glDisable(GL_BLEND);
@@ -351,14 +352,21 @@ void DisplayView::UpdateReleaseFence() {
  }
}

mat4 DisplayView::GetStandardTransform() {
  mat4 m = initial_head_matrix_ * rotation_ * translate_;
  if (current_frame_.visibility == ViewMode::App)
    m *= Eigen::AngleAxisf(M_PI * -0.5f, vec3::UnitZ());
  return m;
}

void DisplayView::DrawIme() {
  program_->Use();
  glBindTexture(GL_TEXTURE_2D, ime_texture_.texture->id());

  mat4 layer_transform = GetLayerTransform(ime_texture_, size_.x(), size_.y());

  mat4 transform = initial_head_matrix_ * translate_ * ime_translate_ * scale_ *
                   layer_transform;
  mat4 transform =
      GetStandardTransform() * ime_translate_ * scale_ * layer_transform;

  DrawWithTransform(transform, *program_);
}
@@ -377,7 +385,7 @@ void DisplayView::DrawDimOverlay(const mat4& mvp, const TextureLayer& layer,
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  mat4 layer_transform = GetLayerTransform(layer, size_.x(), size_.y());

  mat4 transform = initial_head_matrix_ * translate_ * scale_ * layer_transform;
  mat4 transform = GetStandardTransform() * scale_ * layer_transform;
  DrawWithTransform(transform, *overlay_program_);
  glDisable(GL_BLEND);
}
+6 −0
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ class DisplayView {
  void set_2dmode(bool mode) { use_2dmode_ = mode; }
  void set_always_2d(bool mode) { always_2d_ = mode; }

  void set_rotation(const mat4& rotation) { rotation_ = rotation; }

 private:
  bool IsHit(const vec3& view_location, const vec3& view_direction,
             vec3* hit_location, vec2* hit_location_in_window_coord,
@@ -60,6 +62,9 @@ class DisplayView {
                      const vec2& top_left, const vec2& bottom_right);
  void DrawWithTransform(const mat4& transform, const ShaderProgram& program);

  // This is the rotated, translated but unscaled transform to apply everywhere.
  mat4 GetStandardTransform();

  uint32_t id_;
  int touchpad_id_;

@@ -72,6 +77,7 @@ class DisplayView {
  mat4 scale_;
  mat4 translate_;
  mat4 ime_translate_;
  mat4 rotation_;
  vec2 size_;

  std::vector<TextureLayer> textures_;
+14 −6
Original line number Diff line number Diff line
@@ -202,6 +202,12 @@ void ShellView::Set2DMode(bool mode) {
    displays_[0]->set_2dmode(mode);
}

void ShellView::SetRotation(int angle) {
  mat4 m(Eigen::AngleAxisf(M_PI * -0.5f * angle, vec3::UnitZ()));
  for (auto& d: displays_)
    d->set_rotation(m);
}

void ShellView::OnDrawFrame() {
  bool visible = false;

@@ -306,10 +312,6 @@ void ShellView::DrawEye(EyeType eye, const mat4& perspective,

  size_ = vec2(surface_flinger_view_->width(), surface_flinger_view_->height());

  // TODO(alexst): Replicate controller rendering from VR Home.
  // Current approach in the function below is a quick visualization.
  DrawController(perspective, eye_matrix, head_matrix);

  for (auto& display : displays_) {
    if (display->visible()) {
      display->DrawEye(eye, perspective, eye_matrix, head_matrix, size_,
@@ -317,6 +319,10 @@ void ShellView::DrawEye(EyeType eye, const mat4& perspective,
    }
  }

  // TODO(alexst): Replicate controller rendering from VR Home.
  // Current approach in the function below is a quick visualization.
  DrawController(perspective, eye_matrix, head_matrix);

  DrawReticle(perspective, eye_matrix, head_matrix);
}

@@ -456,12 +462,14 @@ void ShellView::Touch() {

  const vec2& hit_location = active_display_->hit_location();

  float x = hit_location.x() / size_.x();
  float y = hit_location.y() / size_.y();

  // Device is portrait, but in landscape when in VR.
  // Rotate touch input appropriately.
  const android::status_t status = dvrVirtualTouchpadTouch(
      virtual_touchpad_.get(), active_display_->touchpad_id(),
      1.0f - hit_location.y() / size_.y(), hit_location.x() / size_.x(),
      is_touching_ ? 1.0f : 0.0f);
      x, y, is_touching_ ? 1.0f : 0.0f);
  if (status != OK) {
    ALOGE("touch failed: %d", status);
  }
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ class ShellView : public Application,
  void VrMode(bool mode) override;
  void dumpInternal(String8& result) override;
  void Set2DMode(bool mode) override;
  void SetRotation(int angle) override;


 protected:
Loading