• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef ANDROID_DVR_DELETER_H_
2 #define ANDROID_DVR_DELETER_H_
3 
4 #include <sys/cdefs.h>
5 
6 #include <memory>
7 
8 // Header-only C++ helper to delete opaque DVR objects.
9 
10 __BEGIN_DECLS
11 
12 // Use forward declarations to avoid dependency on other headers.
13 typedef struct DvrBuffer DvrBuffer;
14 typedef struct DvrReadBuffer DvrReadBuffer;
15 typedef struct DvrWriteBuffer DvrWriteBuffer;
16 typedef struct DvrReadBufferQueue DvrReadBufferQueue;
17 typedef struct DvrWriteBufferQueue DvrWriteBufferQueue;
18 typedef struct DvrDisplayManager DvrDisplayManager;
19 typedef struct DvrSurfaceState DvrSurfaceState;
20 typedef struct DvrSurface DvrSurface;
21 typedef struct DvrHwcClient DvrHwcClient;
22 typedef struct DvrHwcFrame DvrHwcFrame;
23 typedef struct DvrVSyncClient DvrVSyncClient;
24 
25 void dvrBufferDestroy(DvrBuffer* buffer);
26 void dvrReadBufferDestroy(DvrReadBuffer* read_buffer);
27 void dvrWriteBufferDestroy(DvrWriteBuffer* write_buffer);
28 void dvrReadBufferQueueDestroy(DvrReadBufferQueue* read_queue);
29 void dvrWriteBufferQueueDestroy(DvrWriteBufferQueue* write_queue);
30 void dvrDisplayManagerDestroy(DvrDisplayManager* client);
31 void dvrSurfaceStateDestroy(DvrSurfaceState* surface_state);
32 void dvrSurfaceDestroy(DvrSurface* surface);
33 void dvrHwcClientDestroy(DvrHwcClient* client);
34 void dvrHwcFrameDestroy(DvrHwcFrame* frame);
35 void dvrVSyncClientDestroy(DvrVSyncClient* client);
36 
37 __END_DECLS
38 
39 // Avoid errors if this header is included in C code.
40 #if defined(__cplusplus)
41 
42 namespace android {
43 namespace dvr {
44 
45 // Universal DVR object deleter. May be passed to smart pointer types to handle
46 // deletion of DVR API objects.
47 struct DvrObjectDeleter {
operatorDvrObjectDeleter48   void operator()(DvrBuffer* p) { dvrBufferDestroy(p); }
operatorDvrObjectDeleter49   void operator()(DvrReadBuffer* p) { dvrReadBufferDestroy(p); }
operatorDvrObjectDeleter50   void operator()(DvrWriteBuffer* p) { dvrWriteBufferDestroy(p); }
operatorDvrObjectDeleter51   void operator()(DvrReadBufferQueue* p) { dvrReadBufferQueueDestroy(p); }
operatorDvrObjectDeleter52   void operator()(DvrWriteBufferQueue* p) { dvrWriteBufferQueueDestroy(p); }
operatorDvrObjectDeleter53   void operator()(DvrDisplayManager* p) { dvrDisplayManagerDestroy(p); }
operatorDvrObjectDeleter54   void operator()(DvrSurfaceState* p) { dvrSurfaceStateDestroy(p); }
operatorDvrObjectDeleter55   void operator()(DvrSurface* p) { dvrSurfaceDestroy(p); }
operatorDvrObjectDeleter56   void operator()(DvrHwcClient* p) { dvrHwcClientDestroy(p); }
operatorDvrObjectDeleter57   void operator()(DvrHwcFrame* p) { dvrHwcFrameDestroy(p); }
operatorDvrObjectDeleter58   void operator()(DvrVSyncClient* p) { dvrVSyncClientDestroy(p); }
59 };
60 
61 // Helper to define unique pointers for DVR object types.
62 template <typename T>
63 using MakeUniqueDvrPointer = std::unique_ptr<T, DvrObjectDeleter>;
64 
65 // Unique pointer types for DVR objects.
66 using UniqueDvrBuffer = MakeUniqueDvrPointer<DvrBuffer>;
67 using UniqueDvrReadBuffer = MakeUniqueDvrPointer<DvrReadBuffer>;
68 using UniqueDvrWriteBuffer = MakeUniqueDvrPointer<DvrWriteBuffer>;
69 using UniqueDvrReadBufferQueue = MakeUniqueDvrPointer<DvrReadBufferQueue>;
70 using UniqueDvrWriteBufferQueue = MakeUniqueDvrPointer<DvrWriteBufferQueue>;
71 using UniqueDvrDisplayManager = MakeUniqueDvrPointer<DvrDisplayManager>;
72 using UniqueDvrSurfaceState = MakeUniqueDvrPointer<DvrSurfaceState>;
73 using UniqueDvrSurface = MakeUniqueDvrPointer<DvrSurface>;
74 using UniqueDvrHwcClient = MakeUniqueDvrPointer<DvrHwcClient>;
75 using UniqueDvrHwcFrame = MakeUniqueDvrPointer<DvrHwcFrame>;
76 using UniqueDvrVSyncClient = MakeUniqueDvrPointer<DvrVSyncClient>;
77 
78 // TODO(eieio): Add an adapter for std::shared_ptr that injects the deleter into
79 // the relevant constructors.
80 
81 }  // namespace dvr
82 }  // namespace android
83 
84 #endif // defined(__cplusplus)
85 
86 #endif  // ANDROID_DVR_DELETER_H_
87