Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/nativeapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../src/accessibility_manager.h"
#include "../src/app_info.h"
#include "../src/application.h"
#include "../src/capture_source.h"
#include "../src/clipboard.h"
#include "../src/device_info.h"
#include "../src/dialog.h"
Expand All @@ -29,6 +30,8 @@
#include "../src/placement.h"
#include "../src/positioning_strategy.h"
#include "../src/preferences.h"
#include "../src/screen_capturer.h"
#include "../src/screen_recorder.h"
#include "../src/secure_storage.h"
#include "../src/shortcut.h"
#include "../src/shortcut_manager.h"
Expand All @@ -47,6 +50,7 @@
#include "../src/capi/accessibility_manager_c.h"
#include "../src/capi/app_info_c.h"
#include "../src/capi/application_c.h"
#include "../src/capi/capture_source_c.h"
#include "../src/capi/clipboard_c.h"
#include "../src/capi/color_c.h"
#include "../src/capi/common_c.h"
Expand All @@ -69,6 +73,8 @@
#include "../src/capi/placement_c.h"
#include "../src/capi/positioning_strategy_c.h"
#include "../src/capi/preferences_c.h"
#include "../src/capi/screen_capturer_c.h"
#include "../src/capi/screen_recorder_c.h"
#include "../src/capi/secure_storage_c.h"
#include "../src/capi/shortcut_c.h"
#include "../src/capi/shortcut_manager_c.h"
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(nativeapi PUBLIC PkgConfig::GTK PkgConfig::X11 PkgConfig::XI pthread)
elseif(APPLE)
target_link_libraries(nativeapi PUBLIC "-framework Cocoa")
target_link_libraries(nativeapi PUBLIC "-weak_framework ScreenCaptureKit" "-framework AVFoundation"
"-framework CoreMedia" "-framework CoreVideo" "-framework VideoToolbox")
target_link_libraries(nativeapi PUBLIC "-framework QuartzCore")
target_link_libraries(nativeapi PUBLIC "-framework Carbon")
target_link_libraries(nativeapi PUBLIC "-framework ServiceManagement")
Expand All @@ -111,4 +113,5 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
set_target_properties(nativeapi PROPERTIES POSITION_INDEPENDENT_CODE ON)
elseif(WIN32)
target_link_libraries(nativeapi PUBLIC user32 shell32 ole32 uuid comctl32 dwmapi gdiplus crypt32 advapi32 version)
target_link_libraries(nativeapi PUBLIC d3d11 dxgi windowsapp runtimeobject mfplat mfreadwrite mfuuid windowscodecs)
endif ()
74 changes: 74 additions & 0 deletions src/capi/capture_source_c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// AUTO-GENERATED. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.

#include "capture_source_c.h"

#include <cstdio>
#include <memory>
#include <new>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "string_utils_c.h"
#include "user_data.h"
#include "../foundation/handle_table.h"
#include "../display.h"
#include "display_c.h"
#include "../window.h"
#include "window_c.h"
#include "../capture_source.h"

native_capture_source_t native_capture_source_from_display(native_display_t display) {
try {
auto display_cpp = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::Display>(display);
return nativeapi::HandleTable::GetInstance().Insert(nativeapi::CaptureSource::FromDisplay(display_cpp));
} catch (...) {
fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_capture_source_from_display");
return 0;
}
}

native_capture_source_t native_capture_source_from_window(native_window_t window) {
try {
auto window_cpp = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::Window>(window);
return nativeapi::HandleTable::GetInstance().Insert(nativeapi::CaptureSource::FromWindow(window_cpp));
} catch (...) {
fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_capture_source_from_window");
return 0;
}
}

native_capture_source_type_t native_capture_source_get_type(native_capture_source_t capture_source) {
auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::CaptureSource>(capture_source);
if (!self) {
return (native_capture_source_type_t)NATIVE_CAPTURE_SOURCE_TYPE_NONE;
}
try {
return to_c_capture_source_type(self->GetType());
} catch (...) {
fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_capture_source_get_type");
return (native_capture_source_type_t)NATIVE_CAPTURE_SOURCE_TYPE_NONE;
}
}

char* native_capture_source_get_name(native_capture_source_t capture_source) {
auto self = nativeapi::HandleTable::GetInstance().Resolve<nativeapi::CaptureSource>(capture_source);
if (!self) {
return nullptr;
}
try {
return to_c_str(self->GetName());
} catch (...) {
fprintf(stderr, "[nativeapi] %s: unexpected exception\n", "native_capture_source_get_name");
return nullptr;
}
}

void native_capture_source_free(native_capture_source_t capture_source) {
// The table invalidates the handle itself, so releasing an unknown or
// already-released one is a no-op rather than a double free.
nativeapi::HandleTable::GetInstance().Release(capture_source);
}

108 changes: 108 additions & 0 deletions src/capi/capture_source_c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// AUTO-GENERATED. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.

#pragma once

#include <stdbool.h>
#include <stdint.h>

#include "common_c.h"
typedef uint64_t native_display_t;
typedef uint64_t native_window_t;

#include "display_c.h"
#include "window_c.h"

#if _WIN32
#define FFI_PLUGIN_EXPORT __declspec(dllexport)
#else
#define FFI_PLUGIN_EXPORT
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
NATIVE_CAPTURE_SOURCE_TYPE_NONE = 0,
NATIVE_CAPTURE_SOURCE_TYPE_DISPLAY = 1,
NATIVE_CAPTURE_SOURCE_TYPE_WINDOW = 2,
NATIVE_CAPTURE_SOURCE_TYPE_UNKNOWN = 3,
} native_capture_source_type_t;

/// Opaque CaptureSource handle.
///
/// A generational index into the library's handle table, NOT a pointer:
/// never dereference it, and compare it against NATIVE_INVALID_CAPTURE_SOURCE rather than NULL.
/// Releasing a handle invalidates it; later calls fail safely instead of
/// touching freed memory.
typedef uint64_t native_capture_source_t;

/// Never refers to a live CaptureSource.
#define NATIVE_INVALID_CAPTURE_SOURCE ((native_capture_source_t)0)

/// Caller owns the returned handle; release it with native_capture_source_free().
FFI_PLUGIN_EXPORT
native_capture_source_t native_capture_source_from_display(native_display_t display);

/// Caller owns the returned handle; release it with native_capture_source_free().
FFI_PLUGIN_EXPORT
native_capture_source_t native_capture_source_from_window(native_window_t window);

FFI_PLUGIN_EXPORT
native_capture_source_type_t native_capture_source_get_type(native_capture_source_t capture_source);

/// Caller owns the returned string; free it with free_c_str().
FFI_PLUGIN_EXPORT
char* native_capture_source_get_name(native_capture_source_t capture_source);

/// Releases the caller's reference. Safe to call with an invalid or
/// already-released handle.
FFI_PLUGIN_EXPORT
void native_capture_source_free(native_capture_source_t capture_source);

#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
#include "../capture_source.h"
#include "string_utils_c.h"
#include "user_data.h"

// Conversion helpers between these C types and their C++ originals.

inline native_capture_source_type_t to_c_capture_source_type(nativeapi::CaptureSourceType value);
inline nativeapi::CaptureSourceType to_cpp_capture_source_type(native_capture_source_type_t value);

inline native_capture_source_type_t to_c_capture_source_type(nativeapi::CaptureSourceType value) {
switch (value) {
case nativeapi::CaptureSourceType::None:
return NATIVE_CAPTURE_SOURCE_TYPE_NONE;
case nativeapi::CaptureSourceType::Display:
return NATIVE_CAPTURE_SOURCE_TYPE_DISPLAY;
case nativeapi::CaptureSourceType::Window:
return NATIVE_CAPTURE_SOURCE_TYPE_WINDOW;
case nativeapi::CaptureSourceType::Unknown:
return NATIVE_CAPTURE_SOURCE_TYPE_UNKNOWN;
default:
return NATIVE_CAPTURE_SOURCE_TYPE_NONE;
}
}

inline nativeapi::CaptureSourceType to_cpp_capture_source_type(native_capture_source_type_t value) {
switch (value) {
case NATIVE_CAPTURE_SOURCE_TYPE_NONE:
return nativeapi::CaptureSourceType::None;
case NATIVE_CAPTURE_SOURCE_TYPE_DISPLAY:
return nativeapi::CaptureSourceType::Display;
case NATIVE_CAPTURE_SOURCE_TYPE_WINDOW:
return nativeapi::CaptureSourceType::Window;
case NATIVE_CAPTURE_SOURCE_TYPE_UNKNOWN:
return nativeapi::CaptureSourceType::Unknown;
default:
return static_cast<nativeapi::CaptureSourceType>(value);
}
}

#endif // __cplusplus
6 changes: 6 additions & 0 deletions src/capi/color_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,9 @@ unsigned int native_color_to_argb(native_color_t color) {
}
}

void native_color_free(native_color_t* value) {
if (!value) {
return;
}
}

4 changes: 4 additions & 0 deletions src/capi/color_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ unsigned int native_color_to_rgba(native_color_t color);
FFI_PLUGIN_EXPORT
unsigned int native_color_to_argb(native_color_t color);

/// Frees everything the struct owns.
FFI_PLUGIN_EXPORT
void native_color_free(native_color_t* value);

#ifdef __cplusplus
}
#endif
Expand Down
24 changes: 24 additions & 0 deletions src/capi/geometry_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
#include "../foundation/handle_table.h"
#include "../foundation/geometry.h"

void native_point_free(native_point_t* value) {
if (!value) {
return;
}
}

void native_size_free(native_size_t* value) {
if (!value) {
return;
}
}

void native_rectangle_free(native_rectangle_t* value) {
if (!value) {
return;
}
}

native_edge_insets_t native_edge_insets_all(double value) {
try {
const auto cpp_result = nativeapi::EdgeInsets::All(value);
Expand All @@ -38,3 +56,9 @@ native_edge_insets_t native_edge_insets_symmetric(double vertical, double horizo
}
}

void native_edge_insets_free(native_edge_insets_t* value) {
if (!value) {
return;
}
}

16 changes: 16 additions & 0 deletions src/capi/geometry_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,28 @@ typedef struct {
double left;
} native_edge_insets_t;

/// Frees everything the struct owns.
FFI_PLUGIN_EXPORT
void native_point_free(native_point_t* value);

/// Frees everything the struct owns.
FFI_PLUGIN_EXPORT
void native_size_free(native_size_t* value);

/// Frees everything the struct owns.
FFI_PLUGIN_EXPORT
void native_rectangle_free(native_rectangle_t* value);

FFI_PLUGIN_EXPORT
native_edge_insets_t native_edge_insets_all(double value);

FFI_PLUGIN_EXPORT
native_edge_insets_t native_edge_insets_symmetric(double vertical, double horizontal);

/// Frees everything the struct owns.
FFI_PLUGIN_EXPORT
void native_edge_insets_free(native_edge_insets_t* value);

#ifdef __cplusplus
}
#endif
Expand Down
Loading
Loading