Methods Summary |
---|
public void | allocateBuffers()Allocate buffers ahead of time to avoid allocation delays during rendering
synchronized (mLock) {
checkNotReleasedLocked();
nativeAllocateBuffers(mNativeObject);
}
|
private void | checkNotReleasedLocked()
if (mNativeObject == 0) {
throw new IllegalStateException("Surface has already been released.");
}
|
public void | copyFrom(SurfaceControl other)Copy another surface to this one. This surface now holds a reference
to the same data as the original surface, and is -not- the owner.
This is for use by the window manager when returning a window surface
back from a client, converting it from the representation being managed
by the window manager to the representation the client uses to draw
in to it.
if (other == null) {
throw new IllegalArgumentException("other must not be null");
}
long surfaceControlPtr = other.mNativeObject;
if (surfaceControlPtr == 0) {
throw new NullPointerException(
"SurfaceControl native object is null. Are you using a released SurfaceControl?");
}
long newNativeObject = nativeCreateFromSurfaceControl(surfaceControlPtr);
synchronized (mLock) {
if (mNativeObject != 0) {
nativeRelease(mNativeObject);
}
setNativeObjectLocked(newNativeObject);
}
|
public int | describeContents()
return 0;
|
public void | destroy()Free all server-side state associated with this surface and
release this object's reference. This method can only be
called from the process that created the service.
release();
|
protected void | finalize()
try {
if (mCloseGuard != null) {
mCloseGuard.warnIfOpen();
}
release();
} finally {
super.finalize();
}
|
public int | getGenerationId()Gets the generation number of this surface, incremented each time
the native surface contained within this object changes.
synchronized (mLock) {
return mGenerationId;
}
|
public boolean | isConsumerRunningBehind()Returns true if the consumer of this Surface is running behind the producer.
synchronized (mLock) {
checkNotReleasedLocked();
return nativeIsConsumerRunningBehind(mNativeObject);
}
|
public boolean | isValid()Returns true if this object holds a valid surface.
synchronized (mLock) {
if (mNativeObject == 0) return false;
return nativeIsValid(mNativeObject);
}
|
public android.graphics.Canvas | lockCanvas(android.graphics.Rect inOutDirty)Gets a {@link Canvas} for drawing into this surface.
After drawing into the provided {@link Canvas}, the caller must
invoke {@link #unlockCanvasAndPost} to post the new contents to the surface.
synchronized (mLock) {
checkNotReleasedLocked();
if (mLockedObject != 0) {
// Ideally, nativeLockCanvas() would throw in this situation and prevent the
// double-lock, but that won't happen if mNativeObject was updated. We can't
// abandon the old mLockedObject because it might still be in use, so instead
// we just refuse to re-lock the Surface.
throw new IllegalArgumentException("Surface was already locked");
}
mLockedObject = nativeLockCanvas(mNativeObject, mCanvas, inOutDirty);
return mCanvas;
}
|
public android.graphics.Canvas | lockHardwareCanvas()Gets a {@link Canvas} for drawing into this surface.
After drawing into the provided {@link Canvas}, the caller must
invoke {@link #unlockCanvasAndPost} to post the new contents to the surface.
Unlike {@link #lockCanvas(Rect)} this will return a hardware-accelerated
canvas. See the
unsupported drawing operations for a list of what is and isn't
supported in a hardware-accelerated canvas. It is also required to
fully cover the surface every time {@link #lockHardwareCanvas()} is
called as the buffer is not preserved between frames. Partial updates
are not supported.
synchronized (mLock) {
checkNotReleasedLocked();
if (mHwuiContext == null) {
mHwuiContext = new HwuiContext();
}
return mHwuiContext.lockCanvas(
nativeGetWidth(mNativeObject),
nativeGetHeight(mNativeObject));
}
|
private static native long | nHwuiCreate(long rootNode, long surface)
|
private static native void | nHwuiDestroy(long renderer)
|
private static native void | nHwuiDraw(long renderer)
|
private static native void | nHwuiSetSurface(long renderer, long surface)
|
private static native void | nativeAllocateBuffers(long nativeObject)
|
private static native long | nativeCreateFromSurfaceControl(long surfaceControlNativeObject)
|
private static native long | nativeCreateFromSurfaceTexture(android.graphics.SurfaceTexture surfaceTexture)
|
private static native int | nativeGetHeight(long nativeObject)
|
private static native int | nativeGetWidth(long nativeObject)
|
private static native boolean | nativeIsConsumerRunningBehind(long nativeObject)
|
private static native boolean | nativeIsValid(long nativeObject)
|
private static native long | nativeLockCanvas(long nativeObject, android.graphics.Canvas canvas, android.graphics.Rect dirty)
|
private static native long | nativeReadFromParcel(long nativeObject, android.os.Parcel source)
|
private static native void | nativeRelease(long nativeObject)
|
private static native void | nativeUnlockCanvasAndPost(long nativeObject, android.graphics.Canvas canvas)
|
private static native void | nativeWriteToParcel(long nativeObject, android.os.Parcel dest)
|
public void | readFromParcel(android.os.Parcel source)
if (source == null) {
throw new IllegalArgumentException("source must not be null");
}
synchronized (mLock) {
// nativeReadFromParcel() will either return mNativeObject, or
// create a new native Surface and return it after reducing
// the reference count on mNativeObject. Either way, it is
// not necessary to call nativeRelease() here.
mName = source.readString();
setNativeObjectLocked(nativeReadFromParcel(mNativeObject, source));
}
|
public void | release()Release the local reference to the server-side surface.
Always call release() when you're done with a Surface.
This will make the surface invalid.
synchronized (mLock) {
if (mNativeObject != 0) {
nativeRelease(mNativeObject);
setNativeObjectLocked(0);
}
if (mHwuiContext != null) {
mHwuiContext.destroy();
mHwuiContext = null;
}
}
|
public static java.lang.String | rotationToString(int rotation)Returns a human readable representation of a rotation.
switch (rotation) {
case Surface.ROTATION_0: {
return "ROTATION_0";
}
case Surface.ROTATION_90: {
return "ROATATION_90";
}
case Surface.ROTATION_180: {
return "ROATATION_180";
}
case Surface.ROTATION_270: {
return "ROATATION_270";
}
default: {
throw new IllegalArgumentException("Invalid rotation: " + rotation);
}
}
|
void | setCompatibilityTranslator(android.content.res.CompatibilityInfo.Translator translator)Sets the translator used to scale canvas's width/height in compatibility
mode.
if (translator != null) {
float appScale = translator.applicationScale;
mCompatibleMatrix = new Matrix();
mCompatibleMatrix.setScale(appScale, appScale);
}
|
private void | setNativeObjectLocked(long ptr)
if (mNativeObject != ptr) {
if (mNativeObject == 0 && ptr != 0) {
mCloseGuard.open("release");
} else if (mNativeObject != 0 && ptr == 0) {
mCloseGuard.close();
}
mNativeObject = ptr;
mGenerationId += 1;
if (mHwuiContext != null) {
mHwuiContext.updateSurface();
}
}
|
public java.lang.String | toString()
synchronized (mLock) {
return "Surface(name=" + mName + ")/@0x" +
Integer.toHexString(System.identityHashCode(this));
}
|
public void | transferFrom(android.view.Surface other)This is intended to be used by {@link SurfaceView#updateWindow} only.
if (other == null) {
throw new IllegalArgumentException("other must not be null");
}
if (other != this) {
final long newPtr;
synchronized (other.mLock) {
newPtr = other.mNativeObject;
other.setNativeObjectLocked(0);
}
synchronized (mLock) {
if (mNativeObject != 0) {
nativeRelease(mNativeObject);
}
setNativeObjectLocked(newPtr);
}
}
|
public void | unlockCanvas(android.graphics.Canvas canvas)
throw new UnsupportedOperationException();
|
public void | unlockCanvasAndPost(android.graphics.Canvas canvas)Posts the new contents of the {@link Canvas} to the surface and
releases the {@link Canvas}.
synchronized (mLock) {
checkNotReleasedLocked();
if (mHwuiContext != null) {
mHwuiContext.unlockAndPost(canvas);
} else {
unlockSwCanvasAndPost(canvas);
}
}
|
private void | unlockSwCanvasAndPost(android.graphics.Canvas canvas)
if (canvas != mCanvas) {
throw new IllegalArgumentException("canvas object must be the same instance that "
+ "was previously returned by lockCanvas");
}
if (mNativeObject != mLockedObject) {
Log.w(TAG, "WARNING: Surface's mNativeObject (0x" +
Long.toHexString(mNativeObject) + ") != mLockedObject (0x" +
Long.toHexString(mLockedObject) +")");
}
if (mLockedObject == 0) {
throw new IllegalStateException("Surface was not locked");
}
try {
nativeUnlockCanvasAndPost(mLockedObject, canvas);
} finally {
nativeRelease(mLockedObject);
mLockedObject = 0;
}
|
public void | writeToParcel(android.os.Parcel dest, int flags)
if (dest == null) {
throw new IllegalArgumentException("dest must not be null");
}
synchronized (mLock) {
dest.writeString(mName);
nativeWriteToParcel(mNativeObject, dest);
}
if ((flags & Parcelable.PARCELABLE_WRITE_RETURN_VALUE) != 0) {
release();
}
|