Rendering pipeline. WIP.

svn-id: r32882
This commit is contained in:
Vicent Marti 2008-07-03 10:26:55 +00:00
parent 8dbec866d6
commit 48fd843e75
10 changed files with 104 additions and 68 deletions

View File

@ -70,7 +70,7 @@ static bool launcherDialog(OSystem &system) {
// Clear the main screen // Clear the main screen
system.clearScreen(); system.clearScreen();
GUI::ThemeRenderer *test = new GUI::ThemeRenderer; // GUI::ThemeRenderer *test = new GUI::ThemeRenderer("modern", GUI::ThemeRenderer::kGfxAntialias16bit);
#if defined LOL #if defined LOL

View File

@ -134,6 +134,8 @@ bool XMLParser::parse() {
if (_text.ready() == false) if (_text.ready() == false)
return parserError("XML stream not ready for reading."); return parserError("XML stream not ready for reading.");
cleanup();
bool activeClosure = false; bool activeClosure = false;
bool selfClosure = false; bool selfClosure = false;

View File

@ -332,6 +332,14 @@ protected:
return (*key == 0); return (*key == 0);
} }
/**
* Internal state cleanup. Overload this if your parser needs
* to clean itself up before doing a second parse.
* E.g. the Theme Parser cleans the color palette after parsing
* a theme.
*/
virtual void cleanup() {}
int _pos; /** Current position on the XML buffer. */ int _pos; /** Current position on the XML buffer. */
XMLStream _text; /** Buffer with the text being parsed */ XMLStream _text; /** Buffer with the text being parsed */
Common::String _fileName; Common::String _fileName;

View File

@ -406,7 +406,8 @@ public:
* *
* @param sys Pointer to the global System class * @param sys Pointer to the global System class
*/ */
virtual void copyFrame(OSystem *sys, Common::Rect &r) = 0; virtual void copyFrame(OSystem *sys, const Common::Rect &r) = 0;
virtual void copyWholeFrame(OSystem *sys) = 0;
/** /**
* Blits a given graphics surface on top of the current drawing surface. * Blits a given graphics surface on top of the current drawing surface.
@ -533,7 +534,7 @@ public:
/** /**
* @see VectorRenderer::copyFrame() * @see VectorRenderer::copyFrame()
*/ */
virtual void copyFrame(OSystem *sys, Common::Rect &r) { virtual void copyFrame(OSystem *sys, const Common::Rect &r) {
#ifdef OVERLAY_MULTIPLE_DEPTHS // TODO: change OSystem to support templated copyRectToOverlay #ifdef OVERLAY_MULTIPLE_DEPTHS // TODO: change OSystem to support templated copyRectToOverlay
sys->copyRectToOverlay((const PixelType*)_activeSurface->pixels, sys->copyRectToOverlay((const PixelType*)_activeSurface->pixels,
_activeSurface->pitch, r.top, r.left, r.width(), r.height()); _activeSurface->pitch, r.top, r.left, r.width(), r.height());
@ -543,6 +544,16 @@ public:
#endif #endif
} }
virtual void copyWholeFrame(OSystem *sys) {
#ifdef OVERLAY_MULTIPLE_DEPTHS
sys->copyRectToOverlay((const PixelType*)_activeSurface->getBasePtr(0, 0),
_activeSurface->w, 0, 0, _activeSurface->w, _activeSurface->h);
#else
sys->copyRectToOverlay((const OverlayColor*)_activeSurface->getBasePtr(0, 0),
_activeSurface->w, 0, 0, _activeSurface->w, _activeSurface->h);
#endif
}
/** /**
* @see VectorRenderer::blitSurface() * @see VectorRenderer::blitSurface()
*/ */

View File

@ -58,7 +58,7 @@ bool ThemeRenderer::loadDefaultXML() {
"<layout_info>" "<layout_info>"
"</layout_info>"; "</layout_info>";
if (!parser()->loadBuffer(defaultXML, true)) if (!parser()->loadBuffer(defaultXML, false))
return false; return false;
return parser()->parse(); return parser()->parse();

View File

@ -63,6 +63,15 @@ ThemeParser::ThemeParser(ThemeRenderer *parent) : XMLParser() {
_theme = parent; _theme = parent;
} }
void ThemeParser::cleanup() {
delete _defaultStepGlobal;
delete _defaultStepLocal;
_defaultStepGlobal = defaultDrawStep();
_defaultStepLocal = 0;
_palette.clear();
}
bool ThemeParser::keyCallback(Common::String keyName) { bool ThemeParser::keyCallback(Common::String keyName) {
// automatically handle with a function from the hash table. // automatically handle with a function from the hash table.
if (!_callbacks.contains(_activeKey.top()->name)) if (!_callbacks.contains(_activeKey.top()->name))

View File

@ -329,6 +329,8 @@ protected:
bool parserCallback_layoutInfo(); bool parserCallback_layoutInfo();
bool parserCallback_defaultSet(); bool parserCallback_defaultSet();
void cleanup();
Graphics::DrawStep *newDrawStep(); Graphics::DrawStep *newDrawStep();
Graphics::DrawStep *defaultDrawStep(); Graphics::DrawStep *defaultDrawStep();
bool parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawstep, bool functionSpecific); bool parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawstep, bool functionSpecific);

View File

@ -68,10 +68,9 @@ const char *ThemeRenderer::kDrawDataStrings[] = {
"separator" "separator"
}; };
ThemeRenderer::ThemeRenderer() : ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) :
_vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled), _vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled),
_screen(0), _bytesPerPixel(0), _initOk(false), _themeOk(false), _screen(0), _bytesPerPixel(0), _initOk(false), _themeOk(false) {
_needThemeLoad(false), _enabled(false) {
_system = g_system; _system = g_system;
_parser = new ThemeParser(this); _parser = new ThemeParser(this);
@ -79,8 +78,50 @@ ThemeRenderer::ThemeRenderer() :
_widgets[i] = 0; _widgets[i] = 0;
} }
_graphicsMode = kGfxAntialias16bit; // default GFX mode _graphicsMode = mode;
// TODO: load this from a config file setGraphicsMode(_graphicsMode);
if (isThemeLoadingRequired())
loadTheme(themeName);
_initOk = true;
_themeName = themeName;
}
bool ThemeRenderer::init() {
// reset everything and reload the graphics
deinit();
setGraphicsMode(_graphicsMode);
if (_screen->pixels) {
_initOk = true;
clearAll();
resetDrawArea();
}
if (isThemeLoadingRequired())
loadTheme(_themeName);
return true;
}
void ThemeRenderer::deinit() {
if (_initOk) {
_system->hideOverlay();
freeRenderer();
freeScreen();
unloadTheme();
_initOk = false;
}
}
void ThemeRenderer::clearAll() {
if (!_initOk)
return;
_vectorRenderer->clearSurface();
_vectorRenderer->copyWholeFrame(_system);
_system->updateScreen();
} }
template<typename PixelType> template<typename PixelType>
@ -92,16 +133,7 @@ void ThemeRenderer::screenInit() {
_system->clearOverlay(); _system->clearOverlay();
} }
void ThemeRenderer::setGraphicsMode(Graphics_Mode mode) { void ThemeRenderer::setGraphicsMode(GraphicsMode mode) {
// FIXME: reload theme everytime we change resolution...
// what if we change the renderer too?
// ...We may need to reload it to re-cache the widget
// surfaces
if (_system->getOverlayWidth() != _screen->w ||
_system->getOverlayHeight() != _screen->h)
_needThemeLoad = true;
switch (mode) { switch (mode) {
case kGfxStandard16bit: case kGfxStandard16bit:
case kGfxAntialias16bit: case kGfxAntialias16bit:
@ -133,6 +165,7 @@ bool ThemeRenderer::addDrawData(DrawData data_id, bool cached) {
_widgets[data_id] = new WidgetDrawData; _widgets[data_id] = new WidgetDrawData;
_widgets[data_id]->_cached = cached; _widgets[data_id]->_cached = cached;
_widgets[data_id]->_surfaceCache = 0;
return true; return true;
} }
@ -158,7 +191,6 @@ bool ThemeRenderer::loadTheme(Common::String themeName) {
} }
} }
_needThemeLoad = false;
_themeOk = true; _themeOk = true;
return true; return true;
} }
@ -182,18 +214,6 @@ bool ThemeRenderer::loadThemeXML(Common::String themeName) {
return parser()->parse(); return parser()->parse();
} }
bool ThemeRenderer::init() {
if (!_screen || _system->getOverlayWidth() != _screen->w ||
_system->getOverlayHeight() != _screen->h )
setGraphicsMode(_graphicsMode);
if (needThemeReload())
loadTheme();
_initOk = true;
return true;
}
bool ThemeRenderer::isWidgetCached(DrawData type, const Common::Rect &r) { bool ThemeRenderer::isWidgetCached(DrawData type, const Common::Rect &r) {
return _widgets[type] && _widgets[type]->_cached && return _widgets[type] && _widgets[type]->_cached &&
_widgets[type]->_surfaceCache->w == r.width() && _widgets[type]->_surfaceCache->w == r.width() &&

View File

@ -73,7 +73,7 @@ class ThemeRenderer : public Theme {
static const int kMaxDialogDepth = 4; static const int kMaxDialogDepth = 4;
public: public:
enum Graphics_Mode { enum GraphicsMode {
kGfxDisabled = 0, kGfxDisabled = 0,
kGfxStandard16bit, kGfxStandard16bit,
kGfxAntialias16bit kGfxAntialias16bit
@ -109,34 +109,31 @@ public:
kDrawDataMAX kDrawDataMAX
}; };
ThemeRenderer(); ThemeRenderer(Common::String themeName, GraphicsMode mode);
~ThemeRenderer() { ~ThemeRenderer() {
freeRenderer(); freeRenderer();
freeScreen(); freeScreen();
unloadTheme(); unloadTheme();
delete _parser; delete _parser;
while (!_dialogStack.empty())
delete _dialogStack.pop();
} }
// virtual methods from Theme // virtual methods from Theme
bool init(); bool init();
void deinit() {} void deinit();
void clearAll();
void refresh() {} void refresh() {}
void enable() {} void enable() {}
void disable() {} void disable() {}
void openDialog() {} void openDialog() {}
void closeAllDialogs() {} void closeAllDialogs() {}
void clearAll() {}
void updateScreen() {} void updateScreen() {}
void resetDrawArea() {} void resetDrawArea() {}
void openDialog(bool top) {}
virtual bool isDynamic() { void openDialog(bool top) {}
return true;
}
/** Font management */ /** Font management */
const Graphics::Font *getFont(FontStyle font) const { return _font; } const Graphics::Font *getFont(FontStyle font) const { return _font; }
@ -185,7 +182,8 @@ public:
return _initOk && _themeOk; return _initOk && _themeOk;
} }
bool loadTheme() { // REMOVED: theme name is looked up in NewGUI and passed to the constructor
/* bool loadTheme() {
ConfMan.registerDefault("gui_theme", "default"); ConfMan.registerDefault("gui_theme", "default");
Common::String style(ConfMan.get("gui_theme")); Common::String style(ConfMan.get("gui_theme"));
@ -193,16 +191,10 @@ public:
style = "modern"; style = "modern";
return loadTheme(style); return loadTheme(style);
} } */
bool loadTheme(Common::String themeName); bool loadTheme(Common::String themeName);
void setGraphicsMode(GraphicsMode mode);
void closeTopDialog() {
assert(_dialogStack.empty() == false);
delete _dialogStack.pop();
}
void setGraphicsMode(Graphics_Mode mode);
protected: protected:
template<typename PixelType> void screenInit(); template<typename PixelType> void screenInit();
@ -236,16 +228,6 @@ protected:
} }
} }
Dialog *getTopDialog() const {
if (_dialogStack.empty())
return 0;
return _dialogStack.top();
}
bool needThemeReload() {
return (_themeOk == false || _needThemeLoad == true);
}
bool needRedraw() { bool needRedraw() {
return true; return true;
} }
@ -275,20 +257,19 @@ protected:
Graphics::Surface *_screen; Graphics::Surface *_screen;
int _bytesPerPixel; int _bytesPerPixel;
Graphics_Mode _graphicsMode; GraphicsMode _graphicsMode;
Common::String _fontName; Common::String _fontName;
const Graphics::Font *_font; const Graphics::Font *_font;
WidgetDrawData *_widgets[kDrawDataMAX]; WidgetDrawData *_widgets[kDrawDataMAX];
Common::FixedStack<Dialog *, kMaxDialogDepth> _dialogStack;
Common::Array<Common::Rect> _dirtyScreen; Common::Array<Common::Rect> _dirtyScreen;
bool _initOk; bool _initOk;
bool _themeOk; bool _themeOk;
bool _caching; bool _caching;
bool _needThemeLoad;
bool _enabled; Common::String _themeName;
}; };
} // end of namespace GUI. } // end of namespace GUI.

View File

@ -31,6 +31,7 @@
#include "gui/eval.h" #include "gui/eval.h"
#include "gui/ThemeModern.h" #include "gui/ThemeModern.h"
#include "gui/ThemeClassic.h" #include "gui/ThemeClassic.h"
#include "gui/ThemeRenderer.h"
#include "common/config-manager.h" #include "common/config-manager.h"
@ -142,7 +143,7 @@ bool NewGui::loadNewTheme(const Common::String &style) {
delete _theme; delete _theme;
_theme = 0; _theme = 0;
if (style.compareToIgnoreCase("classic (builtin)") == 0 || /* if (style.compareToIgnoreCase("classic (builtin)") == 0 ||
style.compareToIgnoreCase("classic") == 0) { style.compareToIgnoreCase("classic") == 0) {
_theme = new ThemeClassic(_system, style); _theme = new ThemeClassic(_system, style);
} else { } else {
@ -159,7 +160,9 @@ bool NewGui::loadNewTheme(const Common::String &style) {
warning("Config '%s' is NOT usable for themes or not found", style.c_str()); warning("Config '%s' is NOT usable for themes or not found", style.c_str());
} }
} }
cfg.clear(); cfg.clear(); */
_theme = new ThemeRenderer(style, GUI::ThemeRenderer::kGfxAntialias16bit);
if (!_theme) if (!_theme)
return (!oldTheme.empty() ? loadNewTheme(oldTheme) : false); return (!oldTheme.empty() ? loadNewTheme(oldTheme) : false);