blob: 1fed50900395345d3faac75e603a9c19df52d062 [file] [log] [blame]
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001/*
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 Agopiand0566bc2011-11-17 17:49:17 -080021#include <gui/DisplayEventReceiver.h>
22#include <gui/IDisplayEventConnection.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080023#include <gui/ISurfaceComposer.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080024
25#include <private/gui/ComposerService.h>
26
Mathias Agopian801ea092017-03-06 15:05:04 -080027#include <private/gui/BitTube.h>
28
Mathias Agopiand0566bc2011-11-17 17:49:17 -080029// ---------------------------------------------------------------------------
30
31namespace android {
32
33// ---------------------------------------------------------------------------
34
Ady Abraham0f4a1b12019-06-04 16:04:04 -070035DisplayEventReceiver::DisplayEventReceiver(ISurfaceComposer::VsyncSource vsyncSource,
36 ISurfaceComposer::ConfigChanged configChanged) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -080037 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -070038 if (sf != nullptr) {
Ady Abraham0f4a1b12019-06-04 16:04:04 -070039 mEventConnection = sf->createDisplayEventConnection(vsyncSource, configChanged);
Yi Kong48a619f2018-06-05 16:34:59 -070040 if (mEventConnection != nullptr) {
Dan Stoza6b698e42017-04-03 13:09:08 -070041 mDataChannel = std::make_unique<gui::BitTube>();
42 mEventConnection->stealReceiveChannel(mDataChannel.get());
Mathias Agopiand0566bc2011-11-17 17:49:17 -080043 }
44 }
45}
46
47DisplayEventReceiver::~DisplayEventReceiver() {
48}
49
50status_t DisplayEventReceiver::initCheck() const {
Yi Kong48a619f2018-06-05 16:34:59 -070051 if (mDataChannel != nullptr)
Mathias Agopiand0566bc2011-11-17 17:49:17 -080052 return NO_ERROR;
53 return NO_INIT;
54}
55
56int DisplayEventReceiver::getFd() const {
Yi Kong48a619f2018-06-05 16:34:59 -070057 if (mDataChannel == nullptr)
Mathias Agopiand0566bc2011-11-17 17:49:17 -080058 return NO_INIT;
59
60 return mDataChannel->getFd();
61}
62
Mathias Agopian478ae5e2011-12-06 17:22:19 -080063status_t DisplayEventReceiver::setVsyncRate(uint32_t count) {
64 if (int32_t(count) < 0)
65 return BAD_VALUE;
66
Yi Kong48a619f2018-06-05 16:34:59 -070067 if (mEventConnection != nullptr) {
Mathias Agopian478ae5e2011-12-06 17:22:19 -080068 mEventConnection->setVsyncRate(count);
69 return NO_ERROR;
70 }
71 return NO_INIT;
72}
73
74status_t DisplayEventReceiver::requestNextVsync() {
Yi Kong48a619f2018-06-05 16:34:59 -070075 if (mEventConnection != nullptr) {
Mathias Agopian478ae5e2011-12-06 17:22:19 -080076 mEventConnection->requestNextVsync();
77 return NO_ERROR;
78 }
79 return NO_INIT;
80}
81
Alec Mouri271de042020-04-27 22:38:19 -070082status_t DisplayEventReceiver::requestLatestConfig() {
Alec Mouri60aee1c2019-10-28 16:18:59 -070083 if (mEventConnection != nullptr) {
Alec Mouri271de042020-04-27 22:38:19 -070084 mEventConnection->requestLatestConfig();
Alec Mouri60aee1c2019-10-28 16:18:59 -070085 return NO_ERROR;
86 }
87 return NO_INIT;
88}
Mathias Agopian478ae5e2011-12-06 17:22:19 -080089
Mathias Agopiand0566bc2011-11-17 17:49:17 -080090ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
91 size_t count) {
Dan Stoza6b698e42017-04-03 13:09:08 -070092 return DisplayEventReceiver::getEvents(mDataChannel.get(), events, count);
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080093}
94
Dan Stoza6b698e42017-04-03 13:09:08 -070095ssize_t DisplayEventReceiver::getEvents(gui::BitTube* dataChannel,
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080096 Event* events, size_t count)
97{
Dan Stoza27c81152017-03-31 16:30:42 -070098 return gui::BitTube::recvObjects(dataChannel, events, count);
Mathias Agopian7b5be952012-04-02 17:02:19 -070099}
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800100
Dan Stoza6b698e42017-04-03 13:09:08 -0700101ssize_t DisplayEventReceiver::sendEvents(gui::BitTube* dataChannel,
Mathias Agopian7b5be952012-04-02 17:02:19 -0700102 Event const* events, size_t count)
103{
Dan Stoza27c81152017-03-31 16:30:42 -0700104 return gui::BitTube::sendObjects(dataChannel, events, count);
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800105}
106
107// ---------------------------------------------------------------------------
108
109}; // namespace android