sdm: Enhance fence utility class
- Add scope reference for client to access native fd associated
with fence in limited scope.
- Assert if buffer sync handler is not set by the client.
- Add sync status enumeration.
CRs-Fixed: 2579548
Change-Id: Id91826cd9e2be5bcffd82fcc4a66f551fcdda70b
diff --git a/sdm/include/utils/fence.h b/sdm/include/utils/fence.h
index 94bb01b..acc381f 100644
--- a/sdm/include/utils/fence.h
+++ b/sdm/include/utils/fence.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2019, The Linux Foundation. All rights reserved.
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -35,6 +35,7 @@
#include <utility>
#include <memory>
#include <string>
+#include <vector>
namespace sdm {
@@ -43,8 +44,27 @@
class Fence {
public:
+ enum class Status : int32_t {
+ kSignaled = 0,
+ kPending
+ };
+
+ // This class methods allow client to get access to the native file descriptor of fence object
+ // during the scope of this class object. Underlying file descriptor is duped and returned to
+ // the client. Duped file descriptors are closed as soon as scope ends. Client can get access
+ // to multiple fences using the same scoped reference.
+ class ScopedRef {
+ public:
+ ~ScopedRef();
+ int Get(const shared_ptr<Fence> &fence);
+
+ private:
+ std::vector<int> dup_fds_ = {};
+ };
+
~Fence();
+ // Must be set once before using any other method of this class.
static void Set(BufferSyncHandler *buffer_sync_handler);
// Ownership of the file descriptor is transferred to this method.
@@ -56,8 +76,14 @@
static int Dup(const shared_ptr<Fence> &fence);
static shared_ptr<Fence> Merge(const shared_ptr<Fence> &fence1, const shared_ptr<Fence> &fence2);
+
+ // Wait on null fence will return success.
static DisplayError Wait(const shared_ptr<Fence> &fence);
static DisplayError Wait(const shared_ptr<Fence> &fence, int timeout);
+
+ // Status check on null fence will return signaled.
+ static Status GetStatus(const shared_ptr<Fence> &fence);
+
static string GetStr(const shared_ptr<Fence> &fence);
private: