Use TuXiang library
Make GLRootView extends com.hippo.tuxiang.GLSurfaceView
This commit is contained in:
1 parent
2a324c4d89
commit
d4d4ba8c75
4 files changed
+5
-1969
No files matched your search
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.gl.view;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGL11;
|
||||
|
||||
final class EGLError {
|
||||
private EGLError() {}
|
||||
|
||||
private static String getHex(int value) {
|
||||
return "0x" + Integer.toHexString(value);
|
||||
}
|
||||
|
||||
public static String getErrorString(int error) {
|
||||
switch (error) {
|
||||
case EGL10.EGL_SUCCESS:
|
||||
return "EGL_SUCCESS";
|
||||
case EGL10.EGL_NOT_INITIALIZED:
|
||||
return "EGL_NOT_INITIALIZED";
|
||||
case EGL10.EGL_BAD_ACCESS:
|
||||
return "EGL_BAD_ACCESS";
|
||||
case EGL10.EGL_BAD_ALLOC:
|
||||
return "EGL_BAD_ALLOC";
|
||||
case EGL10.EGL_BAD_ATTRIBUTE:
|
||||
return "EGL_BAD_ATTRIBUTE";
|
||||
case EGL10.EGL_BAD_CONFIG:
|
||||
return "EGL_BAD_CONFIG";
|
||||
case EGL10.EGL_BAD_CONTEXT:
|
||||
return "EGL_BAD_CONTEXT";
|
||||
case EGL10.EGL_BAD_CURRENT_SURFACE:
|
||||
return "EGL_BAD_CURRENT_SURFACE";
|
||||
case EGL10.EGL_BAD_DISPLAY:
|
||||
return "EGL_BAD_DISPLAY";
|
||||
case EGL10.EGL_BAD_MATCH:
|
||||
return "EGL_BAD_MATCH";
|
||||
case EGL10.EGL_BAD_NATIVE_PIXMAP:
|
||||
return "EGL_BAD_NATIVE_PIXMAP";
|
||||
case EGL10.EGL_BAD_NATIVE_WINDOW:
|
||||
return "EGL_BAD_NATIVE_WINDOW";
|
||||
case EGL10.EGL_BAD_PARAMETER:
|
||||
return "EGL_BAD_PARAMETER";
|
||||
case EGL10.EGL_BAD_SURFACE:
|
||||
return "EGL_BAD_SURFACE";
|
||||
case EGL11.EGL_CONTEXT_LOST:
|
||||
return "EGL_CONTEXT_LOST";
|
||||
default:
|
||||
return getHex(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,9 @@ import com.hippo.gl.glrenderer.UploadedTexture;
|
||||
import com.hippo.gl.util.ApiHelper;
|
||||
import com.hippo.gl.util.GalleryUtils;
|
||||
import com.hippo.gl.util.MotionEventHelper;
|
||||
import com.hippo.tuxiang.BestConfigChooser;
|
||||
import com.hippo.tuxiang.GLSurfaceView;
|
||||
import com.hippo.tuxiang.Renderer;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
@@ -46,9 +49,7 @@ import java.util.ArrayList;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
import javax.microedition.khronos.opengles.GL11;
|
||||
|
||||
@@ -62,7 +63,7 @@ import javax.microedition.khronos.opengles.GL11;
|
||||
// (2) The public methods of CameraHeadUpDisplay
|
||||
// (3) The overridden methods in GLRootView.
|
||||
public class GLRootView extends GLSurfaceView
|
||||
implements GLSurfaceView.Renderer, GLRoot {
|
||||
implements Renderer, GLRoot {
|
||||
private static final String TAG = "GLRootView";
|
||||
|
||||
private static final boolean DEBUG_FPS = false;
|
||||
@@ -630,111 +631,4 @@ public class GLRootView extends GLSurfaceView
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class BaseConfigChooser implements EGLConfigChooser {
|
||||
|
||||
public BaseConfigChooser(int[] configSpec) {
|
||||
mConfigSpec = filterConfigSpec(configSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
|
||||
int[] num_config = new int[1];
|
||||
if (!egl.eglChooseConfig(display, mConfigSpec, null, 0,
|
||||
num_config)) {
|
||||
throw new IllegalArgumentException("eglChooseConfig failed");
|
||||
}
|
||||
|
||||
int numConfigs = num_config[0];
|
||||
|
||||
if (numConfigs <= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"No configs match configSpec");
|
||||
}
|
||||
|
||||
EGLConfig[] configs = new EGLConfig[numConfigs];
|
||||
if (!egl.eglChooseConfig(display, mConfigSpec, configs, numConfigs,
|
||||
num_config)) {
|
||||
throw new IllegalArgumentException("eglChooseConfig#2 failed");
|
||||
}
|
||||
EGLConfig config = chooseConfig(egl, display, configs);
|
||||
if (config == null) {
|
||||
throw new IllegalArgumentException("No config chosen");
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
abstract EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
|
||||
EGLConfig[] configs);
|
||||
|
||||
protected int[] mConfigSpec;
|
||||
|
||||
private int[] filterConfigSpec(int[] configSpec) {
|
||||
/* We know none of the subclasses define EGL_RENDERABLE_TYPE.
|
||||
* And we know the configSpec is well formed.
|
||||
*/
|
||||
int len = configSpec.length;
|
||||
int[] newConfigSpec = new int[len + 2];
|
||||
System.arraycopy(configSpec, 0, newConfigSpec, 0, len-1);
|
||||
newConfigSpec[len-1] = EGL10.EGL_RENDERABLE_TYPE;
|
||||
newConfigSpec[len] = 4; // EGL14.EGL_OPENGL_ES2_BIT; /* EGL_OPENGL_ES2_BIT */
|
||||
newConfigSpec[len+1] = EGL10.EGL_NONE;
|
||||
return newConfigSpec;
|
||||
}
|
||||
}
|
||||
|
||||
private static class BestConfigChooser extends BaseConfigChooser {
|
||||
|
||||
private final int[] mValue = new int[1];
|
||||
|
||||
public BestConfigChooser() {
|
||||
super(new int[] {
|
||||
EGL10.EGL_DEPTH_SIZE, 0,
|
||||
EGL10.EGL_STENCIL_SIZE, 0,
|
||||
EGL10.EGL_NONE});
|
||||
}
|
||||
|
||||
@Override
|
||||
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
|
||||
EGLConfig[] configs) {
|
||||
// Use score to avoid "No config chosen"
|
||||
int configIndex = 0;
|
||||
int maxScore = 0;
|
||||
|
||||
for (int i = 0, n = configs.length; i < n; i++) {
|
||||
EGLConfig config = configs[i];
|
||||
int redSize = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_RED_SIZE, 0);
|
||||
int greenSize = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_GREEN_SIZE, 0);
|
||||
int blueSize = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_BLUE_SIZE, 0);
|
||||
int alphaSize = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_ALPHA_SIZE, 0);
|
||||
int sampleBuffers = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_SAMPLE_BUFFERS, 0);
|
||||
int samples = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_SAMPLES, 0);
|
||||
|
||||
int score = redSize + greenSize + blueSize + alphaSize +
|
||||
sampleBuffers + samples;
|
||||
|
||||
if (score > maxScore) {
|
||||
maxScore = score;
|
||||
configIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
return configs[configIndex];
|
||||
}
|
||||
|
||||
private int findConfigAttrib(EGL10 egl, EGLDisplay display,
|
||||
EGLConfig config, int attribute, int defaultValue) {
|
||||
|
||||
if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) {
|
||||
return mValue[0];
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user