Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Ady Abraham | 2a6c186 | 2022-07-28 22:54:19 +0000 | [diff] [blame] | 21 | // This file is included by modules that have host support but android/looper.h is not supported |
| 22 | // on host. __REMOVED_IN needs to be defined in order for android/looper.h to be compiled. |
| 23 | #ifndef __BIONIC__ |
| 24 | #define __REMOVED_IN(x) __attribute__((deprecated)) |
| 25 | #endif |
Nanik Tolaram | 5b06dc0 | 2015-02-14 11:32:46 +1100 | [diff] [blame] | 26 | #include <android/looper.h> |
Ady Abraham | 2a6c186 | 2022-07-28 22:54:19 +0000 | [diff] [blame] | 27 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 28 | #include <gui/DisplayEventReceiver.h> |
| 29 | #include <utils/Looper.h> |
| 30 | |
| 31 | using namespace android; |
| 32 | |
Dan Stoza | a282f58 | 2017-03-28 11:28:50 -0700 | [diff] [blame] | 33 | int receiver(int /*fd*/, int /*events*/, void* data) |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 34 | { |
| 35 | DisplayEventReceiver* q = (DisplayEventReceiver*)data; |
| 36 | |
| 37 | ssize_t n; |
| 38 | DisplayEventReceiver::Event buffer[1]; |
| 39 | |
| 40 | static nsecs_t oldTimeStamp = 0; |
| 41 | |
| 42 | while ((n = q->getEvents(buffer, 1)) > 0) { |
| 43 | for (int i=0 ; i<n ; i++) { |
| 44 | if (buffer[i].header.type == DisplayEventReceiver::DISPLAY_EVENT_VSYNC) { |
| 45 | printf("event vsync: count=%d\t", buffer[i].vsync.count); |
| 46 | } |
| 47 | if (oldTimeStamp) { |
| 48 | float t = float(buffer[i].header.timestamp - oldTimeStamp) / s2ns(1); |
| 49 | printf("%f ms (%f Hz)\n", t*1000, 1.0/t); |
| 50 | } |
| 51 | oldTimeStamp = buffer[i].header.timestamp; |
| 52 | } |
| 53 | } |
| 54 | if (n<0) { |
| 55 | printf("error reading events (%s)\n", strerror(-n)); |
| 56 | } |
| 57 | return 1; |
| 58 | } |
| 59 | |
Dan Stoza | a282f58 | 2017-03-28 11:28:50 -0700 | [diff] [blame] | 60 | int main(int /*argc*/, char** /*argv*/) |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 61 | { |
| 62 | DisplayEventReceiver myDisplayEvent; |
| 63 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 64 | sp<Looper> loop = sp<Looper>::make(false); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 65 | loop->addFd(myDisplayEvent.getFd(), 0, ALOOPER_EVENT_INPUT, receiver, |
| 66 | &myDisplayEvent); |
| 67 | |
Mathias Agopian | 3cf199a | 2012-01-31 16:42:54 -0800 | [diff] [blame] | 68 | myDisplayEvent.setVsyncRate(1); |
| 69 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 70 | do { |
| 71 | //printf("about to poll...\n"); |
| 72 | int32_t ret = loop->pollOnce(-1); |
| 73 | switch (ret) { |
| 74 | case ALOOPER_POLL_WAKE: |
| 75 | //("ALOOPER_POLL_WAKE\n"); |
| 76 | break; |
| 77 | case ALOOPER_POLL_CALLBACK: |
| 78 | //("ALOOPER_POLL_CALLBACK\n"); |
| 79 | break; |
| 80 | case ALOOPER_POLL_TIMEOUT: |
| 81 | printf("ALOOPER_POLL_TIMEOUT\n"); |
| 82 | break; |
| 83 | case ALOOPER_POLL_ERROR: |
| 84 | printf("ALOOPER_POLL_TIMEOUT\n"); |
| 85 | break; |
| 86 | default: |
| 87 | printf("ugh? poll returned %d\n", ret); |
| 88 | break; |
| 89 | } |
| 90 | } while (1); |
| 91 | |
| 92 | return 0; |
| 93 | } |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 94 | |
| 95 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 96 | #pragma clang diagnostic pop // ignored "-Wconversion" |