@@ -66,14 +66,13 @@ inline pixel_t RGB888_to_RGBA8888(unsigned c) {
6666 #define GET_FROM_RGB888 (c ) (c)
6767#endif
6868
69- #define GET_LINE (y ) \
70- pixel_t *line; \
71- if (_cacheY == y) { \
69+ #define GET_LINE (line, y ) \
70+ if (_cacheY == y && !_cacheLine) { \
7271 line = _cacheLine; \
7372 } else { \
7473 line = _drawTarget->getLine (y); \
7574 _cacheLine = line; \
76- _cacheY = posY ; \
75+ _cacheY = y ; \
7776 }
7877
7978
@@ -146,10 +145,10 @@ Graphics::Graphics() :
146145 _screen(NULL ),
147146 _drawTarget(NULL ),
148147 _font(NULL ),
149- _w(0 ),
150- _h(0 ),
148+ _cacheLine(NULL ),
151149 _cacheY(-1 ),
152- _cacheLine(NULL ) {
150+ _w(0 ),
151+ _h(0 ) {
153152 graphics = this ;
154153}
155154
@@ -182,16 +181,7 @@ void Graphics::deleteFont(Font *font) {
182181
183182void Graphics::drawImageRegion (Canvas *src, const MAPoint2d *dstPoint, const MARect *srcRect) {
184183 if (_drawTarget && _drawTarget != src) {
185- int destY = dstPoint->y ;
186- int srcH = srcRect->height ;
187- if (srcRect->top + srcRect->height > src->_h ) {
188- srcH = src->_h - srcRect->top ;
189- }
190- for (int y = 0 ; y < srcH && destY < _drawTarget->_h ; y++, destY++) {
191- pixel_t *line = src->getLine (y + srcRect->top ) + srcRect->left ;
192- pixel_t *dstLine = _drawTarget->getLine (destY) + dstPoint->x ;
193- memcpy (dstLine, line, srcRect->width * sizeof (pixel_t ));
194- }
184+ _drawTarget->copy (src, srcRect, dstPoint->x , dstPoint->y );
195185 }
196186}
197187
@@ -212,7 +202,8 @@ void Graphics::drawLine(int startX, int startY, int endX, int endY) {
212202 x2 = _w -1 ;
213203 }
214204 if (startY >= 0 && startY < _h) {
215- pixel_t *line = _drawTarget->getLine (startY);
205+ pixel_t *line;
206+ GET_LINE (line, startY);
216207 for (int x = x1; x <= x2; x++) {
217208 if (x >= _drawTarget->x () && x < _drawTarget->w ()) {
218209 line[x] = _drawColor;
@@ -256,7 +247,8 @@ void Graphics::drawPixel(int posX, int posY) {
256247 && posY >= _drawTarget->y ()
257248 && posX < _drawTarget->w ()
258249 && posY < _drawTarget->h ()) {
259- GET_LINE (posY);
250+ pixel_t *line;
251+ GET_LINE (line, posY);
260252 line[posX] = _drawColor;
261253 }
262254}
@@ -423,7 +415,8 @@ int Graphics::getPixel(Canvas *canvas, int posX, int posY) {
423415 && posY > -1
424416 && posX < canvas->_w
425417 && posY < canvas->_h - 1 ) {
426- pixel_t *line = canvas->getLine (posY);
418+ pixel_t *line;
419+ GET_LINE (line, posY);
427420 result = line[posX];
428421 }
429422 return result;
@@ -527,7 +520,8 @@ void Graphics::wuPlot(int posX, int posY, double c) {
527520 && posY >= _drawTarget->y ()
528521 && posX < _drawTarget->w ()
529522 && posY < _drawTarget->h ()) {
530- pixel_t *line = _drawTarget->getLine (posY);
523+ pixel_t *line;
524+ GET_LINE (line, posY);
531525 uint8_t sR , sG , sB ;
532526 uint8_t dR, dG, dB;
533527
0 commit comments