@@ -78,3 +78,84 @@ void deviceBufferOverwriteThrowsForNegativeDestinationOffset() {
7878 }
7979 assert (exception! .contains ('destinationOffsetInBytes must be positive' ));
8080}
81+
82+ @pragma ('vm:entry-point' )
83+ void canCreateTexture () {
84+ final gpu.Texture ? texture =
85+ gpu.gpuContext.createTexture (gpu.StorageMode .hostVisible, 100 , 100 );
86+ assert (texture != null );
87+
88+ // Check the defaults.
89+ assert (
90+ texture! .coordinateSystem == gpu.TextureCoordinateSystem .renderToTexture);
91+ assert (texture! .width == 100 );
92+ assert (texture! .height == 100 );
93+ assert (texture! .storageMode == gpu.StorageMode .hostVisible);
94+ assert (texture! .sampleCount == 1 );
95+ assert (texture! .format == gpu.PixelFormat .r8g8b8a8UNormInt);
96+ assert (texture! .enableRenderTargetUsage == true );
97+ assert (texture! .enableShaderReadUsage == true );
98+ assert (texture! .enableShaderWriteUsage == false );
99+ assert (texture! .bytesPerTexel == 4 );
100+ assert (texture! .GetBaseMipLevelSizeInBytes () == 40000 );
101+ }
102+
103+ @pragma ('vm:entry-point' )
104+ void canOverwriteTexture () {
105+ final gpu.Texture ? texture =
106+ gpu.gpuContext.createTexture (gpu.StorageMode .hostVisible, 2 , 2 );
107+ assert (texture != null );
108+ final ui.Color red = ui.Color .fromARGB (0xFF , 0xFF , 0 , 0 );
109+ final ui.Color green = ui.Color .fromARGB (0xFF , 0 , 0xFF , 0 );
110+ final bool success = texture! .overwrite (
111+ Int32List .fromList (< int > [red.value, green.value, green.value, red.value])
112+ .buffer
113+ .asByteData ());
114+ assert (success);
115+ }
116+
117+ @pragma ('vm:entry-point' )
118+ void textureOverwriteThrowsForWrongBufferSize () {
119+ final gpu.Texture ? texture =
120+ gpu.gpuContext.createTexture (gpu.StorageMode .hostVisible, 100 , 100 );
121+ assert (texture != null );
122+ final ui.Color red = ui.Color .fromARGB (0xFF , 0xFF , 0 , 0 );
123+ String ? exception;
124+ try {
125+ texture! .overwrite (
126+ Int32List .fromList (< int > [red.value, red.value, red.value, red.value])
127+ .buffer
128+ .asByteData ());
129+ } catch (e) {
130+ exception = e.toString ();
131+ }
132+ assert (exception! .contains (
133+ 'The length of sourceBytes (bytes: 16) must exactly match the size of the base mip level (bytes: 40000)' ));
134+ }
135+
136+ @pragma ('vm:entry-point' )
137+ void textureAsImageReturnsAValidUIImageHandle () {
138+ final gpu.Texture ? texture =
139+ gpu.gpuContext.createTexture (gpu.StorageMode .hostVisible, 100 , 100 );
140+ assert (texture != null );
141+
142+ final ui.Image image = texture! .asImage ();
143+ assert (image.width == 100 );
144+ assert (image.height == 100 );
145+ }
146+
147+ @pragma ('vm:entry-point' )
148+ void textureAsImageThrowsWhenNotShaderReadable () {
149+ final gpu.Texture ? texture = gpu.gpuContext.createTexture (
150+ gpu.StorageMode .hostVisible, 100 , 100 ,
151+ enableShaderReadUsage: false );
152+ assert (texture != null );
153+ String ? exception;
154+ try {
155+ texture! .asImage ();
156+ } catch (e) {
157+ exception = e.toString ();
158+ }
159+ assert (exception! .contains (
160+ 'Only shader readable Flutter GPU textures can be used as UI Images' ));
161+ }
0 commit comments