Swap width and height in TouchVideoFrame

Currently in TouchVideoFrame and related code, the field 'width'
precedes the field 'height'.
But these fields should be  interpreted as follows:
width -> number  of columns
height -> number of rows
In most notations in mathematics, the matrix sizes are designated as
'mxn', where m is the number of rows and n is the number of columns.

So we make TouchVideoFrame consistent with this, and swap these 2
fields.

Test: atest libinput_tests
The actual test is added in the next commit.
Bug: 123241238

Change-Id: I808e7f354bd7b62d5599324eef205bf4450a91c1
diff --git a/services/inputflinger/TouchVideoDevice.cpp b/services/inputflinger/TouchVideoDevice.cpp
index ad70ccc..76df3a1 100644
--- a/services/inputflinger/TouchVideoDevice.cpp
+++ b/services/inputflinger/TouchVideoDevice.cpp
@@ -37,10 +37,10 @@
 namespace android {
 
 TouchVideoDevice::TouchVideoDevice(int fd, std::string&& name, std::string&& devicePath,
-        uint32_t width, uint32_t height,
+        uint32_t height, uint32_t width,
         const std::array<const int16_t*, NUM_BUFFERS>& readLocations) :
         mFd(fd), mName(std::move(name)), mPath(std::move(devicePath)),
-        mWidth(width), mHeight(height),
+        mHeight(height), mWidth(width),
         mReadLocations(readLocations) {
     mFrames.reserve(MAX_QUEUE_SIZE);
 };
@@ -87,9 +87,9 @@
         ALOGE("VIDIOC_G_FMT failed: %s", strerror(errno));
         return nullptr;
     }
-    const uint32_t width = v4l2_fmt.fmt.pix.width;
     const uint32_t height = v4l2_fmt.fmt.pix.height;
-    ALOGI("Frame dimensions: width = %" PRIu32 " height = %" PRIu32, width, height);
+    const uint32_t width = v4l2_fmt.fmt.pix.width;
+    ALOGI("Frame dimensions: height = %" PRIu32 " width = %" PRIu32, height, width);
 
     struct v4l2_requestbuffers req;
     req.count = NUM_BUFFERS;
@@ -116,7 +116,7 @@
             ALOGE("VIDIOC_QUERYBUF failed: %s", strerror(errno));
             return nullptr;
         }
-        if (buf.length != width * height * sizeof(int16_t)) {
+        if (buf.length != height * width * sizeof(int16_t)) {
             ALOGE("Unexpected value of buf.length = %i (offset = %" PRIu32 ")",
                     buf.length, buf.m.offset);
             return nullptr;
@@ -148,7 +148,7 @@
     }
     // Using 'new' to access a non-public constructor.
     return std::unique_ptr<TouchVideoDevice>(new TouchVideoDevice(
-            fd.release(), std::move(name), std::move(devicePath), width, height, readLocations));
+            fd.release(), std::move(name), std::move(devicePath), height, width, readLocations));
 }
 
 size_t TouchVideoDevice::readAndQueueFrames() {
@@ -193,10 +193,10 @@
         ALOGW("The timestamp %ld.%ld was not acquired using CLOCK_MONOTONIC",
                 buf.timestamp.tv_sec, buf.timestamp.tv_usec);
     }
-    std::vector<int16_t> data(mWidth * mHeight);
+    std::vector<int16_t> data(mHeight * mWidth);
     const int16_t* readFrom = mReadLocations[buf.index];
-    std::copy(readFrom, readFrom + mWidth * mHeight, data.begin());
-    TouchVideoFrame frame(mWidth, mHeight, std::move(data), buf.timestamp);
+    std::copy(readFrom, readFrom + mHeight * mWidth, data.begin());
+    TouchVideoFrame frame(mHeight, mWidth, std::move(data), buf.timestamp);
 
     result = ioctl(mFd.get(), VIDIOC_QBUF, &buf);
     if (result == -1) {
@@ -230,7 +230,7 @@
     }
     for (const int16_t* buffer : mReadLocations) {
         void* bufferAddress = static_cast<void*>(const_cast<int16_t*>(buffer));
-        result = munmap(bufferAddress, mWidth * mHeight * sizeof(int16_t));
+        result = munmap(bufferAddress,  mHeight * mWidth * sizeof(int16_t));
         if (result == -1) {
             ALOGE("%s: Couldn't unmap: [%s]", __func__, strerror(errno));
         }
@@ -238,9 +238,9 @@
 }
 
 std::string TouchVideoDevice::dump() const {
-    return StringPrintf("Video device %s (%s) : width=%" PRIu32 ", height=%" PRIu32
+    return StringPrintf("Video device %s (%s) : height=%" PRIu32 ", width=%" PRIu32
             ", fd=%i, hasValidFd=%s",
-            mName.c_str(), mPath.c_str(), mWidth, mHeight, mFd.get(),
+            mName.c_str(), mPath.c_str(), mHeight, mWidth, mFd.get(),
             hasValidFd() ? "true" : "false");
 }