Skip to content

Commit b2bf542

Browse files
committed
Revert changes to Grafika files
1 parent ff103a8 commit b2bf542

6 files changed

Lines changed: 116 additions & 117 deletions

File tree

android/sdl_android/src/androidTest/java/com/android/grafika/gles/OffscreenSurfaceTest.java

Lines changed: 83 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -18,89 +18,88 @@
1818
@RunWith(AndroidJUnit4.class)
1919
public class OffscreenSurfaceTest {
2020

21-
private final String TAG = OffscreenSurfaceTest.class.getSimpleName();
22-
private final int mWidth = 1280;
23-
private final int mHeight = 720;
24-
private final int mIterations = 100;
25-
26-
@Test
27-
public void testReadPixels() {
28-
EglCore eglCore = new EglCore(null, 0);
29-
OffscreenSurface offscreenSurface = new OffscreenSurface(eglCore, mWidth, mHeight);
30-
float time = runReadPixelsTest(offscreenSurface);
31-
Log.d(TAG, "runReadPixelsTest returns " + time + " msec");
32-
}
33-
34-
// HELPER test method
35-
36-
/**
37-
* Does a simple bit of rendering and then reads the pixels back.
38-
*
39-
* @return total time (msec order) spent on glReadPixels()
40-
*/
41-
private float runReadPixelsTest(OffscreenSurface eglSurface) {
42-
long totalTime = 0;
43-
44-
eglSurface.makeCurrent();
45-
46-
ByteBuffer pixelBuf = ByteBuffer.allocateDirect(mWidth * mHeight * 4);
47-
pixelBuf.order(ByteOrder.LITTLE_ENDIAN);
48-
49-
Log.d(TAG, "Running...");
50-
float colorMult = 1.0f / mIterations;
51-
for (int i = 0; i < mIterations; i++) {
52-
if ((i % (mIterations / 8)) == 0) {
53-
Log.d(TAG, "iteration " + i);
54-
}
55-
56-
// Clear the screen to a solid color, then add a rectangle. Change the color
57-
// each time.
58-
float r = i * colorMult;
59-
float g = 1.0f - r;
60-
float b = (r + g) / 2.0f;
61-
GLES20.glClearColor(r, g, b, 1.0f);
62-
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
63-
64-
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
65-
GLES20.glScissor(mWidth / 4, mHeight / 4, mWidth / 2, mHeight / 2);
66-
GLES20.glClearColor(b, g, r, 1.0f);
67-
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
68-
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
69-
70-
// Try to ensure that rendering has finished.
71-
GLES20.glFinish();
72-
GLES20.glReadPixels(0, 0, 1, 1,
73-
GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuf);
74-
75-
// Time individual extraction. Ideally we'd be timing a bunch of these calls
76-
// and measuring the aggregate time, but we want the isolated time, and if we
77-
// just read the same buffer repeatedly we might get some sort of cache effect.
78-
long startWhen = System.nanoTime();
79-
GLES20.glReadPixels(0, 0, mWidth, mHeight,
80-
GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuf);
81-
totalTime += System.nanoTime() - startWhen;
82-
}
83-
Log.d(TAG, "done");
84-
85-
// It's not the good idea to request external strage permission in unit test.
86-
boolean requireStoragePermission = false;
87-
if (requireStoragePermission) {
88-
long startWhen = System.nanoTime();
89-
File file = new File(Environment.getExternalStorageDirectory(),
90-
"test.png");
91-
try {
92-
eglSurface.saveFrame(file);
93-
} catch (IOException ioe) {
94-
throw new RuntimeException(ioe);
95-
}
96-
Log.d(TAG, "Saved frame in " + ((System.nanoTime() - startWhen) / 1000000) + "ms");
97-
assertTrue(file.exists());
98-
} else {
99-
// here' we can recognize Unit Test succeeded, but anyway checks to see totalTime and buffer capacity.
100-
assertTrue(pixelBuf.capacity() > 0 && totalTime > 0);
101-
}
102-
103-
return (float) totalTime / 1000000f;
104-
}
21+
private final String TAG = OffscreenSurfaceTest.class.getSimpleName();
22+
private final int mWidth = 1280;
23+
private final int mHeight = 720;
24+
private final int mIterations = 100;
25+
26+
@Test
27+
public void testReadPixels() {
28+
EglCore eglCore = new EglCore(null, 0);
29+
OffscreenSurface offscreenSurface = new OffscreenSurface(eglCore, mWidth, mHeight);
30+
float time = runReadPixelsTest(offscreenSurface);
31+
Log.d(TAG, "runReadPixelsTest returns " + time + " msec");
32+
}
33+
34+
// HELPER test method
35+
/**
36+
* Does a simple bit of rendering and then reads the pixels back.
37+
*
38+
* @return total time (msec order) spent on glReadPixels()
39+
*/
40+
private float runReadPixelsTest(OffscreenSurface eglSurface) {
41+
long totalTime = 0;
42+
43+
eglSurface.makeCurrent();
44+
45+
ByteBuffer pixelBuf = ByteBuffer.allocateDirect(mWidth * mHeight * 4);
46+
pixelBuf.order(ByteOrder.LITTLE_ENDIAN);
47+
48+
Log.d(TAG, "Running...");
49+
float colorMult = 1.0f / mIterations;
50+
for (int i = 0; i < mIterations; i++) {
51+
if ((i % (mIterations / 8)) == 0) {
52+
Log.d(TAG, "iteration " + i);
53+
}
54+
55+
// Clear the screen to a solid color, then add a rectangle. Change the color
56+
// each time.
57+
float r = i * colorMult;
58+
float g = 1.0f - r;
59+
float b = (r + g) / 2.0f;
60+
GLES20.glClearColor(r, g, b, 1.0f);
61+
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
62+
63+
GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
64+
GLES20.glScissor(mWidth / 4, mHeight / 4, mWidth / 2, mHeight / 2);
65+
GLES20.glClearColor(b, g, r, 1.0f);
66+
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
67+
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
68+
69+
// Try to ensure that rendering has finished.
70+
GLES20.glFinish();
71+
GLES20.glReadPixels(0, 0, 1, 1,
72+
GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuf);
73+
74+
// Time individual extraction. Ideally we'd be timing a bunch of these calls
75+
// and measuring the aggregate time, but we want the isolated time, and if we
76+
// just read the same buffer repeatedly we might get some sort of cache effect.
77+
long startWhen = System.nanoTime();
78+
GLES20.glReadPixels(0, 0, mWidth, mHeight,
79+
GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuf);
80+
totalTime += System.nanoTime() - startWhen;
81+
}
82+
Log.d(TAG, "done");
83+
84+
// It's not the good idea to request external strage permission in unit test.
85+
boolean requireStoragePermission = false;
86+
if (requireStoragePermission) {
87+
long startWhen = System.nanoTime();
88+
File file = new File(Environment.getExternalStorageDirectory(),
89+
"test.png");
90+
try {
91+
eglSurface.saveFrame(file);
92+
} catch (IOException ioe) {
93+
throw new RuntimeException(ioe);
94+
}
95+
Log.d(TAG, "Saved frame in " + ((System.nanoTime() - startWhen) / 1000000) + "ms");
96+
assertTrue(file.exists());
97+
} else {
98+
// here' we can recognize Unit Test succeeded, but anyway checks to see totalTime and buffer capacity.
99+
assertTrue(pixelBuf.capacity() > 0 && totalTime > 0);
100+
}
101+
102+
return (float)totalTime / 1000000f;
103+
}
105104

106105
}

android/sdl_android/src/main/java/com/android/grafika/gles/Drawable2d.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Drawable2d {
2828
* Simple equilateral triangle (1.0 per side). Centered on (0,0).
2929
*/
3030
private static final float TRIANGLE_COORDS[] = {
31-
0.0f, 0.577350269f, // 0 top
31+
0.0f, 0.577350269f, // 0 top
3232
-0.5f, -0.288675135f, // 1 bottom left
3333
0.5f, -0.288675135f // 2 bottom right
3434
};
@@ -51,8 +51,8 @@ public class Drawable2d {
5151
private static final float RECTANGLE_COORDS[] = {
5252
-0.5f, -0.5f, // 0 bottom left
5353
0.5f, -0.5f, // 1 bottom right
54-
-0.5f, 0.5f, // 2 top left
55-
0.5f, 0.5f, // 3 top right
54+
-0.5f, 0.5f, // 2 top left
55+
0.5f, 0.5f, // 3 top right
5656
};
5757
private static final float RECTANGLE_TEX_COORDS[] = {
5858
0.0f, 1.0f, // 0 bottom left
@@ -75,8 +75,8 @@ public class Drawable2d {
7575
private static final float FULL_RECTANGLE_COORDS[] = {
7676
-1.0f, -1.0f, // 0 bottom left
7777
1.0f, -1.0f, // 1 bottom right
78-
-1.0f, 1.0f, // 2 top left
79-
1.0f, 1.0f, // 3 top right
78+
-1.0f, 1.0f, // 2 top left
79+
1.0f, 1.0f, // 3 top right
8080
};
8181
private static final float FULL_RECTANGLE_TEX_COORDS[] = {
8282
0.0f, 0.0f, // 0 bottom left

android/sdl_android/src/main/java/com/android/grafika/gles/EglCore.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public EglCore(EGLContext sharedContext, int flags) {
133133
int[] values = new int[1];
134134
EGL14.eglQueryContext(mEGLDisplay, mEGLContext, EGL14.EGL_CONTEXT_CLIENT_VERSION,
135135
values, 0);
136-
Log.d(TAG, "EGLContext created, client version " + values[0]);
136+
Log.d(TAG,"EGLContext created, client version " + values[0]);
137137
}
138138

139139
/**
@@ -170,7 +170,7 @@ private EGLConfig getConfig(int flags, int version) {
170170
int[] numConfigs = new int[1];
171171
if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
172172
numConfigs, 0)) {
173-
Log.d(TAG, "unable to find RGB8888 / " + version + " EGLConfig");
173+
Log.d(TAG,"unable to find RGB8888 / " + version + " EGLConfig");
174174
return null;
175175
}
176176
return configs[0];
@@ -206,7 +206,7 @@ protected void finalize() throws Throwable {
206206
// the EGL state, so if a surface or context is still current on another
207207
// thread we can't fully release it here. Exceptions thrown from here
208208
// are quietly discarded. Complain in the log file.
209-
Log.e(TAG, "WARNING: EglCore was not explicitly released -- state may be leaked");
209+
Log.e(TAG,"WARNING: EglCore was not explicitly released -- state may be leaked");
210210
release();
211211
}
212212
} finally {
@@ -269,7 +269,7 @@ public EGLSurface createOffscreenSurface(int width, int height) {
269269
public void makeCurrent(EGLSurface eglSurface) {
270270
if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
271271
// called makeCurrent() before create?
272-
Log.d(TAG, "NOTE: makeCurrent w/o display");
272+
Log.d(TAG,"NOTE: makeCurrent w/o display");
273273
}
274274
if (!EGL14.eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext)) {
275275
throw new RuntimeException("eglMakeCurrent failed");
@@ -282,7 +282,7 @@ public void makeCurrent(EGLSurface eglSurface) {
282282
public void makeCurrent(EGLSurface drawSurface, EGLSurface readSurface) {
283283
if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
284284
// called makeCurrent() before create?
285-
Log.d(TAG, "NOTE: makeCurrent w/o display");
285+
Log.d(TAG,"NOTE: makeCurrent w/o display");
286286
}
287287
if (!EGL14.eglMakeCurrent(mEGLDisplay, drawSurface, readSurface, mEGLContext)) {
288288
throw new RuntimeException("eglMakeCurrent(draw,read) failed");
@@ -357,7 +357,7 @@ public static void logCurrent(String msg) {
357357
display = EGL14.eglGetCurrentDisplay();
358358
context = EGL14.eglGetCurrentContext();
359359
surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW);
360-
Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context + ", surface=" + surface);
360+
Log.i(TAG,"Current EGL (" + msg + "): display=" + display + ", context=" + context + ", surface=" + surface);
361361
}
362362

363363
/**

android/sdl_android/src/main/java/com/android/grafika/gles/EglSurfaceBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void makeCurrentReadFrom(EglSurfaceBase readSurface) {
135135
public boolean swapBuffers() {
136136
boolean result = mEglCore.swapBuffers(mEGLSurface);
137137
if (!result) {
138-
Log.d(TAG, "WARNING: swapBuffers() failed");
138+
Log.d(TAG,"WARNING: swapBuffers() failed");
139139
}
140140
return result;
141141
}
@@ -192,6 +192,6 @@ public void saveFrame(File file) throws IOException {
192192
} finally {
193193
if (bos != null) bos.close();
194194
}
195-
Log.d(TAG, "Saved " + width + "x" + height + " frame as '" + filename + "'");
195+
Log.d(TAG,"Saved " + width + "x" + height + " frame as '" + filename + "'");
196196
}
197197
}

android/sdl_android/src/main/java/com/android/grafika/gles/GlUtil.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static int createProgram(String vertexSource, String fragmentSource) {
6161
int program = GLES20.glCreateProgram();
6262
checkGlError("glCreateProgram");
6363
if (program == 0) {
64-
Log.d(TAG, "Could not create program");
64+
Log.d(TAG,"Could not create program");
6565
}
6666
GLES20.glAttachShader(program, vertexShader);
6767
checkGlError("glAttachShader");
@@ -71,8 +71,8 @@ public static int createProgram(String vertexSource, String fragmentSource) {
7171
int[] linkStatus = new int[1];
7272
GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
7373
if (linkStatus[0] != GLES20.GL_TRUE) {
74-
Log.e(TAG, "Could not link program: ");
75-
Log.e(TAG, GLES20.glGetProgramInfoLog(program));
74+
Log.e(TAG,"Could not link program: ");
75+
Log.e(TAG,GLES20.glGetProgramInfoLog(program));
7676
GLES20.glDeleteProgram(program);
7777
program = 0;
7878
}
@@ -92,8 +92,8 @@ public static int loadShader(int shaderType, String source) {
9292
int[] compiled = new int[1];
9393
GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
9494
if (compiled[0] == 0) {
95-
Log.e(TAG, "Could not compile shader " + shaderType + ":");
96-
Log.e(TAG, " " + GLES20.glGetShaderInfoLog(shader));
95+
Log.e(TAG,"Could not compile shader " + shaderType + ":");
96+
Log.e(TAG," " + GLES20.glGetShaderInfoLog(shader));
9797
GLES20.glDeleteShader(shader);
9898
shader = 0;
9999
}
@@ -107,7 +107,7 @@ public static void checkGlError(String op) {
107107
int error = GLES20.glGetError();
108108
if (error != GLES20.GL_NO_ERROR) {
109109
String msg = op + ": glError 0x" + Integer.toHexString(error);
110-
Log.e(TAG, msg);
110+
Log.e(TAG,msg);
111111
throw new RuntimeException(msg);
112112
}
113113
}
@@ -177,9 +177,9 @@ public static FloatBuffer createFloatBuffer(float[] coords) {
177177
* Writes GL version info to the log.
178178
*/
179179
public static void logVersionInfo() {
180-
Log.i(TAG, "vendor : " + GLES20.glGetString(GLES20.GL_VENDOR));
181-
Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
182-
Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION));
180+
Log.i(TAG,"vendor : " + GLES20.glGetString(GLES20.GL_VENDOR));
181+
Log.i(TAG,"renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
182+
Log.i(TAG,"version : " + GLES20.glGetString(GLES20.GL_VERSION));
183183

184184
if (false) {
185185
int[] values = new int[1];
@@ -188,7 +188,7 @@ public static void logVersionInfo() {
188188
GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0);
189189
int minorVersion = values[0];
190190
if (GLES30.glGetError() == GLES30.GL_NO_ERROR) {
191-
Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion);
191+
Log.i(TAG,"iversion: " + majorVersion + "." + minorVersion);
192192
}
193193
}
194194
}

android/sdl_android/src/main/java/com/android/grafika/gles/Texture2dProgram.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public Texture2dProgram(ProgramType programType) {
162162
if (mProgramHandle == 0) {
163163
throw new RuntimeException("Unable to create program");
164164
}
165-
Log.e(TAG, "Created program " + mProgramHandle + " (" + programType + ")");
165+
Log.e(TAG,"Created program " + mProgramHandle + " (" + programType + ")");
166166

167167
// get locations of attributes and uniforms
168168

@@ -188,7 +188,7 @@ public Texture2dProgram(ProgramType programType) {
188188
GlUtil.checkLocation(muColorAdjustLoc, "uColorAdjust");
189189

190190
// initialize default values
191-
setKernel(new float[]{0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f}, 0f);
191+
setKernel(new float[] {0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f}, 0f);
192192
setTexSize(256, 256);
193193
}
194194
}
@@ -200,7 +200,7 @@ public Texture2dProgram(ProgramType programType) {
200200
* the program).
201201
*/
202202
public void release() {
203-
Log.d(TAG, "deleting program " + mProgramHandle);
203+
Log.d(TAG,"deleting program " + mProgramHandle);
204204
GLES20.glDeleteProgram(mProgramHandle);
205205
mProgramHandle = -1;
206206
}
@@ -251,7 +251,7 @@ public void setKernel(float[] values, float colorAdj) {
251251
}
252252
System.arraycopy(values, 0, mKernel, 0, KERNEL_SIZE);
253253
mColorAdjust = colorAdj;
254-
Log.d(TAG, "filt kernel: " + Arrays.toString(mKernel) + ", adj=" + colorAdj);
254+
Log.d(TAG,"filt kernel: " + Arrays.toString(mKernel) + ", adj=" + colorAdj);
255255
}
256256

257257
/**
@@ -262,12 +262,12 @@ public void setTexSize(int width, int height) {
262262
float rh = 1.0f / height;
263263

264264
// Don't need to create a new array here, but it's syntactically convenient.
265-
mTexOffset = new float[]{
266-
-rw, -rh, 0f, -rh, rw, -rh,
267-
-rw, 0f, 0f, 0f, rw, 0f,
268-
-rw, rh, 0f, rh, rw, rh
265+
mTexOffset = new float[] {
266+
-rw, -rh, 0f, -rh, rw, -rh,
267+
-rw, 0f, 0f, 0f, rw, 0f,
268+
-rw, rh, 0f, rh, rw, rh
269269
};
270-
Log.d(TAG, "filt size: " + width + "x" + height + ": " + Arrays.toString(mTexOffset));
270+
Log.d(TAG,"filt size: " + width + "x" + height + ": " + Arrays.toString(mTexOffset));
271271
}
272272

273273
/**
@@ -322,7 +322,7 @@ public void draw(float[] mvpMatrix, FloatBuffer vertexBuffer, int firstVertex,
322322
// Connect texBuffer to "aTextureCoord".
323323
GLES20.glVertexAttribPointer(maTextureCoordLoc, 2,
324324
GLES20.GL_FLOAT, false, texStride, texBuffer);
325-
GlUtil.checkGlError("glVertexAttribPointer");
325+
GlUtil.checkGlError("glVertexAttribPointer");
326326

327327
// Populate the convolution kernel, if present.
328328
if (muKernelLoc >= 0) {

0 commit comments

Comments
 (0)