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