1d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian/*
2d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * Copyright (C) 2011 The Android Open Source Project
3d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian *
4d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * you may not use this file except in compliance with the License.
6d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * You may obtain a copy of the License at
7d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian *
8d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian *
10d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * Unless required by applicable law or agreed to in writing, software
11d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * See the License for the specific language governing permissions and
14d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * limitations under the License.
15d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian */
16d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
17d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <string.h>
18d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
19d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <utils/Errors.h>
20d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
21d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <gui/BitTube.h>
22d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <gui/DisplayEventReceiver.h>
23d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <gui/IDisplayEventConnection.h>
2490ac799241f077a7b7e6c1875fd933864c8dd2a7Mathias Agopian#include <gui/ISurfaceComposer.h>
25d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
26d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <private/gui/ComposerService.h>
27d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
28d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// ---------------------------------------------------------------------------
29d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
30d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopiannamespace android {
31d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
32d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// ---------------------------------------------------------------------------
33d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
34d0566bc26fcf6ca396118701fa11900b627f2c09Mathias AgopianDisplayEventReceiver::DisplayEventReceiver() {
35d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
36d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    if (sf != NULL) {
37d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian        mEventConnection = sf->createDisplayEventConnection();
38d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian        if (mEventConnection != NULL) {
39d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian            mDataChannel = mEventConnection->getDataChannel();
40d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian        }
41d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    }
42d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}
43d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
44d0566bc26fcf6ca396118701fa11900b627f2c09Mathias AgopianDisplayEventReceiver::~DisplayEventReceiver() {
45d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}
46d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
47d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianstatus_t DisplayEventReceiver::initCheck() const {
48d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    if (mDataChannel != NULL)
49d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian        return NO_ERROR;
50d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    return NO_INIT;
51d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}
52d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
53d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianint DisplayEventReceiver::getFd() const {
54d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    if (mDataChannel == NULL)
55d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian        return NO_INIT;
56d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
57d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    return mDataChannel->getFd();
58d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}
59d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
60478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopianstatus_t DisplayEventReceiver::setVsyncRate(uint32_t count) {
61478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian    if (int32_t(count) < 0)
62478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian        return BAD_VALUE;
63478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian
64478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian    if (mEventConnection != NULL) {
65478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian        mEventConnection->setVsyncRate(count);
66478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian        return NO_ERROR;
67478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian    }
68478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian    return NO_INIT;
69478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian}
70478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian
71478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopianstatus_t DisplayEventReceiver::requestNextVsync() {
72478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian    if (mEventConnection != NULL) {
73478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian        mEventConnection->requestNextVsync();
74478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian        return NO_ERROR;
75478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian    }
76478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian    return NO_INIT;
77478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian}
78478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian
79478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian
80d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianssize_t DisplayEventReceiver::getEvents(DisplayEventReceiver::Event* events,
81d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian        size_t count) {
8299ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian    return DisplayEventReceiver::getEvents(mDataChannel, events, count);
8399ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian}
8499ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian
8599ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopianssize_t DisplayEventReceiver::getEvents(const sp<BitTube>& dataChannel,
8699ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian        Event* events, size_t count)
8799ce5cdeb383216dee95af4d90e47406b0948ea1Mathias Agopian{
887b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian    return BitTube::recvObjects(dataChannel, events, count);
897b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian}
907b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian
917b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopianssize_t DisplayEventReceiver::sendEvents(const sp<BitTube>& dataChannel,
927b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian        Event const* events, size_t count)
937b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian{
947b5be95cb3903087742f1079fe89cddd8abe3696Mathias Agopian    return BitTube::sendObjects(dataChannel, events, count);
95d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}
96d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
97d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// ---------------------------------------------------------------------------
98d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
99d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}; // namespace android
100