From patchwork Tue May 15 13:12:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 8649 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 22A6E23E37 for ; Tue, 15 May 2012 13:12:16 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9EA9AA182AC for ; Tue, 15 May 2012 13:12:15 +0000 (UTC) Received: by ggnf1 with SMTP id f1so4698331ggn.11 for ; Tue, 15 May 2012 06:12:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=+hL44oqGpEI+wtrb+UxOgm96ChYBweyNulgSUOCvGSg=; b=UggTWNBUZ6+9sPL2sQgwcnUe6a8thT5LEa3k4Q7FIUf7j8itXtqxSEPXSo8emwQpnN t7d6kbc3sP9ytMC7D0fLNJ0rxG8tETy5Qc3PhxqblTF9AlgOITmRekbLARu95rRI5UZT 6JqPlWKWQJQuGlZV0ReO5xFfzq4vJ/ZZsJduCp3Bj5p/1Ay9u4hc2eAwD+kVtiRWpbkb gAeAjaO75PY3Kx//riEoaAlsMpguRkNuctp9yUR1vGdGZMoWlgXEMWYXXEzme4pNi9f0 BpqhZ6p0ubqQO+kzpmo03L2n2jGESQNd87RFQ41TGgMSr7RFF8sXAh3+Pcrh/s/3rYbl 3haw== Received: by 10.50.203.39 with SMTP id kn7mr6870010igc.53.1337087534887; Tue, 15 May 2012 06:12:14 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp419870ibd; Tue, 15 May 2012 06:12:13 -0700 (PDT) Received: by 10.216.142.194 with SMTP id i44mr981233wej.88.1337087533355; Tue, 15 May 2012 06:12:13 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id dx7si12240816wib.13.2012.05.15.06.12.12 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 May 2012 06:12:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1SUHXw-0007KH-EX for ; Tue, 15 May 2012 13:12:12 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 47E30E013D for ; Tue, 15 May 2012 13:12:12 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 209 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 209: Android: Allow user configuration of visual used for rendering. Message-Id: <20120515131212.4169.50641.launchpad@ackee.canonical.com> Date: Tue, 15 May 2012 13:12:12 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15238"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: f30659f1703a65233a29d8815ef54f554f2d01ac X-Gm-Message-State: ALoCoQk4ap0Pe9f20n9d8RTfKjEm2HEumF5s+YJuZLN8yf/F+OPgR/wsdjxnjFd6gqOZf8gNghBF Merge authors: Alexandros Frantzis (afrantzis) ------------------------------------------------------------ revno: 209 [merge] committer: Alexandros Frantzis branch nick: trunk timestamp: Tue 2012-05-15 16:09:27 +0300 message: Android: Allow user configuration of visual used for rendering. modified: android/src/org/linaro/glmark2/Glmark2SurfaceView.java src/android.cpp src/canvas-android.cpp --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === modified file 'android/src/org/linaro/glmark2/Glmark2SurfaceView.java' --- android/src/org/linaro/glmark2/Glmark2SurfaceView.java 2012-02-14 15:29:48 +0000 +++ android/src/org/linaro/glmark2/Glmark2SurfaceView.java 2012-05-15 12:39:38 +0000 @@ -12,6 +12,29 @@ import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; +/** + * Class that holds a configuration of a GL visual. + */ +class GLVisualConfig { + public GLVisualConfig() {} + public GLVisualConfig(int r, int g, int b, int a, int d, int buf) { + red = r; + green = g; + blue = b; + alpha = a; + depth = d; + buffer = buf; + } + + public int red; + public int green; + public int blue; + public int alpha; + public int depth; + public int buffer; +} + + class Glmark2SurfaceView extends GLSurfaceView { public static final String LOG_TAG = "glmark2"; @@ -22,14 +45,55 @@ setEGLContextClientVersion(2); - // Uncomment the commands below to get an RGBA8888 surface and config. - //this.getHolder().setFormat(PixelFormat.TRANSLUCENT); - //setEGLConfigChooser(new Glmark2ConfigChooser(8, 8, 8, 8, 16, 0)); - setEGLConfigChooser(new Glmark2ConfigChooser(5, 6, 5, 0, 16, 0)); + setEGLConfigChooser(getConfigChooser()); setRenderer(new Glmark2Renderer(this)); } + private EGLConfigChooser getConfigChooser() { + String args = mActivity.getIntent().getStringExtra("args"); + + String[] argv = args.split(" "); + + /* Find the visual-config option argument */ + String configString = new String(); + boolean keepNext = false; + for (String arg : argv) { + if (keepNext) { + configString = arg; + break; + } + + if (arg.equals("--visual-config")) + keepNext = true; + } + + /* Parse the config string parameters */ + String[] configParams = configString.split(":"); + GLVisualConfig targetConfig = new GLVisualConfig(5, 6, 5, 0, 16, 1); + + for (String param : configParams) { + String[] paramKeyValue = param.split("="); + if (paramKeyValue.length < 2) + continue; + + if (paramKeyValue[0].equals("red") || paramKeyValue[0].equals("r")) + targetConfig.red = Integer.parseInt(paramKeyValue[1]); + else if (paramKeyValue[0].equals("green") || paramKeyValue[0].equals("g")) + targetConfig.green = Integer.parseInt(paramKeyValue[1]); + else if (paramKeyValue[0].equals("blue") || paramKeyValue[0].equals("b")) + targetConfig.blue = Integer.parseInt(paramKeyValue[1]); + else if (paramKeyValue[0].equals("alpha") || paramKeyValue[0].equals("a")) + targetConfig.alpha = Integer.parseInt(paramKeyValue[1]); + else if (paramKeyValue[0].equals("depth") || paramKeyValue[0].equals("d")) + targetConfig.depth = Integer.parseInt(paramKeyValue[1]); + else if (paramKeyValue[0].equals("buffer") || paramKeyValue[0].equals("buf")) + targetConfig.buffer = Integer.parseInt(paramKeyValue[1]); + } + + return new Glmark2ConfigChooser(targetConfig); + } + /** * EGLConfigChooser that quits with an error dialog when a suitable config * cannot be found. @@ -37,24 +101,19 @@ private class Glmark2ConfigChooser implements EGLConfigChooser { private int[] mAttribList; - public Glmark2ConfigChooser(int redSize, int greenSize, int blueSize, - int alphaSize, int depthSize, int stencilSize) + public Glmark2ConfigChooser(GLVisualConfig targetConfig) { mAttribList = new int[] { - EGL10.EGL_RED_SIZE, redSize, - EGL10.EGL_GREEN_SIZE, greenSize, - EGL10.EGL_BLUE_SIZE, blueSize, - EGL10.EGL_ALPHA_SIZE, alphaSize, - EGL10.EGL_DEPTH_SIZE, depthSize, - EGL10.EGL_STENCIL_SIZE, stencilSize, + EGL10.EGL_RED_SIZE, targetConfig.red, + EGL10.EGL_GREEN_SIZE, targetConfig.green, + EGL10.EGL_BLUE_SIZE, targetConfig.blue, + EGL10.EGL_ALPHA_SIZE, targetConfig.alpha, + EGL10.EGL_DEPTH_SIZE, targetConfig.depth, + EGL10.EGL_BUFFER_SIZE, targetConfig.buffer, EGL10.EGL_RENDERABLE_TYPE, 4, /* 4 = EGL_OPENGL_ES2_BIT */ EGL10.EGL_NONE }; - mRedSize = redSize; - mGreenSize = greenSize; - mBlueSize = blueSize; - mAlphaSize = alphaSize; - mDepthSize = depthSize; - mStencilSize = stencilSize; + + mTargetConfig = targetConfig; } @Override @@ -101,32 +160,34 @@ throw new IllegalArgumentException("eglChooseConfig#2 failed"); } - /* - * Try to find a config that matches exactly the RGBA size - * specified by the user and is >= for depth and stencil. - */ + /* Find the best matching config. */ + int bestScore = Integer.MIN_VALUE; + EGLConfig bestConfig = configs[0]; + for (EGLConfig config : configs) { - int d = findConfigAttrib(egl, display, config, - EGL10.EGL_DEPTH_SIZE, 0); - int s = findConfigAttrib(egl, display, config, - EGL10.EGL_STENCIL_SIZE, 0); - int r = findConfigAttrib(egl, display, config, - EGL10.EGL_RED_SIZE, 0); - int g = findConfigAttrib(egl, display, config, - EGL10.EGL_GREEN_SIZE, 0); - int b = findConfigAttrib(egl, display, config, - EGL10.EGL_BLUE_SIZE, 0); - int a = findConfigAttrib(egl, display, config, - EGL10.EGL_ALPHA_SIZE, 0); - if (r == mRedSize && g == mGreenSize && - b == mBlueSize && a == mAlphaSize && - d >= mDepthSize && s >= mStencilSize) - { - return config; + GLVisualConfig vc = new GLVisualConfig(); + vc.red = findConfigAttrib(egl, display, config, + EGL10.EGL_RED_SIZE, 0); + vc.green = findConfigAttrib(egl, display, config, + EGL10.EGL_GREEN_SIZE, 0); + vc.blue = findConfigAttrib(egl, display, config, + EGL10.EGL_BLUE_SIZE, 0); + vc.alpha = findConfigAttrib(egl, display, config, + EGL10.EGL_ALPHA_SIZE, 0); + vc.depth = findConfigAttrib(egl, display, config, + EGL10.EGL_DEPTH_SIZE, 0); + vc.buffer = findConfigAttrib(egl, display, config, + EGL10.EGL_BUFFER_SIZE, 0); + + int score = Glmark2Native.scoreConfig(vc, mTargetConfig); + + if (score > bestScore) { + bestScore = score; + bestConfig = config; } } - throw new IllegalArgumentException("No configs match exactly"); + return bestConfig; } private int findConfigAttrib(EGL10 egl, EGLDisplay display, EGLConfig config, @@ -137,12 +198,7 @@ return value[0]; } - protected int mRedSize; - protected int mGreenSize; - protected int mBlueSize; - protected int mAlphaSize; - protected int mDepthSize; - protected int mStencilSize; + protected GLVisualConfig mTargetConfig; } public Activity getActivity() { @@ -159,22 +215,26 @@ } public void onDrawFrame(GL10 gl) { - if (!nativeRender()) + if (!Glmark2Native.render()) mView.getActivity().finish(); } public void onSurfaceChanged(GL10 gl, int width, int height) { - nativeResize(width, height); + Glmark2Native.resize(width, height); } public void onSurfaceCreated(GL10 gl, EGLConfig config) { String args = mView.getActivity().getIntent().getStringExtra("args"); - nativeInit(mView.getActivity().getAssets(), args); + Glmark2Native.init(mView.getActivity().getAssets(), args); } private Glmark2SurfaceView mView; - private static native void nativeInit(AssetManager assetManager, String args); - private static native void nativeResize(int w, int h); - private static native boolean nativeRender(); - private static native void nativeDone(); +} + +class Glmark2Native { + public static native void init(AssetManager assetManager, String args); + public static native void resize(int w, int h); + public static native boolean render(); + public static native void done(); + public static native int scoreConfig(GLVisualConfig vc, GLVisualConfig target); } === modified file 'src/android.cpp' --- src/android.cpp 2012-05-08 13:53:58 +0000 +++ src/android.cpp 2012-05-15 12:28:51 +0000 @@ -135,10 +135,43 @@ delete[] argv; } +/** + * Converts a GLVisualConfig Java object to a GLVisualConfig C++ object. + * + * @param env the JNIEnv + * @param jvc the Java VisualConfig object to convert + * @param vc the C++ VisualConfig object to fill + */ +static void +gl_visual_config_from_jobject(JNIEnv *env, jobject jvc, GLVisualConfig &vc) +{ + jclass cls = env->GetObjectClass(jvc); + jfieldID fid; + + fid = env->GetFieldID(cls, "red", "I"); + vc.red = env->GetIntField(jvc, fid); + + fid = env->GetFieldID(cls, "green", "I"); + vc.green = env->GetIntField(jvc, fid); + + fid = env->GetFieldID(cls, "blue", "I"); + vc.blue = env->GetIntField(jvc, fid); + + fid = env->GetFieldID(cls, "alpha", "I"); + vc.alpha = env->GetIntField(jvc, fid); + + fid = env->GetFieldID(cls, "depth", "I"); + vc.depth = env->GetIntField(jvc, fid); + + fid = env->GetFieldID(cls, "buffer", "I"); + vc.buffer = env->GetIntField(jvc, fid); +} + + void -Java_org_linaro_glmark2_Glmark2Renderer_nativeInit(JNIEnv* env, jclass clazz, - jobject asset_manager, - jstring args) +Java_org_linaro_glmark2_native_init(JNIEnv* env, jclass clazz, + jobject asset_manager, + jstring args) { static_cast(clazz); static const std::string arguments_file("/data/glmark2/args"); @@ -202,10 +235,10 @@ } void -Java_org_linaro_glmark2_Glmark2Renderer_nativeResize(JNIEnv* env, - jclass clazz, - jint w, - jint h) +Java_org_linaro_glmark2_native_resize(JNIEnv* env, + jclass clazz, + jint w, + jint h) { static_cast(env); static_cast(clazz); @@ -215,7 +248,7 @@ } void -Java_org_linaro_glmark2_Glmark2Renderer_nativeDone(JNIEnv* env) +Java_org_linaro_glmark2_native_done(JNIEnv* env) { static_cast(env); @@ -225,7 +258,7 @@ } jboolean -Java_org_linaro_glmark2_Glmark2Renderer_nativeRender(JNIEnv* env) +Java_org_linaro_glmark2_native_render(JNIEnv* env) { static_cast(env); @@ -237,26 +270,46 @@ return true; } +jint +Java_org_linaro_glmark2_native_scoreConfig(JNIEnv* env, jclass clazz, + jobject jvc, jobject jtarget) +{ + static_cast(clazz); + + GLVisualConfig vc; + GLVisualConfig target; + + gl_visual_config_from_jobject(env, jvc, vc); + gl_visual_config_from_jobject(env, jtarget, target); + + return vc.match_score(target); +} + static JNINativeMethod glmark2_native_methods[] = { { - "nativeInit", + "init", "(Landroid/content/res/AssetManager;Ljava/lang/String;)V", - reinterpret_cast(Java_org_linaro_glmark2_Glmark2Renderer_nativeInit) + reinterpret_cast(Java_org_linaro_glmark2_native_init) }, { - "nativeResize", + "resize", "(II)V", - reinterpret_cast(Java_org_linaro_glmark2_Glmark2Renderer_nativeResize) + reinterpret_cast(Java_org_linaro_glmark2_native_resize) }, { - "nativeDone", + "done", "()V", - reinterpret_cast(Java_org_linaro_glmark2_Glmark2Renderer_nativeDone) + reinterpret_cast(Java_org_linaro_glmark2_native_done) }, { - "nativeRender", + "render", "()Z", - reinterpret_cast(Java_org_linaro_glmark2_Glmark2Renderer_nativeRender) + reinterpret_cast(Java_org_linaro_glmark2_native_render) + }, + { + "scoreConfig", + "(Lorg/linaro/glmark2/GLVisualConfig;Lorg/linaro/glmark2/GLVisualConfig;)I", + reinterpret_cast(Java_org_linaro_glmark2_native_scoreConfig) } }; @@ -283,7 +336,7 @@ static int register_natives(JNIEnv *env) { - const char* const class_path_name = "org/linaro/glmark2/Glmark2Renderer"; + const char* const class_path_name = "org/linaro/glmark2/Glmark2Native"; return register_native_methods(env, class_path_name, glmark2_native_methods, sizeof(glmark2_native_methods) / === modified file 'src/canvas-android.cpp' --- src/canvas-android.cpp 2011-10-28 10:51:19 +0000 +++ src/canvas-android.cpp 2012-05-15 12:33:41 +0000 @@ -36,9 +36,24 @@ bool CanvasAndroid::init() { + EGLint attribs[] = { + EGL_CONFIG_ID, 0, + EGL_NONE + }; + + /* Get the current EGL config */ + EGLDisplay egl_display(eglGetCurrentDisplay()); + EGLContext egl_context(eglGetCurrentContext()); + EGLConfig egl_config(0); + EGLint num_configs; + + eglQueryContext(egl_display, egl_context, EGL_CONFIG_ID, &(attribs[1])); + + eglChooseConfig(egl_display, attribs, &egl_config, 1, &num_configs); + resize(width_, height_); - if (!eglSwapInterval(eglGetCurrentDisplay(), 0)) + if (!eglSwapInterval(egl_display, 0)) Log::info("** Failed to set swap interval. Results may be bounded above by refresh rate.\n"); init_gl_extensions(); @@ -50,6 +65,27 @@ clear(); + if (Options::show_debug) { + int buf, red, green, blue, alpha, depth, id, native_id; + eglGetConfigAttrib(egl_display, egl_config, EGL_CONFIG_ID, &id); + eglGetConfigAttrib(egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &native_id); + eglGetConfigAttrib(egl_display, egl_config, EGL_BUFFER_SIZE, &buf); + eglGetConfigAttrib(egl_display, egl_config, EGL_RED_SIZE, &red); + eglGetConfigAttrib(egl_display, egl_config, EGL_GREEN_SIZE, &green); + eglGetConfigAttrib(egl_display, egl_config, EGL_BLUE_SIZE, &blue); + eglGetConfigAttrib(egl_display, egl_config, EGL_ALPHA_SIZE, &alpha); + eglGetConfigAttrib(egl_display, egl_config, EGL_DEPTH_SIZE, &depth); + Log::debug("EGL chosen config ID: 0x%x Native Visual ID: 0x%x\n" + " Buffer: %d bits\n" + " Red: %d bits\n" + " Green: %d bits\n" + " Blue: %d bits\n" + " Alpha: %d bits\n" + " Depth: %d bits\n", + id, native_id, + buf, red, green, blue, alpha, depth); + } + return true; }