public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback2
A GLSurfaceView provides the following features:
For more information about how to use OpenGL, read the OpenGL developer guide.
Typically you use GLSurfaceView by subclassing it and overriding one or more of the
View system input event methods. If your application does not need to override event
methods then GLSurfaceView can be used as-is. For the most part
GLSurfaceView behavior is customized by calling "set" methods rather than by subclassing.
For example, unlike a regular View, drawing is delegated to a separate Renderer object which
is registered with the GLSurfaceView
using the setRenderer(Renderer)
call.
setRenderer(Renderer)
.
However, if desired, you can modify the default behavior of GLSurfaceView by calling one or
more of these methods before calling setRenderer:
setDebugFlags(int)
setEGLConfigChooser(boolean)
setEGLConfigChooser(EGLConfigChooser)
setEGLConfigChooser(int, int, int, int, int, int)
setGLWrapper(GLWrapper)
By default GLSurfaceView chooses a EGLConfig that has an RGB_888 pixel format, with at least a 16-bit depth buffer and no stencil.
If you would prefer a different EGLConfig you can override the default behavior by calling one of the setEGLConfigChooser methods.
setDebugFlags(int)
,
and setGLWrapper(android.opengl.GLSurfaceView.GLWrapper)
. These methods may be called before and/or after setRenderer, but
typically they are called before setRenderer so that they take effect immediately.
setRenderer(android.opengl.GLSurfaceView.Renderer)
to register a GLSurfaceView.Renderer
.
The renderer is
responsible for doing the actual OpenGL rendering.
setRenderMode(int)
. The default is continuous rendering.
onPause()
when the activity stops and
onResume()
when the activity starts. These calls allow GLSurfaceView to
pause and resume the rendering thread, and also allow GLSurfaceView to release and recreate
the OpenGL display.
To handle an event you will typically subclass GLSurfaceView and override the
appropriate method, just as you would with any other View. However, when handling
the event, you may need to communicate with the Renderer object
that's running in the rendering thread. You can do this using any
standard Java cross-thread communication mechanism. In addition,
one relatively easy way to communicate with your renderer is
to call
queueEvent(Runnable)
. For example:
class MyGLSurfaceView extends GLSurfaceView { private MyRenderer mMyRenderer; public void start() { mMyRenderer = ...; setRenderer(mMyRenderer); } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { queueEvent(new Runnable() { // This method will be called on the rendering // thread: public void run() { mMyRenderer.handleDpadCenter(); }}); return true; } return super.onKeyDown(keyCode, event); } }
Modifier and Type | Class and Description |
---|---|
static interface |
GLSurfaceView.EGLConfigChooser
An interface for choosing an EGLConfig configuration from a list of
potential configurations.
|
static interface |
GLSurfaceView.EGLContextFactory
An interface for customizing the eglCreateContext and eglDestroyContext calls.
|
static interface |
GLSurfaceView.EGLWindowSurfaceFactory
An interface for customizing the eglCreateWindowSurface and eglDestroySurface calls.
|
static interface |
GLSurfaceView.GLWrapper
An interface used to wrap a GL interface.
|
static interface |
GLSurfaceView.Renderer
A generic renderer interface.
|
View.AccessibilityDelegate, View.BaseSavedState, View.DragShadowBuilder, View.DrawingCacheQuality, View.FindViewFlags, View.FocusableMode, View.FocusDirection, View.FocusRealDirection, View.LayoutDir, View.MeasureSpec, View.OnApplyWindowInsetsListener, View.OnAttachStateChangeListener, View.OnClickListener, View.OnContextClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnScrollChangeListener, View.OnSystemUiVisibilityChangeListener, View.OnTouchListener, View.ResolvedLayoutDir, View.ScrollBarStyle, View.ScrollIndicators, View.TextAlignment, View.Visibility
Modifier and Type | Field and Description |
---|---|
static int |
DEBUG_CHECK_GL_ERROR
Check glError() after every GL call and throw an exception if glError indicates
that an error has occurred.
|
static int |
DEBUG_LOG_GL_CALLS
Log GL calls to the system log at "verbose" level with tag "GLSurfaceView".
|
static int |
RENDERMODE_CONTINUOUSLY
The renderer is called
continuously to re-render the scene.
|
static int |
RENDERMODE_WHEN_DIRTY
The renderer only renders
when the surface is created, or when
requestRender() is called. |
ACCESSIBILITY_CURSOR_POSITION_UNDEFINED, ACCESSIBILITY_LIVE_REGION_ASSERTIVE, ACCESSIBILITY_LIVE_REGION_NONE, ACCESSIBILITY_LIVE_REGION_POLITE, ALPHA, DEBUG_LAYOUT_PROPERTY, DRAG_FLAG_GLOBAL, DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION, DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION, DRAG_FLAG_GLOBAL_URI_READ, DRAG_FLAG_GLOBAL_URI_WRITE, DRAG_FLAG_OPAQUE, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_UNDEFINED, mAttributes, mBottom, mCachingFailed, mContext, mCurrentAnimation, mDebugViewAttributes, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mInputEventConsistencyVerifier, mLayoutParams, mLeft, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, mUserPaddingBottom, mUserPaddingLeft, mUserPaddingRight, NAVIGATION_BAR_TRANSIENT, NAVIGATION_BAR_TRANSLUCENT, NAVIGATION_BAR_TRANSPARENT, NAVIGATION_BAR_UNHIDE, NO_ID, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, PUBLIC_STATUS_BAR_VISIBILITY_MASK, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_NONE, SCROLL_AXIS_VERTICAL, SCROLL_INDICATOR_BOTTOM, SCROLL_INDICATOR_END, SCROLL_INDICATOR_LEFT, SCROLL_INDICATOR_RIGHT, SCROLL_INDICATOR_START, SCROLL_INDICATOR_TOP, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, sPreserveMarginParamsInLayoutParamConversion, STATUS_BAR_DISABLE_BACK, STATUS_BAR_DISABLE_CLOCK, STATUS_BAR_DISABLE_EXPAND, STATUS_BAR_DISABLE_HOME, STATUS_BAR_DISABLE_NOTIFICATION_ALERTS, STATUS_BAR_DISABLE_NOTIFICATION_ICONS, STATUS_BAR_DISABLE_NOTIFICATION_TICKER, STATUS_BAR_DISABLE_RECENT, STATUS_BAR_DISABLE_SEARCH, STATUS_BAR_DISABLE_SYSTEM_INFO, STATUS_BAR_HIDDEN, STATUS_BAR_TRANSIENT, STATUS_BAR_TRANSLUCENT, STATUS_BAR_TRANSPARENT, STATUS_BAR_UNHIDE, STATUS_BAR_VISIBLE, SYSTEM_UI_CLEARABLE_FLAGS, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_IMMERSIVE, SYSTEM_UI_FLAG_IMMERSIVE_STICKY, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LIGHT_STATUS_BAR, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, SYSTEM_UI_TRANSPARENT, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z
Constructor and Description |
---|
GLSurfaceView(Context context)
Standard View constructor.
|
GLSurfaceView(Context context,
AttributeSet attrs)
Standard View constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
int |
getDebugFlags()
Get the current value of the debug flags.
|
boolean |
getPreserveEGLContextOnPause() |
int |
getRenderMode()
Get the current rendering mode.
|
protected void |
onAttachedToWindow()
This method is used as part of the View class and is not normally
called or subclassed by clients of GLSurfaceView.
|
protected void |
onDetachedFromWindow()
This is called when the view is detached from a window.
|
void |
onPause()
Pause the rendering thread, optionally tearing down the EGL context
depending upon the value of
setPreserveEGLContextOnPause(boolean) . |
void |
onResume()
Resumes the rendering thread, re-creating the OpenGL context if necessary.
|
void |
queueEvent(Runnable r)
Queue a runnable to be run on the GL rendering thread.
|
void |
requestRender()
Request that the renderer render a frame.
|
void |
setDebugFlags(int debugFlags)
Set the debug flags to a new value.
|
void |
setEGLConfigChooser(boolean needDepth)
Install a config chooser which will choose a config
as close to 16-bit RGB as possible, with or without an optional depth
buffer as close to 16-bits as possible.
|
void |
setEGLConfigChooser(GLSurfaceView.EGLConfigChooser configChooser)
Install a custom EGLConfigChooser.
|
void |
setEGLConfigChooser(int redSize,
int greenSize,
int blueSize,
int alphaSize,
int depthSize,
int stencilSize)
Install a config chooser which will choose a config
with at least the specified depthSize and stencilSize,
and exactly the specified redSize, greenSize, blueSize and alphaSize.
|
void |
setEGLContextClientVersion(int version)
Inform the default EGLContextFactory and default EGLConfigChooser
which EGLContext client version to pick.
|
void |
setEGLContextFactory(GLSurfaceView.EGLContextFactory factory)
Install a custom EGLContextFactory.
|
void |
setEGLWindowSurfaceFactory(GLSurfaceView.EGLWindowSurfaceFactory factory)
Install a custom EGLWindowSurfaceFactory.
|
void |
setGLWrapper(GLSurfaceView.GLWrapper glWrapper)
Set the glWrapper.
|
void |
setPreserveEGLContextOnPause(boolean preserveOnPause)
Control whether the EGL context is preserved when the GLSurfaceView is paused and
resumed.
|
void |
setRenderer(GLSurfaceView.Renderer renderer)
Set the renderer associated with this view.
|
void |
setRenderMode(int renderMode)
Set the rendering mode.
|
void |
surfaceChanged(SurfaceHolder holder,
int format,
int w,
int h)
This method is part of the SurfaceHolder.Callback interface, and is
not normally called or subclassed by clients of GLSurfaceView.
|
void |
surfaceCreated(SurfaceHolder holder)
This method is part of the SurfaceHolder.Callback interface, and is
not normally called or subclassed by clients of GLSurfaceView.
|
void |
surfaceDestroyed(SurfaceHolder holder)
This method is part of the SurfaceHolder.Callback interface, and is
not normally called or subclassed by clients of GLSurfaceView.
|
void |
surfaceRedrawNeeded(SurfaceHolder holder)
This method is part of the SurfaceHolder.Callback interface, and is
not normally called or subclassed by clients of GLSurfaceView.
|
dispatchDraw, draw, gatherTransparentRegion, getHolder, isFixedSize, onMeasure, onWindowVisibilityChanged, setFrame, setSecure, setVisibility, setWindowType, setZOrderMediaOverlay, setZOrderOnTop, updateWindow, updateWindowPosition_renderWorker, windowPositionLost_uiRtSync
addChildrenForAccessibility, addFocusables, addFocusables, addFrameMetricsListener, addOnAttachStateChangeListener, addOnLayoutChangeListener, addTouchables, animate, announceForAccessibility, applyDrawableToTransparentRegion, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelDragAndDrop, cancelLongPress, cancelPendingInputEvents, canHaveDisplayList, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, captureTransitioningViews, checkInputConnectionProxy, clearAccessibilityFocus, clearAnimation, clearFocus, combineMeasuredStates, computeFitSystemWindows, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeOpaqueFlags, computeScroll, computeSystemWindowInsets, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createAccessibilityNodeInfo, createAccessibilityNodeInfoInternal, createContextMenu, createSnapshot, damageInParent, debug, debug, debugIndent, destroyDrawingCache, destroyHardwareResources, dispatchActivityResult, dispatchApplyWindowInsets, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericFocusedEvent, dispatchGenericMotionEvent, dispatchGenericPointerEvent, dispatchGetDisplayList, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPrePerformAccessibilityAction, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerEvent, dispatchPopulateAccessibilityEvent, dispatchPopulateAccessibilityEventInternal, dispatchProvideStructure, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, drawableHotspotChanged, drawableStateChanged, encode, encodeProperties, findFocus, findNamedViews, findViewByAccessibilityIdTraversal, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewByPredicateTraversal, findViewsWithText, findViewTraversal, findViewWithTag, findViewWithTagTraversal, fitsSystemWindows, fitSystemWindows, focusSearch, forceHasOverlappingRendering, forceLayout, generateViewId, getAccessibilityClassName, getAccessibilityDelegate, getAccessibilityLiveRegion, getAccessibilityNodeProvider, getAccessibilitySelectionEnd, getAccessibilitySelectionStart, getAccessibilityTraversalAfter, getAccessibilityTraversalBefore, getAccessibilityViewId, getAccessibilityWindowId, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBackgroundTintList, getBackgroundTintMode, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getBoundsOnScreen, getBoundsOnScreen, getCameraDistance, getClipBounds, getClipBounds, getClipToOutline, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDisplay, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getElevation, getFadeHeight, getFadeTop, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getFocusedRect, getForeground, getForegroundGravity, getForegroundTintList, getForegroundTintMode, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHardwareRenderer, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getHorizontalScrollFactor, getHotspotBounds, getId, getImportantForAccessibility, getInverseMatrix, getIterableTextForAccessibility, getIteratorForGranularity, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInSurface, getLocationInWindow, getLocationOnScreen, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOpticalInsets, getOutlineProvider, getOutsets, getOverlay, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getPointerIcon, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getResources, getRevealOnFocusHint, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getRootWindowInsets, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getSolidColor, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getVerticalScrollFactor, getViewRootImpl, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowDisplayFrame, getWindowId, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, getZ, handleScrollBarDragging, hasFocus, hasFocusable, hasHoveredChild, hasNestedScrollingParent, hasOnClickListeners, hasOpaqueScrollbars, hasOverlappingRendering, hasShadow, hasTransientState, hasWindowFocus, includeForAccessibility, inflate, initializeFadingEdge, initializeFadingEdgeInternal, initializeScrollbars, initializeScrollbarsInternal, internalSetPadding, invalidate, invalidate, invalidate, invalidateDrawable, invalidateOutline, invalidateParentCaches, invalidateParentIfNeeded, invalidateParentIfNeededAndWasQuickRejected, isAccessibilityFocused, isAccessibilitySelectionExtendable, isActionableForAccessibility, isActivated, isAssistBlocked, isAttachedToWindow, isClickable, isContextClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isForegroundInsidePadding, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isInEditMode, isInLayout, isInScrollingContainer, isInTouchMode, isLaidOut, isLayoutDirectionInherited, isLayoutDirectionResolved, isLayoutModeOptical, isLayoutRequested, isLayoutRtl, isLongClickable, isNestedScrollingEnabled, isOpaque, isPaddingOffsetRequired, isPaddingRelative, isPressed, isRootNamespace, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentInherited, isTextAlignmentResolved, isTextDirectionInherited, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, isVisibleToUser, isVisibleToUser, jumpDrawablesToCurrentState, layout, makeOptionalFitsSystemWindows, measure, mergeDrawableStates, notifySubtreeAccessibilityStateChangedIfNeeded, notifyViewAccessibilityStateChangedIfNeeded, offsetLeftAndRight, offsetTopAndBottom, onActivityResult, onAnimationEnd, onAnimationStart, onApplyWindowInsets, onCancelPendingInputEvents, onCheckIsTextEditor, onCloseSystemDialogs, onConfigurationChanged, onCreateContextMenu, onCreateDrawableState, onCreateInputConnection, onDetachedFromWindowInternal, onDisplayHint, onDragEvent, onDraw, onDrawForeground, onDrawHorizontalScrollBar, onDrawScrollBars, onDrawVerticalScrollBar, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onFocusLost, onGenericMotionEvent, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityEventInternal, onInitializeAccessibilityNodeInfo, onInitializeAccessibilityNodeInfoInternal, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onLayout, onOverScrolled, onPopulateAccessibilityEvent, onPopulateAccessibilityEventInternal, onProvideStructure, onProvideVirtualStructure, onRenderNodeDetached, onResolveDrawables, onResolvePointerIcon, onRestoreInstanceState, onRtlPropertiesChanged, onSaveInstanceState, onScreenStateChanged, onScrollChanged, onSetAlpha, onSizeChanged, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onVisibilityAggregated, onVisibilityChanged, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, outputDirtyFlags, overScrollBy, performAccessibilityAction, performAccessibilityActionInternal, performButtonActionOnTouchDown, performClick, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, playSoundEffect, pointInView, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, recomputePadding, refreshDrawableState, removeCallbacks, removeFrameMetricsListener, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestAccessibilityFocus, requestApplyInsets, requestFitSystemWindows, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestKeyboardShortcuts, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, requestUnbufferedDispatch, resetPaddingToInitialValues, resetResolvedDrawables, resetResolvedLayoutDirection, resetResolvedPadding, resetResolvedTextAlignment, resetResolvedTextDirection, resetRtlProperties, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveSize, resolveSizeAndState, resolveTextAlignment, resolveTextDirection, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventInternal, sendAccessibilityEventUnchecked, sendAccessibilityEventUncheckedInternal, setAccessibilityDelegate, setAccessibilityLiveRegion, setAccessibilitySelection, setAccessibilityTraversalAfter, setAccessibilityTraversalBefore, setActivated, setAlpha, setAnimation, setAnimationMatrix, setAssistBlocked, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBackgroundTintList, setBackgroundTintMode, setBottom, setCameraDistance, setClickable, setClipBounds, setClipToOutline, setContentDescription, setContextClickable, setDisabledSystemUiVisibility, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setElevation, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setForeground, setForegroundGravity, setForegroundTintList, setForegroundTintMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setIsRootNamespace, setKeepScreenOn, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutParams, setLeft, setLeftTopRightBottom, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnApplyWindowInsetsListener, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOpticalInsets, setOutlineProvider, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPointerIcon, setPressed, setRevealClip, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setStateListAnimator, setSystemUiVisibility, setTag, setTag, setTagInternal, setTextAlignment, setTextDirection, setTop, setTouchDelegate, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setWillNotCacheDrawing, setWillNotDraw, setX, setY, setZ, showContextMenu, showContextMenu, startActionMode, startActionMode, startActivityForResult, startAnimation, startDrag, startDragAndDrop, startMovingTask, startNestedScroll, stopNestedScroll, toGlobalMotionEvent, toLocalMotionEvent, toString, transformFromViewToWindowSpace, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, updateDisplayListIfDirty, updateDragShadow, verifyDrawable, willNotCacheDrawing, willNotDraw
public static final int RENDERMODE_WHEN_DIRTY
requestRender()
is called.public static final int RENDERMODE_CONTINUOUSLY
getRenderMode()
,
setRenderMode(int)
,
Constant Field Valuespublic static final int DEBUG_CHECK_GL_ERROR
getDebugFlags()
,
setDebugFlags(int)
,
Constant Field Valuespublic static final int DEBUG_LOG_GL_CALLS
getDebugFlags()
,
setDebugFlags(int)
,
Constant Field Valuespublic GLSurfaceView(Context context)
setRenderer(android.opengl.GLSurfaceView.Renderer)
to register a renderer.public GLSurfaceView(Context context, AttributeSet attrs)
setRenderer(android.opengl.GLSurfaceView.Renderer)
to register a renderer.protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
public void setGLWrapper(GLSurfaceView.GLWrapper glWrapper)
GLSurfaceView.GLWrapper.wrap(GL)
method is called
whenever a surface is created. A GLWrapper can be used to wrap
the GL object that's passed to the renderer. Wrapping a GL
object enables examining and modifying the behavior of the
GL calls made by the renderer.
Wrapping is typically used for debugging purposes.
The default value is null.
glWrapper
- the new GLWrapperpublic void setDebugFlags(int debugFlags)
debugFlags
- the new debug flagsDEBUG_CHECK_GL_ERROR
,
DEBUG_LOG_GL_CALLS
public int getDebugFlags()
public void setPreserveEGLContextOnPause(boolean preserveOnPause)
If set to true, then the EGL context may be preserved when the GLSurfaceView is paused.
Prior to API level 11, whether the EGL context is actually preserved or not depends upon whether the Android device can support an arbitrary number of EGL contexts or not. Devices that can only support a limited number of EGL contexts must release the EGL context in order to allow multiple applications to share the GPU.
If set to false, the EGL context will be released when the GLSurfaceView is paused, and recreated when the GLSurfaceView is resumed.
The default is false.
preserveOnPause
- preserve the EGL context when pausedpublic boolean getPreserveEGLContextOnPause()
public void setRenderer(GLSurfaceView.Renderer renderer)
This method should be called once and only once in the life-cycle of a GLSurfaceView.
The following GLSurfaceView methods can only be called before setRenderer is called:
setEGLConfigChooser(boolean)
setEGLConfigChooser(EGLConfigChooser)
setEGLConfigChooser(int, int, int, int, int, int)
The following GLSurfaceView methods can only be called after setRenderer is called:
renderer
- the renderer to use to perform OpenGL drawing.public void setEGLContextFactory(GLSurfaceView.EGLContextFactory factory)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If this method is not called, then by default a context will be created with no shared context and with a null attribute list.
public void setEGLWindowSurfaceFactory(GLSurfaceView.EGLWindowSurfaceFactory factory)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If this method is not called, then by default a window surface will be created with a null attribute list.
public void setEGLConfigChooser(GLSurfaceView.EGLConfigChooser configChooser)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If no setEGLConfigChooser method is called, then by default the view will choose an EGLConfig that is compatible with the current android.view.Surface, with a depth buffer depth of at least 16 bits.
configChooser
- public void setEGLConfigChooser(boolean needDepth)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If no setEGLConfigChooser method is called, then by default the view will choose an RGB_888 surface with a depth buffer depth of at least 16 bits.
needDepth
- public void setEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize)
If this method is
called, it must be called before setRenderer(Renderer)
is called.
If no setEGLConfigChooser method is called, then by default the view will choose an RGB_888 surface with a depth buffer depth of at least 16 bits.
public void setEGLContextClientVersion(int version)
Use this method to create an OpenGL ES 2.0-compatible context. Example:
public MyView(Context context) { super(context); setEGLContextClientVersion(2); // Pick an OpenGL ES 2.0 context. setRenderer(new MyRenderer()); }
Note: Activities which require OpenGL ES 2.0 should indicate this by setting @lt;uses-feature android:glEsVersion="0x00020000" /> in the activity's AndroidManifest.xml file.
If this method is called, it must be called before setRenderer(Renderer)
is called.
This method only affects the behavior of the default EGLContexFactory and the
default EGLConfigChooser. If
setEGLContextFactory(EGLContextFactory)
has been called, then the supplied
EGLContextFactory is responsible for creating an OpenGL ES 2.0-compatible context.
If
setEGLConfigChooser(EGLConfigChooser)
has been called, then the supplied
EGLConfigChooser is responsible for choosing an OpenGL ES 2.0-compatible config.
version
- The EGLContext client version to choose. Use 2 for OpenGL ES 2.0public void setRenderMode(int renderMode)
requestRender()
is called. Defaults to RENDERMODE_CONTINUOUSLY.
Using RENDERMODE_WHEN_DIRTY can improve battery life and overall system performance by allowing the GPU and CPU to idle when the view does not need to be updated.
This method can only be called after setRenderer(Renderer)
renderMode
- one of the RENDERMODE_X constantsRENDERMODE_CONTINUOUSLY
,
RENDERMODE_WHEN_DIRTY
public int getRenderMode()
RENDERMODE_CONTINUOUSLY
,
RENDERMODE_WHEN_DIRTY
public void requestRender()
RENDERMODE_WHEN_DIRTY
, so that frames are only rendered on demand.
May be called
from any thread. Must not be called before a renderer has been set.public void surfaceCreated(SurfaceHolder holder)
surfaceCreated
in interface SurfaceHolder.Callback
holder
- The SurfaceHolder whose surface is being created.public void surfaceDestroyed(SurfaceHolder holder)
surfaceDestroyed
in interface SurfaceHolder.Callback
holder
- The SurfaceHolder whose surface is being destroyed.public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
surfaceChanged
in interface SurfaceHolder.Callback
holder
- The SurfaceHolder whose surface has changed.format
- The new PixelFormat of the surface.w
- The new width of the surface.h
- The new height of the surface.public void surfaceRedrawNeeded(SurfaceHolder holder)
surfaceRedrawNeeded
in interface SurfaceHolder.Callback2
holder
- The SurfaceHolder whose surface has changed.public void onPause()
setPreserveEGLContextOnPause(boolean)
.
This method should be called when it is no longer desirable for the
GLSurfaceView to continue rendering, such as in response to
Activity.onStop
.
Must not be called before a renderer has been set.public void onResume()
onPause()
.
This method should typically be called in
Activity.onStart
.
Must not be called before a renderer has been set.public void queueEvent(Runnable r)
r
- the runnable to be run on the GL rendering thread.protected void onAttachedToWindow()
onAttachedToWindow
in class SurfaceView
View.onDetachedFromWindow()
protected void onDetachedFromWindow()
View
onDetachedFromWindow
in class SurfaceView
View.onAttachedToWindow()