blob: 16b06e9a6e2d96e1bf5a3a619e4a5bdbcf5652da [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
35DisplayEventReceiver::DisplayEventReceiver() {
36 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
37 if (sf != NULL) {
38 mEventConnection = sf->createDisplayEventConnection();
39 if (mEventConnection != NULL) {
Dan Stozae1c599b2017-03-30 16:37:19 -070040 mEventConnection->getDataChannel(&mDataChannel);
Mathias Agopiand0566bc2011-11-17 17:49:17 -080041 }
42 }
43}
44
45DisplayEventReceiver::~DisplayEventReceiver() {
46}
47
48status_t DisplayEventReceiver::initCheck() const {
49 if (mDataChannel != NULL)
50 return NO_ERROR;
51 return NO_INIT;
52}
53
54int DisplayEventReceiver::getFd() const {
55 if (mDataChannel == NULL)
56 return NO_INIT;
57
58 return mDataChannel->getFd();
59}
60
Mathias Agopian478ae5e2011-12-06 17:22:19 -080061status_t DisplayEventReceiver::setVsyncRate(uint32_t count) {
62 if (int32_t(count) < 0)
63 return BAD_VALUE;
64
65 if (mEventConnection != NULL) {
66 mEventConnection->setVsyncRate(count);
67 return NO_ERROR;
68 }
69 return NO_INIT;
70}
71
72status_t DisplayEventReceiver::requestNextVsync() {
73 if (mEventConnection != NULL) {
74 mEventConnection->requestNextVsync();
75 return NO_ERROR;
76 }
77 return NO_INIT;
78}
79
80
Mathias Agopiand0566bc2011-11-17 17:49:17 -080081ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
82 size_t count) {
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080083 return DisplayEventReceiver::getEvents(mDataChannel, events, count);
84}
85
86ssize_t DisplayEventReceiver::getEvents(const sp<BitTube>& dataChannel,
87 Event* events, size_t count)
88{
Mathias Agopian7b5be952012-04-02 17:02:19 -070089 return BitTube::recvObjects(dataChannel, events, count);
90}
Mathias Agopiand0566bc2011-11-17 17:49:17 -080091
Mathias Agopian7b5be952012-04-02 17:02:19 -070092ssize_t DisplayEventReceiver::sendEvents(const sp<BitTube>& dataChannel,
93 Event const* events, size_t count)
94{
95 return BitTube::sendObjects(dataChannel, events, count);
Mathias Agopiand0566bc2011-11-17 17:49:17 -080096}
97
98// ---------------------------------------------------------------------------
99
100}; // namespace android