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

Commit

Permalink
Add UI texture scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Nov 26, 2018
1 parent b89303c commit ea63530
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
19 changes: 13 additions & 6 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,10 @@ public void onFrameAvailable(SurfaceTexture surfaceTexture) {
}
widget.setSurfaceTexture(aTexture, aWidth, aHeight);
// Add widget to a virtual display for invalidation
if (((View)widget).getParent() == null) {
mWidgetContainer.addView((View) widget, new FrameLayout.LayoutParams(aWidth, aHeight));
View view = (View) widget;
if (view.getParent() == null) {
float scale = widget.getPlacement().textureScale;
mWidgetContainer.addView(view, new FrameLayout.LayoutParams((int) Math.ceil(aWidth / scale), (int) Math.ceil(aHeight / scale)));
}
});
}
Expand Down Expand Up @@ -473,7 +475,8 @@ void dispatchCreateWidgetLayer(final int aHandle, final Surface aSurface, final
View view = (View) widget;
// Add widget to a virtual display for invalidation
if (aSurface != null && view.getParent() == null) {
mWidgetContainer.addView(view, new FrameLayout.LayoutParams(aWidth, aHeight));
float scale = widget.getPlacement().textureScale;
mWidgetContainer.addView(view, new FrameLayout.LayoutParams((int) Math.ceil(aWidth / scale), (int) Math.ceil(aHeight / scale)));
} else if (aSurface == null && view.getParent() != null) {
mWidgetContainer.removeView(view);
}
Expand All @@ -486,13 +489,17 @@ void dispatchCreateWidgetLayer(final int aHandle, final Surface aSurface, final
void handleMotionEvent(final int aHandle, final int aDevice, final boolean aPressed, final float aX, final float aY) {
runOnUiThread(() -> {
Widget widget = mWidgets.get(aHandle);
float scale = widget != null ? widget.getPlacement().textureScale : 1.0f;
final float x = aX / scale;
final float y = aY / scale;

if (widget == null) {
MotionEventGenerator.dispatch(mRootWidget, aDevice, aPressed, aX, aY);
MotionEventGenerator.dispatch(mRootWidget, aDevice, aPressed, x, y);
} else if (widget == mBrowserWidget && mBrowserWidget.getBorderWidth() > 0) {
final int border = mBrowserWidget.getBorderWidth();
MotionEventGenerator.dispatch(widget, aDevice, aPressed, aX - border, aY - border);
MotionEventGenerator.dispatch(widget, aDevice, aPressed, x - border, y - border);
} else {
MotionEventGenerator.dispatch(widget, aDevice, aPressed, aX, aY);
MotionEventGenerator.dispatch(widget, aDevice, aPressed, x, y);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.anchorX = 0.5f;
aPlacement.anchorY = 0.0f;
aPlacement.visible = true;
aPlacement.textureScale = 1.0f;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public WidgetPlacement(Context aContext) {
public boolean showPointer = true;
public boolean firstDraw = false;
public boolean layer = true;
public float textureScale = 0.7f;

public WidgetPlacement clone() {
WidgetPlacement w = new WidgetPlacement();
Expand Down Expand Up @@ -67,6 +68,7 @@ public void copyFrom(WidgetPlacement w) {
this.opaque = w.opaque;
this.showPointer = w.showPointer;
this.firstDraw = w.firstDraw;
this.textureScale = w.textureScale;
}

public int textureWidth() {
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,8 @@ BrowserWorld::AddWidget(int32_t aHandle, const WidgetPlacementPtr& aPlacement) {
worldWidth = aPlacement->width * kWorldDPIRatio;
}

int32_t textureWidth = (int32_t)(ceilf(aPlacement->width * aPlacement->density));
int32_t textureHeight = (int32_t)(ceilf(aPlacement->height * aPlacement->density));
const int32_t textureWidth = aPlacement->GetTextureWidth();
const int32_t textureHeight = aPlacement->GetTextureHeight();

WidgetPtr widget;
VRLayerQuadPtr layer;
Expand Down Expand Up @@ -734,8 +734,7 @@ BrowserWorld::UpdateWidget(int32_t aHandle, const WidgetPlacementPtr& aPlacement

widget->SetPlacement(aPlacement);
widget->ToggleWidget(aPlacement->visible);
widget->SetSurfaceTextureSize((int32_t)(ceilf(aPlacement->width * aPlacement->density)),
(int32_t)(ceilf(aPlacement->height * aPlacement->density)));
widget->SetSurfaceTextureSize(aPlacement->GetTextureWidth(), aPlacement->GetTextureHeight());

float worldWidth = 0.0f, worldHeight = 0.0f;
widget->GetWorldSize(worldWidth, worldHeight);
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/cpp/WidgetPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ WidgetPlacement::FromJava(JNIEnv* aEnv, jobject& aObject) {
GET_BOOLEAN_FIELD(showPointer);
GET_BOOLEAN_FIELD(firstDraw);
GET_BOOLEAN_FIELD(layer);
GET_FLOAT_FIELD(textureScale, "textureScale");

return result;
}

int32_t
WidgetPlacement::GetTextureWidth() const{
return (int32_t)ceilf(width * density * textureScale);
}

int32_t
WidgetPlacement::GetTextureHeight() const {
return (int32_t)ceilf(height * density * textureScale);
}

}
4 changes: 4 additions & 0 deletions app/src/main/cpp/WidgetPlacement.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct WidgetPlacement {
bool showPointer;
bool firstDraw;
bool layer;
float textureScale;

int32_t GetTextureWidth() const;
int32_t GetTextureHeight() const;

static WidgetPlacementPtr FromJava(JNIEnv* aEnv, jobject& aObject);
private:
Expand Down

0 comments on commit ea63530

Please sign in to comment.