diff --git a/shell/platform/android/android_external_texture_gl.cc b/shell/platform/android/android_external_texture_gl.cc index 0acd0c8337d25f14da5fa8374644f5befee9fa04..935f60b455797b5d8444a740c9635146b80bd5e4 100644 --- a/shell/platform/android/android_external_texture_gl.cc +++ b/shell/platform/android/android_external_texture_gl.cc @@ -68,6 +68,18 @@ void AndroidExternalTextureGL::Paint(SkCanvas& canvas, } } +// The bounds we set for the canvas are post composition. +// To fill the canvas we need to ensure that the transformation matrix +// on the `SurfaceTexture` will be scaled to fill. We rescale and preseve +// the scaled aspect ratio. +SkSize ScaleToFill(float scaleX, float scaleY) { + const double epsilon = std::numeric_limits::epsilon(); + // scaleY is negative. + const double minScale = fmin(scaleX, fabs(scaleY)); + const double rescale = 1.0f / (minScale + epsilon); + return SkSize::Make(scaleX * rescale, scaleY * rescale); +} + void AndroidExternalTextureGL::UpdateTransform() { JNIEnv* env = fml::jni::AttachCurrentThread(); fml::jni::ScopedJavaLocalRef surfaceTexture = @@ -77,10 +89,12 @@ void AndroidExternalTextureGL::UpdateTransform() { SurfaceTextureGetTransformMatrix(env, surfaceTexture.obj(), transformMatrix.obj()); float* m = env->GetFloatArrayElements(transformMatrix.obj(), nullptr); + float scaleX = m[0], scaleY = m[5]; + const SkSize scaled = ScaleToFill(scaleX, scaleY); SkScalar matrix3[] = { - m[0], m[1], m[2], // - m[4], m[5], m[6], // - m[8], m[9], m[10], // + scaled.fWidth, m[1], m[2], // + m[4], scaled.fHeight, m[6], // + m[8], m[9], m[10], // }; env->ReleaseFloatArrayElements(transformMatrix.obj(), m, JNI_ABORT); transform.set9(matrix3);