blob: 1e4f6e7a4c3b8b29661038fe44d54f5fe4648aa3 [file] [log] [blame]
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -08001/*
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
Prabir Pradhanc08b0db2022-09-10 00:57:15 +000017#pragma once
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080018
Michael Wrighta9cf4192022-12-01 23:46:39 +000019#include <ui/Rotation.h>
20
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080021#include <stdint.h>
22#include <sys/time.h>
23#include <vector>
24
25namespace 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 */
32class TouchVideoFrame {
33public:
Siarhei Vishniakoufda3aee2019-02-15 17:10:53 -060034 TouchVideoFrame(uint32_t height, uint32_t width, std::vector<int16_t> data,
Siarhei Vishniakou26cf29d2019-02-15 16:48:38 -060035 const struct timeval& timestamp);
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080036
Siarhei Vishniakou26cf29d2019-02-15 16:48:38 -060037 bool operator==(const TouchVideoFrame& rhs) const;
Siarhei Vishniakou473174e2017-12-27 16:44:42 -080038
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080039 /**
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080040 * Height of the frame
41 */
Siarhei Vishniakou26cf29d2019-02-15 16:48:38 -060042 uint32_t getHeight() const;
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080043 /**
Siarhei Vishniakoufda3aee2019-02-15 17:10:53 -060044 * Width of the frame
45 */
46 uint32_t getWidth() const;
47 /**
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080048 * 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 */
Siarhei Vishniakou26cf29d2019-02-15 16:48:38 -060053 const std::vector<int16_t>& getData() const;
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080054 /**
55 * Time at which the heatmap was taken.
56 */
Siarhei Vishniakou26cf29d2019-02-15 16:48:38 -060057 const struct timeval& getTimestamp() const;
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080058
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -060059 /**
60 * Rotate the video frame.
Marin Shalamanov228f46b2021-01-28 21:11:45 +010061 * The rotation value is an enum from ui/Rotation.h
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -060062 */
Michael Wrighta9cf4192022-12-01 23:46:39 +000063 void rotate(ui::Rotation orientation);
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -060064
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080065private:
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080066 uint32_t mHeight;
Siarhei Vishniakoufda3aee2019-02-15 17:10:53 -060067 uint32_t mWidth;
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080068 std::vector<int16_t> mData;
69 struct timeval mTimestamp;
Siarhei Vishniakou8154bbd2019-02-15 17:21:03 -060070
71 /**
72 * Common method for 90 degree and 270 degree rotation
73 */
74 void rotateQuarterTurn(bool clockwise);
75 void rotate180();
Siarhei Vishniakou7b7c8f62018-12-12 16:09:20 -080076};
77
78} // namespace android