Better compat mode part one: start scaling windows.

First step of improving app screen size compatibility mode.  When
running in compat mode, an application's windows are scaled up on
the screen rather than being small with 1:1 pixels.

Currently we scale the application to fill the entire screen, so
don't use an even pixel scaling.  Though this may have some
negative impact on the appearance (it looks okay to me), it has a
big benefit of allowing us to now treat these apps as normal
full-screens apps and do the normal transition animations as you
move in and out and around in them.

This introduces fun stuff in the input system to take care of
modifying pointer coordinates to account for the app window
surface scaling.  The input dispatcher is told about the scale
that is being applied to each window and, when there is one,
adjusts pointer events appropriately as they are being sent
to the transport.

Also modified is CompatibilityInfo, which has been greatly
simplified to not be so insane and incomprehendible.  It is
now simple -- when constructed it determines if the given app
is compatible with the current screen size and density, and
that is that.

There are new APIs on ActivityManagerService to put applications
that we would traditionally consider compatible with larger screens
in compatibility mode.  This is the start of a facility to have
a UI affordance for a user to switch apps in and out of
compatibility.

To test switching of modes, there is a new variation of the "am"
command to do this: am screen-compat [on|off] [package]

This mode switching has the fundamentals of restarting activities
when it is changed, though the state still needs to be persisted
and the overall mode switch cleaned up.

For the few small apps I have tested, things mostly seem to be
working well.  I know of one problem with the text selection
handles being drawn at the wrong position because at some point
the window offset is being scaled incorrectly.  There are
probably other similar issues around the interaction between
two windows because the different window coordinate spaces are
done in a hacky way instead of being formally integrated into
the window manager layout process.

Change-Id: Ie038e3746b448135117bd860859d74e360938557
This commit is contained in:
Dianne Hackborn 2011-04-27 18:52:56 -04:00
parent 5451520bd5
commit 16fe3c2c1f
2 changed files with 25 additions and 24 deletions

View File

@ -203,6 +203,8 @@ struct PointerCoords {
status_t setAxisValue(int32_t axis, float value);
float* editAxisValue(int32_t axis);
void scale(float scale);
#ifdef HAVE_ANDROID_OS
status_t readFromParcel(Parcel* parcel);
status_t writeToParcel(Parcel* parcel) const;

View File

@ -298,6 +298,24 @@ float* PointerCoords::editAxisValue(int32_t axis) {
return &values[index];
}
static inline void scaleAxisValue(PointerCoords& c, int axis, float scaleFactor) {
float* value = c.editAxisValue(axis);
if (value) {
*value *= scaleFactor;
}
}
void PointerCoords::scale(float scaleFactor) {
// No need to scale pressure or size since they are normalized.
// No need to scale orientation since it is meaningless to do so.
scaleAxisValue(*this, AMOTION_EVENT_AXIS_X, scaleFactor);
scaleAxisValue(*this, AMOTION_EVENT_AXIS_Y, scaleFactor);
scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOUCH_MAJOR, scaleFactor);
scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOUCH_MINOR, scaleFactor);
scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MAJOR, scaleFactor);
scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MINOR, scaleFactor);
}
#ifdef HAVE_ANDROID_OS
status_t PointerCoords::readFromParcel(Parcel* parcel) {
bits = parcel->readInt64();
@ -411,11 +429,9 @@ float MotionEvent::getAxisValue(int32_t axis, size_t pointerIndex) const {
float value = getRawPointerCoords(pointerIndex)->getAxisValue(axis);
switch (axis) {
case AMOTION_EVENT_AXIS_X:
value += mXOffset;
break;
return value + mXOffset;
case AMOTION_EVENT_AXIS_Y:
value += mYOffset;
break;
return value + mYOffset;
}
return value;
}
@ -435,11 +451,9 @@ float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex,
float value = getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->getAxisValue(axis);
switch (axis) {
case AMOTION_EVENT_AXIS_X:
value += mXOffset;
break;
return value + mXOffset;
case AMOTION_EVENT_AXIS_Y:
value += mYOffset;
break;
return value + mYOffset;
}
return value;
}
@ -449,13 +463,6 @@ void MotionEvent::offsetLocation(float xOffset, float yOffset) {
mYOffset += yOffset;
}
static inline void scaleAxisValue(PointerCoords& c, int axis, float scaleFactor) {
float* value = c.editAxisValue(axis);
if (value) {
*value *= scaleFactor;
}
}
void MotionEvent::scale(float scaleFactor) {
mXOffset *= scaleFactor;
mYOffset *= scaleFactor;
@ -464,15 +471,7 @@ void MotionEvent::scale(float scaleFactor) {
size_t numSamples = mSamplePointerCoords.size();
for (size_t i = 0; i < numSamples; i++) {
PointerCoords& c = mSamplePointerCoords.editItemAt(i);
// No need to scale pressure or size since they are normalized.
// No need to scale orientation since it is meaningless to do so.
scaleAxisValue(c, AMOTION_EVENT_AXIS_X, scaleFactor);
scaleAxisValue(c, AMOTION_EVENT_AXIS_Y, scaleFactor);
scaleAxisValue(c, AMOTION_EVENT_AXIS_TOUCH_MAJOR, scaleFactor);
scaleAxisValue(c, AMOTION_EVENT_AXIS_TOUCH_MINOR, scaleFactor);
scaleAxisValue(c, AMOTION_EVENT_AXIS_TOOL_MAJOR, scaleFactor);
scaleAxisValue(c, AMOTION_EVENT_AXIS_TOOL_MINOR, scaleFactor);
mSamplePointerCoords.editItemAt(i).scale(scaleFactor);
}
}