Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MainRender {
private var height = 0
private var previewWidth = 0
private var previewHeight = 0
private var context: Context? = null
private lateinit var context: Context
private var filterRenders = mutableListOf<BaseFilterRender>()
private val running = AtomicBoolean(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.opengl.GLES20;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import com.pedro.encoder.input.gl.render.BaseRenderOffScreen;
Expand All @@ -43,7 +44,8 @@ public abstract class BaseFilterRender extends BaseRenderOffScreen {
private RenderHandler renderHandler = new RenderHandler();
private RenderMode renderMode = RenderMode.ALL;

public void initGl(int width, int height, Context context, int previewWidth, int previewHeight) {
public void initGl(int width, int height, @NonNull Context context,
int previewWidth, int previewHeight) {
this.width = width;
this.height = height;
this.previewWidth = previewWidth;
Expand All @@ -63,7 +65,7 @@ public void initFBOLink() {
renderHandler.getTexId());
}

protected abstract void initGlFilter(Context context);
protected abstract void initGlFilter(@NonNull Context context);

public void draw() {
GlUtil.checkGlError("drawFilter start");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CropFilterRender: BaseFilterRender() {
Matrix.setIdentityM(positionMatrix, 0)
}

override fun initGlFilter(context: Context?) {
override fun initGlFilter(context: Context) {
val vertexShader = GlUtil.getStringFromRaw(context, R.raw.simple_vertex)
val fragmentShader = GlUtil.getStringFromRaw(context, R.raw.simple_fragment)
program = GlUtil.createProgram(vertexShader, fragmentShader)
Expand Down
3 changes: 2 additions & 1 deletion encoder/src/main/java/com/pedro/encoder/utils/gl/GlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.opengl.GLES20;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -97,7 +98,7 @@ public static void createExternalTextures(int quantity, int[] texturesId, int of
createTextures(quantity, texturesId, offset, GLES20.GL_LINEAR, true);
}

public static String getStringFromRaw(Context context, int id) {
public static String getStringFromRaw(@NonNull Context context, int id) {
String str;
try {
Resources r = context.getResources();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2024 pedroSG94.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.pedro.encoder.input.gl.render.filters;

import android.content.Context;
import android.content.ContextWrapper;

import androidx.annotation.NonNull;

import org.junit.Test;

import static org.junit.Assert.assertSame;

public class BaseFilterRenderTest {

@Test
public void initGlForwardsContextToFilter() {
Context expectedContext = new ContextWrapper(null);
TestFilterRender filterRender = new TestFilterRender();

filterRender.initGl(1, 1, expectedContext, 1, 1);

assertSame(expectedContext, filterRender.receivedContext);
}

private static final class TestFilterRender extends BaseFilterRender {

private Context receivedContext;

@Override
protected void initGlFilter(@NonNull Context context) {
receivedContext = context;
}

@Override
protected void drawFilter() {
}

@Override
protected void disableResources() {
}

@Override
public void release() {
}
}
}