From 4e3a88bbab7fbfb53e818c4abec26070e6cac89d Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Thu, 1 Nov 2018 16:36:52 -0700 Subject: [PATCH] Cleanup and documentation (#445) --- .../src/main/cpp/nativewindow/Darwin.mm | 7 ++- .../src/main/cpp/nativewindow/JAWTUtils.cpp | 48 +++++++++++++------ .../src/main/cpp/nativewindow/JAWTUtils.h | 4 +- .../src/main/cpp/nativewindow/Linux.cpp | 15 +++--- .../src/main/cpp/nativewindow/Win32.cpp | 22 +++++---- libs/filameshio/include/filameshio/MeshIO.h | 28 ++++++++++- 6 files changed, 87 insertions(+), 37 deletions(-) diff --git a/android/filament-android/src/main/cpp/nativewindow/Darwin.mm b/android/filament-android/src/main/cpp/nativewindow/Darwin.mm index c21a10b7b2..10bd781165 100644 --- a/android/filament-android/src/main/cpp/nativewindow/Darwin.mm +++ b/android/filament-android/src/main/cpp/nativewindow/Darwin.mm @@ -24,6 +24,8 @@ #import +#pragma clang diagnostic push +#pragma ide diagnostic ignored "NotReleasedValue" extern "C" { void *getNativeWindow(JNIEnv *env, jclass klass, jobject surface) { void *win = nullptr; @@ -40,7 +42,7 @@ void *getNativeWindow(JNIEnv *env, jclass klass, jobject surface) { view.wantsLayer = true; [jawldsip setLayer:view.layer]; - win = (void*)view; + win = (void*) view; releaseDrawingSurface(ds, dsi); return win; } @@ -48,7 +50,7 @@ void *getNativeWindow(JNIEnv *env, jclass klass, jobject surface) { jlong createNativeSurface(jint width, jint height) { NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, width, height)]; view.wantsLayer = true; - return (jlong)view; + return (jlong) view; } void destroyNativeSurface(jlong surface) { @@ -57,3 +59,4 @@ void destroyNativeSurface(jlong surface) { } } +#pragma clang diagnostic pop diff --git a/android/filament-android/src/main/cpp/nativewindow/JAWTUtils.cpp b/android/filament-android/src/main/cpp/nativewindow/JAWTUtils.cpp index 3c7daf692d..4a128fa956 100644 --- a/android/filament-android/src/main/cpp/nativewindow/JAWTUtils.cpp +++ b/android/filament-android/src/main/cpp/nativewindow/JAWTUtils.cpp @@ -25,65 +25,83 @@ static std::vector jawtVersions = { 0x00010009, }; -bool acquireDrawingSurface(JNIEnv *env, jobject surface, JAWT_DrawingSurface** ods, - JAWT_DrawingSurfaceInfo** odsi) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wuninitialized" +bool acquireDrawingSurface(JNIEnv* env, jobject surface, + JAWT_DrawingSurface** ods, JAWT_DrawingSurfaceInfo** odsi) { + JAWT awt; - JAWT_DrawingSurface *ds = nullptr; - JAWT_DrawingSurfaceInfo *dsi = nullptr; + JAWT_DrawingSurface* ds = nullptr; + JAWT_DrawingSurfaceInfo* dsi = nullptr; // Search for a valid AWT - jboolean foundJawt = false; - for(int jawtVersion : jawtVersions) { + jboolean foundJawt = JNI_FALSE; + for (int jawtVersion : jawtVersions) { awt.version = jawtVersion; foundJawt = JAWT_GetAWT(env, &awt); if (foundJawt == JNI_TRUE) { +#ifndef NDEBUG printf("Found valid AWT v%08x.\n", jawtVersion); +#endif break; } else { +#ifndef NDEBUG printf("AWT v%08x not present.\n", jawtVersion); +#endif } } +#ifndef NDEBUG fflush(stdout); +#endif if (foundJawt == JNI_FALSE) { printf("AWT Not found\n"); fflush(stdout); - return 0; + return false; } // Get the drawing surface ds = awt.GetDrawingSurface(env, surface); - if (ds == NULL) { + if (ds == nullptr) { +#ifndef NDEBUG printf("NULL drawing surface\n"); fflush(stdout); - return 0; +#endif + return false; } // Lock the drawing jint lock = ds->Lock(ds); if ((lock & JAWT_LOCK_ERROR) != 0) { +#ifndef NDEBUG printf("Error locking surface\n"); fflush(stdout); +#endif awt.FreeDrawingSurface(ds); - return 0; + return false; } // Get the drawing surface info dsi = ds->GetDrawingSurfaceInfo(ds); - if (dsi == NULL) { + if (dsi == nullptr) { +#ifndef NDEBUG printf("Error getting surface info\n"); fflush(stdout); +#endif + ds->Unlock(ds); awt.FreeDrawingSurface(ds); - return 0; + return false; } *odsi = dsi; *ods = ds; - return 1; -} -void releaseDrawingSurface(JAWT_DrawingSurface *ds, JAWT_DrawingSurfaceInfo *dsi) { + return true; +} +#pragma clang diagnostic pop + +void releaseDrawingSurface(JAWT_DrawingSurface* ds, JAWT_DrawingSurfaceInfo* dsi) { // Free the drawing surface info ds->FreeDrawingSurfaceInfo(dsi); // Unlock the drawing surface diff --git a/android/filament-android/src/main/cpp/nativewindow/JAWTUtils.h b/android/filament-android/src/main/cpp/nativewindow/JAWTUtils.h index f0e7c7ec44..0b52801266 100644 --- a/android/filament-android/src/main/cpp/nativewindow/JAWTUtils.h +++ b/android/filament-android/src/main/cpp/nativewindow/JAWTUtils.h @@ -17,7 +17,7 @@ #include extern "C" { -bool acquireDrawingSurface(JNIEnv *env, jobject obj, JAWT_DrawingSurface** ds, - JAWT_DrawingSurfaceInfo** dsi); +bool acquireDrawingSurface(JNIEnv* env, jobject surface, JAWT_DrawingSurface** ods, + JAWT_DrawingSurfaceInfo** odsi); void releaseDrawingSurface(JAWT_DrawingSurface* ds, JAWT_DrawingSurfaceInfo* dsi); } diff --git a/android/filament-android/src/main/cpp/nativewindow/Linux.cpp b/android/filament-android/src/main/cpp/nativewindow/Linux.cpp index a131555376..114a737b78 100644 --- a/android/filament-android/src/main/cpp/nativewindow/Linux.cpp +++ b/android/filament-android/src/main/cpp/nativewindow/Linux.cpp @@ -23,17 +23,17 @@ #include extern "C" { -void *getNativeWindow(JNIEnv *env, jclass, jobject surface) { - void *win = nullptr; - JAWT_DrawingSurface *ds = nullptr; - JAWT_DrawingSurfaceInfo *dsi = nullptr; +void *getNativeWindow(JNIEnv* env, jclass, jobject surface) { + void* win = nullptr; + JAWT_DrawingSurface* ds = nullptr; + JAWT_DrawingSurfaceInfo* dsi = nullptr; if (!acquireDrawingSurface(env, surface, &ds, &dsi)) { return win; } - JAWT_X11DrawingSurfaceInfo *dsi_x11 = (JAWT_X11DrawingSurfaceInfo *) dsi->platformInfo; + JAWT_X11DrawingSurfaceInfo* dsi_x11 = (JAWT_X11DrawingSurfaceInfo*) dsi->platformInfo; - win = (void *) dsi_x11->drawable; + win = (void*) dsi_x11->drawable; releaseDrawingSurface(ds, dsi); return win; } @@ -77,7 +77,7 @@ jlong createNativeSurface(jint width, jint height) { XFlush(display); // Camouflage the pbuffer as a window which are both XID anyway. - return (jlong)window; + return (jlong) window; } void destroyNativeSurface(jlong surface) { @@ -88,4 +88,3 @@ void destroyNativeSurface(jlong surface) { } } - diff --git a/android/filament-android/src/main/cpp/nativewindow/Win32.cpp b/android/filament-android/src/main/cpp/nativewindow/Win32.cpp index 8f108da4fc..8b32b5b84d 100644 --- a/android/filament-android/src/main/cpp/nativewindow/Win32.cpp +++ b/android/filament-android/src/main/cpp/nativewindow/Win32.cpp @@ -50,18 +50,22 @@ void chooseAndSetPixelFormat(HDC dc) { SetPixelFormat(dc, pixelFormat, &pfd); } -void *getNativeWindow(JNIEnv *env, jclass, jobject surface) { - void *win = nullptr; - JAWT_DrawingSurface *ds = nullptr; - JAWT_DrawingSurfaceInfo *dsi = nullptr; +void* getNativeWindow(JNIEnv* env, jclass, jobject surface) { + void* win = nullptr; + JAWT_DrawingSurface* ds = nullptr; + JAWT_DrawingSurfaceInfo* dsi = nullptr; + if (!acquireDrawingSurface(env, surface, &ds, &dsi)) { return win; } - JAWT_Win32DrawingSurfaceInfo *dsi_win32 = (JAWT_Win32DrawingSurfaceInfo *) dsi->platformInfo; + + JAWT_Win32DrawingSurfaceInfo* dsi_win32 = (JAWT_Win32DrawingSurfaceInfo*) dsi->platformInfo; HDC dc = dsi_win32->hdc; chooseAndSetPixelFormat(dsi_win32->hdc); - win = (void *) dsi_win32->hdc; + + win = (void*) dsi_win32->hdc; releaseDrawingSurface(ds, dsi); + return win; } @@ -77,13 +81,15 @@ jlong createNativeSurface(jint width, jint height) { HWND window = CreateWindowA("STATIC", "dummy", 0, 0, 0, width, height, NULL, NULL, NULL, NULL); SetWindowLong(window, GWL_STYLE, 0); //remove all window styles + HDC dc = GetDC(window); chooseAndSetPixelFormat(dc); - return (jlong)dc; + + return (jlong) dc; } void destroyNativeSurface(jlong surface) { - HDC dc = (HDC)surface; + HDC dc = (HDC) surface; HWND window = WindowFromDC(dc); ReleaseDC(window, dc); DestroyWindow(window); diff --git a/libs/filameshio/include/filameshio/MeshIO.h b/libs/filameshio/include/filameshio/MeshIO.h index b82b52fbd6..7025c86f92 100644 --- a/libs/filameshio/include/filameshio/MeshIO.h +++ b/libs/filameshio/include/filameshio/MeshIO.h @@ -30,6 +30,11 @@ namespace filament { class MaterialInstance; } +/** + * This API can be used to read meshes stored in the "filamesh" format produced + * by the command line tool of the same name. This file format is documented in + * "docs/filamesh.md" in the Filament distribution. + */ class MeshIO { public: using Callback = void(*)(void* buffer, size_t size, void* user); @@ -41,15 +46,34 @@ public: filament::IndexBuffer* indexBuffer = nullptr; }; + /** + * Loads a filamesh renderable from the specified file. The material registry + * can be used to provide named materials. If a material found in the filamesh + * file cannot be matched to a material in the registry, a default material is + * used instead. The default material can be overridden by adding a material + * named "DefaultMaterial" to the registry. + */ static Mesh loadMeshFromFile(filament::Engine* engine, const utils::Path& path, const MaterialRegistry& materials); - static Mesh loadMeshFromBuffer(filament::Engine* engine, + /** + * Loads a filamesh renderable from an in-memory buffer. The material registry + * can be used to provide named materials. If a material found in the filamesh + * file cannot be matched to a material in the registry, a default material is + * used instead. The default material can be overridden by adding a material + * named "DefaultMaterial" to the registry. + */ + static Mesh loadMeshFromBuffer(filament::Engine* engine, void const* data, Callback destructor, void* user, const MaterialRegistry& materials); - static Mesh loadMeshFromBuffer(filament::Engine* engine, + /** + * Loads a filamesh renderable from the specified file. The material registry + * can be used to provide named materials. All the primitives of the decoded + * renderable are assigned the specified default material. + */ + static Mesh loadMeshFromBuffer(filament::Engine* engine, void const* data, Callback destructor, void* user, filament::MaterialInstance* defaultMaterial); };