public LoadResult CheckLoading(IntPtr wrapper, EntityManager man, Entity e, ref Image2D image, ref Image2DHTML imgHTML, ref Image2DLoadFromFile unused, ref Image2DHTMLLoading loading) { int r = ImageIOHTMLNativeCalls.JSCheckLoadImage(imgHTML.imageIndex); if (r == 0) { return(LoadResult.stillWorking); } var fnLog = man.GetBufferAsString <Image2DLoadFromFileImageFile>(e); if (man.HasComponent <Image2DLoadFromFileMaskFile>(e)) { fnLog += " alpha="; fnLog += man.GetBufferAsString <Image2DLoadFromFileMaskFile>(e); } if (r == 2) { image.status = ImageStatus.LoadError; image.imagePixelHeight = 0; image.imagePixelWidth = 0; FreeNative(man, e, ref imgHTML); Debug.Log("Failed to load " + fnLog); return(LoadResult.failed); } int wi = 0; int hi = 0; int ai = 0; ImageIOHTMLNativeCalls.JSFinishLoadImage(imgHTML.imageIndex, ref wi, ref hi, ref ai); image.imagePixelHeight = hi; image.imagePixelWidth = wi; image.status = ImageStatus.Loaded; imgHTML.externalOwner = false; #if IO_ENABLE_TRACE var s = $"Loaded image: {fnLog} size: {wi}, {hi} "; if (ai != 0) { s += " (has alpha channel)"; } s += $" idx: {imgHTML.imageIndex}"; Debug.Log(s); #endif #if ENABLE_DOTSPLAYER_PROFILER ProfilerStats.AccumStats.memTextureCount.Accumulate(1); long bytes = image.imagePixelWidth * image.imagePixelHeight * 4; ProfilerStats.AccumStats.memTexture.Accumulate(bytes); ProfilerStats.AccumStats.memReservedGFX.Accumulate(bytes); ProfilerStats.AccumStats.memUsedGFX.Accumulate(bytes); // WebGL image loading doesn't use our unsafeutility heap allocator so we need to track our own stats ProfilerStats.AccumStats.memReservedExternal.Accumulate(bytes); ProfilerStats.AccumStats.memUsedExternal.Accumulate(bytes); #endif return(LoadResult.success); }
public LoadResult CheckLoading(IntPtr wrapper, EntityManager man, Entity e, ref Image2D image, ref Image2DHTML imgHTML, ref Image2DLoadFromFile unused, ref Image2DHTMLLoading loading) { int r = ImageIOHTMLNativeCalls.JSCheckLoadImage(imgHTML.imageIndex); if (r == 0) { return(LoadResult.stillWorking); } var fnLog = man.GetBufferAsString <Image2DLoadFromFileImageFile>(e); if (man.HasComponent <Image2DLoadFromFileMaskFile>(e)) { fnLog += " alpha="; fnLog += man.GetBufferAsString <Image2DLoadFromFileMaskFile>(e); } if (r == 2) { image.status = ImageStatus.LoadError; image.imagePixelHeight = 0; image.imagePixelWidth = 0; FreeNative(man, e, ref imgHTML); Console.WriteLine("Failed to load " + fnLog); return(LoadResult.failed); } int wi = 0; int hi = 0; int ai = 0; ImageIOHTMLNativeCalls.JSFinishLoadImage(imgHTML.imageIndex, ref wi, ref hi, ref ai); image.imagePixelHeight = hi; image.imagePixelWidth = wi; image.status = ImageStatus.Loaded; imgHTML.externalOwner = false; #if DEBUG var s = $"Loaded image: {fnLog} size: {wi}, {hi} "; if (ai != 0) { s += " (has alpha channel)"; } s += $" idx: {imgHTML.imageIndex}"; Debug.Log(s); #endif return(LoadResult.success); }