Bug 1131470 - Part 2: Update screen configuration HAL to report orientation angle. r=snorp,mwu

--HG--
extra : rebase_source : c6eb4dd4f54b1e9db7e7d2c39e535ba4bcd8af1f
This commit is contained in:
William Chen 2015-08-18 14:55:15 -07:00
parent 3c9928ced9
commit 6d6411c090
14 changed files with 85 additions and 5 deletions

View File

@ -123,6 +123,7 @@ GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
nsIntRect rect;
int32_t colorDepth, pixelDepth;
int16_t angle;
ScreenOrientationInternal orientation;
nsCOMPtr<nsIScreen> screen;
@ -131,9 +132,10 @@ GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
screen->GetColorDepth(&colorDepth);
screen->GetPixelDepth(&pixelDepth);
orientation = static_cast<ScreenOrientationInternal>(bridge->GetScreenOrientation());
angle = bridge->GetScreenAngle();
*aScreenConfiguration =
hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth);
hal::ScreenConfiguration(rect, orientation, angle, colorDepth, pixelDepth);
}
bool

View File

@ -45,7 +45,7 @@ GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration)
: dom::eScreenOrientation_PortraitPrimary;
*aScreenConfiguration =
hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth);
hal::ScreenConfiguration(rect, orientation, 0, colorDepth, pixelDepth);
}
bool

View File

@ -59,6 +59,7 @@ struct WakeLockInformation {
struct ScreenConfiguration {
nsIntRect rect;
ScreenOrientationInternal orientation;
uint16_t angle;
uint32_t colorDepth;
uint32_t pixelDepth;
};

View File

@ -2429,6 +2429,11 @@ public class GeckoAppShell
return GeckoScreenOrientation.getInstance().getScreenOrientation().value;
}
@WrapForJNI
public static int getScreenAngle() {
return GeckoScreenOrientation.getInstance().getAngle();
}
@WrapForJNI
public static void enableScreenOrientationNotifications() {
GeckoScreenOrientation.getInstance().enableNotifications();

View File

@ -212,6 +212,7 @@ public class GeckoEvent {
private int mNativeWindow;
private short mScreenOrientation;
private short mScreenAngle;
private ByteBuffer mBuffer;
@ -745,9 +746,10 @@ public class GeckoEvent {
return event;
}
public static GeckoEvent createScreenOrientationEvent(short aScreenOrientation) {
public static GeckoEvent createScreenOrientationEvent(short aScreenOrientation, short aScreenAngle) {
GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.SCREENORIENTATION_CHANGED);
event.mScreenOrientation = aScreenOrientation;
event.mScreenAngle = aScreenAngle;
return event;
}

View File

@ -152,7 +152,9 @@ public class GeckoScreenOrientation {
} else if (aScreenOrientation == ScreenOrientation.LANDSCAPE) {
aScreenOrientation = ScreenOrientation.LANDSCAPE_PRIMARY;
}
GeckoAppShell.sendEventToGecko(GeckoEvent.createScreenOrientationEvent(aScreenOrientation.value));
GeckoAppShell.sendEventToGecko(
GeckoEvent.createScreenOrientationEvent(aScreenOrientation.value,
getAngle()));
}
return true;
}
@ -264,6 +266,25 @@ public class GeckoScreenOrientation {
return ScreenOrientation.NONE;
}
/*
* @return Device rotation converted to an angle.
*/
public short getAngle() {
switch (getRotation()) {
case Surface.ROTATION_0:
return 0;
case Surface.ROTATION_90:
return 90;
case Surface.ROTATION_180:
return 180;
case Surface.ROTATION_270:
return 270;
default:
Log.w(LOGTAG, "getAngle: unexpected rotation value");
return 0;
}
}
/*
* @return Device rotation from Display.getRotation().
*/

View File

@ -1581,6 +1581,12 @@ AndroidBridge::GetScreenOrientation()
return static_cast<dom::ScreenOrientationInternal>(orientation);
}
uint16_t
AndroidBridge::GetScreenAngle()
{
return GeckoAppShell::GetScreenAngle();
}
void
AndroidBridge::InvalidateAndScheduleComposite()
{

View File

@ -264,6 +264,7 @@ public:
// include IPC headers which requires including basictypes.h which
// requires a lot of changes...
uint32_t GetScreenOrientation();
uint16_t GetScreenAngle();
int GetAPIVersion() { return mAPIVersion; }
bool IsHoneycomb() { return mAPIVersion >= 11 && mAPIVersion <= 13; }

View File

@ -61,6 +61,7 @@ jfieldID AndroidGeckoEvent::jConnectionTypeField = 0;
jfieldID AndroidGeckoEvent::jIsWifiField = 0;
jfieldID AndroidGeckoEvent::jDHCPGatewayField = 0;
jfieldID AndroidGeckoEvent::jScreenOrientationField = 0;
jfieldID AndroidGeckoEvent::jScreenAngleField = 0;
jfieldID AndroidGeckoEvent::jByteBufferField = 0;
jfieldID AndroidGeckoEvent::jWidthField = 0;
jfieldID AndroidGeckoEvent::jHeightField = 0;
@ -169,6 +170,7 @@ AndroidGeckoEvent::InitGeckoEventClass(JNIEnv *jEnv)
jIsWifiField = geckoEvent.getField("mIsWifi", "Z");
jDHCPGatewayField = geckoEvent.getField("mDHCPGateway", "I");
jScreenOrientationField = geckoEvent.getField("mScreenOrientation", "S");
jScreenAngleField = geckoEvent.getField("mScreenAngle", "S");
jByteBufferField = geckoEvent.getField("mBuffer", "Ljava/nio/ByteBuffer;");
jWidthField = geckoEvent.getField("mWidth", "I");
jHeightField = geckoEvent.getField("mHeight", "I");
@ -528,6 +530,7 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jobject jobj)
case SCREENORIENTATION_CHANGED: {
mScreenOrientation = jenv->GetShortField(jobj, jScreenOrientationField);
mScreenAngle = jenv->GetShortField(jobj, jScreenAngleField);
break;
}

View File

@ -562,6 +562,7 @@ public:
bool IsWifi() { return mIsWifi; }
int DHCPGateway() { return mDHCPGateway; }
short ScreenOrientation() { return mScreenOrientation; }
short ScreenAngle() { return mScreenAngle; }
RefCountedJavaObject* ByteBuffer() { return mByteBuffer; }
int Width() { return mWidth; }
int Height() { return mHeight; }
@ -611,6 +612,7 @@ protected:
bool mIsWifi;
int mDHCPGateway;
short mScreenOrientation;
short mScreenAngle;
nsRefPtr<RefCountedJavaObject> mByteBuffer;
int mWidth, mHeight;
int mID;
@ -696,6 +698,7 @@ protected:
static jfieldID jDHCPGatewayField;
static jfieldID jScreenOrientationField;
static jfieldID jScreenAngleField;
static jfieldID jByteBufferField;
static jfieldID jWidthField;

View File

@ -369,6 +369,14 @@ auto GeckoAppShell::GetProxyForURIWrapper(mozilla::jni::String::Param a0, mozill
return mozilla::jni::Method<GetProxyForURIWrapper_t>::Call(nullptr, nullptr, a0, a1, a2, a3);
}
constexpr char GeckoAppShell::GetScreenAngle_t::name[];
constexpr char GeckoAppShell::GetScreenAngle_t::signature[];
auto GeckoAppShell::GetScreenAngle() -> int32_t
{
return mozilla::jni::Method<GetScreenAngle_t>::Call(nullptr, nullptr);
}
constexpr char GeckoAppShell::GetScreenDepthWrapper_t::name[];
constexpr char GeckoAppShell::GetScreenDepthWrapper_t::signature[];

View File

@ -893,6 +893,23 @@ public:
static auto GetProxyForURIWrapper(mozilla::jni::String::Param, mozilla::jni::String::Param, mozilla::jni::String::Param, int32_t) -> mozilla::jni::String::LocalRef;
public:
struct GetScreenAngle_t {
typedef GeckoAppShell Owner;
typedef int32_t ReturnType;
typedef int32_t SetterType;
typedef mozilla::jni::Args<> Args;
static constexpr char name[] = "getScreenAngle";
static constexpr char signature[] =
"()I";
static const bool isStatic = true;
static const bool isMultithreaded = false;
static const mozilla::jni::ExceptionMode exceptionMode =
mozilla::jni::ExceptionMode::ABORT;
};
static auto GetScreenAngle() -> int32_t;
public:
struct GetScreenDepthWrapper_t {
typedef GeckoAppShell Owner;

View File

@ -588,6 +588,7 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
nsIntRect rect;
int32_t colorDepth, pixelDepth;
int16_t angle;
dom::ScreenOrientationInternal orientation;
nsCOMPtr<nsIScreen> screen;
@ -597,9 +598,10 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
screen->GetPixelDepth(&pixelDepth);
orientation =
static_cast<dom::ScreenOrientationInternal>(curEvent->ScreenOrientation());
angle = curEvent->ScreenAngle();
hal::NotifyScreenConfigurationChange(
hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth));
hal::ScreenConfiguration(rect, orientation, angle, colorDepth, pixelDepth));
break;
}

View File

@ -319,6 +319,14 @@ ComputeOrientation(uint32_t aRotation, const nsIntSize& aScreenSize)
}
}
static uint16_t
RotationToAngle(uint32_t aRotation)
{
uint16_t angle = 90 * aRotation;
MOZ_ASSERT(angle == 0 || angle == 90 || angle == 180 || angle == 270);
return angle;
}
ScreenConfiguration
nsScreenGonk::GetConfiguration()
{
@ -328,6 +336,7 @@ nsScreenGonk::GetConfiguration()
// NB: perpetuating colorDepth == pixelDepth illusion here, for
// consistency.
return ScreenConfiguration(mVirtualBounds, orientation,
RotationToAngle(mScreenRotation),
mColorDepth, mColorDepth);
}