Repository navigation
feat(share): integrate native Rust rendering runtime - #679
YinCheng0106 wants to merge 1 commit into
Conversation
New(zh-Hant): 加入地震報告橫式分享圖的原生渲染基礎 New(en-US): Add native rendering support for landscape earthquake report images Platform: all
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
🔍 OpenCodeReview found 6 issue(s) in this PR.
📄
|
| final class ReportPictureFailure extends Failure { | ||
| const ReportPictureFailure(this.reason, super.message, {this.nativeStatus}); | ||
|
|
||
| final ReportPictureFailureReason reason; | ||
| final int? nativeStatus; | ||
| } |
| String? nativeLibraryFileName(String name, NativeLibraryHost host) => | ||
| switch (host) { | ||
| NativeLibraryHost.ios => null, | ||
| NativeLibraryHost.android || | ||
| NativeLibraryHost.linux || | ||
| NativeLibraryHost.fuchsia => 'lib$name.so', | ||
| NativeLibraryHost.macos => 'lib$name.dylib', | ||
| NativeLibraryHost.windows => '$name.dll', | ||
| }; |
| final library = fileName == null | ||
| ? (openProcess ?? DynamicLibrary.process)() | ||
| : (openFile ?? DynamicLibrary.open)(fileName); |
There was a problem hiding this comment.
NativeLibrary.open 中的 openProcess 處理邏輯存在潛在的 Runtime Bug。當 openProcess 為 null 時,程式碼會嘗試執行 DynamicLibrary.process(),但 DynamicLibrary.process 是一個 getter 而非函數,這會導致 NoSuchMethodError。建議將 fallback 改為 () => DynamicLibrary.process 以確保類型一致性。
Suggestion:
| final library = fileName == null | |
| ? (openProcess ?? DynamicLibrary.process)() | |
| : (openFile ?? DynamicLibrary.open)(fileName); | |
| final library = fileName == null | |
| ? (openProcess ?? () => DynamicLibrary.process)() | |
| : (openFile ?? DynamicLibrary.open)(fileName); |
| final render = _pending.then( | ||
| (_) => _renderRequest(_address, input, mode, theme), | ||
| ); | ||
| _pending = render.then((_) {}); |
There was a problem hiding this comment.
當 _renderInIsolate 失敗時,_pending 會變成一個失敗的 Future。由於後續的 _pending.then(...) 僅處理成功情況,這會導致所有後續的渲染請求在尚未呼叫 _renderInIsolate 之前就直接因為 _pending 的錯誤而失敗,這與註解中「失敗請求應讓渲染器保持可用」的設計不符。
Suggestion:
| final render = _pending.then( | |
| (_) => _renderRequest(_address, input, mode, theme), | |
| ); | |
| _pending = render.then((_) {}); | |
| final render = _pending.then( | |
| (_) => _renderRequest(_address, input, mode, theme), | |
| ); | |
| _pending = render.then((_) {}, onError: (_) {}); |
| Future<Uint8List> _renderInIsolate( | ||
| int address, | ||
| Uint8List input, | ||
| EqMapMode mode, | ||
| EqTheme theme, | ||
| ) => Isolate.run( | ||
| () => EqReportPic.fromAddress( | ||
| _workerBindings(), | ||
| address, | ||
| ).renderSharePngV2(input, mode: mode, theme: theme), | ||
| debugName: 'report-picture-render', | ||
| ); | ||
|
|
||
| Future<Result<Uint8List>> _renderRequest( | ||
| int address, | ||
| Uint8List input, | ||
| EqMapMode mode, | ||
| EqTheme theme, | ||
| ) async { | ||
| try { | ||
| return Ok(await _renderInIsolate(address, input, mode, theme)); | ||
| } on ReportPictureFailure catch (failure) { | ||
| return Err(failure); | ||
| } on EqShareRenderException catch (error) { | ||
| final reason = switch (error.reason) { | ||
| EqShareRenderError.invalidArgument => | ||
| ReportPictureFailureReason.invalidInput, | ||
| EqShareRenderError.unsupportedVersion => | ||
| ReportPictureFailureReason.unsupportedVersion, | ||
| EqShareRenderError.unsupportedFeature => | ||
| ReportPictureFailureReason.unsupportedFeature, | ||
| EqShareRenderError.limitExceeded => | ||
| ReportPictureFailureReason.limitExceeded, | ||
| EqShareRenderError.internal || | ||
| EqShareRenderError.unknown => ReportPictureFailureReason.renderFailed, | ||
| }; | ||
| return Err( | ||
| ReportPictureFailure( | ||
| reason, | ||
| error.message, | ||
| nativeStatus: error.nativeStatus, | ||
| ), | ||
| ); | ||
| } catch (error) { | ||
| return Err( | ||
| ReportPictureFailure( | ||
| ReportPictureFailureReason.renderFailed, | ||
| 'The native report renderer failed: $error', | ||
| ), | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
_renderInIsolate 的回傳類型宣告與其實際回傳值(Result<Uint8List>)不符,且在 _renderRequest 中使用 Ok(await ...) 會導致回傳值變成 Result<Result<Uint8List>> 的巢狀結構。
Suggestion:
| Future<Uint8List> _renderInIsolate( | |
| int address, | |
| Uint8List input, | |
| EqMapMode mode, | |
| EqTheme theme, | |
| ) => Isolate.run( | |
| () => EqReportPic.fromAddress( | |
| _workerBindings(), | |
| address, | |
| ).renderSharePngV2(input, mode: mode, theme: theme), | |
| debugName: 'report-picture-render', | |
| ); | |
| Future<Result<Uint8List>> _renderRequest( | |
| int address, | |
| Uint8List input, | |
| EqMapMode mode, | |
| EqTheme theme, | |
| ) async { | |
| try { | |
| return Ok(await _renderInIsolate(address, input, mode, theme)); | |
| } on ReportPictureFailure catch (failure) { | |
| return Err(failure); | |
| } on EqShareRenderException catch (error) { | |
| final reason = switch (error.reason) { | |
| EqShareRenderError.invalidArgument => | |
| ReportPictureFailureReason.invalidInput, | |
| EqShareRenderError.unsupportedVersion => | |
| ReportPictureFailureReason.unsupportedVersion, | |
| EqShareRenderError.unsupportedFeature => | |
| ReportPictureFailureReason.unsupportedFeature, | |
| EqShareRenderError.limitExceeded => | |
| ReportPictureFailureReason.limitExceeded, | |
| EqShareRenderError.internal || | |
| EqShareRenderError.unknown => ReportPictureFailureReason.renderFailed, | |
| }; | |
| return Err( | |
| ReportPictureFailure( | |
| reason, | |
| error.message, | |
| nativeStatus: error.nativeStatus, | |
| ), | |
| ); | |
| } catch (error) { | |
| return Err( | |
| ReportPictureFailure( | |
| ReportPictureFailureReason.renderFailed, | |
| 'The native report renderer failed: $error', | |
| ), | |
| ); | |
| } | |
| } | |
| Future<Result<Uint8List>> _renderInIsolate( | |
| int address, | |
| Uint8List input, | |
| EqMapMode mode, | |
| EqTheme theme, | |
| ) => Isolate.run( | |
| () => EqReportPic.fromAddress( | |
| _workerBindings(), | |
| address, | |
| ).renderSharePngV2(input, mode: mode, theme: theme), | |
| debugName: 'report-picture-render', | |
| ); | |
| Future<Result<Uint8List>> _renderRequest( | |
| int address, | |
| Uint8List input, | |
| EqMapMode mode, | |
| EqTheme theme, | |
| ) async { | |
| try { | |
| return await _renderInIsolate(address, input, mode, theme); | |
| } on ReportPictureFailure catch (failure) { | |
| return Err(failure); | |
| } on EqShareRenderException catch (error) { | |
| final reason = switch (error.reason) { | |
| EqShareRenderError.invalidArgument => | |
| ReportPictureFailureReason.invalidInput, | |
| EqShareRenderError.unsupportedVersion => | |
| ReportPictureFailureReason.unsupportedVersion, | |
| EqShareRenderError.unsupportedFeature => | |
| ReportPictureFailureReason.unsupportedFeature, | |
| EqShareRenderError.limitExceeded => | |
| ReportPictureFailureReason.limitExceeded, | |
| EqShareRenderError.internal || | |
| EqShareRenderError.unknown => ReportPictureFailureReason.renderFailed, | |
| }; | |
| return Err( | |
| ReportPictureFailure( | |
| reason, | |
| error.message, | |
| nativeStatus: error.nativeStatus, | |
| ), | |
| ); | |
| } catch (error) { | |
| return Err( | |
| ReportPictureFailure( | |
| ReportPictureFailureReason.renderFailed, | |
| 'The native report renderer failed: $error', | |
| ), | |
| ); | |
| } | |
| } |
Codecov Report❌ Patch coverage is ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
這個 PR 做了什麼
ReportPicture服務。在建立 renderer 前檢查 ABI 1.2 與 v2/16:9 能力。將原始 UTF-8 交給 Rust 驗證和渲染,回傳 Dart 持有的 PNG 或結構化錯誤。dispose()等待已接受的請求完成後釋放 handle。DynamicLibrary.process()查找。Android APK 封裝 arm64-v8a 與 x86_64 的libeq_report_pic.so,沿用 DPIP 的 ABI 篩選。相關 issue
b135d02bd1ba5103cd3d116a951b1b63a710a312。main獨立建置。#674 是直式分享卡的相關工作。怎麼驗
tool/run.sh通過端到端、缺庫回傳unavailable和一般 DPIP 啟動。未簽署的裝置 Release 及模擬器 Debug 封裝各保留九個匯出。RunnerTests 421 項通過。unsupportedAbi。原生探針確認 3 個 PNG 緩衝區與 2 個 renderer 都已釋放。Debug/Release APK 的兩種 ABI 均通過九個符號、ELF 對齊及zipalign -P 16檢查。一般 DPIP Release 已啟動。0x11F,成功解碼為 1920×1080。相同輸入的 PNG 共 195,390 bytes,SHA-256 為d1a2080c35193928026c05e8aef2eb6fe4ce28c24a9a8bf0fd4b2b0f3c4cae5d。驗證連續請求、無效 JSON/版本、失敗後重試、釋放後解碼與重新開啟。tool/check.sh通過。Flutter 分析無問題,3,837 項測試通過、11 項跳過。 Android lint 通過。Android JVM 測試以 2 GiB 的本機測試 heap 重跑,620 項通過。已知限制
檢查清單
tool/check/commits.sh origin/main..HEAD通過。