@@ -147,8 +147,6 @@ protected void allocate() {
147147 bitmap = Bitmap .createBitmap (width , height , Config .ARGB_8888 );
148148 canvas = new Canvas (bitmap );
149149 }
150- // image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
151- // canvas = (Graphics2D) image.getGraphics();
152150 }
153151
154152
@@ -458,7 +456,8 @@ public void breakShape() {
458456 @ Override
459457 public void endShape (int mode ) {
460458 if (shape == POINTS && stroke && vertexCount > 0 ) {
461- Matrix m = canvas .getMatrix ();
459+ // Matrix m = canvas.getMatrix();
460+ Matrix m = getMatrixImp ();
462461 if (strokeWeight == 1 && m .isIdentity ()) {
463462 if (screenPoint == null ) {
464463 screenPoint = new float [2 ];
@@ -1527,8 +1526,9 @@ public PMatrix2D getMatrix(PMatrix2D target) {
15271526 target = new PMatrix2D ();
15281527 }
15291528// canvas.getTransform().getMatrix(transform);
1530- Matrix m = new Matrix ();
1531- canvas .getMatrix (m );
1529+ // Matrix m = new Matrix();
1530+ // canvas.getMatrix(m);
1531+ Matrix m = getMatrixImp ();
15321532 m .getValues (transform );
15331533// target.set((float) transform[0], (float) transform[2], (float) transform[4],
15341534// (float) transform[1], (float) transform[3], (float) transform[5]);
@@ -1575,6 +1575,12 @@ public void printMatrix() {
15751575 }
15761576
15771577
1578+ protected Matrix getMatrixImp () {
1579+ return parent .getSurfaceView ().getMatrix ();
1580+ // return canvas.getMatrix();
1581+ }
1582+
1583+
15781584
15791585 //////////////////////////////////////////////////////////////
15801586
@@ -1619,7 +1625,8 @@ public float screenX(float x, float y) {
16191625 }
16201626 screenPoint [0 ] = x ;
16211627 screenPoint [1 ] = y ;
1622- canvas .getMatrix ().mapPoints (screenPoint );
1628+ // canvas.getMatrix().mapPoints(screenPoint);
1629+ getMatrixImp ().mapPoints (screenPoint );
16231630 return screenPoint [0 ];
16241631 }
16251632
@@ -1633,7 +1640,8 @@ public float screenY(float x, float y) {
16331640 }
16341641 screenPoint [0 ] = x ;
16351642 screenPoint [1 ] = y ;
1636- canvas .getMatrix ().mapPoints (screenPoint );
1643+ // canvas.getMatrix().mapPoints(screenPoint);
1644+ getMatrixImp ().mapPoints (screenPoint );
16371645 return screenPoint [1 ];
16381646 }
16391647
@@ -2060,35 +2068,28 @@ public void set(int x, int y, PImage src) {
20602068 }
20612069
20622070 if (src .bitmap == null ) {
2063- // hopefully this will do the work to figure out what's on/offscreen
2064- // in spite of the offset and stride that's been provided
2065- canvas . drawBitmap ( src . pixels , 0 , src . width ,
2066- x , y , src .width , src .height , false , null );
2067- // hasAlpha is set to false since we don't want blending.
2068- // however that may be incorrect if it winds up copying only the RGB
2069- // (without the A) portion of the pixels.
2070-
2071- } else { // src.bitmap != null
2072- if (src .width != src . bitmap . getWidth () ||
2073- src . height != src .bitmap .getHeight ()) {
2071+ src . bitmap = Bitmap . createBitmap ( src . width , src . height , Config . ARGB_8888 );
2072+ src . modified = true ;
2073+ }
2074+ if ( src .width != src .bitmap . getWidth () ||
2075+ src . height != src . bitmap . getHeight ()) {
2076+ src . bitmap . recycle ();
2077+ src . bitmap = Bitmap . createBitmap ( src . width , src . height , Config . ARGB_8888 );
2078+ src . modified = true ;
2079+ }
2080+ if (src .modified ) {
2081+ if (! src .bitmap .isMutable ()) {
20742082 src .bitmap .recycle ();
20752083 src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2076- src .modified = true ;
20772084 }
2078- if (src .modified ) {
2079- if (!src .bitmap .isMutable ()) {
2080- src .bitmap .recycle ();
2081- src .bitmap = Bitmap .createBitmap (src .width , src .height , Config .ARGB_8888 );
2082- }
2083- src .bitmap .setPixels (src .pixels , 0 , src .width , 0 , 0 , src .width , src .height );
2084- src .modified = false ;
2085- }
2086- // set() happens in screen coordinates, so need to clear the ctm
2087- canvas .save (Canvas .MATRIX_SAVE_FLAG );
2088- canvas .setMatrix (null ); // set to identity
2089- canvas .drawBitmap (src .bitmap , x , y , null );
2090- canvas .restore ();
2085+ src .bitmap .setPixels (src .pixels , 0 , src .width , 0 , 0 , src .width , src .height );
2086+ src .modified = false ;
20912087 }
2088+ // set() happens in screen coordinates, so need to clear the ctm
2089+ canvas .save (Canvas .MATRIX_SAVE_FLAG );
2090+ canvas .setMatrix (null ); // set to identity
2091+ canvas .drawBitmap (src .bitmap , x , y , null );
2092+ canvas .restore ();
20922093 }
20932094
20942095
0 commit comments