xref: /aosp_15_r20/frameworks/native/include/input/TouchVideoFrame.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2018 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <ui/Rotation.h>
20*38e8c45fSAndroid Build Coastguard Worker 
21*38e8c45fSAndroid Build Coastguard Worker #include <stdint.h>
22*38e8c45fSAndroid Build Coastguard Worker #include <sys/time.h>
23*38e8c45fSAndroid Build Coastguard Worker #include <vector>
24*38e8c45fSAndroid Build Coastguard Worker 
25*38e8c45fSAndroid Build Coastguard Worker namespace android {
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker /**
28*38e8c45fSAndroid Build Coastguard Worker  * Represents data from a single scan of the touchscreen device.
29*38e8c45fSAndroid Build Coastguard Worker  * Similar in concept to a video frame, but the touch strength is used as
30*38e8c45fSAndroid Build Coastguard Worker  * the values instead.
31*38e8c45fSAndroid Build Coastguard Worker  */
32*38e8c45fSAndroid Build Coastguard Worker class TouchVideoFrame {
33*38e8c45fSAndroid Build Coastguard Worker public:
34*38e8c45fSAndroid Build Coastguard Worker     TouchVideoFrame(uint32_t height, uint32_t width, std::vector<int16_t> data,
35*38e8c45fSAndroid Build Coastguard Worker             const struct timeval& timestamp);
36*38e8c45fSAndroid Build Coastguard Worker 
37*38e8c45fSAndroid Build Coastguard Worker     bool operator==(const TouchVideoFrame& rhs) const;
38*38e8c45fSAndroid Build Coastguard Worker 
39*38e8c45fSAndroid Build Coastguard Worker     /**
40*38e8c45fSAndroid Build Coastguard Worker      * Height of the frame
41*38e8c45fSAndroid Build Coastguard Worker      */
42*38e8c45fSAndroid Build Coastguard Worker     uint32_t getHeight() const;
43*38e8c45fSAndroid Build Coastguard Worker     /**
44*38e8c45fSAndroid Build Coastguard Worker      * Width of the frame
45*38e8c45fSAndroid Build Coastguard Worker      */
46*38e8c45fSAndroid Build Coastguard Worker     uint32_t getWidth() const;
47*38e8c45fSAndroid Build Coastguard Worker     /**
48*38e8c45fSAndroid Build Coastguard Worker      * The touch strength data.
49*38e8c45fSAndroid Build Coastguard Worker      * The array is a 2-D row-major matrix, with dimensions (height, width).
50*38e8c45fSAndroid Build Coastguard Worker      * Total size of the array should equal getHeight() * getWidth().
51*38e8c45fSAndroid Build Coastguard Worker      * Data is allowed to be negative.
52*38e8c45fSAndroid Build Coastguard Worker      */
53*38e8c45fSAndroid Build Coastguard Worker     const std::vector<int16_t>& getData() const;
54*38e8c45fSAndroid Build Coastguard Worker     /**
55*38e8c45fSAndroid Build Coastguard Worker      * Time at which the heatmap was taken.
56*38e8c45fSAndroid Build Coastguard Worker      */
57*38e8c45fSAndroid Build Coastguard Worker     const struct timeval& getTimestamp() const;
58*38e8c45fSAndroid Build Coastguard Worker 
59*38e8c45fSAndroid Build Coastguard Worker     /**
60*38e8c45fSAndroid Build Coastguard Worker      * Rotate the video frame.
61*38e8c45fSAndroid Build Coastguard Worker      * The rotation value is an enum from ui/Rotation.h
62*38e8c45fSAndroid Build Coastguard Worker      */
63*38e8c45fSAndroid Build Coastguard Worker     void rotate(ui::Rotation orientation);
64*38e8c45fSAndroid Build Coastguard Worker 
65*38e8c45fSAndroid Build Coastguard Worker private:
66*38e8c45fSAndroid Build Coastguard Worker     uint32_t mHeight;
67*38e8c45fSAndroid Build Coastguard Worker     uint32_t mWidth;
68*38e8c45fSAndroid Build Coastguard Worker     std::vector<int16_t> mData;
69*38e8c45fSAndroid Build Coastguard Worker     struct timeval mTimestamp;
70*38e8c45fSAndroid Build Coastguard Worker 
71*38e8c45fSAndroid Build Coastguard Worker     /**
72*38e8c45fSAndroid Build Coastguard Worker      * Common method for 90 degree and 270 degree rotation
73*38e8c45fSAndroid Build Coastguard Worker      */
74*38e8c45fSAndroid Build Coastguard Worker     void rotateQuarterTurn(bool clockwise);
75*38e8c45fSAndroid Build Coastguard Worker     void rotate180();
76*38e8c45fSAndroid Build Coastguard Worker };
77*38e8c45fSAndroid Build Coastguard Worker 
78*38e8c45fSAndroid Build Coastguard Worker } // namespace android
79