testing draw, not working

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-03-06 17:02:06 +03:00
parent 564a3ca06c
commit d71acbb41d
10 changed files with 121 additions and 39 deletions

View File

@ -39,7 +39,7 @@ set PYTHON3_ENABLE=TRUE
set DEFAULT_NASM_PREFIX=
rem C:\Program Files (x86)\NASM"
rem # %DEFAULT_CYGWIN_HOME%\bin
set DEFAULT_TOOLCHAIN=VS2017
set DEFAULT_TOOLCHAIN=VS2015x86
set DEFAULT_BUILDTARGET=RELEASE
set DEFAULT_TARGETARCH=X64
set DEFAULT_THREADNUMBER=%NUMBER_OF_PROCESSORS%

View File

@ -135,7 +135,7 @@ template<class TYPE>
XArray<TYPE>::XArray(const XArray<TYPE> &anArray)
{
Init();
Add(anArray.Data(), anArray.Length());
AddArray(anArray.Data(), anArray.Length());
}
/* operator = */

View File

@ -1,4 +1,4 @@
#include "menu_items/menu_items.h"
#include "REFIT_MENU_SCREEN.h"
XPointer REFIT_MENU_SCREEN::mPointer;
//XPointer REFIT_MENU_SCREEN::mPointer;

View File

@ -64,8 +64,8 @@ typedef VOID (REFIT_MENU_SCREEN::*MENU_STYLE_FUNC)(IN UINTN Function, IN CONST C
class REFIT_MENU_SCREEN
{
public:
static XPointer mPointer;
// static XPointer mPointer;
XPointer mPointer;
UINTN ID;
CONST CHAR16 *Title; //Title is not const, but *Title is. It will be better to make it XStringW
EG_IMAGE *TitleImage;
@ -97,7 +97,7 @@ public:
TimeoutSeconds(0), TimeoutText(0), Theme(0), AnimeRun(0),
Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0), FilmPlace({0,0,0,0}),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
Film(0), mAction(ActionNone), mItemID(0), mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{};
REFIT_MENU_SCREEN(UINTN ID, CONST CHAR16* Title, CONST CHAR16* TimeoutText)
@ -105,14 +105,14 @@ public:
TimeoutSeconds(0), TimeoutText(TimeoutText), Theme(0), AnimeRun(0),
Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0), FilmPlace({0,0,0,0}),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
Film(0), mAction(ActionNone), mItemID(0), mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{};
REFIT_MENU_SCREEN(UINTN ID, CONST CHAR16* Title, CONST CHAR16* TimeoutText, REFIT_ABSTRACT_MENU_ENTRY* entry1, REFIT_ABSTRACT_MENU_ENTRY* entry2)
: ID(ID), Title(Title), TitleImage(0),
TimeoutSeconds(0), TimeoutText(TimeoutText), Theme(0), AnimeRun(0),
Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0), FilmPlace({0,0,0,0}),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
Film(0), mAction(ActionNone), mItemID(0), mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{
Entries.AddReference(entry1, false);
Entries.AddReference(entry2, false);

View File

@ -391,7 +391,7 @@ typedef VOID (REFIT_MENU_SCREEN::*MENU_STYLE_FUNC)(IN UINTN Function, IN CONST C
class REFIT_MENU_SCREEN
{
public:
static XPointer mPointer;
XPointer mPointer;
UINTN ID;
CONST CHAR16 *Title; //Title is not const, but *Title is. It will be better to make it XStringW
@ -424,7 +424,7 @@ public:
TimeoutSeconds(0), TimeoutText(0), Theme(0), AnimeRun(0),
Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0), FilmPlace({0,0,0,0}),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
Film(0), mAction(ActionNone), mItemID(0), mPointer() //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{};
REFIT_MENU_SCREEN(UINTN ID, CONST CHAR16* Title, CONST CHAR16* TimeoutText)
@ -432,14 +432,14 @@ public:
TimeoutSeconds(0), TimeoutText(TimeoutText), Theme(0), AnimeRun(0),
Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0), FilmPlace({0,0,0,0}),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
Film(0), mAction(ActionNone), mItemID(0), mPointer() //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{};
REFIT_MENU_SCREEN(UINTN ID, CONST CHAR16* Title, CONST CHAR16* TimeoutText, REFIT_ABSTRACT_MENU_ENTRY* entry1, REFIT_ABSTRACT_MENU_ENTRY* entry2)
: ID(ID), Title(Title), TitleImage(0),
TimeoutSeconds(0), TimeoutText(TimeoutText), Theme(0), AnimeRun(0),
Once(0), LastDraw(0), CurrentFrame(0),
Frames(0), FrameTime(0), FilmPlace({0,0,0,0}),
Film(0), mAction(ActionNone), mItemID(0)//, mPointer(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
Film(0), mAction(ActionNone), mItemID(0), mPointer() //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{
Entries.AddReference(entry1, false);
Entries.AddReference(entry2, false);

View File

@ -746,17 +746,25 @@ VOID testSVG()
nsvgRasterize(rast, SVGimage, tx,ty,Scale,Scale, (UINT8*)NewImage->PixelData, (int)Width, (int)Height, (int)Width*4);
DBG("timing rasterize end\n");
//now show it!
#if 1 //test XImage
XImage NewX(NewImage);
NewX.Draw((UGAWidth - Width) / 2,
(UGAHeight - Height) / 2, 1.f);
#else
BltImageAlpha(NewImage,
(UGAWidth - Width) / 2,
(UGAHeight - Height) / 2,
&MenuBackgroundPixel,
16);
#endif //test XImage
FreePool(FileData);
FileData = NULL;
egFreeImage(NewImage);
nsvg__deleteParser(p);
nsvgDeleteRasterizer(rast);
}
#endif
//Test text
Height = 80;

View File

@ -19,13 +19,19 @@ XImage::XImage()
{
Width = 0;
Height = 0;
PixelData = nullptr;
}
XImage::XImage(UINTN W, UINTN H)
{
Width = W;
Height = H;
#if !USE_ARRAY
PixelData.CheckSize(GetWidth()*GetHeight()); // change the allocated size, but not the size. size is still 0 here. PixelData[0] won't work.
PixelData.SetLength(GetWidth()*GetHeight());
#else
PixelData = (__typeof__(PixelData))AllocatePool(W * H * sizeof(*PixelData));
#endif
}
XImage::XImage(EG_IMAGE* egImage)
@ -37,11 +43,15 @@ XImage::XImage(EG_IMAGE* egImage)
Width = 0;
Height = 0;
}
#if !USE_ARRAY
PixelData.CheckSize(GetWidth()*GetHeight()); // change the allocated size, but not the size.
PixelData.SetLength(GetWidth()*GetHeight()); // change the size, ie the number of element in the array
if ( GetWidth()*GetHeight() > 0 ) {
CopyMem(&PixelData[0], egImage->PixelData, PixelData.size());
CopyMem(&PixelData[0], egImage->PixelData, PixelData.size() * sizeof(*egImage->PixelData));
}
#else
PixelData = (__typeof__(PixelData))AllocateCopyPool(Width * Height * sizeof(*egImage->PixelData), egImage->PixelData);
#endif
}
UINT8 Smooth(const UINT8* p, int a01, int a10, int a21, int a12, int dx, int dy, float scale)
@ -56,7 +66,10 @@ XImage::XImage(const XImage& Image, float scale)
UINTN SrcHeight = Image.GetHeight();
Width = (UINTN)(SrcWidth * scale);
Height = (UINTN)(SrcHeight * scale);
#if !USE_ARRAY
PixelData.CheckSize(GetWidth()*GetHeight());
PixelData.SetLength(GetWidth()*GetHeight());
#endif
if (scale < 1.e-4) return;
CopyScaled(Image, scale);
}
@ -125,12 +138,22 @@ do { \
XImage::~XImage()
{
#if USE_ARRAY
FreePool(PixelData);
#endif
}
#if !USE_ARRAY
const XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL>& XImage::GetData() const
{
return PixelData;
}
#else
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetData() const
{
return &PixelData[0];
}
#endif
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetPixelPtr(UINTN x, UINTN y)
{
@ -181,10 +204,15 @@ void XImage::CopyScaled(const XImage& Image, float scale)
int Pixel = sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
int Row = (int)SrcWidth * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
#if !USE_ARRAY
const XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL>& Source = Image.GetData();
#else
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* Source = Image.GetData();
#endif
#if !USE_ARRAY
PixelData.SetLength(Width*Height); // setLength BEFORE, so GetPixelPtr(x, y)
#endif
for (UINTN y = 0; y < Height; y++)
{
int ly = (int)(y / scale);
@ -282,7 +310,7 @@ unsigned XImage::ToPNG(UINT8** Data, UINTN& OutSize)
}
/*
* fill XImage object by rater data described in SVG
* fill XImage object by raster data described in SVG
* caller should create the object with Width and Height and calculate scale
* scale = 1 correspond to fill the rect with the image
* scale = 0.5 will reduce image
@ -345,16 +373,25 @@ void XImage::GetArea(INTN x, INTN y, UINTN W, UINTN H)
UgaDraw = NULL;
}
//this should be somewhere else
INTN ScreenWidth = 0;
INTN ScreenHeight = 0;
egGetScreenSize(&ScreenWidth, &ScreenHeight);
if (W == 0) W = Width;
if (H == 0) H = Height;
// INTN AreaWidth = (x + W > Width) ? (Width - x) : W;
// INTN AreaHeight = (y + H > Height) ? (Height - y) : H;
INTN AreaWidth = (W > Width) ? W : Width;
INTN AreaHeight = (H > Height) ? H : Height;
INTN AreaWidth = (x + W > (UINTN)ScreenWidth) ? ((UINTN)ScreenWidth - x) : W;
INTN AreaHeight = (y + H > (UINTN)ScreenHeight) ? ((UINTN)ScreenHeight - y) : H;
// INTN AreaWidth = (W > Width) ? W : Width;
// INTN AreaHeight = (H > Height) ? H : Height;
DBG("area is {%d, %d, %d, %d}\n", x, y, W, H);
DBG("own width %d and area %d\n", Width, AreaWidth);
if (GraphicsOutput != NULL) {
#if !USE_ARRAY
PixelData.SetLength(AreaWidth*AreaHeight); // setLength BEFORE, so &PixelData[0]
#endif
INTN LineBytes = GraphicsOutput->Mode->Info->HorizontalResolution * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
GraphicsOutput->Blt(GraphicsOutput,
(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)&PixelData[0],
@ -363,14 +400,16 @@ void XImage::GetArea(INTN x, INTN y, UINTN W, UINTN H)
}
else if (UgaDraw != NULL) {
UINT32 LineWidth = 0;
UINT32 ScreenHeight = 0;
UINT32 UGAScreenHeight = 0;
UINT32 Depth = 0;
UINT32 RefreshRate = 60;
Status = UgaDraw->GetMode(UgaDraw, &LineWidth, &ScreenHeight, &Depth, &RefreshRate);
Status = UgaDraw->GetMode(UgaDraw, &LineWidth, &UGAScreenHeight, &Depth, &RefreshRate);
if (EFI_ERROR(Status)) {
return; // graphics not available
}
#if !USE_ARRAY
PixelData.SetLength(AreaWidth*AreaHeight); // setLength BEFORE, so &PixelData[0]
#endif
UgaDraw->Blt(UgaDraw,
(EFI_UGA_PIXEL *)&PixelData[0],
EfiUgaVideoToBltBuffer,
@ -383,16 +422,27 @@ void XImage::GetArea(INTN x, INTN y, UINTN W, UINTN H)
void XImage::Draw(INTN x, INTN y, float scale)
{
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL BlueColor = { 200, 0, 0, 160 };
//prepare images
INTN ScreenWidth = 0;
INTN ScreenHeight = 0;
egGetScreenSize(&ScreenWidth, &ScreenHeight);
XImage Background(ScreenWidth, ScreenHeight);
Background.GetArea(x, y, Width, Height);
XImage Top(*this, scale);
Background.Compose(x, y, Top, true);
UINTN AreaWidth = (x + Width > Background.GetWidth()) ? (Background.GetWidth() - x) : Width;
UINTN AreaHeight = (y + Height > Background.GetHeight()) ? (Background.GetHeight() - y) : Height;
// DBG("1\n");
// XImage Background(ScreenWidth, ScreenHeight);
// DBG("2\n");
// Background.GetArea(x, y, Width, Height);
// DBG("3\n");
// XImage Top(*this, scale);
// XImage Top(Width, Height);
// DBG("4\n");
// Top.CopyScaled(*this, 1.f);
// Top.Fill(BlueColor);
// DBG("5\n");
// Background.Compose(x, y, Top, true);
// DBG("6\n");
UINTN AreaWidth = (x + Width > (UINTN)ScreenWidth) ? (ScreenWidth - x) : Width;
UINTN AreaHeight = (y + Height > (UINTN)ScreenHeight) ? (ScreenHeight - y) : Height;
// DBG("width: own=%d, Background=%d, Area=%d\n", Width, Background.GetWidth(), AreaWidth);
// prepare protocols
EFI_STATUS Status;
@ -409,15 +459,17 @@ void XImage::Draw(INTN x, INTN y, float scale)
UgaDraw = NULL;
}
//output combined image
// DBG("7\n");
if (GraphicsOutput != NULL) {
GraphicsOutput->Blt(GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Background.GetPixelPtr(0, 0),
GraphicsOutput->Blt(GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)GetData(),
EfiBltBufferToVideo,
0, 0, x, y,
AreaWidth, AreaHeight, Background.GetWidth() * 4);
0, 0, //source x,y
x, y, //destination x,y
AreaWidth, AreaHeight, ScreenWidth * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
}
else if (UgaDraw != NULL) {
UgaDraw->Blt(UgaDraw, (EFI_UGA_PIXEL *)Background.GetPixelPtr(0, 0), EfiUgaBltBufferToVideo,
UgaDraw->Blt(UgaDraw, (EFI_UGA_PIXEL *)GetPixelPtr(0, 0), EfiUgaBltBufferToVideo,
0, 0, x, y,
AreaWidth, AreaHeight, Background.GetWidth() * 4);
AreaWidth, AreaHeight, ScreenWidth * sizeof(EFI_UGA_PIXEL));
}
}

View File

@ -19,6 +19,7 @@ extern "C" {
//#include "nanosvg.h"
//#include "FloatLib.h"
#define USE_ARRAY 1
#if 0 //ndef EFI_GRAPHICS_OUTPUT_BLT_PIXEL
typedef struct {
@ -47,7 +48,11 @@ class XImage
protected:
UINTN Width;
UINTN Height;
#if USE_ARRAY
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *PixelData;
#else
XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL> PixelData;
#endif
public:
XImage();
@ -60,17 +65,29 @@ protected:
UINTN GetSize() const; //in bytes
public:
#if !USE_ARRAY
const XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL>& GetData() const;
#else
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetData() const;
#endif
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& GetPixel(UINTN x, UINTN y) const;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(UINTN x, UINTN y);
UINTN GetWidth() const;
UINTN GetHeight() const;
#if USE_ARRAY
void setEmpty() {
Width = 0; Height = 0; if (PixelData) {
FreePool(PixelData); PixelData = nullptr;
}
}
bool isEmpty() const { return PixelData == nullptr; }
#else
void setEmpty() { Width=0; Height=0; PixelData.setEmpty(); }
bool isEmpty() const { return PixelData.size() == 0; }
#endif
void Fill(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color = { 0, 0, 0, 0 });
void FillArea(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color, const EgRect& Rect);

View File

@ -60,7 +60,7 @@ EFI_STATUS XPointer::MouseBirth()
}
if (SimplePointerProtocol) { //do not double
// DBG("DrawPointer\n");
DBG("Mouse is already here\n");
Draw();
return EFI_SUCCESS;
}
@ -84,7 +84,7 @@ EFI_STATUS XPointer::MouseBirth()
if ( PointerImage.isEmpty() ) {
//this is impossible after BuiltinIcon
DBG("No pointer image!\n");
MsgLog("No pointer image!\n");
SimplePointerProtocol = NULL;
Alive = false;
return EFI_NOT_FOUND;
@ -96,6 +96,7 @@ EFI_STATUS XPointer::MouseBirth()
oldPlace.Height = POINTER_HEIGHT;
DBG("init mouse at [%d, %d]\n", oldPlace.XPos, oldPlace.YPos);
CopyMem(&newPlace, &oldPlace, sizeof(EG_RECT));
// DBG("newPlace={%d, %d, %d, %d}\n", newPlace.XPos, newPlace.YPos, newPlace.Width, newPlace.Height);
//newImage->Fill(&MenuBackgroundPixel),
// egTakeImage(oldImage, oldPlace.XPos, oldPlace.YPos,
@ -111,13 +112,15 @@ VOID XPointer::Draw()
// take background image
oldImage.GetArea(newPlace);
// DBG("got area\n");
CopyMem(&oldPlace, &newPlace, sizeof(EG_RECT)); //can we use oldPlace = newPlace; ?
// CopyMem(newImage->PixelData, oldImage->PixelData, (UINTN)(POINTER_WIDTH * POINTER_HEIGHT * sizeof(EG_PIXEL)));
newImage.CopyScaled(oldImage, 1.f);
// newImage.CopyScaled(oldImage, 1.f);
newImage.Compose(0, 0, PointerImage, true);
newImage.Draw(newPlace.XPos, newPlace.YPos, 1.f);
// newImage.Compose(0, 0, PointerImage, true);
// newImage.Draw(newPlace.XPos, newPlace.YPos, 1.f);
PointerImage.Draw(newPlace.XPos, newPlace.YPos, 1.f);
}
VOID XPointer::KillMouse()

View File

@ -16,7 +16,7 @@
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = CLOVER
BASE_NAME = CLOVERX64
FILE_GUID = 8F7D7B1E-0E1C-4C98-B12E-4EC99C4081AC
MODULE_TYPE = UEFI_APPLICATION
EDK_RELEASE_VERSION = 0x00020000
@ -66,6 +66,8 @@
entry_scan/securebootkeys.h
gui/menu_items/menu_items.h
gui/menu_items/menu_globals.h
# gui/REFIT_MENU_SCREEN.cpp
# gui/REFIT_MENU_SCREEN.h
libeg/egemb_icons.cpp
libeg/egemb_icons_dark.cpp
libeg/egemb_font.cpp