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 | |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 35 | DisplayEventReceiver::DisplayEventReceiver(ISurfaceComposer::VsyncSource vsyncSource) { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 36 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 37 | if (sf != NULL) { |
Jorim Jaggi | b1e2f8d | 2017-06-08 15:43:59 -0700 | [diff] [blame] | 38 | mEventConnection = sf->createDisplayEventConnection(vsyncSource); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 39 | if (mEventConnection != NULL) { |
Dan Stoza | 6b698e4 | 2017-04-03 13:09:08 -0700 | [diff] [blame] | 40 | mDataChannel = std::make_unique<gui::BitTube>(); |
| 41 | mEventConnection->stealReceiveChannel(mDataChannel.get()); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | DisplayEventReceiver::~DisplayEventReceiver() { |
| 47 | } |
| 48 | |
| 49 | status_t DisplayEventReceiver::initCheck() const { |
| 50 | if (mDataChannel != NULL) |
| 51 | return NO_ERROR; |
| 52 | return NO_INIT; |
| 53 | } |
| 54 | |
| 55 | int DisplayEventReceiver::getFd() const { |
| 56 | if (mDataChannel == NULL) |
| 57 | return NO_INIT; |
| 58 | |
| 59 | return mDataChannel->getFd(); |
| 60 | } |
| 61 | |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 62 | status_t DisplayEventReceiver::setVsyncRate(uint32_t count) { |
| 63 | if (int32_t(count) < 0) |
| 64 | return BAD_VALUE; |
| 65 | |
| 66 | if (mEventConnection != NULL) { |
| 67 | mEventConnection->setVsyncRate(count); |
| 68 | return NO_ERROR; |
| 69 | } |
| 70 | return NO_INIT; |
| 71 | } |
| 72 | |
| 73 | status_t DisplayEventReceiver::requestNextVsync() { |
| 74 | if (mEventConnection != NULL) { |
| 75 | mEventConnection->requestNextVsync(); |
| 76 | return NO_ERROR; |
| 77 | } |
| 78 | return NO_INIT; |
| 79 | } |
| 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 | |
Dan Stoza | 6b698e4 | 2017-04-03 13:09:08 -0700 | [diff] [blame] | 93 | ssize_t DisplayEventReceiver::sendEvents(gui::BitTube* dataChannel, |
Mathias Agopian | 7b5be95 | 2012-04-02 17:02:19 -0700 | [diff] [blame] | 94 | Event const* events, size_t count) |
| 95 | { |
Dan Stoza | 27c8115 | 2017-03-31 16:30:42 -0700 | [diff] [blame] | 96 | return gui::BitTube::sendObjects(dataChannel, events, count); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | // --------------------------------------------------------------------------- |
| 100 | |
| 101 | }; // namespace android |