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

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

Merge "DO NOT MERGE Remove graphics.cpp and friends" into oc-dev

parents bb576776 fac40740
Loading
Loading
Loading
Loading
+2 −36
Original line number Diff line number Diff line
@@ -13,15 +13,9 @@
// limitations under the License.

sourceFiles = [
    "native_buffer_queue.cpp",
    "display_client.cpp",
    "display_manager_client.cpp",
    "display_protocol.cpp",
    "dummy_native_window.cpp",
    "frame_history.cpp",
    "gl_fenced_flush.cpp",
    "graphics.cpp",
    "late_latch.cpp",
    "vsync_client.cpp",
]

@@ -34,9 +28,6 @@ sharedLibraries = [
    "libcutils",
    "liblog",
    "libutils",
    "libEGL",
    "libGLESv2",
    "libvulkan",
    "libui",
    "libgui",
    "libhardware",
@@ -45,10 +36,9 @@ sharedLibraries = [
]

staticLibraries = [
    "libbufferhub",
    "libbufferhubqueue",
    "libdvrcommon",
    "libdvrgraphics",
    "libbufferhubqueue",
    "libbufferhub",
    "libvrsensor",
    "libpdx_default_transport",
]
@@ -74,27 +64,3 @@ cc_library {

    name: "libdisplay",
}

graphicsAppTestFiles = ["tests/graphics_app_tests.cpp"]

cc_test {
    name: "graphics_app_tests",
    tags: ["optional"],

    srcs: graphicsAppTestFiles,

    shared_libs: sharedLibraries,

    static_libs: ["libdisplay"] + staticLibraries,
}

dummyNativeWindowTestFiles = ["tests/dummy_native_window_tests.cpp"]

cc_test {
    name: "dummy_native_window_tests",
    tags: [ "optional" ],
    srcs: dummyNativeWindowTestFiles,
    shared_libs: sharedLibraries,
    static_libs: [ "libdisplay" ] + staticLibraries,
}
+0 −1
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@
#include <mutex>

#include <private/dvr/display_protocol.h>
#include <private/dvr/late_latch.h>
#include <private/dvr/native_buffer.h>

using android::pdx::ErrorStatus;
+0 −80
Original line number Diff line number Diff line
#include "include/private/dvr/dummy_native_window.h"

#include <utils/Errors.h>

namespace {
// Dummy functions required for an ANativeWindow Implementation.
int F1(struct ANativeWindow*, int) { return 0; }
int F2(struct ANativeWindow*, struct ANativeWindowBuffer**) { return 0; }
int F3(struct ANativeWindow*, struct ANativeWindowBuffer*) { return 0; }
int F4(struct ANativeWindow*, struct ANativeWindowBuffer**, int*) { return 0; }
int F5(struct ANativeWindow*, struct ANativeWindowBuffer*, int) { return 0; }
}  // anonymous namespace

namespace android {
namespace dvr {

DummyNativeWindow::DummyNativeWindow() {
  ANativeWindow::setSwapInterval = F1;
  ANativeWindow::dequeueBuffer = F4;
  ANativeWindow::cancelBuffer = F5;
  ANativeWindow::queueBuffer = F5;
  ANativeWindow::query = Query;
  ANativeWindow::perform = Perform;

  ANativeWindow::dequeueBuffer_DEPRECATED = F2;
  ANativeWindow::cancelBuffer_DEPRECATED = F3;
  ANativeWindow::lockBuffer_DEPRECATED = F3;
  ANativeWindow::queueBuffer_DEPRECATED = F3;
}

int DummyNativeWindow::Query(const ANativeWindow*, int what, int* value) {
  switch (what) {
    // This must be 1 in order for eglCreateWindowSurface to not trigger an
    // error
    case NATIVE_WINDOW_IS_VALID:
      *value = 1;
      return NO_ERROR;
    case NATIVE_WINDOW_WIDTH:
    case NATIVE_WINDOW_HEIGHT:
    case NATIVE_WINDOW_FORMAT:
    case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS:
    case NATIVE_WINDOW_CONCRETE_TYPE:
    case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER:
    case NATIVE_WINDOW_DEFAULT_WIDTH:
    case NATIVE_WINDOW_DEFAULT_HEIGHT:
    case NATIVE_WINDOW_TRANSFORM_HINT:
      *value = 0;
      return NO_ERROR;
  }

  *value = 0;
  return BAD_VALUE;
}

int DummyNativeWindow::Perform(ANativeWindow*, int operation, ...) {
  switch (operation) {
    case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
    case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
    case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
    case NATIVE_WINDOW_SET_USAGE:
    case NATIVE_WINDOW_CONNECT:
    case NATIVE_WINDOW_DISCONNECT:
    case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
    case NATIVE_WINDOW_API_CONNECT:
    case NATIVE_WINDOW_API_DISCONNECT:
    case NATIVE_WINDOW_SET_BUFFER_COUNT:
    case NATIVE_WINDOW_SET_BUFFERS_DATASPACE:
    case NATIVE_WINDOW_SET_SCALING_MODE:
      return NO_ERROR;
    case NATIVE_WINDOW_LOCK:
    case NATIVE_WINDOW_UNLOCK_AND_POST:
    case NATIVE_WINDOW_SET_CROP:
    case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
      return INVALID_OPERATION;
  }
  return NAME_NOT_FOUND;
}

}  // namespace dvr
}  // namespace android
+0 −147
Original line number Diff line number Diff line
#include <private/dvr/frame_history.h>

#include <errno.h>
#include <log/log.h>
#include <sync/sync.h>

#include <pdx/file_handle.h>
#include <private/dvr/clock_ns.h>
#include <private/dvr/sync_util.h>

using android::pdx::LocalHandle;

constexpr int kNumFramesToUseForSchedulePrediction = 10;
constexpr int kDefaultVsyncIntervalPrediction = 1;
constexpr int kMaxVsyncIntervalPrediction = 4;
constexpr int kDefaultPendingFrameBufferSize = 10;

namespace android {
namespace dvr {

FrameHistory::PendingFrame::PendingFrame()
    : start_ns(0), scheduled_vsync(0), scheduled_finish_ns(0) {}

FrameHistory::PendingFrame::PendingFrame(int64_t start_ns,
                                         uint32_t scheduled_vsync,
                                         int64_t scheduled_finish_ns,
                                         LocalHandle&& fence)
    : start_ns(start_ns), scheduled_vsync(scheduled_vsync),
      scheduled_finish_ns(scheduled_finish_ns), fence(std::move(fence)) {}

FrameHistory::FrameHistory() : FrameHistory(kDefaultPendingFrameBufferSize) {}

FrameHistory::FrameHistory(int pending_frame_buffer_size)
    : pending_frames_(pending_frame_buffer_size),
      finished_frames_(pending_frame_buffer_size),
      frame_duration_history_(kNumFramesToUseForSchedulePrediction) {}

void FrameHistory::Reset(int pending_frame_buffer_size) {
  pending_frames_.Reset(pending_frame_buffer_size);
  finished_frames_.Reset(pending_frame_buffer_size);
  frame_duration_history_.Clear();
}

void FrameHistory::OnFrameStart(uint32_t scheduled_vsync,
                                int64_t scheduled_finish_ns) {
  if (!pending_frames_.IsEmpty() && !pending_frames_.Back().fence) {
    // If we don't have a fence set for the previous frame it's because
    // OnFrameStart() was called twice in a row with no OnFrameSubmit() call. In
    // that case throw out the pending frame data for the last frame.
    pending_frames_.PopBack();
  }

  if (pending_frames_.IsFull()) {
    ALOGW("Pending frames buffer is full. Discarding pending frame data.");
  }

  pending_frames_.Append(PendingFrame(GetSystemClockNs(), scheduled_vsync,
                                      scheduled_finish_ns, LocalHandle()));
}

void FrameHistory::OnFrameSubmit(LocalHandle&& fence) {
  // Add the fence to the previous frame data in pending_frames so we can
  // track when it finishes.
  if (!pending_frames_.IsEmpty() && !pending_frames_.Back().fence) {
    if (fence && pending_frames_.Back().scheduled_vsync != UINT32_MAX)
      pending_frames_.Back().fence = std::move(fence);
    else
      pending_frames_.PopBack();
  }
}

void FrameHistory::CheckForFinishedFrames() {
  if (pending_frames_.IsEmpty())
    return;

  android::dvr::FenceInfoBuffer fence_info_buffer;
  while (!pending_frames_.IsEmpty()) {
    const auto& pending_frame = pending_frames_.Front();
    if (!pending_frame.fence) {
      // The frame hasn't been submitted yet, so there's nothing more to do
      break;
    }

    int64_t fence_signaled_time = -1;
    int fence = pending_frame.fence.Get();
    int sync_result = sync_wait(fence, 0);
    if (sync_result == 0) {
      int fence_signaled_result =
          GetFenceSignaledTimestamp(fence, &fence_info_buffer,
                                    &fence_signaled_time);
      if (fence_signaled_result < 0) {
        ALOGE("Failed getting signaled timestamp from fence");
      } else {
        // The frame is finished. Record the duration and move the frame data
        // from pending_frames_ to finished_frames_.
        DvrFrameScheduleResult schedule_result = {};
        schedule_result.vsync_count = pending_frame.scheduled_vsync;
        schedule_result.scheduled_frame_finish_ns =
            pending_frame.scheduled_finish_ns;
        schedule_result.frame_finish_offset_ns =
            fence_signaled_time - pending_frame.scheduled_finish_ns;
        finished_frames_.Append(schedule_result);
        frame_duration_history_.Append(
            fence_signaled_time - pending_frame.start_ns);
      }
      pending_frames_.PopFront();
    } else {
      if (errno != ETIME) {
        ALOGE("sync_wait on frame fence failed. fence=%d errno=%d (%s).",
              fence, errno, strerror(errno));
      }
      break;
    }
  }
}

int FrameHistory::PredictNextFrameVsyncInterval(int64_t vsync_period_ns) const {
  if (frame_duration_history_.IsEmpty())
    return kDefaultVsyncIntervalPrediction;

  double total = 0;
  for (size_t i = 0; i < frame_duration_history_.GetSize(); ++i)
    total += frame_duration_history_.Get(i);
  double avg_duration = total / frame_duration_history_.GetSize();

  return std::min(kMaxVsyncIntervalPrediction,
                  static_cast<int>(avg_duration / vsync_period_ns) + 1);
}

int FrameHistory::GetPreviousFrameResults(DvrFrameScheduleResult* results,
                                          int in_result_count) {
  int out_result_count =
      std::min(in_result_count, static_cast<int>(finished_frames_.GetSize()));
  for (int i = 0; i < out_result_count; ++i) {
    results[i] = finished_frames_.Get(0);
    finished_frames_.PopFront();
  }
  return out_result_count;
}

uint32_t FrameHistory::GetCurrentFrameVsync() const {
  return pending_frames_.IsEmpty() ?
      UINT32_MAX : pending_frames_.Back().scheduled_vsync;
}

}  // namespace dvr
}  // namespace android
+0 −39
Original line number Diff line number Diff line
#include "include/private/dvr/gl_fenced_flush.h"

#include <EGL/eglext.h>
#include <GLES3/gl31.h>

#define ATRACE_TAG ATRACE_TAG_GRAPHICS
#include <utils/Trace.h>

#include <log/log.h>

using android::pdx::LocalHandle;

namespace android {
namespace dvr {

LocalHandle CreateGLSyncAndFlush(EGLDisplay display) {
  ATRACE_NAME("CreateGLSyncAndFlush");

  EGLint attribs[] = {EGL_SYNC_NATIVE_FENCE_FD_ANDROID,
                      EGL_NO_NATIVE_FENCE_FD_ANDROID, EGL_NONE};
  EGLSyncKHR sync_point =
      eglCreateSyncKHR(display, EGL_SYNC_NATIVE_FENCE_ANDROID, attribs);
  glFlush();
  if (sync_point == EGL_NO_SYNC_KHR) {
    ALOGE("sync_point == EGL_NO_SYNC_KHR");
    return LocalHandle();
  }
  EGLint fence_fd = eglDupNativeFenceFDANDROID(display, sync_point);
  eglDestroySyncKHR(display, sync_point);

  if (fence_fd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
    ALOGE("fence_fd == EGL_NO_NATIVE_FENCE_FD_ANDROID");
    return LocalHandle();
  }
  return LocalHandle(fence_fd);
}

}  // namespace dvr
}  // namespace android
Loading