public abstract class BaseSurfaceHolder extends Object implements SurfaceHolder
SurfaceHolder.BadSurfaceTypeException, SurfaceHolder.Callback, SurfaceHolder.Callback2
Modifier and Type | Field and Description |
---|---|
ArrayList<SurfaceHolder.Callback> |
mCallbacks |
protected int |
mRequestedFormat |
Surface |
mSurface |
ReentrantLock |
mSurfaceLock |
SURFACE_TYPE_GPU, SURFACE_TYPE_HARDWARE, SURFACE_TYPE_NORMAL, SURFACE_TYPE_PUSH_BUFFERS
Constructor and Description |
---|
BaseSurfaceHolder() |
Modifier and Type | Method and Description |
---|---|
void |
addCallback(SurfaceHolder.Callback callback)
Add a Callback interface for this holder.
|
SurfaceHolder.Callback[] |
getCallbacks() |
int |
getRequestedFormat() |
int |
getRequestedHeight() |
int |
getRequestedType() |
int |
getRequestedWidth() |
Surface |
getSurface()
Direct access to the surface object.
|
Rect |
getSurfaceFrame()
Retrieve the current size of the surface.
|
Canvas |
lockCanvas()
Start editing the pixels in the surface.
|
Canvas |
lockCanvas(Rect dirty)
Just like
SurfaceHolder.lockCanvas() but allows specification of a dirty rectangle. |
abstract boolean |
onAllowLockCanvas() |
abstract void |
onRelayoutContainer() |
abstract void |
onUpdateSurface() |
void |
removeCallback(SurfaceHolder.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 |
setSurfaceFrameSize(int width,
int height) |
void |
setType(int type)
Sets the surface's type.
|
void |
ungetCallbacks() |
void |
unlockCanvasAndPost(Canvas canvas)
Finish editing pixels in the surface.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isCreating, setKeepScreenOn
public final ArrayList<SurfaceHolder.Callback> mCallbacks
public final ReentrantLock mSurfaceLock
public Surface mSurface
protected int mRequestedFormat
public abstract void onUpdateSurface()
public abstract void onRelayoutContainer()
public abstract boolean onAllowLockCanvas()
public int getRequestedWidth()
public int getRequestedHeight()
public int getRequestedFormat()
public int getRequestedType()
public void addCallback(SurfaceHolder.Callback callback)
SurfaceHolder
addCallback
in interface SurfaceHolder
callback
- The new Callback interface.public void removeCallback(SurfaceHolder.Callback callback)
SurfaceHolder
removeCallback
in interface SurfaceHolder
callback
- The Callback interface to remove.public SurfaceHolder.Callback[] getCallbacks()
public void ungetCallbacks()
public void setFixedSize(int width, int height)
SurfaceHolder
SurfaceView
, this must be called from the
same thread running the SurfaceView's window.setFixedSize
in interface SurfaceHolder
width
- The surface's width.height
- The surface's height.public void setSizeFromLayout()
SurfaceHolder
SurfaceHolder.Callback.surfaceChanged(android.view.SurfaceHolder, int, int, int)
for changes to the size of the surface.
When working with a SurfaceView
, this must be called from the
same thread running the SurfaceView's window.setSizeFromLayout
in interface SurfaceHolder
public void setFormat(int format)
SurfaceHolder
SurfaceView
, this must be called from the
same thread running the SurfaceView's window.setFormat
in interface SurfaceHolder
format
- A constant from PixelFormat.PixelFormat
public void setType(int type)
SurfaceHolder
setType
in interface SurfaceHolder
public Canvas lockCanvas()
SurfaceHolder
Callback.surfaceCreated
to find out when the Surface is available for use.
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 SurfaceHolder.unlockCanvasAndPost(android.graphics.Canvas)
call, preventing
SurfaceView
from creating, destroying, or modifying the surface
while it is being drawn. This can be more convenient than accessing
the Surface directly, as you do not need to do special synchronization
with a drawing thread in Callback.surfaceDestroyed
.
lockCanvas
in interface SurfaceHolder
public Canvas lockCanvas(Rect dirty)
SurfaceHolder
SurfaceHolder.lockCanvas()
but allows specification of a dirty rectangle.
Every
pixel within that rectangle must be written; however pixels outside
the dirty rectangle will be preserved by the next call to lockCanvas().lockCanvas
in interface SurfaceHolder
dirty
- Area of the Surface that will be modified.SurfaceHolder.lockCanvas()
public void unlockCanvasAndPost(Canvas canvas)
SurfaceHolder
unlockCanvasAndPost
in interface SurfaceHolder
canvas
- The Canvas previously returned by lockCanvas().SurfaceHolder.lockCanvas()
public Surface getSurface()
SurfaceHolder
SurfaceView
the holder's
Surface is not created until the view has been attached to the window
manager and performed a layout in order to determine the dimensions
and screen position of the Surface. You will thus usually need
to implement Callback.surfaceCreated
to find out when the Surface is available for use.
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.
This method is intended to be used by frameworks which often need direct access to the Surface object (usually to pass it to native code).
getSurface
in interface SurfaceHolder
public Rect getSurfaceFrame()
SurfaceHolder
SurfaceView
's window, or while inside of
SurfaceHolder.lockCanvas()
.getSurfaceFrame
in interface SurfaceHolder
public void setSurfaceFrameSize(int width, int height)