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 35b1e2f8deb38353e4bcc9d3ef06bc15bd5e417425Jorim JaggiDisplayEventReceiver::DisplayEventReceiver(ISurfaceComposer::VsyncSource vsyncSource) { 36d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian sp<ISurfaceComposer> sf(ComposerService::getComposerService()); 37d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian if (sf != NULL) { 38b1e2f8deb38353e4bcc9d3ef06bc15bd5e417425Jorim Jaggi mEventConnection = sf->createDisplayEventConnection(vsyncSource); 39d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian if (mEventConnection != NULL) { 406b698e4fe4ff50dcef818452283637f9870ae770Dan Stoza mDataChannel = std::make_unique<gui::BitTube>(); 416b698e4fe4ff50dcef818452283637f9870ae770Dan Stoza mEventConnection->stealReceiveChannel(mDataChannel.get()); 42d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian } 43d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian } 44d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 45d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 46d0566bc26fcf6ca396118701fa11900b627f2c09Mathias AgopianDisplayEventReceiver::~DisplayEventReceiver() { 47d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 48d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 49d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianstatus_t DisplayEventReceiver::initCheck() const { 50d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian if (mDataChannel != NULL) 51d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return NO_ERROR; 52d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return NO_INIT; 53d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 54d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 55d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianint DisplayEventReceiver::getFd() const { 56d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian if (mDataChannel == NULL) 57d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return NO_INIT; 58d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 59d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return mDataChannel->getFd(); 60d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 61d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 62478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopianstatus_t DisplayEventReceiver::setVsyncRate(uint32_t count) { 63478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian if (int32_t(count) < 0) 64478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return BAD_VALUE; 65478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 66478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian if (mEventConnection != NULL) { 67478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian mEventConnection->setVsyncRate(count); 68478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_ERROR; 69478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian } 70478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_INIT; 71478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian} 72478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 73478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopianstatus_t DisplayEventReceiver::requestNextVsync() { 74478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian if (mEventConnection != NULL) { 75478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian mEventConnection->requestNextVsync(); 76478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_ERROR; 77478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian } 78478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_INIT; 79478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian} 80478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 81478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 82d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events, 83d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian size_t count) { 846b698e4fe4ff50dcef818452283637f9870ae770Dan Stoza return DisplayEventReceiver::getEvents(mDataChannel.get(), events, count); 8599ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian} 8699ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian 876b698e4fe4ff50dcef818452283637f9870ae770Dan Stozassize_t DisplayEventReceiver::getEvents(gui::BitTube* dataChannel, 8899ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian Event* events, size_t count) 8999ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian{ 9027c8115510cebda13cbe24fd4caa946ea9c5003cDan Stoza return gui::BitTube::recvObjects(dataChannel, events, count); 917b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian} 927b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian 936b698e4fe4ff50dcef818452283637f9870ae770Dan Stozassize_t DisplayEventReceiver::sendEvents(gui::BitTube* dataChannel, 947b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian Event const* events, size_t count) 957b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian{ 9627c8115510cebda13cbe24fd4caa946ea9c5003cDan Stoza return gui::BitTube::sendObjects(dataChannel, events, count); 97d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 98d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 99d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// --------------------------------------------------------------------------- 100d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 101d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}; // namespace android 102