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