blob: 03b33c733067e1cebca9c908ccafdb4a63754f33 [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 Abraham62f216c2020-10-13 19:07:23 -070035DisplayEventReceiver::DisplayEventReceiver(
36 ISurfaceComposer::VsyncSource vsyncSource,
37 ISurfaceComposer::EventRegistrationFlags eventRegistration) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -080038 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Yi Kong48a619f2018-06-05 16:34:59 -070039 if (sf != nullptr) {
Ady Abraham62f216c2020-10-13 19:07:23 -070040 mEventConnection = sf->createDisplayEventConnection(vsyncSource, eventRegistration);
Yi Kong48a619f2018-06-05 16:34:59 -070041 if (mEventConnection != nullptr) {
Dan Stoza6b698e42017-04-03 13:09:08 -070042 mDataChannel = std::make_unique<gui::BitTube>();
43 mEventConnection->stealReceiveChannel(mDataChannel.get());
Mathias Agopiand0566bc2011-11-17 17:49:17 -080044 }
45 }
46}
47
48DisplayEventReceiver::~DisplayEventReceiver() {
49}
50
51status_t DisplayEventReceiver::initCheck() const {
Yi Kong48a619f2018-06-05 16:34:59 -070052 if (mDataChannel != nullptr)
Mathias Agopiand0566bc2011-11-17 17:49:17 -080053 return NO_ERROR;
54 return NO_INIT;
55}
56
57int DisplayEventReceiver::getFd() const {
Yi Kong48a619f2018-06-05 16:34:59 -070058 if (mDataChannel == nullptr)
Mathias Agopiand0566bc2011-11-17 17:49:17 -080059 return NO_INIT;
60
61 return mDataChannel->getFd();
62}
63
Mathias Agopian478ae5e2011-12-06 17:22:19 -080064status_t DisplayEventReceiver::setVsyncRate(uint32_t count) {
65 if (int32_t(count) < 0)
66 return BAD_VALUE;
67
Yi Kong48a619f2018-06-05 16:34:59 -070068 if (mEventConnection != nullptr) {
Mathias Agopian478ae5e2011-12-06 17:22:19 -080069 mEventConnection->setVsyncRate(count);
70 return NO_ERROR;
71 }
72 return NO_INIT;
73}
74
75status_t DisplayEventReceiver::requestNextVsync() {
Yi Kong48a619f2018-06-05 16:34:59 -070076 if (mEventConnection != nullptr) {
Mathias Agopian478ae5e2011-12-06 17:22:19 -080077 mEventConnection->requestNextVsync();
78 return NO_ERROR;
79 }
80 return NO_INIT;
81}
82
Mathias Agopiand0566bc2011-11-17 17:49:17 -080083ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
84 size_t count) {
Dan Stoza6b698e42017-04-03 13:09:08 -070085 return DisplayEventReceiver::getEvents(mDataChannel.get(), events, count);
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080086}
87
Dan Stoza6b698e42017-04-03 13:09:08 -070088ssize_t DisplayEventReceiver::getEvents(gui::BitTube* dataChannel,
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080089 Event* events, size_t count)
90{
Dan Stoza27c81152017-03-31 16:30:42 -070091 return gui::BitTube::recvObjects(dataChannel, events, count);
Mathias Agopian7b5be952012-04-02 17:02:19 -070092}
Mathias Agopiand0566bc2011-11-17 17:49:17 -080093
Alec Mouri967d5d72020-08-05 12:50:03 -070094ssize_t DisplayEventReceiver::sendEvents(Event const* events, size_t count) {
95 return DisplayEventReceiver::sendEvents(mDataChannel.get(), events, count);
96}
97
Dan Stoza6b698e42017-04-03 13:09:08 -070098ssize_t DisplayEventReceiver::sendEvents(gui::BitTube* dataChannel,
Mathias Agopian7b5be952012-04-02 17:02:19 -070099 Event const* events, size_t count)
100{
Dan Stoza27c81152017-03-31 16:30:42 -0700101 return gui::BitTube::sendObjects(dataChannel, events, count);
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800102}
103
104// ---------------------------------------------------------------------------
105
106}; // namespace android