下面列出了怎么用javax.microedition.khronos.egl.EGLSurface的API类实例代码及写法,或者点击链接到github查看源代码。
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e(TAG, "eglCreateWindowSurface", e);
}
return result;
}
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e(TAG, "eglCreateWindowSurface", e);
}
return result;
}
@Override
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
int[] surfaceAttribs = {
EGL10.EGL_NONE
};
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, surfaceAttribs);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e("DefaultWindow", "eglCreateWindowSurface", e);
}
return result;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public android.opengl.EGLSurface createWindowSurface(android.opengl.EGLDisplay display, android.opengl.EGLConfig config, Object nativeWindow) {
int[] surfaceAttribs = {
EGL14.EGL_NONE
};
android.opengl.EGLSurface result = null;
try {
result = EGL14.eglCreateWindowSurface(display, config, nativeWindow, surfaceAttribs, 0);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e("DefaultWindow", "eglCreateWindowSurface", e);
}
return result;
}
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e(TAG, "eglCreateWindowSurface", e);
}
return result;
}
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e(TAG, "eglCreateWindowSurface", e);
}
return result;
}
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e(TAG, "eglCreateWindowSurface", e);
}
return result;
}
/**
* change context to draw this window surface
* @return
*/
private final boolean makeCurrent(final EGLSurface surface) {
// if (DEBUG) Log.v(TAG, "makeCurrent:");
/* if (mEglDisplay == null) {
if (DEBUG) Log.d(TAG, "makeCurrent:eglDisplay not initialized");
} */
if (surface == null || surface == EGL10.EGL_NO_SURFACE) {
final int error = mEgl.eglGetError();
if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
Log.e(TAG, "makeCurrent:EGL_BAD_NATIVE_WINDOW");
}
return false;
}
// attach EGL rendering context to specific EGL window surface
if (!mEgl.eglMakeCurrent(mEglDisplay, surface, surface, mContext.eglContext)) {
Log.w("TAG", "eglMakeCurrent" + mEgl.eglGetError());
return false;
}
return true;
}
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e(TAG, "eglCreateWindowSurface", e);
}
return result;
}
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e(TAG, "eglCreateWindowSurface", e);
}
return result;
}
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e(TAG, "eglCreateWindowSurface", e);
}
return result;
}
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display, EGLConfig config,
Object nativeWindow) {
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e(TAG, "eglCreateWindowSurface", e);
}
return result;
}
@Override
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
int[] surfaceAttribs = {
EGL10.EGL_NONE
};
EGLSurface result = null;
try {
result = egl.eglCreateWindowSurface(display, config, nativeWindow, surfaceAttribs);
} catch (IllegalArgumentException e) {
// This exception indicates that the surface flinger surface
// is not valid. This can happen if the surface flinger surface has
// been torn down, but the application has not yet been
// notified via SurfaceHolder.Callback.surfaceDestroyed.
// In theory the application should be notified first,
// but in practice sometimes it is not. See b/4588890
Log.e("DefaultWindow", "eglCreateWindowSurface", e);
}
return result;
}
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
EGLConfig config, Object nativeWindow) {
EGLSurface result = null;
d = display;
c = config;
try {
mEGLPreviewSurface = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
} catch (IllegalArgumentException e) {
Log.e(TAG, "eglCreateWindowSurface (native)", e);
}
// this return will trigger Renderer
result = mEGLPreviewSurface;
return result;
}
private EGLSurface createSurface(int width, int height) {
int[] surfaceAttrs = {
EGL10.EGL_WIDTH, width,
EGL10.EGL_HEIGHT, height,
EGL10.EGL_NONE
};
EGLSurface eglSurface = mEgl.eglCreatePbufferSurface(mEGLDisplay, mEglConfigs[0], surfaceAttrs);
mEgl.eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, getEGLContext());
return eglSurface;
}
public Bitmap getBlurBitmap(Bitmap bitmap) {
final int w = bitmap.getWidth();
final int h = bitmap.getHeight();
try {
EGLSurface eglSurface = createSurface(w, h);
if (eglSurface == null) {
Log.e(TAG, "Create surface error");
return bitmap;
}
OffScreenBlurRenderer renderer = getRenderer();
if (renderer != null) {
renderer.onDrawFrame(bitmap);
mEgl.eglSwapBuffers(mEGLDisplay, eglSurface);
} else {
Log.e(TAG, "Renderer is unavailable");
return bitmap;
}
convertToBitmap(bitmap);
} catch (Throwable t) {
Log.e(TAG, "Blur the bitmap error", t);
} finally {
unbindEglCurrent();
}
return bitmap;
}
public boolean eglCopyBuffers(EGLDisplay display, EGLSurface surface,
Object native_pixmap) {
begin("eglCopyBuffers");
arg("display", display);
arg("surface", surface);
arg("native_pixmap", native_pixmap);
end();
boolean result = mEgl10.eglCopyBuffers(display, surface, native_pixmap);
returns(result);
checkError();
return result;
}
public EGLSurface eglCreatePixmapSurface(EGLDisplay display,
EGLConfig config, Object native_pixmap, int[] attrib_list) {
begin("eglCreatePixmapSurface");
arg("display", display);
arg("config", config);
arg("native_pixmap", native_pixmap);
arg("attrib_list", attrib_list);
end();
EGLSurface result = mEgl10.eglCreatePixmapSurface(display, config,
native_pixmap, attrib_list);
returns(result);
checkError();
return result;
}
public EGLSurface eglCreateWindowSurface(EGLDisplay display,
EGLConfig config, Object native_window, int[] attrib_list) {
begin("eglCreateWindowSurface");
arg("display", display);
arg("config", config);
arg("native_window", native_window);
arg("attrib_list", attrib_list);
end();
EGLSurface result = mEgl10.eglCreateWindowSurface(display, config,
native_window, attrib_list);
returns(result);
checkError();
return result;
}
public EGLSurface eglGetCurrentSurface(int readdraw) {
begin("eglGetCurrentSurface");
arg("readdraw", readdraw);
end();
EGLSurface result = mEgl10.eglGetCurrentSurface(readdraw);
returns(result);
checkError();
return result;
}
public boolean eglSwapBuffers(EGLDisplay display, EGLSurface surface) {
begin("eglSwapBuffers");
arg("display", display);
arg("surface", surface);
end();
boolean result = mEgl10.eglSwapBuffers(display, surface);
returns(result);
checkError();
return result;
}
private void arg(String name, EGLSurface object) {
if (object == EGL10.EGL_NO_SURFACE) {
arg(name, "EGL10.EGL_NO_SURFACE");
} else {
arg(name, toString(object));
}
}
private final int swap(final EGLSurface surface) {
// if (DEBUG) Log.v(TAG, "swap:");
if (!mEgl.eglSwapBuffers(mEglDisplay, surface)) {
final int err = mEgl.eglGetError();
// if (DEBUG) Log.w(TAG, "swap:err=" + err);
return err;
}
return EGL10.EGL_SUCCESS;
}
private final int getSurfaceHeight(final EGLSurface surface) {
final int[] value = new int[1];
final boolean ret = mEgl.eglQuerySurface(mEglDisplay,
surface, EGL10.EGL_HEIGHT, value);
if (!ret) value[0] = 0;
return value[0];
}
public EGLSurface eglCreatePbufferSurface(EGLDisplay display,
EGLConfig config, int[] attrib_list) {
begin("eglCreatePbufferSurface");
arg("display", display);
arg("config", config);
arg("attrib_list", attrib_list);
end();
EGLSurface result = mEgl10.eglCreatePbufferSurface(display, config,
attrib_list);
returns(result);
checkError();
return result;
}
public EGLSurface eglCreatePixmapSurface(EGLDisplay display,
EGLConfig config, Object native_pixmap, int[] attrib_list) {
begin("eglCreatePixmapSurface");
arg("display", display);
arg("config", config);
arg("native_pixmap", native_pixmap);
arg("attrib_list", attrib_list);
end();
EGLSurface result = mEgl10.eglCreatePixmapSurface(display, config,
native_pixmap, attrib_list);
returns(result);
checkError();
return result;
}
public EGLSurface eglCreateWindowSurface(EGLDisplay display,
EGLConfig config, Object native_window, int[] attrib_list) {
begin("eglCreateWindowSurface");
arg("display", display);
arg("config", config);
arg("native_window", native_window);
arg("attrib_list", attrib_list);
end();
EGLSurface result = mEgl10.eglCreateWindowSurface(display, config,
native_window, attrib_list);
returns(result);
checkError();
return result;
}
public boolean eglDestroySurface(EGLDisplay display, EGLSurface surface) {
begin("eglDestroySurface");
arg("display", display);
arg("surface", surface);
end();
boolean result = mEgl10.eglDestroySurface(display, surface);
returns(result);
checkError();
return result;
}
public EGLSurface eglGetCurrentSurface(int readdraw) {
begin("eglGetCurrentSurface");
arg("readdraw", readdraw);
end();
EGLSurface result = mEgl10.eglGetCurrentSurface(readdraw);
returns(result);
checkError();
return result;
}
public boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw,
EGLSurface read, EGLContext context) {
begin("eglMakeCurrent");
arg("display", display);
arg("draw", draw);
arg("read", read);
arg("context", context);
end();
boolean result = mEgl10.eglMakeCurrent(display, draw, read, context);
returns(result);
checkError();
return result;
}