Repository: godotengine/godot
File: scene/main/viewport.cpp (C++)

Code before:

	if (use_xr != p_use_xr) {
		use_xr = p_use_xr;
		RS::get_singleton()->viewport_set_use_xr(viewport, use_xr);

#ifndef XR_DISABLED
		if (use_xr) {
			// Note: use_xr is ONLY used for the primary XR viewport.
			// Any additional (sub)viewports for composition layers and
			// other purposes should not have use_xr set.
			_check_xr_size();

			// Enable internal process as we need to check for recommended size changes each frame
			// (though size changes should only happen sporadically).
			set_process_internal(true);
		} else
#endif // XR_DISABLED
		{
			// No longer check for recommended size changes in internal process.
			set_process_internal(false);

			// Reset render target override textures.
			RID rt = RS::get_singleton()->viewport_get_render_target(viewport);
			RSG::texture_storage->render_target_set_override(rt, RID(), RID(), RID(), RID());

			// Q: Now that we properly set the size even when using XR,
			// this wouldn't do anything meaningful.
			// Set viewport to previous size when exiting XR.
			// if (size_allocated) {
			//	RS::get_singleton()->viewport_set_size(viewport, size.width, size.height);
			//} else {
			//	RS::get_singleton()->viewport_set_size(viewport, 0, 0);
			//}
		}

		notify_property_list_changed();
	}
}

bool Viewport::is_using_xr() const {
	ERR_READ_THREAD_GUARD_V(false);
	return use_xr;
}
#endif // XR_DISABLED

void Viewport::set_scaling_3d_mode(Scaling3DMode p_scaling_3d_mode) {
	ERR_MAIN_THREAD_GUARD;
	if (scaling_3d_mode == p_scaling_3d_mode) {
		return;
	}


Review comment (refactor):
I don't think this is needed anymore so we probably should remove this commented out code before merging.
Just want to get a bit more feedback in case I'm overlooking a scenario where we need to reset the size.

Code after:
}

#ifndef XR_DISABLED
void Viewport::set_use_xr(bool p_use_xr) {
	ERR_MAIN_THREAD_GUARD;

	if (use_xr != p_use_xr) {
		use_xr = p_use_xr;
		RS::get_singleton()->viewport_set_use_xr(viewport, use_xr);

#ifndef XR_DISABLED
		if (use_xr) {
			// Note: use_xr is ONLY used for the primary XR viewport.
			// Any additional (sub)viewports for composition layers and
			// other purposes should not have use_xr set.
			_check_xr_size();

			// Enable internal process as we need to check for recommended size changes each frame
			// (though size changes should only happen sporadically).
			set_process_internal(true);
		} else
#endif // XR_DISABLED
		{
			// No longer check for recommended size changes in internal process.
			set_process_internal(false);

			// Reset render target override textures.
			RID rt = RS::get_singleton()->viewport_get_render_target(viewport);
			RSG::texture_storage->render_target_set_override(rt, RID(), RID(), RID(), RID());
		}

		notify_property_list_changed();
	}
}

bool Viewport::is_using_xr() const {
	ERR_READ_THREAD_GUARD_V(false);
	return use_xr;
}
#endif // XR_DISABLED

void Viewport::set_scaling_3d_mode(Scaling3DMode p_scaling_3d_mode) {
	ERR_MAIN_THREAD_GUARD;
	if (scaling_3d_mode == p_scaling_3d_mode) {
		return;
	}

	scaling_3d_mode = p_scaling_3d_mode;
	RS::get_singleton()->viewport_set_scaling_3d_mode(viewport, (RS::ViewportScaling3DMode)(int)p_scaling_3d_mode);
}