54 final static int HOST_TYPE_IMAGE = 1; |
54 final static int HOST_TYPE_IMAGE = 1; |
55 final static int HOST_TYPE_CANVAS = 2; |
55 final static int HOST_TYPE_CANVAS = 2; |
56 final static int HOST_TYPE_CUSTOMITEM = 3; |
56 final static int HOST_TYPE_CUSTOMITEM = 3; |
57 |
57 |
58 // Flags for raising settings validation |
58 // Flags for raising settings validation |
59 private final static int NONE = 0; |
59 // FORCE_SETTINGS Forces settings to validated also in case |
60 private final static int COLOR = 1; |
60 // there's only one Graphics instance as client, normally |
61 private final static int CLIP = 2; |
61 // settings are not checked in such case |
62 private final static int FONT = 4; |
62 final static int NONE = 0; |
63 private final static int STROKESTYLE = 8; |
63 final static int COLOR = 1; |
64 private final static int COORS_TRANSLATION = 16; |
64 final static int CLIP = 2; |
|
65 final static int FONT = 4; |
|
66 final static int STROKESTYLE = 8; |
|
67 final static int COORDS_TRANSLATION = 16; |
|
68 final static int FORCE_SETTINGS = 32; |
65 |
69 |
66 // Graphics settings active in buffer |
70 // Graphics settings active in buffer |
67 // all values are comparable to those |
71 // all values are comparable to those |
68 // in Graphics except font which is stored |
72 // in Graphics except font which is stored |
69 // as handle instead of LCDUI Font |
73 // as handle instead of LCDUI Font |
105 * @param control The eSWT control associated with the target, or null if the host is Image |
109 * @param control The eSWT control associated with the target, or null if the host is Image |
106 * @return New buffer instance |
110 * @return New buffer instance |
107 */ |
111 */ |
108 static Buffer createInstance(Object host, Control control) |
112 static Buffer createInstance(Object host, Control control) |
109 { |
113 { |
110 if(host instanceof Canvas) |
114 if(host instanceof Canvas) |
111 { |
115 { |
112 if(OS.windowServer == OS.WS_SYMBIAN_S60) |
116 if(OS.windowServer == OS.WS_SYMBIAN_S60) |
113 { |
117 { |
114 return new CanvasBufferSymbian((Canvas) host, control); |
118 return new CanvasBufferSymbian((Canvas) host, control); |
115 } |
119 } |
116 else if(OS.windowServer == OS.WS_X11) |
120 else if(OS.windowServer == OS.WS_X11) |
117 { |
121 { |
118 return new CanvasBufferLinux((Canvas) host, control); |
122 return new CanvasBufferLinux((Canvas) host, control); |
119 } |
123 } |
120 return null; |
124 return null; |
121 } |
125 } |
122 else if(host instanceof CustomItem) |
126 else if(host instanceof CustomItem) |
123 { |
127 { |
124 if(OS.windowServer == OS.WS_SYMBIAN_S60) |
128 if(OS.windowServer == OS.WS_SYMBIAN_S60) |
125 { |
129 { |
126 return new CustomItemBufferSymbian((CustomItem) host, control); |
130 return new CustomItemBufferSymbian((CustomItem) host, control); |
127 } |
131 } |
128 else if(OS.windowServer == OS.WS_X11) |
132 else if(OS.windowServer == OS.WS_X11) |
129 { |
133 { |
130 return new CustomItemBufferLinux((CustomItem) host, control); |
134 return new CustomItemBufferLinux((CustomItem) host, control); |
131 } |
135 } |
132 return null; |
136 return null; |
133 } |
137 } |
134 else if(host instanceof Image) |
138 else if(host instanceof Image) |
135 { |
139 { |
136 return new ImageBuffer((Image) host); |
140 return new ImageBuffer((Image) host); |
137 } |
141 } |
138 return null; |
142 return null; |
139 } |
143 } |
140 |
144 |
141 /** |
145 /** |
142 * Initializes data, called once |
146 * Initializes data, called once |
143 */ |
147 */ |
187 * @param w The width of the area to be painted |
204 * @param w The width of the area to be painted |
188 * @param h The height of the area to be painted |
205 * @param h The height of the area to be painted |
189 */ |
206 */ |
190 void startFrame(int x, int y, int w, int h) |
207 void startFrame(int x, int y, int w, int h) |
191 { |
208 { |
192 if(!isSurfaceSessionOpen) |
209 if(!isSurfaceSessionOpen) |
193 { |
210 { |
194 beginPaint(x, y, w, h); |
211 beginPaint(x, y, w, h); |
195 isSurfaceSessionOpen = true; |
212 isSurfaceSessionOpen = true; |
196 } |
213 } |
197 } |
214 } |
198 |
215 |
199 /** |
216 /** |
200 * Ends frame painting session. Must be called in UI thread and |
217 * Ends frame painting session. Must be called in UI thread and |
201 * at the end of the frame. BlitToDisplay calls this automatically. |
218 * at the end of the frame. BlitToDisplay calls this automatically. |
202 */ |
219 */ |
203 void endFrame() |
220 void endFrame() |
204 { |
221 { |
205 if(isSurfaceSessionOpen) |
222 if(isSurfaceSessionOpen) |
206 { |
223 { |
207 endPaint(); |
224 endPaint(); |
208 isSurfaceSessionOpen = false; |
225 isSurfaceSessionOpen = false; |
209 } |
226 } |
210 } |
227 } |
211 |
228 |
212 /** |
229 /** |
213 * Transfers the result of rendering to display. |
230 * Transfers the result of rendering to display. |
214 * @param gc The graphics context used for blit, may be null in some cases |
231 * @param gc The graphics context used for blit, may be null in some cases |
215 * @param widget The widget that is the target |
232 * @param widget The widget that is the target |
216 */ |
233 */ |
217 void blitToDisplay(GraphicsContext gc, Widget widget) |
234 void blitToDisplay(GraphicsContext gc, Widget widget) |
218 { |
235 { |
219 endFrame(); |
236 endFrame(); |
220 blit(gc, widget); |
237 blit(gc, widget); |
221 } |
238 } |
222 |
239 |
223 /** |
240 /** |
224 * Prepares surface for painting, implemented by |
241 * Prepares surface for painting, implemented by |
225 * child implementation. |
242 * child implementation. |
363 /** |
380 /** |
364 * Disposes this instance |
381 * Disposes this instance |
365 */ |
382 */ |
366 void dispose() |
383 void dispose() |
367 { |
384 { |
368 if(gc != null) |
385 if(gc != null) |
369 { |
386 { |
370 doRelease(); |
387 doRelease(); |
371 gc.dispose(); |
388 gc.dispose(); |
372 gc = null; |
389 gc = null; |
373 } |
390 } |
374 commandBuffer = null; |
391 commandBuffer = null; |
375 } |
392 } |
376 |
393 |
377 void copyArea(int x1, int y1, int width, int height, int x2, int y2, Graphics client) |
394 void copyArea(int x1, int y1, int width, int height, int x2, int y2, Graphics client) |
378 { |
395 { |
379 gc.copyArea(x1, y1, width, height, x2, y2); |
396 gc.copyArea(x1, y1, width, height, x2, y2); |
380 } |
397 } |
381 |
398 |
382 void fillRect(int x, int y, int w, int h, Graphics client) |
399 void fillRect(int x, int y, int w, int h, Graphics client) |
383 { |
400 { |
384 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client); |
401 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client); |
385 gc.fillRect(x, y, w, h); |
402 gc.fillRect(x, y, w, h); |
386 } |
403 } |
387 |
404 |
388 void fillRoundRect(int x, int y, int w, int h, int arcW, int arcH, Graphics client) |
405 void fillRoundRect(int x, int y, int w, int h, int arcW, int arcH, Graphics client) |
389 { |
406 { |
390 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client); |
407 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client); |
391 gc.fillRoundRect(x, y, w, h, arcW, arcH); |
408 gc.fillRoundRect(x, y, w, h, arcW, arcH); |
392 } |
409 } |
393 |
410 |
394 void fillArc(int x, int y, int w, int h, int startAngle, int arcAngle, Graphics client) |
411 void fillArc(int x, int y, int w, int h, int startAngle, int arcAngle, Graphics client) |
395 { |
412 { |
396 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client); |
413 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client); |
397 gc.fillArc(x, y, w, h, startAngle, arcAngle); |
414 gc.fillArc(x, y, w, h, startAngle, arcAngle); |
398 } |
415 } |
399 |
416 |
400 void fillTriangle(int[] points, Graphics client) |
417 void fillTriangle(int[] points, Graphics client) |
401 { |
418 { |
402 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client); |
419 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client); |
403 gc.fillPolygon(points); |
420 gc.fillPolygon(points); |
404 } |
421 } |
405 |
422 |
406 void setClip(int x, int y, int w, int h, Graphics client) |
423 void setClip(int x, int y, int w, int h, Graphics client) |
407 { |
424 { |
408 validateAndApplySettings(COORS_TRANSLATION, client); |
425 validateAndApplySettings(COORDS_TRANSLATION, client); |
409 // check if given clip is already active in buffer |
426 // check if given clip is already active in buffer |
410 if((bufferClip.x == x) && (bufferClip.y == y) && |
427 if((bufferClip.x == x) && (bufferClip.y == y) && |
411 (bufferClip.width == w) && (bufferClip.height== h)) |
428 (bufferClip.width == w) && (bufferClip.height== h)) |
412 { |
429 { |
413 return; |
430 return; |
501 bufferTranslateY += yDelta; |
523 bufferTranslateY += yDelta; |
502 } |
524 } |
503 |
525 |
504 void drawLine(int xStart, int yStart, int xEnd, int yEnd, Graphics client) |
526 void drawLine(int xStart, int yStart, int xEnd, int yEnd, Graphics client) |
505 { |
527 { |
506 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client); |
528 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client); |
507 gc.drawLine(xStart, yStart, xEnd, yEnd); |
529 gc.drawLine(xStart, yStart, xEnd, yEnd); |
508 } |
530 } |
509 |
531 |
510 void drawRect(int x, int y, int w, int h, Graphics client) |
532 void drawRect(int x, int y, int w, int h, Graphics client) |
511 { |
533 { |
512 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client); |
534 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client); |
513 gc.drawRect(x, y, w, h); |
535 gc.drawRect(x, y, w, h); |
514 } |
536 } |
515 |
537 |
516 void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH, Graphics client) |
538 void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH, Graphics client) |
517 { |
539 { |
518 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client); |
540 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client); |
519 gc.drawRoundRect(x, y, w, h, arcW, arcH); |
541 gc.drawRoundRect(x, y, w, h, arcW, arcH); |
520 } |
542 } |
521 |
543 |
522 void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle, Graphics client) |
544 void drawArc(int x, int y, int w, int h, int startAngle, int arcAngle, Graphics client) |
523 { |
545 { |
524 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client); |
546 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client); |
525 gc.drawArc(x, y, w, h, startAngle, arcAngle); |
547 gc.drawArc(x, y, w, h, startAngle, arcAngle); |
526 } |
548 } |
527 |
549 |
528 void drawString(String string, int x, int y, Graphics client) |
550 void drawString(String string, int x, int y, Graphics client) |
529 { |
551 { |
530 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|FONT), client); |
552 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|FONT), client); |
531 gc.drawString(string, x, y, true); |
553 gc.drawString(string, x, y, true); |
532 } |
554 } |
533 |
555 |
534 void drawImage(org.eclipse.swt.internal.qt.graphics.Image image, int x,int y, Graphics client) |
556 void drawImage(org.eclipse.swt.internal.qt.graphics.Image image, int x,int y, Graphics client) |
535 { |
557 { |
536 validateAndApplySettings((CLIP|COORS_TRANSLATION), client); |
558 validateAndApplySettings((CLIP|COORDS_TRANSLATION), client); |
537 gc.drawImage(image, x, y); |
559 gc.drawImage(image, x, y); |
538 } |
560 } |
539 |
561 |
540 void drawImage(org.eclipse.swt.internal.qt.graphics.Image image, int xDst, int yDst, |
562 void drawImage(org.eclipse.swt.internal.qt.graphics.Image image, int xDst, int yDst, |
541 int wDst, int hDst, int xSrc, int ySrc, int wSrc, int hSrc, |
563 int wDst, int hDst, int xSrc, int ySrc, int wSrc, int hSrc, |
542 int transform, Graphics client) |
564 int transform, Graphics client) |
543 { |
565 { |
544 validateAndApplySettings((CLIP|COORS_TRANSLATION), client); |
566 validateAndApplySettings((CLIP|COORDS_TRANSLATION), client); |
545 gc.drawImage(image, xDst, yDst, wDst, hDst, xSrc, ySrc, wSrc, hSrc, transform); |
567 gc.drawImage(image, xDst, yDst, wDst, hDst, xSrc, ySrc, wSrc, hSrc, transform); |
546 } |
568 } |
547 |
569 |
548 void drawRGB(int[] rgb, |
570 void drawRGB(int[] rgb, |
549 int offset, |
571 int offset, |
600 boolean alpha, |
622 boolean alpha, |
601 int manipulation, |
623 int manipulation, |
602 int format, |
624 int format, |
603 Graphics client) |
625 Graphics client) |
604 { |
626 { |
605 validateAndApplySettings((CLIP|COORS_TRANSLATION), client); |
627 validateAndApplySettings((CLIP|COORDS_TRANSLATION), client); |
606 gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha, manipulation, format); |
628 gc.drawRGB(rgb, offset, scanlength, x, y, w, h, alpha, manipulation, format); |
607 } |
629 } |
608 |
630 |
609 void drawPolygon(int[] points, Graphics client) |
631 void drawPolygon(int[] points, Graphics client) |
610 { |
632 { |
611 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION|STROKESTYLE), client); |
633 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION|STROKESTYLE), client); |
612 gc.drawPolygon(points); |
634 gc.drawPolygon(points); |
613 } |
635 } |
614 |
636 |
615 void fillPolygon(int[] points, Graphics client) |
637 void fillPolygon(int[] points, Graphics client) |
616 { |
638 { |
617 validateAndApplySettings((COLOR|CLIP|COORS_TRANSLATION), client); |
639 validateAndApplySettings((COLOR|CLIP|COORDS_TRANSLATION), client); |
618 gc.fillPolygon(points); |
640 gc.fillPolygon(points); |
619 } |
641 } |
620 |
642 |
621 void setARGBColor(int argb, Graphics client) |
643 void setARGBColor(int argb, Graphics client) |
622 { |
644 { |
656 WindowSurface getWindowSurface() |
678 WindowSurface getWindowSurface() |
657 { |
679 { |
658 return null; |
680 return null; |
659 } |
681 } |
660 |
682 |
661 /** |
683 boolean containsDrawnPrimitives() { |
662 * Translates given rectangle to display/window surface coordinates |
684 boolean result = false; |
|
685 if(commandBuffer != null) { |
|
686 result = commandBuffer.containsDrawnPrimitives(); |
|
687 } |
|
688 return result; |
|
689 } |
|
690 |
|
691 /** |
|
692 * Translates given rectangle to window surface coordinates |
663 * and outlines the clip inside the control bounds. |
693 * and outlines the clip inside the control bounds. |
664 * |
694 * |
665 * @param x The x-coordinate of the rectangle |
695 * @param x The x-coordinate of the rectangle |
666 * @param y The y-coordinate of the rectangle |
696 * @param y The y-coordinate of the rectangle |
667 * @param w The width of the rectangle |
697 * @param w The width of the rectangle |
668 * @param h The height of the rectangle |
698 * @param h The height of the rectangle |
669 * |
699 * |
670 */ |
700 */ |
671 private Rectangle clipToDisplayCoords(int x, int y, int w, int h) |
701 private Rectangle clipToWindowCoords(int x, int y, int w, int h) |
672 { |
702 { |
673 // Bottom-right corner of control bounds in window coordinates |
703 // Bottom-right corner of control bounds in window coordinates |
674 final int hostX2 = hostBounds.x + hostBounds.width; |
704 final int hostX2 = hostBounds.x + hostBounds.width; |
675 final int hostY2 = hostBounds.y + hostBounds.height; |
705 final int hostY2 = hostBounds.y + hostBounds.height; |
676 // clip in window coordinates |
706 // clip in window coordinates |
734 client.currentClip[1] != bufferClip.y && |
764 client.currentClip[1] != bufferClip.y && |
735 client.currentClip[2] != bufferClip.width && |
765 client.currentClip[2] != bufferClip.width && |
736 client.currentClip[3] != bufferClip.height) |
766 client.currentClip[3] != bufferClip.height) |
737 { |
767 { |
738 |
768 |
739 Rectangle rect = clipToDisplayCoords(client.currentClip[0], client.currentClip[1], |
769 Rectangle rect = clipToWindowCoords(client.currentClip[0], client.currentClip[1], |
740 client.currentClip[2], client.currentClip[3]); |
770 client.currentClip[2], client.currentClip[3]); |
741 gc.setClip(rect.x, rect.y, rect.width, rect.height, false); |
771 gc.setClip(rect.x, rect.y, rect.width, rect.height, false); |
742 bufferClip.x = client.currentClip[0]; |
772 bufferClip.x = client.currentClip[0]; |
743 bufferClip.y = client.currentClip[1]; |
773 bufferClip.y = client.currentClip[1]; |
744 bufferClip.width = client.currentClip[2]; |
774 bufferClip.width = client.currentClip[2]; |
745 bufferClip.height = client.currentClip[3]; |
775 bufferClip.height = client.currentClip[3]; |
746 } |
776 } |
747 } |
777 } |
748 if((COORS_TRANSLATION & flags) != 0) |
778 if((COORDS_TRANSLATION & flags) != 0) |
749 { |
779 { |
750 if((bufferTranslateX != client.translateX) && (bufferTranslateY != client.translateY)) |
780 if((bufferTranslateX != client.translateX) && (bufferTranslateY != client.translateY)) |
751 { |
781 { |
752 gc.translate((client.translateX - bufferTranslateX), (client.translateY - bufferTranslateY)); |
782 gc.translate((client.translateX - bufferTranslateX), (client.translateY - bufferTranslateY)); |
753 bufferTranslateX = client.translateX; |
783 bufferTranslateX = client.translateX; |