Skip to content

Commit

Permalink
Use enum instead of boolean for CPULevel
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Apr 8, 2019
1 parent 6cbf070 commit cf41265
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.util.HashMap;
import java.util.LinkedList;

import androidx.annotation.IntDef;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;

Expand Down Expand Up @@ -767,7 +768,7 @@ public void addWidgets(final Iterable<Widget> aWidgets) {
// VideoAvailabilityListener
@Override
public void onVideoAvailabilityChanged(boolean aVideosAvailable) {
queueRunnable(() -> setCPULevelNative(aVideosAvailable));
queueRunnable(() -> setCPULevelNative(aVideosAvailable ? CPU_LEVEL_HIGH : CPU_LEVEL_NORMAL));
}

// WidgetManagerDelegate
Expand Down Expand Up @@ -1036,6 +1037,13 @@ public void setCylinderDensity(final float aDensity) {
private native void setControllersVisibleNative(boolean aVisible);
private native void runCallbackNative(long aCallback);
private native void setCylinderDensityNative(float aDensity);
private native void setCPULevelNative(boolean aHighLevel);
private native void setCPULevelNative(@CPULevelFlags int aCPULevel);
private native void setIsServo(boolean aIsServo);


@IntDef(value = { CPU_LEVEL_NORMAL, CPU_LEVEL_HIGH})
private @interface CPULevelFlags {}

private static final int CPU_LEVEL_NORMAL = 0;
private static final int CPU_LEVEL_HIGH = 1;
}
8 changes: 4 additions & 4 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ BrowserWorld::SetCylinderDensity(const float aDensity) {
}

void
BrowserWorld::SetCPULevel(const bool aHighLevel) {
m.device->SetCPULevel(aHighLevel ? device::CPULevel::High : device::CPULevel::Normal);
BrowserWorld::SetCPULevel(const device::CPULevel aLevel) {
m.device->SetCPULevel(aLevel);
}

void
Expand Down Expand Up @@ -1343,8 +1343,8 @@ JNI_METHOD(void, runCallbackNative)
}

JNI_METHOD(void, setCPULevelNative)
(JNIEnv* aEnv, jobject, jboolean aHighLevel) {
crow::BrowserWorld::Instance().SetCPULevel(aHighLevel);
(JNIEnv* aEnv, jobject, int aCPULevel) {
crow::BrowserWorld::Instance().SetCPULevel(static_cast<crow::device::CPULevel>(aCPULevel));
}

JNI_METHOD(void, setIsServo)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/BrowserWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BrowserWorld {
void ResetUIYaw();
void SetCylinderDensity(const float aDensity);
void SetIsServo(const bool aIsServo);
void SetCPULevel(const bool aHighLevel);
void SetCPULevel(const device::CPULevel aLevel);
JNIEnv* GetJNIEnv() const;
protected:
struct State;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const CapabilityFlags MountDetection = 1 << 8;
const CapabilityFlags PositionEmulated = 1 << 9;
enum class Eye { Left, Right };
enum class RenderMode { StandAlone, Immersive };
enum class CPULevel { Normal, High };
enum class CPULevel { Normal = 0, High };
const int32_t EyeCount = 2;
inline int32_t EyeIndex(const Eye aEye) { return aEye == Eye::Left ? 0 : 1; }

Expand Down

0 comments on commit cf41265

Please sign in to comment.