fixes for Windows
This commit is contained in:
@@ -72,6 +72,14 @@ class _FilamentWidgetState extends State<FilamentWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
if (_texture?.usesBackingWindow == true) {
|
||||
return Stack(children: [
|
||||
Positioned.fill(child: CustomPaint(painter: TransparencyPainter()))
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
if (_texture == null || _resizing) {
|
||||
return widget.initial ??
|
||||
Container(color: kIsWeb ? Colors.transparent : Colors.red);
|
||||
@@ -79,7 +87,7 @@ class _FilamentWidgetState extends State<FilamentWidget> {
|
||||
|
||||
var textureWidget = Texture(
|
||||
key: ObjectKey("texture_${_texture!.flutterTextureId}"),
|
||||
textureId: _texture!.flutterTextureId,
|
||||
textureId: _texture!.flutterTextureId!,
|
||||
filterQuality: FilterQuality.none,
|
||||
freeze: false,
|
||||
);
|
||||
@@ -98,3 +106,19 @@ class _FilamentWidgetState extends State<FilamentWidget> {
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class TransparencyPainter extends CustomPainter {
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(0, 0, size.width, size.height),
|
||||
Paint()
|
||||
..blendMode = BlendMode.clear
|
||||
..color = const Color(0x00000000),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
||||
}
|
||||
@@ -100,6 +100,12 @@ set(flutter_filament_bundled_libraries
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/libc++.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/third_party_abseil-cpp_absl.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lib/Debug/third_party_zlib.dll
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/dart_filament.dll
|
||||
PARENT_SCOPE
|
||||
)
|
||||
else()
|
||||
set(flutter_filament_bundled_libraries
|
||||
${runner_BINARY_DIR}/../../../native_assets/windows/dart_filament.dll
|
||||
PARENT_SCOPE
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma comment(lib, "dxgi.lib")
|
||||
#pragma comment(lib, "d3d11.lib")
|
||||
#pragma comment(lib, "Shlwapi.lib")
|
||||
|
||||
#include "flutter_filament_plugin.h"
|
||||
|
||||
@@ -35,8 +36,7 @@
|
||||
|
||||
namespace flutter_filament {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
void FlutterFilamentPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarWindows *registrar) {
|
||||
@@ -123,6 +123,7 @@ void FlutterFilamentPlugin::freeResource(ResourceBuffer rbuf) {
|
||||
}
|
||||
|
||||
static ResourceBuffer _loadResource(const char *path, void *const plugin) {
|
||||
std::wcout << "Loading resource from path " << path << std::endl;
|
||||
return ((FlutterFilamentPlugin *)plugin)->loadResource(path);
|
||||
}
|
||||
|
||||
@@ -163,10 +164,10 @@ void FlutterFilamentPlugin::CreateTexture(
|
||||
const auto *args =
|
||||
std::get_if<flutter::EncodableList>(methodCall.arguments());
|
||||
|
||||
double dWidth = *(std::get_if<double>(&(args->at(0))));
|
||||
double dHeight = *(std::get_if<double>(&(args->at(1))));
|
||||
double dLeft = *(std::get_if<double>(&(args->at(2))));
|
||||
double dTop = *(std::get_if<double>(&(args->at(3))));
|
||||
int dWidth = *(std::get_if<int>(&(args->at(0))));
|
||||
int dHeight = *(std::get_if<int>(&(args->at(1))));
|
||||
int dLeft = *(std::get_if<int>(&(args->at(2))));
|
||||
int dTop = *(std::get_if<int>(&(args->at(3))));
|
||||
auto width = (uint32_t)round(dWidth );
|
||||
auto height = (uint32_t)round(dHeight );
|
||||
auto left = (uint32_t)round(dLeft );
|
||||
@@ -233,10 +234,11 @@ void FlutterFilamentPlugin::HandleMethodCall(
|
||||
#if WGL_USE_BACKING_WINDOW
|
||||
const auto *args =
|
||||
std::get_if<flutter::EncodableList>(methodCall.arguments());
|
||||
double dWidth = *(std::get_if<double>(&(args->at(0))));
|
||||
double dHeight = *(std::get_if<double>(&(args->at(1))));
|
||||
double dLeft = *(std::get_if<double>(&(args->at(2))));
|
||||
double dTop = *(std::get_if<double>(&(args->at(3))));
|
||||
|
||||
int dWidth = *(std::get_if<int>(&(args->at(0))));
|
||||
int dHeight = *(std::get_if<int>(&(args->at(1))));
|
||||
int dLeft = *(std::get_if<int>(&(args->at(2))));
|
||||
int dTop = *(std::get_if<int>(&(args->at(3))));
|
||||
auto width = (uint32_t)round(dWidth );
|
||||
auto height = (uint32_t)round(dHeight );
|
||||
auto left = (uint32_t)round(dLeft );
|
||||
|
||||
@@ -118,11 +118,10 @@ void WGLContext::CreateRenderingSurface(
|
||||
ResizeRenderingSurface(width, height, left, top);
|
||||
}
|
||||
std::vector<flutter::EncodableValue> resultList;
|
||||
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
||||
resultList.push_back(flutter::EncodableValue()); // return null for Flutter texture ID
|
||||
resultList.push_back(flutter::EncodableValue()); // return null for hardware texture ID
|
||||
resultList.push_back(
|
||||
flutter::EncodableValue((int64_t)_backingWindow->GetHandle()));
|
||||
resultList.push_back(flutter::EncodableValue((int64_t) nullptr));
|
||||
resultList.push_back(flutter::EncodableValue((int64_t)_context));
|
||||
flutter::EncodableValue((int64_t)_backingWindow->GetHandle())); // return the HWND handle for the native window
|
||||
result->Success(resultList);
|
||||
#else
|
||||
if(left != 0 || top != 0) {
|
||||
|
||||
@@ -115,10 +115,10 @@ class FlutterFilamentFFI extends FlutterFilamentPlatform {
|
||||
var result = await _channel
|
||||
.invokeMethod("createTexture", [width, height, offsetLeft, offsetLeft]);
|
||||
|
||||
if (result == null || result[0] == -1) {
|
||||
if (result == null || (result[0] == -1)) {
|
||||
throw Exception("Failed to create texture");
|
||||
}
|
||||
final flutterTextureId = result[0] as int;
|
||||
final flutterTextureId = result[0] as int?;
|
||||
final hardwareTextureId = result[1] as int?;
|
||||
final surfaceAddress = result[2] as int?;
|
||||
|
||||
@@ -126,23 +126,28 @@ class FlutterFilamentFFI extends FlutterFilamentPlatform {
|
||||
"Created texture with flutter texture id ${flutterTextureId}, hardwareTextureId $hardwareTextureId and surfaceAddress $surfaceAddress");
|
||||
|
||||
viewer.viewportDimensions = (width.toDouble(), height.toDouble());
|
||||
var texture = FlutterFilamentTexture(
|
||||
flutterTextureId, hardwareTextureId, width, height, surfaceAddress);
|
||||
|
||||
final texture = FlutterFilamentTexture(
|
||||
flutterTextureId, hardwareTextureId, width, height, surfaceAddress);
|
||||
|
||||
await viewer.createSwapChain(width.toDouble(), height.toDouble(),
|
||||
surface: texture.surfaceAddress == null
|
||||
? nullptr
|
||||
: Pointer<Void>.fromAddress(texture.surfaceAddress!));
|
||||
surface: texture.surfaceAddress == null
|
||||
? nullptr
|
||||
: Pointer<Void>.fromAddress(texture.surfaceAddress!));
|
||||
|
||||
if (texture.hardwareTextureId != null) {
|
||||
print("Creating render target");
|
||||
var renderTarget = await viewer.createRenderTarget(
|
||||
width.toDouble(), height.toDouble(), texture.hardwareTextureId!);
|
||||
width.toDouble(), height.toDouble(), texture.hardwareTextureId!);
|
||||
}
|
||||
|
||||
await viewer.updateViewportAndCameraProjection(
|
||||
width.toDouble(), height.toDouble());
|
||||
viewer.render();
|
||||
_creatingTexture = false;
|
||||
|
||||
_textures.add(texture);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user