Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 1 | #include "include/dvr/dvr_api.h" |
| 2 | |
| 3 | #include <errno.h> |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 4 | #include <utils/Log.h> |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 5 | |
Kevin Schoedel | d8fccf0 | 2017-06-05 11:13:20 -0400 | [diff] [blame] | 6 | #include <algorithm> |
| 7 | |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 8 | // Headers from libdvr |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 9 | #include <dvr/dvr_buffer.h> |
Jiwen 'Steve' Cai | 2d82ceb | 2017-03-22 17:26:00 -0700 | [diff] [blame] | 10 | #include <dvr/dvr_buffer_queue.h> |
Hendrik Wagenaar | bcb03d0 | 2017-05-23 14:59:08 -0700 | [diff] [blame] | 11 | #include <dvr/dvr_configuration_data.h> |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 12 | #include <dvr/dvr_display_manager.h> |
Corey Tabaka | feb636d | 2017-06-23 16:20:07 -0700 | [diff] [blame] | 13 | #include <dvr/dvr_performance.h> |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 14 | #include <dvr/dvr_surface.h> |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 15 | #include <dvr/dvr_vsync.h> |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 16 | |
| 17 | // Headers not yet moved into libdvr. |
| 18 | // TODO(jwcai) Move these once their callers are moved into Google3. |
Daniel Nicoara | 37cdc8d | 2017-03-27 16:56:05 -0400 | [diff] [blame] | 19 | #include <dvr/dvr_hardware_composer_client.h> |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 20 | #include <dvr/pose_client.h> |
| 21 | #include <dvr/virtual_touchpad_client.h> |
| 22 | |
| 23 | extern "C" { |
| 24 | |
Steven Thomas | 3be0aa6 | 2017-05-08 15:45:30 -0700 | [diff] [blame] | 25 | int dvrGetApi(void* api, size_t struct_size, int version) { |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 26 | ALOGI("dvrGetApi: api=%p struct_size=%zu version=%d", api, struct_size, |
| 27 | version); |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 28 | if (version == 1) { |
Kevin Schoedel | d8fccf0 | 2017-06-05 11:13:20 -0400 | [diff] [blame] | 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)); |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 33 | DvrApi_v1* dvr_api = static_cast<DvrApi_v1*>(api); |
| 34 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 35 | // Defines an API entry for V1 (no version suffix). |
Kevin Schoedel | d8fccf0 | 2017-06-05 11:13:20 -0400 | [diff] [blame] | 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) |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 43 | |
Jiwen 'Steve' Cai | 0262d60 | 2018-04-10 17:26:50 -0700 | [diff] [blame] | 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 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 52 | #include "include/dvr/dvr_api_entries.h" |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 53 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 54 | // Undefine macro definitions to play nice with Google3 style rules. |
| 55 | #undef DVR_V1_API_ENTRY |
Jiwen 'Steve' Cai | 0262d60 | 2018-04-10 17:26:50 -0700 | [diff] [blame] | 56 | #undef DVR_V1_API_ENTRY_DEPRECATED |
Daniel Nicoara | 37cdc8d | 2017-03-27 16:56:05 -0400 | [diff] [blame] | 57 | |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 58 | return 0; |
| 59 | } |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 60 | |
| 61 | ALOGE("dvrGetApi: Unknown API version=%d", version); |
Jiwen 'Steve' Cai | bdcee79 | 2017-03-22 16:59:53 -0700 | [diff] [blame] | 62 | return -EINVAL; |
| 63 | } |
| 64 | |
| 65 | } // extern "C" |