| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2011 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 <string.h> | 
|  | 18 |  | 
|  | 19 | #include <utils/Errors.h> | 
|  | 20 |  | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 21 | #include <gui/DisplayEventReceiver.h> | 
|  | 22 | #include <gui/IDisplayEventConnection.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 23 | #include <gui/ISurfaceComposer.h> | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 24 |  | 
|  | 25 | #include <private/gui/ComposerService.h> | 
|  | 26 |  | 
| Mathias Agopian | 801ea09 | 2017-03-06 15:05:04 -0800 | [diff] [blame] | 27 | #include <private/gui/BitTube.h> | 
|  | 28 |  | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 29 | // --------------------------------------------------------------------------- | 
|  | 30 |  | 
|  | 31 | namespace android { | 
|  | 32 |  | 
|  | 33 | // --------------------------------------------------------------------------- | 
|  | 34 |  | 
| Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 35 | DisplayEventReceiver::DisplayEventReceiver(ISurfaceComposer::VsyncSource vsyncSource, | 
|  | 36 | ISurfaceComposer::ConfigChanged configChanged) { | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 37 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 38 | if (sf != nullptr) { | 
| Ady Abraham | 0f4a1b1 | 2019-06-04 16:04:04 -0700 | [diff] [blame] | 39 | mEventConnection = sf->createDisplayEventConnection(vsyncSource, configChanged); | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 40 | if (mEventConnection != nullptr) { | 
| Dan Stoza | 6b698e4 | 2017-04-03 13:09:08 -0700 | [diff] [blame] | 41 | mDataChannel = std::make_unique<gui::BitTube>(); | 
|  | 42 | mEventConnection->stealReceiveChannel(mDataChannel.get()); | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 43 | } | 
|  | 44 | } | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | DisplayEventReceiver::~DisplayEventReceiver() { | 
|  | 48 | } | 
|  | 49 |  | 
|  | 50 | status_t DisplayEventReceiver::initCheck() const { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 51 | if (mDataChannel != nullptr) | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 52 | return NO_ERROR; | 
|  | 53 | return NO_INIT; | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | int DisplayEventReceiver::getFd() const { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 57 | if (mDataChannel == nullptr) | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 58 | return NO_INIT; | 
|  | 59 |  | 
|  | 60 | return mDataChannel->getFd(); | 
|  | 61 | } | 
|  | 62 |  | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 63 | status_t DisplayEventReceiver::setVsyncRate(uint32_t count) { | 
|  | 64 | if (int32_t(count) < 0) | 
|  | 65 | return BAD_VALUE; | 
|  | 66 |  | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 67 | if (mEventConnection != nullptr) { | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 68 | mEventConnection->setVsyncRate(count); | 
|  | 69 | return NO_ERROR; | 
|  | 70 | } | 
|  | 71 | return NO_INIT; | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | status_t DisplayEventReceiver::requestNextVsync() { | 
| Yi Kong | 48a619f | 2018-06-05 16:34:59 -0700 | [diff] [blame] | 75 | if (mEventConnection != nullptr) { | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 76 | mEventConnection->requestNextVsync(); | 
|  | 77 | return NO_ERROR; | 
|  | 78 | } | 
|  | 79 | return NO_INIT; | 
|  | 80 | } | 
|  | 81 |  | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 82 | ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events, | 
|  | 83 | size_t count) { | 
| Dan Stoza | 6b698e4 | 2017-04-03 13:09:08 -0700 | [diff] [blame] | 84 | return DisplayEventReceiver::getEvents(mDataChannel.get(), events, count); | 
| Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 85 | } | 
|  | 86 |  | 
| Dan Stoza | 6b698e4 | 2017-04-03 13:09:08 -0700 | [diff] [blame] | 87 | ssize_t DisplayEventReceiver::getEvents(gui::BitTube* dataChannel, | 
| Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 88 | Event* events, size_t count) | 
|  | 89 | { | 
| Dan Stoza | 27c8115 | 2017-03-31 16:30:42 -0700 | [diff] [blame] | 90 | return gui::BitTube::recvObjects(dataChannel, events, count); | 
| Mathias Agopian | 7b5be95 | 2012-04-02 17:02:19 -0700 | [diff] [blame] | 91 | } | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 92 |  | 
| Alec Mouri | c080030 | 2020-08-05 12:50:03 -0700 | [diff] [blame] | 93 | ssize_t DisplayEventReceiver::sendEvents(Event const* events, size_t count) { | 
|  | 94 | return DisplayEventReceiver::sendEvents(mDataChannel.get(), events, count); | 
|  | 95 | } | 
|  | 96 |  | 
| Dan Stoza | 6b698e4 | 2017-04-03 13:09:08 -0700 | [diff] [blame] | 97 | ssize_t DisplayEventReceiver::sendEvents(gui::BitTube* dataChannel, | 
| Mathias Agopian | 7b5be95 | 2012-04-02 17:02:19 -0700 | [diff] [blame] | 98 | Event const* events, size_t count) | 
|  | 99 | { | 
| Dan Stoza | 27c8115 | 2017-03-31 16:30:42 -0700 | [diff] [blame] | 100 | return gui::BitTube::sendObjects(dataChannel, events, count); | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 101 | } | 
|  | 102 |  | 
|  | 103 | // --------------------------------------------------------------------------- | 
|  | 104 |  | 
|  | 105 | }; // namespace android |