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

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

Merge changes Iea842087,I4830d121,Ied48f024

* changes:
  Allow VRWM to show 2D apps
  VR: Do extra validation in VR HWC
  Start VR WindowManager in a headless mode.
parents 54f2ee40 520fb0e2
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -161,8 +161,10 @@ void Application::ProcessTasks(const std::vector<MainThreadTask>& tasks) {
        }
        }
        break;
        break;
      case MainThreadTask::EnteringVrMode:
      case MainThreadTask::EnteringVrMode:
        if (!initialized_)
        if (!initialized_) {
          AllocateResources();
          if (AllocateResources())
            ALOGE("Failed to allocate resources");
        }
        break;
        break;
      case MainThreadTask::ExitingVrMode:
      case MainThreadTask::ExitingVrMode:
        if (initialized_)
        if (initialized_)
+38 −22
Original line number Original line Diff line number Diff line
@@ -142,17 +142,20 @@ void HwcDisplay::GetChangedCompositionTypes(
  }
  }
}
}


std::vector<ComposerView::ComposerLayer> HwcDisplay::GetFrame() {
Error HwcDisplay::GetFrame(
  // Increment the time the fence is signalled every time we get the
    std::vector<ComposerView::ComposerLayer>* out_frames) {
  // presentation frame. This ensures that calling ReleaseFrame() only affects
  // the current frame.
  fence_time_++;

  bool queued_client_target = false;
  bool queued_client_target = false;
  std::vector<ComposerView::ComposerLayer> frame;
  std::vector<ComposerView::ComposerLayer> frame;
  for (const auto& layer : layers_) {
  for (const auto& layer : layers_) {
    if (layer.composition_type == IComposerClient::Composition::CLIENT) {
    if (layer.composition_type == IComposerClient::Composition::CLIENT) {
      if (!queued_client_target) {
      if (queued_client_target)
        continue;

      if (!buffer_.get()) {
        ALOGE("Client composition requested but no client target buffer");
        return Error::BAD_LAYER;
      }

      ComposerView::ComposerLayer client_target_layer = {
      ComposerView::ComposerLayer client_target_layer = {
          .buffer = buffer_,
          .buffer = buffer_,
          .fence = fence_.get() ? fence_ : new Fence(-1),
          .fence = fence_.get() ? fence_ : new Fence(-1),
@@ -165,13 +168,22 @@ std::vector<ComposerView::ComposerLayer> HwcDisplay::GetFrame() {


      frame.push_back(client_target_layer);
      frame.push_back(client_target_layer);
      queued_client_target = true;
      queued_client_target = true;
      }
    } else {
    } else {
      if (!layer.info.buffer.get() || !layer.info.fence.get()) {
        ALOGE("Layer requested without valid buffer");
        return Error::BAD_LAYER;
      }

      frame.push_back(layer.info);
      frame.push_back(layer.info);
    }
    }
  }
  }


  return frame;
  // Increment the time the fence is signalled every time we get the
  // presentation frame. This ensures that calling ReleaseFrame() only affects
  // the current frame.
  fence_time_++;
  out_frames->swap(frame);
  return Error::NONE;
}
}


void HwcDisplay::GetReleaseFences(int* present_fence,
void HwcDisplay::GetReleaseFences(int* present_fence,
@@ -392,7 +404,8 @@ Error VrHwc::setOutputBuffer(Display display, buffer_handle_t buffer,
  base::unique_fd fence(releaseFence);
  base::unique_fd fence(releaseFence);
  if (display != kDefaultDisplayId) return Error::BAD_DISPLAY;
  if (display != kDefaultDisplayId) return Error::BAD_DISPLAY;


  return Error::NONE;
  ALOGE("Virtual display support not implemented");
  return Error::UNSUPPORTED;
}
}


Error VrHwc::validateDisplay(
Error VrHwc::validateDisplay(
@@ -423,7 +436,10 @@ Error VrHwc::presentDisplay(Display display, int32_t* outPresentFence,
  std::vector<ComposerView::ComposerLayer> frame;
  std::vector<ComposerView::ComposerLayer> frame;
  {
  {
    std::lock_guard<std::mutex> guard(mutex_);
    std::lock_guard<std::mutex> guard(mutex_);
    frame = display_.GetFrame();
    Error status = display_.GetFrame(&frame);
    if (status != Error::NONE)
      return status;

    display_.GetReleaseFences(outPresentFence, outLayers, outReleaseFences);
    display_.GetReleaseFences(outPresentFence, outLayers, outReleaseFences);
  }
  }


+1 −1
Original line number Original line Diff line number Diff line
@@ -115,7 +115,7 @@ class HwcDisplay {
      std::vector<Layer>* layer_ids,
      std::vector<Layer>* layer_ids,
      std::vector<IComposerClient::Composition>* composition);
      std::vector<IComposerClient::Composition>* composition);


  std::vector<ComposerView::ComposerLayer> GetFrame();
  Error GetFrame(std::vector<ComposerView::ComposerLayer>* out_frame);


  void GetReleaseFences(int* present_fence, std::vector<Layer>* layer_ids,
  void GetReleaseFences(int* present_fence, std::vector<Layer>* layer_ids,
                        std::vector<int>* fences);
                        std::vector<int>* fences);
+0 −1
Original line number Original line Diff line number Diff line
@@ -75,7 +75,6 @@ void RenderThread::RunRenderLoop(
  jobject android_context = env->NewLocalRef(android_context_global_ref_);
  jobject android_context = env->NewLocalRef(android_context_global_ref_);


  int init_result = shell_view_.Initialize(env, android_context, class_loader);
  int init_result = shell_view_.Initialize(env, android_context, class_loader);
  init_result += shell_view_.AllocateResources();
  init_result_promise->set_value(init_result);
  init_result_promise->set_value(init_result);
  if (init_result == 0) {
  if (init_result == 0) {
    while (!quit_)
    while (!quit_)
+32 −17
Original line number Original line Diff line number Diff line
@@ -194,16 +194,22 @@ quat FromGvrQuatf(const gvr_quatf& quaternion) {
}
}


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


  // We assume the first two layers are the VR app.
  // We assume the first two layers are the VR app.
  if (layers.size() < kVRAppLayerCount)
  if (layers.size() < kVRAppLayerCount)
    return false;
    return ViewMode::Hidden;


  if (vr_app != layers[0].appid || layers[0].appid == 0)
  if (vr_app != layers[0].appid || layers[0].appid == 0 ||
    return false;
      layers[1].appid != layers[0].appid) {
    if (layers[1].appid != layers[0].appid && layers[0].appid) {
      // This might be a 2D app.
      return ViewMode::App;
    }
    return ViewMode::Hidden;
  }


  // If a non-VR-app, non-skipped layer appears, show.
  // If a non-VR-app, non-skipped layer appears, show.
  size_t index = kVRAppLayerCount;
  size_t index = kVRAppLayerCount;
@@ -219,11 +225,12 @@ bool CalculateVisibilityFromLayerConfig(const HwcCallback::Frame& frame,
  // If any non-skipped layers exist now then we show, otherwise hide.
  // If any non-skipped layers exist now then we show, otherwise hide.
  for (size_t i = index; i < layers.size(); i++) {
  for (size_t i = index; i < layers.size(); i++) {
    if (!layers[i].should_skip_layer())
    if (!layers[i].should_skip_layer())
      return true;
      return ViewMode::VR;
  }
  }
  return false;
  return ViewMode::Hidden;
}
}



}  // namespace
}  // namespace


ShellView::ShellView() {
ShellView::ShellView() {
@@ -308,7 +315,7 @@ void ShellView::OnDrawFrame() {
    if (!pending_frames_.empty()) {
    if (!pending_frames_.empty()) {
      // Check if we should advance the frame.
      // Check if we should advance the frame.
      auto& frame = pending_frames_.front();
      auto& frame = pending_frames_.front();
      if (!frame.visibility ||
      if (frame.visibility == ViewMode::Hidden ||
          frame.frame->Finish() == HwcCallback::FrameStatus::kFinished) {
          frame.frame->Finish() == HwcCallback::FrameStatus::kFinished) {
        current_frame_ = std::move(frame);
        current_frame_ = std::move(frame);
        pending_frames_.pop_front();
        pending_frames_.pop_front();
@@ -316,17 +323,20 @@ void ShellView::OnDrawFrame() {
    }
    }
  }
  }


  if (!debug_mode_ && current_frame_.visibility != is_visible_) {
  bool visible = current_frame_.visibility != ViewMode::Hidden;
    SetVisibility(current_frame_.visibility);

  if (!debug_mode_ && visible != is_visible_) {
    SetVisibility(current_frame_.visibility != ViewMode::Hidden);
  }
  }


  if (!current_frame_.visibility)
  if (!visible)
    return;
    return;


  ime_texture_ = TextureLayer();
  ime_texture_ = TextureLayer();


  surface_flinger_view_->GetTextures(*current_frame_.frame.get(), &textures_,
  surface_flinger_view_->GetTextures(*current_frame_.frame.get(), &textures_,
                                     &ime_texture_, debug_mode_);
                                     &ime_texture_, debug_mode_,
                                     view_mode_ == ViewMode::VR);
  has_ime_ = ime_texture_.texture != nullptr;
  has_ime_ = ime_texture_.texture != nullptr;
}
}


@@ -373,14 +383,17 @@ void ShellView::OnFrame(std::unique_ptr<HwcCallback::Frame> frame) {
  if (!frame || frame->layers().empty())
  if (!frame || frame->layers().empty())
    return;
    return;


  bool visibility = debug_mode_ || CalculateVisibilityFromLayerConfig(
  ViewMode visibility =
                                       *frame.get(), current_vr_app_);
      CalculateVisibilityFromLayerConfig(*frame.get(), current_vr_app_);

  if (visibility == ViewMode::Hidden && debug_mode_)
    visibility = ViewMode::VR;
  current_vr_app_ = frame->layers().front().appid;
  current_vr_app_ = frame->layers().front().appid;


  // If we are not showing the frame there's no need to keep anything around.
  // If we are not showing the frame there's no need to keep anything around.
  if (!visibility) {
  if (visibility == ViewMode::Hidden) {
    // Hidden, no change so drop it completely
    // Hidden, no change so drop it completely
    if (!current_frame_.visibility)
    if (current_frame_.visibility == ViewMode::Hidden)
      return;
      return;


    frame.reset(nullptr);
    frame.reset(nullptr);
@@ -395,9 +408,11 @@ void ShellView::OnFrame(std::unique_ptr<HwcCallback::Frame> frame) {


  // If we are showing ourselves the main thread is not processing anything,
  // If we are showing ourselves the main thread is not processing anything,
  // so give it a kick.
  // so give it a kick.
  if (visibility && !current_frame_.visibility)
  if (visibility != ViewMode::Hidden && current_frame_.visibility == ViewMode::Hidden) {
    QueueTask(MainThreadTask::EnteringVrMode);
    QueueTask(MainThreadTask::Show);
    QueueTask(MainThreadTask::Show);
  }
  }
}


bool ShellView::IsHit(const vec3& view_location, const vec3& view_direction,
bool ShellView::IsHit(const vec3& view_location, const vec3& view_direction,
                      vec3* hit_location, vec2* hit_location_in_window_coord,
                      vec3* hit_location, vec2* hit_location_in_window_coord,
Loading