react-native-webgpu 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@ function generateContextId() {
16
16
  }
17
17
  // Anything else reaching the native component would hit the generated
18
18
  // string-enum parser, which aborts on unknown values.
19
- const resolveSurfaceType = surfaceType => surfaceType === "SurfaceView" || surfaceType === "TextureView" ? surfaceType : "auto";
19
+ const resolveSurfaceType = surfaceType => surfaceType === "SurfaceView" || surfaceType === "TextureView" || surfaceType === "HardwareBufferView" ? surfaceType : "auto";
20
20
  const Canvas = ({
21
21
  opaque = true,
22
22
  android,
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","CONTEXT_COUNTER","generateContextId","resolveSurfaceType","surfaceType","Canvas","opaque","android","ref","props","viewRef","useRef","contextId","_","useState","useEffect","RNWebGPU","destroyContext","useImperativeHandle","getContextId","getNativeSurface","getContext","contextName","Error","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","View","collapsable","style","flex","androidSurfaceType","androidZOrderOnTop","zOrderOnTop","exports"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,0BAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA2D,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OA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AI,GAC3BA,IAAI,CAACE,qBAAqB,CAAC,CAAC,GAC5BF,IAAI,CAACG,8BAA8B,CAAC,CAAC;MAC3C,OAAOZ,QAAQ,CAACa,uBAAuB,CACrCjB,SAAS,EACTc,IAAI,CAACI,KAAK,EACVJ,IAAI,CAACK,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;EAEH,oBACE7D,MAAA,CAAAQ,OAAA,CAAAsD,aAAA,CAAC3D,YAAA,CAAA4D,IAAI,EAAAtC,QAAA;IAACuC,WAAW,EAAE,KAAM;IAAC1B,GAAG,EAAEE;EAAQ,GAAKD,KAAK,gBAC/CvC,MAAA,CAAAQ,OAAA,CAAAsD,aAAA,CAAC1D,0BAAA,CAAAI,OAAgB;IACfyD,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBxB,SAAS,EAAEA,SAAU;IACrBN,MAAM,EAAEA,MAAO;IACf+B,kBAAkB,EAAElC,kBAAkB,CAACI,OAAO,EAAEH,WAAW,CAAE;IAC7DkC,kBAAkB,EAAE,CAAC,CAAC/B,OAAO,EAAEgC;EAAY,CAC5C,CACG,CAAC;AAEX,CAAC;AAACC,OAAA,CAAAnC,MAAA,GAAAA,MAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","CONTEXT_COUNTER","generateContextId","resolveSurfaceType","surfaceType","Canvas","opaque","android","ref","props","viewRef","useRef","contextId","_","useState","useEffect","RNWebGPU","destroyContext","useImperativeHandle","getContextId","getNativeSurface","getContext","contextName","Error","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","View","collapsable","style","flex","androidSurfaceType","androidZOrderOnTop","zOrderOnTop","exports"],"sourceRoot":"../../src","sources":["Can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I,gBAAgB,CAACR,SAAS,CAAC;IAC7C,CAAC;IACDS,UAAUA,CAACC,WAAqB,EAA0B;MACxD,IAAIA,WAAW,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAIC,KAAK,CAAC,iCAAiCD,WAAW,EAAE,CAAC;MACjE;MACA,IAAI,CAACZ,OAAO,CAACc,OAAO,EAAE;QACpB,MAAM,IAAID,KAAK,CAAC,0CAA0C,CAAC;MAC7D;MACA;MACA;MACA,MAAME,IAAI,GAAGf,OAAO,CAACc,OAAc;MACnC,MAAME,IAAI,GACR,uBAAuB,IAAID,IAAI,GAC3BA,IAAI,CAACE,qBAAqB,CAAC,CAAC,GAC5BF,IAAI,CAACG,8BAA8B,CAAC,CAAC;MAC3C,OAAOZ,QAAQ,CAACa,uBAAuB,CACrCjB,SAAS,EACTc,IAAI,CAACI,KAAK,EACVJ,IAAI,CAACK,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;EAEH,oBACE7D,MAAA,CAAAQ,OAAA,CAAAsD,aAAA,CAAC3D,YAAA,CAAA4D,IAAI,EAAAtC,QAAA;IAACuC,WAAW,EAAE,KAAM;IAAC1B,GAAG,EAAEE;EAAQ,GAAKD,KAAK,gBAC/CvC,MAAA,CAAAQ,OAAA,CAAAsD,aAAA,CAAC1D,0BAAA,CAAAI,OAAgB;IACfyD,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBxB,SAAS,EAAEA,SAAU;IACrBN,MAAM,EAAEA,MAAO;IACf+B,kBAAkB,EAAElC,kBAAkB,CAACI,OAAO,EAAEH,WAAW,CAAE;IAC7DkC,kBAAkB,EAAE,CAAC,CAAC/B,OAAO,EAAEgC;EAAY,CAC5C,CACG,CAAC;AAEX,CAAC;AAACC,OAAA,CAAAnC,MAAA,GAAAA,MAAA","ignoreList":[]}
@@ -8,7 +8,7 @@ function generateContextId() {
8
8
  }
9
9
  // Anything else reaching the native component would hit the generated
10
10
  // string-enum parser, which aborts on unknown values.
11
- const resolveSurfaceType = surfaceType => surfaceType === "SurfaceView" || surfaceType === "TextureView" ? surfaceType : "auto";
11
+ const resolveSurfaceType = surfaceType => surfaceType === "SurfaceView" || surfaceType === "TextureView" || surfaceType === "HardwareBufferView" ? surfaceType : "auto";
12
12
  export const Canvas = ({
13
13
  opaque = true,
14
14
  android,
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEffect","useImperativeHandle","useRef","useState","View","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","resolveSurfaceType","surfaceType","Canvas","opaque","android","ref","props","viewRef","contextId","_","RNWebGPU","destroyContext","getContextId","getNativeSurface","getContext","contextName","Error","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","_extends","collapsable","style","flex","androidSurfaceType","androidZOrderOnTop","zOrderOnTop"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAE/E,SAASC,IAAI,QAAQ,cAAc;AAEnC,OAAOC,gBAAgB,MAAM,6BAA6B;AAE1D,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;AAkEA;AACA;AACA,MAAME,kBAAkB,GACtBC,WAA2C,IAE3CA,WAAW,KAAK,aAAa,IAAIA,WAAW,KAAK,aAAa,GAC1DA,WAAW,GACX,MAAM;AAEZ,OAAO,MAAMC,MAAM,GAAGA,CAAC;EACrBC,MAAM,GAAG,IAAI;EACbC,OAAO;EACPC,GAAG;EACH,GAAGC;AACQ,CAAC,KAAK;EACjB,MAAMC,OAAO,GAAGb,MAAM,CAAC,IAAI,CAAC;EAC5B,MAAM,CAACc,SAAS,EAAEC,CAAC,CAAC,GAAGd,QAAQ,CAAC,MAAMI,iBAAiB,CAAC,CAAC,CAAC;EAC1D;EACA;EACA;EACA;EACA;EACAP,S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3B,OAAO,EAAE4B;EAAY,CAC5C,CACG,CAAC;AAEX,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useEffect","useImperativeHandle","useRef","useState","View","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","resolveSurfaceType","surfaceType","Canvas","opaque","android","ref","props","viewRef","contextId","_","RNWebGPU","destroyContext","getContextId","getNativeSurface","getContext","contextName","Error","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","_extends","collapsable","style","flex","androidSurfaceType","androidZOrderOnTop","zOrderOnTop"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAE/E,SAASC,IAAI,QAAQ,cAAc;AAEnC,OAAOC,gBAAgB,MAAM,6BAA6B;AAE1D,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;AAqEA;AACA;AACA,MAAME,kBAAkB,GACtBC,WAA2C,IAE3CA,WAAW,KAAK,aAAa,IAC7BA,WAAW,KAAK,aAAa,IAC7BA,WAAW,KAAK,oBAAoB,GAChCA,WAAW,GACX,MAAM;AAEZ,OAAO,MAAMC,MAAM,GAAGA,CAAC;EACrBC,MAAM,GAAG,IAAI;EACbC,OAAO;EACPC,GAAG;EACH,GAAGC;AACQ,CAAC,KAAK;EACjB,MAAMC,OAAO,GAAGb,MAAM,CAAC,IAAI,CAAC;EAC5B,MAAM,CAACc,SAAS,EAAEC,CAAC,CAAC,GAAGd,QAAQ,CAAC,MAAMI,iBAAiB,CAAC,CAAC,CAAC;EAC1D;EACA;EACA;EACA;EACA;EACAP,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACXkB,QAAQ,CAACC,cAAc,CAACH,SAAS,CAAC;IACpC,CAAC;EACH,CAAC,EAAE,CAACA,SAAS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
4
+ //# sourceMappingURL=react-native.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native.config.d.ts","sourceRoot":"","sources":["../../react-native.config.js"],"names":[],"mappings":""}
@@ -30,12 +30,14 @@ export interface CanvasRef {
30
30
  getContext(contextName: "webgpu"): RNCanvasContext | null;
31
31
  getNativeSurface: () => NativeCanvas;
32
32
  }
33
- export type AndroidSurfaceType = "SurfaceView" | "TextureView";
33
+ export type AndroidSurfaceType = "SurfaceView" | "TextureView" | "HardwareBufferView";
34
34
  export interface AndroidCanvasProps {
35
35
  /**
36
- * Backing view. Defaults to `SurfaceView` when the canvas is opaque and
37
- * `TextureView` otherwise, which is the only pairing that composites
38
- * correctly in React Native stacking order without further flags.
36
+ * Backing view. Defaults to `SurfaceView` when the canvas is opaque and to
37
+ * `TextureView` otherwise; both composite correctly in React Native
38
+ * stacking order without further flags. `HardwareBufferView` (Android 10+,
39
+ * a plain View that draws each frame's AHardwareBuffer inline with no extra
40
+ * copy) is opt-in and experimental; on older devices it uses `TextureView`.
39
41
  */
40
42
  surfaceType?: AndroidSurfaceType;
41
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IAGrB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAC9D,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAA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type { ViewProps } from "react-native";
3
3
  export interface NativeProps extends ViewProps {
4
4
  contextId: Int32;
5
5
  opaque?: WithDefault<boolean, true>;
6
- androidSurfaceType?: WithDefault<"auto" | "SurfaceView" | "TextureView", "auto">;
6
+ androidSurfaceType?: WithDefault<"auto" | "SurfaceView" | "TextureView" | "HardwareBufferView", "auto">;
7
7
  androidZOrderOnTop?: WithDefault<boolean, false>;
8
8
  }
9
9
  declare const _default: import("react-native").HostComponent<NativeProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"WebGPUViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACZ,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACpC,kBAAkB,CAAC,EAAE,WAAW,CAC9B,MAAM,GAAG,aAAa,GAAG,aAAa,EACtC,MAAM,CACP,CAAC;IACF,kBAAkB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CAClD;;AAGD,wBAAiE"}
1
+ {"version":3,"file":"WebGPUViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACZ,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACpC,kBAAkB,CAAC,EAAE,WAAW,CAC9B,MAAM,GAAG,aAAa,GAAG,aAAa,GAAG,oBAAoB,EAC7D,MAAM,CACP,CAAC;IACF,kBAAkB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CAClD;;AAGD,wBAAiE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-webgpu",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -21,6 +21,7 @@
21
21
  "libs/**",
22
22
  "*.podspec",
23
23
  "Package.swift",
24
+ "react-native.config.js",
24
25
  "app.plugin.js",
25
26
  "plugin/build/**"
26
27
  ],
@@ -14,15 +14,14 @@ Pod::Spec.new do |s|
14
14
  s.platforms = { :ios => min_ios_version_supported, :osx => "10.15", :visionos => "1.0" }
15
15
  s.source = { :git => "https://github.com/wcandillon/react-native-webgpu.git", :tag => "#{s.version}" }
16
16
 
17
- # RN's autolinking and codegen both key off this podspec being present and
18
- # supporting the platform (see react-native.config.js docs: there is no way
19
- # to disable CocoaPods linking for a dependency without also disabling
20
- # codegen for it). So when the app links react-native-webgpu via the local
21
- # Swift Package (packages/webgpu/Package.swift) instead of CocoaPods, this
22
- # pod still needs to exist to keep the RNWgpuViewSpec codegen output
23
- # flowing — it just shouldn't compile or link anything itself, or the app
24
- # would get the native module twice. Set RNWGPU_USE_SPM=1 before
25
- # `pod install` for that case.
17
+ # CocoaPods is the supported default. Package.swift (React Native 0.87+
18
+ # SwiftPM autolinking) is additive: SwiftPM ignores this podspec, and
19
+ # CocoaPods ignores Package.swift. An app links through one or the other,
20
+ # never both, so set RNWGPU_USE_SPM=1 before `pod install` when linking
21
+ # through the Swift package instead: RN's autolinking and codegen both key
22
+ # off this podspec being present, so it still needs to exist, but it must
23
+ # not compile or vendor anything itself or the app gets the native module
24
+ # twice.
26
25
  if ENV['RNWGPU_USE_SPM']
27
26
  # The Swift package resolves React Native's headers from the
28
27
  # static-library Pods layout (Pods/Headers/Public). With `use_frameworks!`
@@ -0,0 +1,6 @@
1
+ // Pins the SwiftPM target name. Without it the name is derived: today from the
2
+ // npm name (ReactNativeWebgpu), but an in-flight React Native change derives it
3
+ // from the podspec instead. The name is also the header import prefix, so it
4
+ // must not move. Package.swift declares the same name for its package, product
5
+ // and target; scripts/package-swift-template.ts carries it as SWIFT_PACKAGE_NAME.
6
+ module.exports = { spm: { name: "ReactNativeWebGPU" } };
package/src/Canvas.tsx CHANGED
@@ -45,13 +45,16 @@ export interface CanvasRef {
45
45
  getNativeSurface: () => NativeCanvas;
46
46
  }
47
47
 
48
- export type AndroidSurfaceType = "SurfaceView" | "TextureView";
48
+ export type AndroidSurfaceType =
49
+ "SurfaceView" | "TextureView" | "HardwareBufferView";
49
50
 
50
51
  export interface AndroidCanvasProps {
51
52
  /**
52
- * Backing view. Defaults to `SurfaceView` when the canvas is opaque and
53
- * `TextureView` otherwise, which is the only pairing that composites
54
- * correctly in React Native stacking order without further flags.
53
+ * Backing view. Defaults to `SurfaceView` when the canvas is opaque and to
54
+ * `TextureView` otherwise; both composite correctly in React Native
55
+ * stacking order without further flags. `HardwareBufferView` (Android 10+,
56
+ * a plain View that draws each frame's AHardwareBuffer inline with no extra
57
+ * copy) is opt-in and experimental; on older devices it uses `TextureView`.
55
58
  */
56
59
  surfaceType?: AndroidSurfaceType;
57
60
  /**
@@ -78,7 +81,9 @@ export interface CanvasProps extends ViewProps {
78
81
  const resolveSurfaceType = (
79
82
  surfaceType: AndroidSurfaceType | undefined,
80
83
  ): "auto" | AndroidSurfaceType =>
81
- surfaceType === "SurfaceView" || surfaceType === "TextureView"
84
+ surfaceType === "SurfaceView" ||
85
+ surfaceType === "TextureView" ||
86
+ surfaceType === "HardwareBufferView"
82
87
  ? surfaceType
83
88
  : "auto";
84
89
 
@@ -9,7 +9,7 @@ export interface NativeProps extends ViewProps {
9
9
  contextId: Int32;
10
10
  opaque?: WithDefault<boolean, true>;
11
11
  androidSurfaceType?: WithDefault<
12
- "auto" | "SurfaceView" | "TextureView",
12
+ "auto" | "SurfaceView" | "TextureView" | "HardwareBufferView",
13
13
  "auto"
14
14
  >;
15
15
  androidZOrderOnTop?: WithDefault<boolean, false>;
@@ -1,298 +0,0 @@
1
- package com.webgpu;
2
-
3
- import android.annotation.SuppressLint;
4
- import android.content.Context;
5
- import android.graphics.Bitmap;
6
- import android.graphics.Canvas;
7
- import android.graphics.Paint;
8
- import android.graphics.PixelFormat;
9
- import android.graphics.Rect;
10
- import android.hardware.HardwareBuffer;
11
- import android.media.Image;
12
- import android.media.ImageReader;
13
- import android.os.Build;
14
- import android.os.Handler;
15
- import android.os.Looper;
16
- import android.view.Surface;
17
- import android.view.View;
18
-
19
- import androidx.annotation.NonNull;
20
- import androidx.annotation.RequiresApi;
21
-
22
- import java.nio.ByteBuffer;
23
-
24
- @RequiresApi(api = Build.VERSION_CODES.Q)
25
- @SuppressLint("ViewConstructor")
26
- public class WebGPUAHBView extends View implements ImageReader.OnImageAvailableListener {
27
-
28
- private static final int MAX_IMAGES = 3;
29
- private static final String TAG = "WebGPUAHBView";
30
-
31
- private final WebGPUAPI mApi;
32
- private ImageReader mImageReader;
33
- private Surface mSurface;
34
- private Image mCurrentImage;
35
- private Bitmap mCachedBitmap;
36
- private final Paint mPaint;
37
- private final Handler mHandler;
38
- private final Object mImageLock = new Object();
39
- private boolean mSurfaceCreated = false;
40
- private int mConfiguredWidth = 0;
41
- private int mConfiguredHeight = 0;
42
-
43
- public WebGPUAHBView(Context context, WebGPUAPI api) {
44
- super(context);
45
- mApi = api;
46
- mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
47
- mHandler = new Handler(Looper.getMainLooper());
48
-
49
- // Enable hardware acceleration for this view
50
- setLayerType(LAYER_TYPE_HARDWARE, null);
51
-
52
- // Make sure we get drawn
53
- setWillNotDraw(false);
54
- }
55
-
56
- @Override
57
- protected void onSizeChanged(int w, int h, int oldw, int oldh) {
58
- super.onSizeChanged(w, h, oldw, oldh);
59
-
60
- if (w > 0 && h > 0) {
61
- // Recreate ImageReader with new dimensions
62
- setupImageReader(w, h);
63
- }
64
- }
65
-
66
- private void setupImageReader(int width, int height) {
67
- // Don't recreate if dimensions haven't changed
68
- if (width == mConfiguredWidth && height == mConfiguredHeight && mImageReader != null) {
69
- return;
70
- }
71
-
72
- // Clean up previous ImageReader
73
- cleanupImageReader();
74
-
75
- try {
76
- // Create ImageReader with HardwareBuffer support
77
- mImageReader = ImageReader.newInstance(
78
- width,
79
- height,
80
- PixelFormat.RGBA_8888,
81
- MAX_IMAGES,
82
- HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE |
83
- HardwareBuffer.USAGE_GPU_COLOR_OUTPUT |
84
- HardwareBuffer.USAGE_COMPOSER_OVERLAY |
85
- HardwareBuffer.USAGE_CPU_READ_RARELY // For fallback to Bitmap if needed
86
- );
87
-
88
- mImageReader.setOnImageAvailableListener(this, mHandler);
89
-
90
- // Get the Surface for WebGPU to render to
91
- mSurface = mImageReader.getSurface();
92
-
93
- mConfiguredWidth = width;
94
- mConfiguredHeight = height;
95
-
96
- // Notify WebGPU about the new surface
97
- if (!mSurfaceCreated) {
98
- mApi.surfaceCreated(mSurface);
99
- mSurfaceCreated = true;
100
- } else {
101
- mApi.surfaceChanged(mSurface);
102
- }
103
-
104
- } catch (Exception e) {
105
- e.printStackTrace();
106
- // Fallback to offscreen if ImageReader creation fails
107
- mApi.surfaceOffscreen();
108
- }
109
- }
110
-
111
- @Override
112
- public void onImageAvailable(ImageReader reader) {
113
- synchronized (mImageLock) {
114
- // Close previous image if exists
115
- if (mCurrentImage != null) {
116
- mCurrentImage.close();
117
- mCurrentImage = null;
118
- }
119
-
120
- try {
121
- // Get the latest image
122
- mCurrentImage = reader.acquireLatestImage();
123
-
124
- if (mCurrentImage != null) {
125
- // Request a redraw on the UI thread
126
- postInvalidateOnAnimation();
127
- }
128
- } catch (Exception e) {
129
- e.printStackTrace();
130
- }
131
- }
132
- }
133
-
134
- @Override
135
- protected void onDraw(Canvas canvas) {
136
- super.onDraw(canvas);
137
-
138
- synchronized (mImageLock) {
139
- if (mCurrentImage == null) {
140
- return;
141
- }
142
-
143
- try {
144
- // Try to use HardwareBuffer directly (most efficient path)
145
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
146
- HardwareBuffer hardwareBuffer = mCurrentImage.getHardwareBuffer();
147
-
148
- if (hardwareBuffer != null) {
149
- // Draw using HardwareBuffer
150
- drawHardwareBuffer(canvas, hardwareBuffer);
151
- return;
152
- }
153
- }
154
-
155
- // Fallback: Convert Image to Bitmap
156
- drawImageAsBitmap(canvas, mCurrentImage);
157
-
158
- } catch (Exception e) {
159
- e.printStackTrace();
160
- }
161
- }
162
- }
163
-
164
- private void drawHardwareBuffer(Canvas canvas, HardwareBuffer hardwareBuffer) {
165
- // On Android Q+, we can create a Bitmap from HardwareBuffer
166
- try {
167
- // Create or reuse bitmap with matching dimensions
168
- if (mCachedBitmap == null ||
169
- mCachedBitmap.getWidth() != hardwareBuffer.getWidth() ||
170
- mCachedBitmap.getHeight() != hardwareBuffer.getHeight()) {
171
-
172
- if (mCachedBitmap != null) {
173
- mCachedBitmap.recycle();
174
- }
175
-
176
- // Create a hardware-backed Bitmap from the HardwareBuffer
177
- mCachedBitmap = Bitmap.wrapHardwareBuffer(hardwareBuffer, null);
178
- } else {
179
- // Reuse existing bitmap and update with new HardwareBuffer content
180
- mCachedBitmap = Bitmap.wrapHardwareBuffer(hardwareBuffer, null);
181
- }
182
-
183
- if (mCachedBitmap != null) {
184
- // Draw the bitmap to canvas
185
- canvas.drawBitmap(mCachedBitmap, 0, 0, mPaint);
186
- }
187
- } catch (Exception e) {
188
- e.printStackTrace();
189
- // Fallback to Image-based rendering
190
- drawImageAsBitmap(canvas, mCurrentImage);
191
- }
192
- }
193
-
194
- private void drawImageAsBitmap(Canvas canvas, Image image) {
195
- // Fallback method: manually convert Image to Bitmap
196
- if (image.getFormat() != PixelFormat.RGBA_8888) {
197
- return;
198
- }
199
-
200
- Image.Plane[] planes = image.getPlanes();
201
- if (planes.length == 0) {
202
- return;
203
- }
204
-
205
- ByteBuffer buffer = planes[0].getBuffer();
206
- int pixelStride = planes[0].getPixelStride();
207
- int rowStride = planes[0].getRowStride();
208
- int rowPadding = rowStride - pixelStride * image.getWidth();
209
-
210
- // Create or reuse bitmap
211
- int bitmapWidth = image.getWidth() + rowPadding / pixelStride;
212
- if (mCachedBitmap == null ||
213
- mCachedBitmap.getWidth() != bitmapWidth ||
214
- mCachedBitmap.getHeight() != image.getHeight()) {
215
-
216
- if (mCachedBitmap != null) {
217
- mCachedBitmap.recycle();
218
- }
219
- mCachedBitmap = Bitmap.createBitmap(
220
- bitmapWidth,
221
- image.getHeight(),
222
- Bitmap.Config.ARGB_8888
223
- );
224
- }
225
-
226
- mCachedBitmap.copyPixelsFromBuffer(buffer);
227
-
228
- // Draw only the valid portion (without padding)
229
- Rect src = new Rect(0, 0, image.getWidth(), image.getHeight());
230
- Rect dst = new Rect(0, 0, getWidth(), getHeight());
231
- canvas.drawBitmap(mCachedBitmap, src, dst, mPaint);
232
- }
233
-
234
- private void cleanupImageReader() {
235
- synchronized (mImageLock) {
236
- if (mCurrentImage != null) {
237
- mCurrentImage.close();
238
- mCurrentImage = null;
239
- }
240
-
241
- if (mImageReader != null) {
242
- mImageReader.close();
243
- mImageReader = null;
244
- }
245
-
246
- if (mSurface != null) {
247
- mSurface.release();
248
- mSurface = null;
249
- }
250
- }
251
- }
252
-
253
- @Override
254
- protected void onDetachedFromWindow() {
255
- super.onDetachedFromWindow();
256
-
257
- // Detach: rendering falls back to the offscreen texture until reattach.
258
- if (mSurfaceCreated) {
259
- mApi.surfaceOffscreen();
260
- mSurfaceCreated = false;
261
- }
262
-
263
- // Clean up resources
264
- cleanupImageReader();
265
-
266
- if (mCachedBitmap != null) {
267
- mCachedBitmap.recycle();
268
- mCachedBitmap = null;
269
- }
270
- }
271
-
272
- @Override
273
- protected void onAttachedToWindow() {
274
- super.onAttachedToWindow();
275
-
276
- // Re-setup if we have valid dimensions
277
- if (getWidth() > 0 && getHeight() > 0) {
278
- setupImageReader(getWidth(), getHeight());
279
- }
280
- }
281
-
282
- @Override
283
- public void setAlpha(float alpha) {
284
- super.setAlpha(alpha);
285
- mPaint.setAlpha((int) (alpha * 255));
286
- invalidate();
287
- }
288
-
289
- @Override
290
- protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
291
- super.onVisibilityChanged(changedView, visibility);
292
-
293
- if (visibility == VISIBLE && mSurface == null && getWidth() > 0 && getHeight() > 0) {
294
- // Re-create surface if needed when becoming visible
295
- setupImageReader(getWidth(), getHeight());
296
- }
297
- }
298
- }