modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGCanvas.java

Print this page




 201                     factory.createRTTexture(tw, th, WrapMode.CLAMP_TO_ZERO);
 202                 this.tex = newtex;
 203                 this.g = newtex.createGraphics();
 204                 this.input = new EffectInput(newtex);
 205                 if (oldtex != null) {
 206                     if (init_type == InitType.PRESERVE_UPPER_LEFT) {
 207                         g.setCompositeMode(CompositeMode.SRC);
 208                         if (oldtex.isSurfaceLost()) {
 209                             if (savedPixelData != null) {
 210                                 savedPixelData.restore(g, cw, ch);
 211                             }
 212                         } else {
 213                             g.drawTexture(oldtex, 0, 0, cw, ch);
 214                         }
 215                         g.setCompositeMode(CompositeMode.SRC_OVER);
 216                     }
 217                     oldtex.unlock();
 218                     oldtex.dispose();
 219                 }
 220                 if (init_type == InitType.FILL_WHITE) {
 221                     g.setPaint(Color.WHITE);
 222                     g.fillRect(0, 0, tw, th);
 223                 }
 224                 return true;
 225             } else {
 226                 if (this.g == null) {
 227                     this.g = tex.createGraphics();
 228                     if (this.g == null) {
 229                         tex.dispose();
 230                         ResourceFactory factory = (resg == null)
 231                             ? GraphicsPipeline.getDefaultResourceFactory()
 232                             : resg.getResourceFactory();
 233                         tex = factory.createRTTexture(tw, th, WrapMode.CLAMP_TO_ZERO);
 234                         this.g = tex.createGraphics();
 235                         this.input = new EffectInput(tex);
 236                         if (savedPixelData != null) {
 237                             g.setCompositeMode(CompositeMode.SRC);
 238                             savedPixelData.restore(g, tw, th);
 239                             g.setCompositeMode(CompositeMode.SRC_OVER);
 240                         } else if (init_type == InitType.FILL_WHITE) {
 241                             g.setPaint(Color.WHITE);
 242                             g.fillRect(0, 0, tw, th);
 243                         }
 244                         return true;
 245                     }
 246                 }
 247             }
 248             if (init_type == InitType.CLEAR) {
 249                 g.setCompositeMode(CompositeMode.CLEAR);
 250                 g.setTransform(BaseTransform.IDENTITY_TRANSFORM);
 251                 g.fillRect(0, 0, tw, th);
 252                 g.setCompositeMode(CompositeMode.SRC_OVER);
 253             }
 254             return false;
 255         }
 256 
 257         private void save(int tw, int th) {
 258             if (tex.isVolatile()) {
 259                 if (savedPixelData == null) {
 260                     savedPixelData = new PixelData(tw, th);
 261                 }
 262                 savedPixelData.save(tex);
 263             }
 264         }
 265     }
 266 
 267     // Saved pixel data used to preserve the image that backs the canvas if the
 268     // RTT is volatile.
 269     private static class PixelData {
 270         private IntBuffer pixels = null;
 271         private boolean validPixels = false;
 272         private int cw, ch;


 610             }
 611             this.temp.g = this.clip.g = this.cv.g = null;
 612         }
 613     }
 614 
 615     private void initCanvas(Graphics g) {
 616         if (tw <= 0 || th <= 0) {
 617             cv.dispose();
 618             return;
 619         }
 620         if (cv.validate(g, tw, th)) {
 621             // If the texture was recreated then we add a permanent
 622             // "useful" and extra "lock" status to it.
 623             cv.tex.contentsUseful();
 624             cv.tex.makePermanent();
 625             cv.tex.lock();
 626         }
 627     }
 628 
 629     private void clearCanvas(int x, int y, int w, int h) {
 630         cv.g.setCompositeMode(CompositeMode.SRC);
 631         cv.g.setTransform(BaseTransform.IDENTITY_TRANSFORM);
 632         cv.g.setPaint(Color.TRANSPARENT);
 633         cv.g.fillRect(x, y, w, h);
 634         cv.g.setCompositeMode(CompositeMode.SRC_OVER);
 635     }
 636 
 637     private void resetClip(boolean andDispose) {
 638         if (andDispose) clip.dispose();
 639         clipsRendered = 0;
 640         clipIsRect = true;
 641         clipRect = null;
 642     }
 643 
 644     private static final float CLIPRECT_TOLERANCE = 1.0f / 256.0f;
 645     private static final Rectangle TEMP_RECT = new Rectangle();
 646     private boolean initClip() {
 647         boolean clipValidated;
 648         if (clipIsRect) {
 649             clipValidated = false;
 650         } else {
 651             clipValidated = true;
 652             if (clip.validate(cv.g, tw, th)) {
 653                 clip.tex.contentsUseful();


1182                 }
1183                 if (gr != null) {
1184                     switch (token) {
1185                         case FILL_RECT:
1186                             setupFill(gr);
1187                             gr.fillRect(x, y, w, h);
1188                             break;
1189                         case FILL_OVAL:
1190                             setupFill(gr);
1191                             gr.fillEllipse(x, y, w, h);
1192                             break;
1193                         case STROKE_RECT:
1194                             setupStroke(gr);
1195                             gr.drawRect(x, y, w, h);
1196                             break;
1197                         case STROKE_OVAL:
1198                             setupStroke(gr);
1199                             gr.drawEllipse(x, y, w, h);
1200                             break;
1201                         case CLEAR_RECT:
1202                             gr.setPaint(Color.TRANSPARENT);
1203                             gr.setCompositeMode(CompositeMode.SRC);
1204                             gr.fillRect(x, y, w, h);
1205                             gr.setCompositeMode(CompositeMode.SRC_OVER);
1206                             break;
1207                     }
1208                 }
1209                 break;
1210             }
1211             case STROKE_ROUND_RECT:
1212                 strokeBounds = true;
1213             case FILL_ROUND_RECT:
1214             {
1215                 float x = buf.getFloat();
1216                 float y = buf.getFloat();
1217                 float w = buf.getFloat();
1218                 float h = buf.getFloat();
1219                 float aw = buf.getFloat();
1220                 float ah = buf.getFloat();
1221                 if (bounds != null) {
1222                     bounds.setBounds(x, y, x+w, y+h);
1223                     transformBounds = true;




 201                     factory.createRTTexture(tw, th, WrapMode.CLAMP_TO_ZERO);
 202                 this.tex = newtex;
 203                 this.g = newtex.createGraphics();
 204                 this.input = new EffectInput(newtex);
 205                 if (oldtex != null) {
 206                     if (init_type == InitType.PRESERVE_UPPER_LEFT) {
 207                         g.setCompositeMode(CompositeMode.SRC);
 208                         if (oldtex.isSurfaceLost()) {
 209                             if (savedPixelData != null) {
 210                                 savedPixelData.restore(g, cw, ch);
 211                             }
 212                         } else {
 213                             g.drawTexture(oldtex, 0, 0, cw, ch);
 214                         }
 215                         g.setCompositeMode(CompositeMode.SRC_OVER);
 216                     }
 217                     oldtex.unlock();
 218                     oldtex.dispose();
 219                 }
 220                 if (init_type == InitType.FILL_WHITE) {
 221                     g.clear(Color.WHITE);

 222                 }
 223                 return true;
 224             } else {
 225                 if (this.g == null) {
 226                     this.g = tex.createGraphics();
 227                     if (this.g == null) {
 228                         tex.dispose();
 229                         ResourceFactory factory = (resg == null)
 230                             ? GraphicsPipeline.getDefaultResourceFactory()
 231                             : resg.getResourceFactory();
 232                         tex = factory.createRTTexture(tw, th, WrapMode.CLAMP_TO_ZERO);
 233                         this.g = tex.createGraphics();
 234                         this.input = new EffectInput(tex);
 235                         if (savedPixelData != null) {
 236                             g.setCompositeMode(CompositeMode.SRC);
 237                             savedPixelData.restore(g, tw, th);
 238                             g.setCompositeMode(CompositeMode.SRC_OVER);
 239                         } else if (init_type == InitType.FILL_WHITE) {
 240                             g.clear(Color.WHITE);

 241                         }
 242                         return true;
 243                     }
 244                 }
 245             }
 246             if (init_type == InitType.CLEAR) {
 247                 g.clear();



 248             }
 249             return false;
 250         }
 251 
 252         private void save(int tw, int th) {
 253             if (tex.isVolatile()) {
 254                 if (savedPixelData == null) {
 255                     savedPixelData = new PixelData(tw, th);
 256                 }
 257                 savedPixelData.save(tex);
 258             }
 259         }
 260     }
 261 
 262     // Saved pixel data used to preserve the image that backs the canvas if the
 263     // RTT is volatile.
 264     private static class PixelData {
 265         private IntBuffer pixels = null;
 266         private boolean validPixels = false;
 267         private int cw, ch;


 605             }
 606             this.temp.g = this.clip.g = this.cv.g = null;
 607         }
 608     }
 609 
 610     private void initCanvas(Graphics g) {
 611         if (tw <= 0 || th <= 0) {
 612             cv.dispose();
 613             return;
 614         }
 615         if (cv.validate(g, tw, th)) {
 616             // If the texture was recreated then we add a permanent
 617             // "useful" and extra "lock" status to it.
 618             cv.tex.contentsUseful();
 619             cv.tex.makePermanent();
 620             cv.tex.lock();
 621         }
 622     }
 623 
 624     private void clearCanvas(int x, int y, int w, int h) {
 625         cv.g.setCompositeMode(CompositeMode.CLEAR);
 626         cv.g.setTransform(BaseTransform.IDENTITY_TRANSFORM);
 627         cv.g.fillQuad(x, y, x+w, y+h);

 628         cv.g.setCompositeMode(CompositeMode.SRC_OVER);
 629     }
 630 
 631     private void resetClip(boolean andDispose) {
 632         if (andDispose) clip.dispose();
 633         clipsRendered = 0;
 634         clipIsRect = true;
 635         clipRect = null;
 636     }
 637 
 638     private static final float CLIPRECT_TOLERANCE = 1.0f / 256.0f;
 639     private static final Rectangle TEMP_RECT = new Rectangle();
 640     private boolean initClip() {
 641         boolean clipValidated;
 642         if (clipIsRect) {
 643             clipValidated = false;
 644         } else {
 645             clipValidated = true;
 646             if (clip.validate(cv.g, tw, th)) {
 647                 clip.tex.contentsUseful();


1176                 }
1177                 if (gr != null) {
1178                     switch (token) {
1179                         case FILL_RECT:
1180                             setupFill(gr);
1181                             gr.fillRect(x, y, w, h);
1182                             break;
1183                         case FILL_OVAL:
1184                             setupFill(gr);
1185                             gr.fillEllipse(x, y, w, h);
1186                             break;
1187                         case STROKE_RECT:
1188                             setupStroke(gr);
1189                             gr.drawRect(x, y, w, h);
1190                             break;
1191                         case STROKE_OVAL:
1192                             setupStroke(gr);
1193                             gr.drawEllipse(x, y, w, h);
1194                             break;
1195                         case CLEAR_RECT:
1196                             gr.setCompositeMode(CompositeMode.CLEAR);

1197                             gr.fillRect(x, y, w, h);
1198                             gr.setCompositeMode(CompositeMode.SRC_OVER);
1199                             break;
1200                     }
1201                 }
1202                 break;
1203             }
1204             case STROKE_ROUND_RECT:
1205                 strokeBounds = true;
1206             case FILL_ROUND_RECT:
1207             {
1208                 float x = buf.getFloat();
1209                 float y = buf.getFloat();
1210                 float w = buf.getFloat();
1211                 float h = buf.getFloat();
1212                 float aw = buf.getFloat();
1213                 float ah = buf.getFloat();
1214                 if (bounds != null) {
1215                     bounds.setBounds(x, y, x+w, y+h);
1216                     transformBounds = true;