-
Notifications
You must be signed in to change notification settings - Fork 2
Platform
The Platform module provides cross-platform abstractions that allow the browser engine to run on multiple operating systems. It handles platform-specific functionality while maintaining a unified interface for other modules.
- Abstract platform-specific operations
- Provide OS-independent APIs
- Handle system resource management
- Enable code portability
- Manage platform capabilities
- Support multiple operating systems
A layer that hides OS-specific details:
Grob Engine (Platform-independent)
↓
Platform Module (Abstraction)
↓
↙ ↓ ↘
Windows macOS Linux
- Windows: Using Win32 and system APIs
- macOS: Using Cocoa and system frameworks
- Linux: Using X11 and GTK (Planned)
Platform-independent file access:
- File Reading: Load files from disk
- File Writing: Save data to disk
- Path Handling: Normalize paths across platforms
- Directory Operations: List, create, delete directories
- Permissions: Check file permissions
Retrieve system and environment information:
- OS Type: Detect Windows, macOS, Linux
- Architecture: CPU architecture (x86, ARM)
- Memory: Available system memory
- Display: Screen resolution and DPI
- Locale: System language and region
Manage system resources efficiently:
- Memory: Allocate and free memory
- Timers: High-resolution timing
- Threads: Multi-threading support (Planned)
- Locks: Synchronization primitives
Handle user input and system output:
- Keyboard: Keyboard input processing
- Mouse: Mouse movement and clicks
- Touch: Touch screen input (Planned)
- Clipboard: Copy/paste operations
Graphics-related operations:
- Screen DPI: Device pixel ratio
- Color Space: RGB, sRGB support
- Rendering Backend: Graphics API selection
- Display Scaling: Handle different screen scales
trait FileSystem {
fn read_file(path: &Path) -> Result<Vec<u8>>;
fn write_file(path: &Path, data: &[u8]) -> Result<()>;
fn exists(path: &Path) -> bool;
fn is_directory(path: &Path) -> bool;
}trait SystemInfo {
fn get_os() -> OperatingSystem;
fn get_screen_dpi() -> f32;
fn get_available_memory() -> u64;
fn get_processor_count() -> usize;
}- File System: Windows API for file operations
- Paths: NTFS path handling with drive letters
- Registry: Windows registry access (Planned)
- Fonts: Windows font directories
- Graphics: Direct3D or GDI+ (Planned)
- File System: POSIX file operations
- Paths: Unix-style paths
- Frameworks: Cocoa for native integration
- Fonts: macOS font directories
- Graphics: Metal or OpenGL (Planned)
- File System: Linux filesystem operations
- Paths: Unix-style paths
- Desktop: X11 and GTK integration
- Fonts: Linux font paths
- Graphics: OpenGL or Vulkan
Configuration through environment variables:
-
GROB_DATA_DIR: Custom data directory -
GROB_LOG_LEVEL: Logging verbosity -
GROB_CACHE_DIR: Cache directory location -
GROB_TEMP_DIR: Temporary file directory
Platform-dependent configuration:
- Windows: Registry or ini files
- Unix: .config/ or .grob/ directories
- Shared: Standard locations via XDG
Different font handling per platform:
- Windows: System32/Fonts directory, registry lookup
- macOS: /Library/Fonts, ~/Library/Fonts
- Linux: /usr/share/fonts, ~/.fonts
Platform-specific network setup:
- Proxy Settings: System proxy configuration
- DNS: System DNS resolver
- Certificates: System certificate store
Handle different screen densities:
- DPI Scaling: Pixel ratio calculation
- High DPI: Support for Retina and 4K displays
- Scale Factors: Convert between logical and physical pixels
- Multiple Monitors: Multi-display support (Planned)
Platform-specific optimizations:
- CPU Features: Use SIMD where available
- Memory: Page size and caching strategies
- Threading: Thread pool configuration
- Caching: Platform-specific cache strategies
Uses platform module for window management and input
Platform-specific HTTP implementation
Accesses system font directories
Platform-specific graphics rendering
Cross-platform testing strategies:
- Platform Detection: Conditional compilation
- Fallbacks: Graceful degradation
- Mocking: Mock platform operations for testing
- CI/CD: Test on multiple platforms
Normalize paths across platforms:
// Input: "C:\\Users\\Downloads\\file.txt" (Windows)
// Normalized: "c:/users/downloads/file.txt" (Internal)
// Output: Platform-specific when neededHandle CRLF (Windows) vs LF (Unix):
- Reading: Normalize to LF internally
- Writing: Convert to platform-specific endings
Support multiple character encodings:
- UTF-8: Primary encoding (internal)
- UTF-16: Windows APIs
- Local Encoding: Platform-specific
Current Status:
- Basic path validation
- File access permissions check
Future Plans:
- Sandboxing
- Security context isolation
- Safe file operations
- Permission management
- Linux support
- Wayland support (alternative to X11)
- Touch input support
- Gamepad/controller support
- Microphone/camera access
- Platform notifications
- System tray integration
- Drag and drop support
- Multiple window support
- Platform-specific system libraries
- Graphics APIs (Direct3D, Metal, Vulkan)
- Font loading libraries
- Network libraries
Tested Platforms:
- Windows 10/11
- Ubuntu 20.04+
- macOS 10.15+ (Planned)
Minimum Requirements:
- 64-bit processor
- 2GB RAM
- OpenGL 3.0 or equivalent