Home | History | Annotate | Download | only in android
      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 #ifndef ANDROID_ANDROID_MULTITOUCH_PORT_H_
     18 #define ANDROID_ANDROID_MULTITOUCH_PORT_H_
     19 
     20 #include "android/sdk-controller-socket.h"
     21 
     22 /*
     23  * Encapsulates exchange protocol between the multi-touch screen emulator, and an
     24  * application running on an Android device that provides touch events, and is
     25  * connected to the host via USB.
     26  */
     27 
     28 /*
     29  * Codes that define transmitted framebuffer format:
     30  *
     31  * NOTE: Application on the device side depends on these values. Any changes
     32  * made here must be reflected in the app too. Application location is at
     33  * 'sdk/apps/SdkController/SdkControllerMultitouch' root.
     34  */
     35 
     36 /* Framebuffer is transmitted as JPEG. */
     37 #define MTFB_JPEG       1
     38 /* Framebuffer is transmitted as raw RGB565 bitmap. */
     39 #define MTFB_RGB565     2
     40 /* Framebuffer is transmitted as raw RGB888 bitmap. */
     41 #define MTFB_RGB888     3
     42 
     43 /* Framebuffer update descriptor.
     44  * This descriptor is used to collect properties of the updated framebuffer
     45  * region. This descriptor is also sent to the MT emulation application on the
     46  * device, so it can properly redraw its screen.
     47  *
     48  * NOTE: Application on the device side depends on that structure. Any changes
     49  * made here must be reflected in the app too. Application location is at
     50  * 'sdk/apps/SdkController/SdkControllerMultitouch' root.
     51  */
     52 typedef struct MTFrameHeader {
     53     /* Size of the header. Must be always sizeof(MTFrameHeader). */
     54     int         header_size;
     55     /* Display width */
     56     int         disp_width;
     57     /* Display height */
     58     int         disp_height;
     59     /* x, y, w, and h define framebuffer region that has been updated. */
     60     int         x;
     61     int         y;
     62     int         w;
     63     int         h;
     64     /* Bytes per line in the framebufer. */
     65     int         bpl;
     66     /* Bytes per pixel in the framebufer. */
     67     int         bpp;
     68     /* Defines format in which framebuffer is transmitted to the device. */
     69     int         format;
     70 } MTFrameHeader;
     71 
     72 /* Declares multi-touch port descriptor. */
     73 typedef struct AndroidMTSPort AndroidMTSPort;
     74 
     75 /* Creates multi-touch port, and connects it to the device.
     76  * Param:
     77  *  opaque - An opaque pointer that is passed back to the callback routines.
     78  * Return:
     79  *  Initialized device descriptor on success, or NULL on failure. If failure is
     80  *  returned from this routine, 'errno' indicates the reason for failure. If this
     81  *  routine successeds, a connection is established with the sensor reading
     82  *  application on the device.
     83  */
     84 extern AndroidMTSPort* mts_port_create(void* opaque);
     85 
     86 /* Disconnects from the multi-touch port, and destroys the descriptor. */
     87 extern void mts_port_destroy(AndroidMTSPort* amtp);
     88 
     89 /* Sends framebuffer update to the multi-touch emulation application, running on
     90  * the android device.
     91  * Param:
     92  *  mtsp - Android multi-touch port instance returned from mts_port_create.
     93  *  fmt - Framebuffer update descriptor.
     94  *  fb - Beginning of the framebuffer.
     95  *  cb - Callback to invoke when update has been transferred to the MT-emulating
     96  *      application on the device.
     97  *  cb_opaque - An opaque parameter to pass back to the 'cb' callback.
     98  *  ydir - Indicates direction in which lines are arranged in the framebuffer. If
     99  *      this value is negative, lines are arranged in bottom-up format (i.e. the
    100  *      bottom line is at the beginning of the buffer).
    101  * Return:
    102  *  0 on success, or != 0 on failure.
    103  */
    104 extern int mts_port_send_frame(AndroidMTSPort* mtsp,
    105                                MTFrameHeader* fmt,
    106                                const uint8_t* fb,
    107                                on_sdkctl_direct_cb cb,
    108                                void* cb_opaque,
    109                                int ydir);
    110 
    111 #endif  /* ANDROID_ANDROID_MULTITOUCH_PORT_H_ */
    112