mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Compress frame images using LZ4.
This commit is contained in:
parent
c3c116317d
commit
bef1988800
@ -360,6 +360,7 @@ struct SourceLocationComparator
|
||||
struct FrameImage
|
||||
{
|
||||
const char* ptr;
|
||||
uint32_t csz;
|
||||
uint16_t w, h;
|
||||
};
|
||||
|
||||
|
@ -1271,7 +1271,7 @@ void View::DrawFrames()
|
||||
if( fi != m_frameTexturePtr )
|
||||
{
|
||||
if( !m_frameTexture ) m_frameTexture = MakeTexture();
|
||||
UpdateTexture( m_frameTexture, fi->ptr, fi->w, fi->h );
|
||||
UpdateTexture( m_frameTexture, m_worker.UnpackFrameImage( *fi ), fi->w, fi->h );
|
||||
m_frameTexturePtr = fi;
|
||||
}
|
||||
ImGui::Separator();
|
||||
@ -1659,7 +1659,7 @@ bool View::DrawZoneFrames( const FrameData& frames )
|
||||
if( fi != m_frameTexturePtr )
|
||||
{
|
||||
if( !m_frameTexture ) m_frameTexture = MakeTexture();
|
||||
UpdateTexture( m_frameTexture, fi->ptr, fi->w, fi->h );
|
||||
UpdateTexture( m_frameTexture, m_worker.UnpackFrameImage( *fi ), fi->w, fi->h );
|
||||
m_frameTexturePtr = fi;
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
@ -1240,6 +1240,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
|
||||
if( eventMask & EventType::FrameImages )
|
||||
{
|
||||
size_t tmpbufsz = 0;
|
||||
char* tmpbuf = nullptr;
|
||||
f.Read( sz );
|
||||
m_data.frameImage.reserve_exact( sz, m_slab );
|
||||
s_loadProgress.subTotal.store( sz, std::memory_order_relaxed );
|
||||
@ -1249,11 +1251,17 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
auto fi = m_slab.Alloc<FrameImage>();
|
||||
f.Read2( fi->w, fi->h );
|
||||
const auto sz = fi->w * fi->h / 2;
|
||||
auto ptr = (char*)m_slab.AllocBig( sz );
|
||||
f.Read( ptr, sz );
|
||||
fi->ptr = ptr;
|
||||
if( tmpbufsz < sz )
|
||||
{
|
||||
tmpbufsz = sz;
|
||||
delete[] tmpbuf;
|
||||
tmpbuf = new char[sz];
|
||||
}
|
||||
f.Read( tmpbuf, sz );
|
||||
fi->ptr = PackFrameImage( tmpbuf, fi->w, fi->h, fi->csz );
|
||||
m_data.frameImage[i] = fi;
|
||||
}
|
||||
delete[] tmpbuf;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1325,6 +1333,8 @@ Worker::~Worker()
|
||||
delete[] m_buffer;
|
||||
LZ4_freeStreamDecode( m_stream );
|
||||
|
||||
delete[] m_frameImageBuffer;
|
||||
|
||||
for( auto& v : m_data.threads )
|
||||
{
|
||||
v->timeline.~Vector();
|
||||
@ -2948,7 +2958,7 @@ void Worker::ProcessFrameImage( const QueueFrameImage& ev )
|
||||
assert( it != m_pendingFrameImageData.end() );
|
||||
|
||||
auto fi = m_slab.Alloc<FrameImage>();
|
||||
fi->ptr = (const char*)it->second;
|
||||
fi->ptr = PackFrameImage( (const char*)it->second, ev.w, ev.h, fi->csz );
|
||||
fi->w = ev.w;
|
||||
fi->h = ev.h;
|
||||
|
||||
@ -4331,7 +4341,8 @@ void Worker::Write( FileWrite& f )
|
||||
{
|
||||
f.Write( &fi->w, sizeof( fi->w ) );
|
||||
f.Write( &fi->h, sizeof( fi->h ) );
|
||||
f.Write( fi->ptr, fi->w * fi->h / 2 );
|
||||
const auto image = UnpackFrameImage( *fi );
|
||||
f.Write( image, fi->w * fi->h / 2 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -4409,4 +4420,34 @@ const char* Worker::GetFailureString( Worker::Failure failure )
|
||||
return s_failureReasons[(int)failure];
|
||||
}
|
||||
|
||||
const char* Worker::PackFrameImage( const char* image, uint16_t w, uint16_t h, uint32_t& csz )
|
||||
{
|
||||
const auto insz = size_t( w ) * size_t( h ) / 2;
|
||||
const auto maxout = LZ4_COMPRESSBOUND( insz );
|
||||
if( m_frameImageBufferSize < maxout )
|
||||
{
|
||||
m_frameImageBufferSize = maxout;
|
||||
delete[] m_frameImageBuffer;
|
||||
m_frameImageBuffer = new char[maxout];
|
||||
}
|
||||
const auto outsz = LZ4_compress_default( image, m_frameImageBuffer, insz, maxout );
|
||||
csz = uint32_t( outsz );
|
||||
auto ptr = (char*)m_slab.AllocBig( outsz );
|
||||
memcpy( ptr, m_frameImageBuffer, outsz );
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const char* Worker::UnpackFrameImage( const FrameImage& image )
|
||||
{
|
||||
const auto outsz = size_t( image.w ) * size_t( image.h ) / 2;
|
||||
if( m_frameImageBufferSize < outsz )
|
||||
{
|
||||
m_frameImageBufferSize = outsz;
|
||||
delete[] m_frameImageBuffer;
|
||||
m_frameImageBuffer = new char[outsz];
|
||||
}
|
||||
LZ4_decompress_safe( image.ptr, m_frameImageBuffer, image.csz, outsz );
|
||||
return m_frameImageBuffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -345,6 +345,9 @@ public:
|
||||
const FailureData& GetFailureData() const { return m_failureData; }
|
||||
static const char* GetFailureString( Failure failure );
|
||||
|
||||
const char* PackFrameImage( const char* image, uint16_t w, uint16_t h, uint32_t& csz );
|
||||
const char* UnpackFrameImage( const FrameImage& image );
|
||||
|
||||
private:
|
||||
void Exec();
|
||||
void Query( ServerQuery type, uint64_t data );
|
||||
@ -532,6 +535,9 @@ private:
|
||||
|
||||
Vector<ServerQueryPacket> m_serverQueryQueue;
|
||||
size_t m_serverQuerySpaceLeft;
|
||||
|
||||
char* m_frameImageBuffer = nullptr;
|
||||
size_t m_frameImageBufferSize = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user