Beispiel #1
0
    private IEnumerator WaitForTextureFrame(Action <TextureFrame> callback)
    {
        TextureFrame nextFrame = null;

        lock (((ICollection)availableTextureFrames).SyncRoot) {
            yield return(new WaitUntil(() => {
                return poolSize > frameCount || availableTextureFrames.Count > 0;
            }));

            while (availableTextureFrames.Count > 0)
            {
                var textureFrame = availableTextureFrames.Dequeue();

                if (!IsStale(textureFrame))
                {
                    nextFrame = textureFrame;
                    break;
                }
            }

            if (nextFrame == null)
            {
                nextFrame = CreateNewTextureFrame();
            }
        }

        callback(nextFrame);

        lock (((ICollection)textureFramesInUse).SyncRoot) {
            textureFramesInUse.Add((UInt64)nextFrame.GetNativeTexturePtr(false), nextFrame);
        }
    }