| android.view.SurfaceHolder |
Abstract interface to someone holding a display surface. Allows you to control the surface size and format, edit the pixels in the surface, and monitor changes to the surface. This interface is typically available through the SurfaceView class.
When using this interface from a thread different than the one running its SurfaceView, you will want to carefully read the lockCanvas() and Callback.surfaceCreated.
Nested Classes| SurfaceHolder.Callback | A client may implement this interface to receive information about changes to the surface. |
| void | addCallback(Callback callback) | ||||
| Add a Callback interface for this holder. | |||||
| Surface | getSurface() | ||||
| Direct access to the surface object. | |||||
| Rect | getSurfaceFrame() | ||||
| Retrieve the current size of the surface. | |||||
| Canvas | lockCanvas(Rect dirty) | ||||
| Just like lockCanvas() but allows to specify a dirty rectangle. | |||||
| Canvas | lockCanvas() | ||||
| Start editing the pixels in the surface. | |||||
| void | removeCallback(Callback callback) | ||||
| Removes a previously added Callback interface from this holder. | |||||
| void | setFixedSize(int width, int height) | ||||
| Make the surface a fixed size. | |||||
| void | setFormat(int format) | ||||
| Set the desired PixelFormat of the surface. | |||||
| void | setSizeFromLayout() | ||||
| Allow the surface to resized based on layout of its container (this is the default). | |||||
| void | unlockCanvasAndPost(Canvas canvas) | ||||
| Finish editing pixels in the surface. | |||||
| callback | The new Callback interface. |
|---|
Note that if you directly access the Surface from another thread, it is critical that you correctly implement Callback.surfaceCreated and Callback.surfaceDestroyed to ensure that thread only accesses the Surface while it is valid, and that the Surface does not get destroyed while the thread is using it.
| dirty | Area of the Surface that will be modified. |
|---|
The content of the Surface is never preserved between unlockCanvas() and lockCanvas(), for this reason, every pixel within the Surface area must be written. The only exception to this rule is when a dirty rectangle is specified, in which case, non dirty pixels will be preserved.
If you call this repeatedly when the Surface is not ready (before Callback.surfaceCreated or after Callback.surfaceDestroyed), your calls will be throttled to a slow rate in order to avoid consuming CPU.
If null is not returned, this function internally holds a lock until the corresponding unlockCanvasAndPost(Canvas) call, preventing SurfaceView from creating, destroying, or modifying the surface while it is being drawn. This can be more convenience than accessing the Surface directly, as you do not need to do special synchronization with a drawing thread in Callback.surfaceDestroyed.
| callback | The Callback interface to remove. |
|---|
| width | The surface's width. |
|---|---|
| height | The surface's height. |
| format | A constant from PixelFormat. |
|---|
| canvas | The Canvas previously returned by lockCanvas(). |
|---|