From 727f47c2540d4c1c032c9e8e968994ac9ab0824d Mon Sep 17 00:00:00 2001 From: Niklas Schulze Date: Sat, 17 Feb 2024 18:35:12 +0100 Subject: [PATCH] Remove TextureBridgeFallback --- windows/CMakeLists.txt | 23 +-- windows/texture_bridge_fallback.cc | 135 ------------ windows/texture_bridge_fallback.h | 27 --- windows/util/cpuid/cpuinfo.cc | 80 -------- windows/util/cpuid/cpuinfo.h | 105 ---------- windows/util/cpuid/detail/cpuinfo_impl.h | 69 ------- windows/util/cpuid/detail/extract_x86_flags.h | 43 ---- windows/util/cpuid/detail/init_msvc_x86.h | 36 ---- windows/util/cpuid/detail/init_unknown.h | 9 - windows/util/swizzle.h | 192 ------------------ windows/webview_bridge.cc | 19 +- 11 files changed, 4 insertions(+), 734 deletions(-) delete mode 100644 windows/texture_bridge_fallback.cc delete mode 100644 windows/texture_bridge_fallback.h delete mode 100644 windows/util/cpuid/cpuinfo.cc delete mode 100644 windows/util/cpuid/cpuinfo.h delete mode 100644 windows/util/cpuid/detail/cpuinfo_impl.h delete mode 100644 windows/util/cpuid/detail/extract_x86_flags.h delete mode 100644 windows/util/cpuid/detail/init_msvc_x86.h delete mode 100644 windows/util/cpuid/detail/init_unknown.h delete mode 100644 windows/util/swizzle.h diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 8989c40..5389db2 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -45,6 +45,7 @@ add_library(${PLUGIN_NAME} SHARED "webview_host.cc" "webview_bridge.cc" "texture_bridge.cc" + "texture_bridge_gpu.cc" "graphics_context.cc" "util/direct3d11.interop.cc" "util/rohelper.cc" @@ -52,27 +53,7 @@ add_library(${PLUGIN_NAME} SHARED ) if(MSVC) - target_compile_options(${PLUGIN_NAME} PRIVATE "/await") -endif() - -if(NOT FLUTTER_WEBVIEW_WINDOWS_USE_TEXTURE_FALLBACK) - message(STATUS "Building with D3D texture support.") - target_compile_definitions("${PLUGIN_NAME}" PRIVATE - HAVE_FLUTTER_D3D_TEXTURE - ) - target_sources("${PLUGIN_NAME}" PRIVATE - "texture_bridge_gpu.cc" - ) -else() - message(STATUS "Building with fallback PixelBuffer texture.") - target_sources("${PLUGIN_NAME}" PRIVATE - "texture_bridge_fallback.cc" - "util/cpuid/cpuinfo.cc" - ) - # Enable AVX2 for pixel buffer conversions - if(MSVC) - target_compile_options(${PLUGIN_NAME} PRIVATE "/arch:AVX2" "/await") - endif() + target_compile_options(${PLUGIN_NAME} PRIVATE "/await") endif() apply_standard_settings(${PLUGIN_NAME}) diff --git a/windows/texture_bridge_fallback.cc b/windows/texture_bridge_fallback.cc deleted file mode 100644 index d5731f7..0000000 --- a/windows/texture_bridge_fallback.cc +++ /dev/null @@ -1,135 +0,0 @@ -#include "texture_bridge_fallback.h" - -#include - -#include "util/direct3d11.interop.h" -#include "util/swizzle.h" - -TextureBridgeFallback::TextureBridgeFallback( - GraphicsContext* graphics_context, - ABI::Windows::UI::Composition::IVisual* visual) - : TextureBridge(graphics_context, visual) {} - -TextureBridgeFallback::~TextureBridgeFallback() { - const std::lock_guard lock(buffer_mutex_); -} - -void TextureBridgeFallback::ProcessFrame( - winrt::com_ptr src_texture) { - D3D11_TEXTURE2D_DESC desc; - src_texture->GetDesc(&desc); - - const auto width = desc.Width; - const auto height = desc.Height; - - bool is_exact_size; - EnsureStagingTexture(width, height, is_exact_size); - - auto device_context = graphics_context_->d3d_device_context(); - auto staging_texture = staging_texture_.get(); - - if (is_exact_size) { - device_context->CopyResource(staging_texture, src_texture.get()); - } else { - D3D11_BOX client_box; - client_box.top = 0; - client_box.left = 0; - client_box.right = width; - client_box.bottom = height; - client_box.front = 0; - client_box.back = 1; - device_context->CopySubresourceRegion(staging_texture, 0, 0, 0, 0, - src_texture.get(), 0, &client_box); - } - - D3D11_MAPPED_SUBRESOURCE mappedResource; - if (!SUCCEEDED(device_context->Map(staging_texture, 0, D3D11_MAP_READ, 0, - &mappedResource))) { - return; - } - - { - const std::lock_guard lock(buffer_mutex_); - if (!pixel_buffer_ || pixel_buffer_->width != width || - pixel_buffer_->height != height) { - if (!pixel_buffer_) { - pixel_buffer_ = std::make_unique(); - pixel_buffer_->release_context = &buffer_mutex_; - // Gets invoked after the FlutterDesktopPixelBuffer's - // backing buffer has been uploaded. - pixel_buffer_->release_callback = [](void* opaque) { - auto mutex = reinterpret_cast(opaque); - // Gets locked just before |CopyPixelBuffer| returns. - mutex->unlock(); - }; - } - pixel_buffer_->width = width; - pixel_buffer_->height = height; - const auto size = width * height * 4; - backing_pixel_buffer_.reset(new uint8_t[size]); - pixel_buffer_->buffer = backing_pixel_buffer_.get(); - } - - const auto src_pitch_in_pixels = mappedResource.RowPitch / 4; - RGBA_to_BGRA(reinterpret_cast(backing_pixel_buffer_.get()), - static_cast(mappedResource.pData), height, - src_pitch_in_pixels, width); - } - - device_context->Unmap(staging_texture, 0); -} - -void TextureBridgeFallback::EnsureStagingTexture(uint32_t width, - uint32_t height, - bool& is_exact_size) { - // Only recreate an existing texture if it's too small. - if (!staging_texture_ || staging_texture_size_.width < width || - staging_texture_size_.height < height) { - D3D11_TEXTURE2D_DESC dstDesc = {}; - dstDesc.ArraySize = 1; - dstDesc.MipLevels = 1; - dstDesc.BindFlags = 0; - dstDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - dstDesc.Format = static_cast(kPixelFormat); - dstDesc.Width = width; - dstDesc.Height = height; - dstDesc.MiscFlags = 0; - dstDesc.SampleDesc.Count = 1; - dstDesc.SampleDesc.Quality = 0; - dstDesc.Usage = D3D11_USAGE_STAGING; - - staging_texture_ = nullptr; - if (!SUCCEEDED(graphics_context_->d3d_device()->CreateTexture2D( - &dstDesc, nullptr, staging_texture_.put()))) { - std::cerr << "Creating dst texture failed" << std::endl; - return; - } - - staging_texture_size_ = {width, height}; - } - - is_exact_size = staging_texture_size_.width == width && - staging_texture_size_.height == height; -} - -const FlutterDesktopPixelBuffer* TextureBridgeFallback::CopyPixelBuffer( - size_t width, size_t height) { - const std::lock_guard lock(mutex_); - - if (!is_running_) { - return nullptr; - } - - if (last_frame_) { - ProcessFrame(last_frame_); - } - - auto buffer = pixel_buffer_.get(); - // Only lock the mutex if the buffer is not null - // (to ensure the release callback gets called) - if (buffer) { - // Gets unlocked in the FlutterDesktopPixelBuffer's release callback. - buffer_mutex_.lock(); - } - return buffer; -} diff --git a/windows/texture_bridge_fallback.h b/windows/texture_bridge_fallback.h deleted file mode 100644 index 05b50c5..0000000 --- a/windows/texture_bridge_fallback.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -#include - -#include "texture_bridge.h" - -class TextureBridgeFallback : public TextureBridge { - public: - TextureBridgeFallback(GraphicsContext* graphics_context, - ABI::Windows::UI::Composition::IVisual* visual); - ~TextureBridgeFallback() override; - - const FlutterDesktopPixelBuffer* CopyPixelBuffer(size_t width, size_t height); - - private: - Size staging_texture_size_ = {0, 0}; - winrt::com_ptr staging_texture_{nullptr}; - std::mutex buffer_mutex_; - std::unique_ptr backing_pixel_buffer_; - std::unique_ptr pixel_buffer_; - - void ProcessFrame(winrt::com_ptr src_texture); - void EnsureStagingTexture(uint32_t width, uint32_t height, - bool& is_exact_size); -}; diff --git a/windows/util/cpuid/cpuinfo.cc b/windows/util/cpuid/cpuinfo.cc deleted file mode 100644 index acee343..0000000 --- a/windows/util/cpuid/cpuinfo.cc +++ /dev/null @@ -1,80 +0,0 @@ -#include "cpuinfo.h" - -#include "detail/cpuinfo_impl.h" - -#if defined(_MSC_VER) && (defined(__x86_64__) || defined(_M_X64)) -#include "detail/init_msvc_x86.h" -#else -#include "detail/init_unknown.hpp" -#endif - -namespace cpuid { - -cpuinfo::cpuinfo() : impl_(new impl) { init_cpuinfo(*impl_); } - -cpuinfo::~cpuinfo() {} - -// x86 member functions -bool cpuinfo::has_fpu() const { return impl_->m_has_fpu; } - -bool cpuinfo::has_mmx() const { return impl_->m_has_mmx; } - -bool cpuinfo::has_sse() const { return impl_->m_has_sse; } - -bool cpuinfo::has_sse2() const { return impl_->m_has_sse2; } - -bool cpuinfo::has_sse3() const { return impl_->m_has_sse3; } - -bool cpuinfo::has_ssse3() const { return impl_->m_has_ssse3; } - -bool cpuinfo::has_sse4_1() const { return impl_->m_has_sse4_1; } - -bool cpuinfo::has_sse4_2() const { return impl_->m_has_sse4_2; } - -bool cpuinfo::has_pclmulqdq() const { return impl_->m_has_pclmulqdq; } - -bool cpuinfo::has_avx() const { return impl_->m_has_avx; } - -bool cpuinfo::has_avx2() const { return impl_->m_has_avx2; } - -bool cpuinfo::has_avx512_f() const { return impl_->m_has_avx512_f; } - -bool cpuinfo::has_avx512_dq() const { return impl_->m_has_avx512_dq; } - -bool cpuinfo::has_avx512_ifma() const { return impl_->m_has_avx512_ifma; } - -bool cpuinfo::has_avx512_pf() const { return impl_->m_has_avx512_pf; } - -bool cpuinfo::has_avx512_er() const { return impl_->m_has_avx512_er; } - -bool cpuinfo::has_avx512_cd() const { return impl_->m_has_avx512_cd; } - -bool cpuinfo::has_avx512_bw() const { return impl_->m_has_avx512_bw; } - -bool cpuinfo::has_avx512_vl() const { return impl_->m_has_avx512_vl; } - -bool cpuinfo::has_avx512_vbmi() const { return impl_->m_has_avx512_vbmi; } - -bool cpuinfo::has_avx512_vbmi2() const { return impl_->m_has_avx512_vbmi2; } - -bool cpuinfo::has_avx512_vnni() const { return impl_->m_has_avx512_vnni; } - -bool cpuinfo::has_avx512_bitalg() const { return impl_->m_has_avx512_bitalg; } - -bool cpuinfo::has_avx512_vpopcntdq() const { - return impl_->m_has_avx512_vpopcntdq; -} - -bool cpuinfo::has_avx512_4vnniw() const { return impl_->m_has_avx512_4vnniw; } - -bool cpuinfo::has_avx512_4fmaps() const { return impl_->m_has_avx512_4fmaps; } - -bool cpuinfo::has_avx512_vp2intersect() const { - return impl_->m_has_avx512_vp2intersect; -} - -bool cpuinfo::has_f16c() const { return impl_->m_has_f16c; } - -// ARM member functions -bool cpuinfo::has_neon() const { return impl_->m_has_neon; } -} // namespace cpuid diff --git a/windows/util/cpuid/cpuinfo.h b/windows/util/cpuid/cpuinfo.h deleted file mode 100644 index 0cee359..0000000 --- a/windows/util/cpuid/cpuinfo.h +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once - -#include - -namespace cpuid { - -class cpuinfo { - public: - struct impl; - - cpuinfo(); - ~cpuinfo(); - - // Has X87 FPU - bool has_fpu() const; - - // Return true if the CPU supports MMX - bool has_mmx() const; - - // Return true if the CPU supports SSE - bool has_sse() const; - - // Return true if the CPU supports SSE2 - bool has_sse2() const; - - // Return true if the CPU supports SSE3 - bool has_sse3() const; - - // Return true if the CPU supports SSSE3 - bool has_ssse3() const; - - // Return true if the CPU supports SSE 4.1 - bool has_sse4_1() const; - - // Return true if the CPU supports SSE 4.2 - bool has_sse4_2() const; - - // Return true if the CPU supports pclmulqdq - bool has_pclmulqdq() const; - - // Return true if the CPU supports AVX - bool has_avx() const; - - // Return true if the CPU supports AVX2 - bool has_avx2() const; - - // Return true if the CPU supports AVX512F - bool has_avx512_f() const; - - // Return true if the CPU supports AVX512DQ - bool has_avx512_dq() const; - - // Return true if the CPU supports AVX512_IFMA - bool has_avx512_ifma() const; - - // Return true if the CPU supports AVX512PF - bool has_avx512_pf() const; - - // Return true if the CPU supports AVX512ER - bool has_avx512_er() const; - - // Return true if the CPU supports AVX512CD - bool has_avx512_cd() const; - - // Return true if the CPU supports AVX512BW - bool has_avx512_bw() const; - - // Return true if the CPU supports AVX512VL - bool has_avx512_vl() const; - - // Return true if the CPU supports AVX512_VBMI - bool has_avx512_vbmi() const; - - // Return true if the CPU supports AVX512_VBMI2 - bool has_avx512_vbmi2() const; - - // Return true if the CPU supports AVX512_VNNI - bool has_avx512_vnni() const; - - // Return true if the CPU supports AVX512_BITALG - bool has_avx512_bitalg() const; - - // Return true if the CPU supports AVX512_VPOPCNTDQ - bool has_avx512_vpopcntdq() const; - - // Return true if the CPU supports AVX512_4VNNIW - bool has_avx512_4vnniw() const; - - // Return true if the CPU supports AVX512_4FMAPS - bool has_avx512_4fmaps() const; - - // Return true if the CPU supports AVX512_VP2INTERSECT - bool has_avx512_vp2intersect() const; - - // Return true if the CPU supports F16C - bool has_f16c() const; - - // Return true if the CPU supports NEON - bool has_neon() const; - - private: - // Private implementation - std::unique_ptr impl_; -}; -} // namespace cpuid diff --git a/windows/util/cpuid/detail/cpuinfo_impl.h b/windows/util/cpuid/detail/cpuinfo_impl.h deleted file mode 100644 index 1d2ee69..0000000 --- a/windows/util/cpuid/detail/cpuinfo_impl.h +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -#include "../cpuinfo.h" - -namespace cpuid { - -struct cpuinfo::impl { - impl() - : m_has_fpu(false), - m_has_mmx(false), - m_has_sse(false), - m_has_sse2(false), - m_has_sse3(false), - m_has_ssse3(false), - m_has_sse4_1(false), - m_has_sse4_2(false), - m_has_pclmulqdq(false), - m_has_avx(false), - m_has_avx2(false), - m_has_avx512_f(false), - m_has_avx512_dq(false), - m_has_avx512_ifma(false), - m_has_avx512_pf(false), - m_has_avx512_er(false), - m_has_avx512_cd(false), - m_has_avx512_bw(false), - m_has_avx512_vl(false), - m_has_avx512_vbmi(false), - m_has_avx512_vbmi2(false), - m_has_avx512_vnni(false), - m_has_avx512_bitalg(false), - m_has_avx512_vpopcntdq(false), - m_has_avx512_4vnniw(false), - m_has_avx512_4fmaps(false), - m_has_avx512_vp2intersect(false), - m_has_f16c(false), - m_has_neon(false) {} - - bool m_has_fpu; - bool m_has_mmx; - bool m_has_sse; - bool m_has_sse2; - bool m_has_sse3; - bool m_has_ssse3; - bool m_has_sse4_1; - bool m_has_sse4_2; - bool m_has_pclmulqdq; - bool m_has_avx; - bool m_has_avx2; - bool m_has_avx512_f; - bool m_has_avx512_dq; - bool m_has_avx512_ifma; - bool m_has_avx512_pf; - bool m_has_avx512_er; - bool m_has_avx512_cd; - bool m_has_avx512_bw; - bool m_has_avx512_vl; - bool m_has_avx512_vbmi; - bool m_has_avx512_vbmi2; - bool m_has_avx512_vnni; - bool m_has_avx512_bitalg; - bool m_has_avx512_vpopcntdq; - bool m_has_avx512_4vnniw; - bool m_has_avx512_4fmaps; - bool m_has_avx512_vp2intersect; - bool m_has_f16c; - bool m_has_neon; -}; -} // namespace cpuid diff --git a/windows/util/cpuid/detail/extract_x86_flags.h b/windows/util/cpuid/detail/extract_x86_flags.h deleted file mode 100644 index 5bea586..0000000 --- a/windows/util/cpuid/detail/extract_x86_flags.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include - -#include "cpuinfo_impl.h" - -namespace cpuid { - -void extract_x86_flags(cpuinfo::impl& info, uint32_t ecx, uint32_t edx) { - info.m_has_fpu = (edx & (1 << 0)) != 0; - info.m_has_mmx = (edx & (1 << 23)) != 0; - info.m_has_sse = (edx & (1 << 25)) != 0; - info.m_has_sse2 = (edx & (1 << 26)) != 0; - info.m_has_sse3 = (ecx & (1 << 0)) != 0; - info.m_has_ssse3 = (ecx & (1 << 9)) != 0; - info.m_has_sse4_1 = (ecx & (1 << 19)) != 0; - info.m_has_sse4_2 = (ecx & (1 << 20)) != 0; - info.m_has_pclmulqdq = (ecx & (1 << 1)) != 0; - info.m_has_avx = (ecx & (1 << 28)) != 0; - info.m_has_f16c = (ecx & (1 << 29)) != 0; -} - -void extract_x86_extended_flags(cpuinfo::impl& info, uint32_t ebx, uint32_t ecx, - uint32_t edx) { - info.m_has_avx2 = (ebx & (1 << 5)) != 0; - info.m_has_avx512_f = (ebx & (1 << 16)) != 0; - info.m_has_avx512_dq = (ebx & (1 << 17)) != 0; - info.m_has_avx512_ifma = (ebx & (1 << 21)) != 0; - info.m_has_avx512_pf = (ebx & (1 << 26)) != 0; - info.m_has_avx512_er = (ebx & (1 << 27)) != 0; - info.m_has_avx512_cd = (ebx & (1 << 28)) != 0; - info.m_has_avx512_bw = (ebx & (1 << 30)) != 0; - info.m_has_avx512_vl = (ebx & (1 << 31)) != 0; - info.m_has_avx512_vbmi = (ecx & (1 << 1)) != 0; - info.m_has_avx512_vbmi2 = (ecx & (1 << 6)) != 0; - info.m_has_avx512_vnni = (ecx & (1 << 11)) != 0; - info.m_has_avx512_bitalg = (ecx & (1 << 12)) != 0; - info.m_has_avx512_vpopcntdq = (ecx & (1 << 14)) != 0; - info.m_has_avx512_4vnniw = (edx & (1 << 2)) != 0; - info.m_has_avx512_4fmaps = (edx & (1 << 3)) != 0; - info.m_has_avx512_vp2intersect = (edx & (1 << 8)) != 0; -} -} // namespace cpuid diff --git a/windows/util/cpuid/detail/init_msvc_x86.h b/windows/util/cpuid/detail/init_msvc_x86.h deleted file mode 100644 index 697270b..0000000 --- a/windows/util/cpuid/detail/init_msvc_x86.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include - -#include "cpuinfo_impl.h" -#include "extract_x86_flags.h" - -namespace cpuid { - -void init_cpuinfo(cpuinfo::impl& info) { - int registers[4]; - - // The register information per input can be extracted from here: - // http://en.wikipedia.org/wiki/CPUID - // - // CPUID should be called with EAX=0 first, as this will return the - // maximum supported EAX input value for future calls - __cpuid(registers, 0); - uint32_t maximum_eax = registers[0]; - - // Set registers for basic flag extraction, eax=1 - // All CPUs should support index=1 - if (maximum_eax >= 1U) { - __cpuid(registers, 1); - extract_x86_flags(info, registers[2], registers[3]); - } - - // Set registers for extended flags extraction, eax=7 and ecx=0 - // This operation is not supported on older CPUs, so it should be skipped - // to avoid incorrect results - if (maximum_eax >= 7U) { - __cpuidex(registers, 7, 0); - extract_x86_extended_flags(info, registers[1], registers[2], registers[3]); - } -} -} // namespace cpuid diff --git a/windows/util/cpuid/detail/init_unknown.h b/windows/util/cpuid/detail/init_unknown.h deleted file mode 100644 index 3b52ef2..0000000 --- a/windows/util/cpuid/detail/init_unknown.h +++ /dev/null @@ -1,9 +0,0 @@ - -#pragma once - -#include "cpuinfo_impl.h" - -namespace cpuid { - -void init_cpuinfo(cpuinfo::impl& info) { (void)info; } -} // namespace cpuid diff --git a/windows/util/swizzle.h b/windows/util/swizzle.h deleted file mode 100644 index a632102..0000000 --- a/windows/util/swizzle.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* - * see skia/src/opts/SkSwizzler_opts.h - */ - -#pragma once - -#include "cpuid/cpuinfo.h" - -/** - * SK_CPU_SSE_LEVEL - * - * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. - * On non-intel CPU this should be undefined. - */ -#define SK_CPU_SSE_LEVEL_SSE1 10 -#define SK_CPU_SSE_LEVEL_SSE2 20 -#define SK_CPU_SSE_LEVEL_SSE3 30 -#define SK_CPU_SSE_LEVEL_SSSE3 31 -#define SK_CPU_SSE_LEVEL_SSE41 41 -#define SK_CPU_SSE_LEVEL_SSE42 42 -#define SK_CPU_SSE_LEVEL_AVX 51 -#define SK_CPU_SSE_LEVEL_AVX2 52 -#define SK_CPU_SSE_LEVEL_SKX 60 - -// Are we in GCC/Clang? -#ifndef SK_CPU_SSE_LEVEL -// These checks must be done in descending order to ensure we set the highest -// available SSE level. -#if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX -#elif defined(__AVX2__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 -#elif defined(__AVX__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX -#elif defined(__SSE4_2__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 -#elif defined(__SSE4_1__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 -#elif defined(__SSSE3__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 -#elif defined(__SSE3__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 -#elif defined(__SSE2__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 -#endif -#endif - -// Are we in VisualStudio? -#ifndef SK_CPU_SSE_LEVEL -// These checks must be done in descending order to ensure we set the highest -// available SSE level. 64-bit intel guarantees at least SSE2 support. -#if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \ - defined(__AVX512BW__) && defined(__AVX512VL__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX -#elif defined(__AVX2__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 -#elif defined(__AVX__) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX -#elif defined(_M_X64) || defined(_M_AMD64) -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 -#elif defined(_M_IX86_FP) -#if _M_IX86_FP >= 2 -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 -#elif _M_IX86_FP == 1 -#define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 -#endif -#endif -#endif - -inline void RGBA_to_BGRA_portable(uint32_t* dst, const uint32_t* src, - int height, int src_stride, int dst_stride) { - auto width = std::min(src_stride, dst_stride); - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - uint8_t a = (src[x] >> 24) & 0xFF, b = (src[x] >> 16) & 0xFF, - g = (src[x] >> 8) & 0xFF, r = (src[x] >> 0) & 0xFF; - dst[x] = (uint32_t)a << 24 | (uint32_t)r << 16 | (uint32_t)g << 8 | - (uint32_t)b << 0; - } - - src += src_stride; - dst += dst_stride; - } -} - -#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SKX - -inline void RGBA_to_BGRA_SKX(uint32_t* dst, const uint32_t* src, int height, - int src_stride, int dst_stride) { - const uint8_t mask[64] = {2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, - 13, 12, 15, 2, 1, 0, 3, 6, 5, 4, 7, 10, 9, - 8, 11, 14, 13, 12, 15, 2, 1, 0, 3, 6, 5, 4, - 7, 10, 9, 8, 11, 14, 13, 12, 15, 2, 1, 0, 3, - 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15}; - const __m512i swapRB = _mm512_loadu_si512(mask); - - auto width = std::min(src_stride, dst_stride); - - for (int y = 0; y < height; y++) { - auto cw = width; - auto rptr = src; - auto dptr = dst; - while (cw >= 16) { - __m512i rgba = _mm512_loadu_si512((const __m512i*)rptr); - __m512i bgra = _mm512_shuffle_epi8(rgba, swapRB); - _mm512_storeu_si512((__m512i*)dptr, bgra); - - rptr += 16; - dptr += 16; - cw -= 16; - } - - for (auto x = 0; x < cw; x++) { - uint8_t a = (rptr[x] >> 24) & 0xFF, b = (rptr[x] >> 16) & 0xFF, - g = (rptr[x] >> 8) & 0xFF, r = (rptr[x] >> 0) & 0xFF; - dptr[x] = (uint32_t)a << 24 | (uint32_t)r << 16 | (uint32_t)g << 8 | - (uint32_t)b << 0; - } - - src += src_stride; - dst += dst_stride; - } -} - -#endif - -#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 - -inline void RGBA_to_BGRA_AVX2(uint32_t* dst, const uint32_t* src, int height, - int src_stride, int dst_stride) { - const __m256i swapRB = - _mm256_setr_epi8(2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15, 2, - 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15); - - auto width = std::min(src_stride, dst_stride); - - for (int y = 0; y < height; y++) { - auto cw = width; - auto rptr = src; - auto dptr = dst; - while (cw >= 8) { - __m256i rgba = _mm256_loadu_si256((const __m256i*)rptr); - __m256i bgra = _mm256_shuffle_epi8(rgba, swapRB); - _mm256_storeu_si256((__m256i*)dptr, bgra); - - rptr += 8; - dptr += 8; - cw -= 8; - } - - for (auto x = 0; x < cw; x++) { - uint8_t a = (rptr[x] >> 24) & 0xFF, b = (rptr[x] >> 16) & 0xFF, - g = (rptr[x] >> 8) & 0xFF, r = (rptr[x] >> 0) & 0xFF; - dptr[x] = (uint32_t)a << 24 | (uint32_t)r << 16 | (uint32_t)g << 8 | - (uint32_t)b << 0; - } - - src += src_stride; - dst += dst_stride; - } -} - -#endif - -inline void RGBA_to_BGRA(uint32_t* dst, const uint32_t* src, int height, - int src_stride, int dst_stride) { - static cpuid::cpuinfo info; - -#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SKX - if (info.has_avx512_f() && info.has_avx512_dq() && info.has_avx512_cd() && - info.has_avx512_bw() && info.has_avx512_vl()) { - return RGBA_to_BGRA_SKX(dst, src, height, src_stride, dst_stride); - } -#endif - -#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 - if (info.has_avx2()) { - return RGBA_to_BGRA_AVX2(dst, src, height, src_stride, dst_stride); - } -#endif - - RGBA_to_BGRA_portable(dst, src, height, src_stride, dst_stride); -} diff --git a/windows/webview_bridge.cc b/windows/webview_bridge.cc index f417f9a..6ea5b7d 100644 --- a/windows/webview_bridge.cc +++ b/windows/webview_bridge.cc @@ -5,11 +5,7 @@ #include -#ifdef HAVE_FLUTTER_D3D_TEXTURE #include "texture_bridge_gpu.h" -#else -#include "texture_bridge_fallback.h" -#endif namespace { constexpr auto kErrorInvalidArgs = "invalidArguments"; @@ -144,7 +140,6 @@ WebviewBridge::WebviewBridge(flutter::BinaryMessenger* messenger, GraphicsContext* graphics_context, std::unique_ptr webview) : webview_(std::move(webview)), texture_registrar_(texture_registrar) { -#ifdef HAVE_FLUTTER_D3D_TEXTURE texture_bridge_ = std::make_unique(graphics_context, webview_->surface()); @@ -156,17 +151,6 @@ WebviewBridge::WebviewBridge(flutter::BinaryMessenger* messenger, size_t height) -> const FlutterDesktopGpuSurfaceDescriptor* { return bridge->GetSurfaceDescriptor(width, height); })); -#else - texture_bridge_ = std::make_unique( - graphics_context, webview_->surface()); - - flutter_texture_ = - std::make_unique(flutter::PixelBufferTexture( - [bridge = static_cast(texture_bridge_.get())]( - size_t width, size_t height) -> const FlutterDesktopPixelBuffer* { - return bridge->CopyPixelBuffer(width, height); - })); -#endif texture_id_ = texture_registrar->RegisterTexture(flutter_texture_.get()); texture_bridge_->SetOnFrameAvailable( @@ -318,7 +302,8 @@ void WebviewBridge::RegisterEventHandlers() { } void WebviewBridge::OnPermissionRequested( - const std::string& url, WebviewPermissionKind permissionKind, + const std::string& url, + WebviewPermissionKind permissionKind, bool isUserInitiated, Webview::WebviewPermissionRequestedCompleter completer) { auto args = std::make_unique(flutter::EncodableMap{