void ISurfaceHolderCallback.SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height)
{
if ((int)Android.OS.Build.VERSION.SdkInt >= 19)
{
if (!_isSurfaceChanged)
{
_isSurfaceChanged = true;
_prevSurfaceWidth = width;
_prevSurfaceHeight = height;
}
else
{
// Forcing reinitialization of the view if SurfaceChanged() is called more than once to fix shifted drawing on KitKat.
// See https://github.com/mono/MonoGame/issues/2492.
if (!ScreenReceiver.ScreenLocked && Game.Instance.Platform.IsActive &&
(_prevSurfaceWidth != width || _prevSurfaceHeight != height))
{
_prevSurfaceWidth = width;
_prevSurfaceHeight = height;
base.SurfaceDestroyed(holder);
base.SurfaceCreated(holder);
}
}
}
// When the game is resumed from a portrait orientation it may receive a portrait surface at first.
// If the game does not support portrait we should ignore it because we will receive the landscape surface a moment later.
if (width < height && (_game.graphicsDeviceManager.SupportedOrientations & DisplayOrientation.Portrait) == 0)
{
return;
}
var manager = _game.graphicsDeviceManager;
manager.PreferredBackBufferWidth = width;
manager.PreferredBackBufferHeight = height;
if (manager.GraphicsDevice != null)
{
manager.GraphicsDevice.Viewport = new Viewport(0, 0, width, height);
}
_gameWindow.ChangeClientBounds(new Rectangle(0, 0, width, height));
manager.ApplyChanges();
SurfaceChanged(holder, format, width, height);
Android.Util.Log.Debug("MonoGame", "MonoGameAndroidGameView.SurfaceChanged: format = " + format + ", width = " + width + ", height = " + height);
if (_game.GraphicsDevice != null)
{
_game.graphicsDeviceManager.ResetClientBounds();
}
}