From 2b4ee6ad96baa0a29fd8850b2e589e921e3b4f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20H=C3=A4user?= <8659494+mhaeuser@users.noreply.github.com> Date: Sun, 28 Feb 2021 23:59:14 +0100 Subject: [PATCH] OpenCanopy: Simplify code --- Platform/OpenCanopy/OpenCanopy.c | 44 ++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Platform/OpenCanopy/OpenCanopy.c b/Platform/OpenCanopy/OpenCanopy.c index 595aed2a..f6cc0a41 100644 --- a/Platform/OpenCanopy/OpenCanopy.c +++ b/Platform/OpenCanopy/OpenCanopy.c @@ -402,6 +402,9 @@ GuiDrawToBuffer ( IN BOOLEAN RequestDraw ) { + UINT32 PosX; + UINT32 PosY; + UINT32 PosBaseX; UINT32 PosBaseY; UINT32 PosOffsetX; @@ -441,8 +444,6 @@ GuiDrawToBuffer ( UINT32 ActualArea; - UINT32 PosX; - ASSERT (Image != NULL); ASSERT (DrawContext != NULL); ASSERT (DrawContext->Screen != NULL); @@ -487,6 +488,9 @@ GuiDrawToBuffer ( } } + ASSERT (PosBaseX + PosOffsetX == BaseX + OffsetX); + ASSERT (PosBaseY + PosOffsetY == BaseY + OffsetY); + if (!Fill) { ASSERT (Image->Width > OffsetX); ASSERT (Image->Height > OffsetY); @@ -496,14 +500,16 @@ GuiDrawToBuffer ( Width = MIN (Width, Image->Width - OffsetX); Height = MIN (Height, Image->Height - OffsetY); } + + PosX = PosBaseX + PosOffsetX; + PosY = PosBaseY + PosOffsetY; // // Crop to the screen's dimensions. // - ASSERT (DrawContext->Screen->Width >= PosBaseX + PosOffsetX); - ASSERT (DrawContext->Screen->Height >= PosBaseY + PosOffsetY); - PosX = PosBaseX + PosOffsetX; + ASSERT (DrawContext->Screen->Width >= PosX); + ASSERT (DrawContext->Screen->Height >= PosY); Width = MIN (Width, DrawContext->Screen->Width - PosX); - Height = MIN (Height, DrawContext->Screen->Height - (PosBaseY + PosOffsetY)); + Height = MIN (Height, DrawContext->Screen->Height - PosY); if (Width == 0 || Height == 0) { return; @@ -518,7 +524,7 @@ GuiDrawToBuffer ( for ( RowIndex = 0, SourceRowOffset = OffsetY * Image->Width, - TargetRowOffset = (PosBaseY + PosOffsetY) * DrawContext->Screen->Width; + TargetRowOffset = PosY * DrawContext->Screen->Width; RowIndex < Height; ++RowIndex, SourceRowOffset += Image->Width, @@ -528,11 +534,11 @@ GuiDrawToBuffer ( // Blend the row pixel-by-pixel. // for ( - TargetColumnOffset = PosOffsetX, SourceColumnOffset = OffsetX; - TargetColumnOffset < PosOffsetX + Width; + TargetColumnOffset = PosX, SourceColumnOffset = OffsetX; + TargetColumnOffset < PosX + Width; ++TargetColumnOffset, ++SourceColumnOffset ) { - TargetPixel = &mScreenBuffer[TargetRowOffset + PosBaseX + TargetColumnOffset]; + TargetPixel = &mScreenBuffer[TargetRowOffset + TargetColumnOffset]; SourcePixel = &Image->Buffer[SourceRowOffset + SourceColumnOffset]; GuiBlendPixel (TargetPixel, SourcePixel, Opacity); } @@ -551,7 +557,7 @@ GuiDrawToBuffer ( // for ( RowIndex = 0, - TargetRowOffset = (PosBaseY + PosOffsetY) * DrawContext->Screen->Width; + TargetRowOffset = PosY * DrawContext->Screen->Width; RowIndex < Height; ++RowIndex, TargetRowOffset += DrawContext->Screen->Width @@ -572,7 +578,7 @@ GuiDrawToBuffer ( // for ( RowIndex = 0, - TargetRowOffset = (PosBaseY + PosOffsetY) * DrawContext->Screen->Width; + TargetRowOffset = PosY * DrawContext->Screen->Width; RowIndex < Height; ++RowIndex, TargetRowOffset += DrawContext->Screen->Width @@ -581,11 +587,11 @@ GuiDrawToBuffer ( // Blend the row pixel-by-pixel with Source's (0,0). // for ( - TargetColumnOffset = PosOffsetX; - TargetColumnOffset < PosOffsetX + Width; + TargetColumnOffset = PosY; + TargetColumnOffset < PosY + Width; ++TargetColumnOffset ) { - TargetPixel = &mScreenBuffer[TargetRowOffset + PosBaseX + TargetColumnOffset]; + TargetPixel = &mScreenBuffer[TargetRowOffset + TargetColumnOffset]; GuiBlendPixel (TargetPixel, &Image->Buffer[0], Opacity); } } @@ -597,10 +603,10 @@ GuiDrawToBuffer ( // // Update the coordinates of the smallest rectangle covering all changes. // - ThisReq.MinX = PosBaseX + PosOffsetX; - ThisReq.MinY = PosBaseY + PosOffsetY; - ThisReq.MaxX = PosBaseX + PosOffsetX + Width - 1; - ThisReq.MaxY = PosBaseY + PosOffsetY + Height - 1; + ThisReq.MinX = PosX; + ThisReq.MinY = PosY; + ThisReq.MaxX = PosX + Width - 1; + ThisReq.MaxY = PosY + Height - 1; ThisArea = Width * Height;