java.lang.Object | |
↳ | android.view.Surface |
Class Overview类的概述
Handle onto a raw buffer that is being managed by the screen compositor.被屏幕合成器所管理的 原生缓冲区 的句柄。
Summary
Nested Classes内嵌的类 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
class |
Surface.OutOfResourcesException surface没有资源异常 |
Exception thrown when a Canvas couldn't be locked with 当一个canvas不能通过lockCanvas(Rect)被锁定时,或者一个SurfaceTexture不能成功的被分配。 |
Constants常量 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ROTATION_0 | Rotation constant: 0 degree rotation (natural orientation) | |||||||||
int | ROTATION_180 | Rotation constant: 180 degree rotation. | |||||||||
int | ROTATION_270 | Rotation constant: 270 degree rotation. | |||||||||
int | ROTATION_90 | Rotation constant: 90 degree rotation. |
[Expand]
Inherited Constants
| |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface android.os.Parcelable
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
public static final Creator<Surface> | CREATOR |
Public Constructors公共构造方法 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Surface(SurfaceTexture surfaceTexture) 从一个SurfaceTexture中创建surface Create Surface from a |
Public Methods公共方法 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int |
描述在这个Parcelables 马歇尔陈述中包含的各种对象 Describe the kinds of special objects contained in this Parcelable's marshalled representation.
|
||||||||||
boolean |
isValid() 如果这个对象持有一个有效的surface,则返回true。 Returns true if this object holds a valid surface.
|
||||||||||
Canvas |
lockCanvas(Rect inOutDirty) 获取一张画布用来向这个surface中画画。 Gets a
Canvas for drawing into this surface. |
||||||||||
void |
readFromParcel(Parcel source) 从打包中读取数据(打包数据源) |
||||||||||
void |
release() 释放指向服务端surface的本地连接。 Release the local reference to the server-side surface.
|
||||||||||
String |
toString() 返回一个包含了精确,人类可读懂的这个对象的描述。 Returns a string containing a concise, human-readable description of this object.
|
||||||||||
void |
unlockCanvas(Canvas canvas) 在API7中这个方法被弃用了。 This method was deprecated in API level 17. This API has been removed and is not supported. Do not use.
|
||||||||||
void |
unlockCanvasAndPost(Canvas canvas) 提交这个canvas中新的内容到surface,并释放这个canvas。 |
||||||||||
void |
writeToParcel(Parcel dest, int flags) 写到打包(目标导报对象,标记)。扁平化这个对象到一个包中。 Flatten this object in to a Parcel.
|
Protected Methods受保护的方法 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void |
finalize() 当垃圾回收器侦测到这个实例不再可读时,被调用。 Invoked when the garbage collector has detected that this instance is no longer reachable.
|
[Expand]
Inherited Methods
| |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object |
|||||||||||
From interface android.os.Parcelable |
Constants
public static final int ROTATION_0
Rotation constant: 0 degree rotation (natural orientation)
public static final int ROTATION_180
Rotation constant: 180 degree rotation.
public static final int ROTATION_270
Rotation constant: 270 degree rotation.
public static final int ROTATION_90
Rotation constant: 90 degree rotation.
Fields
Public Constructors共有构造方法
public Surface (SurfaceTexture surfaceTexture)
从一个SurfaceTexture中创建surface。被画到surface的图像将会被SurfaceTexture可得到。SurfaceTexture可以通过updateTextImage()方法附加他们到一个开放的图形ES texture。
SurfaceTexture
.Images drawn to the Surface will be made available to the
SurfaceTexture
, which can attach them to an OpenGL ES texture via updateTexImage()
.
Parameters
surfaceTexture |
The 通过这个Surface更新的surfaceTexture |
---|
Throws
Surface.OutOfResourcesException 抛出surface资源不可获得异常 |
if the surface could not be created. 如果这个surface不能创建 |
---|
Public Methods
public int describeContents ()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
Returns
返回一个bitmask指示了这个包的marshalled的集合对象的类型- a bitmask indicating the set of special object types marshalled by the Parcelable.
public boolean isValid ()
Returns true if this object holds a valid surface.Returns
如果它持有一个物理的surface,则返回true,因此lockCanvas()将会成功。否则返回false。- True if it holds a physical surface, so lockCanvas() will succeed. Otherwise returns false.
public Canvas lockCanvas (Rect inOutDirty)
Canvas
for drawing into this surface.After drawing into the provided
Canvas
, the caller must invoke unlockCanvasAndPost(Canvas)
to post the new contents to the surface.
Parameters
inOutDirty 参数 |
A rectangle that represents the dirty region that the caller wants to redraw. This function may choose to expand the dirty rectangle if for example the surface has been resized or if the previous contents of the surface were not available. The caller must redraw the entire dirty region as represented by the contents of the inOutDirty rectangle upon return from this function. The caller may also pass 一个矩形代表dirty区域,调用者想在这个区域重画。这个功能可以选择去扩展这个dirty区域,如果例如这个surface大小被改变或者如果说surface先前的内容不再可以得到了。这个调用者必需重新绘制整个dirty区域 根据return这个函数返回的inOutDirty矩形区域。这个调用者或许也传递null,在这种情况下,整个surface应该被重画。 |
---|
Returns
返回一个canvas用来画到surface上- A canvas for drawing into the surface.
Throws
IllegalArgumentException 非法参数异常 | If the inOutDirty rectangle is not valid.矩形无效的 |
---|---|
Surface.OutOfResourcesException surface资源不可得异常 | If the canvas cannot be locked.如果这个画布不能被锁定 |
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.
public String toString ()
返回一个字符串,包含一个精确的,人类可读懂的对于这个对象的描述。子类被鼓励去重写这个方法并且提供一个实现。这个实现需要考虑这个对象的类型和数据。默认的实现与下面的表达相等 getClass().getName()+'@'+Integer,toHexString(hashCode())
getClass().getName()+'@'+Integer.toHexString(hashCode())
See Writing a useful toString
method if you intend implementing your own toString
method.
Returns
- a printable representation of this object.返回一个打印的这个对象的描述。
public void unlockCanvas (Canvas canvas)
This method was deprecated in API level 17.
This API has been removed and is not supported. Do not use.
public void unlockCanvasAndPost (Canvas canvas)
Parameters
canvas | The canvas previously obtained from lockCanvas(Rect) . |
---|
public void writeToParcel (Parcel dest, int flags)
Parameters
dest | The Parcel in which the object should be written.这个对象被写入的包 |
---|---|
flags |
Additional flags about how the object should be written. May be 0 or 附加的标记关于这个对象被怎么写入。或许为0或许为PARCELABLE_WRITE_RETURN_VALUE |
Protected Methods
protected void finalize ()
Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.
注意对象重写finalize 值得注意的它比不重写的对象是更昂贵。当这个对象不再可读时,Finalizers或许运行很长一段时间,这依赖于内存的压力,因此依赖这个方法来实现cleanup是很不好的一个注意。另外也要注意finalizers运行在一个单独的VM wide finalizer线程,因此在一个finalizer中进行一个堵塞性的工作是非常不好的。一个finalizer通常仅仅在一个类有一个本地的peer而且需要调用一个本地方法去销毁那个同龄的peer。即使如此,最好提供一个明确的close方法(并实现Closeable),并且坚持这个callers人为的处理这个instance。这个有时工作的很好,例如对于files,但是对于一些像BigInteger这些典型的调用代码则会处理很多临时性的问题。不幸的是,创建很多临时性的代码是最烂的代码之一,就view的 单finalizer线程而言。
Note that objects that override finalize
are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close
method (and implement Closeable
), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.
如果你必须finalizers,考虑一下至少提供你自己的ReferenceQueue并且有你自己的队列线程。
If you must use finalizers, consider at least providing your own ReferenceQueue
and having your own thread process that queue.
不像构造方法,finalizers不是自动的链接上的。你要自己负责调用super.finalize()方法。
Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize()
yourself.
由finalizers抛出的未捕捉的异常,被忽略。并且不决定这个finalizer线程。看 Effective Java Item7的“Avoid finalizers”获得更多的内容。
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread.
See Effective Java Item 7, "Avoid finalizers" for more.
Throws
Throwable |
---|