blob: a1b45e6adb45f1090261546dd1ba70ed3f4dd75e [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
Nanik Tolaram5b06dc02015-02-14 11:32:46 +110017#include <android/looper.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080018#include <gui/DisplayEventReceiver.h>
19#include <utils/Looper.h>
20
21using namespace android;
22
Dan Stozaa282f582017-03-28 11:28:50 -070023int receiver(int /*fd*/, int /*events*/, void* data)
Mathias Agopiand0566bc2011-11-17 17:49:17 -080024{
25 DisplayEventReceiver* q = (DisplayEventReceiver*)data;
26
27 ssize_t n;
28 DisplayEventReceiver::Event buffer[1];
29
30 static nsecs_t oldTimeStamp = 0;
31
32 while ((n = q->getEvents(buffer, 1)) > 0) {
33 for (int i=0 ; i<n ; i++) {
34 if (buffer[i].header.type == DisplayEventReceiver::DISPLAY_EVENT_VSYNC) {
35 printf("event vsync: count=%d\t", buffer[i].vsync.count);
36 }
37 if (oldTimeStamp) {
38 float t = float(buffer[i].header.timestamp - oldTimeStamp) / s2ns(1);
39 printf("%f ms (%f Hz)\n", t*1000, 1.0/t);
40 }
41 oldTimeStamp = buffer[i].header.timestamp;
42 }
43 }
44 if (n<0) {
45 printf("error reading events (%s)\n", strerror(-n));
46 }
47 return 1;
48}
49
Dan Stozaa282f582017-03-28 11:28:50 -070050int main(int /*argc*/, char** /*argv*/)
Mathias Agopiand0566bc2011-11-17 17:49:17 -080051{
52 DisplayEventReceiver myDisplayEvent;
53
54
55 sp<Looper> loop = new Looper(false);
56 loop->addFd(myDisplayEvent.getFd(), 0, ALOOPER_EVENT_INPUT, receiver,
57 &myDisplayEvent);
58
Mathias Agopian3cf199a2012-01-31 16:42:54 -080059 myDisplayEvent.setVsyncRate(1);
60
Mathias Agopiand0566bc2011-11-17 17:49:17 -080061 do {
62 //printf("about to poll...\n");
63 int32_t ret = loop->pollOnce(-1);
64 switch (ret) {
65 case ALOOPER_POLL_WAKE:
66 //("ALOOPER_POLL_WAKE\n");
67 break;
68 case ALOOPER_POLL_CALLBACK:
69 //("ALOOPER_POLL_CALLBACK\n");
70 break;
71 case ALOOPER_POLL_TIMEOUT:
72 printf("ALOOPER_POLL_TIMEOUT\n");
73 break;
74 case ALOOPER_POLL_ERROR:
75 printf("ALOOPER_POLL_TIMEOUT\n");
76 break;
77 default:
78 printf("ugh? poll returned %d\n", ret);
79 break;
80 }
81 } while (1);
82
83 return 0;
84}