public static unsafe void Execute(List <PSDLayer> extractedLayer, List <BitmapLayer> layers, bool importHiddenLayer, PSDImporter.FlattenLayerData[] previousFlattenLayer, IPSDLayerMappingStrategy mappingStrategy) { UnityEngine.Profiling.Profiler.BeginSample("ExtractLayer_PrepareJob"); List <LayerExtractData> layerToExtract = new List <LayerExtractData>(); ExtractLayer(extractedLayer, layers, importHiddenLayer, false, layerToExtract, previousFlattenLayer, mappingStrategy, true); if (layerToExtract.Count == 0) { foreach (var l in extractedLayer) { l.texture = default; } return; } var job = new ConvertBufferJob(); job.original = new NativeArray <IntPtr>(extractedLayer.Count, Allocator.TempJob); job.output = new NativeArray <IntPtr>(layerToExtract.Count, Allocator.TempJob); job.width = new NativeArray <int>(extractedLayer.Count, Allocator.TempJob); job.height = new NativeArray <int>(extractedLayer.Count, Allocator.TempJob); for (int i = 0, extractLayerIndex = 0; i < extractedLayer.Count; ++i) { var el = extractedLayer[i]; job.original[i] = el.texture.IsCreated ? new IntPtr(el.texture.GetUnsafePtr()) : IntPtr.Zero; if (extractLayerIndex < layerToExtract.Count && layerToExtract[extractLayerIndex].start == i) { el.texture = new NativeArray <Color32>(layerToExtract[extractLayerIndex].width * layerToExtract[extractLayerIndex].height, Allocator.Persistent); job.output[extractLayerIndex] = el.texture.IsCreated ? new IntPtr(el.texture.GetUnsafePtr()) : IntPtr.Zero; ++extractLayerIndex; } else { el.texture = default; } job.width[i] = el.width; job.height[i] = el.height; } job.flattenIndex = new NativeArray <LayerExtractData>(layerToExtract.ToArray(), Allocator.TempJob); var jobsPerThread = layerToExtract.Count / (SystemInfo.processorCount == 0 ? 8 : SystemInfo.processorCount); jobsPerThread = Mathf.Max(jobsPerThread, 1); var handle = job.Schedule(layerToExtract.Count, jobsPerThread); UnityEngine.Profiling.Profiler.EndSample(); handle.Complete(); }
public static unsafe void Execute(List <PSDLayer> extractedLayer, List <BitmapLayer> layers, bool importHiddenLayer) { UnityEngine.Profiling.Profiler.BeginSample("ExtractLayer_PrepareJob"); var tempExtractLayer = new List <PSDLayer>(); int layerWithBuffer = ExtractLayer(tempExtractLayer, layers, importHiddenLayer); if (layerWithBuffer == 0) { return; } var job = new ConvertBufferJob(); job.original = new NativeArray <IntPtr>(layerWithBuffer, Allocator.TempJob); job.output = new NativeArray <IntPtr>(layerWithBuffer, Allocator.TempJob); job.width = new NativeArray <int>(layerWithBuffer, Allocator.TempJob); job.height = new NativeArray <int>(layerWithBuffer, Allocator.TempJob); for (int i = 0, jobIndex = 0; i < tempExtractLayer.Count; ++i) { var el = tempExtractLayer[i]; if (el.texture.Length == 0 || el.width == 0 || el.height == 0) { extractedLayer.Add(el); continue; } job.original[jobIndex] = new IntPtr(el.texture.GetUnsafeReadOnlyPtr()); el.texture = new NativeArray <Color32>(el.texture.Length, Allocator.Persistent); extractedLayer.Add(el); job.output[jobIndex] = new IntPtr(el.texture.GetUnsafePtr()); job.width[jobIndex] = el.width; job.height[jobIndex] = el.height; ++jobIndex; } var jobsPerThread = layerWithBuffer / (SystemInfo.processorCount == 0 ? 8 : SystemInfo.processorCount); jobsPerThread = Mathf.Max(jobsPerThread, 1); var handle = job.Schedule(layerWithBuffer, jobsPerThread); UnityEngine.Profiling.Profiler.EndSample(); handle.Complete(); }