From c78adf6b63935d744bdad8b112cb02b29047aae7 Mon Sep 17 00:00:00 2001 From: Adam Simmons Date: Fri, 24 Mar 2023 19:44:13 -0500 Subject: [PATCH] Updating headers for latest trunk (1.3 stable) --- AppCore/JSHelpers.h | 6 +- AppCore/Window.h | 34 +- Ultralight/Bitmap.h | 97 +- Ultralight/Buffer.h | 57 +- Ultralight/CAPI.h | 1954 +---------------------- Ultralight/CAPI/CAPI_Bitmap.h | 116 ++ Ultralight/CAPI/CAPI_Buffer.h | 65 + Ultralight/CAPI/CAPI_Clipboard.h | 41 + Ultralight/CAPI/CAPI_Config.h | 160 ++ Ultralight/CAPI/CAPI_Defines.h | 274 ++++ Ultralight/CAPI/CAPI_FileSystem.h | 64 + Ultralight/CAPI/CAPI_FontFile.h | 33 + Ultralight/CAPI/CAPI_FontLoader.h | 66 + Ultralight/CAPI/CAPI_GPUDriver.h | 319 ++++ Ultralight/CAPI/CAPI_Geometry.h | 42 + Ultralight/CAPI/CAPI_KeyEvent.h | 46 + Ultralight/CAPI/CAPI_Logger.h | 29 + Ultralight/CAPI/CAPI_MouseEvent.h | 28 + Ultralight/CAPI/CAPI_Platform.h | 94 ++ Ultralight/CAPI/CAPI_Renderer.h | 68 + Ultralight/CAPI/CAPI_ScrollEvent.h | 28 + Ultralight/CAPI/CAPI_Session.h | 56 + Ultralight/CAPI/CAPI_String.h | 68 + Ultralight/CAPI/CAPI_Surface.h | 203 +++ Ultralight/CAPI/CAPI_View.h | 486 ++++++ Ultralight/Defines.h | 18 +- Ultralight/GamepadEvent.h | 115 ++ Ultralight/Geometry.h | 6 +- Ultralight/JavaScript.h | 7 +- Ultralight/KeyCodes.h | 685 ++++---- Ultralight/KeyEvent.h | 75 +- Ultralight/Listener.h | 117 +- Ultralight/Matrix.h | 12 +- Ultralight/MouseEvent.h | 14 +- Ultralight/RefPtr.h | 2 +- Ultralight/RenderTarget.h | 2 +- Ultralight/Renderer.h | 133 +- Ultralight/ScrollEvent.h | 10 +- Ultralight/Session.h | 14 +- Ultralight/String.h | 2 +- Ultralight/String16.h | 2 +- Ultralight/String32.h | 2 +- Ultralight/String8.h | 2 +- Ultralight/Ultralight.h | 2 +- Ultralight/View.h | 206 ++- Ultralight/platform/Clipboard.h | 2 +- Ultralight/platform/Config.h | 31 +- Ultralight/platform/FileSystem.h | 64 +- Ultralight/platform/FontLoader.h | 2 +- Ultralight/platform/GPUDriver.h | 2 +- Ultralight/platform/Logger.h | 2 +- Ultralight/platform/Platform.h | 2 +- Ultralight/platform/Surface.h | 2 +- Ultralight/private/PlatformFileSystem.h | 17 - 54 files changed, 3354 insertions(+), 2630 deletions(-) create mode 100644 Ultralight/CAPI/CAPI_Bitmap.h create mode 100644 Ultralight/CAPI/CAPI_Buffer.h create mode 100644 Ultralight/CAPI/CAPI_Clipboard.h create mode 100644 Ultralight/CAPI/CAPI_Config.h create mode 100644 Ultralight/CAPI/CAPI_Defines.h create mode 100644 Ultralight/CAPI/CAPI_FileSystem.h create mode 100644 Ultralight/CAPI/CAPI_FontFile.h create mode 100644 Ultralight/CAPI/CAPI_FontLoader.h create mode 100644 Ultralight/CAPI/CAPI_GPUDriver.h create mode 100644 Ultralight/CAPI/CAPI_Geometry.h create mode 100644 Ultralight/CAPI/CAPI_KeyEvent.h create mode 100644 Ultralight/CAPI/CAPI_Logger.h create mode 100644 Ultralight/CAPI/CAPI_MouseEvent.h create mode 100644 Ultralight/CAPI/CAPI_Platform.h create mode 100644 Ultralight/CAPI/CAPI_Renderer.h create mode 100644 Ultralight/CAPI/CAPI_ScrollEvent.h create mode 100644 Ultralight/CAPI/CAPI_Session.h create mode 100644 Ultralight/CAPI/CAPI_String.h create mode 100644 Ultralight/CAPI/CAPI_Surface.h create mode 100644 Ultralight/CAPI/CAPI_View.h create mode 100644 Ultralight/GamepadEvent.h delete mode 100644 Ultralight/private/PlatformFileSystem.h diff --git a/AppCore/JSHelpers.h b/AppCore/JSHelpers.h index 01ab5ed..da0ad65 100644 --- a/AppCore/JSHelpers.h +++ b/AppCore/JSHelpers.h @@ -45,16 +45,16 @@ class AExport JSString { /// Create from Ultralight String JSString(const String& str); - /// Take ownership of existing JSStringRef (will not increase ref-count) + /// Create from existing JSStringRef JSString(JSStringRef str); - /// Copy constructor (will increase ref-count) + /// Copy constructor JSString(const JSString& other); /// Destructor ~JSString(); - /// Assignment operator (will increase ref-count) + /// Assignment operator JSString& operator=(const JSString& other); /// Cast to String diff --git a/AppCore/Window.h b/AppCore/Window.h index c6500e7..9609b49 100644 --- a/AppCore/Window.h +++ b/AppCore/Window.h @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include namespace ultralight { @@ -34,7 +37,7 @@ class WindowListener { /// /// Called when the Window is closed. /// - virtual void OnClose(ultralight::Window* window) = 0; + virtual void OnClose(ultralight::Window* window) { } /// /// Called when the Window is resized. @@ -43,7 +46,34 @@ class WindowListener { /// /// @param height The new height (in pixels). /// - virtual void OnResize(ultralight::Window* window, uint32_t width_px, uint32_t height_px) = 0; + virtual void OnResize(ultralight::Window* window, uint32_t width_px, uint32_t height_px) { } + + /// + /// Called when a keyboard event is fired. + /// + /// @param evt Details for the event. + /// + /// @return Return false to consume the event and prevent it from propagating further. + /// + virtual bool OnKeyEvent(const ultralight::KeyEvent& evt) { return true; } + + /// + /// Called when a mouse event is fired. + /// + /// @param evt Details for the event. + /// + /// @return Return false to consume the event and prevent it from propagating further. + /// + virtual bool OnMouseEvent(const ultralight::MouseEvent& evt) { return true; } + + /// + /// Called when a scroll event is fired. + /// + /// @param evt Details for the event. + /// + /// @return Return false to consume the event and prevent it from propagating further. + /// + virtual bool OnScrollEvent(const ultralight::ScrollEvent& evt) { return true; } }; /// diff --git a/Ultralight/Bitmap.h b/Ultralight/Bitmap.h index dab8466..1da64b2 100644 --- a/Ultralight/Bitmap.h +++ b/Ultralight/Bitmap.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2021 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include @@ -18,8 +18,6 @@ namespace ultralight { -#pragma pack(push, 1) - /// /// The various Bitmap formats. /// @@ -48,6 +46,12 @@ enum class UExport BitmapFormat : uint8_t { /// #define GetBytesPerPixel(x) (x == BitmapFormat::A8_UNORM ? 1 : 4) +/// +/// Forward declaration for the LockedPixels class. +/// +template +class LockedPixels; + /// /// @brief Bitmap container with basic blitting and conversion routines. /// @@ -71,6 +75,25 @@ class UExport Bitmap : public RefCounted { /// static RefPtr Create(uint32_t width, uint32_t height, BitmapFormat format); + /// + /// Create an aligned Bitmap with a certain configuration. Pixels will be allocated but not + /// initialized. Row bytes will be padded to reach the specified alignment. + /// + /// @param width The width in pixels. + /// + /// @param height The height in pixels. + /// + /// @param format The pixel format to use. + /// + /// @param alignment The alignment (in bytes) to use. Row bytes will be padded to reach a + /// multiple of this value and the underlying storage will be allocated with + /// this alignment. + /// + /// @return A ref-pointer to a new Bitmap instance. + /// + static RefPtr Create(uint32_t width, uint32_t height, BitmapFormat format, + uint32_t alignment); + /// /// Create a Bitmap with existing pixels and configuration. /// @@ -148,6 +171,14 @@ class UExport Bitmap : public RefCounted { /// virtual bool owns_pixels() const = 0; + /// + /// Lock the pixel buffer for reading/writing (safe version, automatically unlocks). + /// + /// @return A managed container that can be used to access the pixels (LockedPixels::data()). + /// This container will automatically unlock the pixels when it goes out of scope. + /// + virtual LockedPixels> LockPixelsSafe() const = 0; + /// /// Lock the pixel buffer for reading/writing. /// @@ -213,7 +244,7 @@ class UExport Bitmap : public RefCounted { /// edge pixels from the source bitmap. /// /// @return Whether or not the operation succeeded (this can fail if the src_rect and/or - /// dest_rect are invalid, or if their total dimensions do not match). + /// dest_rect are invalid). /// virtual bool DrawBitmap(IntRect src_rect, IntRect dest_rect, RefPtr src, bool pad_repeat) = 0; @@ -277,6 +308,62 @@ class UExport Bitmap : public RefCounted { void operator=(const Bitmap&); }; -#pragma pack(pop) +template +class LockedPixels { + public: + LockedPixels(const LockedPixels&) = delete; + LockedPixels& operator=(const LockedPixels&) = delete; + LockedPixels(int) = delete; + explicit LockedPixels(T& lockable) : lockable_(lockable), data_(nullptr), size_(0) { lock(); } + + ~LockedPixels() { + if (lockable_) + lockable_->UnlockPixels(); + } + + /// + /// Access the locked pixel data. + /// + void* data() { return data_; } + + /// + /// Access the size of the locked pixel data. + /// + size_t size() { return size_; } + + explicit operator bool() const { return !!lockable_; } + + LockedPixels(LockedPixels&& other) : lockable_(other.lockable_), data_(other.data_), + size_(other.size_) { + other.lockable_ = nullptr; + other.data_ = nullptr; + other.size_ = 0; + } + + LockedPixels& operator=(LockedPixels&& other) { + if (lockable_) + lockable_->UnlockPixels(); + lockable_ = other.lockable_; + data_ = other.data_; + size_ = other.size_; + other.lockable_ = nullptr; + other.data_ = nullptr; + other.size_ = 0; + return *this; + } + + private: + void lock() { + if (lockable_) { + data_ = lockable_->LockPixels(); + size_ = lockable_->size(); + } + } + + T lockable_; + void* data_; + size_t size_; +}; + } // namespace ultralight diff --git a/Ultralight/Buffer.h b/Ultralight/Buffer.h index 835b13f..6501c3a 100644 --- a/Ultralight/Buffer.h +++ b/Ultralight/Buffer.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2021 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include @@ -17,18 +17,49 @@ namespace ultralight { +/// +/// Function signature for a user-defined destruction callback to be optionally called when Buffer +/// is destroyed. +/// +/// @param user_data Pointer to user-defined user-data (this will be the same value as what was +/// passed to Buffer::Create, if any) +/// +/// @param data Pointer to raw Buffer data. +/// +typedef void (*DestroyBufferCallback)(void* user_data, void* data); + /// /// A fixed-size byte container for passing data around. /// class UExport Buffer : public RefCounted { -public: + public: + /// + /// Create a Buffer from existing, user-owned data without any copies. An optional, user-supplied + /// callback will be called to deallocate data upon destruction. + /// + /// @param data A pointer to the data. + /// + /// @param size Size of the data in bytes. + /// + /// @param user_data Optional user data that will be passed to destruction_callback + /// when the returned Buffer is destroyed. + /// + /// @param destruction_callback Optional callback that will be called upon destruction. Pass a + /// null pointer if you don't want to be informed of destruction. + /// /// - /// Create a Buffer, a copy of data is made. + /// @return A ref-counted Buffer object that wraps the existing data. /// - static RefPtr Create(const void* data, size_t size); + static RefPtr Create(void* data, size_t size, void* user_data, + DestroyBufferCallback destruction_callback); /// - /// Get a pointer to raw byte data. + /// Create a Buffer from existing data, a deep copy of data will be made. + /// + static RefPtr CreateFromCopy(const void* data, size_t size); + + /// + /// Get a pointer to the raw byte data. /// virtual void* data() = 0; @@ -37,11 +68,23 @@ class UExport Buffer : public RefCounted { /// virtual size_t size() const = 0; -protected: + /// + /// Get the user data associated with this Buffer, if any. + /// + virtual void* user_data() = 0; + + /// + /// Check whether this Buffer owns its own data (Buffer was created via CreateFromCopy). + /// If this is false, Buffer will call the user-supplied destruction callback to deallocate data + /// when this Buffer instance is destroyed. + /// + virtual bool owns_data() const = 0; + + protected: Buffer(); virtual ~Buffer(); Buffer(const Buffer&); void operator=(const Buffer&); }; -} // namespace ultralight +} // namespace ultralight diff --git a/Ultralight/CAPI.h b/Ultralight/CAPI.h index 2b07103..4f4d041 100644 --- a/Ultralight/CAPI.h +++ b/Ultralight/CAPI.h @@ -9,257 +9,11 @@ /// /// Website: /// -/// Copyright (C) 2020 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #ifndef ULTRALIGHT_CAPI_H #define ULTRALIGHT_CAPI_H -#ifndef __cplusplus -//#include -#endif - -#include -#include -#ifdef __OBJC__ -#import -#endif - -#if defined(ULTRALIGHT_STATIC_BUILD) -# define ULExport -#else -# if defined(__WIN32__) || defined(_WIN32) -# if defined(ULTRALIGHT_IMPLEMENTATION) -# define ULExport __declspec(dllexport) -# else -# define ULExport __declspec(dllimport) -# endif -# else -# define ULExport __attribute__((visibility("default"))) -# endif -#endif - -#if defined(__WIN32__) || defined(_WIN32) -# define _thread_local __declspec(thread) -# ifndef _NATIVE_WCHAR_T_DEFINED -# define DISABLE_NATIVE_WCHAR_T - typedef unsigned short ULChar16; -# else - typedef wchar_t ULChar16; -# endif -#else -# define _thread_local __thread - typedef unsigned short ULChar16; -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct C_Config* ULConfig; -typedef struct C_Renderer* ULRenderer; -typedef struct C_Session* ULSession; -typedef struct C_ViewConfig* ULViewConfig; -typedef struct C_View* ULView; -typedef struct C_Bitmap* ULBitmap; -typedef struct C_String* ULString; -typedef struct C_Buffer* ULBuffer; -typedef struct C_KeyEvent* ULKeyEvent; -typedef struct C_MouseEvent* ULMouseEvent; -typedef struct C_ScrollEvent* ULScrollEvent; -typedef struct C_Surface* ULSurface; -typedef struct C_Surface* ULBitmapSurface; - -typedef enum { - kMessageSource_XML = 0, - kMessageSource_JS, - kMessageSource_Network, - kMessageSource_ConsoleAPI, - kMessageSource_Storage, - kMessageSource_AppCache, - kMessageSource_Rendering, - kMessageSource_CSS, - kMessageSource_Security, - kMessageSource_ContentBlocker, - kMessageSource_Other, -} ULMessageSource; - -typedef enum { - kMessageLevel_Log = 1, - kMessageLevel_Warning = 2, - kMessageLevel_Error = 3, - kMessageLevel_Debug = 4, - kMessageLevel_Info = 5, -} ULMessageLevel; - -typedef enum { - kCursor_Pointer = 0, - kCursor_Cross, - kCursor_Hand, - kCursor_IBeam, - kCursor_Wait, - kCursor_Help, - kCursor_EastResize, - kCursor_NorthResize, - kCursor_NorthEastResize, - kCursor_NorthWestResize, - kCursor_SouthResize, - kCursor_SouthEastResize, - kCursor_SouthWestResize, - kCursor_WestResize, - kCursor_NorthSouthResize, - kCursor_EastWestResize, - kCursor_NorthEastSouthWestResize, - kCursor_NorthWestSouthEastResize, - kCursor_ColumnResize, - kCursor_RowResize, - kCursor_MiddlePanning, - kCursor_EastPanning, - kCursor_NorthPanning, - kCursor_NorthEastPanning, - kCursor_NorthWestPanning, - kCursor_SouthPanning, - kCursor_SouthEastPanning, - kCursor_SouthWestPanning, - kCursor_WestPanning, - kCursor_Move, - kCursor_VerticalText, - kCursor_Cell, - kCursor_ContextMenu, - kCursor_Alias, - kCursor_Progress, - kCursor_NoDrop, - kCursor_Copy, - kCursor_None, - kCursor_NotAllowed, - kCursor_ZoomIn, - kCursor_ZoomOut, - kCursor_Grab, - kCursor_Grabbing, - kCursor_Custom -} ULCursor; - -typedef enum { - /// - /// Alpha channel only, 8-bits per pixel. - /// - /// Encoding: 8-bits per channel, unsigned normalized. - /// - /// Color-space: Linear (no gamma), alpha-coverage only. - /// - kBitmapFormat_A8_UNORM, - - /// - /// Blue Green Red Alpha channels, 32-bits per pixel. - /// - /// Encoding: 8-bits per channel, unsigned normalized. - /// - /// Color-space: sRGB gamma with premultiplied linear alpha channel. - /// - kBitmapFormat_BGRA8_UNORM_SRGB -} ULBitmapFormat; - -typedef enum { - /// - /// Key-Down event type. (Does not trigger accelerator commands in WebCore) - /// - /// @NOTE: You should probably use RawKeyDown instead when a physical key - /// is pressed. This member is only here for historic compatibility - /// with WebCore's key event types. - /// - kKeyEventType_KeyDown, - - /// - /// Key-Up event type. Use this when a physical key is released. - /// - kKeyEventType_KeyUp, - - /// - /// Raw Key-Down type. Use this when a physical key is pressed. - /// - /// @NOTE: You should use RawKeyDown for physical key presses since it - /// allows WebCore to do additional command translation. - /// - kKeyEventType_RawKeyDown, - - /// - /// Character input event type. Use this when the OS generates text from - /// a physical key being pressed (eg, WM_CHAR on Windows). - /// - kKeyEventType_Char, -} ULKeyEventType; - -typedef enum { - kMouseEventType_MouseMoved, - kMouseEventType_MouseDown, - kMouseEventType_MouseUp, -} ULMouseEventType; - -typedef enum { - kMouseButton_None = 0, - kMouseButton_Left, - kMouseButton_Middle, - kMouseButton_Right, -} ULMouseButton; - -typedef enum { - kScrollEventType_ScrollByPixel, - kScrollEventType_ScrollByPage, -} ULScrollEventType; - -typedef enum { - kFaceWinding_Clockwise, - kFaceWindow_CounterClockwise, -} ULFaceWinding; - -typedef enum { - /// - /// Lighter hinting algorithm-- glyphs are slightly fuzzier but better - /// resemble their original shape. This is achieved by snapping glyphs to the - /// pixel grid only vertically which better preserves inter-glyph spacing. - /// - kFontHinting_Smooth, - - /// - /// Default hinting algorithm-- offers a good balance between sharpness and - /// shape at smaller font sizes. - /// - kFontHinting_Normal, - - /// - /// Strongest hinting algorithm-- outputs only black/white glyphs. The result - /// is usually unpleasant if the underlying TTF does not contain hints for - /// this type of rendering. - /// - kFontHinting_Monochrome, -} ULFontHinting; - -typedef struct { - float left; - float top; - float right; - float bottom; -} ULRect; - -typedef struct { - int left; - int top; - int right; - int bottom; -} ULIntRect; - -typedef struct { - bool is_empty; - unsigned int width; - unsigned int height; - unsigned int texture_id; - unsigned int texture_width; - unsigned int texture_height; - ULBitmapFormat texture_format; - ULRect uv_coords; - unsigned int render_buffer_id; -} ULRenderTarget; - - /****************************************************************************** * API Note: * @@ -267,1691 +21,25 @@ typedef struct { * any objects returned from the API or callbacks unless otherwise noted. *****************************************************************************/ -/****************************************************************************** - * Version - *****************************************************************************/ - -/// -/// Get the version string of the library in MAJOR.MINOR.PATCH format. -/// -ULExport const char* ulVersionString(); - -/// -/// Get the numeric major version of the library. -/// -ULExport unsigned int ulVersionMajor(); - -/// -/// Get the numeric minor version of the library. -/// -ULExport unsigned int ulVersionMinor(); - -/// -/// Get the numeric patch version of the library. -/// -ULExport unsigned int ulVersionPatch(); - -/****************************************************************************** - * Config - *****************************************************************************/ - -/// -/// Create config with default values (see ). -/// -ULExport ULConfig ulCreateConfig(); - -/// -/// Destroy config. -/// -ULExport void ulDestroyConfig(ULConfig config); - -/// -/// Set the file path to a writable directory that will be used to store -/// cookies, cached resources, and other persistent data. -/// -ULExport void ulConfigSetCachePath(ULConfig config, ULString cache_path); - -/// -/// The winding order for front-facing triangles. @see FaceWinding -/// -/// Note: This is only used with custom GPUDrivers -/// -ULExport void ulConfigSetFaceWinding(ULConfig config, ULFaceWinding winding); - -/// -/// The hinting algorithm to use when rendering fonts. (Default = kFontHinting_Normal) -/// @see ULFontHinting -/// -ULExport void ulConfigSetFontHinting(ULConfig config, ULFontHinting font_hinting); - -/// -/// The gamma to use when compositing font glyphs, change this value to -/// adjust contrast (Adobe and Apple prefer 1.8, others may prefer 2.2). -/// (Default = 1.8) -/// -ULExport void ulConfigSetFontGamma(ULConfig config, double font_gamma); - -/// -/// Set user stylesheet (CSS) (Default = Empty). -/// -ULExport void ulConfigSetUserStylesheet(ULConfig config, ULString css_string); - -/// -/// Set whether or not we should continuously repaint any Views or compositor -/// layers, regardless if they are dirty or not. This is mainly used to -/// diagnose painting/shader issues. (Default = False) -/// -ULExport void ulConfigSetForceRepaint(ULConfig config, bool enabled); - -/// -/// Set the amount of time to wait before triggering another repaint when a -/// CSS animation is active. (Default = 1.0 / 60.0) -/// -ULExport void ulConfigSetAnimationTimerDelay(ULConfig config, double delay); - -/// -/// When a smooth scroll animation is active, the amount of time (in seconds) -/// to wait before triggering another repaint. Default is 60 Hz. -/// -ULExport void ulConfigSetScrollTimerDelay(ULConfig config, double delay); - -/// -/// The amount of time (in seconds) to wait before running the recycler (will -/// attempt to return excess memory back to the system). (Default = 4.0) -/// -ULExport void ulConfigSetRecycleDelay(ULConfig config, double delay); - -/// -/// Set the size of WebCore's memory cache for decoded images, scripts, and -/// other assets in bytes. (Default = 64 * 1024 * 1024) -/// -ULExport void ulConfigSetMemoryCacheSize(ULConfig config, unsigned int size); - -/// -/// Set the number of pages to keep in the cache. (Default = 0) -/// -ULExport void ulConfigSetPageCacheSize(ULConfig config, unsigned int size); - -/// -/// JavaScriptCore tries to detect the system's physical RAM size to set -/// reasonable allocation limits. Set this to anything other than 0 to -/// override the detected value. Size is in bytes. -/// -/// This can be used to force JavaScriptCore to be more conservative with -/// its allocation strategy (at the cost of some performance). -/// -ULExport void ulConfigSetOverrideRAMSize(ULConfig config, unsigned int size); - -/// -/// The minimum size of large VM heaps in JavaScriptCore. Set this to a -/// lower value to make these heaps start with a smaller initial value. -/// -ULExport void ulConfigSetMinLargeHeapSize(ULConfig config, unsigned int size); - -/// -/// The minimum size of small VM heaps in JavaScriptCore. Set this to a -/// lower value to make these heaps start with a smaller initial value. -/// -ULExport void ulConfigSetMinSmallHeapSize(ULConfig config, unsigned int size); - -/****************************************************************************** - * Renderer - *****************************************************************************/ - -/// -/// Create the Ultralight Renderer directly. -/// -/// Unlike ulCreateApp(), this does not use any native windows for drawing -/// and allows you to manage your own runloop and painting. This method is -/// recommended for those wishing to integrate the library into a game. -/// -/// This singleton manages the lifetime of all Views and coordinates all -/// painting, rendering, network requests, and event dispatch. -/// -/// You should only call this once per process lifetime. -/// -/// You shoud set up your platform handlers (eg, ulPlatformSetLogger, -/// ulPlatformSetFileSystem, etc.) before calling this. -/// -/// You will also need to define a font loader before calling this-- -/// as of this writing (v1.2) the only way to do this in C API is by calling -/// ulEnablePlatformFontLoader() (available in ). -/// -/// @NOTE: You should not call this if you are using ulCreateApp(), it -/// creates its own renderer and provides default implementations for -/// various platform handlers automatically. -/// -ULExport ULRenderer ulCreateRenderer(ULConfig config); - -/// -/// Destroy the renderer. -/// -ULExport void ulDestroyRenderer(ULRenderer renderer); - -/// -/// Update timers and dispatch internal callbacks (JavaScript and network). -/// -ULExport void ulUpdate(ULRenderer renderer); - -/// -/// Render all active Views. -/// -ULExport void ulRender(ULRenderer renderer); - -/// -/// Attempt to release as much memory as possible. Don't call this from any -/// callbacks or driver code. -/// -ULExport void ulPurgeMemory(ULRenderer renderer); - -/// -/// Print detailed memory usage statistics to the log. -/// (@see ulPlatformSetLogger) -/// -ULExport void ulLogMemoryUsage(ULRenderer renderer); - -/****************************************************************************** - * Session - *****************************************************************************/ - -/// -/// Create a Session to store local data in (such as cookies, local storage, -/// application cache, indexed db, etc). -/// -ULExport ULSession ulCreateSession(ULRenderer renderer, bool is_persistent, - ULString name); - -/// -/// Destroy a Session. -/// -ULExport void ulDestroySession(ULSession session); - -/// -/// Get the default session (persistent session named "default"). -/// -/// @note This session is owned by the Renderer, you shouldn't destroy it. -/// -ULExport ULSession ulDefaultSession(ULRenderer renderer); - -/// -/// Whether or not is persistent (backed to disk). -/// -ULExport bool ulSessionIsPersistent(ULSession session); - -/// -/// Unique name identifying the session (used for unique disk path). -/// -ULExport ULString ulSessionGetName(ULSession session); - -/// -/// Unique numeric Id for the session. -/// -ULExport unsigned long long ulSessionGetId(ULSession session); - -/// -/// The disk path to write to (used by persistent sessions only). -/// -ULExport ULString ulSessionGetDiskPath(ULSession session); - -/****************************************************************************** - * ViewConfig - *****************************************************************************/ - -/// -/// Create view configuration with default values (see ). -/// -ULExport ULViewConfig ulCreateViewConfig(); - -/// -/// Destroy view configuration. -/// -ULExport void ulDestroyViewConfig(ULViewConfig config); - -/// -/// When enabled, the View will be rendered to an offscreen GPU texture -/// using the GPU driver set in ulPlatformSetGPUDriver. You can fetch -/// details for the texture via ulViewGetRenderTarget. -/// -/// When disabled (the default), the View will be rendered to an offscreen -/// pixel buffer surface. This pixel buffer can optionally be provided by the user-- -/// for more info see ulViewGetSurface. -/// -ULExport void ulViewConfigSetIsAccelerated(ULViewConfig config, bool is_accelerated); - -/// -/// Set whether images should be enabled (Default = True). -/// -ULExport void ulViewConfigSetIsTransparent(ULViewConfig config, bool is_transparent); - -/// -/// Set the amount that the application DPI has been scaled, used for -/// scaling device coordinates to pixels and oversampling raster shapes -/// (Default = 1.0). -/// -ULExport void ulViewConfigSetInitialDeviceScale(ULViewConfig config, double initial_device_scale); - -ULExport void ulViewConfigSetInitialFocus(ULViewConfig config, bool is_focused); - -/// -/// Set whether images should be enabled (Default = True). -/// -ULExport void ulViewConfigSetEnableImages(ULViewConfig config, bool enabled); - -/// -/// Set whether JavaScript should be eanbled (Default = True). -/// -ULExport void ulViewConfigSetEnableJavaScript(ULViewConfig config, bool enabled); - -/// -/// Set default font-family to use (Default = Times New Roman). -/// -ULExport void ulViewConfigSetFontFamilyStandard(ULViewConfig config, ULString font_name); - -/// -/// Set default font-family to use for fixed fonts, eg
 and 
-/// (Default = Courier New).
-///
-ULExport void ulViewConfigSetFontFamilyFixed(ULViewConfig config, ULString font_name);
-
-///
-/// Set default font-family to use for serif fonts (Default = Times New Roman).
-///
-ULExport void ulViewConfigSetFontFamilySerif(ULViewConfig config, ULString font_name);
-
-///
-/// Set default font-family to use for sans-serif fonts (Default = Arial).
-///
-ULExport void ulViewConfigSetFontFamilySansSerif(ULViewConfig config, ULString font_name);
-
-///
-/// Set user agent string (See  for the default).
-///
-ULExport void ulViewConfigSetUserAgent(ULViewConfig config, ULString agent_string);
-
-/******************************************************************************
- * View
- *****************************************************************************/
-
-///
-/// Create a View with certain size (in pixels).
-///
-/// @note  You can pass null to 'session' to use the default session.
-///
-ULExport ULView ulCreateView(ULRenderer renderer, unsigned int width, unsigned int height,
-                             ULViewConfig view_config, ULSession session);
-
-///
-/// Destroy a View.
-///
-ULExport void ulDestroyView(ULView view);
-
-///
-/// Get current URL.
-///
-/// @note Don't destroy the returned string, it is owned by the View.
-///
-ULExport ULString ulViewGetURL(ULView view);
-
-///
-/// Get current title.
-///
-/// @note Don't destroy the returned string, it is owned by the View.
-///
-ULExport ULString ulViewGetTitle(ULView view);
-
-///
-/// Get the width, in pixels.
-///
-ULExport unsigned int ulViewGetWidth(ULView view);
-
-///
-/// Get the height, in pixels.
-///
-ULExport unsigned int ulViewGetHeight(ULView view);
-
-///
-/// Check if main frame is loading.
-///
-ULExport bool ulViewIsLoading(ULView view);
-
-///
-/// Get the RenderTarget for the View.
-///
-/// @note  Only valid when the GPU renderer is enabled in Config.
-///
-ULExport ULRenderTarget ulViewGetRenderTarget(ULView view);
-
-///
-/// Get the Surface for the View (native pixel buffer container).
-///
-/// @note  Only valid when the GPU renderer is disabled in Config.
-///
-///        (Will return a nullptr when the GPU renderer is enabled.)
-///
-///        The default Surface is BitmapSurface but you can provide your
-///        own Surface implementation via ulPlatformSetSurfaceDefinition.
-///
-///        When using the default Surface, you can retrieve the underlying
-///        bitmap by casting ULSurface to ULBitmapSurface and calling
-///        ulBitmapSurfaceGetBitmap().
-///
-ULExport ULSurface ulViewGetSurface(ULView view);
-
-///
-/// Load a raw string of HTML.
-///
-ULExport void ulViewLoadHTML(ULView view, ULString html_string);
-
-///
-/// Load a URL into main frame.
-///
-ULExport void ulViewLoadURL(ULView view, ULString url_string);
-
-///
-/// Resize view to a certain width and height (in pixels).
-///
-ULExport void ulViewResize(ULView view, unsigned int width,
-                           unsigned int height);
-
-///
-/// Acquire the page's JSContext for use with JavaScriptCore API.
-/// 
-/// @note  This call locks the context for the current thread. You should
-///        call ulViewUnlockJSContext() after using the context so other
-///        worker threads can modify JavaScript state.
-///
-/// @note  The lock is recusive, it's okay to call this multiple times as long
-///        as you call ulViewUnlockJSContext() the same number of times.
-///
-ULExport JSContextRef ulViewLockJSContext(ULView view);
-
-///
-/// Unlock the page's JSContext after a previous call to ulViewLockJSContext().
-///
-ULExport void ulViewUnlockJSContext(ULView view);
-
-///
-/// Evaluate a string of JavaScript and return result.
-///
-/// @param  js_string  The string of JavaScript to evaluate.
-///
-/// @param  exception  The address of a ULString to store a description of the
-///                    last exception. Pass NULL to ignore this. Don't destroy
-///                    the exception string returned, it's owned by the View.
-///
-/// @note Don't destroy the returned string, it's owned by the View. This value
-///       is reset with every call-- if you want to retain it you should copy
-///       the result to a new string via ulCreateStringFromCopy().
-///
-/// @note An example of using this API:
-///       
-///         ULString script = ulCreateString("1 + 1");
-///         ULString exception;
-///         ULString result = ulViewEvaluateScript(view, script, &exception);
-///         /* Use the result ("2") and exception description (if any) here. */
-///         ulDestroyString(script);
-///       
-/// -ULExport ULString ulViewEvaluateScript(ULView view, ULString js_string, ULString* exception); - -/// -/// Check if can navigate backwards in history. -/// -ULExport bool ulViewCanGoBack(ULView view); - -/// -/// Check if can navigate forwards in history. -/// -ULExport bool ulViewCanGoForward(ULView view); - -/// -/// Navigate backwards in history. -/// -ULExport void ulViewGoBack(ULView view); - -/// -/// Navigate forwards in history. -/// -ULExport void ulViewGoForward(ULView view); - -/// -/// Navigate to arbitrary offset in history. -/// -ULExport void ulViewGoToHistoryOffset(ULView view, int offset); - -/// -/// Reload current page. -/// -ULExport void ulViewReload(ULView view); - -/// -/// Stop all page loads. -/// -ULExport void ulViewStop(ULView view); - -/// -/// Give focus to the View. -/// -/// You should call this to give visual indication that the View has input -/// focus (changes active text selection colors, for example). -/// -ULExport void ulViewFocus(ULView view); - -/// -/// Remove focus from the View and unfocus any focused input elements. -/// -/// You should call this to give visual indication that the View has lost -/// input focus. -/// -ULExport void ulViewUnfocus(ULView view); - -/// -/// Whether or not the View has focus. -/// -ULExport bool ulViewHasFocus(ULView view); - -/// -/// Whether or not the View has an input element with visible keyboard focus -/// (indicated by a blinking caret). -/// -/// You can use this to decide whether or not the View should consume -/// keyboard input events (useful in games with mixed UI and key handling). -/// -ULExport bool ulViewHasInputFocus(ULView view); - -/// -/// Fire a keyboard event. -/// -ULExport void ulViewFireKeyEvent(ULView view, ULKeyEvent key_event); - -/// -/// Fire a mouse event. -/// -ULExport void ulViewFireMouseEvent(ULView view, ULMouseEvent mouse_event); - -/// -/// Fire a scroll event. -/// -ULExport void ulViewFireScrollEvent(ULView view, ULScrollEvent scroll_event); - -typedef void -(*ULChangeTitleCallback) (void* user_data, ULView caller, ULString title); - -/// -/// Set callback for when the page title changes. -/// -ULExport void ulViewSetChangeTitleCallback(ULView view, - ULChangeTitleCallback callback, - void* user_data); - -typedef void -(*ULChangeURLCallback) (void* user_data, ULView caller, ULString url); - -/// -/// Set callback for when the page URL changes. -/// -ULExport void ulViewSetChangeURLCallback(ULView view, - ULChangeURLCallback callback, - void* user_data); - -typedef void -(*ULChangeTooltipCallback) (void* user_data, ULView caller, ULString tooltip); - -/// -/// Set callback for when the tooltip changes (usually result of a mouse hover). -/// -ULExport void ulViewSetChangeTooltipCallback(ULView view, - ULChangeTooltipCallback callback, - void* user_data); - -typedef void -(*ULChangeCursorCallback) (void* user_data, ULView caller, ULCursor cursor); - -/// -/// Set callback for when the mouse cursor changes. -/// -ULExport void ulViewSetChangeCursorCallback(ULView view, - ULChangeCursorCallback callback, - void* user_data); - -typedef void -(*ULAddConsoleMessageCallback) (void* user_data, ULView caller, - ULMessageSource source, ULMessageLevel level, - ULString message, unsigned int line_number, - unsigned int column_number, - ULString source_id); - -/// -/// Set callback for when a message is added to the console (useful for -/// JavaScript / network errors and debugging). -/// -ULExport void ulViewSetAddConsoleMessageCallback(ULView view, - ULAddConsoleMessageCallback callback, - void* user_data); - -typedef ULView -(*ULCreateChildViewCallback) (void* user_data, ULView caller, - ULString opener_url, ULString target_url, bool is_popup, - ULIntRect popup_rect); - -/// -/// Set callback for when the page wants to create a new View. -/// -/// This is usually the result of a user clicking a link with target="_blank" -/// or by JavaScript calling window.open(url). -/// -/// To allow creation of these new Views, you should create a new View in -/// this callback, resize it to your container, -/// and return it. You are responsible for displaying the returned View. -/// -/// You should return NULL if you want to block the action. -/// -ULExport void ulViewSetCreateChildViewCallback(ULView view, - ULCreateChildViewCallback callback, - void* user_data); - -typedef void -(*ULBeginLoadingCallback) (void* user_data, ULView caller, - unsigned long long frame_id, bool is_main_frame, ULString url); - -/// -/// Set callback for when the page begins loading a new URL into a frame. -/// -ULExport void ulViewSetBeginLoadingCallback(ULView view, - ULBeginLoadingCallback callback, - void* user_data); - -typedef void -(*ULFinishLoadingCallback) (void* user_data, ULView caller, - unsigned long long frame_id, bool is_main_frame, ULString url); - -/// -/// Set callback for when the page finishes loading a URL into a frame. -/// -ULExport void ulViewSetFinishLoadingCallback(ULView view, - ULFinishLoadingCallback callback, - void* user_data); - -typedef void -(*ULFailLoadingCallback) (void* user_data, ULView caller, - unsigned long long frame_id, bool is_main_frame, ULString url, - ULString description, ULString error_domain, int error_code); - -/// -/// Set callback for when an error occurs while loading a URL into a frame. -/// -ULExport void ulViewSetFailLoadingCallback(ULView view, - ULFailLoadingCallback callback, - void* user_data); - -typedef void -(*ULWindowObjectReadyCallback) (void* user_data, ULView caller, - unsigned long long frame_id, bool is_main_frame, ULString url); - -/// -/// Set callback for when the JavaScript window object is reset for a new -/// page load. -/// -/// This is called before any scripts are executed on the page and is the -/// earliest time to setup any initial JavaScript state or bindings. -/// -/// The document is not guaranteed to be loaded/parsed at this point. If -/// you need to make any JavaScript calls that are dependent on DOM elements -/// or scripts on the page, use DOMReady instead. -/// -/// The window object is lazily initialized (this will not be called on pages -/// with no scripts). -/// -ULExport void ulViewSetWindowObjectReadyCallback(ULView view, - ULWindowObjectReadyCallback callback, - void* user_data); - -typedef void -(*ULDOMReadyCallback) (void* user_data, ULView caller, - unsigned long long frame_id, bool is_main_frame, ULString url); - -/// -/// Set callback for when all JavaScript has been parsed and the document is -/// ready. -/// -/// This is the best time to make any JavaScript calls that are dependent on -/// DOM elements or scripts on the page. -/// -ULExport void ulViewSetDOMReadyCallback(ULView view, - ULDOMReadyCallback callback, - void* user_data); - -typedef void -(*ULUpdateHistoryCallback) (void* user_data, ULView caller); - -/// -/// Set callback for when the history (back/forward state) is modified. -/// -ULExport void ulViewSetUpdateHistoryCallback(ULView view, - ULUpdateHistoryCallback callback, - void* user_data); - -/// -/// Set whether or not a view should be repainted during the next call to -/// ulRender. -/// -/// @note This flag is automatically set whenever the page content changes -/// but you can set it directly in case you need to force a repaint. -/// -ULExport void ulViewSetNeedsPaint(ULView view, bool needs_paint); - -/// -/// Whether or not a view should be painted during the next call to ulRender. -/// -ULExport bool ulViewGetNeedsPaint(ULView view); - -/// -/// Create an inspector for this View, this is useful for debugging and -/// inspecting pages locally. This will only succeed if you have the -/// inspector assets in your filesystem-- the inspector will look for -/// file:///inspector/Main.html when it loads. -/// -/// @note The initial dimensions of the returned View are 10x10, you should -/// call ulViewResize on the returned View to resize it to your desired -/// dimensions. -/// -/// @note You will need to call ulDestroyView on the returned instance -/// when you're done using it. -/// -ULExport ULView ulViewCreateInspectorView(ULView view); - -/****************************************************************************** - * String - *****************************************************************************/ - -/// -/// Create string from null-terminated ASCII C-string. -/// -ULExport ULString ulCreateString(const char* str); - -/// -/// Create string from UTF-8 buffer. -/// -ULExport ULString ulCreateStringUTF8(const char* str, size_t len); - -/// -/// Create string from UTF-16 buffer. -/// -ULExport ULString ulCreateStringUTF16(ULChar16* str, size_t len); - -/// -/// Create string from copy of existing string. -/// -ULExport ULString ulCreateStringFromCopy(ULString str); - -/// -/// Destroy string (you should destroy any strings you explicitly Create). -/// -ULExport void ulDestroyString(ULString str); - -/// -/// Get internal UTF-16 buffer data. -/// -ULExport ULChar16* ulStringGetData(ULString str); - -/// -/// Get length in UTF-16 characters. -/// -ULExport size_t ulStringGetLength(ULString str); - -/// -/// Whether this string is empty or not. -/// -ULExport bool ulStringIsEmpty(ULString str); - -/// -/// Replaces the contents of 'str' with the contents of 'new_str' -/// -ULExport void ulStringAssignString(ULString str, ULString new_str); - -/// -/// Replaces the contents of 'str' with the contents of a C-string. -/// -ULExport void ulStringAssignCString(ULString str, const char* c_str); - -/****************************************************************************** - * Bitmap - *****************************************************************************/ - -/// -/// Create empty bitmap. -/// -ULExport ULBitmap ulCreateEmptyBitmap(); - -/// -/// Create bitmap with certain dimensions and pixel format. -/// -ULExport ULBitmap ulCreateBitmap(unsigned int width, unsigned int height, - ULBitmapFormat format); - -/// -/// Create bitmap from existing pixel buffer. @see Bitmap for help using -/// this function. -/// -ULExport ULBitmap ulCreateBitmapFromPixels(unsigned int width, - unsigned int height, - ULBitmapFormat format, - unsigned int row_bytes, - const void* pixels, size_t size, - bool should_copy); - -/// -/// Create bitmap from copy. -/// -ULExport ULBitmap ulCreateBitmapFromCopy(ULBitmap existing_bitmap); - -/// -/// Destroy a bitmap (you should only destroy Bitmaps you have explicitly -/// created via one of the creation functions above. -/// -ULExport void ulDestroyBitmap(ULBitmap bitmap); - -/// -/// Get the width in pixels. -/// -ULExport unsigned int ulBitmapGetWidth(ULBitmap bitmap); - -/// -/// Get the height in pixels. -/// -ULExport unsigned int ulBitmapGetHeight(ULBitmap bitmap); - -/// -/// Get the pixel format. -/// -ULExport ULBitmapFormat ulBitmapGetFormat(ULBitmap bitmap); - -/// -/// Get the bytes per pixel. -/// -ULExport unsigned int ulBitmapGetBpp(ULBitmap bitmap); - -/// -/// Get the number of bytes per row. -/// -ULExport unsigned int ulBitmapGetRowBytes(ULBitmap bitmap); - -/// -/// Get the size in bytes of the underlying pixel buffer. -/// -ULExport size_t ulBitmapGetSize(ULBitmap bitmap); - -/// -/// Whether or not this bitmap owns its own pixel buffer. -/// -ULExport bool ulBitmapOwnsPixels(ULBitmap bitmap); - -/// -/// Lock pixels for reading/writing, returns pointer to pixel buffer. -/// -ULExport void* ulBitmapLockPixels(ULBitmap bitmap); - -/// -/// Unlock pixels after locking. -/// -ULExport void ulBitmapUnlockPixels(ULBitmap bitmap); - -/// -/// Get raw pixel buffer-- you should only call this if Bitmap is already -/// locked. -/// -ULExport void* ulBitmapRawPixels(ULBitmap bitmap); - -/// -/// Whether or not this bitmap is empty. -/// -ULExport bool ulBitmapIsEmpty(ULBitmap bitmap); - -/// -/// Reset bitmap pixels to 0. -/// -ULExport void ulBitmapErase(ULBitmap bitmap); - -/// -/// Write bitmap to a PNG on disk. -/// -ULExport bool ulBitmapWritePNG(ULBitmap bitmap, const char* path); - -/// -/// This converts a BGRA bitmap to RGBA bitmap and vice-versa by swapping -/// the red and blue channels. -/// -ULExport void ulBitmapSwapRedBlueChannels(ULBitmap bitmap); - -/****************************************************************************** -* Key Event -******************************************************************************/ - -/// -/// Create a key event, @see KeyEvent for help with the following parameters. -/// -ULExport ULKeyEvent ulCreateKeyEvent(ULKeyEventType type, - unsigned int modifiers, - int virtual_key_code, int native_key_code, - ULString text, ULString unmodified_text, - bool is_keypad, bool is_auto_repeat, - bool is_system_key); - -#ifdef _WIN32 -/// -/// Create a key event from native Windows event. -/// -ULExport ULKeyEvent ulCreateKeyEventWindows(ULKeyEventType type, - uintptr_t wparam, intptr_t lparam, - bool is_system_key); -#endif - -#ifdef __OBJC__ -/// -/// Create a key event from native macOS event. -/// -ULExport ULKeyEvent ulCreateKeyEventMacOS(NSEvent* evt); -#endif - -/// -/// Destroy a key event. -/// -ULExport void ulDestroyKeyEvent(ULKeyEvent evt); - -/****************************************************************************** - * Mouse Event - *****************************************************************************/ - -/// -/// Create a mouse event, @see MouseEvent for help using this function. -/// -ULExport ULMouseEvent ulCreateMouseEvent(ULMouseEventType type, int x, int y, - ULMouseButton button); - -/// -/// Destroy a mouse event. -/// -ULExport void ulDestroyMouseEvent(ULMouseEvent evt); - -/****************************************************************************** - * Scroll Event - *****************************************************************************/ - -/// -/// Create a scroll event, @see ScrollEvent for help using this function. -/// -ULExport ULScrollEvent ulCreateScrollEvent(ULScrollEventType type, int delta_x, - int delta_y); - -/// -/// Destroy a scroll event. -/// -ULExport void ulDestroyScrollEvent(ULScrollEvent evt); - -/****************************************************************************** - * Rect - *****************************************************************************/ - -/// -/// Whether or not a ULRect is empty (all members equal to 0) -/// -ULExport bool ulRectIsEmpty(ULRect rect); - -/// -/// Create an empty ULRect (all members equal to 0) -/// -ULExport ULRect ulRectMakeEmpty(); - -/****************************************************************************** - * IntRect - *****************************************************************************/ - - /// - /// Whether or not a ULIntRect is empty (all members equal to 0) - /// -ULExport bool ulIntRectIsEmpty(ULIntRect rect); - -/// -/// Create an empty ULIntRect (all members equal to 0) -/// -ULExport ULIntRect ulIntRectMakeEmpty(); - -/****************************************************************************** - * Surface - *****************************************************************************/ - -/// -/// Width (in pixels). -/// -ULExport unsigned int ulSurfaceGetWidth(ULSurface surface); - -/// -/// Height (in pixels). -/// -ULExport unsigned int ulSurfaceGetHeight(ULSurface surface); - -/// -/// Number of bytes between rows (usually width * 4) -/// -ULExport unsigned int ulSurfaceGetRowBytes(ULSurface surface); - -/// -/// Size in bytes. -/// -ULExport size_t ulSurfaceGetSize(ULSurface surface); - -/// -/// Lock the pixel buffer and get a pointer to the beginning of the data -/// for reading/writing. -/// -/// Native pixel format is premultiplied BGRA 32-bit (8 bits per channel). -/// -ULExport void* ulSurfaceLockPixels(ULSurface surface); - -/// -/// Unlock the pixel buffer. -/// -ULExport void ulSurfaceUnlockPixels(ULSurface surface); - -/// -/// Resize the pixel buffer to a certain width and height (both in pixels). -/// -/// This should never be called while pixels are locked. -/// -ULExport void ulSurfaceResize(ULSurface surface, unsigned int width, unsigned int height); - -/// -/// Set the dirty bounds to a certain value. -/// -/// This is called after the Renderer paints to an area of the pixel buffer. -/// (The new value will be joined with the existing dirty_bounds()) -/// -ULExport void ulSurfaceSetDirtyBounds(ULSurface surface, ULIntRect bounds); - -/// -/// Get the dirty bounds. -/// -/// This value can be used to determine which portion of the pixel buffer has -/// been updated since the last call to ulSurfaceClearDirtyBounds(). -/// -/// The general algorithm to determine if a Surface needs display is: -///
-///   if (!ulIntRectIsEmpty(ulSurfaceGetDirtyBounds(surface))) {
-///       // Surface pixels are dirty and needs display.
-///       // Cast Surface to native Surface and use it here (pseudo code)
-///       DisplaySurface(surface);
-///
-///       // Once you're done, clear the dirty bounds:
-///       ulSurfaceClearDirtyBounds(surface);
-///  }
-///  
-/// -ULExport ULIntRect ulSurfaceGetDirtyBounds(ULSurface surface); - -/// -/// Clear the dirty bounds. -/// -/// You should call this after you're done displaying the Surface. -/// -ULExport void ulSurfaceClearDirtyBounds(ULSurface surface); - -/// -/// Get the underlying user data pointer (this is only valid if you have -/// set a custom surface implementation via ulPlatformSetSurfaceDefinition). -/// -/// This will return nullptr if this surface is the default ULBitmapSurface. -/// -ULExport void* ulSurfaceGetUserData(ULSurface surface); - -/****************************************************************************** - * BitmapSurface - *****************************************************************************/ - -/// -/// Get the underlying Bitmap from the default Surface. -/// -/// @note Do not call ulDestroyBitmap() on the returned value, it is owned -/// by the surface. -/// -ULExport ULBitmap ulBitmapSurfaceGetBitmap(ULBitmapSurface surface); - -/****************************************************************************** - * Surface Definition - *****************************************************************************/ - -/// -/// The callback invoked when a Surface is created. -/// -/// @param width The width in pixels. -/// @param height The height in pixels. -/// -/// @return This callback should return a pointer to user-defined data for the -/// instance. This user data pointer will be passed to all other -/// callbacks when operating on the instance. -/// -typedef void* -(*ULSurfaceDefinitionCreateCallback) (unsigned int width, unsigned int height); - -/// -/// The callback invoked when a Surface is destroyed. -/// -/// @param user_data User data pointer uniquely identifying the surface. -/// -typedef void -(*ULSurfaceDefinitionDestroyCallback) (void* user_data); - -/// -/// The callback invoked when a Surface's width (in pixels) is requested. -/// -/// @param user_data User data pointer uniquely identifying the surface. -/// -typedef unsigned int -(*ULSurfaceDefinitionGetWidthCallback) (void* user_data); - -/// -/// The callback invoked when a Surface's height (in pixels) is requested. -/// -/// @param user_data User data pointer uniquely identifying the surface. -/// -typedef unsigned int -(*ULSurfaceDefinitionGetHeightCallback) (void* user_data); - -/// -/// The callback invoked when a Surface's row bytes is requested. -/// -/// @note This value is also known as "stride". Usually width * 4. -/// -/// @param user_data User data pointer uniquely identifying the surface. -/// -typedef unsigned int -(*ULSurfaceDefinitionGetRowBytesCallback) (void* user_data); - -/// -/// The callback invoked when a Surface's size (in bytes) is requested. -/// -/// @param user_data User data pointer uniquely identifying the surface. -/// -typedef size_t -(*ULSurfaceDefinitionGetSizeCallback) (void* user_data); - -/// -/// The callback invoked when a Surface's pixel buffer is requested to be -/// locked for reading/writing (should return a pointer to locked bytes). -/// -/// @param user_data User data pointer uniquely identifying the surface. -/// -typedef void* -(*ULSurfaceDefinitionLockPixelsCallback) (void* user_data); - -/// -/// The callback invoked when a Surface's pixel buffer is requested to be -/// unlocked after previously being locked. -/// -/// @param user_data User data pointer uniquely identifying the surface. -/// -typedef void -(*ULSurfaceDefinitionUnlockPixelsCallback) (void* user_data); - -/// -/// The callback invoked when a Surface is requested to be resized to a -/// certain width/height. -/// -/// @param user_data User data pointer uniquely identifying the surface. -/// @param width Width in pixels. -/// @param height Height in pixels. -/// -typedef void -(*ULSurfaceDefinitionResizeCallback) (void* user_data, unsigned int width, unsigned int height); - -typedef struct { - ULSurfaceDefinitionCreateCallback create; - ULSurfaceDefinitionDestroyCallback destroy; - ULSurfaceDefinitionGetWidthCallback get_width; - ULSurfaceDefinitionGetHeightCallback get_height; - ULSurfaceDefinitionGetRowBytesCallback get_row_bytes; - ULSurfaceDefinitionGetSizeCallback get_size; - ULSurfaceDefinitionLockPixelsCallback lock_pixels; - ULSurfaceDefinitionUnlockPixelsCallback unlock_pixels; - ULSurfaceDefinitionResizeCallback resize; -} ULSurfaceDefinition; - -/****************************************************************************** - * File System - *****************************************************************************/ - -/// -/// File Handle type used as unique ID for opened files. -/// -#if defined(__WIN32__) || defined(_WIN32) -typedef size_t ULFileHandle; -#else -typedef int ULFileHandle; -#endif - -/// -/// Handle used to denote an invalid file. -/// -const ULFileHandle ULInvalidFileHandle = (ULFileHandle)-1; - -/// -/// The callback invoked when the FileSystem wants to check if a file path -/// exists, return true if it exists. -/// -typedef bool -(*ULFileSystemFileExistsCallback) (ULString path); - -/// -/// The callback invoked when the FileSystem wants to get the file size of a -/// previously opened file, store result in 'result'. Return true on success. -/// -typedef bool -(*ULFileSystemGetFileSizeCallback) (ULFileHandle handle, long long* result); - -/// -/// The callback invoked when the FileSystem wants to get the mime type of a -/// file (eg "text/html"), store result in 'result'. Return true on success. -/// -typedef bool -(*ULFileSystemGetFileMimeTypeCallback) (ULString path, ULString result); - -/// -/// The callback invoked when the FileSystem wants to open a file path for -/// reading or writing. Return file handle on success, or ULInvalidFileHandle -/// on failure. -/// -/// @NOTE: As of this writing (v1.2), this function is only used for reading. -/// -typedef ULFileHandle -(*ULFileSystemOpenFileCallback) (ULString path, bool open_for_writing); - -/// -/// The callback invoked when the FileSystem wants to close a previously-opened -/// file. -/// -typedef void -(*ULFileSystemCloseFileCallback) (ULFileHandle handle); - -/// -/// The callback invoked when the FileSystem wants to read from a -/// currently-opened file, return number of bytes read or -1 on failure. -/// -typedef long long -(*ULFileSystemReadFromFileCallback) (ULFileHandle handle, char* data, long long length); - -typedef struct { - ULFileSystemFileExistsCallback file_exists; - ULFileSystemGetFileSizeCallback get_file_size; - ULFileSystemGetFileMimeTypeCallback get_file_mime_type; - ULFileSystemOpenFileCallback open_file; - ULFileSystemCloseFileCallback close_file; - ULFileSystemReadFromFileCallback read_from_file; -} ULFileSystem; - -/****************************************************************************** - * Logger - *****************************************************************************/ - -typedef enum { - kLogLevel_Error = 0, - kLogLevel_Warning, - kLogLevel_Info -} ULLogLevel; - -/// -/// The callback invoked when the library wants to print a message to the log. -/// -typedef void -(*ULLoggerLogMessageCallback) (ULLogLevel log_level, ULString message); - -typedef struct { - ULLoggerLogMessageCallback log_message; -} ULLogger; - - -/****************************************************************************** - * GPUDriver - *****************************************************************************/ - -/// -/// Render buffer description. -/// -typedef struct { - unsigned int texture_id; // The backing texture for this RenderBuffer - unsigned int width; // The width of the RenderBuffer texture - unsigned int height; // The height of the RenderBuffer texture - bool has_stencil_buffer; // Currently unused, always false. - bool has_depth_buffer; // Currently unsued, always false. -} ULRenderBuffer; - -/// -/// @note This pragma pack(push, 1) command is important! Vertex layouts -/// should not be padded with any bytes. -/// -#pragma pack(push, 1) - -/// -/// Vertex layout for path vertices. -/// -/// (this struct's members aligned on single-byte boundaries) -/// -typedef struct { - float pos[2]; - unsigned char color[4]; - float obj[2]; -} ULVertex_2f_4ub_2f; - -/// -/// Vertex layout for quad vertices. -/// -/// (this struct's members aligned on single-byte boundaries) -/// -typedef struct { - float pos[2]; - unsigned char color[4]; - float tex[2]; - float obj[2]; - float data0[4]; - float data1[4]; - float data2[4]; - float data3[4]; - float data4[4]; - float data5[4]; - float data6[4]; -} ULVertex_2f_4ub_2f_2f_28f; - -/// -/// End single-byte alignment. -/// -#pragma pack(pop) - -/// -/// Vertex formats. -/// -typedef enum { - kVertexBufferFormat_2f_4ub_2f, - kVertexBufferFormat_2f_4ub_2f_2f_28f, -} ULVertexBufferFormat; - -/// -/// Vertex buffer data. -/// -typedef struct { - ULVertexBufferFormat format; - unsigned int size; - unsigned char* data; -} ULVertexBuffer; - -/// -/// Vertex index type. -/// -typedef unsigned int ULIndexType; - -/// -/// Vertex index buffer data. -/// -typedef struct { - unsigned int size; - unsigned char* data; -} ULIndexBuffer; - -/// -/// Shader types, used with ULGPUState::shader_type -/// -/// Each of these correspond to a vertex/pixel shader pair. You can find -/// stock shader code for these in the `shaders` folder of the AppCore repo. -/// -typedef enum { - kShaderType_Fill, // Shader program for quad geometry - kShaderType_FillPath, // Shader program for path geometry -} ULShaderType; - -/// -/// Raw 4x4 matrix as an array of floats -/// -typedef struct { - float data[16]; -} ULMatrix4x4; - -/// -/// 4-component float vector -/// -typedef struct { - float value[4]; -} ULvec4; - -/// -/// GPU State description. -/// -typedef struct { - /// Viewport width in pixels - unsigned int viewport_width; - - /// Viewport height in pixels - unsigned int viewport_height; - - /// Transform matrix-- you should multiply this with the screen-space - /// orthographic projection matrix then pass to the vertex shader. - ULMatrix4x4 transform; - - /// Whether or not we should enable texturing for the current draw command. - bool enable_texturing; - - /// Whether or not we should enable blending for the current draw command. - /// If blending is disabled, any drawn pixels should overwrite existing. - /// Mainly used so we can modify alpha values of the RenderBuffer during - /// scissored clears. - bool enable_blend; - - /// The vertex/pixel shader program pair to use for the current draw command. - /// You should cast this to ShaderType to get the corresponding enum. - unsigned char shader_type; - - /// The render buffer to use for the current draw command. - unsigned int render_buffer_id; - - /// The texture id to bind to slot #1. (Will be 0 if none) - unsigned int texture_1_id; - - /// The texture id to bind to slot #2. (Will be 0 if none) - unsigned int texture_2_id; - - /// The texture id to bind to slot #3. (Will be 0 if none) - unsigned int texture_3_id; - - /// The following four members are passed to the pixel shader via uniforms. - float uniform_scalar[8]; - ULvec4 uniform_vector[8]; - unsigned char clip_size; - ULMatrix4x4 clip[8]; - - /// Whether or not scissor testing should be used for the current draw - /// command. - bool enable_scissor; - - /// The scissor rect to use for scissor testing (units in pixels) - ULIntRect scissor_rect; -} ULGPUState; - -/// -/// Command types, used with ULCommand::command_type -/// -typedef enum { - kCommandType_ClearRenderBuffer, - kCommandType_DrawGeometry, -} ULCommandType; - -/// -/// Command description. -/// -typedef struct { - unsigned char command_type; // The type of command to dispatch. - ULGPUState gpu_state; // GPU state parameters for current command. - - /// The following members are only used with kCommandType_DrawGeometry - unsigned int geometry_id; // The geometry ID to bind - unsigned int indices_count; // The number of indices - unsigned int indices_offset; // The index to start from -} ULCommand; - -/// -/// Command list, @see ULGPUDriverUpdateCommandList -typedef struct { - unsigned int size; - ULCommand* commands; -} ULCommandList; - -/// -/// The callback invoked when the GPUDriver will begin dispatching commands -/// (such as CreateTexture and UpdateCommandList) during the current call to -/// ulRender(). -/// -typedef void -(*ULGPUDriverBeginSynchronizeCallback) (); - -/// -/// The callback invoked when the GPUDriver has finished dispatching commands. -/// during the current call to ulRender(). -/// -typedef void -(*ULGPUDriverEndSynchronizeCallback) (); - -/// -/// The callback invoked when the GPUDriver wants to get the next available -/// texture ID. -/// -typedef unsigned int -(*ULGPUDriverNextTextureIdCallback) (); - -/// -/// The callback invoked when the GPUDriver wants to create a texture with a -/// certain ID and optional bitmap. -/// -/// **NOTE**: If the Bitmap is empty (ulBitmapIsEmpty), then a RTT Texture -/// should be created instead. This will be used as a backing -/// texture for a new RenderBuffer. -/// -typedef void -(*ULGPUDriverCreateTextureCallback) (unsigned int texture_id, - ULBitmap bitmap); - -/// -/// The callback invoked when the GPUDriver wants to update an existing non-RTT -/// texture with new bitmap data. -/// -typedef void -(*ULGPUDriverUpdateTextureCallback) (unsigned int texture_id, - ULBitmap bitmap); - -/// -/// The callback invoked when the GPUDriver wants to destroy a texture. -/// -typedef void -(*ULGPUDriverDestroyTextureCallback) (unsigned int texture_id); - -/// -/// The callback invoked when the GPUDriver wants to generate the next -/// available render buffer ID. -/// -typedef unsigned int -(*ULGPUDriverNextRenderBufferIdCallback) (); - -/// -/// The callback invoked when the GPUDriver wants to create a render buffer -/// with certain ID and buffer description. -/// -typedef void -(*ULGPUDriverCreateRenderBufferCallback) (unsigned int render_buffer_id, - ULRenderBuffer buffer); - -/// -/// The callback invoked when the GPUDriver wants to destroy a render buffer -/// -typedef void -(*ULGPUDriverDestroyRenderBufferCallback) (unsigned int render_buffer_id); - -/// -/// The callback invoked when the GPUDriver wants to generate the next -/// available geometry ID. -/// -typedef unsigned int -(*ULGPUDriverNextGeometryIdCallback) (); - -/// -/// The callback invoked when the GPUDriver wants to create geometry with -/// certain ID and vertex/index data. -/// -typedef void -(*ULGPUDriverCreateGeometryCallback) (unsigned int geometry_id, - ULVertexBuffer vertices, - ULIndexBuffer indices); - -/// -/// The callback invoked when the GPUDriver wants to update existing geometry -/// with new vertex/index data. -/// -typedef void -(*ULGPUDriverUpdateGeometryCallback) (unsigned int geometry_id, - ULVertexBuffer vertices, - ULIndexBuffer indices); - -/// -/// The callback invoked when the GPUDriver wants to destroy geometry. -/// -typedef void -(*ULGPUDriverDestroyGeometryCallback) (unsigned int geometry_id); - -/// -/// The callback invoked when the GPUDriver wants to update the command list -/// (you should copy the commands to your own structure). -/// -typedef void -(*ULGPUDriverUpdateCommandListCallback) (ULCommandList list); - -typedef struct { - ULGPUDriverBeginSynchronizeCallback begin_synchronize; - ULGPUDriverEndSynchronizeCallback end_synchronize; - ULGPUDriverNextTextureIdCallback next_texture_id; - ULGPUDriverCreateTextureCallback create_texture; - ULGPUDriverUpdateTextureCallback update_texture; - ULGPUDriverDestroyTextureCallback destroy_texture; - ULGPUDriverNextRenderBufferIdCallback next_render_buffer_id; - ULGPUDriverCreateRenderBufferCallback create_render_buffer; - ULGPUDriverDestroyRenderBufferCallback destroy_render_buffer; - ULGPUDriverNextGeometryIdCallback next_geometry_id; - ULGPUDriverCreateGeometryCallback create_geometry; - ULGPUDriverUpdateGeometryCallback update_geometry; - ULGPUDriverDestroyGeometryCallback destroy_geometry; - ULGPUDriverUpdateCommandListCallback update_command_list; -} ULGPUDriver; - -/// -/// Sets up an orthographic projection matrix with a certain viewport width -/// and height, multiplies it by 'transform', and returns the result. -/// -/// This should be used to calculate the model-view projection matrix for the -/// vertex shaders using the current ULGPUState. -/// -/// The 'flip_y' can be optionally used to flip the Y coordinate-space. -/// (Usually flip_y == true for OpenGL) -/// -ULExport ULMatrix4x4 ulApplyProjection(ULMatrix4x4 transform, - float viewport_width, - float viewport_height, - bool flip_y); - -/****************************************************************************** - * Clipboard - *****************************************************************************/ - -/// -/// The callback invoked when the library wants to clear the system's -/// clipboard. -/// -typedef void -(*ULClipboardClearCallback) (); - -/// -/// The callback invoked when the library wants to read from the system's -/// clipboard. -/// -/// You should store the result (if any) in 'result'. -/// -typedef void -(*ULClipboardReadPlainTextCallback) (ULString result); - -/// -/// The callback invoked when the library wants to write to the system's -/// clipboard. -/// -typedef void -(*ULClipboardWritePlainTextCallback) (ULString text); - -typedef struct { - ULClipboardClearCallback clear; - ULClipboardReadPlainTextCallback read_plain_text; - ULClipboardWritePlainTextCallback write_plain_text; -} ULClipboard; - -/****************************************************************************** - * Platform - *****************************************************************************/ - -/// -/// Set a custom Logger implementation. -/// -/// This is used to log debug messages to the console or to a log file. -/// -/// You should call this before ulCreateRenderer() or ulCreateApp(). -/// -/// @note ulCreateApp() will use the default logger if you never call this. -/// -/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) -/// you can still use the default logger by calling -/// ulEnableDefaultLogger() (@see ) -/// -ULExport void ulPlatformSetLogger(ULLogger logger); - -/// -/// Set a custom FileSystem implementation. -/// -/// This is used for loading File URLs (eg, ). If you don't -/// call this, and are not using ulCreateApp() or ulEnablePlatformFileSystem(), -/// you will not be able to load any File URLs. -/// -/// You should call this before ulCreateRenderer() or ulCreateApp(). -/// -/// @note ulCreateApp() will use the default platform file system if you never -/// call this. -/// -/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) -/// you can still use the default platform file system by calling -/// ulEnablePlatformFileSystem() (@see ) -/// -ULExport void ulPlatformSetFileSystem(ULFileSystem file_system); - -/// -/// Set a custom Surface implementation. -/// -/// This can be used to wrap a platform-specific GPU texture, Windows DIB, -/// macOS CGImage, or any other pixel buffer target for display on screen. -/// -/// By default, the library uses a bitmap surface for all surfaces but you can -/// override this by providing your own surface definition here. -/// -/// You should call this before ulCreateRenderer() or ulCreateApp(). -/// -ULExport void ulPlatformSetSurfaceDefinition(ULSurfaceDefinition surface_definition); - -/// -/// Set a custom GPUDriver implementation. -/// -/// This should be used if you have enabled the GPU renderer in the Config and -/// are using ulCreateRenderer() (which does not provide its own GPUDriver -/// implementation). -/// -/// The GPUDriver interface is used by the library to dispatch GPU calls to -/// your native GPU context (eg, D3D11, Metal, OpenGL, Vulkan, etc.) There -/// are reference implementations for this interface in the AppCore repo. -/// -/// You should call this before ulCreateRenderer(). -/// -ULExport void ulPlatformSetGPUDriver(ULGPUDriver gpu_driver); - -/// -/// Set a custom Clipboard implementation. -/// -/// This should be used if you are using ulCreateRenderer() (which does not -/// provide its own clipboard implementation). -/// -/// The Clipboard interface is used by the library to make calls to the -/// system's native clipboard (eg, cut, copy, paste). -/// -/// You should call this before ulCreateRenderer(). -/// -ULExport void ulPlatformSetClipboard(ULClipboard clipboard); - -#ifdef __cplusplus -} -#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif // ULTRALIGHT_CAPI_H diff --git a/Ultralight/CAPI/CAPI_Bitmap.h b/Ultralight/CAPI/CAPI_Bitmap.h new file mode 100644 index 0000000..a49267b --- /dev/null +++ b/Ultralight/CAPI/CAPI_Bitmap.h @@ -0,0 +1,116 @@ +#ifndef ULTRALIGHT_CAPI_BITMAP_H +#define ULTRALIGHT_CAPI_BITMAP_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Bitmap + *****************************************************************************/ + +/// +/// Create empty bitmap. +/// +ULExport ULBitmap ulCreateEmptyBitmap(); + +/// +/// Create bitmap with certain dimensions and pixel format. +/// +ULExport ULBitmap ulCreateBitmap(unsigned int width, unsigned int height, ULBitmapFormat format); + +/// +/// Create bitmap from existing pixel buffer. @see Bitmap for help using this function. +/// +ULExport ULBitmap ulCreateBitmapFromPixels(unsigned int width, unsigned int height, + ULBitmapFormat format, unsigned int row_bytes, + const void* pixels, size_t size, bool should_copy); + +/// +/// Create bitmap from copy. +/// +ULExport ULBitmap ulCreateBitmapFromCopy(ULBitmap existing_bitmap); + +/// +/// Destroy a bitmap (you should only destroy Bitmaps you have explicitly created via one of the +/// creation functions above. +/// +ULExport void ulDestroyBitmap(ULBitmap bitmap); + +/// +/// Get the width in pixels. +/// +ULExport unsigned int ulBitmapGetWidth(ULBitmap bitmap); + +/// +/// Get the height in pixels. +/// +ULExport unsigned int ulBitmapGetHeight(ULBitmap bitmap); + +/// +/// Get the pixel format. +/// +ULExport ULBitmapFormat ulBitmapGetFormat(ULBitmap bitmap); + +/// +/// Get the bytes per pixel. +/// +ULExport unsigned int ulBitmapGetBpp(ULBitmap bitmap); + +/// +/// Get the number of bytes per row. +/// +ULExport unsigned int ulBitmapGetRowBytes(ULBitmap bitmap); + +/// +/// Get the size in bytes of the underlying pixel buffer. +/// +ULExport size_t ulBitmapGetSize(ULBitmap bitmap); + +/// +/// Whether or not this bitmap owns its own pixel buffer. +/// +ULExport bool ulBitmapOwnsPixels(ULBitmap bitmap); + +/// +/// Lock pixels for reading/writing, returns pointer to pixel buffer. +/// +ULExport void* ulBitmapLockPixels(ULBitmap bitmap); + +/// +/// Unlock pixels after locking. +/// +ULExport void ulBitmapUnlockPixels(ULBitmap bitmap); + +/// +/// Get raw pixel buffer-- you should only call this if Bitmap is already locked. +/// +ULExport void* ulBitmapRawPixels(ULBitmap bitmap); + +/// +/// Whether or not this bitmap is empty. +/// +ULExport bool ulBitmapIsEmpty(ULBitmap bitmap); + +/// +/// Reset bitmap pixels to 0. +/// +ULExport void ulBitmapErase(ULBitmap bitmap); + +/// +/// Write bitmap to a PNG on disk. +/// +ULExport bool ulBitmapWritePNG(ULBitmap bitmap, const char* path); + +/// +/// This converts a BGRA bitmap to RGBA bitmap and vice-versa by swapping the red and blue channels. +/// +ULExport void ulBitmapSwapRedBlueChannels(ULBitmap bitmap); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_BITMAP_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Buffer.h b/Ultralight/CAPI/CAPI_Buffer.h new file mode 100644 index 0000000..09a1e8b --- /dev/null +++ b/Ultralight/CAPI/CAPI_Buffer.h @@ -0,0 +1,65 @@ +#ifndef ULTRALIGHT_CAPI_BUFFER_H +#define ULTRALIGHT_CAPI_BUFFER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*ulDestroyBufferCallback)(void* user_data, void* data); + +/// +/// Create a Buffer from existing, user-owned data without any copies. An optional, user-supplied +/// callback will be called to deallocate data upon destruction. +/// +/// @param data A pointer to the data. +/// +/// @param size Size of the data in bytes. +/// +/// @param user_data Optional user data that will be passed to destruction_callback +/// when the returned Buffer is destroyed. +/// +/// @param destruction_callback Optional callback that will be called upon destruction. Pass a +/// null pointer if you don't want to be informed of destruction. +/// +ULExport ULBuffer ulCreateBuffer(void* data, size_t size, void* user_data, + ulDestroyBufferCallback destruction_callback); + +/// +/// Create a Buffer from existing data, a deep copy of data will be made. +/// +ULExport ULBuffer ulCreateBufferFromCopy(const void* data, size_t size); + +/// +/// Destroy buffer (you should destroy any buffers you explicitly Create). +/// +ULExport void ulDestroyBuffer(ULBuffer buffer); + +/// +/// Get a pointer to the raw byte data. +/// +ULExport void* ulBufferGetData(ULBuffer buffer); + +/// +/// Get the size in bytes. +/// +ULExport size_t ulBufferGetSize(ULBuffer buffer); + +/// +/// Get the user data associated with this Buffer, if any. +/// +ULExport void* ulBufferGetUserData(ULBuffer buffer); + +/// +/// Check whether this Buffer owns its own data (Buffer was created via ulCreateBufferFromCopy). +/// If this is false, Buffer will call the user-supplied destruction callback to deallocate data +/// when this Buffer instance is destroyed. +/// +ULExport bool ulBufferOwnsData(ULBuffer buffer); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_BUFFER_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Clipboard.h b/Ultralight/CAPI/CAPI_Clipboard.h new file mode 100644 index 0000000..792bac2 --- /dev/null +++ b/Ultralight/CAPI/CAPI_Clipboard.h @@ -0,0 +1,41 @@ +#ifndef ULTRALIGHT_CAPI_CLIPBOARD_H +#define ULTRALIGHT_CAPI_CLIPBOARD_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Clipboard + *****************************************************************************/ + +/// +/// The callback invoked when the library wants to clear the system's clipboard. +/// +typedef void (*ULClipboardClearCallback)(); + +/// +/// The callback invoked when the library wants to read from the system's clipboard. +/// +/// You should store the result (if any) in 'result'. +/// +typedef void (*ULClipboardReadPlainTextCallback)(ULString result); + +/// +/// The callback invoked when the library wants to write to the system's clipboard. +/// +typedef void (*ULClipboardWritePlainTextCallback)(ULString text); + +typedef struct { + ULClipboardClearCallback clear; + ULClipboardReadPlainTextCallback read_plain_text; + ULClipboardWritePlainTextCallback write_plain_text; +} ULClipboard; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_CLIPBOARD_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Config.h b/Ultralight/CAPI/CAPI_Config.h new file mode 100644 index 0000000..033e2a6 --- /dev/null +++ b/Ultralight/CAPI/CAPI_Config.h @@ -0,0 +1,160 @@ +#ifndef ULTRALIGHT_CAPI_CONFIG_H +#define ULTRALIGHT_CAPI_CONFIG_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Config + *****************************************************************************/ + +/// +/// Create config with default values (see ). +/// +ULExport ULConfig ulCreateConfig(); + +/// +/// Destroy config. +/// +ULExport void ulDestroyConfig(ULConfig config); + +/// +/// Set the file path to a writable directory that will be used to store cookies, cached resources, and other persistent data. +/// +/// Files are only written to disk when using a persistent Session. +/// +ULExport void ulConfigSetCachePath(ULConfig config, ULString cache_path); + +/// +/// The library loads bundled resources (eg, cacert.pem and other localized resources) from the +/// FileSystem API (eg, `file:///resources/cacert.pem`). You can customize the prefix to use when +/// loading resource URLs by modifying this setting. (Default = "resources/") +/// +ULExport void ulConfigSetResourcePathPrefix(ULConfig config, ULString resource_path_prefix); + +/// +/// The winding order for front-facing triangles. (Default = kFaceWinding_CounterClockwise) +/// +/// Note: This is only used with custom GPUDrivers +/// +ULExport void ulConfigSetFaceWinding(ULConfig config, ULFaceWinding winding); + +/// +/// The hinting algorithm to use when rendering fonts. (Default = kFontHinting_Normal) +/// @see ULFontHinting +/// +ULExport void ulConfigSetFontHinting(ULConfig config, ULFontHinting font_hinting); + +/// +/// The gamma to use when compositing font glyphs, change this value to adjust contrast (Adobe and +/// Apple prefer 1.8, others may prefer 2.2). (Default = 1.8) +/// +ULExport void ulConfigSetFontGamma(ULConfig config, double font_gamma); + +/// +/// Set user stylesheet (CSS) (Default = Empty). +/// +ULExport void ulConfigSetUserStylesheet(ULConfig config, ULString css_string); + +/// +/// Set whether or not we should continuously repaint any Views or compositor layers, regardless if +/// they are dirty or not. This is mainly used to diagnose painting/shader issues. (Default = False) +/// +ULExport void ulConfigSetForceRepaint(ULConfig config, bool enabled); + +/// +/// Set the amount of time to wait before triggering another repaint when a CSS animation is active. +/// (Default = 1.0 / 60.0) +/// +ULExport void ulConfigSetAnimationTimerDelay(ULConfig config, double delay); + +/// +/// When a smooth scroll animation is active, the amount of time (in seconds) to wait before +/// triggering another repaint. Default is 60 Hz. +/// +ULExport void ulConfigSetScrollTimerDelay(ULConfig config, double delay); + +/// +/// The amount of time (in seconds) to wait before running the recycler (will attempt to return +/// excess memory back to the system). (Default = 4.0) +/// +ULExport void ulConfigSetRecycleDelay(ULConfig config, double delay); + +/// +/// Set the size of WebCore's memory cache for decoded images, scripts, and other assets in bytes. +/// (Default = 64 * 1024 * 1024) +/// +ULExport void ulConfigSetMemoryCacheSize(ULConfig config, unsigned int size); + +/// +/// Set the number of pages to keep in the cache. (Default = 0) +/// +ULExport void ulConfigSetPageCacheSize(ULConfig config, unsigned int size); + +/// +/// JavaScriptCore tries to detect the system's physical RAM size to set reasonable allocation +/// limits. Set this to anything other than 0 to override the detected value. Size is in bytes. +/// +/// This can be used to force JavaScriptCore to be more conservative with its allocation strategy +/// (at the cost of some performance). +/// +ULExport void ulConfigSetOverrideRAMSize(ULConfig config, unsigned int size); + +/// +/// The minimum size of large VM heaps in JavaScriptCore. Set this to a lower value to make these +/// heaps start with a smaller initial value. +/// +ULExport void ulConfigSetMinLargeHeapSize(ULConfig config, unsigned int size); + +/// +/// The minimum size of small VM heaps in JavaScriptCore. Set this to a lower value to make these +/// heaps start with a smaller initial value. +/// +ULExport void ulConfigSetMinSmallHeapSize(ULConfig config, unsigned int size); + +/// +/// The number of threads to use in the Renderer (for parallel painting on the CPU, etc.). +/// +/// You can set this to a certain number to limit the number of threads to spawn. +/// +/// @note If this value is 0 (the default), the number of threads will be determined at runtime +/// using the following formula: +/// +/// max(PhysicalProcessorCount() - 1, 1) +/// +ULExport void ulConfigSetNumRendererThreads(ULConfig config, unsigned int num_renderer_threads); + +/// +/// The max amount of time (in seconds) to allow Renderer::Update to run per call. The library will +/// attempt to throttle timers and/or reschedule work if this time budget is exceeded. (Default = +/// 0.01) +/// +ULExport void ulConfigSetMaxUpdateTime(ULConfig config, double max_update_time); + +/// +/// The alignment (in bytes) of the BitmapSurface when using the CPU renderer. +/// +/// The underlying bitmap associated with each BitmapSurface will have row_bytes padded to reach +/// this alignment. +/// +/// Aligning the bitmap helps improve performance when using the CPU renderer. Determining the +/// proper value to use depends on the CPU architecture and max SIMD instruction set used. +/// +/// We generally target the 128-bit SSE2 instruction set across most PC platforms so '16' is a safe +/// value to use. +/// +/// You can set this to '0' to perform no padding (row_bytes will always be width * 4) at a slight +/// cost to performance. +/// +/// (Default = 16) +/// +ULExport void ulConfigSetBitmapAlignment(ULConfig config, double bitmap_alignment); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_CONFIG_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Defines.h b/Ultralight/CAPI/CAPI_Defines.h new file mode 100644 index 0000000..4da1667 --- /dev/null +++ b/Ultralight/CAPI/CAPI_Defines.h @@ -0,0 +1,274 @@ +#ifndef ULTRALIGHT_CAPI_DEFINES_H +#define ULTRALIGHT_CAPI_DEFINES_H + +#include +#include +#ifdef __OBJC__ +#import +#endif + +#if defined(ULTRALIGHT_STATIC_BUILD) +#define ULExport +#else +#if defined(__WIN32__) || defined(_WIN32) +#if defined(ULTRALIGHT_IMPLEMENTATION) +#define ULExport __declspec(dllexport) +#else +#define ULExport __declspec(dllimport) +#endif +#else +#define ULExport __attribute__((visibility("default"))) +#endif +#endif + +#if defined(__WIN32__) || defined(_WIN32) +#define _thread_local __declspec(thread) +#ifndef _NATIVE_WCHAR_T_DEFINED +#define DISABLE_NATIVE_WCHAR_T +typedef unsigned short ULChar16; +#else +typedef wchar_t ULChar16; +#endif +#else +#define _thread_local __thread +typedef unsigned short ULChar16; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct C_Config* ULConfig; +typedef struct C_Renderer* ULRenderer; +typedef struct C_Session* ULSession; +typedef struct C_ViewConfig* ULViewConfig; +typedef struct C_View* ULView; +typedef struct C_Bitmap* ULBitmap; +typedef struct C_String* ULString; +typedef struct C_Buffer* ULBuffer; +typedef struct C_KeyEvent* ULKeyEvent; +typedef struct C_MouseEvent* ULMouseEvent; +typedef struct C_ScrollEvent* ULScrollEvent; +typedef struct C_Surface* ULSurface; +typedef struct C_Surface* ULBitmapSurface; +typedef struct C_FontFile* ULFontFile; + +typedef enum { + kMessageSource_XML = 0, + kMessageSource_JS, + kMessageSource_Network, + kMessageSource_ConsoleAPI, + kMessageSource_Storage, + kMessageSource_AppCache, + kMessageSource_Rendering, + kMessageSource_CSS, + kMessageSource_Security, + kMessageSource_ContentBlocker, + kMessageSource_Other, +} ULMessageSource; + +typedef enum { + kMessageLevel_Log = 1, + kMessageLevel_Warning = 2, + kMessageLevel_Error = 3, + kMessageLevel_Debug = 4, + kMessageLevel_Info = 5, +} ULMessageLevel; + +typedef enum { + kCursor_Pointer = 0, + kCursor_Cross, + kCursor_Hand, + kCursor_IBeam, + kCursor_Wait, + kCursor_Help, + kCursor_EastResize, + kCursor_NorthResize, + kCursor_NorthEastResize, + kCursor_NorthWestResize, + kCursor_SouthResize, + kCursor_SouthEastResize, + kCursor_SouthWestResize, + kCursor_WestResize, + kCursor_NorthSouthResize, + kCursor_EastWestResize, + kCursor_NorthEastSouthWestResize, + kCursor_NorthWestSouthEastResize, + kCursor_ColumnResize, + kCursor_RowResize, + kCursor_MiddlePanning, + kCursor_EastPanning, + kCursor_NorthPanning, + kCursor_NorthEastPanning, + kCursor_NorthWestPanning, + kCursor_SouthPanning, + kCursor_SouthEastPanning, + kCursor_SouthWestPanning, + kCursor_WestPanning, + kCursor_Move, + kCursor_VerticalText, + kCursor_Cell, + kCursor_ContextMenu, + kCursor_Alias, + kCursor_Progress, + kCursor_NoDrop, + kCursor_Copy, + kCursor_None, + kCursor_NotAllowed, + kCursor_ZoomIn, + kCursor_ZoomOut, + kCursor_Grab, + kCursor_Grabbing, + kCursor_Custom +} ULCursor; + +typedef enum { + /// + /// Alpha channel only, 8-bits per pixel. + /// + /// Encoding: 8-bits per channel, unsigned normalized. + /// + /// Color-space: Linear (no gamma), alpha-coverage only. + /// + kBitmapFormat_A8_UNORM, + + /// + /// Blue Green Red Alpha channels, 32-bits per pixel. + /// + /// Encoding: 8-bits per channel, unsigned normalized. + /// + /// Color-space: sRGB gamma with premultiplied linear alpha channel. + /// + kBitmapFormat_BGRA8_UNORM_SRGB +} ULBitmapFormat; + +typedef enum { + /// + /// Key-Down event type. (Does not trigger accelerator commands in WebCore) + /// + /// @NOTE: You should probably use RawKeyDown instead when a physical key + /// is pressed. This member is only here for historic compatibility + /// with WebCore's key event types. + /// + kKeyEventType_KeyDown, + + /// + /// Key-Up event type. Use this when a physical key is released. + /// + kKeyEventType_KeyUp, + + /// + /// Raw Key-Down type. Use this when a physical key is pressed. + /// + /// @NOTE: You should use RawKeyDown for physical key presses since it + /// allows WebCore to do additional command translation. + /// + kKeyEventType_RawKeyDown, + + /// + /// Character input event type. Use this when the OS generates text from + /// a physical key being pressed (eg, WM_CHAR on Windows). + /// + kKeyEventType_Char, +} ULKeyEventType; + +typedef enum { + kMouseEventType_MouseMoved, + kMouseEventType_MouseDown, + kMouseEventType_MouseUp, +} ULMouseEventType; + +typedef enum { + kMouseButton_None = 0, + kMouseButton_Left, + kMouseButton_Middle, + kMouseButton_Right, +} ULMouseButton; + +typedef enum { + kScrollEventType_ScrollByPixel, + kScrollEventType_ScrollByPage, +} ULScrollEventType; + +typedef enum { + kFaceWinding_Clockwise, + kFaceWinding_CounterClockwise, +} ULFaceWinding; + +typedef enum { + /// + /// Lighter hinting algorithm-- glyphs are slightly fuzzier but better + /// resemble their original shape. This is achieved by snapping glyphs to the + /// pixel grid only vertically which better preserves inter-glyph spacing. + /// + kFontHinting_Smooth, + + /// + /// Default hinting algorithm-- offers a good balance between sharpness and + /// shape at smaller font sizes. + /// + kFontHinting_Normal, + + /// + /// Strongest hinting algorithm-- outputs only black/white glyphs. The result + /// is usually unpleasant if the underlying TTF does not contain hints for + /// this type of rendering. + /// + kFontHinting_Monochrome, +} ULFontHinting; + +typedef struct { + float left; + float top; + float right; + float bottom; +} ULRect; + +typedef struct { + int left; + int top; + int right; + int bottom; +} ULIntRect; + +typedef struct { + bool is_empty; + unsigned int width; + unsigned int height; + unsigned int texture_id; + unsigned int texture_width; + unsigned int texture_height; + ULBitmapFormat texture_format; + ULRect uv_coords; + unsigned int render_buffer_id; +} ULRenderTarget; + +/****************************************************************************** + * Version + *****************************************************************************/ + +/// +/// Get the version string of the library in MAJOR.MINOR.PATCH format. +/// +ULExport const char* ulVersionString(); + +/// +/// Get the numeric major version of the library. +/// +ULExport unsigned int ulVersionMajor(); + +/// +/// Get the numeric minor version of the library. +/// +ULExport unsigned int ulVersionMinor(); + +/// +/// Get the numeric patch version of the library. +/// +ULExport unsigned int ulVersionPatch(); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_DEFINES_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_FileSystem.h b/Ultralight/CAPI/CAPI_FileSystem.h new file mode 100644 index 0000000..0b7da20 --- /dev/null +++ b/Ultralight/CAPI/CAPI_FileSystem.h @@ -0,0 +1,64 @@ +#ifndef ULTRALIGHT_CAPI_FILESYSTEM_H +#define ULTRALIGHT_CAPI_FILESYSTEM_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * File System + *****************************************************************************/ + +/// +/// The callback invoked when the FileSystem wants to check if a file path exists, return true if it +/// exists. +/// +typedef bool (*ULFileSystemFileExistsCallback)(ULString path); + +/// +/// Get the mime-type of the file (eg "text/html"). +/// +/// This is usually determined by analyzing the file extension. +/// +/// If a mime-type cannot be determined, you should return "application/unknown" for this value. +/// +/// The library will consume the result and call ulDestroyString() after this call returns. +/// +typedef ULString (*ULFileSystemGetFileMimeTypeCallback)(ULString path); + +/// +/// Get the charset / encoding of the file (eg "utf-8"). +/// +/// This is only important for text-based files and is usually determined by analyzing the +/// contents of the file. +/// +/// If a charset cannot be determined, it's usually safe to return "utf-8" for this value. +/// +/// The library will consume the result and call ulDestroyString() after this call returns. +/// +typedef ULString (*ULFileSystemGetFileCharsetCallback)(ULString path); + +/// +/// Open file for reading and map it to a Buffer. +/// +/// To minimize copies, you should map the requested file into memory and use ulCreateBuffer() +/// to wrap the data pointer (unmapping should be performed in the destruction callback). +/// +/// If the file was unable to be opened, you should return NULL for this value. +/// +typedef ULBuffer (*ULFileSystemOpenFileCallback)(ULString path); + +typedef struct { + ULFileSystemFileExistsCallback file_exists; + ULFileSystemGetFileMimeTypeCallback get_file_mime_type; + ULFileSystemGetFileCharsetCallback get_file_charset; + ULFileSystemOpenFileCallback open_file; +} ULFileSystem; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_FILESYSTEM_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_FontFile.h b/Ultralight/CAPI/CAPI_FontFile.h new file mode 100644 index 0000000..160cfd8 --- /dev/null +++ b/Ultralight/CAPI/CAPI_FontFile.h @@ -0,0 +1,33 @@ +#ifndef ULTRALIGHT_CAPI_FONTFILE_H +#define ULTRALIGHT_CAPI_FONTFILE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/// +/// Create a font file from an on-disk file path. +/// +/// @note The file path should already exist. +/// +ULExport ULFontFile ulFontFileCreateFromFilePath(ULString file_path); + +/// +/// Create a font file from an in-memory buffer. +/// +ULExport ULFontFile ulFontFileCreateFromBuffer(ULBuffer buffer); + +/// +/// Destroy font file +/// +ULExport void ulDestroyFontFile(ULFontFile font_file); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_FONTFILE_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_FontLoader.h b/Ultralight/CAPI/CAPI_FontLoader.h new file mode 100644 index 0000000..8d8c6b8 --- /dev/null +++ b/Ultralight/CAPI/CAPI_FontLoader.h @@ -0,0 +1,66 @@ +#ifndef ULTRALIGHT_CAPI_FONTLOADER_H +#define ULTRALIGHT_CAPI_FONTLOADER_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Font Loader + *****************************************************************************/ + +/// +/// Fallback font family name. Will be used if all other fonts fail to load. +/// +/// @note This font should be guaranteed to exist (eg, ULFontLoader::load should not fail when +/// when passed this font family name). +/// +/// @note The returned ULString instance will be consumed (ulDestroyString will be called on it). +/// +typedef ULString (*ULFontLoaderGetFallbackFont)(); + +/// +/// Fallback font family name that can render the specified characters. This is mainly used to +/// support CJK (Chinese, Japanese, Korean) text display. +/// +/// @param characters One or more UTF-16 characters. This is almost always a single character. +/// +/// @param weight Font weight. +/// +/// @param italic Whether or not italic is requested. +/// +/// @return Should return a font family name that can render the text. The returned ULString +/// instance will be consumed (ulDestroyString will be called on it). +/// +typedef ULString (*ULFontLoaderGetFallbackFontForCharacters)(ULString characters, int weight, + bool italic); + +/// +/// Get the actual font file data (TTF/OTF) for a given font description. +/// +/// @param family Font family name. +/// +/// @param weight Font weight. +/// +/// @param italic Whether or not italic is requested. +/// +/// @return A font file matching the given description (either an on-disk font filepath or an +/// in-memory file buffer). You can return NULL here and the loader will fallback to +/// another font. +/// +typedef ULFontFile (*ULFontLoaderLoad)(ULString family, int weight, bool italic); + +typedef struct { + ULFontLoaderGetFallbackFont get_fallback_font; + ULFontLoaderGetFallbackFontForCharacters get_fallback_font_for_characters; + ULFontLoaderLoad load; +} ULFontLoader; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_FONTLOADER_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_GPUDriver.h b/Ultralight/CAPI/CAPI_GPUDriver.h new file mode 100644 index 0000000..4a0b2dc --- /dev/null +++ b/Ultralight/CAPI/CAPI_GPUDriver.h @@ -0,0 +1,319 @@ +#ifndef ULTRALIGHT_CAPI_GPUDRIVER_H +#define ULTRALIGHT_CAPI_GPUDRIVER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * GPUDriver + *****************************************************************************/ + +/// +/// Render buffer description. +/// +typedef struct { + unsigned int texture_id; // The backing texture for this RenderBuffer + unsigned int width; // The width of the RenderBuffer texture + unsigned int height; // The height of the RenderBuffer texture + bool has_stencil_buffer; // Currently unused, always false. + bool has_depth_buffer; // Currently unsued, always false. +} ULRenderBuffer; + +/// +/// @note This pragma pack(push, 1) command is important! Vertex layouts should not be padded with +/// any bytes. +/// +#pragma pack(push, 1) + +/// +/// Vertex layout for path vertices. +/// +/// (this struct's members aligned on single-byte boundaries) +/// +typedef struct { + float pos[2]; + unsigned char color[4]; + float obj[2]; +} ULVertex_2f_4ub_2f; + +/// +/// Vertex layout for quad vertices. +/// +/// (this struct's members aligned on single-byte boundaries) +/// +typedef struct { + float pos[2]; + unsigned char color[4]; + float tex[2]; + float obj[2]; + float data0[4]; + float data1[4]; + float data2[4]; + float data3[4]; + float data4[4]; + float data5[4]; + float data6[4]; +} ULVertex_2f_4ub_2f_2f_28f; + +/// +/// End single-byte alignment. +/// +#pragma pack(pop) + +/// +/// Vertex formats. +/// +typedef enum { + kVertexBufferFormat_2f_4ub_2f, + kVertexBufferFormat_2f_4ub_2f_2f_28f, +} ULVertexBufferFormat; + +/// +/// Vertex buffer data. +/// +typedef struct { + ULVertexBufferFormat format; + unsigned int size; + unsigned char* data; +} ULVertexBuffer; + +/// +/// Vertex index type. +/// +typedef unsigned int ULIndexType; + +/// +/// Vertex index buffer data. +/// +typedef struct { + unsigned int size; + unsigned char* data; +} ULIndexBuffer; + +/// +/// Shader types, used with ULGPUState::shader_type +/// +/// Each of these correspond to a vertex/pixel shader pair. You can find stock shader code for these +/// in the `shaders` folder of the AppCore repo. +/// +typedef enum { + kShaderType_Fill, // Shader program for quad geometry + kShaderType_FillPath, // Shader program for path geometry +} ULShaderType; + +/// +/// Raw 4x4 matrix as an array of floats +/// +typedef struct { + float data[16]; +} ULMatrix4x4; + +/// +/// 4-component float vector +/// +typedef struct { + float value[4]; +} ULvec4; + +/// +/// GPU State description. +/// +typedef struct { + /// Viewport width in pixels + unsigned int viewport_width; + + /// Viewport height in pixels + unsigned int viewport_height; + + /// Transform matrix-- you should multiply this with the screen-space orthographic projection + /// matrix then pass to the vertex shader. + ULMatrix4x4 transform; + + /// Whether or not we should enable texturing for the current draw command. + bool enable_texturing; + + /// Whether or not we should enable blending for the current draw command. If blending is + /// disabled, any drawn pixels should overwrite existing. Mainly used so we can modify alpha + /// values of the RenderBuffer during scissored clears. + bool enable_blend; + + /// The vertex/pixel shader program pair to use for the current draw command. You should cast this + /// to ShaderType to get the corresponding enum. + unsigned char shader_type; + + /// The render buffer to use for the current draw command. + unsigned int render_buffer_id; + + /// The texture id to bind to slot #1. (Will be 0 if none) + unsigned int texture_1_id; + + /// The texture id to bind to slot #2. (Will be 0 if none) + unsigned int texture_2_id; + + /// The texture id to bind to slot #3. (Will be 0 if none) + unsigned int texture_3_id; + + /// The following four members are passed to the pixel shader via uniforms. + float uniform_scalar[8]; + ULvec4 uniform_vector[8]; + unsigned char clip_size; + ULMatrix4x4 clip[8]; + + /// Whether or not scissor testing should be used for the current draw + /// command. + bool enable_scissor; + + /// The scissor rect to use for scissor testing (units in pixels) + ULIntRect scissor_rect; +} ULGPUState; + +/// +/// Command types, used with ULCommand::command_type +/// +typedef enum { + kCommandType_ClearRenderBuffer, + kCommandType_DrawGeometry, +} ULCommandType; + +/// +/// Command description. +/// +typedef struct { + unsigned char command_type; // The type of command to dispatch. + ULGPUState gpu_state; // GPU state parameters for current command. + + /// The following members are only used with kCommandType_DrawGeometry + unsigned int geometry_id; // The geometry ID to bind + unsigned int indices_count; // The number of indices + unsigned int indices_offset; // The index to start from +} ULCommand; + +/// +/// Command list, @see ULGPUDriverUpdateCommandList +typedef struct { + unsigned int size; + ULCommand* commands; +} ULCommandList; + +/// +/// The callback invoked when the GPUDriver will begin dispatching commands (such as CreateTexture +/// and UpdateCommandList) during the current call to ulRender(). +/// +typedef void (*ULGPUDriverBeginSynchronizeCallback)(); + +/// +/// The callback invoked when the GPUDriver has finished dispatching commands during the current +/// call to ulRender(). +/// +typedef void (*ULGPUDriverEndSynchronizeCallback)(); + +/// +/// The callback invoked when the GPUDriver wants to get the next available texture ID. +/// +typedef unsigned int (*ULGPUDriverNextTextureIdCallback)(); + +/// +/// The callback invoked when the GPUDriver wants to create a texture with a +/// certain ID and optional bitmap. +/// +/// @note: If the Bitmap is empty (ulBitmapIsEmpty), then a RTT Texture should be created +/// instead. This will be used as a backing texture for a new RenderBuffer. +/// +typedef void (*ULGPUDriverCreateTextureCallback)(unsigned int texture_id, ULBitmap bitmap); + +/// +/// The callback invoked when the GPUDriver wants to update an existing non-RTT texture with new +/// bitmap data. +/// +typedef void (*ULGPUDriverUpdateTextureCallback)(unsigned int texture_id, ULBitmap bitmap); + +/// +/// The callback invoked when the GPUDriver wants to destroy a texture. +/// +typedef void (*ULGPUDriverDestroyTextureCallback)(unsigned int texture_id); + +/// +/// The callback invoked when the GPUDriver wants to generate the next available render buffer ID. +/// +typedef unsigned int (*ULGPUDriverNextRenderBufferIdCallback)(); + +/// +/// The callback invoked when the GPUDriver wants to create a render buffer with certain ID and +/// buffer description. +/// +typedef void (*ULGPUDriverCreateRenderBufferCallback)(unsigned int render_buffer_id, + ULRenderBuffer buffer); + +/// +/// The callback invoked when the GPUDriver wants to destroy a render buffer +/// +typedef void (*ULGPUDriverDestroyRenderBufferCallback)(unsigned int render_buffer_id); + +/// +/// The callback invoked when the GPUDriver wants to generate the next available geometry ID. +/// +typedef unsigned int (*ULGPUDriverNextGeometryIdCallback)(); + +/// +/// The callback invoked when the GPUDriver wants to create geometry with certain ID and +/// vertex/index data. +/// +typedef void (*ULGPUDriverCreateGeometryCallback)(unsigned int geometry_id, ULVertexBuffer vertices, + ULIndexBuffer indices); + +/// +/// The callback invoked when the GPUDriver wants to update existing geometry with new vertex/index +/// data. +/// +typedef void (*ULGPUDriverUpdateGeometryCallback)(unsigned int geometry_id, ULVertexBuffer vertices, + ULIndexBuffer indices); + +/// +/// The callback invoked when the GPUDriver wants to destroy geometry. +/// +typedef void (*ULGPUDriverDestroyGeometryCallback)(unsigned int geometry_id); + +/// +/// The callback invoked when the GPUDriver wants to update the command list (you should copy the +/// commands to your own structure). +/// +typedef void (*ULGPUDriverUpdateCommandListCallback)(ULCommandList list); + +typedef struct { + ULGPUDriverBeginSynchronizeCallback begin_synchronize; + ULGPUDriverEndSynchronizeCallback end_synchronize; + ULGPUDriverNextTextureIdCallback next_texture_id; + ULGPUDriverCreateTextureCallback create_texture; + ULGPUDriverUpdateTextureCallback update_texture; + ULGPUDriverDestroyTextureCallback destroy_texture; + ULGPUDriverNextRenderBufferIdCallback next_render_buffer_id; + ULGPUDriverCreateRenderBufferCallback create_render_buffer; + ULGPUDriverDestroyRenderBufferCallback destroy_render_buffer; + ULGPUDriverNextGeometryIdCallback next_geometry_id; + ULGPUDriverCreateGeometryCallback create_geometry; + ULGPUDriverUpdateGeometryCallback update_geometry; + ULGPUDriverDestroyGeometryCallback destroy_geometry; + ULGPUDriverUpdateCommandListCallback update_command_list; +} ULGPUDriver; + +/// +/// Sets up an orthographic projection matrix with a certain viewport width and height, multiplies +/// it by 'transform', and returns the result. +/// +/// This should be used to calculate the model-view projection matrix for the vertex shaders using +/// the current ULGPUState. +/// +/// The 'flip_y' can be optionally used to flip the Y coordinate-space. (Usually flip_y == true for +/// OpenGL) +/// +ULExport ULMatrix4x4 ulApplyProjection(ULMatrix4x4 transform, float viewport_width, + float viewport_height, bool flip_y); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_GPUDRIVER_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Geometry.h b/Ultralight/CAPI/CAPI_Geometry.h new file mode 100644 index 0000000..1aca897 --- /dev/null +++ b/Ultralight/CAPI/CAPI_Geometry.h @@ -0,0 +1,42 @@ +#ifndef ULTRALIGHT_CAPI_GEOMETRY_H +#define ULTRALIGHT_CAPI_GEOMETRY_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Rect + *****************************************************************************/ + +/// +/// Whether or not a ULRect is empty (all members equal to 0) +/// +ULExport bool ulRectIsEmpty(ULRect rect); + +/// +/// Create an empty ULRect (all members equal to 0) +/// +ULExport ULRect ulRectMakeEmpty(); + +/****************************************************************************** + * IntRect + *****************************************************************************/ + +/// +/// Whether or not a ULIntRect is empty (all members equal to 0) +/// +ULExport bool ulIntRectIsEmpty(ULIntRect rect); + +/// +/// Create an empty ULIntRect (all members equal to 0) +/// +ULExport ULIntRect ulIntRectMakeEmpty(); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_GEOMETRY_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_KeyEvent.h b/Ultralight/CAPI/CAPI_KeyEvent.h new file mode 100644 index 0000000..139b34a --- /dev/null +++ b/Ultralight/CAPI/CAPI_KeyEvent.h @@ -0,0 +1,46 @@ +#ifndef ULTRALIGHT_CAPI_KEYEVENT_H +#define ULTRALIGHT_CAPI_KEYEVENT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Key Event + ******************************************************************************/ + +/// +/// Create a key event, @see KeyEvent for help with the following parameters. +/// +ULExport ULKeyEvent ulCreateKeyEvent(ULKeyEventType type, unsigned int modifiers, + int virtual_key_code, int native_key_code, ULString text, + ULString unmodified_text, bool is_keypad, bool is_auto_repeat, + bool is_system_key); + +#ifdef _WIN32 +/// +/// Create a key event from native Windows event. +/// +ULExport ULKeyEvent ulCreateKeyEventWindows(ULKeyEventType type, uintptr_t wparam, intptr_t lparam, + bool is_system_key); +#endif + +#ifdef __OBJC__ +/// +/// Create a key event from native macOS event. +/// +ULExport ULKeyEvent ulCreateKeyEventMacOS(NSEvent* evt); +#endif + +/// +/// Destroy a key event. +/// +ULExport void ulDestroyKeyEvent(ULKeyEvent evt); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_KEYEVENT_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Logger.h b/Ultralight/CAPI/CAPI_Logger.h new file mode 100644 index 0000000..dc300ea --- /dev/null +++ b/Ultralight/CAPI/CAPI_Logger.h @@ -0,0 +1,29 @@ +#ifndef ULTRALIGHT_CAPI_LOGGER_H +#define ULTRALIGHT_CAPI_LOGGER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Logger + *****************************************************************************/ + +typedef enum { kLogLevel_Error = 0, kLogLevel_Warning, kLogLevel_Info } ULLogLevel; + +/// +/// The callback invoked when the library wants to print a message to the log. +/// +typedef void (*ULLoggerLogMessageCallback)(ULLogLevel log_level, ULString message); + +typedef struct { + ULLoggerLogMessageCallback log_message; +} ULLogger; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_LOGGER_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_MouseEvent.h b/Ultralight/CAPI/CAPI_MouseEvent.h new file mode 100644 index 0000000..b09932f --- /dev/null +++ b/Ultralight/CAPI/CAPI_MouseEvent.h @@ -0,0 +1,28 @@ +#ifndef ULTRALIGHT_CAPI_MOUSEEVENT_H +#define ULTRALIGHT_CAPI_MOUSEEVENT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Mouse Event + *****************************************************************************/ + +/// +/// Create a mouse event, @see MouseEvent for help using this function. +/// +ULExport ULMouseEvent ulCreateMouseEvent(ULMouseEventType type, int x, int y, ULMouseButton button); + +/// +/// Destroy a mouse event. +/// +ULExport void ulDestroyMouseEvent(ULMouseEvent evt); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_MOUSEEVENT_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Platform.h b/Ultralight/CAPI/CAPI_Platform.h new file mode 100644 index 0000000..1f5e446 --- /dev/null +++ b/Ultralight/CAPI/CAPI_Platform.h @@ -0,0 +1,94 @@ +#ifndef ULTRALIGHT_CAPI_PLATFORM_H +#define ULTRALIGHT_CAPI_PLATFORM_H + +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Platform + *****************************************************************************/ + +/// +/// Set a custom Logger implementation. +/// +/// This is used to log debug messages to the console or to a log file. +/// +/// You should call this before ulCreateRenderer() or ulCreateApp(). +/// +/// @note ulCreateApp() will use the default logger if you never call this. +/// +/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) you can still use the +/// default logger by calling ulEnableDefaultLogger() (@see ) +/// +ULExport void ulPlatformSetLogger(ULLogger logger); + +/// +/// Set a custom FileSystem implementation. +/// +/// This is used for loading File URLs (eg, ). If you don't call this, and are +/// not using ulCreateApp() or ulEnablePlatformFileSystem(), you will not be able to load any File +/// URLs. +/// +/// You should call this before ulCreateRenderer() or ulCreateApp(). +/// +/// @note ulCreateApp() will use the default platform file system if you never call this. +/// +/// @note If you're not using ulCreateApp(), (eg, using ulCreateRenderer()) you can still use the +/// default platform file system by calling ulEnablePlatformFileSystem()' +/// (@see ) +/// +ULExport void ulPlatformSetFileSystem(ULFileSystem file_system); + +/// +/// Set a custom Surface implementation. +/// +/// This can be used to wrap a platform-specific GPU texture, Windows DIB, macOS CGImage, or any +/// other pixel buffer target for display on screen. +/// +/// By default, the library uses a bitmap surface for all surfaces but you can override this by +/// providing your own surface definition here. +/// +/// You should call this before ulCreateRenderer() or ulCreateApp(). +/// +ULExport void ulPlatformSetSurfaceDefinition(ULSurfaceDefinition surface_definition); + +/// +/// Set a custom GPUDriver implementation. +/// +/// This should be used if you have enabled the GPU renderer in the Config and are using +/// ulCreateRenderer() (which does not provide its own GPUDriver implementation). +/// +/// The GPUDriver interface is used by the library to dispatch GPU calls to your native GPU context +/// (eg, D3D11, Metal, OpenGL, Vulkan, etc.) There are reference implementations for this interface +/// in the AppCore repo. +/// +/// You should call this before ulCreateRenderer(). +/// +ULExport void ulPlatformSetGPUDriver(ULGPUDriver gpu_driver); + +/// +/// Set a custom Clipboard implementation. +/// +/// This should be used if you are using ulCreateRenderer() (which does not provide its own +/// clipboard implementation). +/// +/// The Clipboard interface is used by the library to make calls to the system's native clipboard +/// (eg, cut, copy, paste). +/// +/// You should call this before ulCreateRenderer(). +/// +ULExport void ulPlatformSetClipboard(ULClipboard clipboard); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_PLATFORM_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Renderer.h b/Ultralight/CAPI/CAPI_Renderer.h new file mode 100644 index 0000000..ccbc6fb --- /dev/null +++ b/Ultralight/CAPI/CAPI_Renderer.h @@ -0,0 +1,68 @@ +#ifndef ULTRALIGHT_CAPI_RENDERER_H +#define ULTRALIGHT_CAPI_RENDERER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Renderer + *****************************************************************************/ + +/// +/// Create the Ultralight Renderer directly. +/// +/// Unlike ulCreateApp(), this does not use any native windows for drawing and allows you to manage +/// your own runloop and painting. This method is recommended for those wishing to integrate the +/// library into a game. +/// +/// This singleton manages the lifetime of all Views and coordinates all painting, rendering, +/// network requests, and event dispatch. +/// +/// You should only call this once per process lifetime. +/// +/// You shoud set up your platform handlers (eg, ulPlatformSetLogger, ulPlatformSetFileSystem, etc.) +/// before calling this. +/// +/// You will also need to define a font loader before calling this-- as of this writing (v1.2) the +/// only way to do this in C API is by calling ulEnablePlatformFontLoader() (available in +/// ). +/// +/// @NOTE: You should not call this if you are using ulCreateApp(), it creates its own renderer and +/// provides default implementations for various platform handlers automatically. +/// +ULExport ULRenderer ulCreateRenderer(ULConfig config); + +/// +/// Destroy the renderer. +/// +ULExport void ulDestroyRenderer(ULRenderer renderer); + +/// +/// Update timers and dispatch internal callbacks (JavaScript and network). +/// +ULExport void ulUpdate(ULRenderer renderer); + +/// +/// Render all active Views. +/// +ULExport void ulRender(ULRenderer renderer); + +/// +/// Attempt to release as much memory as possible. Don't call this from any callbacks or driver +/// code. +/// +ULExport void ulPurgeMemory(ULRenderer renderer); + +/// +/// Print detailed memory usage statistics to the log. (@see ulPlatformSetLogger) +/// +ULExport void ulLogMemoryUsage(ULRenderer renderer); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_RENDERER_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_ScrollEvent.h b/Ultralight/CAPI/CAPI_ScrollEvent.h new file mode 100644 index 0000000..7a067cf --- /dev/null +++ b/Ultralight/CAPI/CAPI_ScrollEvent.h @@ -0,0 +1,28 @@ +#ifndef ULTRALIGHT_CAPI_SCROLLEVENT_H +#define ULTRALIGHT_CAPI_SCROLLEVENT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Scroll Event + *****************************************************************************/ + +/// +/// Create a scroll event, @see ScrollEvent for help using this function. +/// +ULExport ULScrollEvent ulCreateScrollEvent(ULScrollEventType type, int delta_x, int delta_y); + +/// +/// Destroy a scroll event. +/// +ULExport void ulDestroyScrollEvent(ULScrollEvent evt); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_SCROLLEVENT_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Session.h b/Ultralight/CAPI/CAPI_Session.h new file mode 100644 index 0000000..b6b11f8 --- /dev/null +++ b/Ultralight/CAPI/CAPI_Session.h @@ -0,0 +1,56 @@ +#ifndef ULTRALIGHT_CAPI_SESSION_H +#define ULTRALIGHT_CAPI_SESSION_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Session + *****************************************************************************/ + +/// +/// Create a Session to store local data in (such as cookies, local storage, application cache, +/// indexed db, etc). +/// +ULExport ULSession ulCreateSession(ULRenderer renderer, bool is_persistent, ULString name); + +/// +/// Destroy a Session. +/// +ULExport void ulDestroySession(ULSession session); + +/// +/// Get the default session (persistent session named "default"). +/// +/// @note This session is owned by the Renderer, you shouldn't destroy it. +/// +ULExport ULSession ulDefaultSession(ULRenderer renderer); + +/// +/// Whether or not is persistent (backed to disk). +/// +ULExport bool ulSessionIsPersistent(ULSession session); + +/// +/// Unique name identifying the session (used for unique disk path). +/// +ULExport ULString ulSessionGetName(ULSession session); + +/// +/// Unique numeric Id for the session. +/// +ULExport unsigned long long ulSessionGetId(ULSession session); + +/// +/// The disk path to write to (used by persistent sessions only). +/// +ULExport ULString ulSessionGetDiskPath(ULSession session); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_SESSION_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_String.h b/Ultralight/CAPI/CAPI_String.h new file mode 100644 index 0000000..0895c27 --- /dev/null +++ b/Ultralight/CAPI/CAPI_String.h @@ -0,0 +1,68 @@ +#ifndef ULTRALIGHT_CAPI_STRING_H +#define ULTRALIGHT_CAPI_STRING_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * String + *****************************************************************************/ + +/// +/// Create string from null-terminated ASCII C-string. +/// +ULExport ULString ulCreateString(const char* str); + +/// +/// Create string from UTF-8 buffer. +/// +ULExport ULString ulCreateStringUTF8(const char* str, size_t len); + +/// +/// Create string from UTF-16 buffer. +/// +ULExport ULString ulCreateStringUTF16(ULChar16* str, size_t len); + +/// +/// Create string from copy of existing string. +/// +ULExport ULString ulCreateStringFromCopy(ULString str); + +/// +/// Destroy string (you should destroy any strings you explicitly Create). +/// +ULExport void ulDestroyString(ULString str); + +/// +/// Get native UTF-8 buffer data (always null-terminated). +/// +ULExport char* ulStringGetData(ULString str); + +/// +/// Get length (in bytes) of the UTF-8 buffer data, not including null terminator. +/// +ULExport size_t ulStringGetLength(ULString str); + +/// +/// Whether this string is empty or not. +/// +ULExport bool ulStringIsEmpty(ULString str); + +/// +/// Replaces the contents of 'str' with the contents of 'new_str' +/// +ULExport void ulStringAssignString(ULString str, ULString new_str); + +/// +/// Replaces the contents of 'str' with the contents of a C-string. +/// +ULExport void ulStringAssignCString(ULString str, const char* c_str); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_STRING_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_Surface.h b/Ultralight/CAPI/CAPI_Surface.h new file mode 100644 index 0000000..5550b1e --- /dev/null +++ b/Ultralight/CAPI/CAPI_Surface.h @@ -0,0 +1,203 @@ +#ifndef ULTRALIGHT_CAPI_SURFACE_H +#define ULTRALIGHT_CAPI_SURFACE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * Surface + *****************************************************************************/ + +/// +/// Width (in pixels). +/// +ULExport unsigned int ulSurfaceGetWidth(ULSurface surface); + +/// +/// Height (in pixels). +/// +ULExport unsigned int ulSurfaceGetHeight(ULSurface surface); + +/// +/// Number of bytes between rows (usually width * 4) +/// +ULExport unsigned int ulSurfaceGetRowBytes(ULSurface surface); + +/// +/// Size in bytes. +/// +ULExport size_t ulSurfaceGetSize(ULSurface surface); + +/// +/// Lock the pixel buffer and get a pointer to the beginning of the data for reading/writing. +/// +/// Native pixel format is premultiplied BGRA 32-bit (8 bits per channel). +/// +ULExport void* ulSurfaceLockPixels(ULSurface surface); + +/// +/// Unlock the pixel buffer. +/// +ULExport void ulSurfaceUnlockPixels(ULSurface surface); + +/// +/// Resize the pixel buffer to a certain width and height (both in pixels). +/// +/// This should never be called while pixels are locked. +/// +ULExport void ulSurfaceResize(ULSurface surface, unsigned int width, unsigned int height); + +/// +/// Set the dirty bounds to a certain value. +/// +/// This is called after the Renderer paints to an area of the pixel buffer. (The new value will be +/// joined with the existing dirty_bounds()) +/// +ULExport void ulSurfaceSetDirtyBounds(ULSurface surface, ULIntRect bounds); + +/// +/// Get the dirty bounds. +/// +/// This value can be used to determine which portion of the pixel buffer has been updated since the +/// last call to ulSurfaceClearDirtyBounds(). +/// +/// The general algorithm to determine if a Surface needs display is: +///
+///   if (!ulIntRectIsEmpty(ulSurfaceGetDirtyBounds(surface))) {
+///       // Surface pixels are dirty and needs display.
+///       // Cast Surface to native Surface and use it here (pseudo code)
+///       DisplaySurface(surface);
+///
+///       // Once you're done, clear the dirty bounds:
+///       ulSurfaceClearDirtyBounds(surface);
+///  }
+///  
+/// +ULExport ULIntRect ulSurfaceGetDirtyBounds(ULSurface surface); + +/// +/// Clear the dirty bounds. +/// +/// You should call this after you're done displaying the Surface. +/// +ULExport void ulSurfaceClearDirtyBounds(ULSurface surface); + +/// +/// Get the underlying user data pointer (this is only valid if you have set a custom surface +/// implementation via ulPlatformSetSurfaceDefinition). +/// +/// This will return nullptr if this surface is the default ULBitmapSurface. +/// +ULExport void* ulSurfaceGetUserData(ULSurface surface); + +/****************************************************************************** + * BitmapSurface + *****************************************************************************/ + +/// +/// Get the underlying Bitmap from the default Surface. +/// +/// @note Do not call ulDestroyBitmap() on the returned value, it is owned by the surface. +/// +ULExport ULBitmap ulBitmapSurfaceGetBitmap(ULBitmapSurface surface); + +/****************************************************************************** + * Surface Definition + *****************************************************************************/ + +/// +/// The callback invoked when a Surface is created. +/// +/// @param width The width in pixels. +/// @param height The height in pixels. +/// +/// @return This callback should return a pointer to user-defined data for the instance. This user +/// data pointer will be passed to all other callbacks when operating on the instance. +/// +typedef void* (*ULSurfaceDefinitionCreateCallback)(unsigned int width, unsigned int height); + +/// +/// The callback invoked when a Surface is destroyed. +/// +/// @param user_data User data pointer uniquely identifying the surface. +/// +typedef void (*ULSurfaceDefinitionDestroyCallback)(void* user_data); + +/// +/// The callback invoked when a Surface's width (in pixels) is requested. +/// +/// @param user_data User data pointer uniquely identifying the surface. +/// +typedef unsigned int (*ULSurfaceDefinitionGetWidthCallback)(void* user_data); + +/// +/// The callback invoked when a Surface's height (in pixels) is requested. +/// +/// @param user_data User data pointer uniquely identifying the surface. +/// +typedef unsigned int (*ULSurfaceDefinitionGetHeightCallback)(void* user_data); + +/// +/// The callback invoked when a Surface's row bytes is requested. +/// +/// @note This value is also known as "stride". Usually width * 4. +/// +/// @param user_data User data pointer uniquely identifying the surface. +/// +typedef unsigned int (*ULSurfaceDefinitionGetRowBytesCallback)(void* user_data); + +/// +/// The callback invoked when a Surface's size (in bytes) is requested. +/// +/// @param user_data User data pointer uniquely identifying the surface. +/// +typedef size_t (*ULSurfaceDefinitionGetSizeCallback)(void* user_data); + +/// +/// The callback invoked when a Surface's pixel buffer is requested to be locked for reading/writing +/// (should return a pointer to locked bytes). +/// +/// @param user_data User data pointer uniquely identifying the surface. +/// +typedef void* (*ULSurfaceDefinitionLockPixelsCallback)(void* user_data); + +/// +/// The callback invoked when a Surface's pixel buffer is requested to be unlocked after previously +/// being locked. +/// +/// @param user_data User data pointer uniquely identifying the surface. +/// +typedef void (*ULSurfaceDefinitionUnlockPixelsCallback)(void* user_data); + +/// +/// The callback invoked when a Surface is requested to be resized to a certain width/height. +/// +/// @param user_data User data pointer uniquely identifying the surface. +/// +/// @param width Width in pixels. +/// +/// @param height Height in pixels. +/// +typedef void (*ULSurfaceDefinitionResizeCallback)(void* user_data, unsigned int width, + unsigned int height); + +typedef struct { + ULSurfaceDefinitionCreateCallback create; + ULSurfaceDefinitionDestroyCallback destroy; + ULSurfaceDefinitionGetWidthCallback get_width; + ULSurfaceDefinitionGetHeightCallback get_height; + ULSurfaceDefinitionGetRowBytesCallback get_row_bytes; + ULSurfaceDefinitionGetSizeCallback get_size; + ULSurfaceDefinitionLockPixelsCallback lock_pixels; + ULSurfaceDefinitionUnlockPixelsCallback unlock_pixels; + ULSurfaceDefinitionResizeCallback resize; +} ULSurfaceDefinition; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_SURFACE_H \ No newline at end of file diff --git a/Ultralight/CAPI/CAPI_View.h b/Ultralight/CAPI/CAPI_View.h new file mode 100644 index 0000000..96bba43 --- /dev/null +++ b/Ultralight/CAPI/CAPI_View.h @@ -0,0 +1,486 @@ +#ifndef ULTRALIGHT_CAPI_VIEW_H +#define ULTRALIGHT_CAPI_VIEW_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** + * ViewConfig + *****************************************************************************/ + +/// +/// Create view configuration with default values (see ). +/// +ULExport ULViewConfig ulCreateViewConfig(); + +/// +/// Destroy view configuration. +/// +ULExport void ulDestroyViewConfig(ULViewConfig config); + +/// +/// Whether to render using the GPU renderer (accelerated) or the CPU renderer (unaccelerated). +/// +/// This option is only valid if you're managing the Renderer yourself (eg, you've previously +/// called ulCreateRenderer() instead of ulCreateApp()). +/// +/// When true, the View will be rendered to an offscreen GPU texture using the GPU driver set in +/// ulPlatformSetGPUDriver(). You can fetch details for the texture via ulViewGetRenderTarget(). +/// +/// When false (the default), the View will be rendered to an offscreen pixel buffer using the +/// multithreaded CPU renderer. This pixel buffer can optionally be provided by the user-- +/// for more info see ulViewGetSurface(). +/// +ULExport void ulViewConfigSetIsAccelerated(ULViewConfig config, bool is_accelerated); + +/// +/// Set whether images should be enabled (Default = True). +/// +ULExport void ulViewConfigSetIsTransparent(ULViewConfig config, bool is_transparent); + +/// +/// The initial device scale, ie. the amount to scale page units to screen pixels. This should be +/// set to the scaling factor of the device that the View is displayed on. (Default = 1.0) +/// +/// @note 1.0 is equal to 100% zoom (no scaling), 2.0 is equal to 200% zoom (2x scaling) +/// +ULExport void ulViewConfigSetInitialDeviceScale(ULViewConfig config, double initial_device_scale); + +/// +/// Whether or not the View should initially have input focus. (Default = True) +/// +ULExport void ulViewConfigSetInitialFocus(ULViewConfig config, bool is_focused); + +/// +/// Set whether images should be enabled (Default = True). +/// +ULExport void ulViewConfigSetEnableImages(ULViewConfig config, bool enabled); + +/// +/// Set whether JavaScript should be enabled (Default = True). +/// +ULExport void ulViewConfigSetEnableJavaScript(ULViewConfig config, bool enabled); + +/// +/// Set default font-family to use (Default = Times New Roman). +/// +ULExport void ulViewConfigSetFontFamilyStandard(ULViewConfig config, ULString font_name); + +/// +/// Set default font-family to use for fixed fonts, eg
 and 
+/// (Default = Courier New).
+///
+ULExport void ulViewConfigSetFontFamilyFixed(ULViewConfig config, ULString font_name);
+
+///
+/// Set default font-family to use for serif fonts (Default = Times New Roman).
+///
+ULExport void ulViewConfigSetFontFamilySerif(ULViewConfig config, ULString font_name);
+
+///
+/// Set default font-family to use for sans-serif fonts (Default = Arial).
+///
+ULExport void ulViewConfigSetFontFamilySansSerif(ULViewConfig config, ULString font_name);
+
+///
+/// Set user agent string (See  for the default).
+///
+ULExport void ulViewConfigSetUserAgent(ULViewConfig config, ULString agent_string);
+
+/******************************************************************************
+ * View
+ *****************************************************************************/
+
+///
+/// Create a View with certain size (in pixels).
+///
+/// @note  You can pass null to 'session' to use the default session.
+///
+ULExport ULView ulCreateView(ULRenderer renderer, unsigned int width, unsigned int height,
+                             ULViewConfig view_config, ULSession session);
+
+///
+/// Destroy a View.
+///
+ULExport void ulDestroyView(ULView view);
+
+///
+/// Get current URL.
+///
+/// @note Don't destroy the returned string, it is owned by the View.
+///
+ULExport ULString ulViewGetURL(ULView view);
+
+///
+/// Get current title.
+///
+/// @note Don't destroy the returned string, it is owned by the View.
+///
+ULExport ULString ulViewGetTitle(ULView view);
+
+///
+/// Get the width, in pixels.
+///
+ULExport unsigned int ulViewGetWidth(ULView view);
+
+///
+/// Get the height, in pixels.
+///
+ULExport unsigned int ulViewGetHeight(ULView view);
+
+///
+/// Get the device scale, ie. the amount to scale page units to screen pixels.
+///
+/// For example, a value of 1.0 is equivalent to 100% zoom. A value of 2.0 is 200% zoom.
+///
+ULExport double ulViewGetDeviceScale(ULView view);
+
+///
+/// Set the device scale.
+///
+ULExport void ulViewSetDeviceScale(ULView view, double scale);
+
+///
+/// Whether or not the View is GPU-accelerated. If this is false, the page will be rendered
+/// via the CPU renderer.
+///
+ULExport bool ulViewIsAccelerated(ULView view);
+
+///
+/// Whether or not the View supports transparent backgrounds.
+///
+ULExport bool ulViewIsTransparent(ULView view);
+
+///
+/// Check if the main frame of the page is currrently loading.
+///
+ULExport bool ulViewIsLoading(ULView view);
+
+///
+/// Get the RenderTarget for the View.
+///
+/// @note  Only valid if this View is GPU accelerated.
+/// 
+///        You can use this with your GPUDriver implementation to bind and display the
+///        corresponding texture in your application.
+///
+ULExport ULRenderTarget ulViewGetRenderTarget(ULView view);
+
+///
+/// Get the Surface for the View (native pixel buffer that the CPU renderer draws into).
+///
+/// @note  This operation is only valid if you're managing the Renderer yourself (eg, you've
+///        previously called ulCreateRenderer() instead of ulCreateApp()).
+///
+///        This function will return NULL if this View is GPU accelerated.
+///
+///        The default Surface is BitmapSurface but you can provide your own Surface implementation
+///        via ulPlatformSetSurfaceDefinition.
+///
+///        When using the default Surface, you can retrieve the underlying bitmap by casting
+///        ULSurface to ULBitmapSurface and calling ulBitmapSurfaceGetBitmap().
+///
+ULExport ULSurface ulViewGetSurface(ULView view);
+
+///
+/// Load a raw string of HTML.
+///
+ULExport void ulViewLoadHTML(ULView view, ULString html_string);
+
+///
+/// Load a URL into main frame.
+///
+ULExport void ulViewLoadURL(ULView view, ULString url_string);
+
+///
+/// Resize view to a certain width and height (in pixels).
+///
+ULExport void ulViewResize(ULView view, unsigned int width, unsigned int height);
+
+///
+/// Acquire the page's JSContext for use with JavaScriptCore API.
+///
+/// @note  This call locks the context for the current thread. You should call
+///        ulViewUnlockJSContext() after using the context so other worker threads can modify
+///        JavaScript state.
+///
+/// @note  The lock is recusive, it's okay to call this multiple times as long as you call
+///        ulViewUnlockJSContext() the same number of times.
+///
+ULExport JSContextRef ulViewLockJSContext(ULView view);
+
+///
+/// Unlock the page's JSContext after a previous call to ulViewLockJSContext().
+///
+ULExport void ulViewUnlockJSContext(ULView view);
+
+///
+/// Evaluate a string of JavaScript and return result.
+///
+/// @param  js_string  The string of JavaScript to evaluate.
+///
+/// @param  exception  The address of a ULString to store a description of the last exception. Pass
+///                    NULL to ignore this. Don't destroy the exception string returned, it's owned
+///                    by the View.
+///
+/// @note Don't destroy the returned string, it's owned by the View. This value is reset with every
+///       call-- if you want to retain it you should copy the result to a new string via
+///       ulCreateStringFromCopy().
+///
+/// @note An example of using this API:
+///       
+///         ULString script = ulCreateString("1 + 1");
+///         ULString exception;
+///         ULString result = ulViewEvaluateScript(view, script, &exception);
+///         /* Use the result ("2") and exception description (if any) here. */
+///         ulDestroyString(script);
+///       
+/// +ULExport ULString ulViewEvaluateScript(ULView view, ULString js_string, ULString* exception); + +/// +/// Check if can navigate backwards in history. +/// +ULExport bool ulViewCanGoBack(ULView view); + +/// +/// Check if can navigate forwards in history. +/// +ULExport bool ulViewCanGoForward(ULView view); + +/// +/// Navigate backwards in history. +/// +ULExport void ulViewGoBack(ULView view); + +/// +/// Navigate forwards in history. +/// +ULExport void ulViewGoForward(ULView view); + +/// +/// Navigate to arbitrary offset in history. +/// +ULExport void ulViewGoToHistoryOffset(ULView view, int offset); + +/// +/// Reload current page. +/// +ULExport void ulViewReload(ULView view); + +/// +/// Stop all page loads. +/// +ULExport void ulViewStop(ULView view); + +/// +/// Give focus to the View. +/// +/// You should call this to give visual indication that the View has input focus (changes active +/// text selection colors, for example). +/// +ULExport void ulViewFocus(ULView view); + +/// +/// Remove focus from the View and unfocus any focused input elements. +/// +/// You should call this to give visual indication that the View has lost input focus. +/// +ULExport void ulViewUnfocus(ULView view); + +/// +/// Whether or not the View has focus. +/// +ULExport bool ulViewHasFocus(ULView view); + +/// +/// Whether or not the View has an input element with visible keyboard focus (indicated by a +/// blinking caret). +/// +/// You can use this to decide whether or not the View should consume keyboard input events (useful +/// in games with mixed UI and key handling). +/// +ULExport bool ulViewHasInputFocus(ULView view); + +/// +/// Fire a keyboard event. +/// +ULExport void ulViewFireKeyEvent(ULView view, ULKeyEvent key_event); + +/// +/// Fire a mouse event. +/// +ULExport void ulViewFireMouseEvent(ULView view, ULMouseEvent mouse_event); + +/// +/// Fire a scroll event. +/// +ULExport void ulViewFireScrollEvent(ULView view, ULScrollEvent scroll_event); + +typedef void (*ULChangeTitleCallback)(void* user_data, ULView caller, ULString title); + +/// +/// Set callback for when the page title changes. +/// +ULExport void ulViewSetChangeTitleCallback(ULView view, ULChangeTitleCallback callback, + void* user_data); + +typedef void (*ULChangeURLCallback)(void* user_data, ULView caller, ULString url); + +/// +/// Set callback for when the page URL changes. +/// +ULExport void ulViewSetChangeURLCallback(ULView view, ULChangeURLCallback callback, + void* user_data); + +typedef void (*ULChangeTooltipCallback)(void* user_data, ULView caller, ULString tooltip); + +/// +/// Set callback for when the tooltip changes (usually result of a mouse hover). +/// +ULExport void ulViewSetChangeTooltipCallback(ULView view, ULChangeTooltipCallback callback, + void* user_data); + +typedef void (*ULChangeCursorCallback)(void* user_data, ULView caller, ULCursor cursor); + +/// +/// Set callback for when the mouse cursor changes. +/// +ULExport void ulViewSetChangeCursorCallback(ULView view, ULChangeCursorCallback callback, + void* user_data); + +typedef void (*ULAddConsoleMessageCallback)(void* user_data, ULView caller, ULMessageSource source, + ULMessageLevel level, ULString message, + unsigned int line_number, unsigned int column_number, + ULString source_id); + +/// +/// Set callback for when a message is added to the console (useful for JavaScript / network errors +/// and debugging). +/// +ULExport void ulViewSetAddConsoleMessageCallback(ULView view, ULAddConsoleMessageCallback callback, + void* user_data); + +typedef ULView (*ULCreateChildViewCallback)(void* user_data, ULView caller, ULString opener_url, + ULString target_url, bool is_popup, + ULIntRect popup_rect); + +/// +/// Set callback for when the page wants to create a new View. +/// +/// This is usually the result of a user clicking a link with target="_blank" or by JavaScript +/// calling window.open(url). +/// +/// To allow creation of these new Views, you should create a new View in this callback, resize it +/// to your container, and return it. You are responsible for displaying the returned View. +/// +/// You should return NULL if you want to block the action. +/// +ULExport void ulViewSetCreateChildViewCallback(ULView view, ULCreateChildViewCallback callback, + void* user_data); + +typedef ULView (*ULCreateInspectorViewCallback)(void* user_data, ULView caller, bool is_local, + ULString inspected_url); + +ULExport void ulViewSetCreateInspectorViewCallback(ULView view, ULCreateInspectorViewCallback callback, + void* user_data); + +typedef void (*ULBeginLoadingCallback)(void* user_data, ULView caller, unsigned long long frame_id, + bool is_main_frame, ULString url); + +/// +/// Set callback for when the page begins loading a new URL into a frame. +/// +ULExport void ulViewSetBeginLoadingCallback(ULView view, ULBeginLoadingCallback callback, + void* user_data); + +typedef void (*ULFinishLoadingCallback)(void* user_data, ULView caller, unsigned long long frame_id, + bool is_main_frame, ULString url); + +/// +/// Set callback for when the page finishes loading a URL into a frame. +/// +ULExport void ulViewSetFinishLoadingCallback(ULView view, ULFinishLoadingCallback callback, + void* user_data); + +typedef void (*ULFailLoadingCallback)(void* user_data, ULView caller, unsigned long long frame_id, + bool is_main_frame, ULString url, ULString description, + ULString error_domain, int error_code); + +/// +/// Set callback for when an error occurs while loading a URL into a frame. +/// +ULExport void ulViewSetFailLoadingCallback(ULView view, ULFailLoadingCallback callback, + void* user_data); + +typedef void (*ULWindowObjectReadyCallback)(void* user_data, ULView caller, + unsigned long long frame_id, bool is_main_frame, + ULString url); + +/// +/// Set callback for when the JavaScript window object is reset for a new page load. +/// +/// This is called before any scripts are executed on the page and is the earliest time to setup any +/// initial JavaScript state or bindings. +/// +/// The document is not guaranteed to be loaded/parsed at this point. If you need to make any +/// JavaScript calls that are dependent on DOM elements or scripts on the page, use DOMReady +/// instead. +/// +/// The window object is lazily initialized (this will not be called on pages with no scripts). +/// +ULExport void ulViewSetWindowObjectReadyCallback(ULView view, ULWindowObjectReadyCallback callback, + void* user_data); + +typedef void (*ULDOMReadyCallback)(void* user_data, ULView caller, unsigned long long frame_id, + bool is_main_frame, ULString url); + +/// +/// Set callback for when all JavaScript has been parsed and the document is ready. +/// +/// This is the best time to make any JavaScript calls that are dependent on DOM elements or scripts +/// on the page. +/// +ULExport void ulViewSetDOMReadyCallback(ULView view, ULDOMReadyCallback callback, void* user_data); + +typedef void (*ULUpdateHistoryCallback)(void* user_data, ULView caller); + +/// +/// Set callback for when the history (back/forward state) is modified. +/// +ULExport void ulViewSetUpdateHistoryCallback(ULView view, ULUpdateHistoryCallback callback, + void* user_data); + +/// +/// Set whether or not a view should be repainted during the next call to ulRender. +/// +/// @note This flag is automatically set whenever the page content changes but you can set it +/// directly in case you need to force a repaint. +/// +ULExport void ulViewSetNeedsPaint(ULView view, bool needs_paint); + +/// +/// Whether or not a view should be painted during the next call to ulRender. +/// +ULExport bool ulViewGetNeedsPaint(ULView view); + +/// +/// Create an Inspector View to inspect / debug this View locally. +/// +/// This will only succeed if you have the inspector assets in your filesystem-- the inspector +/// will look for file:///inspector/Main.html when it first loads. +/// +/// You must handle ULCreateChildViewCallback so that the library has a View to display +/// the inspector in. This function will call the callback only if an inspector view is not +/// currently active. +/// +ULExport void ulViewCreateLocalInspectorView(ULView view); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // ULTRALIGHT_CAPI_VIEW_H \ No newline at end of file diff --git a/Ultralight/Defines.h b/Ultralight/Defines.h index 49445a4..011855b 100644 --- a/Ultralight/Defines.h +++ b/Ultralight/Defines.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2021 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once @@ -35,6 +35,20 @@ # error This project can only be compiled with a compiler that supports C++11 #endif +#if INTPTR_MAX == INT32_MAX +#define UL_ARCH_32_BIT +#elif INTPTR_MAX == INT64_MAX +#define UL_ARCH_64_BIT +#else +#error "Unknown CPU architecture: environment not 32 or 64-bit." +#endif + +#if defined(__aarch64__) +# define UL_ARCH_ARM64 +# if defined(__APPLE__) +# define UL_ARCH_ARM64_APPLE_SILICON +# endif +#endif #if defined(__WIN32__) || defined(_WIN32) # if defined(ULTRALIGHT_STATIC_BUILD) @@ -98,5 +112,5 @@ UExport uint32_t UltralightVersionPatch(); /// - GitHub: -- Report issues and browse code /// /// @section copyright_sec Copyright -/// Documentation is Copyright (C) 2021 Ultralight, Inc. All rights reserved. +/// Documentation is Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// diff --git a/Ultralight/GamepadEvent.h b/Ultralight/GamepadEvent.h new file mode 100644 index 0000000..1d838b3 --- /dev/null +++ b/Ultralight/GamepadEvent.h @@ -0,0 +1,115 @@ +/// +/// @file GamepadEvent.h +/// +/// @brief The header for various gamepad events. +/// +/// @author +/// +/// This file is a part of Ultralight, a next-generation HTML renderer. +/// +/// Website: +/// +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. +/// +#pragma once +#include +#include + +namespace ultralight { + +/// +/// @brief A gamepad event. +/// +/// @see View::FireGamepadEvent +/// +class UExport GamepadEvent { + public: + /// + /// The various GamepadEvent types. + /// + enum Type { + /// + /// This event type should be fired when a gamepad is connected. + /// + /// @note You will need to previously declare the gamepad, its index, and details about + /// its axis and button layout via View::SetGamepadDetails prior to calling + /// View::FireGamepadEvent. + /// + kType_GamepadConnected, + + /// + /// This event type should be fired when a gamepad is disconnected. + /// + kType_GamepadDisconnected, + }; + + /// + // The type of this GamepadEvent + /// + Type type; + + /// + /// The index of the gamepad, this should match the value previously set in + /// View::SetGamepadDetails. + /// + uint32_t index; +}; + +/// +/// @brief A gamepad axis event. +/// +/// @see View::FireGamepadAxisEvent +/// +class UExport GamepadAxisEvent { + public: + /// + /// The index of the gamepad, this should match the value previously set in + /// View::SetGamepadDetails. + /// + uint32_t index; + + /// + /// The index of the axis whose value has changed. + /// + /// This value should be in the range previously set in View::SetGamepadDetails. + /// + uint32_t axis_index; + + /// + /// The new value of the axis. + /// + /// This value should be normalized to the range [-1.0, 1.0]. + /// + double value; +}; + +/// +/// @brief A gamepad button event. +/// +/// @see View::FireGamepadButtonEvent +/// +class UExport GamepadButtonEvent { + public: + /// + /// The index of the gamepad, this should match the value previously set in + /// View::SetGamepadDetails. + /// + uint32_t index; + + /// + /// The index of the button whose value has changed. + /// + /// This value should be in the range previously set in View::SetGamepadDetails. + /// + uint32_t button_index; + + /// + /// The new value of the button. + /// + /// This value should be normalized to the range [-1.0, 1.0], with any value greater than + /// 0.0 to be considered "pressed". + /// + double value; +}; + +} // namespace ultralight diff --git a/Ultralight/Geometry.h b/Ultralight/Geometry.h index 1607031..6fe5197 100644 --- a/Ultralight/Geometry.h +++ b/Ultralight/Geometry.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2021 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include @@ -399,14 +399,14 @@ struct UExport vec4 { (a.w < b.w) ? b.w : a.w }; } - constexpr void load(const float* val) { + inline void load(const float* val) { x = val[0]; y = val[1]; z = val[2]; w = val[3]; } - constexpr void store(float* val) const { + inline void store(float* val) const { val[0] = x; val[1] = y; val[2] = z; diff --git a/Ultralight/JavaScript.h b/Ultralight/JavaScript.h index 2f422d2..64543b8 100644 --- a/Ultralight/JavaScript.h +++ b/Ultralight/JavaScript.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2020 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include @@ -20,9 +20,8 @@ namespace ultralight { /// -/// This class wraps a JSContextRef (a JavaScript execution context for use -/// with JavaScriptCore) and locks the context on the current thread for the -/// duration of its lifetime. +/// This class wraps a JSContextRef (a JavaScript execution context for use with JavaScriptCore) +/// and locks the context on the current thread for the duration of its lifetime. /// class UExport JSContext : public RefCounted { public: diff --git a/Ultralight/KeyCodes.h b/Ultralight/KeyCodes.h index d666621..fb39358 100644 --- a/Ultralight/KeyCodes.h +++ b/Ultralight/KeyCodes.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2020 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once @@ -18,517 +18,520 @@ namespace ultralight { /// /// Namespace containing all the key-code definitions for KeyboardEvent. /// Most of these correspond directly to the key-code values on Windows. - /// +/// namespace KeyCodes { - // GK_BACK (08) BACKSPACE key - const int GK_BACK = 0x08; +// GK_BACK (08) BACKSPACE key +const int GK_BACK = 0x08; - // GK_TAB (09) TAB key - const int GK_TAB = 0x09; +// GK_TAB (09) TAB key +const int GK_TAB = 0x09; - // GK_CLEAR (0C) CLEAR key - const int GK_CLEAR = 0x0C; +// GK_CLEAR (0C) CLEAR key +const int GK_CLEAR = 0x0C; - // GK_RETURN (0D) - const int GK_RETURN = 0x0D; +// GK_RETURN (0D) +const int GK_RETURN = 0x0D; - // GK_SHIFT (10) SHIFT key - const int GK_SHIFT = 0x10; +// GK_SHIFT (10) SHIFT key +const int GK_SHIFT = 0x10; - // GK_CONTROL (11) CTRL key - const int GK_CONTROL = 0x11; +// GK_CONTROL (11) CTRL key +const int GK_CONTROL = 0x11; - // GK_MENU (12) ALT key - const int GK_MENU = 0x12; +// GK_MENU (12) ALT key +const int GK_MENU = 0x12; - // GK_PAUSE (13) PAUSE key - const int GK_PAUSE = 0x13; +// GK_PAUSE (13) PAUSE key +const int GK_PAUSE = 0x13; - // GK_CAPITAL (14) CAPS LOCK key - const int GK_CAPITAL = 0x14; +// GK_CAPITAL (14) CAPS LOCK key +const int GK_CAPITAL = 0x14; - // GK_KANA (15) Input Method Editor (IME) Kana mode - const int GK_KANA = 0x15; +// GK_KANA (15) Input Method Editor (IME) Kana mode +const int GK_KANA = 0x15; - // GK_HANGUEL (15) IME Hanguel mode (maintained for compatibility; use GK_HANGUL) - // GK_HANGUL (15) IME Hangul mode - const int GK_HANGUL = 0x15; +// GK_HANGUEL (15) IME Hanguel mode (maintained for compatibility; use GK_HANGUL) +// GK_HANGUL (15) IME Hangul mode +const int GK_HANGUL = 0x15; - // GK_IME_ON (16) IME On - const int GK_IME_ON = 0x16; +// GK_IME_ON (16) IME On +const int GK_IME_ON = 0x16; - // GK_JUNJA (17) IME Junja mode - const int GK_JUNJA = 0x17; +// GK_JUNJA (17) IME Junja mode +const int GK_JUNJA = 0x17; - // GK_FINAL (18) IME final mode - const int GK_FINAL = 0x18; +// GK_FINAL (18) IME final mode +const int GK_FINAL = 0x18; - // GK_HANJA (19) IME Hanja mode - const int GK_HANJA = 0x19; +// GK_HANJA (19) IME Hanja mode +const int GK_HANJA = 0x19; - // GK_KANJI (19) IME Kanji mode - const int GK_KANJI = 0x19; +// GK_KANJI (19) IME Kanji mode +const int GK_KANJI = 0x19; - // GK_IME_OFF (1A) IME Off - const int GK_IME_OFF = 0x1A; +// GK_IME_OFF (1A) IME Off +const int GK_IME_OFF = 0x1A; - // GK_ESCAPE (1B) ESC key - const int GK_ESCAPE = 0x1B; +// GK_ESCAPE (1B) ESC key +const int GK_ESCAPE = 0x1B; - // GK_CONVERT (1C) IME convert - const int GK_CONVERT = 0x1C; +// GK_CONVERT (1C) IME convert +const int GK_CONVERT = 0x1C; - // GK_NONCONVERT (1D) IME nonconvert - const int GK_NONCONVERT = 0x1D; +// GK_NONCONVERT (1D) IME nonconvert +const int GK_NONCONVERT = 0x1D; - // GK_ACCEPT (1E) IME accept - const int GK_ACCEPT = 0x1E; +// GK_ACCEPT (1E) IME accept +const int GK_ACCEPT = 0x1E; - // GK_MODECHANGE (1F) IME mode change request - const int GK_MODECHANGE = 0x1F; +// GK_MODECHANGE (1F) IME mode change request +const int GK_MODECHANGE = 0x1F; - // GK_SPACE (20) SPACEBAR - const int GK_SPACE = 0x20; +// GK_SPACE (20) SPACEBAR +const int GK_SPACE = 0x20; - // GK_PRIOR (21) PAGE UP key - const int GK_PRIOR = 0x21; +// GK_PRIOR (21) PAGE UP key +const int GK_PRIOR = 0x21; - // GK_NEXT (22) PAGE DOWN key - const int GK_NEXT = 0x22; +// GK_NEXT (22) PAGE DOWN key +const int GK_NEXT = 0x22; - // GK_END (23) END key - const int GK_END = 0x23; +// GK_END (23) END key +const int GK_END = 0x23; - // GK_HOME (24) HOME key - const int GK_HOME = 0x24; +// GK_HOME (24) HOME key +const int GK_HOME = 0x24; - // GK_LEFT (25) LEFT ARROW key - const int GK_LEFT = 0x25; +// GK_LEFT (25) LEFT ARROW key +const int GK_LEFT = 0x25; - // GK_UP (26) UP ARROW key - const int GK_UP = 0x26; +// GK_UP (26) UP ARROW key +const int GK_UP = 0x26; - // GK_RIGHT (27) RIGHT ARROW key - const int GK_RIGHT = 0x27; +// GK_RIGHT (27) RIGHT ARROW key +const int GK_RIGHT = 0x27; - // GK_DOWN (28) DOWN ARROW key - const int GK_DOWN = 0x28; +// GK_DOWN (28) DOWN ARROW key +const int GK_DOWN = 0x28; - // GK_SELECT (29) SELECT key - const int GK_SELECT = 0x29; +// GK_SELECT (29) SELECT key +const int GK_SELECT = 0x29; - // GK_PRINT (2A) PRINT key - const int GK_PRINT = 0x2A; +// GK_PRINT (2A) PRINT key +const int GK_PRINT = 0x2A; - // GK_EXECUTE (2B) EXECUTE key - const int GK_EXECUTE = 0x2B; +// GK_EXECUTE (2B) EXECUTE key +const int GK_EXECUTE = 0x2B; - // GK_SNAPSHOT (2C) PRINT SCREEN key - const int GK_SNAPSHOT = 0x2C; +// GK_SNAPSHOT (2C) PRINT SCREEN key +const int GK_SNAPSHOT = 0x2C; - // GK_INSERT (2D) INS key - const int GK_INSERT = 0x2D; +// GK_INSERT (2D) INS key +const int GK_INSERT = 0x2D; - // GK_DELETE (2E) DEL key - const int GK_DELETE = 0x2E; +// GK_DELETE (2E) DEL key +const int GK_DELETE = 0x2E; - // GK_HELP (2F) HELP key - const int GK_HELP = 0x2F; +// GK_HELP (2F) HELP key +const int GK_HELP = 0x2F; - // (30) 0 key - const int GK_0 = 0x30; +// (30) 0 key +const int GK_0 = 0x30; - // (31) 1 key - const int GK_1 = 0x31; +// (31) 1 key +const int GK_1 = 0x31; - // (32) 2 key - const int GK_2 = 0x32; +// (32) 2 key +const int GK_2 = 0x32; - // (33) 3 key - const int GK_3 = 0x33; +// (33) 3 key +const int GK_3 = 0x33; - // (34) 4 key - const int GK_4 = 0x34; +// (34) 4 key +const int GK_4 = 0x34; - // (35) 5 key; - const int GK_5 = 0x35; +// (35) 5 key; +const int GK_5 = 0x35; - // (36) 6 key - const int GK_6 = 0x36; +// (36) 6 key +const int GK_6 = 0x36; - // (37) 7 key - const int GK_7 = 0x37; +// (37) 7 key +const int GK_7 = 0x37; - // (38) 8 key - const int GK_8 = 0x38; +// (38) 8 key +const int GK_8 = 0x38; - // (39) 9 key - const int GK_9 = 0x39; +// (39) 9 key +const int GK_9 = 0x39; - // (41) A key - const int GK_A = 0x41; +// (41) A key +const int GK_A = 0x41; - // (42) B key - const int GK_B = 0x42; +// (42) B key +const int GK_B = 0x42; - // (43) C key - const int GK_C = 0x43; +// (43) C key +const int GK_C = 0x43; - // (44) D key - const int GK_D = 0x44; +// (44) D key +const int GK_D = 0x44; - // (45) E key - const int GK_E = 0x45; +// (45) E key +const int GK_E = 0x45; - // (46) F key - const int GK_F = 0x46; +// (46) F key +const int GK_F = 0x46; - // (47) G key - const int GK_G = 0x47; +// (47) G key +const int GK_G = 0x47; - // (48) H key - const int GK_H = 0x48; +// (48) H key +const int GK_H = 0x48; - // (49) I key - const int GK_I = 0x49; +// (49) I key +const int GK_I = 0x49; - // (4A) J key - const int GK_J = 0x4A; +// (4A) J key +const int GK_J = 0x4A; - // (4B) K key - const int GK_K = 0x4B; +// (4B) K key +const int GK_K = 0x4B; - // (4C) L key - const int GK_L = 0x4C; +// (4C) L key +const int GK_L = 0x4C; - // (4D) M key - const int GK_M = 0x4D; +// (4D) M key +const int GK_M = 0x4D; - // (4E) N key - const int GK_N = 0x4E; +// (4E) N key +const int GK_N = 0x4E; - // (4F) O key - const int GK_O = 0x4F; +// (4F) O key +const int GK_O = 0x4F; - // (50) P key - const int GK_P = 0x50; +// (50) P key +const int GK_P = 0x50; - // (51) Q key - const int GK_Q = 0x51; +// (51) Q key +const int GK_Q = 0x51; - // (52) R key - const int GK_R = 0x52; +// (52) R key +const int GK_R = 0x52; - // (53) S key - const int GK_S = 0x53; +// (53) S key +const int GK_S = 0x53; - // (54) T key - const int GK_T = 0x54; +// (54) T key +const int GK_T = 0x54; - // (55) U key - const int GK_U = 0x55; +// (55) U key +const int GK_U = 0x55; - // (56) V key - const int GK_V = 0x56; +// (56) V key +const int GK_V = 0x56; - // (57) W key - const int GK_W = 0x57; +// (57) W key +const int GK_W = 0x57; - // (58) X key - const int GK_X = 0x58; +// (58) X key +const int GK_X = 0x58; - // (59) Y key - const int GK_Y = 0x59; +// (59) Y key +const int GK_Y = 0x59; - // (5A) Z key - const int GK_Z = 0x5A; +// (5A) Z key +const int GK_Z = 0x5A; - // GK_LWIN (5B) Left Windows key (Microsoft Natural keyboard) - const int GK_LWIN = 0x5B; +// GK_LWIN (5B) Left Windows key (Microsoft Natural keyboard) +const int GK_LWIN = 0x5B; - // GK_RWIN (5C) Right Windows key (Natural keyboard) - const int GK_RWIN = 0x5C; +// GK_RWIN (5C) Right Windows key (Natural keyboard) +const int GK_RWIN = 0x5C; - // GK_APPS (5D) Applications key (Natural keyboard) - const int GK_APPS = 0x5D; +// GK_APPS (5D) Applications key (Natural keyboard) +const int GK_APPS = 0x5D; - // GK_SLEEP (5F) Computer Sleep key - const int GK_SLEEP = 0x5F; +// GK_SLEEP (5F) Computer Sleep key +const int GK_SLEEP = 0x5F; - // GK_NUMPAD0 (60) Numeric keypad 0 key - const int GK_NUMPAD0 = 0x60; +// GK_NUMPAD0 (60) Numeric keypad 0 key +const int GK_NUMPAD0 = 0x60; - // GK_NUMPAD1 (61) Numeric keypad 1 key - const int GK_NUMPAD1 = 0x61; +// GK_NUMPAD1 (61) Numeric keypad 1 key +const int GK_NUMPAD1 = 0x61; - // GK_NUMPAD2 (62) Numeric keypad 2 key - const int GK_NUMPAD2 = 0x62; +// GK_NUMPAD2 (62) Numeric keypad 2 key +const int GK_NUMPAD2 = 0x62; - // GK_NUMPAD3 (63) Numeric keypad 3 key - const int GK_NUMPAD3 = 0x63; +// GK_NUMPAD3 (63) Numeric keypad 3 key +const int GK_NUMPAD3 = 0x63; - // GK_NUMPAD4 (64) Numeric keypad 4 key - const int GK_NUMPAD4 = 0x64; +// GK_NUMPAD4 (64) Numeric keypad 4 key +const int GK_NUMPAD4 = 0x64; - // GK_NUMPAD5 (65) Numeric keypad 5 key - const int GK_NUMPAD5 = 0x65; +// GK_NUMPAD5 (65) Numeric keypad 5 key +const int GK_NUMPAD5 = 0x65; - // GK_NUMPAD6 (66) Numeric keypad 6 key - const int GK_NUMPAD6 = 0x66; +// GK_NUMPAD6 (66) Numeric keypad 6 key +const int GK_NUMPAD6 = 0x66; - // GK_NUMPAD7 (67) Numeric keypad 7 key - const int GK_NUMPAD7 = 0x67; +// GK_NUMPAD7 (67) Numeric keypad 7 key +const int GK_NUMPAD7 = 0x67; - // GK_NUMPAD8 (68) Numeric keypad 8 key - const int GK_NUMPAD8 = 0x68; +// GK_NUMPAD8 (68) Numeric keypad 8 key +const int GK_NUMPAD8 = 0x68; - // GK_NUMPAD9 (69) Numeric keypad 9 key - const int GK_NUMPAD9 = 0x69; +// GK_NUMPAD9 (69) Numeric keypad 9 key +const int GK_NUMPAD9 = 0x69; - // GK_MULTIPLY (6A) Multiply key - const int GK_MULTIPLY = 0x6A; +// GK_MULTIPLY (6A) Multiply key +const int GK_MULTIPLY = 0x6A; - // GK_ADD (6B) Add key - const int GK_ADD = 0x6B; +// GK_ADD (6B) Add key +const int GK_ADD = 0x6B; - // GK_SEPARATOR (6C) Separator key - const int GK_SEPARATOR = 0x6C; +// GK_SEPARATOR (6C) Separator key +const int GK_SEPARATOR = 0x6C; - // GK_SUBTRACT (6D) Subtract key - const int GK_SUBTRACT = 0x6D; +// GK_SUBTRACT (6D) Subtract key +const int GK_SUBTRACT = 0x6D; - // GK_DECIMAL (6E) Decimal key - const int GK_DECIMAL = 0x6E; +// GK_DECIMAL (6E) Decimal key +const int GK_DECIMAL = 0x6E; - // GK_DIVIDE (6F) Divide key - const int GK_DIVIDE = 0x6F; +// GK_DIVIDE (6F) Divide key +const int GK_DIVIDE = 0x6F; - // GK_F1 (70) F1 key - const int GK_F1 = 0x70; +// GK_F1 (70) F1 key +const int GK_F1 = 0x70; - // GK_F2 (71) F2 key - const int GK_F2 = 0x71; +// GK_F2 (71) F2 key +const int GK_F2 = 0x71; - // GK_F3 (72) F3 key - const int GK_F3 = 0x72; +// GK_F3 (72) F3 key +const int GK_F3 = 0x72; - // GK_F4 (73) F4 key - const int GK_F4 = 0x73; +// GK_F4 (73) F4 key +const int GK_F4 = 0x73; - // GK_F5 (74) F5 key - const int GK_F5 = 0x74; +// GK_F5 (74) F5 key +const int GK_F5 = 0x74; - // GK_F6 (75) F6 key - const int GK_F6 = 0x75; +// GK_F6 (75) F6 key +const int GK_F6 = 0x75; - // GK_F7 (76) F7 key - const int GK_F7 = 0x76; +// GK_F7 (76) F7 key +const int GK_F7 = 0x76; - // GK_F8 (77) F8 key - const int GK_F8 = 0x77; +// GK_F8 (77) F8 key +const int GK_F8 = 0x77; - // GK_F9 (78) F9 key - const int GK_F9 = 0x78; +// GK_F9 (78) F9 key +const int GK_F9 = 0x78; - // GK_F10 (79) F10 key - const int GK_F10 = 0x79; +// GK_F10 (79) F10 key +const int GK_F10 = 0x79; - // GK_F11 (7A) F11 key - const int GK_F11 = 0x7A; +// GK_F11 (7A) F11 key +const int GK_F11 = 0x7A; - // GK_F12 (7B) F12 key - const int GK_F12 = 0x7B; +// GK_F12 (7B) F12 key +const int GK_F12 = 0x7B; - // GK_F13 (7C) F13 key - const int GK_F13 = 0x7C; +// GK_F13 (7C) F13 key +const int GK_F13 = 0x7C; - // GK_F14 (7D) F14 key - const int GK_F14 = 0x7D; +// GK_F14 (7D) F14 key +const int GK_F14 = 0x7D; - // GK_F15 (7E) F15 key - const int GK_F15 = 0x7E; +// GK_F15 (7E) F15 key +const int GK_F15 = 0x7E; - // GK_F16 (7F) F16 key - const int GK_F16 = 0x7F; +// GK_F16 (7F) F16 key +const int GK_F16 = 0x7F; - // GK_F17 (80H) F17 key - const int GK_F17 = 0x80; +// GK_F17 (80H) F17 key +const int GK_F17 = 0x80; - // GK_F18 (81H) F18 key - const int GK_F18 = 0x81; +// GK_F18 (81H) F18 key +const int GK_F18 = 0x81; - // GK_F19 (82H) F19 key - const int GK_F19 = 0x82; +// GK_F19 (82H) F19 key +const int GK_F19 = 0x82; - // GK_F20 (83H) F20 key - const int GK_F20 = 0x83; +// GK_F20 (83H) F20 key +const int GK_F20 = 0x83; - // GK_F21 (84H) F21 key - const int GK_F21 = 0x84; +// GK_F21 (84H) F21 key +const int GK_F21 = 0x84; - // GK_F22 (85H) F22 key - const int GK_F22 = 0x85; +// GK_F22 (85H) F22 key +const int GK_F22 = 0x85; - // GK_F23 (86H) F23 key - const int GK_F23 = 0x86; +// GK_F23 (86H) F23 key +const int GK_F23 = 0x86; - // GK_F24 (87H) F24 key - const int GK_F24 = 0x87; +// GK_F24 (87H) F24 key +const int GK_F24 = 0x87; - // GK_NUMLOCK (90) NUM LOCK key - const int GK_NUMLOCK = 0x90; +// GK_NUMLOCK (90) NUM LOCK key +const int GK_NUMLOCK = 0x90; - // GK_SCROLL (91) SCROLL LOCK key - const int GK_SCROLL = 0x91; +// GK_SCROLL (91) SCROLL LOCK key +const int GK_SCROLL = 0x91; - // GK_LSHIFT (A0) Left SHIFT key - const int GK_LSHIFT = 0xA0; +// GK_LSHIFT (A0) Left SHIFT key +const int GK_LSHIFT = 0xA0; - // GK_RSHIFT (A1) Right SHIFT key - const int GK_RSHIFT = 0xA1; +// GK_RSHIFT (A1) Right SHIFT key +const int GK_RSHIFT = 0xA1; - // GK_LCONTROL (A2) Left CONTROL key - const int GK_LCONTROL = 0xA2; +// GK_LCONTROL (A2) Left CONTROL key +const int GK_LCONTROL = 0xA2; - // GK_RCONTROL (A3) Right CONTROL key - const int GK_RCONTROL = 0xA3; +// GK_RCONTROL (A3) Right CONTROL key +const int GK_RCONTROL = 0xA3; - // GK_LMENU (A4) Left MENU key - const int GK_LMENU = 0xA4; +// GK_LMENU (A4) Left MENU key +const int GK_LMENU = 0xA4; - // GK_RMENU (A5) Right MENU key - const int GK_RMENU = 0xA5; +// GK_RMENU (A5) Right MENU key +const int GK_RMENU = 0xA5; - // GK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key - const int GK_BROWSER_BACK = 0xA6; +// GK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key +const int GK_BROWSER_BACK = 0xA6; - // GK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key - const int GK_BROWSER_FORWARD = 0xA7; +// GK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key +const int GK_BROWSER_FORWARD = 0xA7; - // GK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key - const int GK_BROWSER_REFRESH = 0xA8; +// GK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key +const int GK_BROWSER_REFRESH = 0xA8; - // GK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key - const int GK_BROWSER_STOP = 0xA9; +// GK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key +const int GK_BROWSER_STOP = 0xA9; - // GK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key - const int GK_BROWSER_SEARCH = 0xAA; +// GK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key +const int GK_BROWSER_SEARCH = 0xAA; - // GK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key - const int GK_BROWSER_FAVORITES = 0xAB; +// GK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key +const int GK_BROWSER_FAVORITES = 0xAB; - // GK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key - const int GK_BROWSER_HOME = 0xAC; +// GK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key +const int GK_BROWSER_HOME = 0xAC; - // GK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key - const int GK_VOLUME_MUTE = 0xAD; +// GK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key +const int GK_VOLUME_MUTE = 0xAD; - // GK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key - const int GK_VOLUME_DOWN = 0xAE; +// GK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key +const int GK_VOLUME_DOWN = 0xAE; - // GK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key - const int GK_VOLUME_UP = 0xAF; +// GK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key +const int GK_VOLUME_UP = 0xAF; - // GK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key - const int GK_MEDIA_NEXT_TRACK = 0xB0; +// GK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key +const int GK_MEDIA_NEXT_TRACK = 0xB0; - // GK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key - const int GK_MEDIA_PREV_TRACK = 0xB1; +// GK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key +const int GK_MEDIA_PREV_TRACK = 0xB1; - // GK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key - const int GK_MEDIA_STOP = 0xB2; +// GK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key +const int GK_MEDIA_STOP = 0xB2; - // GK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key - const int GK_MEDIA_PLAY_PAUSE = 0xB3; +// GK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key +const int GK_MEDIA_PLAY_PAUSE = 0xB3; - // GK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key - const int GK_MEDIA_LAUNCH_MAIL = 0xB4; +// GK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key +const int GK_MEDIA_LAUNCH_MAIL = 0xB4; - // GK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key - const int GK_MEDIA_LAUNCH_MEDIA_SELECT = 0xB5; +// GK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key +const int GK_MEDIA_LAUNCH_MEDIA_SELECT = 0xB5; - // GK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key - const int GK_MEDIA_LAUNCH_APP1 = 0xB6; +// GK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key +const int GK_MEDIA_LAUNCH_APP1 = 0xB6; - // GK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key - const int GK_MEDIA_LAUNCH_APP2 = 0xB7; +// GK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key +const int GK_MEDIA_LAUNCH_APP2 = 0xB7; - // GK_OEM_1 (BA) ';:' for US - const int GK_OEM_1 = 0xBA; +// GK_OEM_1 (BA) ';:' for US +const int GK_OEM_1 = 0xBA; - // GK_OEM_PLUS (BB) '=+' any country - const int GK_OEM_PLUS = 0xBB; +// GK_OEM_PLUS (BB) '=+' any country +const int GK_OEM_PLUS = 0xBB; - // GK_OEM_COMMA (BC) ',<' any country - const int GK_OEM_COMMA = 0xBC; +// GK_OEM_COMMA (BC) ',<' any country +const int GK_OEM_COMMA = 0xBC; - // GK_OEM_MINUS (BD) '-_' any country - const int GK_OEM_MINUS = 0xBD; +// GK_OEM_MINUS (BD) '-_' any country +const int GK_OEM_MINUS = 0xBD; - // GK_OEM_PERIOD (BE) '.>' any country - const int GK_OEM_PERIOD = 0xBE; +// GK_OEM_PERIOD (BE) '.>' any country +const int GK_OEM_PERIOD = 0xBE; - // GK_OEM_2 (BF) '/?' for US - const int GK_OEM_2 = 0xBF; +// GK_OEM_2 (BF) '/?' for US +const int GK_OEM_2 = 0xBF; - // GK_OEM_3 (C0) '`~' for US - const int GK_OEM_3 = 0xC0; +// GK_OEM_3 (C0) '`~' for US +const int GK_OEM_3 = 0xC0; - // GK_OEM_4 (DB) '[{' for US - const int GK_OEM_4 = 0xDB; +// GK_OEM_4 (DB) '[{' for US +const int GK_OEM_4 = 0xDB; - // GK_OEM_5 (DC) '\|' for US - const int GK_OEM_5 = 0xDC; +// GK_OEM_5 (DC) '\|' for US +const int GK_OEM_5 = 0xDC; - // GK_OEM_6 (DD) ']}' for US - const int GK_OEM_6 = 0xDD; +// GK_OEM_6 (DD) ']}' for US +const int GK_OEM_6 = 0xDD; - // GK_OEM_7 (DE) ''"' for US - const int GK_OEM_7 = 0xDE; +// GK_OEM_7 (DE) ''"' for US +const int GK_OEM_7 = 0xDE; - // GK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard. - const int GK_OEM_8 = 0xDF; +// GK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard. +const int GK_OEM_8 = 0xDF; - // GK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard - const int GK_OEM_102 = 0xE2; +// GK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT +// 102-key keyboard +const int GK_OEM_102 = 0xE2; - // GK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key - const int GK_PROCESSKEY = 0xE5; +// GK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key +const int GK_PROCESSKEY = 0xE5; - // GK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The GK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP - const int GK_PACKET = 0xE7; +// GK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The +// GK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. +// For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP +const int GK_PACKET = 0xE7; - const int GK_OEM_ATTN = 0xF0; +const int GK_OEM_ATTN = 0xF0; - // GK_ATTN (F6) Attn key - const int GK_ATTN = 0xF6; +// GK_ATTN (F6) Attn key +const int GK_ATTN = 0xF6; - // GK_CRSEL (F7) CrSel key - const int GK_CRSEL = 0xF7; +// GK_CRSEL (F7) CrSel key +const int GK_CRSEL = 0xF7; - // GK_EXSEL (F8) ExSel key - const int GK_EXSEL = 0xF8; +// GK_EXSEL (F8) ExSel key +const int GK_EXSEL = 0xF8; - // GK_EREOF (F9) Erase EOF key - const int GK_EREOF = 0xF9; +// GK_EREOF (F9) Erase EOF key +const int GK_EREOF = 0xF9; - // GK_PLAY (FA) Play key - const int GK_PLAY = 0xFA; +// GK_PLAY (FA) Play key +const int GK_PLAY = 0xFA; - // GK_ZOOM (FB) Zoom key - const int GK_ZOOM = 0xFB; +// GK_ZOOM (FB) Zoom key +const int GK_ZOOM = 0xFB; - // GK_NONAME (FC) Reserved for future use - const int GK_NONAME = 0xFC; +// GK_NONAME (FC) Reserved for future use +const int GK_NONAME = 0xFC; - // GK_PA1 (FD) PA1 key - const int GK_PA1 = 0xFD; +// GK_PA1 (FD) PA1 key +const int GK_PA1 = 0xFD; - // GK_OEM_CLEAR (FE) Clear key - const int GK_OEM_CLEAR = 0xFE; +// GK_OEM_CLEAR (FE) Clear key +const int GK_OEM_CLEAR = 0xFE; - const int GK_UNKNOWN = 0; +const int GK_UNKNOWN = 0; } // namespace KeyCodes diff --git a/Ultralight/KeyEvent.h b/Ultralight/KeyEvent.h index dcc2e53..be74f56 100644 --- a/Ultralight/KeyEvent.h +++ b/Ultralight/KeyEvent.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2020 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include @@ -22,13 +22,12 @@ namespace ultralight { /// -/// @brief A generic keyboard event that can be created from a platform event -/// or synthesized from scratch. +/// @brief A generic keyboard event, created from a platform event or synthesized from scratch. /// /// @see View::FireKeyEvent /// class UExport KeyEvent { -public: + public: /// /// The various KeyEvent types. /// @@ -36,9 +35,8 @@ class UExport KeyEvent { /// /// Key-Down event type. (Does not trigger accelerator commands in WebCore) /// - /// @NOTE: You should probably use RawKeyDown instead when a physical key - /// is pressed. This member is only here for historic compatibility - /// with WebCore's key event types. + /// @NOTE: You should probably use RawKeyDown instead when a physical key is pressed. + /// This type is only here for historic compatibility with WebCore's key event types. /// kType_KeyDown, @@ -50,14 +48,14 @@ class UExport KeyEvent { /// /// Raw Key-Down type. Use this when a physical key is pressed. /// - /// @NOTE: You should use RawKeyDown for physical key presses since it - /// allows WebCore to do additional command translation. + /// @NOTE: You should use RawKeyDown for physical key presses since it allows the renderer to + /// handle accelerator command translation. /// kType_RawKeyDown, /// - /// Character input event type. Use this when the OS generates text from - /// a physical key being pressed (eg, WM_CHAR on Windows). + /// Character input event type. Use this when the OS generates text from a physical key being + /// pressed (for example, this maps to WM_CHAR on Windows). /// kType_Char, }; @@ -105,44 +103,41 @@ class UExport KeyEvent { Type type; /// - /// The current state of the keyboard. Modifiers may be OR'd together to - /// represent multiple values. + /// The current state of the keyboard. Modifiers may be OR'd together to represent multiple + /// values. /// unsigned modifiers; /// - // The virtual key-code associated with this keyboard event. This is either - // directly from the event (ie, WPARAM on Windows) or via a mapping function. - // You can see a full list of the possible virtual key-codes in - // KeyCodes.h + /// The virtual key-code associated with this keyboard event. This is either directly from the + /// event (ie, WPARAM on Windows) or via a mapping function. You can see a full list of the + /// possible virtual key-codes in KeyCodes.h /// int virtual_key_code; /// - /// The actual key-code generated by the platform. The DOM spec primarily - /// uses Windows-equivalent codes (hence virtualKeyCode above) but it helps to - /// also specify the platform-specific key-code as well. + /// The actual key-code generated by the platform. The DOM spec primarily uses Windows-equivalent + /// codes (hence virtualKeyCode above) but it helps to also specify the platform-specific + /// key-code as well. /// int native_key_code; /// - /// This is a string identifying the key that was pressed. This can be - /// generated from the virtual_key_code via the GetKeyIdentifierFromVirtualKeyCode() - /// utility function. You can find the full list of key identifiers at: + /// This is a string identifying the key that was pressed. This can be generated from the + /// virtual_key_code via the GetKeyIdentifierFromVirtualKeyCode() utility function. You can find + /// the full list of key identifiers at: /// /// String key_identifier; /// - /// The actual text generated by this keyboard event. This is usually only a - /// single character. + /// The actual text generated by this keyboard event. This is usually only a single character. /// String text; /// - /// The text generated by this keyboard event before all modifiers except - /// shift are applied. This is used internally for working out shortcut keys. - /// This is usually only a single character. + /// The text generated by this keyboard event before all modifiers except shift are applied. This + /// is used internally for working out shortcut keys. This is usually only a single character. /// String unmodified_text; @@ -152,15 +147,13 @@ class UExport KeyEvent { bool is_keypad; /// - /// Whether or not this was generated as the result of an auto-repeat - /// (eg, holding down a key). + /// Whether or not this was generated as the result of an auto-repeat (eg, holding down a key). /// bool is_auto_repeat; /// - /// Whether or not the pressed key is a "system key". This is a Windows-only - /// concept and should be "false" for all non-Windows platforms. For more - /// information, see the following link: + /// Whether or not the pressed key is a "system key". This is a Windows-only concept and should + /// be "false" for all non-Windows platforms. For more information, see the following link: /// bool is_system_key; }; @@ -169,28 +162,26 @@ class UExport KeyEvent { /// Utility function for generating a key identifier string from a virtual /// key-code. /// -/// @param virtual_key_code The virtual key-code to generate the key -/// identifier from. +/// @param virtual_key_code The virtual key-code to generate the key identifier from. /// /// @param key_identifier_result The string to store the result in. /// void UExport GetKeyIdentifierFromVirtualKeyCode(int virtual_key_code, - String& key_identifier_result); + String& key_identifier_result); /// /// Utility function for generating a key string from a virtual key-code. /// -/// @param virtual_key_code The virtual key-code to generate the key -/// string from. -/// +/// @param virtual_key_code The virtual key-code to generate the key string from. +/// /// @param shift Whether or not the shift key is currently pressed. /// /// @param key_result The string to store the result in. -/// +/// /// @note This function assumes US keyboard layout. -/// +/// /// @see /// void UExport GetKeyFromVirtualKeyCode(int virtual_key_code, bool shift, String& key_result); -} // namespace ultralight +} // namespace ultralight diff --git a/Ultralight/Listener.h b/Ultralight/Listener.h index f6b0300..ae55dc3 100644 --- a/Ultralight/Listener.h +++ b/Ultralight/Listener.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2020 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include @@ -105,43 +105,35 @@ enum Cursor { /// @note For more info @see View::set_view_listener /// class UExport ViewListener { -public: - virtual ~ViewListener() {} + public: + virtual ~ViewListener() { } /// /// Called when the page title changes /// - virtual void OnChangeTitle(ultralight::View* caller, - const String& title) {} + virtual void OnChangeTitle(ultralight::View* caller, const String& title) { } /// /// Called when the page URL changes /// - virtual void OnChangeURL(ultralight::View* caller, - const String& url) {} + virtual void OnChangeURL(ultralight::View* caller, const String& url) { } /// /// Called when the tooltip changes (usually as result of a mouse hover) /// - virtual void OnChangeTooltip(ultralight::View* caller, - const String& tooltip) {} + virtual void OnChangeTooltip(ultralight::View* caller, const String& tooltip) { } /// /// Called when the mouse cursor changes /// - virtual void OnChangeCursor(ultralight::View* caller, - Cursor cursor) {} + virtual void OnChangeCursor(ultralight::View* caller, Cursor cursor) { } /// /// Called when a message is added to the console (useful for errors / debug) /// - virtual void OnAddConsoleMessage(ultralight::View* caller, - MessageSource source, - MessageLevel level, - const String& message, - uint32_t line_number, - uint32_t column_number, - const String& source_id) {} + virtual void OnAddConsoleMessage(ultralight::View* caller, MessageSource source, + MessageLevel level, const String& message, uint32_t line_number, + uint32_t column_number, const String& source_id) { } /// /// Called when the page wants to create a new View. @@ -149,9 +141,9 @@ class UExport ViewListener { /// This is usually the result of a user clicking a link with target="_blank" /// or by JavaScript calling window.open(url). /// - /// To allow creation of these new Views, you should create a new View in - /// this callback (eg, Renderer::CreateView()), resize it to your container, - /// and return it. You are responsible for displaying the returned View. + /// To allow creation of these new Views, you should create a new View in this callback (eg, + /// Renderer::CreateView()), resize it to your container, and return it. You are responsible for + /// displaying the returned View. /// /// @param caller The View that called this event. /// @@ -161,19 +153,22 @@ class UExport ViewListener { /// /// @param is_popup Whether or not this was triggered by window.open(). /// - /// @param popup_rect Popups can optionally request certain dimensions and - /// coordinates via window.open(). You can choose to - /// respect these or not by resizing/moving the View to - /// this rect. + /// @param popup_rect Popups can optionally request certain dimensions and coordinates via + /// window.open(). You can choose to respect these or not by resizing/moving + /// the View to this rect. /// - /// @return Returns a RefPtr<> to a created View to use to satisfy the - /// the request (or return nullptr if you want to block the action). + /// @return Returns a RefPtr<> to a created View to use to satisfy the the request (or return + /// nullptr if you want to block the action). /// - virtual RefPtr OnCreateChildView(ultralight::View* caller, - const String& opener_url, - const String& target_url, - bool is_popup, + virtual RefPtr OnCreateChildView(ultralight::View* caller, const String& opener_url, + const String& target_url, bool is_popup, const IntRect& popup_rect); + + virtual RefPtr OnCreateInspectorView(ultralight::View* caller, bool is_local, + const String& inspected_url); + + virtual void OnRequestClose(ultralight::View* caller) { } + }; /// @@ -182,8 +177,8 @@ class UExport ViewListener { /// @note For more info @see View::set_load_listener /// class UExport LoadListener { -public: - virtual ~LoadListener() {} + public: + virtual ~LoadListener() { } /// /// Called when the page begins loading a new URL into a frame. @@ -194,10 +189,8 @@ class UExport LoadListener { /// /// @param url The URL for the load. /// - virtual void OnBeginLoading(ultralight::View* caller, - uint64_t frame_id, - bool is_main_frame, - const String& url) {} + virtual void OnBeginLoading(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, + const String& url) { } /// /// Called when the page finishes loading a URL into a frame. @@ -208,10 +201,8 @@ class UExport LoadListener { /// /// @param url The URL for the load. /// - virtual void OnFinishLoading(ultralight::View* caller, - uint64_t frame_id, - bool is_main_frame, - const String& url) {} + virtual void OnFinishLoading(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, + const String& url) { } /// /// Called when an error occurs while loading a URL into a frame. @@ -228,26 +219,21 @@ class UExport LoadListener { /// /// @param error_code Internal error code generated by the module. /// - virtual void OnFailLoading(ultralight::View* caller, - uint64_t frame_id, - bool is_main_frame, - const String& url, - const String& description, - const String& error_domain, - int error_code) {} + virtual void OnFailLoading(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, + const String& url, const String& description, + const String& error_domain, int error_code) { } /// /// Called when the JavaScript window object is reset for a new page load. /// - /// This is called before any scripts are executed on the page and is the - /// earliest time to setup any initial JavaScript state or bindings. + /// This is called before any scripts are executed on the page and is the earliest time to setup + /// any initial JavaScript state or bindings. /// - /// The document is not guaranteed to be loaded/parsed at this point. If - /// you need to make any JavaScript calls that are dependent on DOM elements - /// or scripts on the page, use OnDOMReady instead. + /// The document is not guaranteed to be loaded/parsed at this point. If you need to make any + /// JavaScript calls that are dependent on DOM elements or scripts on the page, use OnDOMReady + /// instead. /// - /// The window object is lazily initialized (this will not be called on pages - /// with no scripts). + /// The window object is lazily initialized (this will not be called on pages with no scripts). /// /// @param frame_id A unique ID for the frame. /// @@ -255,16 +241,14 @@ class UExport LoadListener { /// /// @param url The URL for the load. /// - virtual void OnWindowObjectReady(ultralight::View* caller, - uint64_t frame_id, - bool is_main_frame, - const String& url) {} + virtual void OnWindowObjectReady(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, + const String& url) { } /// /// Called when all JavaScript has been parsed and the document is ready. /// - /// This is the best time to make any JavaScript calls that are dependent on - /// DOM elements or scripts on the page. + /// This is the best time to make any JavaScript calls that are dependent on DOM elements or + /// scripts on the page. /// /// @param frame_id A unique ID for the frame. /// @@ -272,16 +256,13 @@ class UExport LoadListener { /// /// @param url The URL for the load. /// - virtual void OnDOMReady(ultralight::View* caller, - uint64_t frame_id, - bool is_main_frame, - const String& url) {} + virtual void OnDOMReady(ultralight::View* caller, uint64_t frame_id, bool is_main_frame, + const String& url) { } /// /// Called when the session history (back/forward state) is modified. /// - virtual void OnUpdateHistory(ultralight::View* caller) {} - + virtual void OnUpdateHistory(ultralight::View* caller) { } }; -} // namespace ultralight +} // namespace ultralight diff --git a/Ultralight/Matrix.h b/Ultralight/Matrix.h index 78f4435..041d13a 100644 --- a/Ultralight/Matrix.h +++ b/Ultralight/Matrix.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2021 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include @@ -36,16 +36,8 @@ struct UExport Matrix4x4 { /// /// Transformation Matrix helper /// -struct UExport Matrix { -#if defined(__x86_64__) || defined(_M_X64) -#if defined(_MSC_VER) - __declspec(align(16)) typedef double Aligned4x4[4][4]; -#else - typedef double Aligned4x4[4][4] __attribute__((aligned(16))); -#endif -#else +struct UExport alignas(16) Matrix { typedef double Aligned4x4[4][4]; -#endif Aligned4x4 data; diff --git a/Ultralight/MouseEvent.h b/Ultralight/MouseEvent.h index 8c2e727..66844ae 100644 --- a/Ultralight/MouseEvent.h +++ b/Ultralight/MouseEvent.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2020 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include @@ -27,19 +27,19 @@ class MouseEvent { /// The various MouseEvent types. /// enum Type { - /// + /// /// Mouse moved type - /// + /// kType_MouseMoved, - /// + /// /// Mouse button pressed type - /// + /// kType_MouseDown, - /// + /// /// Mouse button released type - /// + /// kType_MouseUp, }; diff --git a/Ultralight/RefPtr.h b/Ultralight/RefPtr.h index 918681a..46a73ab 100644 --- a/Ultralight/RefPtr.h +++ b/Ultralight/RefPtr.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2021 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// /* * Portions of the below code are derived from 'RefPtr.h' from Apple's WTF, diff --git a/Ultralight/RenderTarget.h b/Ultralight/RenderTarget.h index 73606d2..55b8265 100644 --- a/Ultralight/RenderTarget.h +++ b/Ultralight/RenderTarget.h @@ -9,7 +9,7 @@ /// /// Website: /// -/// Copyright (C) 2021 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include diff --git a/Ultralight/Renderer.h b/Ultralight/Renderer.h index f796018..5ba3d1a 100644 --- a/Ultralight/Renderer.h +++ b/Ultralight/Renderer.h @@ -9,39 +9,39 @@ /// /// Website: /// -/// Copyright (C) 2021 Ultralight, Inc. All rights reserved. +/// Copyright (C) 2022 Ultralight, Inc. All rights reserved. /// #pragma once #include #include #include #include +#include namespace ultralight { /// -/// @brief This singleton manages the lifetime of all Views (@see View) and -/// coordinates painting, network requests, and event dispatch. +/// @brief This singleton manages the lifetime of all Views (@see View) and coordinates +/// painting, network requests, and event dispatch. /// -/// @note You don't have to create this instance directly if you use the -/// AppCore API. The App class will automatically create a Renderer and -/// perform all rendering within its run loop. @see App::Create +/// @note You don't have to create this instance directly if you use the AppCore API. The App +/// class will automatically create a Renderer and perform all rendering within its run +/// loop. @see App::Create /// class UExport Renderer : public RefCounted { -public: + public: /// /// Create the Ultralight Renderer directly. /// - /// Unlike App::Create(), this does not use any native windows for drawing - /// and allows you to manage your own runloop and painting. This method is - /// recommended for those wishing to integrate the library into a game. + /// Unlike App::Create(), this does not use any native windows for drawing and allows you to + /// manage your own runloop and painting. This method is recommended for those wishing to + /// integrate the library into a game. /// - /// You should set up your Platform config, file-system, font loader, - /// and surface-factories/gpu-drivers before calling this function. - /// (@see ) + /// You should set up your Platform config, file-system, font loader, surface-factories, and + /// gpu-drivers before calling this function. (@see ) /// - /// At a minimum, you will need to define a FontLoader ahead of time or this - /// call will fail. You can use the platform's native FontLoader by calling: + /// At a minimum, you will need to define a FontLoader ahead of time or this call will fail. You + /// can use the platform's native FontLoader by calling: ///
   ///   /// This function is defined in 
   ///   Platform::instance().set_font_loader(GetPlatformFontLoader());
@@ -49,13 +49,11 @@ class UExport Renderer : public RefCounted {
   ///
   /// @note  You should only create one Renderer per application lifetime.
   ///
-  /// @note: You should not call this if you are using App::Create(), it
-  ///        creates its own renderer and provides default implementations for
-  ///        various platform handlers automatically.
+  /// @note: You should not call this if you are using App::Create(), it creates its own renderer
+  ///        and provides default implementations for various platform handlers automatically.
   ///
-  /// @return  Renderer is ref-counted. This method returns a ref-pointer
-  ///          to a new instance, you should store it in a RefPtr<> to keep
-  ///          the instance alive.
+  /// @return  Renderer is ref-counted. This method returns a ref-pointer to a new instance, you
+  ///          should store it in a RefPtr<> to keep the instance alive.
   ///
   static RefPtr Create();
 
@@ -63,22 +61,21 @@ class UExport Renderer : public RefCounted {
   /// Create a Session to store local data in (such as cookies, local storage,
   /// application cache, indexed db, etc).
   ///
-  /// @note  A default, persistent Session is already created for you. You
-  ///        only need to call this if you want to create private, in-memory
-  ///        session or use a separate session for each View.
+  /// @note  A default, persistent Session is already created for you. You only need to call this
+  ///        if you want to create private, in-memory session or use a separate session for each
+  ///        View.
   ///
-  /// @param  is_persistent  Whether or not to store the session on disk.
-  ///                        Persistent sessions will be written to the path
-  ///                        set in Config::cache_path
+  /// @param  is_persistent  Whether or not to store the session on disk. Persistent sessions will
+  ///                        be written to the path set in Config::cache_path
   ///
-  /// @param  name  A unique name for this session, this will be used to
-  ///               generate a unique disk path for persistent sessions.
+  /// @param  name  A unique name for this session, this will be used to generate a unique disk
+  ///               path for persistent sessions.
   ///
   virtual RefPtr CreateSession(bool is_persistent, const String& name) = 0;
-  
+
   ///
-  /// Get the default Session. This session is persistent (backed to disk) and
-  /// has the name "default".
+  /// Get the default Session. This session is persistent (backed to disk) and has the name
+  /// "default".
   ///
   virtual RefPtr default_session() = 0;
 
@@ -86,20 +83,19 @@ class UExport Renderer : public RefCounted {
   /// Create a new View.
   ///
   /// @param  width   The initial width, in pixels.
-  /// 
+  ///
   /// @param  height  The initial height, in pixels.
   ///
   /// @param  config  Configuration details for the View.
   ///
-  /// @param  session  The session to store local data in. Pass a nullptr to
-  ///                  use the default session.
+  /// @param  session  The session to store local data in. Pass a nullptr to use the default
+  ///                  session.
   ///
-  /// @return  Returns a ref-pointer to a new View instance. You should assign
-  ///          it to either a Ref (non-nullable) or RefPtr
-  ///          (nullable).
+  /// @return  Returns a ref-pointer to a new View instance.
   ///
-  virtual RefPtr CreateView(uint32_t width, uint32_t height,
-    const ViewConfig& config, RefPtr session) = 0;
+  virtual RefPtr CreateView(uint32_t width, uint32_t height, const ViewConfig& config,
+                                  RefPtr session)
+      = 0;
 
   ///
   /// Update timers and dispatch internal callbacks. You should call this often
@@ -131,7 +127,62 @@ class UExport Renderer : public RefCounted {
   ///
   virtual void LogMemoryUsage() = 0;
 
-protected:
+  ///
+  /// Start the remote inspector server, Views that are loaded into this renderer
+  /// will be able to be remotely inspected either locally (another app on same machine) or
+  /// remotely (over the network) by navigating a View to inspector://ADDRESS:PORT
+  /// 
+  /// @return  Returns whether the server started successfully or not.
+  /// 
+  virtual bool StartRemoteInspectorServer(const char* address, uint16_t port) = 0;
+
+  ///
+  /// Describe the details of a gamepad, to be used with FireGamepadEvent and related
+  /// events below. This can be called multiple times with the same index if the details change.
+  ///
+  /// @param  index   The unique index (or "connection slot") of the gamepad. For example,
+  ///                 controller #1 would be "1", controller #2 would be "2" and so on.
+  ///
+  /// @param  id      A string ID representing the device, this will be made available
+  ///                 in JavaScript as gamepad.id
+  ///
+  /// @param  axis_count  The number of axes on the device.
+  ///
+  /// @param  button_count  The number of buttons on the device.
+  ///
+  virtual void SetGamepadDetails(uint32_t index, const String& id, uint32_t axis_count,
+                                 uint32_t button_count)
+      = 0;
+
+  ///
+  /// Fire a gamepad event (connection / disconnection).
+  ///
+  /// @note  The gamepad should first be described via SetGamepadDetails before calling this
+  ///        function.
+  ///
+  /// @see 
+  ///
+  virtual void FireGamepadEvent(const GamepadEvent& evt) = 0;
+
+  ///
+  /// Fire a gamepad axis event (to be called when an axis value is changed).
+  ///
+  /// @note  The gamepad should be connected via a previous call to FireGamepadEvent.
+  ///
+  /// @see 
+  ///
+  virtual void FireGamepadAxisEvent(const GamepadAxisEvent& evt) = 0;
+
+  ///
+  /// Fire a gamepad button event (to be called when a button value is changed).
+  ///
+  /// @note  The gamepad should be connected via a previous call to FireGamepadEvent.
+  ///
+  /// @see 
+  ///
+  virtual void FireGamepadButtonEvent(const GamepadButtonEvent& evt) = 0;
+
+ protected:
   virtual ~Renderer();
 };
 
diff --git a/Ultralight/ScrollEvent.h b/Ultralight/ScrollEvent.h
index 1dee4a2..170c5a1 100644
--- a/Ultralight/ScrollEvent.h
+++ b/Ultralight/ScrollEvent.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2020 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
@@ -22,15 +22,15 @@ namespace ultralight {
 /// @note   @see View::FireScrollEvent
 ///
 class ScrollEvent {
-public:
+ public:
   ///
   /// The scroll event granularity type
   ///
   enum Type {
-	  /// The delta value is interpreted as number of pixels
+    /// The delta value is interpreted as number of pixels
     kType_ScrollByPixel,
 
-	  /// The delta value is interpreted as number of pages
+    /// The delta value is interpreted as number of pages
     kType_ScrollByPage,
   };
 
@@ -50,4 +50,4 @@ class ScrollEvent {
   int delta_y;
 };
 
-}  // namespace ultralight
+} // namespace ultralight
diff --git a/Ultralight/Session.h b/Ultralight/Session.h
index de97298..16e6898 100644
--- a/Ultralight/Session.h
+++ b/Ultralight/Session.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2020 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
@@ -19,13 +19,13 @@
 namespace ultralight {
 
 ///
-/// @brief A Session stores local data such as cookies, local storage,
-///        and application cache for one or more Views. 
+/// @brief  A Session stores local data such as cookies, local storage, and application cache for
+///         one or more Views.
 ///
-/// @see   Renderer::CreateSession
+/// @see  Renderer::CreateSession
 ///
 class UExport Session : public RefCounted {
-public:
+ public:
   ///
   /// Whether or not this session is written to disk.
   ///
@@ -46,8 +46,8 @@ class UExport Session : public RefCounted {
   ///
   virtual String disk_path() const = 0;
 
-protected:
+ protected:
   virtual ~Session();
 };
 
-}  // namespace ultralight
+} // namespace ultralight
diff --git a/Ultralight/String.h b/Ultralight/String.h
index e70dca8..7894e0f 100644
--- a/Ultralight/String.h
+++ b/Ultralight/String.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
diff --git a/Ultralight/String16.h b/Ultralight/String16.h
index ffbe9aa..d42fffb 100644
--- a/Ultralight/String16.h
+++ b/Ultralight/String16.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
diff --git a/Ultralight/String32.h b/Ultralight/String32.h
index 571aecb..af1c033 100644
--- a/Ultralight/String32.h
+++ b/Ultralight/String32.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
diff --git a/Ultralight/String8.h b/Ultralight/String8.h
index 777834f..bc45b5b 100644
--- a/Ultralight/String8.h
+++ b/Ultralight/String8.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
diff --git a/Ultralight/Ultralight.h b/Ultralight/Ultralight.h
index 5b87585..098f690 100644
--- a/Ultralight/Ultralight.h
+++ b/Ultralight/Ultralight.h
@@ -1,4 +1,4 @@
-// Copyright 2020 Ultralight, Inc. All rights reserved.
+// Copyright 2022 Ultralight, Inc. All rights reserved.
 #pragma once
 #include 
 #include 
diff --git a/Ultralight/View.h b/Ultralight/View.h
index 5705083..03c5be8 100644
--- a/Ultralight/View.h
+++ b/Ultralight/View.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2020 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -27,20 +28,40 @@ namespace ultralight {
 
 struct UExport ViewConfig {
   ///
-  /// When enabled, the View will be rendered to an offscreen GPU texture
-  /// using the GPU driver set in Platform::set_gpu_driver. You can fetch
-  /// details for the texture via View::render_target.
+  /// Whether to render using the GPU renderer (accelerated) or the CPU renderer (unaccelerated).
+  /// 
+  /// This option is only valid if you're managing the Renderer yourself (eg, you've previously
+  /// called Renderer::Create() instead of App::Create()).
+  ///
+  /// When true, the View will be rendered to an offscreen GPU texture using the GPU driver set in
+  /// Platform::set_gpu_driver. You can fetch details for the texture via View::render_target.
   ///
-  /// When disabled (the default), the View will be rendered to an offscreen
-  /// pixel buffer. This pixel buffer can optionally be provided by the user--
+  /// When false (the default), the View will be rendered to an offscreen pixel buffer using the
+  /// multithreaded CPU renderer. This pixel buffer can optionally be provided by the user--
   /// for more info see  and View::surface.
   ///
   bool is_accelerated = false;
 
+  ///
+  /// Whether or not this View should support transparency.
+  ///
+  /// @note Make sure to also set the following CSS on the page:
+  ///
+  ///    html, body { background: transparent; }
+  ///
   bool is_transparent = false;
 
+  ///
+  /// The initial device scale, ie. the amount to scale page units to screen pixels. This should
+  /// be set to the scaling factor of the device that the View is displayed on.
+  ///
+  /// @note 1.0 is equal to 100% zoom (no scaling), 2.0 is equal to 200% zoom (2x scaling)
+  ///
   double initial_device_scale = 1.0;
 
+  ///
+  /// Whether or not the View should initially have input focus, @see View::Focus()
+  ///
   bool initial_focus = true;
 
   ///
@@ -77,33 +98,33 @@ struct UExport ViewConfig {
   /// Default user-agent string.
   ///
   String user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
-                        "AppleWebKit/608.3.10 (KHTML, like Gecko) "
-                         "Ultralight/1.3.0 Safari/608.3.10";
+                      "AppleWebKit/605.1.15 (KHTML, like Gecko) "
+                      "Ultralight/1.3.0 Version/13.0.3 Safari/605.1.15";
 };
 
 ///
 /// @brief The View class is used to load and display web content.
 ///
-/// View is an offscreen web-page container that can be used to display
-/// web-content in your application.
+/// View is an offscreen web-page container that can be used to display web-content in your
+/// application.
 ///
-/// You can load content into a View via View::LoadURL() or View::LoadHTML()
-/// and interact with it via View::FireMouseEvent() and similar API.
+/// You can load content into a View via View::LoadURL() or View::LoadHTML() and interact with it
+/// via View::FireMouseEvent() and similar API.
 ///
-/// When displaying a View, the API is different depending on whether you
-/// are using the CPU renderer or the GPU renderer:
+/// When displaying a View, the API is different depending on whether you are using the CPU
+/// renderer or the GPU renderer:
 ///
-/// When using the CPU renderer, you would get the underlying pixel-buffer
-/// surface for a View via View::surface().
+/// When using the CPU renderer, you would get the underlying pixel-buffer surface for a View via
+/// View::surface().
 ///
-/// When using the GPU renderer, you would get the underlying render target
-/// and texture information via View::render_target().
+/// When using the GPU renderer, you would get the underlying render target and texture information
+/// via View::render_target().
 ///
-/// @note  The API is not currently thread-safe, all calls must be made on the
-///        same thread that the Renderer/App was created on.
+/// @note  The API is not currently thread-safe, all calls must be made on the same thread that the
+///        Renderer/App was created on.
 ///
 class UExport View : public RefCounted {
-public:
+ public:
   ///
   /// Get the URL of the current page loaded into this View, if any.
   ///
@@ -124,12 +145,27 @@ class UExport View : public RefCounted {
   ///
   virtual uint32_t height() const = 0;
 
+  ///
+  /// Get the device scale, ie. the amount to scale page units to screen pixels.
+  /// 
+  /// For example, a value of 1.0 is equivalent to 100% zoom. A value of 2.0 is 200% zoom.
+  /// 
   virtual double device_scale() const = 0;
 
+  ///
+  /// Set the device scale.
+  /// 
   virtual void set_device_scale(double scale) = 0;
 
+  ///
+  /// Whether or not the View is GPU-accelerated. If this is false, the page will be rendered
+  /// via the CPU renderer.
+  /// 
   virtual bool is_accelerated() const = 0;
 
+  ///
+  /// Whether or not the View supports transparent backgrounds.
+  ///
   virtual bool is_transparent() const = 0;
 
   ///
@@ -138,23 +174,26 @@ class UExport View : public RefCounted {
   virtual bool is_loading() = 0;
 
   ///
-  /// Get the offscreen RenderTarget for the View.
+  /// Get the RenderTarget for the View.
   ///
-  /// @note  Only valid when the GPU renderer is enabled in Config.
+  /// @note  Only valid if this View is GPU accelerated.
   ///
-  ///        You can use this with your GPUDriver implementation to bind
-  ///        and display the corresponding texture in your application.
+  ///        You can use this with your GPUDriver implementation to bind and display the
+  ///        corresponding texture in your application.
   ///
   virtual RenderTarget render_target() = 0;
 
   ///
-  /// Get the offscreen Surface for the View (pixel-buffer container).
+  /// Get the Surface for the View (native pixel buffer that the CPU renderer draws into).
   ///
-  /// @note  Only valid when the CPU is enabled (will return a nullptr
-  ///        otherwise)
+  /// @note  This operation is only valid if you're managing the Renderer yourself (eg, you've
+  ///        previously called Renderer::Create() instead of App::Create()).
   ///
-  ///        The default Surface is BitmapSurface but you can provide your
-  ///        own Surface implementation via Platform::set_surface_factory.
+  ///        This function will return nullptr if this View is GPU accelerated (eg, not using
+  ///        the CPU renderer). @see ViewConfig::is_accelerated
+  ///
+  ///        The default Surface is BitmapSurface but you can provide your own Surface
+  ///        implementation via Platform::set_surface_factory().
   ///
   virtual Surface* surface() = 0;
 
@@ -163,23 +202,21 @@ class UExport View : public RefCounted {
   ///
   /// @param  html  The raw HTML string to load.
   ///
-  /// @param  url   An optional URL for this load (to make it appear as if we
-  ///               we loaded this HTML from a certain URL). Can be used for
-  ///               resolving relative URLs and cross-origin rules.
+  /// @param  url   An optional URL for this load (to make it appear as if we we loaded this HTML
+  ///               from a certain URL). Can be used for resolving relative URLs and cross-origin
+  ///               rules.
   ///
-  /// @param  add_to_history  Whether or not this load should be added to the
-  ///                         session's history (back/forward list).
+  /// @param  add_to_history  Whether or not this load should be added to the session's history
+  ///                         (eg, the back/forward list).
   ///
-  virtual void LoadHTML(const String& html,
-    const String& url = "", 
-    bool add_to_history = false) = 0;
+  virtual void LoadHTML(const String& html, const String& url = "", bool add_to_history = false)
+      = 0;
 
   ///
   /// Load a URL, the View will navigate to it as a new page.
   ///
-  /// @note  You can use File URLs (eg, file:///page.html) but you must define
-  ///        your own FileSystem implementation if you are not using AppCore.
-  ///        @see Platform::set_file_system
+  /// @note  You can use File URLs (eg, file:///page.html) but you must define your own FileSystem
+  ///        implementation if you are not using AppCore. @see Platform::set_file_system
   ///
   virtual void LoadURL(const String& url) = 0;
 
@@ -187,7 +224,7 @@ class UExport View : public RefCounted {
   /// Resize View to a certain size.
   ///
   /// @param  width   The initial width, in pixels.
-  /// 
+  ///
   /// @param  height  The initial height, in pixels.
   ///
   ///
@@ -196,37 +233,41 @@ class UExport View : public RefCounted {
   ///
   /// Acquire the page's JSContext for use with the JavaScriptCore API
   ///
-  /// @note  You can use the underlying JSContextRef with the JavaScriptCore
-  ///        C API. This allows you to marshall C/C++ objects to/from
-  ///        JavaScript, bind callbacks, and call JS functions directly.
+  /// @note  You can use the underlying JSContextRef with the JavaScriptCore C API. This allows you
+  ///        to marshall C/C++ objects to/from JavaScript, bind callbacks, and call JS functions
+  ///        directly.
   ///
-  /// @note  The JSContextRef gets reset after each page navigation. You
-  ///        should initialize your JavaScript state within the
-  ///        OnWindowObjectReady and OnDOMReady events, @see ViewListener.
+  /// @note  The JSContextRef gets reset after each page navigation. You should initialize your
+  ///        JavaScript state within the OnWindowObjectReady and OnDOMReady events,
+  ///        @see ViewListener.
   ///
-  /// @note  This call locks the internal context for the current thread.
-  ///        It will be unlocked when the returned JSContext's ref-count goes
-  ///        to zero. The lock is recursive, you can call this multiple times.
+  /// @note  This call locks the internal context for the current thread. It will be unlocked when
+  ///        the returned JSContext's ref-count goes to zero. The lock is recursive, you can call
+  ///        this multiple times.
   ///
   virtual RefPtr LockJSContext() = 0;
 
   ///
-  /// Helper function to evaluate a raw string of JavaScript and return the
-  /// result as a String.
+  /// Get a handle to the internal JavaScriptCore VM.
+  ///
+  virtual void* JavaScriptVM() = 0;
+
+  ///
+  /// Helper function to evaluate a raw string of JavaScript and return the result as a String.
   ///
   /// @param  script     A string of JavaScript to evaluate in the main frame.
   ///
-  /// @param  exception  A string to store the exception in, if any. Pass a
-  ///                    nullptr if you don't care about exceptions.
+  /// @param  exception  A string to store the exception in, if any. Pass a nullptr if you don't
+  ///                    care about exceptions.
   ///
   /// @return  Returns the JavaScript result typecast to a String.
   ///
   ///
   /// @note  You do not need to lock the JS context, it is done automatically.
   ///
-  /// @note  If you need lower-level access to native JavaScript values, you
-  ///        should instead lock the JS context and call JSEvaluateScript() in
-  ///        the JavaScriptCore C API. @see 
+  /// @note  If you need lower-level access to native JavaScript values, you should instead lock
+  ///        the JS context and call JSEvaluateScript() in the JavaScriptCore C API.
+  ///        @see 
   ///
   virtual String EvaluateScript(const String& script, String* exception = nullptr) = 0;
 
@@ -268,16 +309,15 @@ class UExport View : public RefCounted {
   ///
   /// Give focus to the View.
   ///
-  /// You should call this to give visual indication that the View has input
-  /// focus (changes active text selection colors, for example).
+  /// You should call this to give visual indication that the View has input focus (changes active
+  /// text selection colors, for example).
   ///
   virtual void Focus() = 0;
 
   ///
   /// Remove focus from the View and unfocus any focused input elements.
   ///
-  /// You should call this to give visual indication that the View has lost
-  /// input focus.
+  /// You should call this to give visual indication that the View has lost input focus.
   ///
   virtual void Unfocus() = 0;
 
@@ -287,14 +327,14 @@ class UExport View : public RefCounted {
   virtual bool HasFocus() = 0;
 
   ///
-  /// Whether or not the View has an input element with visible keyboard focus
-  /// (indicated by a blinking caret).
+  /// Whether or not the View has an input element with visible keyboard focus (indicated by a
+  /// blinking caret).
   ///
-  /// You can use this to decide whether or not the View should consume
-  /// keyboard input events (useful in games with mixed UI and key handling).
+  /// You can use this to decide whether or not the View should consume keyboard input events
+  /// (useful in games with mixed UI and key handling).
   ///
   virtual bool HasInputFocus() = 0;
-  
+
   ///
   /// Fire a keyboard event
   ///
@@ -318,7 +358,7 @@ class UExport View : public RefCounted {
   /// @note  Ownership remains with the caller.
   ///
   virtual void set_view_listener(ViewListener* listener) = 0;
-  
+
   ///
   /// Get the active ViewListener, if any
   ///
@@ -337,11 +377,10 @@ class UExport View : public RefCounted {
   virtual LoadListener* load_listener() const = 0;
 
   ///
-  /// Set whether or not this View should be repainted during the next
-  /// call to Renderer::Render
+  /// Set whether or not this View should be repainted during the next call to Renderer::Render
   ///
-  /// @note  This flag is automatically set whenever the page content changes
-  ///        but you can set it directly in case you need to force a repaint.
+  /// @note  This flag is automatically set whenever the page content changes but you can set it
+  ///        directly in case you need to force a repaint.
   ///
   virtual void set_needs_paint(bool needs_paint) = 0;
 
@@ -352,20 +391,19 @@ class UExport View : public RefCounted {
   virtual bool needs_paint() const = 0;
 
   ///
-  /// Get the inspector for this View, this is useful for debugging and
-  /// inspecting pages locally. This will only succeed if you have the
-  /// inspector assets in your filesystem-- the inspector will look for
-  /// file:///inspector/Main.html when it first loads.
-  ///
-  /// @note  The inspector View is owned by the View and lazily-created on
-  ///        first call. The initial dimensions are 10x10, you should call
-  ///        View::Resize() on the returned View to resize it to your desired
-  ///        dimensions.
+  /// Create an Inspector View to inspect / debug this View locally.
+  /// 
+  /// This will only succeed if you have the inspector assets in your filesystem-- the inspector
+  /// will look for file:///inspector/Main.html when it first loads.
+  /// 
+  /// You must handle ViewListener::OnCreateInspectorView so that the library has a View to display
+  /// the inspector in. This function will call this event only if an inspector view is not
+  /// currently active.
   ///
-  virtual RefPtr inspector() = 0;
+  virtual void CreateLocalInspectorView() = 0;
 
-protected:
+ protected:
   virtual ~View();
 };
 
-}  // namespace ultralight
+} // namespace ultralight
diff --git a/Ultralight/platform/Clipboard.h b/Ultralight/platform/Clipboard.h
index dcde762..530f3be 100644
--- a/Ultralight/platform/Clipboard.h
+++ b/Ultralight/platform/Clipboard.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
diff --git a/Ultralight/platform/Config.h b/Ultralight/platform/Config.h
index 14cff20..d182e2d 100644
--- a/Ultralight/platform/Config.h
+++ b/Ultralight/platform/Config.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
@@ -51,6 +51,11 @@ enum class UExport FontHinting : uint8_t {
   /// unpleasant if the underlying TTF does not contain hints for this type of rendering.
   ///
   Monochrome,
+
+  ///
+  /// No hinting is performed-- fonts may be blurry at smaller font sizes.
+  ///
+  None,
 };
 
 ///
@@ -174,10 +179,28 @@ struct UExport Config {
   uint32_t num_renderer_threads = 0;
 
   /// 
-  /// The max amount of time (in seconds) to allow Renderer::Update to run per call. The library
-  /// will attempt to throttle timers and/or reschedule work if this time budget is exceeded.
+  /// The max amount of time (in seconds) to allow repeating timers to run during each call to
+  /// Renderer::Update. The library will attempt to throttle timers and/or reschedule work if this
+  /// time budget is exceeded.
+  ///
+  double max_update_time = 1.0 / 200.0;
+
+  ///
+  /// The alignment (in bytes) of the BitmapSurface when using the CPU renderer.
+  ///
+  /// The underlying bitmap associated with each BitmapSurface will have row_bytes padded to reach
+  /// this alignment.
+  ///
+  /// Aligning the bitmap helps improve performance when using the CPU renderer. Determining the
+  /// proper value to use depends on the CPU architecture and max SIMD instruction set used.
+  ///
+  /// We generally target the 128-bit SSE2 instruction set across most PC platforms so '16' is
+  /// a safe value to use.
+  ///
+  /// You can set this to '0' to perform no padding (row_bytes will always be width * 4) at a
+  /// slight cost to performance.
   ///
-  double max_update_time = 1.0 / 100.0;
+  uint32_t bitmap_alignment = 16;
 };
 
 } // namespace ultralight
diff --git a/Ultralight/platform/FileSystem.h b/Ultralight/platform/FileSystem.h
index e9f250a..7fa3048 100644
--- a/Ultralight/platform/FileSystem.h
+++ b/Ultralight/platform/FileSystem.h
@@ -9,24 +9,15 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
 #include 
+#include 
 
 namespace ultralight {
 
-///
-/// File Handle type used as unique ID for opened files.
-///
-typedef size_t FileHandle;
-
-///
-/// Handle used to denote an invalid file.
-///
-const FileHandle invalidFileHandle = (FileHandle)-1;
-
 ///
 /// @brief  FileSystem interface.
 ///
@@ -54,35 +45,44 @@ class UExport FileSystem {
   ///
   /// Check if file path exists, return true if exists.
   ///
-  virtual bool FileExists(const String& path) = 0;
-
-  ///
-  /// Get file size of previously opened file, store result in 'result'. Return true on success.
-  ///
-  virtual bool GetFileSize(FileHandle handle, int64_t& result) = 0;
+  virtual bool FileExists(const String& file_path) = 0;
 
   ///
-  /// Get file mime type (eg "text/html"), store result in 'result'. Return true on success.
+  /// Get the mime-type of the file (eg "text/html").
+  /// 
+  /// This is usually determined by analyzing the file extension.
+  /// 
+  /// If a mime-type cannot be determined, this should return "application/unknown".
   ///
-  virtual bool GetFileMimeType(const String& path, String& result) = 0;
+  virtual String GetFileMimeType(const String& file_path) = 0;
 
   ///
-  /// Open file path for reading or writing. Return file handle on success, or invalidFileHandle on
-  /// failure.
-  ///
-  /// @NOTE:  As of this writing (v1.3), this function is only used for reading.
-  ///
-  virtual FileHandle OpenFile(const String& path, bool open_for_writing) = 0;
-
-  ///
-  /// Close previously-opened file.
-  ///
-  virtual void CloseFile(FileHandle& handle) = 0;
+  /// Get the charset / encoding of the file (eg "utf-8", "iso-8859-1").
+  /// 
+  /// This is only applicable for text-based files (eg, "text/html", "text/plain") and is usually
+  /// determined by analyzing the contents of the file.
+  /// 
+  /// If a charset cannot be determined, a safe default to return is "utf-8".
+  /// 
+  virtual String GetFileCharset(const String& file_path) = 0;
 
   ///
-  /// Read from currently-opened file, return number of bytes read or -1 on failure.
+  /// Open file for reading and map it to a Buffer.
+  /// 
+  /// To minimize copies, you should map the requested file into memory and use Buffer::Create()
+  /// to wrap the data pointer (unmapping should be performed in the destruction callback).
+  /// 
+  /// If the file was unable to be opened, you should return nullptr for this value.
   ///
-  virtual int64_t ReadFromFile(FileHandle handle, char* data, int64_t length) = 0;
+  /// @note  File data addresses returned from this function should generally be aligned to 16-byte
+  ///        boundaries (the default alignment on most operating systems-- if you're using C stdlib
+  ///        or C++ STL functions this is already handled for you). This requirement is currently
+  ///        necessary when loading the ICU data file (eg, icudt67l.dat), and may be relaxed for
+  ///        other files (but you may still see a performance benefit due to cache line alignment).
+  ///        If you can't guarantee alignment or are unsure, you can use Buffer::CreateFromCopy to
+  ///        copy the file data content to an aligned block (at the expense of data duplication).
+  /// 
+  virtual RefPtr OpenFile(const String& file_path) = 0;
 };
 
 } // namespace ultralight
diff --git a/Ultralight/platform/FontLoader.h b/Ultralight/platform/FontLoader.h
index ddce296..c04a80a 100644
--- a/Ultralight/platform/FontLoader.h
+++ b/Ultralight/platform/FontLoader.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
diff --git a/Ultralight/platform/GPUDriver.h b/Ultralight/platform/GPUDriver.h
index 0406d25..7af1c9e 100644
--- a/Ultralight/platform/GPUDriver.h
+++ b/Ultralight/platform/GPUDriver.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #pragma warning(disable : 4251)
diff --git a/Ultralight/platform/Logger.h b/Ultralight/platform/Logger.h
index 24f45ce..30afb9e 100644
--- a/Ultralight/platform/Logger.h
+++ b/Ultralight/platform/Logger.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
diff --git a/Ultralight/platform/Platform.h b/Ultralight/platform/Platform.h
index 9c5845b..7a4b30f 100644
--- a/Ultralight/platform/Platform.h
+++ b/Ultralight/platform/Platform.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
diff --git a/Ultralight/platform/Surface.h b/Ultralight/platform/Surface.h
index f26dbf1..98953bf 100644
--- a/Ultralight/platform/Surface.h
+++ b/Ultralight/platform/Surface.h
@@ -9,7 +9,7 @@
 ///
 /// Website: 
 ///
-/// Copyright (C) 2021 Ultralight, Inc. All rights reserved.
+/// Copyright (C) 2022 Ultralight, Inc. All rights reserved.
 ///
 #pragma once
 #include 
diff --git a/Ultralight/private/PlatformFileSystem.h b/Ultralight/private/PlatformFileSystem.h
deleted file mode 100644
index 172809c..0000000
--- a/Ultralight/private/PlatformFileSystem.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-#include 
-#include 
-
-namespace ultralight {
-namespace PlatformFileSystem {
-
-bool UExport FileExists(const String& path);
-bool UExport IsDirectory(const String& path, bool follow_symbolic_links);
-String UExport AppendPath(const String& path, const String& component);
-bool UExport MakeAllDirectories(const String& path);
-String UExport GetFileName(const String& path);
-String UExport GetDirectoryName(const String& path);
-String UExport RealFilePath(const String& path);
-
-}  // PlatformFileSystem
-}  // ultralight