diff --git a/tools/mediaplayer/build.gradle b/tools/mediaplayer/build.gradle index 6c5097308..0637fae66 100644 --- a/tools/mediaplayer/build.gradle +++ b/tools/mediaplayer/build.gradle @@ -34,7 +34,7 @@ android { dependencies { implementation project(':wpe') - implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'androidx.appcompat:appcompat:1.7.0' modules { module("org.jetbrains.kotlin:kotlin-stdlib-jdk7") { diff --git a/wpe/src/main/cpp/Browser/Page.cpp b/wpe/src/main/cpp/Browser/Page.cpp index 7d49c16d4..8668b15af 100644 --- a/wpe/src/main/cpp/Browser/Page.cpp +++ b/wpe/src/main/cpp/Browser/Page.cpp @@ -127,8 +127,8 @@ class JNIPageCache final : public JNI::TypedClass { const JNI::Method m_onExitFullscreenMode; // NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members) - static jlong nativeInit( - JNIEnv* env, jobject obj, jlong wkWebContextPtr, jint width, jint height, jboolean headless); + static jlong nativeInit(JNIEnv* env, jobject obj, jlong wkWebContextPtr, jint width, jint height, + jfloat deviceScale, jboolean headless); static void nativeClose(JNIEnv* env, jobject obj, jlong pagePtr) noexcept; static void nativeDestroy(JNIEnv* env, jobject obj, jlong pagePtr) noexcept; static void nativeLoadUrl(JNIEnv* env, jobject obj, jlong pagePtr, jstring url) noexcept; @@ -168,7 +168,8 @@ JNIPageCache::JNIPageCache() , m_onEnterFullscreenMode(getMethod("onEnterFullscreenMode")) , m_onExitFullscreenMode(getMethod("onExitFullscreenMode")) { - registerNativeMethods(JNI::NativeMethod("nativeInit", JNIPageCache::nativeInit), + registerNativeMethods( + JNI::NativeMethod("nativeInit", JNIPageCache::nativeInit), JNI::NativeMethod("nativeClose", JNIPageCache::nativeClose), JNI::NativeMethod("nativeDestroy", JNIPageCache::nativeDestroy), JNI::NativeMethod("nativeLoadUrl", JNIPageCache::nativeLoadUrl), @@ -192,13 +193,13 @@ JNIPageCache::JNIPageCache() } jlong JNIPageCache::nativeInit( - JNIEnv* env, jobject obj, jlong wkWebContextPtr, jint width, jint height, jboolean headless) + JNIEnv* env, jobject obj, jlong wkWebContextPtr, jint width, jint height, jfloat deviceScale, jboolean headless) { - Logging::logDebug("Page::nativeInit(%p, %d, %d) [tid %d]", obj, width, height, gettid()); + Logging::logDebug("Page::nativeInit(%p, %d, %d, [density %f] [tid %d]", obj, width, height, deviceScale, gettid()); auto* wkWebContext = reinterpret_cast(wkWebContextPtr); // NOLINT(performance-no-int-to-ptr) // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - Page* page - = new Page(env, reinterpret_cast(obj), wkWebContext, width, height, static_cast(headless)); + Page* page = new Page( + env, reinterpret_cast(obj), wkWebContext, width, height, deviceScale, static_cast(headless)); return reinterpret_cast(page); } @@ -282,11 +283,14 @@ void JNIPageCache::nativeSurfaceChanged( Logging::logDebug("Page::nativeSurfaceChanged(%d, %d, %d) [tid %d]", format, width, height, gettid()); Page* page = reinterpret_cast(pagePtr); // NOLINT(performance-no-int-to-ptr) if ((page != nullptr) && (page->m_viewBackend != nullptr) && page->m_renderer) { - const uint32_t uWidth = std::max(0, width); - const uint32_t uHeight = std::max(0, height); + const uint32_t physicalWidth = std::max(0, width); + const uint32_t physicalHeight = std::max(0, height); + const uint32_t logicalWidth = std::floor(static_cast(physicalWidth) / page->deviceScale()); + const uint32_t logicalHeight = std::floor(static_cast(physicalHeight) / page->deviceScale()); + wpe_view_backend_dispatch_set_size( - WPEAndroidViewBackend_getWPEViewBackend(page->m_viewBackend), uWidth, uHeight); - page->m_renderer->onSurfaceChanged(format, uWidth, uHeight); + WPEAndroidViewBackend_getWPEViewBackend(page->m_viewBackend), logicalWidth, logicalHeight); + page->m_renderer->onSurfaceChanged(format, physicalWidth, physicalHeight); } } @@ -390,10 +394,12 @@ void JNIPageCache::nativeRequestExitFullscreenMode(JNIEnv* /*env*/, jobject /*ob void Page::configureJNIMappings() { getJNIPageCache(); } -Page::Page(JNIEnv* env, JNIPage jniPage, WKWebContext* wkWebContext, int width, int height, bool headless) +Page::Page( + JNIEnv* env, JNIPage jniPage, WKWebContext* wkWebContext, int width, int height, float deviceScale, bool headless) : m_pageJavaInstance(JNI::createTypedProtectedRef(env, jniPage, true)) , m_inputMethodContext(this) , m_isHeadless(headless) + , m_deviceScale(deviceScale) { const uint32_t uWidth = std::max(0, width); const uint32_t uHeight = std::max(0, height); @@ -427,6 +433,9 @@ Page::Page(JNIEnv* env, JNIPage jniPage, WKWebContext* wkWebContext, int width, wpeBackend, reinterpret_cast(JNIPageCache::onFullscreenRequest), this); WPEAndroidViewBackend_setCommitBufferHandler(m_viewBackend, this, handleCommitBuffer); + + wpe_view_backend_dispatch_set_device_scale_factor( + WPEAndroidViewBackend_getWPEViewBackend(m_viewBackend), deviceScale); } void Page::close() noexcept diff --git a/wpe/src/main/cpp/Browser/Page.h b/wpe/src/main/cpp/Browser/Page.h index fbd3b7208..c35ff572c 100644 --- a/wpe/src/main/cpp/Browser/Page.h +++ b/wpe/src/main/cpp/Browser/Page.h @@ -46,6 +46,7 @@ class Page final : public InputMethodContextObserver { void close() noexcept; + float deviceScale() const noexcept { return m_deviceScale; } WebKitWebView* webView() const noexcept { return m_webView; } void onInputMethodContextIn() noexcept override; @@ -56,7 +57,8 @@ class Page final : public InputMethodContextObserver { private: friend class JNIPageCache; - Page(JNIEnv* env, JNIPage jniPage, WKWebContext* wkWebContext, int width, int height, bool headless); + Page(JNIEnv* env, JNIPage jniPage, WKWebContext* wkWebContext, int width, int height, float deviceScale, + bool headless); JNI::ProtectedType m_pageJavaInstance; InputMethodContext m_inputMethodContext; @@ -67,4 +69,5 @@ class Page final : public InputMethodContextObserver { std::vector m_signalHandlers; bool m_isFullscreenRequested = false; bool m_isHeadless = false; + float m_deviceScale; }; diff --git a/wpe/src/main/java/com/wpe/wpe/Page.java b/wpe/src/main/java/com/wpe/wpe/Page.java index 438f1b914..204fd0ec4 100644 --- a/wpe/src/main/java/com/wpe/wpe/Page.java +++ b/wpe/src/main/java/com/wpe/wpe/Page.java @@ -27,6 +27,7 @@ import android.content.Context; import android.os.Handler; import android.os.Looper; +import android.util.DisplayMetrics; import android.util.Log; import android.view.MotionEvent; import android.view.ScaleGestureDetector; @@ -62,7 +63,7 @@ public final class Page { protected long nativePtr = 0; public long getNativePtr() { return nativePtr; } - private native long nativeInit(long nativeContextPtr, int width, int height, boolean headless); + private native long nativeInit(long nativeContextPtr, int width, int height, float deviceScale, boolean headless); private native void nativeClose(long nativePtr); private native void nativeDestroy(long nativePtr); private native void nativeLoadUrl(long nativePtr, @NonNull String url); @@ -109,7 +110,9 @@ public Page(@NonNull WPEView wpeView, @NonNull WKWebContext context, boolean hea height = kHeadlessHeight; } - nativePtr = nativeInit(context.getNativePtr(), width, height, headless); + DisplayMetrics displayMetrics = context.getApplicationContext().getResources().getDisplayMetrics(); + + nativePtr = nativeInit(context.getNativePtr(), width, height, displayMetrics.density, headless); Context ctx = wpeView.getContext(); surfaceView = new PageSurfaceView(ctx);