Browse Source

Enable simd for wasm, early implementation of file dialogs

Signed-off-by: falkTX <falktx@falktx.com>
pull/321/head
falkTX 2 years ago
parent
commit
c2938c0299
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
7 changed files with 93 additions and 7 deletions
  1. +1
    -1
      Makefile.base.mk
  2. +1
    -1
      dgl/src/pugl-upstream
  3. +1
    -0
      dgl/src/pugl.cpp
  4. +1
    -0
      distrho/DistrhoUI_macOS.mm
  5. +86
    -5
      distrho/extra/FileBrowserDialogImpl.cpp
  6. +1
    -0
      distrho/src/DistrhoUI.cpp
  7. +2
    -0
      distrho/src/DistrhoUIPrivateData.hpp

+ 1
- 1
Makefile.base.mk View File

@@ -172,7 +172,7 @@ BASE_OPTS = -O3 -ffast-math -fdata-sections -ffunction-sections
ifeq ($(CPU_I386_OR_X86_64),true)
BASE_OPTS += -mtune=generic
ifeq ($(WASM),true)
# BASE_OPTS += -msse -msse2 -msse3 -msimd128
BASE_OPTS += -msse -msse2 -msse3 -msimd128
else
BASE_OPTS += -msse -msse2 -mfpmath=sse
endif


+ 1
- 1
dgl/src/pugl-upstream

@@ -1 +1 @@
Subproject commit dbad9da2f2b5ce9b6a0049a70268a0b8a3ec14a2
Subproject commit eb7607571d38d8f06eea95eb2a04667402d49eab

+ 1
- 0
dgl/src/pugl.cpp View File

@@ -108,6 +108,7 @@

#ifndef DGL_FILE_BROWSER_DISABLED
# define FILE_BROWSER_DIALOG_DGL_NAMESPACE
# define FILE_BROWSER_DIALOG_NAMESPACE DGL_NAMESPACE
# define DGL_FILE_BROWSER_DIALOG_HPP_INCLUDED
START_NAMESPACE_DGL
# include "../../distrho/extra/FileBrowserDialogImpl.hpp"


+ 1
- 0
distrho/DistrhoUI_macOS.mm View File

@@ -25,6 +25,7 @@

#if DISTRHO_UI_FILE_BROWSER
# define DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED
# define FILE_BROWSER_DIALOG_NAMESPACE DISTRHO_NAMESPACE
# define FILE_BROWSER_DIALOG_DISTRHO_NAMESPACE
START_NAMESPACE_DISTRHO
# include "extra/FileBrowserDialogImpl.hpp"


+ 86
- 5
distrho/extra/FileBrowserDialogImpl.cpp View File

@@ -27,6 +27,9 @@
#ifdef DISTRHO_OS_MAC
# import <Cocoa/Cocoa.h>
#endif
#ifdef DISTRHO_OS_WASM
# include <emscripten/emscripten.h>
#endif
#ifdef DISTRHO_OS_WINDOWS
# include <direct.h>
# include <process.h>
@@ -71,6 +74,52 @@ static constexpr int toHexChar(const char c) noexcept
}
#endif

#ifdef DISTRHO_OS_WASM
# define DISTRHO_WASM_NAMESPACE_MACRO_HELPER(NS, SEP, FUNCTION) NS ## SEP ## FUNCTION
# define DISTRHO_WASM_NAMESPACE_MACRO(NS, FUNCTION) DISTRHO_WASM_NAMESPACE_MACRO_HELPER(NS, _, FUNCTION)
# define DISTRHO_WASM_NAMESPACE_HELPER(NS) #NS
# define DISTRHO_WASM_NAMESPACE(NS) DISTRHO_WASM_NAMESPACE_HELPER(NS)
// FIXME use world class name as prefix
EM_JS(bool, DISTRHO_WASM_NAMESPACE_MACRO(FILE_BROWSER_DIALOG_NAMESPACE, openWebBrowserFileDialog), (const char* funcname, void* handle), {
var canvasFileElem = document.getElementById('canvas_file_open');
var jsfuncname = UTF8ToString(funcname);
if (canvasFileElem) {
canvasFileElem.onchange = function(e) {
if (!!canvasFileElem.files) {
var file = canvasFileElem.files[0];
var filename = '/' + file.name;
var reader = new FileReader();
reader.onloadend = function(e) {
var content = new Uint8Array(reader.result);
Module.FS.writeFile(filename, content);
Module.ccall(jsfuncname, 'null', ['number', 'string'], [handle, filename]);
};
reader.readAsArrayBuffer(file);
}
};
canvasFileElem.click();
return true;
}
return false;
});
EM_JS(bool, DISTRHO_WASM_NAMESPACE_MACRO(FILE_BROWSER_DIALOG_NAMESPACE, downloadWebBrowserFile), (), {
var canvasFileElem = document.getElementById('canvas_file_save');
if (canvasFileElem) {
// FIXME filename shouldn't change
var content = Module.FS.readFile('/download.vcv');
canvasFileElem.download = 'download.vcv';
canvasFileElem.href = URL.createObjectURL(new Blob([content]));
canvasFileElem.click();
return true;
}
return false;
});
# define openWebBrowserFileDialogNamespaced DISTRHO_WASM_NAMESPACE_MACRO(FILE_BROWSER_DIALOG_NAMESPACE, openWebBrowserFileDialog)
# define downloadWebBrowserFileNamespaced DISTRHO_WASM_NAMESPACE_MACRO(FILE_BROWSER_DIALOG_NAMESPACE, downloadWebBrowserFile)
# define fileBrowserSetPathNamespaced DISTRHO_WASM_NAMESPACE_MACRO(FILE_BROWSER_DIALOG_NAMESPACE, fileBrowserSetPath)
# define fileBrowserSetPathFuncName DISTRHO_WASM_NAMESPACE(FILE_BROWSER_DIALOG_NAMESPACE) "_fileBrowserSetPath"
#endif

struct FileBrowserData {
const char* selectedFile;

@@ -284,6 +333,19 @@ struct FileBrowserData {

// --------------------------------------------------------------------------------------------------------------------

#ifdef DISTRHO_OS_WASM
extern "C" {
EMSCRIPTEN_KEEPALIVE
void fileBrowserSetPathNamespaced(FileBrowserHandle handle, const char* filename)
{
handle->free();

if (filename != nullptr && filename[0] != '\0')
handle->selectedFile = strdup(filename);
}
}
#endif

FileBrowserHandle fileBrowserCreate(const bool isEmbed,
const uintptr_t windowId,
const double scaleFactor,
@@ -295,17 +357,13 @@ FileBrowserHandle fileBrowserCreate(const bool isEmbed,
{
#ifdef DISTRHO_OS_WINDOWS
if (char* const cwd = _getcwd(nullptr, 0))
{
startDir = cwd;
std::free(cwd);
}
#else
if (char* const cwd = getcwd(nullptr, 0))
#endif
{
startDir = cwd;
std::free(cwd);
}
#endif
}

DISTRHO_SAFE_ASSERT_RETURN(startDir.isNotEmpty(), nullptr);
@@ -375,6 +433,18 @@ FileBrowserHandle fileBrowserCreate(const bool isEmbed,
# endif
#endif

#ifdef DISTRHO_OS_WASM
if (options.saving)
{
handle->selectedFile = strdup("/download");
return handle.release();
}

const char* const funcname = fileBrowserSetPathFuncName;
if (openWebBrowserFileDialogNamespaced(funcname, handle.get()))
return handle.release();
#endif

#ifdef DISTRHO_OS_WINDOWS
handle->setupAndStart(isEmbed, startDir, windowTitle, windowId, options);
#endif
@@ -663,6 +733,11 @@ bool fileBrowserIdle(const FileBrowserHandle handle)

void fileBrowserClose(const FileBrowserHandle handle)
{
#ifdef DISTRHO_OS_WASM
if (fileBrowserGetPath(handle) != nullptr)
downloadWebBrowserFileNamespaced();
#endif

#ifdef HAVE_X11
if (Display* const x11display = handle->x11display)
x_fib_close(x11display);
@@ -693,3 +768,9 @@ END_NAMESPACE_DISTRHO

#undef FILE_BROWSER_DIALOG_DISTRHO_NAMESPACE
#undef FILE_BROWSER_DIALOG_DGL_NAMESPACE
#undef FILE_BROWSER_DIALOG_NAMESPACE

#undef openWebBrowserFileDialogNamespaced
#undef downloadWebBrowserFileNamespaced
#undef fileBrowserSetPathNamespaced
#undef fileBrowserSetPathFuncName

+ 1
- 0
distrho/src/DistrhoUI.cpp View File

@@ -44,6 +44,7 @@
# define x_fib_show DISTRHO_PUGL_NAMESPACE_MACRO(plugin, x_fib_show)
# define x_fib_status DISTRHO_PUGL_NAMESPACE_MACRO(plugin, x_fib_status)
# define DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED
# define FILE_BROWSER_DIALOG_NAMESPACE DISTRHO_NAMESPACE
# define FILE_BROWSER_DIALOG_DISTRHO_NAMESPACE
START_NAMESPACE_DISTRHO
# include "../extra/FileBrowserDialogImpl.hpp"


+ 2
- 0
distrho/src/DistrhoUIPrivateData.hpp View File

@@ -481,7 +481,9 @@ inline void PluginWindow::onFileSelected(const char* const filename)
}
#endif

puglBackendEnter(pData->view);
ui->uiFileBrowserSelected(filename);
puglBackendLeave(pData->view);
}
#endif



Loading…
Cancel
Save