Skip to content

Commit 4980762

Browse files
committed
テクスチャへの描画領域を指定できるように修正。libmedia 1.4.0 へバージョン変更。
1 parent a5fb6ff commit 4980762

2 files changed

Lines changed: 46 additions & 24 deletions

File tree

dConnectSDK/dConnectLibStreaming/libmedia/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (githubPropertiesFile.exists()) {
88
}
99

1010
def getVersionName = { ->
11-
return "1.3.0"
11+
return "1.4.0"
1212
}
1313

1414
def getArtificatId = { ->

dConnectSDK/dConnectLibStreaming/libmedia/src/main/java/org/deviceconnect/android/libmedia/streaming/gles/SurfaceTextureRenderer.java

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,12 @@ public class SurfaceTextureRenderer {
2525
private static final float[] TRIANGLE_VERTICES_DATA = {
2626
// X, Y, Z, U, V
2727
-1.0f, -1.0f, 0.f, 0.f, 0.f,
28-
1.0f, -1.0f, 0.f, 1.f, 0.f,
28+
1.0f, -1.0f, 0.f, 1.f, 0.f,
2929
-1.0f, 1.0f, 0.f, 0.f, 1.f,
30-
1.0f, 1.0f, 0.f, 1.f, 1.f,
31-
};
32-
33-
private static final float[] TRIANGLE_VERTICES_DATA_2 = {
34-
// X, Y, Z, U, V
35-
-1.0f, -1.0f, 0.f, 0.f, 1.f,
36-
1.0f, -1.0f, 0.f, 1.f, 1.f,
37-
-1.0f, 1.0f, 0.f, 0.f, 0.f,
38-
1.0f, 1.0f, 0.f, 1.f, 0.f,
30+
1.0f, 1.0f, 0.f, 1.f, 1.f,
3931
};
4032

33+
private final FloatBuffer mDefaultTriangleVertices;
4134
private final FloatBuffer mTriangleVertices;
4235
private final boolean mInverse;
4336

@@ -78,20 +71,54 @@ public class SurfaceTextureRenderer {
7871
* @param inverse テクスチャの反転フラグ
7972
*/
8073
public SurfaceTextureRenderer(boolean inverse) {
74+
this(inverse, TRIANGLE_VERTICES_DATA);
75+
}
76+
77+
/**
78+
* コンストラクタ.
79+
* @param inverse テクスチャの反転フラグ
80+
* @param vertices テクスチャの頂点バッファ(初期値)
81+
*/
82+
public SurfaceTextureRenderer(boolean inverse, float[] vertices) {
8183
mInverse = inverse;
84+
if (inverse) {
85+
vertices = inverseVertices(vertices);
86+
}
87+
88+
mDefaultTriangleVertices = ByteBuffer.allocateDirect(
89+
TRIANGLE_VERTICES_DATA.length * FLOAT_SIZE_BYTES)
90+
.order(ByteOrder.nativeOrder()).asFloatBuffer();
91+
mDefaultTriangleVertices.put(vertices).position(0);
92+
8293
mTriangleVertices = ByteBuffer.allocateDirect(
8394
TRIANGLE_VERTICES_DATA.length * FLOAT_SIZE_BYTES)
8495
.order(ByteOrder.nativeOrder()).asFloatBuffer();
85-
if (inverse) {
86-
mTriangleVertices.put(TRIANGLE_VERTICES_DATA_2).position(0);
87-
} else {
88-
mTriangleVertices.put(TRIANGLE_VERTICES_DATA).position(0);
89-
}
96+
mTriangleVertices.put(vertices).position(0);
9097

9198
Matrix.setIdentityM(mSTMatrix, 0);
9299
Matrix.setIdentityM(mMVPMatrix, 0);
93100
}
94101

102+
private static float[] inverseVertices(final float[] vertices) {
103+
int len = vertices.length;
104+
float[] inverse = new float[len];
105+
System.arraycopy(vertices, 0, inverse, 0, len);
106+
inverse[3] = vertices[13];
107+
inverse[4] = vertices[14];
108+
inverse[13] = vertices[3];
109+
inverse[14] = vertices[4];
110+
inverse[8] = vertices[18];
111+
inverse[9] = vertices[19];
112+
inverse[18] = vertices[8];
113+
inverse[19] = vertices[9];
114+
return inverse;
115+
}
116+
117+
public void setTextureVertices(final float[] vertices) {
118+
mTriangleVertices.clear();
119+
mTriangleVertices.put(vertices).position(0);
120+
}
121+
95122
/**
96123
* テクスチャの ID を取得します.
97124
*
@@ -227,11 +254,7 @@ public void drawFrame(SurfaceTexture st, int displayRotation) {
227254
*/
228255
public void clearCropRect() {
229256
mTriangleVertices.clear();
230-
if (mInverse) {
231-
mTriangleVertices.put(TRIANGLE_VERTICES_DATA_2).position(0);
232-
} else {
233-
mTriangleVertices.put(TRIANGLE_VERTICES_DATA).position(0);
234-
}
257+
mTriangleVertices.put(mDefaultTriangleVertices).position(0);
235258
}
236259

237260
/**
@@ -293,8 +316,7 @@ private void setCropRect(float l, float t, float r, float b) {
293316
ex, ey, 0.f, r, (1 - b),
294317
};
295318

296-
mTriangleVertices.clear();
297-
mTriangleVertices.put(triangleVerticesData).position(0);
319+
setTextureVertices(triangleVerticesData);
298320
}
299321

300322
private int loadShader(int shaderType, String source) {
@@ -366,4 +388,4 @@ private static void checkLocation(int location, String label) {
366388
throw new RuntimeException("Unable to locate '" + label + "' in program");
367389
}
368390
}
369-
}
391+
}

0 commit comments

Comments
 (0)