Prabir Pradhan | 29c9533 | 2018-11-14 20:14:11 -0800 | [diff] [blame^] | 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 | #define LOG_TAG "InputReaderBase" |
| 18 | |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
| 21 | #include "InputReaderBase.h" |
| 22 | |
| 23 | #include <android/log.h> |
| 24 | #include <android-base/stringprintf.h> |
| 25 | |
| 26 | #define INDENT " " |
| 27 | #define INDENT2 " " |
| 28 | #define INDENT3 " " |
| 29 | #define INDENT4 " " |
| 30 | #define INDENT5 " " |
| 31 | |
| 32 | using android::base::StringPrintf; |
| 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | // --- InputReaderThread --- |
| 37 | |
| 38 | InputReaderThread::InputReaderThread(const sp<InputReaderInterface>& reader) : |
| 39 | Thread(/*canCallJava*/ true), mReader(reader) { |
| 40 | } |
| 41 | |
| 42 | InputReaderThread::~InputReaderThread() { |
| 43 | } |
| 44 | |
| 45 | bool InputReaderThread::threadLoop() { |
| 46 | mReader->loopOnce(); |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | // --- InputReaderConfiguration --- |
| 51 | |
| 52 | std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewport( |
| 53 | ViewportType viewportType, const std::string& uniqueDisplayId) const { |
| 54 | for (const DisplayViewport& currentViewport : mDisplays) { |
| 55 | if (currentViewport.type == viewportType) { |
| 56 | if (uniqueDisplayId.empty() || |
| 57 | (!uniqueDisplayId.empty() && uniqueDisplayId == currentViewport.uniqueId)) { |
| 58 | return std::make_optional(currentViewport); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | return std::nullopt; |
| 63 | } |
| 64 | |
| 65 | void InputReaderConfiguration::setDisplayViewports(const std::vector<DisplayViewport>& viewports) { |
| 66 | mDisplays = viewports; |
| 67 | } |
| 68 | |
| 69 | void InputReaderConfiguration::dump(std::string& dump) const { |
| 70 | for (const DisplayViewport& viewport : mDisplays) { |
| 71 | dumpViewport(dump, viewport); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void InputReaderConfiguration::dumpViewport(std::string& dump, const DisplayViewport& viewport) |
| 76 | const { |
| 77 | dump += StringPrintf(INDENT4 "%s\n", viewport.toString().c_str()); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | // -- TouchAffineTransformation -- |
| 82 | void TouchAffineTransformation::applyTo(float& x, float& y) const { |
| 83 | float newX, newY; |
| 84 | newX = x * x_scale + y * x_ymix + x_offset; |
| 85 | newY = x * y_xmix + y * y_scale + y_offset; |
| 86 | |
| 87 | x = newX; |
| 88 | y = newY; |
| 89 | } |
| 90 | |
| 91 | } // namespace android |