Files
SDL/src/render/ngage/SDL_render_ngage_c.hpp
Michael Fitzmayer b53b31b74a [N-Gage] Add various micro-optimizations to rendering back-end
- Add reusable line points buffer to eliminate per-call heap allocations in DrawLines.
- Cache last draw color to skip redundant SetPenColor/SetBrushColor calls.
- Pre-compute cardinal angle constants (0°, 90°, 180°, 270°) for CopyEx fast-path.
- Cache color modulation state to avoid redundant LUT rebuilds.
- Add missing break statement in HandleEvent.
- Initialize previously uninitialized lastTime variable in UpdateFPS.
2026-04-16 21:38:07 +02:00

123 lines
4.0 KiB
C++

/*
Simple DirectMedia Layer
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef ngage_video_render_ngage_c_hpp
#define ngage_video_render_ngage_c_hpp
#include "SDL_render_ngage_c.h"
#include <3dtypes.h>
#include <NRenderer.h>
#include <e32std.h>
#include <w32std.h>
class CRenderer : public MDirectScreenAccess
{
public:
static CRenderer *NewL();
virtual ~CRenderer();
// Rendering functions.
void Clear(TUint32 iColor);
bool Copy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect);
bool CopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const NGAGE_CopyExData *copydata);
bool CreateTextureData(NGAGE_TextureData *aTextureData, const TInt aWidth, const TInt aHeight);
void DrawLines(NGAGE_Vertex *aVerts, const TInt aCount);
void DrawPoints(NGAGE_Vertex *aVerts, const TInt aCount);
void FillRects(NGAGE_Vertex *aVerts, const TInt aCount);
void Flip();
void SetDrawColor(TUint32 iColor);
void SetClipRect(TInt aX, TInt aY, TInt aWidth, TInt aHeight);
void UpdateFPS();
void SuspendScreenSaver(TBool aSuspend);
// Event handling.
void DisableKeyBlocking();
void HandleEvent(const TWsEvent &aWsEvent);
void PumpEvents();
private:
CRenderer();
void ConstructL(void);
// BackBuffer.
CNRenderer *iRenderer;
// Direct screen access.
CDirectScreenAccess *iDirectScreen;
CFbsBitGc *iScreenGc;
TBool iIsFocused;
// Window server session.
RWsSession iWsSession;
RWindowGroup iWsWindowGroup;
TInt iWsWindowGroupID;
RWindow iWsWindow;
CWsScreenDevice *iWsScreen;
// Event handling.
TRequestStatus iWsEventStatus;
TWsEvent iWsEvent;
// MDirectScreenAccess functions.
void Restart(RDirectScreenAccess::TTerminationReasons aReason);
void AbortNow(RDirectScreenAccess::TTerminationReasons aReason);
// Frame per second.
TBool iShowFPS;
TUint iFPS;
const CFont *iFont;
// Screen saver.
TBool iSuspendScreenSaver;
// Work buffers for texture transformations (reusable to avoid per-frame allocations).
void *iWorkBuffer1;
void *iWorkBuffer2;
TInt iWorkBufferSize;
// Temporary render bitmap to avoid destroying source textures.
CFbsBitmap *iTempRenderBitmap;
TInt iTempRenderBitmapWidth;
TInt iTempRenderBitmapHeight;
// Color modulation lookup tables (pre-calculated to avoid per-pixel FixMul).
TUint8 iColorModLUT[768]; // 256 entries each for R, G, B
TFixed iLastColorR;
TFixed iLastColorG;
TFixed iLastColorB;
// Reusable line points buffer to avoid per-frame allocations in DrawLines.
TPoint *iLinePointsBuffer;
TInt iLinePointsBufferCapacity;
// Cached draw color to avoid redundant SetPenColor/SetBrushColor calls.
TUint32 iLastDrawColor;
// Helper methods.
bool EnsureWorkBufferCapacity(TInt aRequiredSize);
bool EnsureTempBitmapCapacity(TInt aWidth, TInt aHeight);
bool EnsureLinePointsCapacity(TInt aRequiredCount);
void BuildColorModLUT(TFixed rf, TFixed gf, TFixed bf);
CFbsBitmap *GetCardinalRotation(NGAGE_TextureData *aTextureData, TInt aAngleIndex);
};
#endif // ngage_video_render_ngage_c_hpp