Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shell/platform/android/android_shell_holder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class MockPlatformViewAndroidJNI : public PlatformViewAndroidJNI {
SurfaceTextureUpdateTexImage,
(JavaLocalRef surface_texture),
(override));
MOCK_METHOD(void,
MOCK_METHOD(SkM44,
SurfaceTextureGetTransformMatrix,
(JavaLocalRef surface_texture, SkMatrix& transform),
(JavaLocalRef surface_texture),
(override));
MOCK_METHOD(void,
SurfaceTextureDetachFromGLContext,
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/android/jni/jni_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class JNIMock final : public PlatformViewAndroidJNI {
(JavaLocalRef surface_texture),
(override));

MOCK_METHOD(void,
MOCK_METHOD(SkM44,
SurfaceTextureGetTransformMatrix,
(JavaLocalRef surface_texture, SkMatrix& transform),
(JavaLocalRef surface_texture),
(override));

MOCK_METHOD(JavaLocalRef,
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/android/jni/platform_view_android_jni.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class PlatformViewAndroidJNI {
/// Then, it updates the `transform` matrix, so it fill the canvas
/// and preserve the aspect ratio.
///
virtual void SurfaceTextureGetTransformMatrix(JavaLocalRef surface_texture,
SkMatrix& transform) = 0;
virtual SkM44 SurfaceTextureGetTransformMatrix(
JavaLocalRef surface_texture) = 0;

//----------------------------------------------------------------------------
/// @brief Detaches a SurfaceTexture from the OpenGL ES context.
Expand Down
43 changes: 9 additions & 34 deletions shell/platform/android/platform_view_android_jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1502,20 +1502,19 @@ void PlatformViewAndroidJNIImpl::SurfaceTextureUpdateTexImage(
FML_CHECK(fml::jni::CheckException(env));
}

void PlatformViewAndroidJNIImpl::SurfaceTextureGetTransformMatrix(
JavaLocalRef surface_texture,
SkMatrix& transform) {
SkM44 PlatformViewAndroidJNIImpl::SurfaceTextureGetTransformMatrix(
JavaLocalRef surface_texture) {
JNIEnv* env = fml::jni::AttachCurrentThread();

if (surface_texture.is_null()) {
return;
return {};
}

fml::jni::ScopedJavaLocalRef<jobject> surface_texture_local_ref(
env, env->CallObjectMethod(surface_texture.obj(),
g_java_weak_reference_get_method));
if (surface_texture_local_ref.is_null()) {
return;
return {};
}

fml::jni::ScopedJavaLocalRef<jfloatArray> transformMatrix(
Expand All @@ -1527,36 +1526,12 @@ void PlatformViewAndroidJNIImpl::SurfaceTextureGetTransformMatrix(

float* m = env->GetFloatArrayElements(transformMatrix.obj(), nullptr);

// SurfaceTexture 4x4 Column Major -> Skia 3x3 Row Major

// SurfaceTexture 4x4 (Column Major):
// | m[0] m[4] m[ 8] m[12] |
// | m[1] m[5] m[ 9] m[13] |
// | m[2] m[6] m[10] m[14] |
// | m[3] m[7] m[11] m[15] |

// According to Android documentation, the 4x4 matrix returned should be used
// with texture coordinates in the form (s, t, 0, 1). Since the z component is
// always 0.0, we are free to ignore any element that multiplies with the z
// component. Converting this to a 3x3 matrix is easy:

// SurfaceTexture 3x3 (Column Major):
// | m[0] m[4] m[12] |
// | m[1] m[5] m[13] |
// | m[3] m[7] m[15] |

// Skia (Row Major):
// | m[0] m[1] m[2] |
// | m[3] m[4] m[5] |
// | m[6] m[7] m[8] |

SkScalar matrix3[] = {
m[0], m[4], m[12], //
m[1], m[5], m[13], //
m[3], m[7], m[15], //
};
static_assert(sizeof(SkScalar) == sizeof(float));
const auto transform = SkM44::ColMajor(m);

env->ReleaseFloatArrayElements(transformMatrix.obj(), m, JNI_ABORT);
transform.set9(matrix3);

return transform;
}

void PlatformViewAndroidJNIImpl::SurfaceTextureDetachFromGLContext(
Expand Down
3 changes: 1 addition & 2 deletions shell/platform/android/platform_view_android_jni_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI {

void SurfaceTextureUpdateTexImage(JavaLocalRef surface_texture) override;

void SurfaceTextureGetTransformMatrix(JavaLocalRef surface_texture,
SkMatrix& transform) override;
SkM44 SurfaceTextureGetTransformMatrix(JavaLocalRef surface_texture) override;

void SurfaceTextureDetachFromGLContext(JavaLocalRef surface_texture) override;

Expand Down
9 changes: 4 additions & 5 deletions shell/platform/android/surface_texture_external_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void SurfaceTextureExternalTexture::DrawFrame(
PaintContext& context,
const SkRect& bounds,
const DlImageSampling sampling) const {
auto transform = GetCurrentUVTransformation();
auto transform = GetCurrentUVTransformation().asM33();

// Android's SurfaceTexture transform matrix works on texture coordinate
// lookups in the range 0.0-1.0, while Skia's Shader transform matrix works on
Expand Down Expand Up @@ -136,12 +136,11 @@ bool SurfaceTextureExternalTexture::ShouldUpdate() {
void SurfaceTextureExternalTexture::Update() {
jni_facade_->SurfaceTextureUpdateTexImage(
fml::jni::ScopedJavaLocalRef<jobject>(surface_texture_));
jni_facade_->SurfaceTextureGetTransformMatrix(
fml::jni::ScopedJavaLocalRef<jobject>(surface_texture_), transform_);
transform_ = jni_facade_->SurfaceTextureGetTransformMatrix(
fml::jni::ScopedJavaLocalRef<jobject>(surface_texture_));
}

const SkMatrix& SurfaceTextureExternalTexture::GetCurrentUVTransformation()
const {
const SkM44& SurfaceTextureExternalTexture::GetCurrentUVTransformation() const {
return transform_;
}

Expand Down
5 changes: 3 additions & 2 deletions shell/platform/android/surface_texture_external_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "flutter/common/graphics/texture.h"
#include "flutter/shell/platform/android/platform_view_android_jni_impl.h"
#include "flutter/third_party/skia/include/core/SkM44.h"

namespace flutter {

Expand Down Expand Up @@ -64,7 +65,7 @@ class SurfaceTextureExternalTexture : public flutter::Texture {
///
/// @return The current uv transformation.
///
const SkMatrix& GetCurrentUVTransformation() const;
const SkM44& GetCurrentUVTransformation() const;

//----------------------------------------------------------------------------
/// @brief Provides an opportunity for the subclasses to sever the
Expand Down Expand Up @@ -111,7 +112,7 @@ class SurfaceTextureExternalTexture : public flutter::Texture {
sk_sp<flutter::DlImage> dl_image_;

private:
SkMatrix transform_;
SkM44 transform_;

// |Texture|
void Paint(PaintContext& context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ void SurfaceTextureExternalTextureVKImpeller::ProcessFrame(
vk::ImageLayout::eColorAttachmentOptimal,
LayoutUpdateMode::kSync);

SkM44 transformation(GetCurrentUVTransformation());
impeller::Matrix uv_transformation;
transformation.getColMajor(reinterpret_cast<SkScalar*>(&uv_transformation));
GetCurrentUVTransformation().getColMajor(
reinterpret_cast<SkScalar*>(&uv_transformation));

glvk::Trampoline::GLTextureInfo src_texture;
src_texture.texture = src_gl_texture;
Expand Down