List of usage examples for android.view Surface isValid
public boolean isValid()
From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java
private void canvasDraw(Bitmap bitmap, int src_width, int src_height, int startLine, int endLine) { SurfaceHolder surfaceHolder = getHolder(); Surface surface = surfaceHolder.getSurface(); Canvas canvas = null;/*from w w w. ja v a 2 s . c o m*/ try { synchronized (surfaceHolder) { boolean isDirty = false; if (mDirtyCount < 3) { mDirtyCount++; isDirty = true; startLine = 0; endLine = src_height; } if (mScale) { mDstRect.set(0, 0, mRenderer.width, mRenderer.height); mSrcRect.set(0, 0, src_width, src_height); mDstRect.offset(mRenderer.x, mRenderer.y); mDirtyRect.set(0, startLine * mRenderer.height / src_height, mRenderer.width, endLine * mRenderer.height / src_height + 1); //locnet, 2011-04-21, a strip on right side not updated mDirtyRect.offset(mRenderer.x, mRenderer.y); } else { //L,T,R,B mSrcRect.set(-mScroll_x, Math.max(-mScroll_y, startLine), mRenderer.mCropWorkspace[2], Math.min(Math.min(getHeight() - mScroll_y, src_height), endLine)); mDstRect.set(0, mSrcRect.top + mScroll_y, mSrcRect.width(), mSrcRect.top + mScroll_y + mSrcRect.height()); if (isLandscape) { mDstRect.offset((getWidth() - mSrcRect.width()) / 2, 0); } else { mDstRect.offset((getWidth() - mSrcRect.width()) / 2, mActionBarHeight); } mDirtyRect.set(mDstRect); } if (surface != null && surface.isValid()) { if (isDirty) { canvas = surfaceHolder.lockCanvas(null); canvas.drawColor(0xff000000); } else { canvas = surfaceHolder.lockCanvas(mDirtyRect); } if (mScale) { canvas.drawBitmap(bitmap, mSrcRect, mDstRect, (mParent.mPrefScaleFilterOn) ? mBitmapPaint : null); } else { canvas.drawBitmap(bitmap, mSrcRect, mDstRect, null); } } } } finally { if (canvas != null && surface != null && surface.isValid()) { surfaceHolder.unlockCanvasAndPost(canvas); } } surfaceHolder = null; }