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 #include "include/dvr/dvr_api_entries.h"
45
46 // Undefine macro definitions to play nice with Google3 style rules.
47 #undef DVR_V1_API_ENTRY
48
49 return 0;
50 }
51
52 ALOGE("dvrGetApi: Unknown API version=%d", version);
53 return -EINVAL;
54 }
55
56 } // extern "C"
57