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

Commit 6f468c6a authored by Okan Arikan's avatar Okan Arikan
Browse files

Sync up the DvrConfig struct with Google3

Bug: 38506720
Test: No functional change. Just make.
Change-Id: Ib159dd156cef353a7881bc6b4004c46da5e2d449
parent 76dd2a70
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
#ifndef ANDROID_DVR_VRFLINGER_CONFIG_H
#define ANDROID_DVR_VRFLINGER_CONFIG_H
#ifndef ANDROID_DVR_CONFIG_H
#define ANDROID_DVR_CONFIG_H

// This header is shared by VrCore and Android and must be kept in sync.

#include <stdint.h>
#include <sys/cdefs.h>

__BEGIN_DECLS

// This is a shared memory buffer for passing config data from VrCore to
// libvrflinger in SurfaceFlinger.
struct DvrVrFlingerConfig {
struct __attribute__((packed, aligned(16))) DvrConfig {
  // Offset before vsync to submit frames to hardware composer.
  int frame_post_offset_ns{4000000};
  int32_t frame_post_offset_ns{4000000};

  // If the number of pending fences goes over this count at the point when we
  // are about to submit a new frame to HWC, we will drop the frame. This
@@ -20,11 +21,14 @@ struct DvrVrFlingerConfig {
  // the next vsync, at the point when the DMA to the display completes.
  // Currently we use a smart display and the EDS timing coincides with zero
  // pending fences, so this is 0.
  size_t allowed_pending_fence_count{0};
  int32_t allowed_pending_fence_count{0};

  // New fields should always be added to the end for backwards compat.

  // Reserved padding to 16 bytes.
  uint8_t pad[8];
};

__END_DECLS

#endif  // ANDROID_DVR_VRFLINGER_CONFIG_H
#endif  // ANDROID_DVR_CONFIG_H
+5 −5
Original line number Diff line number Diff line
#ifndef ANDROID_DVR_SHARED_BUFFERS_H_
#define ANDROID_DVR_SHARED_BUFFERS_H_

#include <dvr/dvr_config.h>
#include <dvr/dvr_pose.h>
#include <dvr/dvr_vrflinger_config.h>
#include <dvr/dvr_vsync.h>
#include <libbroadcastring/broadcast_ring.h>

@@ -11,7 +11,7 @@ namespace android {
namespace dvr {

// Increment when the layout for the buffers change.
constexpr uint32_t kSharedBufferLayoutVersion = 1;
enum : uint32_t { kSharedBufferLayoutVersion = 1 };

// Note: These buffers will be mapped from various system processes as well
// as VrCore and the application processes in a r/w manner.
@@ -26,6 +26,7 @@ constexpr uint32_t kSharedBufferLayoutVersion = 1;
static_assert(sizeof(DvrPoseAsync) == 128, "Unexpected size for DvrPoseAsync");
static_assert(sizeof(DvrPose) == 96, "Unexpected size for DvrPose");
static_assert(sizeof(DvrVsync) == 32, "Unexpected size for DvrVsync");
static_assert(sizeof(DvrConfig) == 16, "Unexpected size for DvrConfig");

// A helper class that provides compile time sized traits for the BroadcastRing.
template <class DvrType, size_t StaticCount>
@@ -41,13 +42,12 @@ class DvrRingBufferTraits {
// Traits classes.
using DvrPoseTraits = DvrRingBufferTraits<DvrPose, 0>;
using DvrVsyncTraits = DvrRingBufferTraits<DvrVsync, 2>;
using DvrVrFlingerConfigTraits = DvrRingBufferTraits<DvrVrFlingerConfig, 2>;
using DvrConfigTraits = DvrRingBufferTraits<DvrConfig, 2>;

// The broadcast ring classes that will expose the data.
using DvrPoseRing = BroadcastRing<DvrPose, DvrPoseTraits>;
using DvrVsyncRing = BroadcastRing<DvrVsync, DvrVsyncTraits>;
using DvrVrFlingerConfigRing =
    BroadcastRing<DvrVrFlingerConfig, DvrVrFlingerConfigTraits>;
using DvrConfigRing = BroadcastRing<DvrConfig, DvrConfigTraits>;

// This is a shared memory buffer for passing pose data estimated at vsyncs.
//
+3 −3
Original line number Diff line number Diff line
#include <android/hardware_buffer.h>
#include <dvr/dvr_buffer.h>
#include <dvr/dvr_config.h>
#include <dvr/dvr_display_manager.h>
#include <dvr/dvr_shared_buffers.h>
#include <dvr/dvr_surface.h>
#include <dvr/dvr_vrflinger_config.h>
#include <system/graphics.h>

#include <base/logging.h>
@@ -285,8 +285,8 @@ TEST_F(DvrGlobalBufferTest, TestVrflingerConfigBuffer) {
  const uint64_t usage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN |
                         AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY;

  size_t correct_size = DvrVrFlingerConfigRing::MemorySize();
  size_t wrong_size = DvrVrFlingerConfigRing::MemorySize(0);
  size_t correct_size = DvrConfigRing::MemorySize();
  size_t wrong_size = DvrConfigRing::MemorySize(0);

  // Setup an invalid config buffer (too small) and assert that it fails.
  DvrBuffer* setup_buffer = nullptr;
+5 −6
Original line number Diff line number Diff line
@@ -481,9 +481,9 @@ void HardwareComposer::OnDeletedGlobalBuffer(DvrGlobalBufferKey key) {

int HardwareComposer::MapConfigBuffer(IonBuffer& ion_buffer) {
  std::lock_guard<std::mutex> lock(shared_config_mutex_);
  shared_config_ring_ = DvrVrFlingerConfigRing();
  shared_config_ring_ = DvrConfigRing();

  if (ion_buffer.width() < DvrVrFlingerConfigRing::MemorySize()) {
  if (ion_buffer.width() < DvrConfigRing::MemorySize()) {
    ALOGE("HardwareComposer::MapConfigBuffer: invalid buffer size.");
    return -EINVAL;
  }
@@ -497,8 +497,7 @@ int HardwareComposer::MapConfigBuffer(IonBuffer& ion_buffer) {
    return -EPERM;
  }

  shared_config_ring_ =
      DvrVrFlingerConfigRing::Create(buffer_base, ion_buffer.width());
  shared_config_ring_ = DvrConfigRing::Create(buffer_base, ion_buffer.width());
  ion_buffer.Unlock();

  return 0;
@@ -506,7 +505,7 @@ int HardwareComposer::MapConfigBuffer(IonBuffer& ion_buffer) {

void HardwareComposer::ConfigBufferDeleted() {
  std::lock_guard<std::mutex> lock(shared_config_mutex_);
  shared_config_ring_ = DvrVrFlingerConfigRing();
  shared_config_ring_ = DvrConfigRing();
}

void HardwareComposer::UpdateConfigBuffer() {
@@ -514,7 +513,7 @@ void HardwareComposer::UpdateConfigBuffer() {
  if (!shared_config_ring_.is_valid())
    return;
  // Copy from latest record in shared_config_ring_ to local copy.
  DvrVrFlingerConfig record;
  DvrConfig record;
  if (shared_config_ring_.GetNewest(&shared_config_ring_sequence_, &record)) {
    post_thread_config_ = record;
  }
+3 −3
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#include <tuple>
#include <vector>

#include <dvr/dvr_vrflinger_config.h>
#include <dvr/dvr_config.h>
#include <dvr/dvr_vsync.h>
#include <pdx/file_handle.h>
#include <pdx/rpc/variant.h>
@@ -452,10 +452,10 @@ class HardwareComposer {
  std::unique_ptr<CPUMappedBroadcastRing<DvrVsyncRing>> vsync_ring_;

  // Broadcast ring for receiving config data from the DisplayManager.
  DvrVrFlingerConfigRing shared_config_ring_;
  DvrConfigRing shared_config_ring_;
  uint32_t shared_config_ring_sequence_{0};
  // Config buffer for reading from the post thread.
  DvrVrFlingerConfig post_thread_config_;
  DvrConfig post_thread_config_;
  std::mutex shared_config_mutex_;

  static constexpr int kPostThreadInterrupted = 1;