surface用来处理一段单独的缓冲区,这段缓冲区是由屏幕合成器来管理的。
surface 包含安全的内容,使用一些特殊的措施来阻止在其他的进程中复制surface内容。尤其是截屏和VNC服务。surface不能被硬件加速。它创建的缓冲区有几种:BUFFERS,NORMAL,BLUR,DIM。
当surface不能被创建或更改大小时候,系统会抛出异常。surface创建过程中,创建了一个画布,并且在之后的程序设计中我们可以使用。我们可以锁定或解锁一个surface,但解锁时,只有调用post()或postAll() 是才会更新屏幕。
源码:
package Android.view;
import android.graphics.*;
import android.os.Parcelable;
import android.os.Parcel;
import android.util.Log;
public class Surface implements Parcelable {
private static final String LOG_TAG = "Surface";
public static final int HIDDEN = 0x00000004;
public static final int HARDWARE = 0x00000010;
public static final int GPU = 0x00000028;
public static final int SECURE = 0x00000080;
public static final int NON_PREMULTIPLIED = 0x00000100;
public static final int PUSH_BUFFERS = 0x00000200;
public static final int FX_SURFACE_NORMAL = 0x00000000;
public static final int FX_SURFACE_BLUR = 0x00010000;
public static final int FX_SURFACE_DIM = 0x00020000;
public static final int FX_SURFACE_MASK = 0x000F0000;
public static final int SURFACE_HIDDEN = 0x01;
public static final int SURACE_FROZEN = 0x02;
public static final int SURFACE_DITHER = 0x04;
public static final int SURFACE_BLUR_FREEZE= 0x10;
public static final int ROTATION_0 = 0;
public static final int ROTATION_90 = 1;
public static final int ROTATION_180 = 2;
public static final int ROTATION_270 = 3;
public static final int FLAGS_ORIENTATION_ANIMATION_DISABLE = 0x000000001;
@SuppressWarnings("unused")
private int mSurface;
@SuppressWarnings("unused")
private int mSaveCount;
@SuppressWarnings("unused")
private Canvas mCanvas;
/**
* Exception thrown when a surface couldn't be created or resized
*/
public static class OutOfResourcesException extends Exception {
public OutOfResourcesException() {
}
public OutOfResourcesException(String name) {
super(name);
}
}
native private static void nativeClassInit();
static { nativeClassInit(); }
public Surface(SurfaceSession s,
int pid, int display, int w, int h, int format, int flags)
throws OutOfResourcesException {
mCanvas = new Canvas();
init(s,pid,display,w,h,format,flags);
}
public Surface() {
mCanvas = new Canvas();
}
public native void copyFrom(Surface o);
public native boolean isValid();
public native void clear();
public Canvas lockCanvas(Rect dirty) throws OutOfResourcesException {
return lockCanvasNative(dirty);
}
private native Canvas lockCanvasNative(Rect dirty);
public native void unlockCanvasAndPost(Canvas canvas);