1 #include "include/dvr/dvr_api.h"
2 
3 #include <errno.h>
4 #include <utils/Log.h>
5 
6 #include <algorithm>
7 
8 // Headers from libdvr
9 #include <dvr/dvr_buffer.h>
10 #include <dvr/dvr_buffer_queue.h>
11 #include <dvr/dvr_configuration_data.h>
12 #include <dvr/dvr_display_manager.h>
13 #include <dvr/dvr_performance.h>
14 #include <dvr/dvr_surface.h>
15 #include <dvr/dvr_vsync.h>
16 
17 // Headers not yet moved into libdvr.
18 // TODO(jwcai) Move these once their callers are moved into Google3.
19 #include <dvr/dvr_hardware_composer_client.h>
20 #include <dvr/pose_client.h>
21 #include <dvr/virtual_touchpad_client.h>
22 
23 extern "C" {
24 
dvrGetApi(void * api,size_t struct_size,int version)25 int dvrGetApi(void* api, size_t struct_size, int version) {
26   ALOGI("dvrGetApi: api=%p struct_size=%zu version=%d", api, struct_size,
27         version);
28   if (version == 1) {
29     // New entry points are added at the end. If the caller's struct and
30     // this library have different sizes, we define the entry points in common.
31     // The caller is expected to handle unset entry points if necessary.
32     size_t clamped_struct_size = std::min(struct_size, sizeof(DvrApi_v1));
33     DvrApi_v1* dvr_api = static_cast<DvrApi_v1*>(api);
34 
35 // Defines an API entry for V1 (no version suffix).
36 #define DVR_V1_API_ENTRY(name)                                 \
37   do {                                                         \
38     if ((offsetof(DvrApi_v1, name) + sizeof(dvr_api->name)) <= \
39         clamped_struct_size) {                                 \
40       dvr_api->name = dvr##name;                               \
41     }                                                          \
42   } while (0)
43 
44 #define DVR_V1_API_ENTRY_DEPRECATED(name)                      \
45   do {                                                         \
46     if ((offsetof(DvrApi_v1, name) + sizeof(dvr_api->name)) <= \
47         clamped_struct_size) {                                 \
48       dvr_api->name = nullptr;                                 \
49     }                                                          \
50   } while (0)
51 
52 #include "include/dvr/dvr_api_entries.h"
53 
54 // Undefine macro definitions to play nice with Google3 style rules.
55 #undef DVR_V1_API_ENTRY
56 #undef DVR_V1_API_ENTRY_DEPRECATED
57 
58     return 0;
59   }
60 
61   ALOGE("dvrGetApi: Unknown API version=%d", version);
62   return -EINVAL;
63 }
64 
65 }  // extern "C"
66