Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 015f5d9d authored by Brandon Pollack's avatar Brandon Pollack
Browse files

Change POINTER_ICON_STYLE enum to a type safe enum class

Test: Current tests all pass, this is a static type change, not
a functional change.

Change-Id: I8f0e8e43ea64f5abab163e4ef5444a8cb3d4fa78
parent 925e3670
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ static struct {

// --- Global Functions ---

jobject android_view_PointerIcon_getSystemIcon(JNIEnv* env, jobject contextObj, int32_t style) {
jobject android_view_PointerIcon_getSystemIcon(JNIEnv* env, jobject contextObj,
                                               PointerIconStyle style) {
    jobject pointerIconObj = env->CallStaticObjectMethod(gPointerIconClassInfo.clazz,
            gPointerIconClassInfo.getSystemIcon, contextObj, style);
    if (env->ExceptionCheck()) {
@@ -80,7 +81,8 @@ status_t android_view_PointerIcon_getLoadedIcon(JNIEnv* env, jobject pointerIcon
    if (!pointerIconObj) {
        return BAD_VALUE;
    }
    outPointerIcon->style = env->GetIntField(pointerIconObj, gPointerIconClassInfo.mType);
    outPointerIcon->style = static_cast<PointerIconStyle>(
            env->GetIntField(pointerIconObj, gPointerIconClassInfo.mType));
    outPointerIcon->hotSpotX = env->GetFloatField(pointerIconObj, gPointerIconClassInfo.mHotSpotX);
    outPointerIcon->hotSpotY = env->GetFloatField(pointerIconObj, gPointerIconClassInfo.mHotSpotY);

@@ -107,7 +109,8 @@ status_t android_view_PointerIcon_getLoadedIcon(JNIEnv* env, jobject pointerIcon
}

status_t android_view_PointerIcon_loadSystemIcon(JNIEnv* env, jobject contextObj,
        int32_t style, PointerIcon* outPointerIcon) {
                                                 PointerIconStyle style,
                                                 PointerIcon* outPointerIcon) {
    jobject pointerIconObj = android_view_PointerIcon_getSystemIcon(env, contextObj, style);
    if (!pointerIconObj) {
        outPointerIcon->reset();
@@ -120,7 +123,6 @@ status_t android_view_PointerIcon_loadSystemIcon(JNIEnv* env, jobject contextObj
    return status;
}


// --- JNI Registration ---

int register_android_view_PointerIcon(JNIEnv* env) {
+6 −5
Original line number Diff line number Diff line
@@ -33,17 +33,17 @@ namespace android {
struct PointerIcon {
    inline PointerIcon() { reset(); }

    int32_t style;
    PointerIconStyle style;
    graphics::Bitmap bitmap;
    float hotSpotX;
    float hotSpotY;
    std::vector<graphics::Bitmap> bitmapFrames;
    int32_t durationPerFrame;

    inline bool isNullIcon() { return style == POINTER_ICON_STYLE_NULL; }
    inline bool isNullIcon() { return style == PointerIconStyle::TYPE_NULL; }

    inline void reset() {
        style = POINTER_ICON_STYLE_NULL;
        style = PointerIconStyle::TYPE_NULL;
        bitmap.reset();
        hotSpotX = 0;
        hotSpotY = 0;
@@ -54,7 +54,7 @@ struct PointerIcon {

/* Gets a system pointer icon with the specified style. */
extern jobject android_view_PointerIcon_getSystemIcon(JNIEnv* env, jobject contextObj,
                                                      int32_t style);
                                                      PointerIconStyle style);

/* Loads the bitmap associated with a pointer icon.
 * If pointerIconObj is NULL, returns OK and a pointer icon with POINTER_ICON_STYLE_NULL. */
@@ -68,7 +68,8 @@ extern status_t android_view_PointerIcon_getLoadedIcon(JNIEnv* env, jobject poin
/* Loads the bitmap associated with a pointer icon by style.
 * If pointerIconObj is NULL, returns OK and a pointer icon with POINTER_ICON_STYLE_NULL. */
extern status_t android_view_PointerIcon_loadSystemIcon(JNIEnv* env, jobject contextObj,
                                                        int32_t style, PointerIcon* outPointerIcon);
                                                        PointerIconStyle style,
                                                        PointerIcon* outPointerIcon);

} // namespace android

+6 −5
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

#include "MouseCursorController.h"

#include <input/Input.h>
#include <log/log.h>

namespace {
@@ -286,7 +287,7 @@ void MouseCursorController::setDisplayViewport(const DisplayViewport& viewport,
    updatePointerLocked();
}

void MouseCursorController::updatePointerIcon(int32_t iconId) {
void MouseCursorController::updatePointerIcon(PointerIconStyle iconId) {
    std::scoped_lock lock(mLock);

    if (mLocked.requestedPointerType != iconId) {
@@ -299,7 +300,7 @@ void MouseCursorController::updatePointerIcon(int32_t iconId) {
void MouseCursorController::setCustomPointerIcon(const SpriteIcon& icon) {
    std::scoped_lock lock(mLock);

    const int32_t iconId = mContext.getPolicy()->getCustomPointerIconId();
    const PointerIconStyle iconId = mContext.getPolicy()->getCustomPointerIconId();
    mLocked.additionalMouseResources[iconId] = icon;
    mLocked.requestedPointerType = iconId;
    mLocked.updatePointerIcon = true;
@@ -334,7 +335,7 @@ bool MouseCursorController::doFadingAnimationLocked(nsecs_t timestamp) REQUIRES(
}

bool MouseCursorController::doBitmapAnimationLocked(nsecs_t timestamp) REQUIRES(mLock) {
    std::map<int32_t, PointerAnimation>::const_iterator iter =
    std::map<PointerIconStyle, PointerAnimation>::const_iterator iter =
            mLocked.animationResources.find(mLocked.requestedPointerType);
    if (iter == mLocked.animationResources.end()) {
        return false;
@@ -380,10 +381,10 @@ void MouseCursorController::updatePointerLocked() REQUIRES(mLock) {
        if (mLocked.requestedPointerType == mContext.getPolicy()->getDefaultPointerIconId()) {
            mLocked.pointerSprite->setIcon(mLocked.pointerIcon);
        } else {
            std::map<int32_t, SpriteIcon>::const_iterator iter =
            std::map<PointerIconStyle, SpriteIcon>::const_iterator iter =
                    mLocked.additionalMouseResources.find(mLocked.requestedPointerType);
            if (iter != mLocked.additionalMouseResources.end()) {
                std::map<int32_t, PointerAnimation>::const_iterator anim_iter =
                std::map<PointerIconStyle, PointerAnimation>::const_iterator anim_iter =
                        mLocked.animationResources.find(mLocked.requestedPointerType);
                if (anim_iter != mLocked.animationResources.end()) {
                    mLocked.animationFrameIndex = 0;
+4 −4
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ public:
    void unfade(PointerControllerInterface::Transition transition);
    void setDisplayViewport(const DisplayViewport& viewport, bool getAdditionalMouseResources);

    void updatePointerIcon(int32_t iconId);
    void updatePointerIcon(PointerIconStyle iconId);
    void setCustomPointerIcon(const SpriteIcon& icon);
    void reloadPointerResources(bool getAdditionalMouseResources);

@@ -88,10 +88,10 @@ private:

        bool resourcesLoaded;

        std::map<int32_t, SpriteIcon> additionalMouseResources;
        std::map<int32_t, PointerAnimation> animationResources;
        std::map<PointerIconStyle, SpriteIcon> additionalMouseResources;
        std::map<PointerIconStyle, PointerAnimation> animationResources;

        int32_t requestedPointerType;
        PointerIconStyle requestedPointerType;

        int32_t buttonState;

+1 −1
Original line number Diff line number Diff line
@@ -264,7 +264,7 @@ void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
    }
}

void PointerController::updatePointerIcon(int32_t iconId) {
void PointerController::updatePointerIcon(PointerIconStyle iconId) {
    std::scoped_lock lock(getLock());
    mCursorController.updatePointerIcon(iconId);
}
Loading