1 #ifndef ANDROID_DVR_SURFACE_H_
2 #define ANDROID_DVR_SURFACE_H_
3 
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <stdint.h>
7 #include <sys/cdefs.h>
8 
9 #include <dvr/dvr_api.h>
10 #include <dvr/dvr_buffer.h>
11 #include <dvr/dvr_buffer_queue.h>
12 #include <dvr/dvr_display_types.h>
13 
14 __BEGIN_DECLS
15 
16 // Attribute types. The values are one-hot encoded to support singluar types or
17 // masks of supported types.
18 enum {
19   DVR_SURFACE_ATTRIBUTE_TYPE_NONE = 0,
20   DVR_SURFACE_ATTRIBUTE_TYPE_INT32 = (1 << 0),
21   DVR_SURFACE_ATTRIBUTE_TYPE_INT64 = (1 << 1),
22   DVR_SURFACE_ATTRIBUTE_TYPE_BOOL = (1 << 2),
23   DVR_SURFACE_ATTRIBUTE_TYPE_FLOAT = (1 << 3),
24   DVR_SURFACE_ATTRIBUTE_TYPE_FLOAT2 = (1 << 4),
25   DVR_SURFACE_ATTRIBUTE_TYPE_FLOAT3 = (1 << 5),
26   DVR_SURFACE_ATTRIBUTE_TYPE_FLOAT4 = (1 << 6),
27   DVR_SURFACE_ATTRIBUTE_TYPE_FLOAT8 = (1 << 7),
28   DVR_SURFACE_ATTRIBUTE_TYPE_FLOAT16 = (1 << 8),
29 };
30 
31 typedef uint64_t DvrSurfaceAttributeType;
32 typedef int32_t DvrSurfaceAttributeKey;
33 
34 typedef struct DvrSurfaceAttributeValue {
35   DvrSurfaceAttributeType type;
36   union {
37     int32_t int32_value;
38     int64_t int64_value;
39     bool bool_value;
40     float float_value;
41     float float2_value[2];
42     float float3_value[3];
43     float float4_value[4];
44     float float8_value[8];
45     float float16_value[16];
46   };
47 } DvrSurfaceAttributeValue;
48 
49 typedef struct DvrSurfaceAttribute {
50   DvrSurfaceAttributeKey key;
51   DvrSurfaceAttributeValue value;
52 } DvrSurfaceAttribute;
53 
54 // Creates a new display surface with the given attributes.
55 // @return 0 on success. Otherwise returns a negative error value.
56 int dvrSurfaceCreate(const DvrSurfaceAttribute* attributes,
57                      size_t attribute_count, DvrSurface** surface_out);
58 
59 // Destroys the display surface.
60 void dvrSurfaceDestroy(DvrSurface* surface);
61 
62 // Gets the DisplayService global id for this surface.
63 int dvrSurfaceGetId(DvrSurface* surface);
64 
65 // Sets attributes on the given display surface.
66 // @return 0 on success. Otherwise returns a negative error value.
67 int dvrSurfaceSetAttributes(DvrSurface* surface,
68                             const DvrSurfaceAttribute* attributes,
69                             size_t attribute_count);
70 
71 // Creates a new write-side buffer queue on the given surface. Direct surfaces
72 // may only have one queue, the latest call replacing any prior queue. Replaced
73 // queues are still referenced and should be destryoed using the queue destroy
74 // API.
75 // @return 0 on success. Otherwise returns a negative error value.
76 int dvrSurfaceCreateWriteBufferQueue(DvrSurface* surface, uint32_t width,
77                                      uint32_t height, uint32_t format,
78                                      uint32_t layer_count, uint64_t usage,
79                                      size_t capacity, size_t metadata_size,
80                                      DvrWriteBufferQueue** queue_out);
81 
82 // Sets up a named buffer for shared memory data transfer between display
83 // clients and the system. Protected API that may only be called with sufficient
84 // privilege.
85 // @return 0 on success. Otherwise returns a negative error value.
86 int dvrSetupGlobalBuffer(DvrGlobalBufferKey key, size_t size, uint64_t usage,
87                          DvrBuffer** buffer_out);
88 
89 // Deletes a named buffer. WARNING: This is dangerous because any existing
90 // clients of this buffer will not be notified and will remain attached to
91 // the old buffer. This is useful for tests, but probably not for production
92 // code.
93 // @return 0 on success. Otherwise returns a negative error value.
94 int dvrDeleteGlobalBuffer(DvrGlobalBufferKey key);
95 
96 // Get a global buffer from the display service.
97 // @return 0 on success. Otherwise returns a negative error value.
98 int dvrGetGlobalBuffer(DvrGlobalBufferKey key, DvrBuffer** out_buffer);
99 
100 // Read the native device display metrics as reported by the hardware composer.
101 // This is useful as otherwise the device metrics are only reported as
102 // relative to the current device orientation.
103 // @param sizeof_metrics the size of the passed in metrics struct. This is used
104 //   to ensure we don't break each other during active development.
105 // @param metrics on success holds the retrieved device metrics.
106 // @return 0 on success. Otherwise returns a negative error value (typically
107 //   this means the display service is not available).
108 int dvrGetNativeDisplayMetrics(size_t metrics_struct_size,
109                                DvrNativeDisplayMetrics* metrics);
110 
111 __END_DECLS
112 
113 #endif  // ANDROID_DVR_SURFACE_H_
114