Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 6551d1a

Browse files
committed
Fix display density
1 parent 7f31f8d commit 6551d1a

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.os.Bundle;
1414
import android.os.Handler;
1515
import android.support.annotation.Keep;
16+
import android.util.DisplayMetrics;
1617
import android.util.Log;
1718
import android.view.View;
1819
import android.widget.FrameLayout;
@@ -260,6 +261,12 @@ void handleAudioPose(float qx, float qy, float qz, float qw, float px, float py,
260261
runOnUiThread(mAudioUpdateRunnable);
261262
}
262263

264+
@Keep
265+
int getDisplayDensity() {
266+
DisplayMetrics dm = getResources().getDisplayMetrics();
267+
return dm.densityDpi;
268+
}
269+
263270
void createOffscreenDisplay() {
264271
int[] ids = new int[1];
265272
GLES20.glGenTextures(1, ids, 0);

app/src/main/cpp/BrowserWorld.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static const float kScrollFactor = 20.0f; // Just picked what fell right.
4141

4242
static const char* kDispatchCreateWidgetName = "dispatchCreateWidget";
4343
static const char* kDispatchCreateWidgetSignature = "(IILandroid/graphics/SurfaceTexture;II)V";
44+
static const char* kGetDisplayDensityName = "getDisplayDensity";
45+
static const char* kGetDisplayDensitySignature = "()I";
4446
static const char* kHandleMotionEventName = "handleMotionEvent";
4547
static const char* kHandleMotionEventSignature = "(IIZFF)V";
4648
static const char* kHandleScrollEvent = "handleScrollEvent";
@@ -160,6 +162,7 @@ struct BrowserWorld::State {
160162
float farClip;
161163
JNIEnv* env;
162164
jobject activity;
165+
int displayDensity;
163166
jmethodID dispatchCreateWidgetMethod;
164167
jmethodID handleMotionEventMethod;
165168
jmethodID handleScrollEventMethod;
@@ -178,26 +181,32 @@ struct BrowserWorld::State {
178181
root->AddLight(light);
179182
cullVisitor = CullVisitor::Create(contextWeak);
180183
drawList = DrawableList::Create(contextWeak);
184+
}
185+
186+
void InitializeWindows();
187+
void UpdateControllers();
188+
};
181189

190+
void
191+
BrowserWorld::State::InitializeWindows() {
182192
WidgetPtr browser = Widget::Create(contextWeak, WidgetTypeBrowser);
183193
browser->SetTransform(Matrix::Position(Vector(0.0f, -3.0f, -18.0f)));
184194
root->AddNode(browser->GetRoot());
185195
widgets.push_back(std::move(browser));
186-
#if defined(VRBROWSER_GOOGLEVR)
196+
/*#if defined(VRBROWSER_GOOGLEVR)
187197
static const float kUIScaleFactor = 1.0f;
188198
#else
189199
static const float kUIScaleFactor = 1.5f;
190-
#endif // defined(VRBROWSER_GOOGLEVR)
200+
#endif // defined(VRBROWSER_GOOGLEVR*/
201+
const float uiScaleFactor = displayDensity/420.0f;
202+
191203
WidgetPtr urlbar = Widget::Create(contextWeak, WidgetTypeURLBar,
192-
(int32_t) (1920.0f * kUIScaleFactor),
193-
(int32_t) (275.0f * kUIScaleFactor), 9.0f);
204+
(int32_t) (1920.0f * uiScaleFactor),
205+
(int32_t) (275.0f * uiScaleFactor), 9.0f);
194206
urlbar->SetTransform(Matrix::Position(Vector(0.0f, 7.15f, -18.0f)));
195207
root->AddNode(urlbar->GetRoot());
196208
widgets.push_back(std::move(urlbar));
197-
}
198-
199-
void UpdateControllers();
200-
};
209+
}
201210

202211
void
203212
BrowserWorld::State::UpdateControllers() {
@@ -375,6 +384,13 @@ BrowserWorld::InitializeJava(JNIEnv* aEnv, jobject& aActivity, jobject& aAssetMa
375384
VRB_LOG("Failed to find Java method: %s %s", kHandleGestureName, kHandleGestureSignature);
376385
}
377386

387+
jmethodID getDisplayDensityMethod = m.env->GetMethodID(clazz, kGetDisplayDensityName, kGetDisplayDensitySignature);
388+
if (getDisplayDensityMethod) {
389+
m.displayDensity = m.env->CallIntMethod(m.activity, getDisplayDensityMethod);
390+
}
391+
392+
m.InitializeWindows();
393+
378394
if ((m.controllers.size() == 0) && (m.controllerCount > 0)) {
379395
for (int32_t ix = 0; ix < m.controllerCount; ix++) {
380396
ControllerRecord record(ix);

0 commit comments

Comments
 (0)