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