interfaceIDisplayEventConnection{/*
* stealReceiveChannel() returns a BitTube to receive events from. Only the receive file
* descriptor of outChannel will be initialized, and this effectively "steals" the receive
* channel from the remote end (such that the remote end can only use its send channel).
*/voidstealReceiveChannel(outBitTubeoutChannel);/*
* setVsyncRate() sets the vsync event delivery rate. A value of 1 returns every vsync event.
* A value of 2 returns every other event, etc. A value of 0 returns no event unless
* requestNextVsync() has been called.
*/voidsetVsyncRate(inintcount);/*
* requestNextVsync() schedules the next vsync event. It has no effect if the vsync rate is > 0.
*/onewayvoidrequestNextVsync();// Asynchronous
/*
* getLatestVsyncEventData() gets the latest vsync event data.
*/ParcelableVsyncEventDatagetLatestVsyncEventData();}
publicFrameDisplayEventReceiver(Looperlooper,intvsyncSource){super(looper,vsyncSource,0);//直接调用了父类的构造
}/**
* Creates a display event receiver.
*
* @param looper The looper to use when invoking callbacks.
* @param vsyncSource The source of the vsync tick. Must be on of the VSYNC_SOURCE_* values.
* @param eventRegistration Which events to dispatch. Must be a bitfield consist of the
* EVENT_REGISTRATION_*_FLAG values.
*/publicDisplayEventReceiver(Looperlooper,intvsyncSource,inteventRegistration){mMessageQueue=looper.getQueue();mReceiverPtr=nativeInit(newWeakReference<DisplayEventReceiver>(this),mMessageQueue,vsyncSource,eventRegistration);}
BitTube::BitTube(size_tbufsize):mSendFd(-1),mReceiveFd(-1){init(bufsize,bufsize);//调用是init方法
}voidBitTube::init(size_trcvbuf,size_tsndbuf){intsockets[2];//其实本质是有一对socketpair
if(socketpair(AF_UNIX,SOCK_SEQPACKET,0,sockets)==0){size_tsize=DEFAULT_SOCKET_BUFFER_SIZE;setsockopt(sockets[0],SOL_SOCKET,SO_RCVBUF,&rcvbuf,sizeof(rcvbuf));setsockopt(sockets[1],SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf));// sine we don't use the "return channel", we keep it small...
setsockopt(sockets[0],SOL_SOCKET,SO_SNDBUF,&size,sizeof(size));setsockopt(sockets[1],SOL_SOCKET,SO_RCVBUF,&size,sizeof(size));fcntl(sockets[0],F_SETFL,O_NONBLOCK);fcntl(sockets[1],F_SETFL,O_NONBLOCK);mReceiveFd=sockets[0];mSendFd=sockets[1];}else{mReceiveFd=-errno;ALOGE("BitTube: pipe creation failed (%s)",strerror(-mReceiveFd));}}