From a407d6a003d746fa0aff50f7ba5da61f19a85b75 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Wed, 5 Feb 2014 18:02:40 -0800 Subject: [PATCH] Remove SkRegion dependency from libinput This gets us one step closer to removing our dependency on Skia, which is at least one of the things blocking us from moving the input system out of f/b. Change-Id: I755e6267996c93fe700f1056327386923287575a --- libs/input/InputDispatcher.cpp | 11 +++++++---- libs/input/InputWindow.cpp | 9 ++++++++- libs/input/InputWindow.h | 9 ++++++--- .../com_android_server_input_InputWindowHandle.cpp | 10 +++++++--- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/libs/input/InputDispatcher.cpp b/libs/input/InputDispatcher.cpp index 10a639e7aaad9..8c8e7058538f9 100644 --- a/libs/input/InputDispatcher.cpp +++ b/libs/input/InputDispatcher.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -172,21 +173,23 @@ static bool isMainDisplay(int32_t displayId) { return displayId == ADISPLAY_ID_DEFAULT || displayId == ADISPLAY_ID_NONE; } -static void dumpRegion(String8& dump, const SkRegion& region) { +static void dumpRegion(String8& dump, const Region& region) { if (region.isEmpty()) { dump.append(""); return; } bool first = true; - for (SkRegion::Iterator it(region); !it.done(); it.next()) { + Region::const_iterator cur = region.begin(); + Region::const_iterator const tail = region.end(); + while (cur != tail) { if (first) { first = false; } else { dump.append("|"); } - const SkIRect& rect = it.rect(); - dump.appendFormat("[%d,%d][%d,%d]", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + dump.appendFormat("[%d,%d][%d,%d]", cur->left, cur->top, cur->right, cur->bottom); + cur++; } } diff --git a/libs/input/InputWindow.cpp b/libs/input/InputWindow.cpp index fe61918e1d868..da59159196726 100644 --- a/libs/input/InputWindow.cpp +++ b/libs/input/InputWindow.cpp @@ -15,17 +15,24 @@ */ #define LOG_TAG "InputWindow" +#define LOG_NDEBUG 0 #include "InputWindow.h" #include +#include +#include + namespace android { // --- InputWindowInfo --- +void InputWindowInfo::addTouchableRegion(const Rect& region) { + touchableRegion.orSelf(region); +} bool InputWindowInfo::touchableRegionContainsPoint(int32_t x, int32_t y) const { - return touchableRegion.contains(x, y); + return touchableRegion.contains(x,y); } bool InputWindowInfo::frameContainsPoint(int32_t x, int32_t y) const { diff --git a/libs/input/InputWindow.h b/libs/input/InputWindow.h index 28fa7ab42d44c..9618ffe00bc50 100644 --- a/libs/input/InputWindow.h +++ b/libs/input/InputWindow.h @@ -19,16 +19,17 @@ #include #include +#include +#include #include #include #include -#include - #include "InputApplication.h" namespace android { + /* * Describes the properties of a window that can receive input. */ @@ -125,7 +126,7 @@ struct InputWindowInfo { int32_t frameRight; int32_t frameBottom; float scaleFactor; - SkRegion touchableRegion; + Region touchableRegion; bool visible; bool canReceiveKeys; bool hasFocus; @@ -137,6 +138,8 @@ struct InputWindowInfo { int32_t inputFeatures; int32_t displayId; + void addTouchableRegion(const Rect& region); + bool touchableRegionContainsPoint(int32_t x, int32_t y) const; bool frameContainsPoint(int32_t x, int32_t y) const; diff --git a/services/core/jni/com_android_server_input_InputWindowHandle.cpp b/services/core/jni/com_android_server_input_InputWindowHandle.cpp index b80183c73b80d..03bf7eb2df991 100644 --- a/services/core/jni/com_android_server_input_InputWindowHandle.cpp +++ b/services/core/jni/com_android_server_input_InputWindowHandle.cpp @@ -23,6 +23,7 @@ #include #include +#include #include "com_android_server_input_InputWindowHandle.h" #include "com_android_server_input_InputApplicationHandle.h" @@ -86,6 +87,8 @@ bool NativeInputWindowHandle::updateInfo() { if (!mInfo) { mInfo = new InputWindowInfo(); + } else { + mInfo->touchableRegion.clear(); } jobject inputChannelObj = env->GetObjectField(obj, @@ -131,10 +134,11 @@ bool NativeInputWindowHandle::updateInfo() { gInputWindowHandleClassInfo.touchableRegion); if (regionObj) { SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj); - mInfo->touchableRegion.set(*region); + for (SkRegion::Iterator it(*region); !it.done(); it.next()) { + const SkIRect& rect = it.rect(); + mInfo->addTouchableRegion(Rect(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom)); + } env->DeleteLocalRef(regionObj); - } else { - mInfo->touchableRegion.setEmpty(); } mInfo->visible = env->GetBooleanField(obj,