[GameSurfaceLayer] convert foo_ variable naming to mFoo (I hate this variable naming scheme and kept flip-flopping on it)

This commit is contained in:
amwatson 2024-02-08 18:50:10 -06:00
parent 2657b849ad
commit 751d38bcb0
4 changed files with 87 additions and 87 deletions

View file

@ -45,18 +45,18 @@ const std::vector<float> immersiveLevelFactor = {1.0f, 5.0f, 3.0f};
class AndroidWindowSpace {
public:
AndroidWindowSpace(const float widthInDp, const float heightInDp)
: widthInDp_(widthInDp), heightInDp_(heightInDp) {}
: mWidthInDp(widthInDp), mHeightInDp(heightInDp) {}
float Width() const {
return widthInDp_;
return mWidthInDp;
}
float Height() const {
return heightInDp_;
return mHeightInDp;
}
// "DP" refers to display pixels, which are the same as Android's
// "density-independent pixels" (dp).
const float widthInDp_ = 0;
const float heightInDp_ = 0;
const float mWidthInDp = 0;
const float mHeightInDp = 0;
// given a 2D point in worldspace 'point2d', returns the transformed
// coordinate in DP, written to 'result'
@ -226,17 +226,17 @@ XrPosef CreateTopPanelFromWorld(const XrVector3f& position) {
GameSurfaceLayer::GameSurfaceLayer(const XrVector3f&& position, JNIEnv* env, jobject activityObject,
const XrSession& session, const uint32_t resolutionFactor)
: session_(session), topPanelFromWorld_(CreateTopPanelFromWorld(position)),
lowerPanelFromWorld_(CreateLowerPanelFromWorld(topPanelFromWorld_)),
resolutionFactor_(resolutionFactor), immersiveMode_(VRSettings::values.vr_immersive_mode),
env_(env), activityObject_(activityObject)
: mSession(session), mTopPanelFromWorld(CreateTopPanelFromWorld(position)),
mLowerPanelFromWorld(CreateLowerPanelFromWorld(mTopPanelFromWorld)),
mResolutionFactor(resolutionFactor), mImmersiveMode(VRSettings::values.vr_immersive_mode),
mEnv(env), mActivityObject(activityObject)
{
assert(immersiveMode_ == 0 || immersiveMode_ == 1);
if (immersiveMode_ > 0) {
ALOGI("Using VR immersive mode {}", immersiveMode_);
topPanelFromWorld_.position.z = lowerPanelFromWorld_.position.z;
lowerPanelFromWorld_.position.y = -1.0f - (0.5f * (immersiveMode_ - 1));
assert(mImmersiveMode == 0 || mImmersiveMode == 1);
if (mImmersiveMode > 0) {
ALOGI("Using VR immersive mode {}", mImmersiveMode);
mTopPanelFromWorld.position.z = mLowerPanelFromWorld.position.z;
mLowerPanelFromWorld.position.y = -1.0f - (0.5f * (mImmersiveMode - 1));
}
const int32_t initializationStatus = Init(activityObject, position, session);
if (initializationStatus < 0) {
@ -249,28 +249,28 @@ GameSurfaceLayer::~GameSurfaceLayer() {
}
void GameSurfaceLayer::SetSurface() const {
assert(vrGameSurfaceClass_ != nullptr);
assert(mVrGameSurfaceClass != nullptr);
const jmethodID setSurfaceMethodID =
env_->GetStaticMethodID(vrGameSurfaceClass_, "setSurface",
mEnv->GetStaticMethodID(mVrGameSurfaceClass, "setSurface",
"(Lorg/citra/citra_emu/vr/VrActivity;Landroid/view/Surface;)V");
if (setSurfaceMethodID == nullptr) {
FAIL("Couldn't find setSurface()");
}
env_->CallStaticVoidMethod(vrGameSurfaceClass_, setSurfaceMethodID, activityObject_, surface_);
mEnv->CallStaticVoidMethod(mVrGameSurfaceClass, setSurfaceMethodID, mActivityObject, mSurface);
}
void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLayer>& layers,
uint32_t& layerCount) const
{
const uint32_t panelWidth = swapchain_.Width / 2;
const uint32_t panelHeight = swapchain_.Height / 2;
const uint32_t panelWidth = mSwapchain.Width / 2;
const uint32_t panelHeight = mSwapchain.Height / 2;
const double aspectRatio =
static_cast<double>(2 * panelWidth) / static_cast<double>(panelHeight);
// Prevent a seam between the top and bottom view
constexpr uint32_t verticalBorderTex = 1;
const bool useCylinder = (GetCylinderSysprop() != 0) || (immersiveMode_ > 0);
const bool useCylinder = (GetCylinderSysprop() != 0) || (mImmersiveMode > 0);
if (useCylinder) {
// Create the Top Display Panel (Curved display)
@ -287,13 +287,13 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
layer.eyeVisibility = eye == 0 ? XR_EYE_VISIBILITY_LEFT : XR_EYE_VISIBILITY_RIGHT;
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
layer.subImage.swapchain = swapchain_.Handle;
layer.subImage.swapchain = mSwapchain.Handle;
layer.subImage.imageRect.offset.x = eye == 0 ? 0 : panelWidth;
layer.subImage.imageRect.offset.y = 0;
layer.subImage.imageRect.extent.width = panelWidth;
layer.subImage.imageRect.extent.height = panelHeight - verticalBorderTex;
layer.subImage.imageArrayIndex = 0;
layer.pose = topPanelFromWorld_;
layer.pose = mTopPanelFromWorld;
layer.pose.position.z += GetRadiusSysprop();
// Radius effectively controls the width of the cylinder shape.
@ -302,8 +302,8 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
// scale of the texture.
const float radius = GetRadiusSysprop();
layer.radius = radius;
layer.centralAngle = (!immersiveMode_ ? GetCentralAngleSysprop()
: 55.0f * immersiveLevelFactor[immersiveMode_]) *
layer.centralAngle = (!mImmersiveMode ? GetCentralAngleSysprop()
: 55.0f * immersiveLevelFactor[mImmersiveMode]) *
MATH_FLOAT_PI / 180.0f;
layer.aspectRatio = -aspectRatio;
layers[layerCount++].mCylinder = layer;
@ -311,7 +311,7 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
} else {
// Create the Top Display Panel (Flat display)
for (uint32_t eye = 0; eye < 2; eye++) {
const uint32_t cropHoriz = 50 * resolutionFactor_;
const uint32_t cropHoriz = 50 * mResolutionFactor;
XrCompositionLayerQuad layer = {};
layer.type = XR_TYPE_COMPOSITION_LAYER_QUAD;
@ -324,17 +324,17 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
layer.eyeVisibility = eye == 0 ? XR_EYE_VISIBILITY_LEFT : XR_EYE_VISIBILITY_RIGHT;
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
layer.subImage.swapchain = swapchain_.Handle;
layer.subImage.swapchain = mSwapchain.Handle;
layer.subImage.imageRect.offset.x = (eye == 0 ? 0 : panelWidth) + cropHoriz / 2;
layer.subImage.imageRect.offset.y = 0;
layer.subImage.imageRect.extent.width = panelWidth - cropHoriz;
layer.subImage.imageRect.extent.height = panelHeight - verticalBorderTex;
layer.subImage.imageArrayIndex = 0;
layer.pose = topPanelFromWorld_;
layer.pose = mTopPanelFromWorld;
// Scale to get the desired density within the visible area (if we
// want).
const auto scale = GetDensityScaleForSize(panelWidth - cropHoriz, -panelHeight, 1.0f,
resolutionFactor_);
mResolutionFactor);
layer.size.width = scale.x;
layer.size.height = scale.y;
@ -349,7 +349,7 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
// waste rendering time copying the buffer between runtimes. No time for
// that now!
{
const uint32_t cropHoriz = 90 * resolutionFactor_;
const uint32_t cropHoriz = 90 * mResolutionFactor;
XrCompositionLayerQuad layer = {};
layer.type = XR_TYPE_COMPOSITION_LAYER_QUAD;
@ -362,20 +362,20 @@ void GameSurfaceLayer::Frame(const XrSpace& space, std::vector<XrCompositionLaye
layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH;
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
layer.subImage.swapchain = swapchain_.Handle;
layer.subImage.swapchain = mSwapchain.Handle;
layer.subImage.imageRect.offset.x =
(cropHoriz / 2) / immersiveLevelFactor[immersiveMode_] +
panelWidth * (0.5f - (0.5f / immersiveLevelFactor[immersiveMode_]));
(cropHoriz / 2) / immersiveLevelFactor[mImmersiveMode] +
panelWidth * (0.5f - (0.5f / immersiveLevelFactor[mImmersiveMode]));
layer.subImage.imageRect.offset.y =
panelHeight + verticalBorderTex +
panelHeight * (0.5f - (0.5f / immersiveLevelFactor[immersiveMode_]));
panelHeight * (0.5f - (0.5f / immersiveLevelFactor[mImmersiveMode]));
layer.subImage.imageRect.extent.width =
(panelWidth - cropHoriz) / immersiveLevelFactor[immersiveMode_];
layer.subImage.imageRect.extent.height = panelHeight / immersiveLevelFactor[immersiveMode_];
(panelWidth - cropHoriz) / immersiveLevelFactor[mImmersiveMode];
layer.subImage.imageRect.extent.height = panelHeight / immersiveLevelFactor[mImmersiveMode];
layer.subImage.imageArrayIndex = 0;
layer.pose = lowerPanelFromWorld_;
layer.pose = mLowerPanelFromWorld;
const auto scale = GetDensityScaleForSize(panelWidth - cropHoriz, -panelHeight,
lowerPanelScaleFactor, resolutionFactor_);
lowerPanelScaleFactor, mResolutionFactor);
layer.size.width = scale.x;
layer.size.height = scale.y;
layers[layerCount++].mQuad = layer;
@ -388,20 +388,20 @@ bool GameSurfaceLayer::GetRayIntersectionWithPanelTopPanel(const XrVector3f& sta
XrPosef& result3d) const
{
const uint32_t panelWidth = swapchain_.Width / 2;
const uint32_t panelHeight = swapchain_.Height / 2;
const auto scale = GetDensityScaleForSize(panelWidth, panelHeight, 1.0f, resolutionFactor_);
return ::GetRayIntersectionWithPanel(topPanelFromWorld_, panelWidth, panelHeight, scale, start,
const uint32_t panelWidth = mSwapchain.Width / 2;
const uint32_t panelHeight = mSwapchain.Height / 2;
const auto scale = GetDensityScaleForSize(panelWidth, panelHeight, 1.0f, mResolutionFactor);
return ::GetRayIntersectionWithPanel(mTopPanelFromWorld, panelWidth, panelHeight, scale, start,
end, result2d, result3d);
}
bool GameSurfaceLayer::GetRayIntersectionWithPanel(const XrVector3f& start, const XrVector3f& end,
XrVector2f& result2d, XrPosef& result3d) const {
const uint32_t panelWidth = swapchain_.Width / 2;
const uint32_t panelHeight = swapchain_.Height / 2;
const uint32_t panelWidth = mSwapchain.Width / 2;
const uint32_t panelHeight = mSwapchain.Height / 2;
const XrVector2f scale =
GetDensityScaleForSize(panelWidth, panelHeight, lowerPanelScaleFactor, resolutionFactor_);
return ::GetRayIntersectionWithPanel(lowerPanelFromWorld_, panelWidth, panelHeight, scale,
GetDensityScaleForSize(panelWidth, panelHeight, lowerPanelScaleFactor, mResolutionFactor);
return ::GetRayIntersectionWithPanel(mLowerPanelFromWorld, panelWidth, panelHeight, scale,
start, end, result2d, result3d);
}
@ -409,7 +409,7 @@ void GameSurfaceLayer::SetTopPanelFromController(const XrVector3f& controllerPos
static const XrVector3f viewerPosition{0, 0, 0}; // Set viewer position
const float sphereRadius = XrMath::Vector3f::Length(
topPanelFromWorld_.position - viewerPosition); // Set the initial distance of the
mTopPanelFromWorld.position - viewerPosition); // Set the initial distance of the
// window from the viewer
const XrVector3f windowUpDirection{0, 1, 0}; // Y is up
@ -425,7 +425,7 @@ void GameSurfaceLayer::SetTopPanelFromController(const XrVector3f& controllerPos
return;
}
topPanelFromWorld_ = XrPosef{windowRotation, windowPosition};
mTopPanelFromWorld = XrPosef{windowRotation, windowPosition};
}
// based on thumbstick, modify the depth of the top panel
@ -433,19 +433,19 @@ void GameSurfaceLayer::SetTopPanelFromThumbstick(const float thumbstickY) {
static constexpr float kDepthSpeed = 0.05f;
static constexpr float kMaxDepth = -10.0f;
topPanelFromWorld_.position.z -= (thumbstickY * kDepthSpeed);
topPanelFromWorld_.position.z =
std::min(topPanelFromWorld_.position.z, lowerPanelFromWorld_.position.z);
topPanelFromWorld_.position.z = std::max(topPanelFromWorld_.position.z, kMaxDepth);
mTopPanelFromWorld.position.z -= (thumbstickY * kDepthSpeed);
mTopPanelFromWorld.position.z =
std::min(mTopPanelFromWorld.position.z, mLowerPanelFromWorld.position.z);
mTopPanelFromWorld.position.z = std::max(mTopPanelFromWorld.position.z, kMaxDepth);
}
// Next error code: -2
int32_t GameSurfaceLayer::Init(const jobject activityObject, const XrVector3f& position,
const XrSession& session) {
static const std::string gameSurfaceClassName = "org/citra/citra_emu/vr/GameSurfaceLayer";
vrGameSurfaceClass_ =
JniUtils::GetGlobalClassReference(env_, activityObject, gameSurfaceClassName.c_str());
BAIL_ON_COND(vrGameSurfaceClass_ == nullptr, "No java Game Surface Layer class", -1);
mVrGameSurfaceClass =
JniUtils::GetGlobalClassReference(mEnv, activityObject, gameSurfaceClassName.c_str());
BAIL_ON_COND(mVrGameSurfaceClass == nullptr, "No java Game Surface Layer class", -1);
CreateSwapchain();
SetSurface();
@ -453,9 +453,9 @@ int32_t GameSurfaceLayer::Init(const jobject activityObject, const XrVector3f& p
}
void GameSurfaceLayer::Shutdown() {
xrDestroySwapchain(swapchain_.Handle);
xrDestroySwapchain(mSwapchain.Handle);
// This currently causes a memory exception
// env_->DeleteGlobalRef(vrGameSurfaceClass_);
// mEnv->DeleteGlobalRef(mVrGameSurfaceClass);
}
void GameSurfaceLayer::CreateSwapchain() {
@ -468,8 +468,8 @@ void GameSurfaceLayer::CreateSwapchain() {
xsci.usageFlags = XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT;
xsci.format = 0;
xsci.sampleCount = 0;
xsci.width = SURFACE_WIDTH_UNSCALED * resolutionFactor_;
xsci.height = SURFACE_HEIGHT_UNSCALED * resolutionFactor_;
xsci.width = SURFACE_WIDTH_UNSCALED * mResolutionFactor;
xsci.height = SURFACE_HEIGHT_UNSCALED * mResolutionFactor;
xsci.faceCount = 0;
xsci.arraySize = 0;
@ -480,7 +480,7 @@ void GameSurfaceLayer::CreateSwapchain() {
ALOGI("GameSurfaceLayer: Creating swapchain of size {}x{} ({}x{} with resolution factor {}x)",
xsci.width, xsci.height, SURFACE_WIDTH_UNSCALED, SURFACE_HEIGHT_UNSCALED,
resolutionFactor_);
mResolutionFactor);
PFN_xrCreateSwapchainAndroidSurfaceKHR pfnCreateSwapchainAndroidSurfaceKHR = nullptr;
assert(OpenXr::GetInstance() != XR_NULL_HANDLE);
@ -492,7 +492,7 @@ void GameSurfaceLayer::CreateSwapchain() {
"xrCreateSwapchainAndroidSurfaceKHR");
}
OXR(pfnCreateSwapchainAndroidSurfaceKHR(session_, &xsci, &swapchain_.Handle, &surface_));
swapchain_.Width = xsci.width;
swapchain_.Height = xsci.height;
OXR(pfnCreateSwapchainAndroidSurfaceKHR(mSession, &xsci, &mSwapchain.Handle, &mSurface));
mSwapchain.Width = xsci.width;
mSwapchain.Height = xsci.height;
}

View file

@ -148,15 +148,15 @@ private:
static_assert((SURFACE_WIDTH_UNSCALED % 2) == 0, "Swapchain width must be a multiple of 2");
static_assert((SURFACE_HEIGHT_UNSCALED % 2) == 0, "Swapchain height must be a multiple of 2");
const XrSession session_;
Swapchain swapchain_;
const XrSession mSession;
Swapchain mSwapchain;
XrPosef topPanelFromWorld_;
XrPosef lowerPanelFromWorld_;
XrPosef mTopPanelFromWorld;
XrPosef mLowerPanelFromWorld;
// Density scale for surface. Citra's auto-scale sets this as the internal
// resolution.
const uint32_t resolutionFactor_;
const uint32_t mResolutionFactor;
// EXPERIMENTAL: When true, the top screen + its extents
// (previously-unseen parts of the scene) are projected onto a 275-degree
@ -168,12 +168,12 @@ private:
// performance optimizations to avoid maxing out the GPU, e.g.:
// - Multiview (requires a merged Citra/CitraVR renderer)
// - Rendering the top-screen and bottom screen separately.
const uint32_t immersiveMode_;
const uint32_t mImmersiveMode;
//============================
// JNI objects
JNIEnv* env_ = nullptr;
jobject activityObject_ = nullptr;
jclass vrGameSurfaceClass_ = nullptr;
jobject surface_ = nullptr;
JNIEnv* mEnv = nullptr;
jobject mActivityObject = nullptr;
jclass mVrGameSurfaceClass = nullptr;
jobject mSurface = nullptr;
};

View file

@ -74,8 +74,6 @@ public:
}
};
struct BoundsHandle {
BoundsHandle(AndroidWindowBounds* _p) : p(_p) {}
BoundsHandle(jlong _l) : l(_l) {}
@ -133,8 +131,8 @@ bool GetRayIntersectionWithPanel(const XrPosef& panelFromWorld, const uint32_t p
const AndroidWindowBounds viewBounds(panelWidth, panelHeight);
viewBounds.Transform(result2dNDC, result2d);
const bool isInBounds = result2d.x >= 0 && result2d.y >= 0 &&
result2d.x < viewBounds.Width() && result2d.y < viewBounds.Height();
const bool isInBounds = result2d.x >= 0 && result2d.y >= 0 && result2d.x < viewBounds.Width() &&
result2d.y < viewBounds.Height();
result2d.y += viewBounds.Height();
if (!isInBounds) {
@ -243,8 +241,8 @@ void UILayer::TryCreateSwapchain() {
AndroidWindowBounds viewBounds;
{
const jint ret = env_->CallIntMethod(vrUILayerObject_, getBoundsMethodID_,
BoundsHandle(&viewBounds).l);
const jint ret =
env_->CallIntMethod(vrUILayerObject_, getBoundsMethodID_, BoundsHandle(&viewBounds).l);
if (ret < 0) {
ALOGD("getBoundsForView() returned error %d", ret);
return;
@ -286,8 +284,8 @@ void UILayer::TryCreateSwapchain() {
if (setSurfaceMethodId == nullptr) {
FAIL("Couldn't find setSurface()");
}
env_->CallIntMethod(vrUILayerObject_, setSurfaceMethodId, surface_,
(int)viewBounds.Width(), (int)viewBounds.Height());
env_->CallIntMethod(vrUILayerObject_, setSurfaceMethodId, surface_, (int)viewBounds.Width(),
(int)viewBounds.Height());
}
isSwapchainCreated_ = true;

View file

@ -7,15 +7,14 @@
class UILayer {
public:
/** Constructor.
* @param position: position of the layer, in world space
* @param activity object: reference to the current activity. Used to get
* the class information for gameSurfaceClass
* @param session a valid XrSession
*/
UILayer(const std::string& className, const XrVector3f&& position, JNIEnv* jni, jobject activityObject,
const XrSession& session);
UILayer(const std::string& className, const XrVector3f&& position, JNIEnv* jni,
jobject activityObject, const XrSession& session);
~UILayer();
/** Called on resume. Sets the surface in the native rendering library.
@ -58,16 +57,19 @@ public:
/** Returns whether the swapchain is created
*/
bool IsSwapchainCreated() const { return isSwapchainCreated_; }
bool IsSwapchainCreated() const {
return isSwapchainCreated_;
}
/** Creates the swapchain.
*/
void TryCreateSwapchain();
void SendClickToUI(const XrVector2f& pos2d, const int type);
private:
int Init(const std::string& className, const jobject activityObject, const XrVector3f& position, const XrSession& session);
int Init(const std::string& className, const jobject activityObject, const XrVector3f& position,
const XrSession& session);
void Shutdown();
const XrSession session_;
@ -92,6 +94,6 @@ private:
// the decorView representing an entire window, it's important to accont for the
// x, y offset of the view within the window, in case there are things like
// window decorations or status bars.
jmethodID getBoundsMethodID_ = nullptr;
jmethodID getBoundsMethodID_ = nullptr;
jmethodID sendClickToWindowMethodID_ = nullptr;
};