DisplayEventReceiver.cpp revision 27c8115510cebda13cbe24fd4caa946ea9c5003c
1d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian/* 2d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * Copyright (C) 2011 The Android Open Source Project 3d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * 4d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * you may not use this file except in compliance with the License. 6d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * You may obtain a copy of the License at 7d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * 8d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * 10d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * Unless required by applicable law or agreed to in writing, software 11d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * See the License for the specific language governing permissions and 14d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * limitations under the License. 15d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian */ 16d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 17d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <string.h> 18d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 19d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <utils/Errors.h> 20d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 21d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <gui/DisplayEventReceiver.h> 22d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <gui/IDisplayEventConnection.h> 2390ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#include <gui/ISurfaceComposer.h> 24d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 25d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <private/gui/ComposerService.h> 26d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 27801ea093b0e923a61b832f2adba698a273479880Mathias Agopian#include <private/gui/BitTube.h> 28801ea093b0e923a61b832f2adba698a273479880Mathias Agopian 29d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// --------------------------------------------------------------------------- 30d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 31d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopiannamespace android { 32d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 33d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// --------------------------------------------------------------------------- 34d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 35d0566bc26fcf6ca396118701fa11900b627f2c09Mathias AgopianDisplayEventReceiver::DisplayEventReceiver() { 36d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian sp<ISurfaceComposer> sf(ComposerService::getComposerService()); 37d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian if (sf != NULL) { 38d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian mEventConnection = sf->createDisplayEventConnection(); 39d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian if (mEventConnection != NULL) { 40e1c599b52fcce94bd27ebbc4d74cd59c9e71b452Dan Stoza mEventConnection->getDataChannel(&mDataChannel); 41d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian } 42d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian } 43d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 44d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 45d0566bc26fcf6ca396118701fa11900b627f2c09Mathias AgopianDisplayEventReceiver::~DisplayEventReceiver() { 46d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 47d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 48d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianstatus_t DisplayEventReceiver::initCheck() const { 49d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian if (mDataChannel != NULL) 50d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return NO_ERROR; 51d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return NO_INIT; 52d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 53d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 54d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianint DisplayEventReceiver::getFd() const { 55d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian if (mDataChannel == NULL) 56d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return NO_INIT; 57d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 58d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return mDataChannel->getFd(); 59d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 60d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 61478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopianstatus_t DisplayEventReceiver::setVsyncRate(uint32_t count) { 62478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian if (int32_t(count) < 0) 63478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return BAD_VALUE; 64478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 65478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian if (mEventConnection != NULL) { 66478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian mEventConnection->setVsyncRate(count); 67478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_ERROR; 68478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian } 69478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_INIT; 70478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian} 71478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 72478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopianstatus_t DisplayEventReceiver::requestNextVsync() { 73478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian if (mEventConnection != NULL) { 74478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian mEventConnection->requestNextVsync(); 75478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_ERROR; 76478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian } 77478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_INIT; 78478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian} 79478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 80478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 81d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events, 82d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian size_t count) { 8399ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian return DisplayEventReceiver::getEvents(mDataChannel, events, count); 8499ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian} 8599ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian 8627c8115510cebda13cbe24fd4caa946ea9c5003cDan Stozassize_t DisplayEventReceiver::getEvents(const sp<gui::BitTube>& dataChannel, 8799ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian Event* events, size_t count) 8899ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian{ 8927c8115510cebda13cbe24fd4caa946ea9c5003cDan Stoza return gui::BitTube::recvObjects(dataChannel, events, count); 907b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian} 917b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian 9227c8115510cebda13cbe24fd4caa946ea9c5003cDan Stozassize_t DisplayEventReceiver::sendEvents(const sp<gui::BitTube>& dataChannel, 937b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian Event const* events, size_t count) 947b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian{ 9527c8115510cebda13cbe24fd4caa946ea9c5003cDan Stoza return gui::BitTube::sendObjects(dataChannel, events, count); 96d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 97d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 98d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// --------------------------------------------------------------------------- 99d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 100d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}; // namespace android 101