mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-29 10:26:36 +01:00
fix Nougat-only draw bug
Starting with the release of Nougat there have been cases where the board would not correctly redraw. It's been most evident when using the hit feature many times in a row, with something going wrong every fifth time or so (but not that consistently.) It's as if modifications of the bitmap backing BoardCanvas were being done asynchronously and not necessarily all completed when I blit the canvas to the screen via canvas.drawBitmap(). (As evidence of this I confirmed that a tap on a tile in the tray after a bad draw would cause the screen to correct itself even though the only additional rendering was to the tray. So by the time that second drawBitmap() call happened the bitmap data was correct: all draws that hadn't completed earlier had done so by now.) The fix is to call Bitmap.createBitmap(bitmap) and to use the copy as the source of the canvas.drawBitmap() blit operation. I suspect that createBitmap() waits for any pending draws into its source to complete before making the copy. Regardless, if this hasn't fixed the problem it's made it so rare that I'm not seeing it, and since I'm only doing the copy on Nougat there's little risk in the change. And I can't detect any problems coming from the considerable additional memory being used and immediately marked available for gc.
This commit is contained in:
parent
e6561cbcac
commit
7a1965aeaf
1 changed files with 8 additions and 1 deletions
|
@ -26,6 +26,7 @@ import android.graphics.Bitmap;
|
|||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.FloatMath;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -45,6 +46,7 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
|
||||
private static final float MIN_FONT_DIPS = 10.0f;
|
||||
private static final int MULTI_INACTIVE = -1;
|
||||
private static final int VERSION_CODES_N = 24; // until we're building on SDK 24...
|
||||
|
||||
private static boolean s_isFirstDraw;
|
||||
private static int s_curGameID;
|
||||
|
@ -203,7 +205,12 @@ public class BoardView extends View implements BoardHandler, SyncedDraw {
|
|||
{
|
||||
synchronized( this ) {
|
||||
if ( layoutBoardOnce() && m_measuredFromDims ) {
|
||||
canvas.drawBitmap( s_bitmap, 0, 0, new Paint() );
|
||||
Bitmap bitmap = s_bitmap;
|
||||
if ( Build.VERSION.SDK_INT >= VERSION_CODES_N ) {
|
||||
bitmap = Bitmap.createBitmap(bitmap);
|
||||
}
|
||||
canvas.drawBitmap( bitmap, 0, 0, new Paint() );
|
||||
|
||||
ConnStatusHandler.draw( m_context, canvas, getResources(),
|
||||
m_connTypes, m_isSolo );
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue