1 /*
2  * Copyright (C) 2018 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 _LIBINPUT_TOUCHVIDEOFRAME_H
18 #define _LIBINPUT_TOUCHVIDEOFRAME_H
19 
20 #include <stdint.h>
21 #include <sys/time.h>
22 #include <ui/DisplayInfo.h>
23 #include <vector>
24 
25 namespace android {
26 
27 /**
28  * Represents data from a single scan of the touchscreen device.
29  * Similar in concept to a video frame, but the touch strength is used as
30  * the values instead.
31  */
32 class TouchVideoFrame {
33 public:
34     TouchVideoFrame(uint32_t height, uint32_t width, std::vector<int16_t> data,
35             const struct timeval& timestamp);
36 
37     bool operator==(const TouchVideoFrame& rhs) const;
38 
39     /**
40      * Height of the frame
41      */
42     uint32_t getHeight() const;
43     /**
44      * Width of the frame
45      */
46     uint32_t getWidth() const;
47     /**
48      * The touch strength data.
49      * The array is a 2-D row-major matrix, with dimensions (height, width).
50      * Total size of the array should equal getHeight() * getWidth().
51      * Data is allowed to be negative.
52      */
53     const std::vector<int16_t>& getData() const;
54     /**
55      * Time at which the heatmap was taken.
56      */
57     const struct timeval& getTimestamp() const;
58 
59     /**
60      * Rotate the video frame.
61      * The rotation value is an enum from ui/DisplayInfo.h
62      */
63     void rotate(int32_t orientation);
64 
65 private:
66     uint32_t mHeight;
67     uint32_t mWidth;
68     std::vector<int16_t> mData;
69     struct timeval mTimestamp;
70 
71     /**
72      * Common method for 90 degree and 270 degree rotation
73      */
74     void rotateQuarterTurn(bool clockwise);
75     void rotate180();
76 };
77 
78 } // namespace android
79 
80 #endif // _LIBINPUT_TOUCHVIDEOFRAME_H
81