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 <stdint.h> 18d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <sys/types.h> 19d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 20d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <utils/Errors.h> 21d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <utils/RefBase.h> 22d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <utils/Timers.h> 23d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 24d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <binder/Parcel.h> 25d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <binder/IInterface.h> 26d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 27d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <gui/IDisplayEventConnection.h> 28d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <gui/BitTube.h> 29d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 30d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopiannamespace android { 31d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// ---------------------------------------------------------------------------- 32d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 33d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianenum { 34d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian GET_DATA_CHANNEL = IBinder::FIRST_CALL_TRANSACTION, 35478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian SET_VSYNC_RATE, 36478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian REQUEST_NEXT_VSYNC 37d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}; 38d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 39d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianclass BpDisplayEventConnection : public BpInterface<IDisplayEventConnection> 40d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian{ 41d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianpublic: 42d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian BpDisplayEventConnection(const sp<IBinder>& impl) 43d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian : BpInterface<IDisplayEventConnection>(impl) 44d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian { 45d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian } 46d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 47d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza virtual ~BpDisplayEventConnection(); 48d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza 49d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian virtual sp<BitTube> getDataChannel() const 50d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian { 51d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian Parcel data, reply; 52d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); 53d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian remote()->transact(GET_DATA_CHANNEL, data, &reply); 54d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return new BitTube(reply); 55d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian } 56478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 57478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian virtual void setVsyncRate(uint32_t count) { 58478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian Parcel data, reply; 59478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); 60d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza data.writeUint32(count); 61478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian remote()->transact(SET_VSYNC_RATE, data, &reply); 62478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian } 63478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian 64478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian virtual void requestNextVsync() { 65478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian Parcel data, reply; 66478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); 67478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian remote()->transact(REQUEST_NEXT_VSYNC, data, &reply, IBinder::FLAG_ONEWAY); 68478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian } 69d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}; 70d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 71d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza// Out-of-line virtual method definition to trigger vtable emission in this 72d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza// translation unit (see clang warning -Wweak-vtables) 73d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan StozaBpDisplayEventConnection::~BpDisplayEventConnection() {} 74d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza 75d0566bc26fcf6ca396118701fa11900b627f2c09Mathias AgopianIMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection"); 76d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 77d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// ---------------------------------------------------------------------------- 78d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 79d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianstatus_t BnDisplayEventConnection::onTransact( 80d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 81d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian{ 82d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian switch(code) { 83d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian case GET_DATA_CHANNEL: { 84d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian CHECK_INTERFACE(IDisplayEventConnection, data, reply); 85d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian sp<BitTube> channel(getDataChannel()); 86d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian channel->writeToParcel(reply); 87d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return NO_ERROR; 88d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza } 89478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian case SET_VSYNC_RATE: { 90478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian CHECK_INTERFACE(IDisplayEventConnection, data, reply); 91d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza setVsyncRate(data.readUint32()); 92478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_ERROR; 93d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza } 94478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian case REQUEST_NEXT_VSYNC: { 95478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian CHECK_INTERFACE(IDisplayEventConnection, data, reply); 96478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian requestNextVsync(); 97478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian return NO_ERROR; 98d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza } 99d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian } 100d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian return BBinder::onTransact(code, data, reply, flags); 101d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian} 102d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian 103d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian// ---------------------------------------------------------------------------- 104d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}; // namespace android 105