blob: 1757ec1cd3c4a0c124fa68b15d094d23ab78e1c9 [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
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -070035DisplayEventReceiver::DisplayEventReceiver(ISurfaceComposer::VsyncSource vsyncSource) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -080036 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
37 if (sf != NULL) {
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -070038 mEventConnection = sf->createDisplayEventConnection(vsyncSource);
Mathias Agopiand0566bc2011-11-17 17:49:17 -080039 if (mEventConnection != NULL) {
Dan Stoza6b698e42017-04-03 13:09:08 -070040 mDataChannel = std::make_unique<gui::BitTube>();
41 mEventConnection->stealReceiveChannel(mDataChannel.get());
Mathias Agopiand0566bc2011-11-17 17:49:17 -080042 }
43 }
44}
45
46DisplayEventReceiver::~DisplayEventReceiver() {
47}
48
49status_t DisplayEventReceiver::initCheck() const {
50 if (mDataChannel != NULL)
51 return NO_ERROR;
52 return NO_INIT;
53}
54
55int DisplayEventReceiver::getFd() const {
56 if (mDataChannel == NULL)
57 return NO_INIT;
58
59 return mDataChannel->getFd();
60}
61
Mathias Agopian478ae5e2011-12-06 17:22:19 -080062status_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
73status_t DisplayEventReceiver::requestNextVsync() {
74 if (mEventConnection != NULL) {
75 mEventConnection->requestNextVsync();
76 return NO_ERROR;
77 }
78 return NO_INIT;
79}
80
81
Mathias Agopiand0566bc2011-11-17 17:49:17 -080082ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
83 size_t count) {
Dan Stoza6b698e42017-04-03 13:09:08 -070084 return DisplayEventReceiver::getEvents(mDataChannel.get(), events, count);
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080085}
86
Dan Stoza6b698e42017-04-03 13:09:08 -070087ssize_t DisplayEventReceiver::getEvents(gui::BitTube* dataChannel,
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080088 Event* events, size_t count)
89{
Dan Stoza27c81152017-03-31 16:30:42 -070090 return gui::BitTube::recvObjects(dataChannel, events, count);
Mathias Agopian7b5be952012-04-02 17:02:19 -070091}
Mathias Agopiand0566bc2011-11-17 17:49:17 -080092
Dan Stoza6b698e42017-04-03 13:09:08 -070093ssize_t DisplayEventReceiver::sendEvents(gui::BitTube* dataChannel,
Mathias Agopian7b5be952012-04-02 17:02:19 -070094 Event const* events, size_t count)
95{
Dan Stoza27c81152017-03-31 16:30:42 -070096 return gui::BitTube::sendObjects(dataChannel, events, count);
Mathias Agopiand0566bc2011-11-17 17:49:17 -080097}
98
99// ---------------------------------------------------------------------------
100
101}; // namespace android