Home | History | Annotate | Download | only in gui
      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 <stdint.h>
     18 #include <sys/types.h>
     19 
     20 #include <utils/Errors.h>
     21 #include <utils/RefBase.h>
     22 #include <utils/Timers.h>
     23 
     24 #include <binder/Parcel.h>
     25 #include <binder/IInterface.h>
     26 
     27 #include <gui/IDisplayEventConnection.h>
     28 #include <gui/BitTube.h>
     29 
     30 namespace android {
     31 // ----------------------------------------------------------------------------
     32 
     33 enum {
     34     GET_DATA_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
     35     SET_VSYNC_RATE,
     36     REQUEST_NEXT_VSYNC
     37 };
     38 
     39 class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection>
     40 {
     41 public:
     42     BpDisplayEventConnection(const sp<IBinder>& impl)
     43         : BpInterface<IDisplayEventConnection>(impl)
     44     {
     45     }
     46 
     47     virtual sp<BitTube> getDataChannel() const
     48     {
     49         Parcel data, reply;
     50         data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
     51         remote()->transact(GET_DATA_CHANNEL, data, &reply);
     52         return new BitTube(reply);
     53     }
     54 
     55     virtual void setVsyncRate(uint32_t count) {
     56         Parcel data, reply;
     57         data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
     58         data.writeInt32(count);
     59         remote()->transact(SET_VSYNC_RATE, data, &reply);
     60     }
     61 
     62     virtual void requestNextVsync() {
     63         Parcel data, reply;
     64         data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
     65         remote()->transact(REQUEST_NEXT_VSYNC, data, &reply, IBinder::FLAG_ONEWAY);
     66     }
     67 };
     68 
     69 IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
     70 
     71 // ----------------------------------------------------------------------------
     72 
     73 status_t BnDisplayEventConnection::onTransact(
     74     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
     75 {
     76     switch(code) {
     77         case GET_DATA_CHANNEL: {
     78             CHECK_INTERFACE(IDisplayEventConnection, data, reply);
     79             sp<BitTube> channel(getDataChannel());
     80             channel->writeToParcel(reply);
     81             return NO_ERROR;
     82         } break;
     83         case SET_VSYNC_RATE: {
     84             CHECK_INTERFACE(IDisplayEventConnection, data, reply);
     85             setVsyncRate(data.readInt32());
     86             return NO_ERROR;
     87         } break;
     88         case REQUEST_NEXT_VSYNC: {
     89             CHECK_INTERFACE(IDisplayEventConnection, data, reply);
     90             requestNextVsync();
     91             return NO_ERROR;
     92         } break;
     93     }
     94     return BBinder::onTransact(code, data, reply, flags);
     95 }
     96 
     97 // ----------------------------------------------------------------------------
     98 }; // namespace android
     99