blob: 77ecbd280edbfe5932411fa83d56bf71677e3445 [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 <stdint.h>
18#include <sys/types.h>
19
20#include <gui/IDisplayEventConnection.h>
21#include <gui/BitTube.h>
22#include <gui/DisplayEventReceiver.h>
23
24#include <utils/Errors.h>
25
26#include "SurfaceFlinger.h"
27#include "DisplayEventConnection.h"
Mathias Agopian478ae5e2011-12-06 17:22:19 -080028#include "EventThread.h"
Mathias Agopiand0566bc2011-11-17 17:49:17 -080029
30// ---------------------------------------------------------------------------
31
32namespace android {
33
34// ---------------------------------------------------------------------------
35
36DisplayEventConnection::DisplayEventConnection(
Mathias Agopian478ae5e2011-12-06 17:22:19 -080037 const sp<EventThread>& eventThread)
38 : mEventThread(eventThread), mChannel(new BitTube())
Mathias Agopiand0566bc2011-11-17 17:49:17 -080039{
40}
41
42DisplayEventConnection::~DisplayEventConnection() {
Mathias Agopian478ae5e2011-12-06 17:22:19 -080043 mEventThread->unregisterDisplayEventConnection(this);
Mathias Agopiand0566bc2011-11-17 17:49:17 -080044}
45
46void DisplayEventConnection::onFirstRef() {
Mathias Agopian478ae5e2011-12-06 17:22:19 -080047 // NOTE: mEventThread doesn't hold a strong reference on us
48 mEventThread->registerDisplayEventConnection(this);
Mathias Agopiand0566bc2011-11-17 17:49:17 -080049}
50
51sp<BitTube> DisplayEventConnection::getDataChannel() const {
52 return mChannel;
53}
54
Mathias Agopian478ae5e2011-12-06 17:22:19 -080055void DisplayEventConnection::setVsyncRate(uint32_t count) {
56 mEventThread->setVsyncRate(count, this);
57}
58
59void DisplayEventConnection::requestNextVsync() {
60 mEventThread->requestNextVsync(this);
61}
62
Mathias Agopiand0566bc2011-11-17 17:49:17 -080063status_t DisplayEventConnection::postEvent(const DisplayEventReceiver::Event& event)
64{
65 ssize_t size = mChannel->write(&event, sizeof(DisplayEventReceiver::Event));
66 return size < 0 ? status_t(size) : status_t(NO_ERROR);
67}
68
Mathias Agopiand0566bc2011-11-17 17:49:17 -080069// ---------------------------------------------------------------------------
70
71}; // namespace android