Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/0298_keybo…
Browse files Browse the repository at this point in the history
…ard_enchancements
  • Loading branch information
AKalinich-Luxoft committed Feb 6, 2021
2 parents cd1136e + 7f6db08 commit 55de319
Show file tree
Hide file tree
Showing 79 changed files with 6,118 additions and 1,304 deletions.
2 changes: 1 addition & 1 deletion android/sdl_android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ android {
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api 'com.smartdevicelink:bson_java_port:1.2.2'
api 'com.livio.taskmaster:taskmaster:0.3.0'
api 'com.livio.taskmaster:taskmaster:0.4.0'
api 'androidx.lifecycle:lifecycle-extensions:2.2.0'
api 'androidx.annotation:annotation:1.1.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.2.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.android.grafika.gles;

import android.opengl.GLES20;
import android.os.Environment;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import android.util.Log;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import static junit.framework.TestCase.assertTrue;

@RunWith(AndroidJUnit4.class)
public class OffscreenSurfaceTest {

private final String TAG = OffscreenSurfaceTest.class.getSimpleName();
private final int mWidth = 1280;
private final int mHeight = 720;
private final int mIterations = 100;

@Test
public void testReadPixels() {
EglCore eglCore = new EglCore(null, 0);
OffscreenSurface offscreenSurface = new OffscreenSurface(eglCore, mWidth, mHeight);
float time = runReadPixelsTest(offscreenSurface);
Log.d(TAG, "runReadPixelsTest returns " + time + " msec");
}

// HELPER test method
/**
* Does a simple bit of rendering and then reads the pixels back.
*
* @return total time (msec order) spent on glReadPixels()
*/
private float runReadPixelsTest(OffscreenSurface eglSurface) {
long totalTime = 0;

eglSurface.makeCurrent();

ByteBuffer pixelBuf = ByteBuffer.allocateDirect(mWidth * mHeight * 4);
pixelBuf.order(ByteOrder.LITTLE_ENDIAN);

Log.d(TAG, "Running...");
float colorMult = 1.0f / mIterations;
for (int i = 0; i < mIterations; i++) {
if ((i % (mIterations / 8)) == 0) {
Log.d(TAG, "iteration " + i);
}

// Clear the screen to a solid color, then add a rectangle. Change the color
// each time.
float r = i * colorMult;
float g = 1.0f - r;
float b = (r + g) / 2.0f;
GLES20.glClearColor(r, g, b, 1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
GLES20.glScissor(mWidth / 4, mHeight / 4, mWidth / 2, mHeight / 2);
GLES20.glClearColor(b, g, r, 1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glDisable(GLES20.GL_SCISSOR_TEST);

// Try to ensure that rendering has finished.
GLES20.glFinish();
GLES20.glReadPixels(0, 0, 1, 1,
GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuf);

// Time individual extraction. Ideally we'd be timing a bunch of these calls
// and measuring the aggregate time, but we want the isolated time, and if we
// just read the same buffer repeatedly we might get some sort of cache effect.
long startWhen = System.nanoTime();
GLES20.glReadPixels(0, 0, mWidth, mHeight,
GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuf);
totalTime += System.nanoTime() - startWhen;
}
Log.d(TAG, "done");

// It's not the good idea to request external strage permission in unit test.
boolean requireStoragePermission = false;
if (requireStoragePermission) {
long startWhen = System.nanoTime();
File file = new File(Environment.getExternalStorageDirectory(),
"test.png");
try {
eglSurface.saveFrame(file);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
Log.d(TAG, "Saved frame in " + ((System.nanoTime() - startWhen) / 1000000) + "ms");
assertTrue(file.exists());
} else {
// here' we can recognize Unit Test succeeded, but anyway checks to see totalTime and buffer capacity.
assertTrue(pixelBuf.capacity() > 0 && totalTime > 0);
}

return (float)totalTime / 1000000f;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import androidx.test.platform.app.InstrumentationRegistry;

import com.livio.taskmaster.Taskmaster;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.ISdl;
import com.smartdevicelink.managers.audio.AudioStreamManager.SampleType;
Expand Down Expand Up @@ -50,6 +51,7 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class AudioStreamManagerTest extends TestCase {
public static final String TAG = AudioStreamManagerTest.class.getSimpleName();
Expand Down Expand Up @@ -107,7 +109,7 @@ public Void answer(InvocationOnMock invocation) {
}
};

ISdl internalInterface = mock(ISdl.class);
ISdl internalInterface = createISdlMock();
SystemCapabilityManager systemCapabilityManager = mock(SystemCapabilityManager.class);
doReturn(systemCapabilityManager).when(internalInterface).getSystemCapabilityManager();
AudioPassThruCapabilities audioCapabilities = new AudioPassThruCapabilities(SamplingRate._16KHZ, BitsPerSample._16_BIT, AudioType.PCM);
Expand Down Expand Up @@ -299,7 +301,7 @@ public Void answer(InvocationOnMock invocation) {
}
};

ISdl internalInterface = mock(ISdl.class);
ISdl internalInterface = createISdlMock();
SystemCapabilityManager systemCapabilityManager = mock(SystemCapabilityManager.class);
doReturn(systemCapabilityManager).when(internalInterface).getSystemCapabilityManager();
doReturn(true).when(internalInterface).isConnected();
Expand Down Expand Up @@ -530,7 +532,7 @@ public Void answer(InvocationOnMock invocation) {
}
};

ISdl internalInterface = mock(ISdl.class);
ISdl internalInterface = createISdlMock();
SystemCapabilityManager systemCapabilityManager = mock(SystemCapabilityManager.class);
doReturn(systemCapabilityManager).when(internalInterface).getSystemCapabilityManager();
doReturn(true).when(internalInterface).isConnected();
Expand Down Expand Up @@ -609,7 +611,7 @@ public Void answer(InvocationOnMock invocation) {
}
};

ISdl internalInterface = mock(ISdl.class);
ISdl internalInterface = createISdlMock();
SystemCapabilityManager systemCapabilityManager = mock(SystemCapabilityManager.class);
doReturn(systemCapabilityManager).when(internalInterface).getSystemCapabilityManager();
doReturn(true).when(internalInterface).isConnected();
Expand Down Expand Up @@ -747,4 +749,13 @@ private void updateWaveHeaderLength(RandomAccessFile stream, long audiolength) t
stream.write((int) ((audiolength >> 16) & 0xff));
stream.write((int) ((audiolength >> 24) & 0xff));
}

private ISdl createISdlMock() {
ISdl internalInterface = mock(ISdl.class);
Taskmaster taskmaster = new Taskmaster.Builder().build();
taskmaster.start();

when(internalInterface.getTaskmaster()).thenReturn(taskmaster);
return internalInterface;
}
}
Loading

0 comments on commit 55de319

Please sign in to comment.