blob: 9fcce32c38c985f503c4821777a5b09e4a36abd8 [file] [log] [blame]
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001/*
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 Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Ady Abraham2a6c1862022-07-28 22:54:19 +000021// 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 Tolaram5b06dc02015-02-14 11:32:46 +110026#include <android/looper.h>
Ady Abraham2a6c1862022-07-28 22:54:19 +000027
Mathias Agopiand0566bc2011-11-17 17:49:17 -080028#include <gui/DisplayEventReceiver.h>
29#include <utils/Looper.h>
30
31using namespace android;
32
Dan Stozaa282f582017-03-28 11:28:50 -070033int receiver(int /*fd*/, int /*events*/, void* data)
Mathias Agopiand0566bc2011-11-17 17:49:17 -080034{
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 Stozaa282f582017-03-28 11:28:50 -070060int main(int /*argc*/, char** /*argv*/)
Mathias Agopiand0566bc2011-11-17 17:49:17 -080061{
62 DisplayEventReceiver myDisplayEvent;
63
64
65 sp<Looper> loop = new Looper(false);
66 loop->addFd(myDisplayEvent.getFd(), 0, ALOOPER_EVENT_INPUT, receiver,
67 &myDisplayEvent);
68
Mathias Agopian3cf199a2012-01-31 16:42:54 -080069 myDisplayEvent.setVsyncRate(1);
70
Mathias Agopiand0566bc2011-11-17 17:49:17 -080071 do {
72 //printf("about to poll...\n");
73 int32_t ret = loop->pollOnce(-1);
74 switch (ret) {
75 case ALOOPER_POLL_WAKE:
76 //("ALOOPER_POLL_WAKE\n");
77 break;
78 case ALOOPER_POLL_CALLBACK:
79 //("ALOOPER_POLL_CALLBACK\n");
80 break;
81 case ALOOPER_POLL_TIMEOUT:
82 printf("ALOOPER_POLL_TIMEOUT\n");
83 break;
84 case ALOOPER_POLL_ERROR:
85 printf("ALOOPER_POLL_TIMEOUT\n");
86 break;
87 default:
88 printf("ugh? poll returned %d\n", ret);
89 break;
90 }
91 } while (1);
92
93 return 0;
94}
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080095
96// TODO(b/129481165): remove the #pragma below and fix conversion issues
97#pragma clang diagnostic pop // ignored "-Wconversion"