| OLD | NEW |
| 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 android.opengl.GLSurfaceView; | 10 import android.opengl.GLSurfaceView; |
| 11 import android.os.Handler; | 11 import android.os.Handler; |
| 12 import android.util.Log; |
| 12 | 13 |
| 13 import javax.microedition.khronos.egl.EGLConfig; | 14 import javax.microedition.khronos.egl.EGLConfig; |
| 14 import javax.microedition.khronos.opengles.GL10; | 15 import javax.microedition.khronos.opengles.GL10; |
| 16 import javax.microedition.khronos.opengles.GL11; |
| 15 | 17 |
| 16 public class SkiaSampleRenderer implements GLSurfaceView.Renderer { | 18 public class SkiaSampleRenderer implements GLSurfaceView.Renderer { |
| 17 | 19 |
| 18 private final SkiaSampleView mSampleView; | 20 private final SkiaSampleView mSampleView; |
| 19 private Handler mHandler = new Handler(); | 21 private Handler mHandler = new Handler(); |
| 22 private int mMSAASampleCount; |
| 20 | 23 |
| 21 SkiaSampleRenderer(SkiaSampleView view) { | 24 SkiaSampleRenderer(SkiaSampleView view) { |
| 22 mSampleView = view; | 25 mSampleView = view; |
| 23 } | 26 } |
| 24 | 27 |
| 25 @Override | 28 @Override |
| 26 public void onDrawFrame(GL10 gl) { | 29 public void onDrawFrame(GL10 gl) { |
| 27 draw(); | 30 draw(); |
| 28 } | 31 } |
| 29 | 32 |
| 30 @Override | 33 @Override |
| 31 public void onSurfaceChanged(GL10 gl, int width, int height) { | 34 public void onSurfaceChanged(GL10 gl, int width, int height) { |
| 32 updateSize(width, height); | 35 updateSize(width, height); |
| 33 } | 36 } |
| 34 | 37 |
| 35 @Override | 38 @Override |
| 36 public void onSurfaceCreated(GL10 gl, EGLConfig config) { | 39 public void onSurfaceCreated(GL10 gl, EGLConfig config) { |
| 40 if (gl instanceof GL11) { |
| 41 int value[] = new int[1]; |
| 42 ((GL11) gl).glGetIntegerv(GL11.GL_SAMPLES, value, 0); |
| 43 if (value[0] == 1) { |
| 44 mMSAASampleCount = 0; |
| 45 } else { |
| 46 mMSAASampleCount = value[0]; |
| 47 } |
| 48 } |
| 49 |
| 37 gl.glClearStencil(0); | 50 gl.glClearStencil(0); |
| 38 gl.glClear(GL10.GL_STENCIL_BUFFER_BIT); | 51 gl.glClear(GL10.GL_STENCIL_BUFFER_BIT); |
| 39 init((SkiaSampleActivity)mSampleView.getContext()); | 52 init((SkiaSampleActivity)mSampleView.getContext(), mMSAASampleCount); |
| 53 } |
| 54 |
| 55 // Called by JNI and the view. |
| 56 synchronized public int getMSAASampleCount() { |
| 57 return mMSAASampleCount; |
| 40 } | 58 } |
| 41 | 59 |
| 42 // Called by JNI | 60 // Called by JNI |
| 43 private void startTimer(int ms) { | 61 private void startTimer(int ms) { |
| 44 // After the delay, queue an event to the Renderer's thread | 62 // After the delay, queue an event to the Renderer's thread |
| 45 // to handle the event on the timer queue | 63 // to handle the event on the timer queue |
| 46 mHandler.postDelayed(new Runnable() { | 64 mHandler.postDelayed(new Runnable() { |
| 47 @Override | 65 @Override |
| 48 public void run() { | 66 public void run() { |
| 49 mSampleView.queueEvent(new Runnable() { | 67 mSampleView.queueEvent(new Runnable() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 64 processSkEvent(); | 82 processSkEvent(); |
| 65 } | 83 } |
| 66 }); | 84 }); |
| 67 } | 85 } |
| 68 | 86 |
| 69 // Called by JNI | 87 // Called by JNI |
| 70 private void requestRender() { | 88 private void requestRender() { |
| 71 mSampleView.requestRender(); | 89 mSampleView.requestRender(); |
| 72 } | 90 } |
| 73 | 91 |
| 74 native void init(SkiaSampleActivity activity); | 92 native void init(SkiaSampleActivity activity, int msaaSampleCount); |
| 75 native void term(); | 93 native void term(); |
| 76 native void draw(); | 94 native void draw(); |
| 77 native void updateSize(int w, int h); | 95 native void updateSize(int w, int h); |
| 78 native void handleClick(int owner, float x, float y, int state); | 96 native void handleClick(int owner, float x, float y, int state); |
| 79 native void showOverview(); | 97 native void showOverview(); |
| 80 native void nextSample(); | 98 native void nextSample(); |
| 81 native void previousSample(); | 99 native void previousSample(); |
| 82 native void goToSample(int position); | 100 native void goToSample(int position); |
| 83 native void toggleRenderingMode(); | 101 native void toggleRenderingMode(); |
| 84 native void toggleSlideshow(); | 102 native void toggleSlideshow(); |
| 85 native void toggleFPS(); | 103 native void toggleFPS(); |
| 86 native void toggleTiling(); | 104 native void toggleTiling(); |
| 87 native void toggleBBox(); | 105 native void toggleBBox(); |
| 88 native void processSkEvent(); | 106 native void processSkEvent(); |
| 89 native void serviceQueueTimer(); | 107 native void serviceQueueTimer(); |
| 90 native void saveToPDF(); | 108 native void saveToPDF(); |
| 91 native void postInval(); | 109 native void postInval(); |
| 92 } | 110 } |
| OLD | NEW |