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

Commit 093516f6 authored by John Bates's avatar John Bates
Browse files

Hold onto FileHandles for glBindSharedBufferQCOM calls

The internal implementation of glBindSharedBuffer does not dup
the file descriptor, so to be pedantic about fd lifetime we
need to hold onto the fd until the gl buffer is deleted.

Bug: b/34256609
Test: manually switched between apps
Change-Id: I35bfbfe6a6b793bc3bdf38d7ddca31699ee0f4ff
parent a2d92c56
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -178,6 +178,9 @@ class LateLatch {
  LateLatchOutput* eds_late_latch_output_;

  DvrPose* pose_client_;

  pdx::LocalHandle surface_metadata_fd_;
  pdx::LocalHandle pose_buffer_fd_;
};

}  // namespace dvr
+7 −7
Original line number Diff line number Diff line
@@ -252,7 +252,8 @@ LateLatch::LateLatch(bool is_app_late_latch,
                     LocalHandle&& surface_metadata_fd)
    : is_app_late_latch_(is_app_late_latch),
      app_late_latch_output_(NULL),
      eds_late_latch_output_(NULL) {
      eds_late_latch_output_(NULL),
      surface_metadata_fd_(std::move(surface_metadata_fd)) {
  CHECK_GL();
  glGenBuffers(1, &input_buffer_id_);
  glBindBuffer(GL_SHADER_STORAGE_BUFFER, input_buffer_id_);
@@ -264,12 +265,11 @@ LateLatch::LateLatch(bool is_app_late_latch,
               GL_DYNAMIC_COPY);
  CHECK_GL();

  LocalHandle pose_buffer_fd;
  pose_client_ = dvrPoseCreate();
  if (!pose_client_) {
    ALOGE("LateLatch Error: failed to create pose client");
  } else {
    int ret = privateDvrPoseGetRingBufferFd(pose_client_, &pose_buffer_fd);
    int ret = privateDvrPoseGetRingBufferFd(pose_client_, &pose_buffer_fd_);
    if (ret < 0) {
      ALOGE("LateLatch Error: failed to get pose ring buffer");
    }
@@ -280,20 +280,20 @@ LateLatch::LateLatch(bool is_app_late_latch,
  if (!glBindSharedBufferQCOM) {
    ALOGE("Error: Missing gralloc buffer extension, no pose data");
  } else {
    if (pose_buffer_fd) {
    if (pose_buffer_fd_) {
      glBindBuffer(GL_SHADER_STORAGE_BUFFER, pose_buffer_object_);
      glBindSharedBufferQCOM(GL_SHADER_STORAGE_BUFFER,
                             kPoseAsyncBufferTotalCount * sizeof(DvrPoseAsync),
                             pose_buffer_fd.Release());
                             pose_buffer_fd_.Get());
    }
    CHECK_GL();
  }

  glBindBuffer(GL_SHADER_STORAGE_BUFFER, metadata_buffer_id_);
  if (surface_metadata_fd && glBindSharedBufferQCOM) {
  if (surface_metadata_fd_ && glBindSharedBufferQCOM) {
    glBindSharedBufferQCOM(GL_SHADER_STORAGE_BUFFER,
                           sizeof(DisplaySurfaceMetadata),
                           surface_metadata_fd.Release());
                           surface_metadata_fd_.Get());
  } else {
    // Fall back on internal metadata buffer when none provided, for example
    // when distortion is done in the application process.
+6 −3
Original line number Diff line number Diff line
@@ -246,16 +246,17 @@ void Compositor::RenderTarget::DiscardColorAttachment() {

class Compositor::RenderPoseBufferObject {
 public:
  RenderPoseBufferObject(LocalHandle&& render_pose_buffer_fd) {
  RenderPoseBufferObject(LocalHandle&& render_pose_buffer_fd) :
      fd_(std::move(render_pose_buffer_fd)) {
    // Create new pose tracking buffer for this surface.
    glGenBuffers(1, &render_pose_buffer_object_);
    glBindBuffer(GL_UNIFORM_BUFFER, render_pose_buffer_object_);
    if (render_pose_buffer_fd) {
    if (fd_) {
      LOG_ALWAYS_FATAL_IF(!glBindSharedBufferQCOM);
      if (glBindSharedBufferQCOM)
        glBindSharedBufferQCOM(GL_UNIFORM_BUFFER,
                               sizeof(DisplaySurfaceMetadata),
                               render_pose_buffer_fd.Get());
                               fd_.Get());
      else
        ALOGE("Error: Missing gralloc buffer extension");
      CHECK_GL();
@@ -271,6 +272,7 @@ class Compositor::RenderPoseBufferObject {
  // Render pose buffer object. This contains an array of poses that corresponds
  // with the surface buffers.
  GLuint render_pose_buffer_object_;
  LocalHandle fd_;

  RenderPoseBufferObject(const RenderPoseBufferObject&) = delete;
  void operator=(const RenderPoseBufferObject&) = delete;
@@ -428,6 +430,7 @@ bool Compositor::InitializeEGL() {
}

void Compositor::Shutdown() {
  glFinish();
  render_target_[0].Destroy();
  render_target_[1].Destroy();
  layers_.clear();