Пример #1
0
        void OnTextureFrameRelease(TextureFrame textureFrame)
        {
            lock (((ICollection)textureFramesInUse).SyncRoot) {
                if (!textureFramesInUse.Remove(textureFrame.GetInstanceID()))
                {
                    // won't be run
                    Logger.LogWarning(TAG, "The released texture does not belong to the pool");
                    return;
                }

                if (frameCount > poolSize || IsStale(textureFrame))
                {
                    return;
                }
                availableTextureFrames.Enqueue(textureFrame);
            }
        }
        public bool TryGetTextureFrame(out TextureFrame outFrame)
        {
            TextureFrame nextFrame = null;

            lock (((ICollection)_availableTextureFrames).SyncRoot)
            {
                if (_poolSize <= frameCount)
                {
                    while (_availableTextureFrames.Count > 0)
                    {
                        var textureFrame = _availableTextureFrames.Dequeue();

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

            if (nextFrame == null)
            {
                outFrame = null;
                return(false);
            }

            lock (((ICollection)_textureFramesInUse).SyncRoot)
            {
                _textureFramesInUse.Add(nextFrame.GetInstanceID(), nextFrame);
            }

            nextFrame.WaitUntilReleased();
            outFrame = nextFrame;
            return(true);
        }
Пример #3
0
        IEnumerator YieldTextureFrame(Action <TextureFrame> callback)
        {
            TextureFrame nextFrame = null;

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

                if (poolSize <= frameCount)
                {
                    while (availableTextureFrames.Count > 0)
                    {
                        var textureFrame = availableTextureFrames.Dequeue();

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

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

            lock (((ICollection)textureFramesInUse).SyncRoot) {
                textureFramesInUse.Add(nextFrame.GetInstanceID(), nextFrame);
            }

            nextFrame.WaitUntilReleased();
            callback(nextFrame);

            yield return(nextFrame);
        }