Changeset - r28091:b8764615ab11
[Not reviewed]
master
0 7 0
Michael Lutz - 13 months ago 2023-11-04 14:20:21
michi@icosahedron.de
Codechange: Replicate cursor screen backup to chat message display, removing explicit memory management.

Incidentally, this makes Blitter::GetBytesPerPixel unneeed.
7 files changed with 4 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/blitter/32bpp_anim.hpp
Show inline comments
 
@@ -48,7 +48,6 @@ public:
 
	Blitter::PaletteAnimation UsePaletteAnimation() override;
 

	
 
	const char *GetName() override { return "32bpp-anim"; }
 
	int GetBytesPerPixel() override { return 6; }
 
	void PostResize() override;
 

	
 
	/**
src/blitter/32bpp_base.hpp
Show inline comments
 
@@ -30,7 +30,6 @@ public:
 
	size_t BufferSize(uint width, uint height) override;
 
	void PaletteAnimate(const Palette &palette) override;
 
	Blitter::PaletteAnimation UsePaletteAnimation() override;
 
	int GetBytesPerPixel() override { return 4; }
 

	
 
	/**
 
	 * Look up the colour in the current palette.
src/blitter/40bpp_anim.hpp
Show inline comments
 
@@ -33,7 +33,6 @@ public:
 
	bool NeedsAnimationBuffer() override;
 

	
 
	const char *GetName()  override { return "40bpp-anim"; }
 
	int GetBytesPerPixel()  override { return 5; }
 

	
 
	template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
 

	
src/blitter/8bpp_base.hpp
Show inline comments
 
@@ -28,7 +28,6 @@ public:
 
	size_t BufferSize(uint width, uint height) override;
 
	void PaletteAnimate(const Palette &palette) override;
 
	Blitter::PaletteAnimation UsePaletteAnimation() override;
 
	int GetBytesPerPixel() override { return 1; }
 
};
 

	
 
#endif /* BLITTER_8BPP_BASE_HPP */
src/blitter/base.hpp
Show inline comments
 
@@ -199,11 +199,6 @@ public:
 
	virtual const char *GetName() = 0;
 

	
 
	/**
 
	 * Get how many bytes are needed to store a pixel.
 
	 */
 
	virtual int GetBytesPerPixel() = 0;
 

	
 
	/**
 
	 * Post resize event
 
	 */
 
	virtual void PostResize() { };
src/blitter/null.hpp
Show inline comments
 
@@ -32,7 +32,6 @@ public:
 
	Blitter::PaletteAnimation UsePaletteAnimation() override { return Blitter::PALETTE_ANIMATION_NONE; };
 

	
 
	const char *GetName() override { return "null"; }
 
	int GetBytesPerPixel() override { return 0; }
 
};
 

	
 
/** Factory for the blitter that does nothing. */
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -58,7 +58,7 @@ static std::chrono::steady_clock::time_p
 
 * the left and pixels from the bottom. The height is the maximum height.
 
 */
 
static PointDimension _chatmsg_box;
 
static uint8_t *_chatmessage_backup = nullptr; ///< Backup in case text is moved.
 
static ReusableBuffer<uint8_t> _chatmessage_backup; ///< Backup in case text is moved.
 

	
 
/**
 
 * Test if there are any chat messages to display.
 
@@ -103,7 +103,6 @@ void NetworkReInitChatBoxSize()
 
{
 
	_chatmsg_box.y       = 3 * FONT_HEIGHT_NORMAL;
 
	_chatmsg_box.height  = MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + ScaleGUITrad(NETWORK_CHAT_LINE_SPACING)) + ScaleGUITrad(4);
 
	_chatmessage_backup  = ReallocT(_chatmessage_backup, static_cast<size_t>(_chatmsg_box.width) * _chatmsg_box.height * BlitterFactory::GetCurrentBlitter()->GetBytesPerPixel());
 
}
 

	
 
/** Initialize all buffers of the chat visualisation. */
 
@@ -156,7 +155,7 @@ void NetworkUndrawChatMessage()
 

	
 
		_chatmessage_visible = false;
 
		/* Put our 'shot' back to the screen */
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup.GetBuffer(), width, height);
 
		/* And make sure it is updated next time */
 
		VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
 

	
 
@@ -208,10 +207,9 @@ void NetworkDrawChatMessage()
 
	}
 
	if (width <= 0 || height <= 0) return;
 

	
 
	assert(blitter->BufferSize(width, height) <= static_cast<size_t>(_chatmsg_box.width) * _chatmsg_box.height * blitter->GetBytesPerPixel());
 

	
 
	/* Make a copy of the screen as it is before painting (for undraw) */
 
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
 
	uint8_t *buffer = _chatmessage_backup.Allocate(BlitterFactory::GetCurrentBlitter()->BufferSize(width, height));
 
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), buffer, width, height);
 

	
 
	_cur_dpi = &_screen; // switch to _screen painting
 

	
0 comments (0 inline, 0 general)