Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[vdr] Re: OSD and patterns
Klaus Schmidinger writes:
>
> Take a look at how, for instance, cSkinClassicDisplayChannel does it.
> It creates a cOsd object in its consructor and deletes it in its
> destructor. Since at any time there is only one cSkin* object alive,
> this is an easy to follow rule.
>
> At no time is there more than one object that has direct access to
> any cOsd object, so there is no need for a "pattern" as you described it.
You are probably right. Here is the patch anyway, do as you wish.
yours,
Jouni
diff -Naur vdr-1.3.10/PLUGINS/src/osddemo/osddemo.c vdr-1.3.10-mod/PLUGINS/src/osddemo/osddemo.c
--- vdr-1.3.10/PLUGINS/src/osddemo/osddemo.c Sun May 16 12:28:51 2004
+++ vdr-1.3.10-mod/PLUGINS/src/osddemo/osddemo.c Sun Jun 13 15:49:26 2004
@@ -16,7 +16,7 @@
class cLineGame : public cOsdObject {
private:
- cOsd *osd;
+ cOsdPtr osd;
int x;
int y;
tColor color;
@@ -29,20 +29,18 @@
cLineGame::cLineGame(void)
{
- osd = NULL;
x = y = 50;
color = clrRed;
}
cLineGame::~cLineGame()
{
- delete osd;
}
void cLineGame::Show(void)
{
osd = cOsdProvider::NewOsd(100, 50);
- if (osd) {
+ if (osd.active()) {
tArea Area = { 0, 0, 99, 199, 4 };
osd->SetAreas(&Area, 1);
osd->DrawRectangle(0, 0, 99, 199, clrGray50);
diff -Naur vdr-1.3.10/dvbosd.c vdr-1.3.10-mod/dvbosd.c
--- vdr-1.3.10/dvbosd.c Sat May 1 18:10:44 2004
+++ vdr-1.3.10-mod/dvbosd.c Sun Jun 13 14:42:44 2004
@@ -144,7 +144,7 @@
osdDev = OsdDev;
}
-cOsd *cDvbOsdProvider::CreateOsd(int Left, int Top)
+cOsdPtr cDvbOsdProvider::CreateOsd(int Left, int Top)
{
- return new cDvbOsd(Left, Top, osdDev);
+ return cOsdPtr(new cDvbOsd(Left, Top, osdDev));
}
diff -Naur vdr-1.3.10/dvbosd.h vdr-1.3.10-mod/dvbosd.h
--- vdr-1.3.10/dvbosd.h Fri Apr 30 16:44:16 2004
+++ vdr-1.3.10-mod/dvbosd.h Sat Jun 12 19:48:29 2004
@@ -31,7 +31,7 @@
int osdDev;
public:
cDvbOsdProvider(int OsdDev);
- virtual cOsd *CreateOsd(int Left, int Top);
- };
+ virtual cOsdPtr CreateOsd(int Left, int Top);
+};
#endif //__DVBOSD_H
diff -Naur vdr-1.3.10/dvbspu.c vdr-1.3.10-mod/dvbspu.c
--- vdr-1.3.10/dvbspu.c Sat May 22 17:02:32 2004
+++ vdr-1.3.10-mod/dvbspu.c Sun Jun 13 14:45:13 2004
@@ -225,7 +225,6 @@
clean = true;
scaleMode = eSpuNormal;
spu = NULL;
- osd = NULL;
spubmp = NULL;
}
@@ -233,7 +232,6 @@
{
delete spubmp;
delete spu;
- delete osd;
}
void cDvbSpuDecoder::processSPU(uint32_t pts, uint8_t * buf)
@@ -363,8 +361,8 @@
}
if (bg || fg) {
- if (osd == NULL)
- if ((osd = cOsdProvider::NewOsd(0, 0)) == NULL) {
+ if (osd.active())
+ if ((osd = cOsdProvider::NewOsd(0, 0)).active()) {
dsyslog("NewOsd failed\n");
return;
}
@@ -383,8 +381,7 @@
void cDvbSpuDecoder::Hide(void)
{
- delete osd;
- osd = NULL;
+ osd.release();
}
void cDvbSpuDecoder::Empty(void)
diff -Naur vdr-1.3.10/dvbspu.h vdr-1.3.10-mod/dvbspu.h
--- vdr-1.3.10/dvbspu.h Mon May 31 11:49:20 2004
+++ vdr-1.3.10-mod/dvbspu.h Sat Jun 12 19:53:41 2004
@@ -91,7 +91,7 @@
class cDvbSpuDecoder:public cSpuDecoder {
private:
- cOsd * osd;
+ cOsdPtr osd;
// processing state
uint8_t *spu;
diff -Naur vdr-1.3.10/osd.c vdr-1.3.10-mod/osd.c
--- vdr-1.3.10/osd.c Sat Jun 5 19:52:51 2004
+++ vdr-1.3.10-mod/osd.c Sun Jun 13 15:00:43 2004
@@ -585,6 +585,7 @@
top = Top;
width = height = 0;
isOpen = true;
+ refcount = 0;
}
cOsd::~cOsd()
@@ -711,12 +712,14 @@
osdProvider = NULL;
}
-cOsd *cOsdProvider::NewOsd(int Left, int Top)
+cOsdPtr cOsdProvider::NewOsd(int Left, int Top)
{
if (osdProvider)
return osdProvider->CreateOsd(Left, Top);
esyslog("ERROR: no OSD provider available - using dummy OSD!");
- return new cOsd(Left, Top); // create a dummy cOsd, so that access won't result in a segfault
+ return cOsdPtr(new cOsd(Left, Top)); // create a dummy cOsd, so that
+ // access won't result in a
+ // segfault
}
void cOsdProvider::Shutdown(void)
@@ -729,7 +732,6 @@
cTextScroller::cTextScroller(void)
{
- osd = NULL;
left = top = width = height = 0;
font = NULL;
colorFg = 0;
@@ -738,12 +740,12 @@
shown = 0;
}
-cTextScroller::cTextScroller(cOsd *Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg)
+cTextScroller::cTextScroller(cOsdPtr Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg)
{
Set(Osd, Left, Top, Width, Height, Text, Font, ColorFg, ColorBg);
}
-void cTextScroller::Set(cOsd *Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg)
+void cTextScroller::Set(cOsdPtr Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg)
{
osd = Osd;
left = Left;
@@ -762,15 +764,15 @@
void cTextScroller::Reset(void)
{
- osd = NULL; // just makes sure it won't draw anything
+ osd.release(); // just makes sure it won't draw anything
}
void cTextScroller::DrawText(void)
{
- if (osd) {
- for (int i = 0; i < shown; i++)
+ if (osd.active()) {
+ for (int i = 0; i < shown; i++)
osd->DrawText(left, top + i * font->Height(), textWrapper.GetLine(offset + i), colorFg, colorBg, font, width);
- }
+ }
}
void cTextScroller::Scroll(bool Up, bool Page)
diff -Naur vdr-1.3.10/osd.h vdr-1.3.10-mod/osd.h
--- vdr-1.3.10/osd.h Sat Jun 5 15:38:44 2004
+++ vdr-1.3.10-mod/osd.h Sun Jun 13 15:53:44 2004
@@ -208,12 +208,14 @@
#define MAXOSDAREAS 16
class cOsd {
+ friend class cOsdPtr;
private:
static bool isOpen;
cBitmap *savedRegion;
cBitmap *bitmaps[MAXOSDAREAS];
int numBitmaps;
int left, top, width, height;
+ int refcount;
public:
cOsd(int Left, int Top);
///< Initializes the OSD with the given coordinates.
@@ -314,18 +316,64 @@
///< Actually commits all data to the OSD hardware.
};
+class cOsdPtr {
+private:
+ cOsd *_osd;
+
+public:
+
+ cOsdPtr() {
+ _osd = 0;
+ };
+
+ cOsdPtr(cOsd *osd) {
+ _osd = osd;
+ if (_osd) _osd->refcount++;
+ };
+
+ cOsdPtr(const cOsdPtr& osdptr) {
+ _osd = ((cOsdPtr *)&osdptr)->_osd;
+ if (_osd) _osd->refcount++;
+ };
+
+ ~cOsdPtr() {release();};
+
+ cOsdPtr& operator=(const cOsdPtr& osdptr) {
+ if (this != &osdptr) {
+ release();
+ _osd = ((cOsdPtr *)&osdptr)->_osd;
+ _osd->refcount++;
+ }
+ return *this;
+ };
+
+ cOsd& operator*() { return *_osd; };
+ cOsd* operator->() { return _osd; };
+
+ bool active(void) {
+ return (_osd != 0);
+ };
+
+ void release(void) {
+ if (_osd && --_osd->refcount == 0) {
+ delete _osd;
+ }
+ _osd = 0;
+ };
+};
+
class cOsdProvider {
private:
static cOsdProvider *osdProvider;
protected:
- virtual cOsd *CreateOsd(int Left, int Top) = 0;
+ virtual cOsdPtr CreateOsd(int Left, int Top) = 0;
///< Returns a pointer to a newly created cOsd object, which will be located
///< at the given coordinates.
public:
cOsdProvider(void);
//XXX maybe parameter to make this one "sticky"??? (frame-buffer etc.)
virtual ~cOsdProvider();
- static cOsd *NewOsd(int Left, int Top);
+ static cOsdPtr NewOsd(int Left, int Top);
///< Returns a pointer to a newly created cOsd object, which will be located
///< at the given coordinates. When the cOsd object is no longer needed, the
///< caller must delete it.
@@ -335,7 +383,7 @@
class cTextScroller {
private:
- cOsd *osd;
+ cOsdPtr osd;
int left, top, width, height;
const cFont *font;
tColor colorFg, colorBg;
@@ -344,8 +392,8 @@
void DrawText(void);
public:
cTextScroller(void);
- cTextScroller(cOsd *Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg);
- void Set(cOsd *Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg);
+ cTextScroller(cOsdPtr Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg);
+ void Set(cOsdPtr Osd, int Left, int Top, int Width, int Height, const char *Text, const cFont *Font, tColor ColorFg, tColor ColorBg);
void Reset(void);
int Left(void) { return left; }
int Top(void) { return top; }
diff -Naur vdr-1.3.10/skinclassic.c vdr-1.3.10-mod/skinclassic.c
--- vdr-1.3.10/skinclassic.c Sat May 29 17:04:50 2004
+++ vdr-1.3.10-mod/skinclassic.c Sat Jun 12 20:22:25 2004
@@ -73,7 +73,7 @@
class cSkinClassicDisplayChannel : public cSkinDisplayChannel {
private:
- cOsd *osd;
+ cOsdPtr osd;
int lineHeight;
int timeWidth;
bool message;
@@ -101,7 +101,6 @@
cSkinClassicDisplayChannel::~cSkinClassicDisplayChannel()
{
- delete osd;
}
void cSkinClassicDisplayChannel::SetChannel(const cChannel *Channel, int Number)
@@ -151,7 +150,7 @@
class cSkinClassicDisplayMenu : public cSkinDisplayMenu {
private:
- cOsd *osd;
+ cOsdPtr osd;
int x0, x1;
int y0, y1, y2, y3, y4, y5;
int lineHeight;
@@ -200,7 +199,6 @@
cSkinClassicDisplayMenu::~cSkinClassicDisplayMenu()
{
- delete osd;
}
void cSkinClassicDisplayMenu::SetScrollbar(void)
@@ -348,7 +346,7 @@
class cSkinClassicDisplayReplay : public cSkinDisplayReplay {
private:
- cOsd *osd;
+ cOsdPtr osd;
int x0, x1;
int y0, y1, y2, y3;
int lastCurrentWidth;
@@ -386,7 +384,6 @@
cSkinClassicDisplayReplay::~cSkinClassicDisplayReplay()
{
- delete osd;
}
void cSkinClassicDisplayReplay::SetTitle(const char *Title)
@@ -458,7 +455,7 @@
class cSkinClassicDisplayVolume : public cSkinDisplayVolume {
private:
- cOsd *osd;
+ cOsdPtr osd;
public:
cSkinClassicDisplayVolume(void);
virtual ~cSkinClassicDisplayVolume();
@@ -477,7 +474,6 @@
cSkinClassicDisplayVolume::~cSkinClassicDisplayVolume()
{
- delete osd;
}
void cSkinClassicDisplayVolume::SetVolume(int Current, int Total, bool Mute)
@@ -506,7 +502,7 @@
class cSkinClassicDisplayMessage : public cSkinDisplayMessage {
private:
- cOsd *osd;
+ cOsdPtr osd;
public:
cSkinClassicDisplayMessage(void);
virtual ~cSkinClassicDisplayMessage();
@@ -525,7 +521,6 @@
cSkinClassicDisplayMessage::~cSkinClassicDisplayMessage()
{
- delete osd;
}
void cSkinClassicDisplayMessage::SetMessage(eMessageType Type, const char *Text)
diff -Naur vdr-1.3.10/skinsttng.c vdr-1.3.10-mod/skinsttng.c
--- vdr-1.3.10/skinsttng.c Sat May 29 17:05:12 2004
+++ vdr-1.3.10-mod/skinsttng.c Sat Jun 12 20:20:45 2004
@@ -118,7 +118,7 @@
class cSkinSTTNGDisplayChannel : public cSkinDisplayChannel {
private:
- cOsd *osd;
+ cOsdPtr osd;
int x0, x1, x2, x3, x4, x5, x6, x7;
int y0, y1, y2, y3, y4, y5, y6, y7;
bool withInfo;
@@ -218,7 +218,6 @@
cSkinSTTNGDisplayChannel::~cSkinSTTNGDisplayChannel()
{
- delete osd;
}
void cSkinSTTNGDisplayChannel::SetChannel(const cChannel *Channel, int Number)
@@ -314,7 +313,7 @@
class cSkinSTTNGDisplayMenu : public cSkinDisplayMenu {
private:
- cOsd *osd;
+ cOsdPtr osd;
int x0, x1, x2, x3, x4, x5, x6, x7;
int y0, y1, y2, y3, y4, y5, y6, y7;
int lineHeight;
@@ -398,7 +397,6 @@
cSkinSTTNGDisplayMenu::~cSkinSTTNGDisplayMenu()
{
- delete osd;
}
void cSkinSTTNGDisplayMenu::SetScrollbar(void)
@@ -594,7 +592,7 @@
class cSkinSTTNGDisplayReplay : public cSkinDisplayReplay {
private:
- cOsd *osd;
+ cOsdPtr osd;
int x0, x1, x2, x3, x4, x5, x6, x7;
int y0, y1, y2, y3, y4, y5, y6, y7;
tColor frameColor;
@@ -671,7 +669,6 @@
cSkinSTTNGDisplayReplay::~cSkinSTTNGDisplayReplay()
{
- delete osd;
}
void cSkinSTTNGDisplayReplay::SetTitle(const char *Title)
@@ -745,7 +742,7 @@
class cSkinSTTNGDisplayVolume : public cSkinDisplayVolume {
private:
- cOsd *osd;
+ cOsdPtr osd;
int x0, x1, x2, x3, x4, x5, x6, x7;
int y0, y1;
tColor frameColor;
@@ -786,7 +783,6 @@
cSkinSTTNGDisplayVolume::~cSkinSTTNGDisplayVolume()
{
- delete osd;
}
void cSkinSTTNGDisplayVolume::SetVolume(int Current, int Total, bool Mute)
@@ -826,7 +822,7 @@
class cSkinSTTNGDisplayMessage : public cSkinDisplayMessage {
private:
- cOsd *osd;
+ cOsdPtr osd;
int x0, x1, x2, x3, x4, x5, x6, x7;
int y0, y1;
public:
@@ -863,7 +859,6 @@
cSkinSTTNGDisplayMessage::~cSkinSTTNGDisplayMessage()
{
- delete osd;
}
void cSkinSTTNGDisplayMessage::SetMessage(eMessageType Type, const char *Text)
Home |
Main Index |
Thread Index