/*** Olive - Non-Linear Video Editor Copyright (C) 2019 Olive Team This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ***/ #ifndef MEMORYCACHE_H #define MEMORYCACHE_H #include #include #include "texturebuffer.h" #include "memorybuffer.h" class ImageCache : public QObject { public: enum BufferType { kInvalidBuf, // No buffer kMemBuf, // RAM (CPU) buffer kTexBuf // VRAM (GPU) buffer }; class Ref { public: Ref(ImageCache* cache); ~Ref(); void Relinquish(); protected: void* BufferInternal(); BufferType buffer_type_; int width_; int height_; private: void Request(); ImageCache* cache_; int buffer_; }; class ImgRef : public Ref { public: ImgRef(ImageCache* cache); void SetSize(int w, int h); MemoryBuffer* buffer(); }; class TexRef : public Ref { public: TexRef(ImageCache* cache); TextureBuffer* buffer(); }; ImageCache(); ~ImageCache(); void SetParameters(QOpenGLContext* ctx, int width, int height); private: int RequestBuffer(Ref *r, const BufferType& type, const olive::PixelFormat &format, int width, int height); int RequestBufferInternal(Ref *r, const BufferType& type, const olive::PixelFormat &format, int width, int height); void RelinquishBuffer(int index, const BufferType& type); void *Buffer(int index, const BufferType &type); bool OutOfMemory(); void Clear(); QList img_buffers_; QList img_refs_; QList img_access_times_; QList img_relinquished_; QList tex_buffers_; QList tex_refs_; QList tex_access_times_; QList tex_relinquished_; QOpenGLContext* ctx_; int width_; int height_; QMutex buffer_array_mutex_; }; #endif // MEMORYCACHE_H