Make XPointer a shared instance. Fixed some unallocated memory with

XArray.
This commit is contained in:
jief 2020-03-06 10:55:52 +03:00
parent bc45ded349
commit 564a3ca06c
13 changed files with 282 additions and 27 deletions

View File

@ -10,7 +10,7 @@
#include "../refit/screen.h"
#include "../refit/menu.h"
#include "gma.h"
#include "XPointer.h"
//#include "XPointer.h"
#ifndef DEBUG_ALL
#define DEBUG_SET 1

View File

@ -185,6 +185,7 @@ void XArray<TYPE>::CheckSize(xsize nNewSize)
template<class TYPE>
void XArray<TYPE>::SetLength(xsize l)
{
CheckSize(l, XArrayGrowByDefault); // be sure the size is allocated
m_len = l;
#ifdef DEBUG
if(m_len > m_size) {
@ -199,12 +200,12 @@ void XArray<TYPE>::SetLength(xsize l)
template<class TYPE>
TYPE &XArray<TYPE>::ElementAt(xsize index)
{
#ifdef _DEBUG
// #ifdef _DEBUG
if ( index >= m_len ) {
DebugLog(2, "XArray::ElementAt(xsize) -> Operator [] : index > m_len");
CpuDeadLoop();
}
#endif
// #endif
return m_data[index];
}
@ -212,12 +213,12 @@ TYPE &XArray<TYPE>::ElementAt(xsize index)
template<class TYPE>
const TYPE& XArray<TYPE>::ElementAt(xsize index) const
{
#ifdef _DEBUG
// #ifdef _DEBUG
if ( index >= m_len ) {
DebugLog(2, "XArray::ElementAt(xsize) const -> Operator [] : index > m_len");
CpuDeadLoop();
}
#endif
// #endif
return m_data[index];
}

View File

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

View File

@ -0,0 +1,240 @@
/*
*
* Copyright (c) 2020 Jief
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Christoph Pfisterer nor the names of the
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __menu_items_H__
#define __menu_items_H__
#include "libeg.h"
#include "../refit/lib.h"
#include "../cpp_foundation/XObjArray.h"
#include "../cpp_foundation/XStringWArray.h"
#include "../cpp_foundation/XStringW.h"
#include "../libeg/XPointer.h"
#include "menu_items/menu_items.h"
//some unreal values
#define FILM_CENTRE 40000
//#define FILM_LEFT 50000
//#define FILM_TOP 50000
//#define FILM_RIGHT 60000
//#define FILM_BOTTOM 60000
//#define FILM_PERCENT 100000
#define INITVALUE 40000
class REFIT_ABSTRACT_MENU_ENTRY;
class REFIT_MENU_ITEM_IEM_ABSTRACT;
class REFIT_MENU_ENTRY;
typedef VOID (REFIT_MENU_SCREEN::*MENU_STYLE_FUNC)(IN UINTN Function, IN CONST CHAR16 *ParamText);
class REFIT_MENU_SCREEN
{
public:
static 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;
// INTN InfoLineCount;
// CONST CHAR16 **InfoLines;
XStringWArray InfoLines;
// INTN EntryCount;
// REFIT_MENU_ENTRY **Entries;
XObjArray<REFIT_ABSTRACT_MENU_ENTRY> Entries;
INTN TimeoutSeconds;
CONST CHAR16 *TimeoutText;
CONST CHAR16 *Theme;
BOOLEAN AnimeRun;
BOOLEAN Once;
UINT64 LastDraw;
INTN CurrentFrame;
INTN Frames;
UINTN FrameTime; //ms
EG_RECT FilmPlace;
EG_IMAGE **Film;
ACTION mAction;
UINTN mItemID;
SCROLL_STATE ScrollState;
// MENU_STYLE_FUNC StyleFunc;
REFIT_MENU_SCREEN()
: ID(0), Title(0), TitleImage(0),
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)
{};
REFIT_MENU_SCREEN(UINTN ID, CONST CHAR16* Title, CONST CHAR16* TimeoutText)
: 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)
{};
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)
{
Entries.AddReference(entry1, false);
Entries.AddReference(entry2, false);
};
// REFIT_MENU_SCREEN( UINTN ID_,
// CONST CHAR16 *Title_,
// EG_IMAGE *TitleImage_,
//// INTN InfoLineCount_,
//// CONST CHAR16 **InfoLines_,
// INTN TimeoutSeconds_,
// CONST CHAR16 *TimeoutText_,
// CONST CHAR16 *Theme_,
// BOOLEAN AnimeRun_,
// BOOLEAN Once_,
// UINT64 LastDraw_,
// INTN CurrentFrame_,
// INTN Frames_,
// UINTN FrameTime_,
// EG_RECT FilmPlace_,
// EG_IMAGE **Film_)
// : ID(ID_), Title(Title_), TitleImage(TitleImage_),
// /*InfoLineCount(InfoLineCount_), InfoLines(InfoLines_),*/ TimeoutSeconds(TimeoutSeconds_),
// TimeoutText(TimeoutText_), Theme(Theme_), AnimeRun(AnimeRun_),
// Once(Once_), LastDraw(LastDraw_), CurrentFrame(CurrentFrame_),
// Frames(Frames_), FrameTime(FrameTime_), FilmPlace(FilmPlace_),
// Film(Film_), mAction(ActionNone), mItemID(0), mPointer(NULL)
// {};
//
// REFIT_MENU_SCREEN( UINTN ID_,
// CONST CHAR16 *Title_,
// EG_IMAGE *TitleImage_,
//// INTN InfoLineCount_,
//// CONST CHAR16 **InfoLines_,
// REFIT_ABSTRACT_MENU_ENTRY* entry,
// INTN TimeoutSeconds_,
// CONST CHAR16 *TimeoutText_,
// CONST CHAR16 *Theme_,
// BOOLEAN AnimeRun_,
// BOOLEAN Once_,
// UINT64 LastDraw_,
// INTN CurrentFrame_,
// INTN Frames_,
// UINTN FrameTime_,
// EG_RECT FilmPlace_,
// EG_IMAGE **Film_)
// : ID(ID_), Title(Title_), TitleImage(TitleImage_),
// /*InfoLineCount(InfoLineCount_), InfoLines(InfoLines_),*/ TimeoutSeconds(TimeoutSeconds_),
// TimeoutText(TimeoutText_), Theme(Theme_), AnimeRun(AnimeRun_),
// Once(Once_), LastDraw(LastDraw_), CurrentFrame(CurrentFrame_),
// Frames(Frames_), FrameTime(FrameTime_), FilmPlace(FilmPlace_),
// Film(Film_), mAction(ActionNone), mItemID(0), mPointer(NULL)
// {
// Entries.AddReference(entry, false);
// };
// REFIT_MENU_SCREEN( UINTN ID_,
// CONST CHAR16 *Title_,
// EG_IMAGE *TitleImage_,
//// INTN InfoLineCount_,
//// CONST CHAR16 **InfoLines_,
// REFIT_ABSTRACT_MENU_ENTRY* entry1,
// REFIT_ABSTRACT_MENU_ENTRY* entry2,
// INTN TimeoutSeconds_,
// CONST CHAR16 *TimeoutText_,
// CONST CHAR16 *Theme_,
// BOOLEAN AnimeRun_,
// BOOLEAN Once_,
// UINT64 LastDraw_,
// INTN CurrentFrame_,
// INTN Frames_,
// UINTN FrameTime_,
// EG_RECT FilmPlace_,
// EG_IMAGE **Film_)
// : ID(ID_), Title(Title_), TitleImage(TitleImage_),
// /*InfoLineCount(InfoLineCount_), InfoLines(InfoLines_),*/ TimeoutSeconds(TimeoutSeconds_),
// TimeoutText(TimeoutText_), Theme(Theme_), AnimeRun(AnimeRun_),
// Once(Once_), LastDraw(LastDraw_), CurrentFrame(CurrentFrame_),
// Frames(Frames_), FrameTime(FrameTime_), FilmPlace(FilmPlace_),
// Film(Film_), mAction(ActionNone), mItemID(0), mPointer(NULL)
// {
// Entries.AddReference(entry1, false);
// Entries.AddReference(entry2, false);
// };
//Scroll functions
VOID InitScroll(IN INTN ItemCount, IN UINTN MaxCount,
IN UINTN VisibleSpace, IN INTN Selected);
VOID UpdateScroll(IN UINTN Movement);
VOID HidePointer();
EFI_STATUS MouseBirth();
VOID KillMouse();
VOID AddMenuItem_(REFIT_MENU_ITEM_IEM_ABSTRACT* InputBootArgs, INTN Inx, CONST CHAR8 *Title, BOOLEAN Cursor);
VOID AddMenuInfo(CONST CHAR16 *Line);
VOID AddMenuInfoLine(IN CONST CHAR16 *InfoLine);
VOID AddMenuEntry(IN REFIT_MENU_ENTRY *Entry, bool freeIt);
VOID AddMenuItemSwitch(INTN Inx, CONST CHAR8 *Title, BOOLEAN Cursor);
VOID AddMenuCheck(CONST CHAR8 *Text, UINTN Bit, INTN ItemNum);
VOID AddMenuItemInput(INTN Inx, CONST CHAR8 *Title, BOOLEAN Cursor);
VOID FreeMenu();
INTN FindMenuShortcutEntry(IN CHAR16 Shortcut);
UINTN RunGenericMenu(IN MENU_STYLE_FUNC StyleFunc, IN OUT INTN *DefaultEntryIndex, OUT REFIT_ABSTRACT_MENU_ENTRY **ChosenEntry);
UINTN RunMenu(OUT REFIT_ABSTRACT_MENU_ENTRY **ChosenEntry);
UINTN RunMainMenu(IN INTN DefaultSelection, OUT REFIT_ABSTRACT_MENU_ENTRY **ChosenEntry);
UINTN InputDialog(IN MENU_STYLE_FUNC StyleFunc);
VOID DrawMainMenuLabel(IN CONST CHAR16 *Text, IN INTN XPos, IN INTN YPos);
VOID CountItems();
VOID InitAnime();
BOOLEAN GetAnime();
VOID UpdateAnime();
//Style functions
virtual VOID MainMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamText);
virtual VOID MainMenuVerticalStyle(IN UINTN Function, IN CONST CHAR16 *ParamText);
virtual VOID GraphicsMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamText);
virtual VOID TextMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamText);
~REFIT_MENU_SCREEN() {};
};
#endif
/*
EOF */

View File

@ -391,6 +391,8 @@ typedef VOID (REFIT_MENU_SCREEN::*MENU_STYLE_FUNC)(IN UINTN Function, IN CONST C
class REFIT_MENU_SCREEN
{
public:
static 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;
@ -413,7 +415,6 @@ public:
EG_IMAGE **Film;
ACTION mAction;
UINTN mItemID;
XPointer *mPointer;
SCROLL_STATE ScrollState;
// MENU_STYLE_FUNC StyleFunc;
@ -423,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(NULL) //, StyleFunc(&REFIT_MENU_SCREEN::TextMenuStyle)
{};
REFIT_MENU_SCREEN(UINTN ID, CONST CHAR16* Title, CONST CHAR16* TimeoutText)
@ -431,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(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

@ -25,7 +25,7 @@ XImage::XImage(UINTN W, UINTN H)
{
Width = W;
Height = H;
PixelData.CheckSize(GetWidth()*GetHeight());
PixelData.CheckSize(GetWidth()*GetHeight()); // change the allocated size, but not the size. size is still 0 here. PixelData[0] won't work.
}
XImage::XImage(EG_IMAGE* egImage)
@ -184,6 +184,7 @@ void XImage::CopyScaled(const XImage& Image, float scale)
const XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL>& Source = Image.GetData();
PixelData.SetLength(Width*Height); // setLength BEFORE, so GetPixelPtr(x, y)
for (UINTN y = 0; y < Height; y++)
{
int ly = (int)(y / scale);
@ -347,10 +348,13 @@ void XImage::GetArea(INTN x, INTN y, UINTN W, UINTN H)
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 = (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;
if (GraphicsOutput != NULL) {
PixelData.SetLength(AreaWidth*AreaHeight); // setLength BEFORE, so &PixelData[0]
INTN LineBytes = GraphicsOutput->Mode->Info->HorizontalResolution * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
GraphicsOutput->Blt(GraphicsOutput,
(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)&PixelData[0],
@ -366,6 +370,7 @@ void XImage::GetArea(INTN x, INTN y, UINTN W, UINTN H)
if (EFI_ERROR(Status)) {
return; // graphics not available
}
PixelData.SetLength(AreaWidth*AreaHeight); // setLength BEFORE, so &PixelData[0]
UgaDraw->Blt(UgaDraw,
(EFI_UGA_PIXEL *)&PixelData[0],
EfiUgaVideoToBltBuffer,

View File

@ -128,8 +128,8 @@ VOID XPointer::KillMouse()
return;
}
newImage.setEmpty();
oldImage.setEmpty();
// newImage.setEmpty(); // Don't empty them, we'll need them at the next mouse birth
// oldImage.setEmpty();
// delete PointerImage;

View File

@ -1,7 +1,7 @@
#pragma once
#include "XImage.h"
#include "../refit/IO.h"
//#include "../refit/IO.h"
class REFIT_MENU_SCREEN;
class XImage;

View File

@ -351,7 +351,7 @@
[Pcd]
[BuildOptions]
XCODE:*_*_*_CC_FLAGS = -fsigned-char -O2 -fno-omit-frame-pointer -ffreestanding -fno-rtti -fno-exceptions -Wno-deprecated -Wno-writable-strings -Wno-unused-const-variable -DJCONST=const -Wno-incompatible-ms-struct
XCODE:*_*_*_CC_FLAGS = -fsigned-char -O2 -fno-omit-frame-pointer -ffreestanding -fno-rtti -fno-exceptions -Wno-deprecated -Wno-writable-strings -Wno-unused-const-variable -DJCONST=CONST -Wno-incompatible-ms-struct
GCC:*_*_*_CC_FLAGS = -std=c99 -Os -fno-omit-frame-pointer -maccumulate-outgoing-args
GCC:*_*_*_CXX_FLAGS = -std=c++11 -Os -fno-omit-frame-pointer -maccumulate-outgoing-args -ffreestanding -fno-rtti -fno-exceptions -Wno-deprecated -Wno-write-strings -Wno-unused-const-variable -Wno-pointer-arith -DJCONST=const
GCC:*_*_*_CXX_FLAGS = -std=c++11 -Os -fno-omit-frame-pointer -maccumulate-outgoing-args -ffreestanding -fno-rtti -fno-exceptions -Wno-deprecated -Wno-write-strings -Wno-unused-const-variable -Wno-pointer-arith -DJCONST=CONST
MSFT:*_*_*_CC_FLAGS = /Os /wd4201 /D JCONST=const

View File

@ -1080,16 +1080,16 @@ EFI_STATUS WaitForInputEventPoll(REFIT_MENU_SCREEN* ScreenPtr, UINTN TimeoutDefa
CheckSyncSound();
}
TimeoutRemain--;
if ( Screen.mPointer ) {
if (Screen.mPointer->isAlive()) {
Screen.mPointer->UpdatePointer();
Status = Screen.mPointer->CheckMouseEvent(&Screen); //out: gItemID, gAction
// if ( Screen.mPointer ) {
if (Screen.mPointer.isAlive()) {
Screen.mPointer.UpdatePointer();
Status = Screen.mPointer.CheckMouseEvent(&Screen); //out: gItemID, gAction
if (Status != EFI_TIMEOUT) { //this check should return timeout if no mouse events occured
break;
}
}
}
// }
}
return Status;
}

View File

@ -26,6 +26,7 @@ Revision History
#include <Library/GenericBdsLib.h>
#include "../gui/menu_items/menu_items.h" // for REFIT_MENU_SCREEN
#include "../gui/REFIT_MENU_SCREEN.h"
#define EFI_TPL_APPLICATION 4
#define EFI_TPL_CALLBACK 8

View File

@ -2074,7 +2074,10 @@ RefitMain (IN EFI_HANDLE ImageHandle,
return Status;
DBG("Clover : Image base = 0x%x\n", SelfLoadedImage->ImageBase); // do not change, it's used by grep to feed the debugger
#ifdef JIEF_DEBUG
gBS->Stall(1000000); // to give time to gdb to connect
// PauseForKey(L"press\n");
#endif
construct_globals_objects(); // do this after SelfLoadedImage is initialized
all_tests();

View File

@ -2168,19 +2168,19 @@ VOID REFIT_MENU_SCREEN::UpdateScroll(IN UINTN Movement)
VOID REFIT_MENU_SCREEN::HidePointer()
{
if ( mPointer ) mPointer->Hide();
/*if ( mPointer )*/ mPointer.Hide();
}
EFI_STATUS REFIT_MENU_SCREEN::MouseBirth()
{
if ( !mPointer ) mPointer = new XPointer();
return mPointer->MouseBirth();
//if ( !mPointer ) mPointer = new XPointer();
return mPointer.MouseBirth();
}
VOID REFIT_MENU_SCREEN::KillMouse()
{
if ( mPointer ) mPointer->KillMouse();
/*if ( mPointer ) */mPointer.KillMouse();
}
//
// menu helper functions