@@ -428,6 +428,9 @@ class Video extends openfl.display.Bitmap
428428 @:noCompletion
429429 private var texturePlanes : Null <BytesData >;
430430
431+ @:noCompletion
432+ private var texturePlanesArray : Null <UInt8Array >;
433+
431434 #if lime_openal
432435 @:noCompletion
433436 private var alUseEXTFLOAT32 : Null <Bool >;
@@ -870,9 +873,15 @@ class Video extends openfl.display.Bitmap
870873 bitmapData .dispose ();
871874 }
872875
876+ if (texturePlanes != null )
877+ {
878+ texturePlanes .setSize (0 );
879+ texturePlanes = null ;
880+ }
881+
873882 textureWidth = 0 ;
874883 textureHeight = 0 ;
875- texturePlanes = null ;
884+ texturePlanesArray = null ;
876885 }
877886
878887 textureMutex .release ();
@@ -1339,7 +1348,9 @@ class Video extends openfl.display.Bitmap
13391348 if (texturePlanes == null )
13401349 texturePlanes = new BytesData ();
13411350
1342- texturePlanes .resize (textureWidth * textureHeight * 4 );
1351+ texturePlanes .setSize (textureWidth * textureHeight * 4 );
1352+
1353+ texturePlanesArray = UInt8Array .fromBytes (Bytes .ofData (texturePlanes ));
13431354
13441355 pitches [0 ] = textureWidth * 4 ;
13451356 lines [0 ] = textureHeight ;
@@ -1354,10 +1365,11 @@ class Video extends openfl.display.Bitmap
13541365 textureMutex .acquire ();
13551366
13561367 final sizeMismatch : Bool = bitmapData != null && (bitmapData .width != textureWidth || bitmapData .height != textureHeight );
1357- final textureMismatch : Bool = bitmapData != null && bitmapData .__texture != null && ! useTexture ;
1358- final imageMismatch : Bool = bitmapData != null && bitmapData .image != null && useTexture ;
1368+ final dataMismatch : Bool = bitmapData != null && (
1369+ if (useTexture ) bitmapData .image != null && Lib .current .stage ?. context3D != null
1370+ else bitmapData .__texture != null );
13591371
1360- if (bitmapData == null || sizeMismatch || textureMismatch || imageMismatch )
1372+ if (bitmapData == null || sizeMismatch || dataMismatch )
13611373 {
13621374 if (bitmapData != null )
13631375 {
@@ -1367,28 +1379,32 @@ class Video extends openfl.display.Bitmap
13671379 bitmapData .dispose ();
13681380 }
13691381
1370- bitmapData = new BitmapData (textureWidth , textureHeight , true , 0 );
1371-
1382+ if (useTexture )
13721383 {
13731384 @:privateAccess
1374- if (useTexture )
1385+ if (Lib . current . stage ?. context3D != null )
13751386 {
1376- @:nullSafety (Off )
1377- if (Lib .current .stage ?. context3D != null )
1378- {
1379- bitmapData .disposeImage ();
1387+ // This creates an image-less BitmapData
1388+ bitmapData = new BitmapData (0 , 0 , true , 0 );
13801389
1381- {
1382- bitmapData .__texture = new VideoTexture (Lib .current .stage .context3D , bitmapData , textureWidth * textureHeight * 4 );
1383- bitmapData .__textureContext = bitmapData .__texture .__textureContext ;
1384- bitmapData .__surface = null ;
1385- }
1390+ // Because the BitmapData doesnt have an image we set the bounds of it here
1391+ bitmapData .rect .setTo (0 , 0 , textureWidth , textureHeight );
13861392
1387- bitmapData .image = null ;
1388- }
1389- else
1390- trace (' Unable to utilize GPU texture, resorting to CPU-based image rendering.' );
1393+ // Allocates the Texture here so its a GPU BitmapData
1394+ bitmapData .__texture = new VideoTexture (Lib .current .stage .context3D , textureWidth , textureHeight , texturePlanesArray );
1395+ bitmapData .__textureContext = bitmapData .__texture .__textureContext ;
1396+ bitmapData .__resize (textureWidth , textureHeight );
1397+ bitmapData .__isValid = true ;
13911398 }
1399+ else
1400+ {
1401+ trace (' Unable to utilize GPU texture, resorting to CPU-based image rendering.' );
1402+ bitmapData = new BitmapData (textureWidth , textureHeight , true , 0 );
1403+ }
1404+ }
1405+ else
1406+ {
1407+ bitmapData = new BitmapData (textureWidth , textureHeight , true , 0 );
13921408 }
13931409
13941410 if (onFormatSetup != null )
@@ -1729,8 +1745,14 @@ class Video extends openfl.display.Bitmap
17291745
17301746 if (texturePlanes != null )
17311747 {
1732- bitmapData .image .buffer .data = UInt8Array .fromBytes (Bytes .ofData (texturePlanes ));
1748+ final dest : RawPointer <cpp. Void > = untyped bitmapData .image .buffer .data .buffer .getData ().getBase ().getBase ();
1749+
1750+ final src : RawConstPointer <cpp. Void > = untyped texturePlanes .getBase ().getBase ();
1751+
1752+ Stdlib .nativeMemcpy (dest , src , bitmapData .image .buffer .data .buffer .byteLength );
1753+
17331754 bitmapData .image .dirty = true ;
1755+
17341756 bitmapData .image .version ++ ;
17351757 }
17361758
@@ -1747,7 +1769,7 @@ class Video extends openfl.display.Bitmap
17471769 {
17481770 MainLoop .runInMainThread (function (): Void
17491771 {
1750- if (! isValid () || bitmapData == null || texturePlanes == null )
1772+ if (! isValid () || bitmapData == null || texturePlanesArray == null )
17511773 return ;
17521774
17531775 textureMutex .acquire ();
@@ -1756,7 +1778,9 @@ class Video extends openfl.display.Bitmap
17561778
17571779 if (texture != null )
17581780 {
1759- texture .uploadFromTypedArray (UInt8Array .fromBytes (Bytes .ofData (texturePlanes )));
1781+ texture .uploadFromTypedArray (texturePlanesArray );
1782+
1783+ bitmapData .__textureVersion ++ ;
17601784
17611785 if (__renderable )
17621786 __setRenderDirty ();
0 commit comments