@@ -23,6 +23,43 @@ public static Image makeRaster(ImageInfo imageInfo, byte[] bytes, long rowBytes)
2323 return makeRasterFromBytes (imageInfo , bytes , rowBytes );
2424 }
2525
26+ /**
27+ * <p>Creates Image from an OpenGL texture.</p>
28+ *
29+ * <p>Image is returned if the texture is valid. Valid texture parameters include:</p>
30+ * <ul>
31+ * <li>textureId is a valid OpenGL texture ID;</li>
32+ * <li>width and height are greater than zero;</li>
33+ * <li>ColorType and AlphaType are valid, and ColorType is not ColorType.UNKNOWN;</li>
34+ * <li>colorSpace is a valid SkColorSpace;</li>
35+ * </ul>
36+ *
37+ * @param context GrDirectContext
38+ * @param textureId OpenGL texture ID
39+ * @param width width of the texture
40+ * @param height height of the texture
41+ * @param colorType color type of the texture
42+ * @return Image
43+ */
44+ public static Image adoptGLTextureFrom (DirectContext context , int textureId , int target , int width , int height , int format , SurfaceOrigin surfaceOrigin , ColorType colorType ) {
45+ try {
46+ Stats .onNativeCall ();
47+ long ptr = _nAdoptGLTextureFrom (Native .getPtr (context ),
48+ textureId ,
49+ target ,
50+ width ,
51+ height ,
52+ format ,
53+ surfaceOrigin .ordinal (),
54+ colorType .ordinal ());
55+ if (ptr == 0 )
56+ throw new RuntimeException ("Failed to adoptGLTextureFrom " + textureId + " " + width + "x" + height );
57+ return new Image (ptr );
58+ } finally {
59+ ReferenceUtil .reachabilityFence (context );
60+ }
61+ }
62+
2663 /**
2764 * <p>Creates Image from pixels.</p>
2865 *
@@ -382,6 +419,7 @@ public boolean scalePixels(@NotNull Pixmap dst, SamplingMode samplingMode, boole
382419 }
383420 }
384421
422+ @ ApiStatus .Internal public static native long _nAdoptGLTextureFrom (long contextPtr , int textureId , int target , int width , int height , int format , int surfaceOrigin , int colorType );
385423 @ ApiStatus .Internal public static native long _nMakeRasterFromBytes (int width , int height , int colorType , int alphaType , long colorSpacePtr , byte [] pixels , long rowBytes );
386424 @ ApiStatus .Internal public static native long _nMakeRasterFromData (int width , int height , int colorType , int alphaType , long colorSpacePtr , long dataPtr , long rowBytes );
387425 @ ApiStatus .Internal public static native long _nMakeRasterFromBitmap (long bitmapPtr );
0 commit comments