Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[MOSYNC-2375] Android: Fixed bug that made runtime crash when rotatin…

…g the device and drawing using maSetClipRect. A test program is included in the issue MOSYNC-2375.
  • Loading branch information...
commit 9fa1cd19de5d16106adcbba862e08bc9385db69d 1 parent 3c40e46
authored September 13, 2012
24  runtimes/java/platforms/androidJNI/AndroidProject/src/com/mosync/internal/android/MoSyncThread.java
@@ -586,6 +586,19 @@ public synchronized void updateSurfaceSize(int width, int height)
586 586
 		mCanvas = mDrawTargetScreen.mCanvas;
587 587
 		mBitmap = mDrawTargetScreen.mBitmap;
588 588
 
  589
+		// Set/reset clip rect.
  590
+		mClipLeft = 0;
  591
+		mClipTop = 0;
  592
+		mClipWidth = mWidth;
  593
+		mClipHeight = mHeight;
  594
+
  595
+		// Set original clip rect.
  596
+		// Save the clip state since we have a new canvas created.
  597
+		// This initial save is needed for the clip rect stack to
  598
+		// work correctly when calling restore clip rect.
  599
+		mCanvas.save();
  600
+		mCanvas.clipRect(mClipLeft, mClipTop, mClipWidth, mClipHeight, Region.Op.REPLACE);
  601
+
589 602
 		updateScreen();
590 603
 
591 604
 		SYSLOG("mBitmap width:" + mBitmap.getWidth()
@@ -1122,17 +1135,10 @@ public ByteBuffer getBinaryResource(int handle)
1122 1135
 	void initSyscalls()
1123 1136
 	{
1124 1137
 		SYSLOG("initSyscalls");
1125  
-		mUsingFrameBuffer = false;
1126 1138
 
1127  
-		mClipLeft = 0;
1128  
-		mClipTop = 0;
1129  
-		mClipWidth = mWidth;
1130  
-		mClipHeight = mHeight;
  1139
+		//Log.i("@@@@@", "initSyscalls");
1131 1140
 
1132  
-		// Set original clip rect.
1133  
-		// First we save the clip state.
1134  
-		mCanvas.save();
1135  
-		mCanvas.clipRect(mClipLeft, mClipTop, mClipWidth, mClipHeight, Region.Op.REPLACE);
  1141
+		mUsingFrameBuffer = false;
1136 1142
 
1137 1143
 		mPaint.setStyle(Paint.Style.FILL);
1138 1144
 		mPaint.setAntiAlias(false);
54  runtimes/java/platforms/androidJNI/AndroidProject/src/com/mosync/internal/android/MoSyncView.java
@@ -34,7 +34,7 @@
34 34
 public class MoSyncView extends SurfaceView implements SurfaceHolder.Callback
35 35
 {
36 36
 	public SurfaceHolder mSurfaceHolder;
37  
-	
  37
+
38 38
 	private Context mContext;
39 39
 	private MoSyncThread mMoSyncThread;
40 40
 
@@ -43,13 +43,13 @@
43 43
 	 * @param context		The Android Activity Context
44 44
 	 * @param moSyncThread	The thread in which the runtime is running
45 45
 	 */
46  
-	public MoSyncView(Context context, MoSyncThread moSyncThread) 
  46
+	public MoSyncView(Context context, MoSyncThread moSyncThread)
47 47
 		throws Exception
48 48
 	{
49 49
 		super(context);
50  
-		
  50
+
51 51
 		SYSLOG("Constructor");
52  
-		
  52
+
53 53
 		mContext = context;
54 54
 		mMoSyncThread = moSyncThread;
55 55
 
@@ -86,16 +86,16 @@ public MoSyncView(Context context, MoSyncThread moSyncThread)
86 86
 			default: Log.i("MoSync", "No hardware acceleration available");
87 87
 		}
88 88
 */
89  
-		mSurfaceHolder.addCallback(this);    
90  
-		
  89
+		mSurfaceHolder.addCallback(this);
  90
+
91 91
 		setVisibility(VISIBLE);
92  
-		
  92
+
93 93
 		setFocusableInTouchMode(true);
94 94
 	}
95 95
 
96 96
 	/**
97  
-	 * Called during layout when the size of this view has changed. 
98  
-	 * If you were just added to the view hierarchy, you're called 
  97
+	 * Called during layout when the size of this view has changed.
  98
+	 * If you were just added to the view hierarchy, you're called
99 99
 	 * with the old values of 0.
100 100
 	 * @param w Current width of this view.
101 101
 	 * @param w h Current height of this view.
@@ -105,12 +105,12 @@ public MoSyncView(Context context, MoSyncThread moSyncThread)
105 105
 	@Override
106 106
 	public void onSizeChanged(int w, int h, int oldw, int oldh)
107 107
 	{
108  
-		SYSLOG("onSizeChanged w:" + w + " h:" + h 
  108
+		SYSLOG("onSizeChanged w:" + w + " h:" + h
109 109
 			+ " oldw:" + oldw + " oldh:" + oldh);
110  
-		
  110
+
111 111
 		super.onSizeChanged(w, h, oldw, oldh);
112 112
 	}
113  
-	
  113
+
114 114
 	/**
115 115
 	 * This function is called directly after a change to the surface.
116 116
 	 *
@@ -123,16 +123,18 @@ public void onSizeChanged(int w, int h, int oldw, int oldh)
123 123
 	 */
124 124
 	@Override
125 125
 	public void surfaceChanged(
126  
-		SurfaceHolder holder, 
127  
-		int format, 
128  
-		int width, 
  126
+		SurfaceHolder holder,
  127
+		int format,
  128
+		int width,
129 129
 		int height)
130 130
 	{
131 131
 		SYSLOG("surfaceChanged");
132  
-		
  132
+
  133
+		//Log.i("@@@@@", "surfaceChanged");
  134
+
133 135
 		// Allocate new screen buffer.
134 136
 		mMoSyncThread.updateSurfaceSize(width, height);
135  
-		
  137
+
136 138
 		// Post screen changed event.
137 139
 		// TODO: Should this be done also initially, when the surface is
138 140
 		// first created, or only when it is changed after it has been created?
@@ -145,7 +147,7 @@ public void surfaceChanged(
145 147
 	}
146 148
 
147 149
 	/**
148  
-	 * Function which is called by Android directly after the surface 
  150
+	 * Function which is called by Android directly after the surface
149 151
 	 * has been created.
150 152
 	 *
151 153
 	 * NOTE: Here we start the MoSync thread.
@@ -156,19 +158,23 @@ public void surfaceChanged(
156 158
 	public void surfaceCreated(SurfaceHolder holder)
157 159
 	{
158 160
 		SYSLOG("surfaceCreated");
159  
-		
  161
+
  162
+		//Log.i("@@@@@", "surfaceCreated");
  163
+
160 164
 		if (!mMoSyncThread.isAlive())
161 165
 		{
162  
-			mMoSyncThread.updateSurfaceSize(getWidth(), getHeight());
  166
+			//Log.i("@@@@@", "surfaceCreated 1");
163 167
 			mMoSyncThread.initSyscalls();
  168
+			mMoSyncThread.updateSurfaceSize(getWidth(), getHeight());
164 169
 			mMoSyncThread.start();
165 170
 		}
166 171
 		else
167 172
 		{
  173
+			//Log.i("@@@@@", "surfaceCreated 2");
168 174
 			mMoSyncThread.updateScreen();
169 175
 		}
170 176
 	}
171  
-	
  177
+
172 178
 	/**
173 179
 	 * Method that is called directly before the surface is destroyed.
174 180
 	 */
@@ -185,13 +191,13 @@ protected void onDraw(Canvas canvas)
185 191
 	}
186 192
 
187 193
 	protected void onFocusChanged(
188  
-		boolean gainFocus, 
189  
-		int direction, 
  194
+		boolean gainFocus,
  195
+		int direction,
190 196
 		Rect previouslyFocusedRect)
191 197
 	{
192 198
 		SYSLOG("onFocusChanged");
193 199
 	}
194  
-	
  200
+
195 201
 	public boolean onTouchEvent(MotionEvent motionEvent)
196 202
 	{
197 203
 		return ((Activity) mContext).onTouchEvent(motionEvent);

0 notes on commit 9fa1cd1

Please sign in to comment.
Something went wrong with that request. Please try again.