3 #include <lib/gdi/grc.h>
4 #include <lib/gdi/font.h>
5 #include <lib/gdi/lcd.h>
6 #include <lib/system/init.h>
7 #include <lib/system/init_num.h>
9 void *gRC::thread_wrapper(void *ptr
)
12 return ((gRC
*)ptr
)->thread();
21 pthread_mutex_init(&mutex
, 0);
22 pthread_cond_init(&cond
, 0);
24 eDebug(pthread_create(&the_thread
, 0, thread_wrapper
, this)?"RC thread couldn't be created":"RC thread createted successfully");
29 fbClass::getInstance()->lock();
31 eDBoxLCD::getInstance()->lock();
36 o
.opcode
=gOpcode::shutdown
;
38 eDebug("waiting for gRC thread shutdown");
39 pthread_join(the_thread
, 0);
40 eDebug("gRC thread has finished");
41 pthread_mutex_destroy(&mutex
);
42 pthread_cond_destroy(&cond
);
49 pthread_mutex_lock(&mutex
);
52 gOpcode
o(queue
[rp
++]);
55 pthread_mutex_unlock(&mutex
);
56 if (o
.opcode
==gOpcode::shutdown
)
62 pthread_cond_wait(&cond
, &mutex
);
63 pthread_mutex_unlock(&mutex
);
70 gRC
&gRC::getInstance()
75 static int gPainter_instances
;
77 gPainter::gPainter(gDC
&dc
, eRect rect
): dc(dc
), rc(gRC::getInstance()), foregroundColor(0), backgroundColor(0)
80 rect
=eRect(ePoint(0, 0), dc
.getSize());
81 // ASSERT(!gPainter_instances);
92 void gPainter::begin(const eRect
&rect
)
99 o
.opcode
=gOpcode::begin
;
100 o
.parm
.begin
=new gOpcode::para::pbegin(rect
);
101 // cliparea=std::stack<eRect, std::list<eRect> >();
102 cliparea
=std::stack
<eRect
>();
104 setLogicalZero(cliparea
.top().topLeft());
108 void gPainter::setBackgroundColor(const gColor
&color
)
110 backgroundColor
=color
;
113 void gPainter::setForegroundColor(const gColor
&color
)
115 foregroundColor
=color
;
118 void gPainter::setFont(const gFont
&mfont
)
123 void gPainter::renderText(const eRect
&pos
, const std::string
&string
, int flags
)
128 area
.moveBy(logicalZero
.x(), logicalZero
.y());
132 o
.opcode
=gOpcode::renderText
;
133 o
.parm
.renderText
=new gOpcode::para::prenderText(font
, area
, string
, dc
.getRGB(foregroundColor
), dc
.getRGB(backgroundColor
));
138 void gPainter::renderPara(eTextPara
¶
, ePoint offset
)
144 o
.opcode
=gOpcode::renderPara
;
145 o
.parm
.renderPara
=new gOpcode::para::prenderPara(logicalZero
+offset
, para
.grab(), dc
.getRGB(foregroundColor
), dc
.getRGB(backgroundColor
));
149 void gPainter::fill(const eRect
&area
)
155 o
.opcode
=gOpcode::fill
;
157 a
.moveBy(logicalZero
.x(), logicalZero
.y());
160 o
.parm
.fill
=new gOpcode::para::pfill(a
, foregroundColor
);
164 void gPainter::clear()
170 o
.opcode
=gOpcode::fill
;
171 o
.parm
.fill
=new gOpcode::para::pfill(cliparea
.top(), backgroundColor
);
175 void gPainter::setPalette(gRGB
*colors
, int start
, int len
)
181 o
.opcode
=gOpcode::setPalette
;
182 gPalette
*p
=new gPalette
;
184 p
->data
=new gRGB
[len
];
185 memcpy(p
->data
, colors
, len
*sizeof(gRGB
));
188 o
.parm
.setPalette
=new gOpcode::para::psetPalette(p
);
192 void gPainter::mergePalette(gPixmap
&target
)
198 o
.opcode
=gOpcode::mergePalette
;
199 o
.parm
.mergePalette
=new gOpcode::para::pmergePalette(target
.lock());
203 void gPainter::line(ePoint start
, ePoint end
)
209 o
.opcode
=gOpcode::line
;
210 o
.parm
.line
=new gOpcode::para::pline(start
+logicalZero
, end
+logicalZero
, foregroundColor
);
214 void gPainter::setLogicalZero(ePoint rel
)
219 void gPainter::moveLogicalZero(ePoint rel
)
224 void gPainter::resetLogicalZero()
230 void gPainter::clip(eRect clip
)
236 o
.opcode
=gOpcode::clip
;
237 clip
.moveBy(logicalZero
.x(), logicalZero
.y());
238 cliparea
.push(cliparea
.top()&clip
);
239 o
.parm
.clip
=new gOpcode::para::pclip(cliparea
.top());
244 void gPainter::clippop()
248 ASSERT (cliparea
.size()>1);
251 o
.opcode
=gOpcode::clip
;
253 o
.parm
.clip
=new gOpcode::para::pclip(cliparea
.top());
257 void gPainter::flush()
263 o
.opcode
=gOpcode::flush
;
271 o
.opcode
=gOpcode::end
;
279 gPixmapDC::gPixmapDC(): pixmap(0)
283 gPixmapDC::gPixmapDC(gPixmap
*pixmap
): pixmap(pixmap
)
287 gPixmapDC::~gPixmapDC()
292 void gPixmapDC::exec(gOpcode
*o
)
297 clip
=o
->parm
.begin
->area
;
298 delete o
->parm
.begin
;
300 case gOpcode::renderText
:
302 eTextPara
*para
=new eTextPara(o
->parm
.renderText
->area
);
303 para
->setFont(o
->parm
.renderText
->font
);
304 para
->renderString(o
->parm
.renderText
->text
, o
->flags
);
305 para
->blit(*this, ePoint(0, 0), o
->parm
.renderText
->backgroundColor
, o
->parm
.renderText
->foregroundColor
);
307 if (o
->parm
.renderText
->text
)
308 free(o
->parm
.renderText
->text
);
309 delete o
->parm
.renderText
;
312 case gOpcode::renderPara
:
314 o
->parm
.renderPara
->textpara
->blit(*this, o
->parm
.renderPara
->offset
, o
->parm
.renderPara
->backgroundColor
, o
->parm
.renderPara
->foregroundColor
);
315 o
->parm
.renderPara
->textpara
->destroy();
316 delete o
->parm
.renderPara
;
320 pixmap
->fill(o
->parm
.fill
->area
, o
->parm
.fill
->color
);
325 if (o
->parm
.blit
->clip
.isNull())
326 o
->parm
.blit
->clip
=clip
;
328 o
->parm
.blit
->clip
&=clip
;
329 pixmap
->blit(*o
->parm
.blit
->pixmap
, o
->parm
.blit
->position
, o
->parm
.blit
->clip
, o
->flags
);
330 o
->parm
.blit
->pixmap
->unlock();
334 case gOpcode::setPalette
:
335 if (o
->parm
.setPalette
->palette
->start
>pixmap
->clut
.colors
)
336 o
->parm
.setPalette
->palette
->start
=pixmap
->clut
.colors
;
337 if (o
->parm
.setPalette
->palette
->colors
>(pixmap
->clut
.colors
-o
->parm
.setPalette
->palette
->start
))
338 o
->parm
.setPalette
->palette
->colors
=pixmap
->clut
.colors
-o
->parm
.setPalette
->palette
->start
;
339 if (o
->parm
.setPalette
->palette
->colors
)
340 memcpy(pixmap
->clut
.data
+o
->parm
.setPalette
->palette
->start
, o
->parm
.setPalette
->palette
->data
, o
->parm
.setPalette
->palette
->colors
*sizeof(gRGB
));
341 delete[] o
->parm
.setPalette
->palette
->data
;
342 delete o
->parm
.setPalette
->palette
;
343 delete o
->parm
.setPalette
;
345 case gOpcode::mergePalette
:
346 pixmap
->mergePalette(*o
->parm
.blit
->pixmap
);
347 o
->parm
.blit
->pixmap
->unlock();
351 pixmap
->line(o
->parm
.line
->start
, o
->parm
.line
->end
, o
->parm
.line
->color
);
355 clip
=o
->parm
.clip
->clip
;
363 eFatal("illegal opcode %d. expect memory leak!", o
->opcode
);
367 gRGB
gPixmapDC::getRGB(gColor col
)
369 if ((!pixmap
) || (!pixmap
->clut
.data
))
370 return gRGB(col
, col
, col
);
373 eFatal("bla transp");
374 return gRGB(0, 0, 0, 0xFF);
376 return pixmap
->clut
.data
[col
];
379 eAutoInitP0
<gRC
> init_grc(eAutoInitNumbers::graphic
, "gRC");