Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: platform_tools/android/app/src/com/skia/SkiaSampleView.java

Issue 60273006: Support MSAA4 and (non-ES) OpenGL in Android SampleApp (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase now that api level changes are merged Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « platform_tools/android/app/src/com/skia/SkiaSampleRenderer.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 package com.skia; 8 package com.skia;
9 9
10 import javax.microedition.khronos.egl.EGL10;
11 import javax.microedition.khronos.egl.EGLConfig;
12 import javax.microedition.khronos.egl.EGLDisplay;
13 import javax.microedition.khronos.opengles.GL10;
14
10 import android.content.Context; 15 import android.content.Context;
16 import android.opengl.EGL14;
11 import android.opengl.GLSurfaceView; 17 import android.opengl.GLSurfaceView;
18 import android.os.Build;
12 import android.view.MotionEvent; 19 import android.view.MotionEvent;
13 20
14 public class SkiaSampleView extends GLSurfaceView { 21 public class SkiaSampleView extends GLSurfaceView {
15 22
16 private final SkiaSampleRenderer mSampleRenderer; 23 private final SkiaSampleRenderer mSampleRenderer;
24 private boolean mRequestedOpenGLAPI; // true == use (desktop) OpenGL. false == use OpenGL ES.
25 private int mRequestedMSAASampleCount;
17 26
18 public SkiaSampleView(Context ctx) { 27 public SkiaSampleView(Context ctx, boolean useOpenGL, int msaaSampleCount) {
19 super(ctx); 28 super(ctx);
20 29
21 mSampleRenderer = new SkiaSampleRenderer(this); 30 mSampleRenderer = new SkiaSampleRenderer(this);
31 mRequestedMSAASampleCount = msaaSampleCount;
22 32
23 setEGLContextClientVersion(2); 33 setEGLContextClientVersion(2);
24 setEGLConfigChooser(8,8,8,8,0,8); 34 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
35 setEGLConfigChooser(8, 8, 8, 8, 0, 8);
36 } else {
37 mRequestedOpenGLAPI = useOpenGL;
38 setEGLConfigChooser(new SampleViewEGLConfigChooser());
39 }
25 setRenderer(mSampleRenderer); 40 setRenderer(mSampleRenderer);
26 setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); 41 setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
27 } 42 }
28 43
29 @Override 44 @Override
30 public boolean onTouchEvent(MotionEvent event) { 45 public boolean onTouchEvent(MotionEvent event) {
31 int count = event.getPointerCount(); 46 int count = event.getPointerCount();
32 for (int i = 0; i < count; i++) { 47 for (int i = 0; i < count; i++) {
33 final float x = event.getX(i); 48 final float x = event.getX(i);
34 final float y = event.getY(i); 49 final float y = event.getY(i);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 170 }
156 171
157 public void saveToPDF() { 172 public void saveToPDF() {
158 queueEvent(new Runnable() { 173 queueEvent(new Runnable() {
159 @Override 174 @Override
160 public void run() { 175 public void run() {
161 mSampleRenderer.saveToPDF(); 176 mSampleRenderer.saveToPDF();
162 } 177 }
163 }); 178 });
164 } 179 }
180
181 public boolean getUsesOpenGLAPI() {
182 return mRequestedOpenGLAPI;
183 }
184
185 public int getMSAASampleCount() {
186 return mSampleRenderer.getMSAASampleCount();
187 }
188
189 private class SampleViewEGLConfigChooser implements GLSurfaceView.EGLConfigC hooser {
190 private int[] mValue;
191
192 @Override
193 public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
194 mValue = new int[1];
195
196 int glAPIToTry;
197
198 if (mRequestedOpenGLAPI) {
199 glAPIToTry = EGL14.EGL_OPENGL_API;
200 } else {
201 glAPIToTry = EGL14.EGL_OPENGL_ES_API;
202 }
203
204 int numConfigs = 0;
205 int[] configSpec = null;
206
207 do {
208 EGL14.eglBindAPI(glAPIToTry);
209
210 int renderableType;
211 if (glAPIToTry == EGL14.EGL_OPENGL_API) {
212 renderableType = EGL14.EGL_OPENGL_ES2_BIT;
213
214 // If this API does not work, try ES next.
215 glAPIToTry = EGL14.EGL_OPENGL_ES_API;
216 } else {
217 renderableType = EGL14.EGL_OPENGL_BIT;
218 }
219
220
221 if (mRequestedMSAASampleCount > 0) {
222 configSpec = new int[] {
223 EGL10.EGL_RED_SIZE, 8,
224 EGL10.EGL_GREEN_SIZE, 8,
225 EGL10.EGL_BLUE_SIZE, 8,
226 EGL10.EGL_ALPHA_SIZE, 8,
227 EGL10.EGL_DEPTH_SIZE, 0,
228 EGL10.EGL_STENCIL_SIZE, 8,
229 EGL10.EGL_RENDERABLE_TYPE, renderableType,
230 EGL10.EGL_SAMPLE_BUFFERS, 1,
231 EGL10.EGL_SAMPLES, mRequestedMSAASampleCount,
232 EGL10.EGL_NONE
233 };
234
235 if (!egl.eglChooseConfig(display, configSpec, null, 0, mValu e)) {
236 throw new IllegalArgumentException("Could not get MSAA c ontext count");
237 }
238
239 numConfigs = mValue[0];
240 }
241
242 if (numConfigs <= 0) {
243 // Try without multisampling.
244 configSpec = new int[] {
245 EGL10.EGL_RED_SIZE, 8,
246 EGL10.EGL_GREEN_SIZE, 8,
247 EGL10.EGL_BLUE_SIZE, 8,
248 EGL10.EGL_ALPHA_SIZE, 8,
249 EGL10.EGL_DEPTH_SIZE, 0,
250 EGL10.EGL_STENCIL_SIZE, 8,
251 EGL10.EGL_RENDERABLE_TYPE, renderableType,
252 EGL10.EGL_NONE
253 };
254
255 if (!egl.eglChooseConfig(display, configSpec, null, 0, mValu e)) {
256 throw new IllegalArgumentException("Could not get non-MS AA context count");
257 }
258 numConfigs = mValue[0];
259 }
260
261 } while (glAPIToTry != EGL14.EGL_OPENGL_ES_API && numConfigs == 0);
262
263 if (numConfigs <= 0) {
264 throw new IllegalArgumentException("No configs match configSpec" );
265 }
266
267 // Get all matching configurations.
268 EGLConfig[] configs = new EGLConfig[numConfigs];
269 if (!egl.eglChooseConfig(display, configSpec, configs, numConfigs, m Value)) {
270 throw new IllegalArgumentException("Could not get config data");
271 }
272
273 for (int i = 0; i < configs.length; ++i) {
274 EGLConfig config = configs[i];
275 if (findConfigAttrib(egl, display, config , EGL10.EGL_RED_SIZE, 0) == 8 &&
276 findConfigAttrib(egl, display, config, EGL10.EGL_BLUE_SI ZE, 0) == 8 &&
277 findConfigAttrib(egl, display, config, EGL10.EGL_GREEN_S IZE, 0) == 8 &&
278 findConfigAttrib(egl, display, config, EGL10.EGL_ALPHA_S IZE, 0) == 8 &&
279 findConfigAttrib(egl, display, config, EGL10.EGL_STENCIL _SIZE, 0) == 8) {
280 return config;
281 }
282 }
283
284 throw new IllegalArgumentException("Could not find suitable EGL conf ig");
285 }
286
287 private int findConfigAttrib(EGL10 egl, EGLDisplay display,
288 EGLConfig config, int attribute, int defaultValue) {
289 if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) {
290 return mValue[0];
291 }
292 return defaultValue;
293 }
294
295 }
165 } 296 }
OLDNEW
« no previous file with comments | « platform_tools/android/app/src/com/skia/SkiaSampleRenderer.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698