Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native implementation of Engine.setHardwareScalingRatio #566

Merged
merged 18 commits into from
Jan 13, 2021

Conversation

Drigax
Copy link
Contributor

@Drigax Drigax commented Jan 8, 2021

This PR implements and adds boilerplate to expose NativeEngine.getHardwareScalingRatio.

Render scaling is implemented via a scalar used to resize bgfx's rendering resolution.

Addresses #482

Plugins/NativeEngine/Source/NativeEngine.cpp Outdated Show resolved Hide resolved
Core/Graphics/Source/Graphics.cpp Outdated Show resolved Hide resolved
Core/Graphics/Source/Graphics.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@syntheticmagus syntheticmagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than two minor considerations, looks good to me.

m_state.Resolution.width = width;
m_state.Resolution.height = height;
}
UpdateBgfxResolution();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: In both places where this is called, the state mutex is locked immediately before calling it, then that lock is abandoned, then it's locked again inside the call. If the contract for this method became that it's unsafe (maybe by putting it on the struct and/or calling it UnsafeUpdate...()?) then we could just move the call inside the scope of the outer lock and not need to lock, unlock, and relock. Honestly, I'm not sure about this one; the two locks feel unnecessary, but making a helper method which exists exclusively to modify mutex-guarded state, then making that helper method explicitly unguarded, also feels kind of weird. Do we know if it's meaningfully worse perf-wise to just leave in the two locks?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just replace mutex with recursive_mutex which allows for re-entrancy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use lock_guard instead of scoped_lock here. scoped_lock is just a helper for locking on multiple mutexes in an raii fashion, but we’re only locking on one mutex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good suggestion, that definitely removes the need for awkward block scoping to prevent re-locking the same mutex in the caller.

I'm going to keep with scoped_lock, I'm not sure if there's anything to gain in using the older lock implementation, I was under the impression that this supplanted lock_guard

Core/Graphics/Source/Graphics.cpp Outdated Show resolved Hide resolved
@Drigax Drigax merged commit 2c75587 into BabylonJS:master Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants