2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <utils/Errors.h>
21 #include <gui/DisplayEventReceiver.h>
22 #include <gui/IDisplayEventConnection.h>
23 #include <gui/ISurfaceComposer.h>
25 #include <private/gui/ComposerService.h>
27 #include <private/gui/BitTube.h>
29 // ---------------------------------------------------------------------------
33 // ---------------------------------------------------------------------------
35 DisplayEventReceiver::DisplayEventReceiver(ISurfaceComposer::VsyncSource vsyncSource) {
36 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
38 mEventConnection = sf->createDisplayEventConnection(vsyncSource);
39 if (mEventConnection != NULL) {
40 mDataChannel = std::make_unique<gui::BitTube>();
41 mEventConnection->stealReceiveChannel(mDataChannel.get());
46 DisplayEventReceiver::~DisplayEventReceiver() {
49 status_t DisplayEventReceiver::initCheck() const {
50 if (mDataChannel != NULL)
55 int DisplayEventReceiver::getFd() const {
56 if (mDataChannel == NULL)
59 return mDataChannel->getFd();
62 status_t DisplayEventReceiver::setVsyncRate(uint32_t count) {
63 if (int32_t(count) < 0)
66 if (mEventConnection != NULL) {
67 mEventConnection->setVsyncRate(count);
73 status_t DisplayEventReceiver::requestNextVsync() {
74 if (mEventConnection != NULL) {
75 mEventConnection->requestNextVsync();
82 ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
84 return DisplayEventReceiver::getEvents(mDataChannel.get(), events, count);
87 ssize_t DisplayEventReceiver::getEvents(gui::BitTube* dataChannel,
88 Event* events, size_t count)
90 return gui::BitTube::recvObjects(dataChannel, events, count);
93 ssize_t DisplayEventReceiver::sendEvents(gui::BitTube* dataChannel,
94 Event const* events, size_t count)
96 return gui::BitTube::sendObjects(dataChannel, events, count);
99 // ---------------------------------------------------------------------------
101 }; // namespace android