mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-01 10:40:20 +03:00
Optimize eterm Kitty graphics frame replacement
- swap decoded frames into reusable image storage - recycle previous frame allocations for subsequent transfers - avoid full-frame copies during anonymous image replacement - extend tests to verify safe allocation reuse across frames - document eterm and eeiv in the project introduction
This commit is contained in:
@@ -663,11 +663,11 @@ KittyGraphicsHandleResult KittyGraphicsProtocol::finishTransfer( PendingTransfer
|
||||
std::shared_ptr<std::vector<Uint8>> pixelStorage;
|
||||
if ( existing != mImages.end() && existing->second.pixels.use_count() == 1 ) {
|
||||
pixelStorage = existing->second.pixels;
|
||||
pixelStorage->assign( pixels.begin(), pixels.end() );
|
||||
if ( format == 24 )
|
||||
recycleBuffer( pixels, mDecodedScratch );
|
||||
else if ( format == 32 )
|
||||
recycleBuffer( pixels, mDecodedScratch );
|
||||
// The existing image is no longer referenced by a queued UI update. Exchange its backing
|
||||
// allocation with the freshly decoded frame instead of copying the complete image. The old
|
||||
// image allocation becomes the next transfer's decode buffer.
|
||||
pixelStorage->swap( pixels );
|
||||
recycleBuffer( pixels, mDecodedScratch );
|
||||
} else {
|
||||
pixelStorage = std::make_shared<std::vector<Uint8>>( std::move( pixels ) );
|
||||
}
|
||||
|
||||
@@ -1064,12 +1064,24 @@ UTEST( eterm, kitty_graphics_reuses_unreferenced_replacement_pixel_storage ) {
|
||||
updates.clear();
|
||||
const auto* storage = protocol.imagePixels( 91 );
|
||||
ASSERT_TRUE( storage != nullptr );
|
||||
const auto* firstAllocation = storage->data();
|
||||
|
||||
ASSERT_EQ( KittyGraphicsError::None,
|
||||
protocol.handle( "a=t,f=24,s=2,v=1,i=91,q=2;BwgJCgsM" ).error );
|
||||
EXPECT_TRUE( storage == protocol.imagePixels( 91 ) );
|
||||
const std::vector<Uint8> expected{ 7, 8, 9, 10, 11, 12 };
|
||||
EXPECT_TRUE( expected == *protocol.imagePixels( 91 ) );
|
||||
ASSERT_TRUE( firstAllocation != protocol.imagePixels( 91 )->data() );
|
||||
updates = protocol.takeUpdates();
|
||||
ASSERT_EQ( static_cast<size_t>( 1 ), updates.size() );
|
||||
updates.clear();
|
||||
|
||||
ASSERT_EQ( KittyGraphicsError::None,
|
||||
protocol.handle( "a=t,f=24,s=2,v=1,i=91,q=2;DQ4PEBES" ).error );
|
||||
EXPECT_TRUE( storage == protocol.imagePixels( 91 ) );
|
||||
const std::vector<Uint8> recycledExpected{ 13, 14, 15, 16, 17, 18 };
|
||||
EXPECT_TRUE( recycledExpected == *protocol.imagePixels( 91 ) );
|
||||
EXPECT_TRUE( firstAllocation == protocol.imagePixels( 91 )->data() );
|
||||
}
|
||||
|
||||
UTEST( eterm, kitty_graphics_rejects_shared_memory_transmission ) {
|
||||
|
||||
Reference in New Issue
Block a user