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

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

Merge "vrwm: Add 2D Mode + control app change"

parents b3a7005a 297e6deb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24,5 +24,6 @@ interface IVrWindowManager {
    void enterVrMode() = 2;
    void exitVrMode() = 3;
    void setDebugMode(int mode) = 4;
    void set2DMode(int mode) = 5;
}
+21 −7
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ namespace dvr {
namespace {

constexpr float kLayerScaleFactor = 3.0f;
constexpr unsigned int kVRAppLayerCount = 2;
constexpr unsigned int kMaximumPendingFrames = 8;

// clang-format off
@@ -99,7 +98,7 @@ mat4 GetLayerTransform(const TextureLayer& texture_layer, float display_width,

// Determine if ths frame should be shown or hidden.
ViewMode CalculateVisibilityFromLayerConfig(const HwcCallback::Frame& frame,
                                            uint32_t vr_app) {
                                            uint32_t *appid) {
  auto& layers = frame.layers();

  // TODO(achaulk): Figure out how to identify the current VR app for 2D app
@@ -120,6 +119,11 @@ ViewMode CalculateVisibilityFromLayerConfig(const HwcCallback::Frame& frame,
    return ViewMode::Hidden;
  }

  if(layers[index].appid != *appid) {
    *appid = layers[index].appid;
    return ViewMode::App;
  }

  // This is the VR app, ignore it.
  index++;

@@ -136,6 +140,7 @@ ViewMode CalculateVisibilityFromLayerConfig(const HwcCallback::Frame& frame,
    if (!layers[i].should_skip_layer())
      return ViewMode::VR;
  }

  return ViewMode::Hidden;
}

@@ -198,16 +203,25 @@ void DisplayView::OnDrawFrame(SurfaceFlingerView* surface_flinger_view,

base::unique_fd DisplayView::OnFrame(std::unique_ptr<HwcCallback::Frame> frame,
                                     bool debug_mode, bool* showing) {
  ViewMode visibility =
      CalculateVisibilityFromLayerConfig(*frame.get(), current_vr_app_);
  uint32_t app = current_vr_app_;
  ViewMode visibility = CalculateVisibilityFromLayerConfig(*frame.get(), &app);

  if (visibility == ViewMode::Hidden && debug_mode)
    visibility = ViewMode::VR;

  if (frame->layers().empty())
  if (frame->layers().empty()) {
    current_vr_app_ = 0;
  else
    current_vr_app_ = frame->layers().front().appid;
  } else if (visibility == ViewMode::App) {
    // This is either a VR app switch or a 2D app launching.
    // If we can have VR apps, update if it's 0.
    if (!always_2d_ && (current_vr_app_ == 0 || !use_2dmode_)) {
      visibility = ViewMode::Hidden;
      current_vr_app_ = app;
    }
  } else if (!current_vr_app_) {
    // The VR app is running.
    current_vr_app_ = app;
  }

  pending_frames_.emplace_back(std::move(frame), visibility);

+5 −0
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ class DisplayView {
  uint32_t id() const { return id_; }
  int touchpad_id() const { return touchpad_id_; }

  void set_2dmode(bool mode) { use_2dmode_ = mode; }
  void set_always_2d(bool mode) { always_2d_ = mode; }

 private:
  bool IsHit(const vec3& view_location, const vec3& view_direction,
             vec3* hit_location, vec2* hit_location_in_window_coord,
@@ -79,6 +82,8 @@ class DisplayView {
  vec2 ime_top_left_;
  vec2 ime_size_;
  bool has_ime_ = false;
  bool use_2dmode_ = false;
  bool always_2d_ = false;

  struct PendingFrame {
    PendingFrame() = default;
+12 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ namespace dvr {

namespace {

constexpr uint32_t kPrimaryDisplayId = 1;

const std::string kVertexShader = SHADER0([]() {
  layout(location = 0) in vec4 aPosition;
  layout(location = 1) in vec4 aTexCoord;
@@ -96,7 +98,7 @@ mat4 GetHorizontallyAlignedMatrixFromPose(const Posef& pose) {
}

int GetTouchIdForDisplay(uint32_t display) {
  return display == 1 ? DVR_VIRTUAL_TOUCHPAD_PRIMARY
  return display == kPrimaryDisplayId ? DVR_VIRTUAL_TOUCHPAD_PRIMARY
                                      : DVR_VIRTUAL_TOUCHPAD_VIRTUAL;
}

@@ -190,6 +192,11 @@ void ShellView::dumpInternal(String8& result) {
  result.append("\n");
}

void ShellView::Set2DMode(bool mode) {
  if (!displays_.empty())
    displays_[0]->set_2dmode(mode);
}

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

@@ -253,6 +260,9 @@ DisplayView* ShellView::FindOrCreateDisplay(uint32_t id) {
  }

  auto display = new DisplayView(id, GetTouchIdForDisplay(id));
  // Virtual displays only ever have 2D apps so force it.
  if (id != kPrimaryDisplayId)
    display->set_always_2d(true);
  new_displays_.emplace_back(display);
  return display;
}
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ class ShellView : public Application,
  void EnableDebug(bool debug) override;
  void VrMode(bool mode) override;
  void dumpInternal(String8& result) override;
  void Set2DMode(bool mode) override;


 protected:
  void DrawEye(EyeType eye, const mat4& perspective, const mat4& eye_matrix,
Loading