OSDN Git Service

Merge tag 'android-8.1.0_r74' into oreo-x86
[android-x86/frameworks-native.git] / libs / gui / DisplayEventReceiver.cpp
1 /*
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
21 #include <gui/DisplayEventReceiver.h>
22 #include <gui/IDisplayEventConnection.h>
23 #include <gui/ISurfaceComposer.h>
24
25 #include <private/gui/ComposerService.h>
26
27 #include <private/gui/BitTube.h>
28
29 // ---------------------------------------------------------------------------
30
31 namespace android {
32
33 // ---------------------------------------------------------------------------
34
35 DisplayEventReceiver::DisplayEventReceiver(ISurfaceComposer::VsyncSource vsyncSource) {
36     sp<ISurfaceComposer> sf(ComposerService::getComposerService());
37     if (sf != NULL) {
38         mEventConnection = sf->createDisplayEventConnection(vsyncSource);
39         if (mEventConnection != NULL) {
40             mDataChannel = std::make_unique<gui::BitTube>();
41             mEventConnection->stealReceiveChannel(mDataChannel.get());
42         }
43     }
44 }
45
46 DisplayEventReceiver::~DisplayEventReceiver() {
47 }
48
49 status_t DisplayEventReceiver::initCheck() const {
50     if (mDataChannel != NULL)
51         return NO_ERROR;
52     return NO_INIT;
53 }
54
55 int DisplayEventReceiver::getFd() const {
56     if (mDataChannel == NULL)
57         return NO_INIT;
58
59     return mDataChannel->getFd();
60 }
61
62 status_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
73 status_t DisplayEventReceiver::requestNextVsync() {
74     if (mEventConnection != NULL) {
75         mEventConnection->requestNextVsync();
76         return NO_ERROR;
77     }
78     return NO_INIT;
79 }
80
81
82 ssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
83         size_t count) {
84     return DisplayEventReceiver::getEvents(mDataChannel.get(), events, count);
85 }
86
87 ssize_t DisplayEventReceiver::getEvents(gui::BitTube* dataChannel,
88         Event* events, size_t count)
89 {
90     return gui::BitTube::recvObjects(dataChannel, events, count);
91 }
92
93 ssize_t DisplayEventReceiver::sendEvents(gui::BitTube* dataChannel,
94         Event const* events, size_t count)
95 {
96     return gui::BitTube::sendObjects(dataChannel, events, count);
97 }
98
99 // ---------------------------------------------------------------------------
100
101 }; // namespace android