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

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

Merge changes If66d1b06,I923c24b9

* changes:
  vrwm: Fix startup flickering
  vrwm: Add a listener for enter/exit vr mode events
parents e5046a71 57d3f2d9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ static_libs := \
  libperformance \
  libpdx_default_transport \
  libcutils \
  libvr_manager \

shared_libs := \
  android.dvr.composer@1.0 \
+23 −1
Original line number Diff line number Diff line
@@ -17,9 +17,16 @@
namespace android {
namespace dvr {

Application::Application() {}
Application::Application() {
  vr_mode_listener_ = new VrModeListener(this);
}

Application::~Application() {
  sp<IVrManager> vrManagerService = interface_cast<IVrManager>(
      defaultServiceManager()->getService(String16("vrmanager")));
  if (vrManagerService.get()) {
    vrManagerService->unregisterListener(vr_mode_listener_);
  }
}

int Application::Initialize() {
@@ -29,6 +36,11 @@ int Application::Initialize() {
  elbow_model_.Enable(ElbowModel::kDefaultNeckPosition, is_right_handed);
  last_frame_time_ = std::chrono::system_clock::now();

  sp<IVrManager> vrManagerService = interface_cast<IVrManager>(
      defaultServiceManager()->getService(String16("vrmanager")));
  if (vrManagerService.get()) {
    vrManagerService->registerListener(vr_mode_listener_);
  }
  return 0;
}

@@ -274,6 +286,11 @@ void Application::ProcessControllerInput() {
}

void Application::SetVisibility(bool visible) {
  if (visible && !initialized_) {
    if (AllocateResources())
      ALOGE("Failed to allocate resources");
  }

  bool changed = is_visible_ != visible;
  if (changed) {
    is_visible_ = visible;
@@ -296,5 +313,10 @@ void Application::QueueTask(MainThreadTask task) {
  wake_up_init_and_render_.notify_one();
}

void Application::VrModeListener::onVrStateChanged(bool enabled) {
  if (!enabled)
    app_->QueueTask(MainThreadTask::ExitingVrMode);
}

}  // namespace dvr
}  // namespace android
+11 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
#include <memory>
#include <private/dvr/types.h>
#include <stdint.h>
#include <vr/vr_manager/vr_manager.h>

#include <chrono>
#include <mutex>
@@ -43,6 +44,16 @@ class Application {
    Show,
  };

  class VrModeListener : public BnVrStateCallbacks {
   public:
    VrModeListener(Application *app) : app_(app) {}
    void onVrStateChanged(bool enabled) override;

   private:
    Application *app_;
  };

  sp<VrModeListener> vr_mode_listener_;
  virtual void OnDrawFrame() = 0;
  virtual void DrawEye(EyeType eye, const mat4& perspective,
                       const mat4& eye_matrix, const mat4& head_matrix) = 0;
+12 −0
Original line number Diff line number Diff line
@@ -51,6 +51,18 @@ class HwcCallback : public VrComposerView::Callback {
      }
    }

    // This is a layer that provides some other functionality, eg dim layer.
    // We use this to determine the point at which layers are "on top".
    bool is_extra_layer() const {
      switch(type) {
      case kSurfaceFlingerLayer:
      case kUndefinedWindow:
        return true;
      default:
        return false;
      }
    }

    sp<Fence> fence;
    sp<GraphicBuffer> buffer;
    Rectf crop;
+9 −5
Original line number Diff line number Diff line
@@ -195,7 +195,8 @@ ViewMode CalculateVisibilityFromLayerConfig(const HwcCallback::Frame& frame,
                                            uint32_t vr_app) {
  auto& layers = frame.layers();

  // We assume the first two layers are the VR app.
  // We assume the first two layers are the VR app. In the case of a 2D app,
  // there will be the app + at least one system layer so this is still safe.
  if (layers.size() < kVRAppLayerCount)
    return ViewMode::Hidden;

@@ -203,19 +204,23 @@ ViewMode CalculateVisibilityFromLayerConfig(const HwcCallback::Frame& frame,
      layers[1].appid != layers[0].appid) {
    if (layers[1].appid != layers[0].appid && layers[0].appid) {
      // This might be a 2D app.
      // If a dim layer exists afterwards it is much more likely that this is
      // actually an app launch artifact.
      for (size_t i = 2; i < layers.size(); i++) {
        if (layers[i].is_extra_layer())
          return ViewMode::Hidden;
      }
      return ViewMode::App;
    }
    return ViewMode::Hidden;
  }

  // If a non-VR-app, non-skipped layer appears, show.
  size_t index = kVRAppLayerCount;
  // Now, find a dim layer if it exists.
  // If it does, ignore any layers behind it for visibility determination.
  for (size_t i = index; i < layers.size(); i++) {
    if (layers[i].appid == 0) {
    if (layers[i].appid == HwcCallback::HwcLayer::kSurfaceFlingerLayer) {
      index = i + 1;
      break;
    }
  }

@@ -419,7 +424,6 @@ base::unique_fd ShellView::OnFrame(std::unique_ptr<HwcCallback::Frame> frame) {
  // so give it a kick.
  if (visibility != ViewMode::Hidden &&
      current_frame_.visibility == ViewMode::Hidden) {
    QueueTask(MainThreadTask::EnteringVrMode);
    QueueTask(MainThreadTask::Show);
  }