@@ -143,8 +143,6 @@ protected void allocate() {
143143 if (bitmap != null ) bitmap .recycle ();
144144 bitmap = Bitmap .createBitmap (width , height , Config .ARGB_8888 );
145145 canvas = new Canvas (bitmap );
146- // image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
147- // canvas = (Graphics2D) image.getGraphics();
148146 }
149147
150148
@@ -448,7 +446,7 @@ public void breakShape() {
448446 @ Override
449447 public void endShape (int mode ) {
450448 if (shape == POINTS && stroke && vertexCount > 0 ) {
451- Matrix m = canvas . getMatrix ();
449+ Matrix m = getMatrixImp ();
452450 if (strokeWeight == 1 && m .isIdentity ()) {
453451 if (screenPoint == null ) {
454452 screenPoint = new float [2 ];
@@ -1516,12 +1514,8 @@ public PMatrix2D getMatrix(PMatrix2D target) {
15161514 if (target == null ) {
15171515 target = new PMatrix2D ();
15181516 }
1519- // canvas.getTransform().getMatrix(transform);
1520- Matrix m = new Matrix ();
1521- canvas .getMatrix (m );
1517+ Matrix m = getMatrixImp ();
15221518 m .getValues (transform );
1523- // target.set((float) transform[0], (float) transform[2], (float) transform[4],
1524- // (float) transform[1], (float) transform[3], (float) transform[5]);
15251519 target .set ((float ) transform [0 ], (float ) transform [1 ], (float ) transform [2 ],
15261520 (float ) transform [3 ], (float ) transform [4 ], (float ) transform [5 ]);
15271521 return target ;
@@ -1565,6 +1559,11 @@ public void printMatrix() {
15651559 }
15661560
15671561
1562+ protected Matrix getMatrixImp () {
1563+ return parent .getSurfaceView ().getMatrix ();
1564+ // return canvas.getMatrix();
1565+ }
1566+
15681567
15691568 //////////////////////////////////////////////////////////////
15701569
@@ -1609,7 +1608,7 @@ public float screenX(float x, float y) {
16091608 }
16101609 screenPoint [0 ] = x ;
16111610 screenPoint [1 ] = y ;
1612- canvas . getMatrix ().mapPoints (screenPoint );
1611+ getMatrixImp ().mapPoints (screenPoint );
16131612 return screenPoint [0 ];
16141613 }
16151614
@@ -1623,7 +1622,7 @@ public float screenY(float x, float y) {
16231622 }
16241623 screenPoint [0 ] = x ;
16251624 screenPoint [1 ] = y ;
1626- canvas . getMatrix ().mapPoints (screenPoint );
1625+ getMatrixImp ().mapPoints (screenPoint );
16271626 return screenPoint [1 ];
16281627 }
16291628
@@ -2046,35 +2045,31 @@ public void set(int x, int y, PImage src) {
20462045 }
20472046
20482047 if (src .bitmap == null ) {
2049- // hopefully this will do the work to figure out what's on/offscreen
2050- // in spite of the offset and stride that's been provided
2051- canvas .drawBitmap (src .pixels , 0 , src .width ,
2052- x , y , src .width , src .height , false , null );
2053- // hasAlpha is set to false since we don't want blending.
2054- // however that may be incorrect if it winds up copying only the RGB
2055- // (without the A) portion of the pixels.
2056-
2057- } else { // src.bitmap != null
2058- if (src .width != src .bitmap .getWidth () ||
2059- src .height != src .bitmap .getHeight ()) {
2048+ src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2049+ src .modified = true ;
2050+ }
2051+
2052+ if (src .width != src .bitmap .getWidth () ||
2053+ src .height != src .bitmap .getHeight ()) {
2054+ src .bitmap .recycle ();
2055+ src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2056+ src .modified = true ;
2057+ }
2058+ if (src .modified ) {
2059+ if (!src .bitmap .isMutable ()) {
20602060 src .bitmap .recycle ();
20612061 src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2062- src .modified = true ;
2063- }
2064- if (src .modified ) {
2065- if (!src .bitmap .isMutable ()) {
2066- src .bitmap .recycle ();
2067- src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2068- }
2069- src .bitmap .setPixels (src .pixels , 0 , src .width , 0 , 0 , src .width , src .height );
2070- src .modified = false ;
20712062 }
2072- // set() happens in screen coordinates, so need to clear the ctm
2073- canvas .save (Canvas .MATRIX_SAVE_FLAG );
2074- canvas .setMatrix (null ); // set to identity
2075- canvas .drawBitmap (src .bitmap , x , y , null );
2076- canvas .restore ();
2063+ src .bitmap .setPixels (src .pixels , 0 , src .width , 0 , 0 , src .width , src .height );
2064+ src .modified = false ;
20772065 }
2066+
2067+ // set() happens in screen coordinates, so need to clear the ctm
2068+ canvas .save (Canvas .MATRIX_SAVE_FLAG );
2069+ canvas .setMatrix (null ); // set to identity
2070+ canvas .drawBitmap (src .bitmap , x , y , null );
2071+ canvas .restore ();
2072+
20782073 }
20792074
20802075
0 commit comments