tahoma2d/toonz/sources/include/tcachedlevel.h

311 lines
7.1 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TCACHEDLEVEL_INCLUDED
#define TCACHEDLEVEL_INCLUDED
/*
PER ORA SI PUO' USARE LA CACHE SOLO CON WINDOWS
*/
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
#include <windows.h>
#endif
#include "tfilepath.h"
#include "traster.h"
#include "tthread.h"
#undef DVAPI
#undef DVVAR
#ifdef TRASTERIMAGE_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//=============================================================================
// forward declaration
class TRawDataCodec;
class TRasterCodec;
class TCachePersist;
//=============================================================================
/*
class TCache {
public:
TCache();
virtual ~TCache();
bool isCached(int frame) const = 0;
bool isCached(int starFrame, int endFrame) const = 0; // estremi compresi
virtual void putRaster(int frame, const TRasterP &ras) = 0;
2016-06-15 18:43:10 +12:00
2016-03-19 06:57:51 +13:00
virtual void getRaster(int frame, TRaster32P &ras) const
{ getRaster(frame, TRasterP(ras)); }
virtual void getRaster(int frame, TRaster64P &ras) const
{ getRaster(frame, TRasterP(ras)); }
virtual void getRaster(int frame, TRasterYUV422P &ras) const
{ getRaster(frame, TRasterP(ras)); }
void invalidateAll() = 0;
void invalidate(int starFrame, int endFrame) = 0; // estremi compresi
protected:
virtual void getRaster(int frame, TRasterP &ras) const = 0;
};
class TRamCache final : public TCache {
2016-03-19 06:57:51 +13:00
public:
TRamCache();
};
class TDiskCache final : public TCache {
2016-03-19 06:57:51 +13:00
public:
TDiskCache();
};
void TDiskCache::putRaster(int frame, const TRsterP &ras)
{
}
void TDiskCache::getRaster(
class TRAMUncompressedCache final : public TRamCache {
2016-03-19 06:57:51 +13:00
};
class TRAMLzoCache final : public TRamCache {
2016-03-19 06:57:51 +13:00
};
class TDiskUncompressedCache final : public TDiskCache {
2016-03-19 06:57:51 +13:00
};
class TDiskYUV422Cache final : public TDiskCache {
2016-03-19 06:57:51 +13:00
public:
TDiskYUV422Cache();
~TDiskYUV422Cache();
void putRaster(int frame, const TRasterP &ras);
void getRaster(int frame, TRasterYUV422P &ras) const;
};
2016-06-15 18:43:10 +12:00
void TRAMUncompressedCache::getRaster(int frame, TRasterP &ras)
2016-03-19 06:57:51 +13:00
{
TRaster32P ras32(ras.getSize());
getRaster(frame, ras32);
convert(ras, ras32);
}
void TRAMUncompressedCache::getRaster(int frame, TRaster32P &ras) const
{
//....
}
*/
//=============================================================================
//=============================================================================
//=============================================================================
2016-06-15 18:43:10 +12:00
class DVAPI TRasterCache {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TRasterCache(TCachePersist *cp);
virtual ~TRasterCache();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setMode(const TDimension &size, int bpp);
void getMode(TDimension &size, int &bpp) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRasterP getRaster(int frame) const;
bool getBuffer(int frame, UCHAR *&buffer, int &wrap, int &bpp,
TDimension &rasDim) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool getRaster(int frame, TRaster32P &ras) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void putRaster(int frame, const TRasterP &ras);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isFrameCached(int frame) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void invalidate();
void invalidate(int startFrame, int endFrame);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void enablePrefetch(bool newState);
bool isPrefetchEnabled() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TUINT64 getUsedSpace();
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
// virtual TRasterP doGetRaster(int frame) = 0;
// virtual void doPutRaster(int frame, const TRasterP &ras) = 0;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
class Data;
Data *m_data;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TCachePersist {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TCachePersist(TRasterCodec *codec) : m_codec(codec) {}
virtual ~TCachePersist() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void setFrameSize(int lx, int ly, int bpp) = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual TRasterP doGetRaster(int frame) = 0;
virtual bool doGetRaster(int frame, TRaster32P &ras) const = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual bool doPutRaster(int frame, const TRasterP &ras) = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void onInvalidate() = 0;
virtual void onInvalidate(int startFrame, int endFrame) = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual TUINT64 getUsedSpace() = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// private:
TRasterCodec *m_codec;
2016-03-19 06:57:51 +13:00
};
class DVAPI TRamCachePersist final : public TCachePersist {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TRamCachePersist(TRasterCodec *codec);
~TRamCachePersist();
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void setFrameSize(int lx, int ly, int bpp) override {}
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void onInvalidate() override;
void onInvalidate(int startFrame, int endFrame) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TUINT64 getUsedSpace() override;
2016-03-19 06:57:51 +13:00
private:
2016-06-19 20:06:29 +12:00
TRasterP doGetRaster(int frame) override;
bool doGetRaster(int frame, TRaster32P &ras) const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool doPutRaster(int frame, const TRasterP &ras) override;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
class Imp;
Imp *m_imp;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
class DVAPI TDiskCachePersist final : public TCachePersist {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TDiskCachePersist(TRasterCodec *codec, const TFilePath &fullpath);
~TDiskCachePersist();
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void setFrameSize(int lx, int ly, int bpp) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void onInvalidate() override;
void onInvalidate(int startFrame, int endFrame) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TUINT64 getUsedSpace() override;
2016-03-19 06:57:51 +13:00
private:
2016-06-19 20:06:29 +12:00
TRasterP doGetRaster(int frame) override;
bool doGetRaster(int frame, TRaster32P &ras) const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool doPutRaster(int frame, const TRasterP &ras) override;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
class Imp;
Imp *m_imp;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
// TDiskCachePersist2 usa il Direct File I/O (acceso al disco non bufferizzato)
class DVAPI TDiskCachePersist2 final : public TCachePersist {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TDiskCachePersist2(TRasterCodec *codec, const TFilePath &fullpath);
~TDiskCachePersist2();
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void setFrameSize(int lx, int ly, int bpp) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void onInvalidate() override;
void onInvalidate(int startFrame, int endFrame) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
UCHAR *getRawData(int frame, TINT32 &size, int &lx, int &ly) override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
TUINT64 getUsedSpace() override;
2016-03-19 06:57:51 +13:00
private:
2016-06-19 20:06:29 +12:00
TRasterP doGetRaster(int frame) override;
bool doGetRaster(int frame, TRaster32P &ras) const override;
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
bool doPutRaster(int frame, const TRasterP &ras) override;
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
class Imp;
Imp *m_imp;
2016-03-19 06:57:51 +13:00
};
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TCompressedLevel {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TCompressedLevel(const TFilePath &fullpath);
~TCompressedLevel();
void setSize(TDimension d);
void putImage(int frame, const TRaster32P &ras);
TRaster32P getImage(int frame);
void invalidate(int frame);
void invalidateAll();
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
TCompressedLevel(); // not implemented
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TFilePath m_fullpath;
TRawDataCodec *m_codec;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_viewFrameMin, m_viewFrameMax;
2016-03-19 06:57:51 +13:00
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-06-15 18:43:10 +12:00
HANDLE m_hFile, m_hMap;
LPVOID m_fileMapAddress;
int m_xSize, m_ySize;
int m_frameSize;
SYSTEM_INFO m_systemInfo;
__int64 m_mapOffset;
static DWORD m_maxViewSize;
static DWORD m_maxFileSize;
static DWORD m_reallocFileSize;
//-------
HANDLE initFile(const TFilePath &fname);
HANDLE mapFile(HANDLE hFile, ULONGLONG size);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
static TThread::Mutex m_mutex;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setCurrentView(int frame, bool force = false);
2016-03-19 06:57:51 +13:00
};
#endif