├── .gitignore
├── .project
├── .settings
└── org.eclipse.buildship.core.prefs
├── LICENSE
├── README-en.md
├── README.md
├── build.gradle
├── canvasgl
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.buildship.core.prefs
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── chillingvan
│ └── canvasgl
│ ├── CanvasGL.java
│ ├── ICanvasGL.java
│ ├── MultiTexOffScreenCanvas.java
│ ├── OffScreenCanvas.java
│ ├── OpenGLUtil.java
│ ├── androidCanvas
│ ├── AndroidCanvasHelperAsync.java
│ ├── AndroidCanvasHelperSync.java
│ └── IAndroidCanvasHelper.java
│ ├── glcanvas
│ ├── BasicTexture.java
│ ├── BitmapTexture.java
│ ├── GLCanvas.java
│ ├── GLCanvasUtils.java
│ ├── GLES20Canvas.java
│ ├── GLES20IdImpl.java
│ ├── GLId.java
│ ├── GLPaint.java
│ ├── IntArray.java
│ ├── RawTexture.java
│ ├── Texture.java
│ ├── TextureMatrixTransformer.java
│ └── UploadedTexture.java
│ ├── glview
│ ├── GLContinuousView.java
│ ├── GLView.java
│ └── texture
│ │ ├── BaseGLCanvasTextureView.java
│ │ ├── BaseGLTextureView.java
│ │ ├── GLContinuousTextureView.java
│ │ ├── GLMultiTexConsumerView.java
│ │ ├── GLMultiTexProducerView.java
│ │ ├── GLSharedContextView.java
│ │ ├── GLSurfaceTextureProducerView.java
│ │ ├── GLTexture.java
│ │ ├── GLTextureView.java
│ │ ├── GLViewRenderer.java
│ │ └── gles
│ │ ├── EGLLogWrapper.java
│ │ ├── EglContextWrapper.java
│ │ ├── EglHelper.java
│ │ ├── EglHelperAPI17.java
│ │ ├── EglHelperFactory.java
│ │ ├── GLThread.java
│ │ └── IEglHelper.java
│ ├── matrix
│ ├── BaseBitmapMatrix.java
│ └── IBitmapMatrix.java
│ ├── shapeFilter
│ ├── BasicDrawShapeFilter.java
│ ├── DrawCircleFilter.java
│ └── DrawShapeFilter.java
│ ├── textureFilter
│ ├── BasicTextureFilter.java
│ ├── ColorMatrixFilter.java
│ ├── ContrastFilter.java
│ ├── CropFilter.java
│ ├── DarkenBlendFilter.java
│ ├── DirectionalSobelEdgeDetectionFilter.java
│ ├── FilterGroup.java
│ ├── GammaFilter.java
│ ├── GaussianBlurFilter.java
│ ├── HueFilter.java
│ ├── LightenBlendFilter.java
│ ├── LookupFilter.java
│ ├── OneValueFilter.java
│ ├── PixelationFilter.java
│ ├── RGBFilter.java
│ ├── SaturationFilter.java
│ ├── TextureFilter.java
│ ├── TextureSampling3mul3Filter.java
│ └── TwoTextureFilter.java
│ └── util
│ ├── FileLogger.java
│ ├── FileUtil.java
│ └── Loggers.java
├── canvasglsample
├── .classpath
├── .gitignore
├── .project
├── .settings
│ └── org.eclipse.buildship.core.prefs
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ ├── test_video.mp4
│ └── test_video_2.mp4
│ ├── java
│ └── com
│ │ └── chillingvan
│ │ └── canvasglsample
│ │ ├── CrashHandler.java
│ │ ├── MainActivity.java
│ │ ├── MainApplication.kt
│ │ ├── animation
│ │ ├── AnimActivity.java
│ │ ├── AnimGLTextureView.java
│ │ ├── AnimGLView.java
│ │ └── bubble
│ │ │ ├── Bubble.java
│ │ │ ├── MovableObj.java
│ │ │ └── Wall.java
│ │ ├── compareCanvas
│ │ ├── CompareCanvasActivity.kt
│ │ ├── CompareGLView.kt
│ │ └── CompareNormalView.kt
│ │ ├── comparePerformance
│ │ ├── ComparePerformanceActivity.java
│ │ ├── GLBubblesView.java
│ │ ├── NormalBubblesView.java
│ │ ├── RefreshTimer.java
│ │ └── SurfaceBubblesView.java
│ │ ├── filter
│ │ ├── CaseEntity.java
│ │ ├── CaseItemView.java
│ │ ├── FilterActivity.java
│ │ ├── FilterAdjuster.java
│ │ └── FilterGLView.java
│ │ ├── listSample
│ │ ├── ProviderOffScreenCanvas.java
│ │ ├── TextureItemEntity.java
│ │ ├── TextureItemView.java
│ │ └── TextureListActivity.java
│ │ ├── multi
│ │ ├── MultiTextureActivity.java
│ │ └── MultiVideoTexture.java
│ │ ├── offscreen
│ │ ├── MultiTexOffScreenActivity.java
│ │ ├── OffScreenActivity.java
│ │ ├── SimpleOffScreenActivity.java
│ │ └── camera
│ │ │ ├── CameraPreviewOffScreen.java
│ │ │ └── OffscreenCameraActivity.java
│ │ ├── screenRecord
│ │ ├── ScreenRecordActivity.java
│ │ ├── ScreenRecordHelper.java
│ │ └── ScreenRecordTextureView.java
│ │ ├── testcase
│ │ └── testMatrix
│ │ │ ├── Camera2Util.java
│ │ │ ├── TestMatrixActivity.java
│ │ │ ├── TestMatrixSurfaceActivity.java
│ │ │ ├── TestMatrixSurfaceTextureView.java
│ │ │ └── TestMatrixTextureView.java
│ │ ├── text
│ │ ├── Dannmaku.java
│ │ ├── DannmakuFactory.java
│ │ ├── DrawTextActivity.java
│ │ ├── DrawTextTextureView.java
│ │ └── ObjectFactory.java
│ │ ├── textureView
│ │ ├── CameraPreviewTextureView.java
│ │ ├── CameraUtils.java
│ │ ├── PreviewConsumerTextureView.java
│ │ └── TextureCameraActivity.java
│ │ ├── util
│ │ ├── ScreenUtil.java
│ │ └── adapter
│ │ │ ├── BaseItemView.java
│ │ │ ├── CommonAdapterInternal.java
│ │ │ ├── CommonBaseAdapter.java
│ │ │ ├── CommonItemView.java
│ │ │ ├── CommonRecyclerAdapter.java
│ │ │ └── RenderEntity.java
│ │ └── video
│ │ ├── MediaPlayerActivity.java
│ │ ├── MediaPlayerHelper.java
│ │ ├── MediaPlayerProduceTextureView.java
│ │ ├── MediaPlayerTextureView.java
│ │ ├── MergeVideoActivity.java
│ │ └── MergeVideoTextureView.java
│ └── res
│ ├── drawable-nodpi
│ ├── baboon.png
│ ├── lenna.png
│ └── lookup_amatorka.png
│ ├── drawable-xhdpi
│ └── ic_robot.png
│ ├── layout
│ ├── activity_anim.xml
│ ├── activity_camera_offscreen.xml
│ ├── activity_compare_canvas.xml
│ ├── activity_compare_performace.xml
│ ├── activity_draw_text.xml
│ ├── activity_filter.xml
│ ├── activity_media_player.xml
│ ├── activity_merge_video.xml
│ ├── activity_multi_tex_off_screen.xml
│ ├── activity_multi_texture.xml
│ ├── activity_off_screen.xml
│ ├── activity_screen_record.xml
│ ├── activity_simple_off_screen.xml
│ ├── activity_test_matrix.xml
│ ├── activity_test_matrix_surface.xml
│ ├── activity_texture_canvas.xml
│ ├── activity_texture_list.xml
│ ├── item_case_filter.xml
│ └── item_texture_list.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ ├── values-zh-rCN
│ └── strings.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jitpack.yml
├── screenshots
├── anim-activity-example.png
├── camera-example-v1.jpg
├── canvas-example-v1.png
└── filter_example-v1.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | /.idea
11 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | android-openGL-canvas
4 | Project android-openGL-canvas created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.buildship.core.gradleprojectbuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.buildship.core.gradleprojectnature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | connection.project.dir=
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
22 |
23 | buildscript {
24 | ext.kotlin_version = '1.6.21'
25 | repositories {
26 | google()
27 | mavenCentral()
28 | }
29 | dependencies {
30 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
31 | classpath 'com.android.tools.build:gradle:4.2.2'
32 | // NOTE: Do not place your application dependencies here; they belong
33 | // in the individual module build.gradle files
34 | }
35 | }
36 |
37 | allprojects {
38 | repositories {
39 | google()
40 | mavenCentral()
41 | }
42 | }
43 |
44 | task clean(type: Delete) {
45 | delete rootProject.buildDir
46 | }
47 |
--------------------------------------------------------------------------------
/canvasgl/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/canvasgl/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/canvasgl/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | canvasgl
4 | Project canvasgl created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.buildship.core.gradleprojectbuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.buildship.core.gradleprojectnature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/canvasgl/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | connection.project.dir=..
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/canvasgl/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | apply plugin: 'com.android.library'
22 | apply plugin: 'maven-publish'
23 | def NAMESPACE="com.github.ChillingVan"
24 | group = NAMESPACE
25 | def VERSION_NAME="1.5.4.0"
26 |
27 | android {
28 | namespace = NAMESPACE
29 | compileSdkVersion 32
30 | defaultConfig {
31 | minSdkVersion 14
32 | targetSdkVersion 32
33 | versionCode 105040
34 | versionName VERSION_NAME
35 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
36 | }
37 | buildTypes {
38 | release {
39 | minifyEnabled false
40 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
41 | }
42 | }
43 |
44 | lintOptions {
45 | checkReleaseBuilds false
46 | // Or, if you prefer, you can continue to check for errors in release builds,
47 | // but continue the build even when errors are found:
48 | abortOnError false
49 | }
50 | compileOptions {
51 | sourceCompatibility JavaVersion.VERSION_1_8
52 | targetCompatibility JavaVersion.VERSION_1_8
53 | }
54 |
55 | }
56 |
57 | dependencies {
58 | implementation fileTree(include: ['*.jar'], dir: 'libs')
59 | testImplementation 'junit:junit:4.12'
60 | implementation 'androidx.annotation:annotation:1.3.0'
61 | }
62 |
63 |
64 | // build a jar with source files
65 | task sourcesJar(type: Jar) {
66 | from android.sourceSets.main.java.srcDirs
67 | classifier = 'sources'
68 | }
69 |
70 | task javadoc(type: Javadoc) {
71 | failOnError false
72 | source = android.sourceSets.main.java.sourceFiles
73 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
74 | classpath += configurations.compile
75 | }
76 |
77 | // build a jar with javadoc
78 | task javadocJar(type: Jar, dependsOn: javadoc) {
79 | classifier = 'javadoc'
80 | from javadoc.destinationDir
81 | }
82 |
83 |
84 | artifacts {
85 | archives sourcesJar
86 | archives javadocJar
87 | }
88 |
89 |
90 | afterEvaluate {
91 | publishing {
92 | publications {
93 | // Creates a Maven publication called "release".
94 | release(MavenPublication) {
95 | from components.release
96 | groupId = NAMESPACE
97 | artifactId = 'android-openGL-canvas'
98 | version = VERSION_NAME
99 | }
100 | }
101 | }
102 | }
103 |
104 |
--------------------------------------------------------------------------------
/canvasgl/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\develop-win\android\dev-tools-win\android-studio-windows\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 |
20 | -dontpreverify
21 | -repackageclasses ''
22 | -allowaccessmodification
23 | -optimizations !code/simplification/arithmetic
24 | -keepparameternames
25 | -renamesourcefileattribute SourceFile
26 | -keepattributes Exceptions,InnerClasses,Signature,Deprecated, SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
27 |
28 | -keep public class * {
29 | public protected *;
30 | }
31 |
32 | -keepclassmembernames class * {
33 | java.lang.Class class$(java.lang.String);
34 | java.lang.Class class$(java.lang.String, boolean);
35 | }
36 |
37 | -keepclasseswithmembernames,includedescriptorclasses class * {
38 | native ;
39 | }
40 |
41 | -keepclassmembers,allowoptimization enum * {
42 | public static **[] values(); public static ** valueOf(java.lang.String);
43 | }
44 |
45 | -keepclassmembers class * implements java.io.Serializable {
46 | static final long serialVersionUID;
47 | private static final java.io.ObjectStreamField[] serialPersistentFields;
48 | private void writeObject(java.io.ObjectOutputStream);
49 | private void readObject(java.io.ObjectInputStream);
50 | java.lang.Object writeReplace();
51 | java.lang.Object readResolve();
52 | }
53 |
54 | -keep public class * extends android.view.View {
55 | public (android.content.Context);
56 | public (android.content.Context, android.util.AttributeSet);
57 | public (android.content.Context, android.util.AttributeSet, int);
58 | public void set*(...);
59 | }
60 |
61 |
62 | -keepclasseswithmembers class * {
63 | public (android.content.Context, android.util.AttributeSet);
64 | }
65 |
66 | -keepclasseswithmembers class * {
67 | public (android.content.Context, android.util.AttributeSet, int);
68 | }
69 |
70 | -keepclassmembers class * extends android.content.Context {
71 | public void *(android.view.View);
72 | public void *(android.view.MenuItem);
73 | }
74 |
75 | -keepclassmembers class * implements android.os.Parcelable {
76 | static ** CREATOR;
77 | }
78 |
79 | -keepclassmembers class **.R$* {
80 | public static ;
81 | }
82 |
83 | -keepclassmembers class * {
84 | @android.webkit.JavascriptInterface ;
85 | }
86 |
--------------------------------------------------------------------------------
/canvasgl/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/OpenGLUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl;
22 |
23 | import android.graphics.Bitmap;
24 | import android.opengl.GLES11;
25 | import android.opengl.GLES20;
26 | import android.opengl.GLException;
27 |
28 | import java.nio.IntBuffer;
29 |
30 | import javax.microedition.khronos.opengles.GL10;
31 |
32 | /**
33 | * Some tools for OpenGL
34 | */
35 | public class OpenGLUtil {
36 |
37 | public static void setUniformMatrix4f(final int location, final float[] matrix) {
38 | GLES20.glUniformMatrix4fv(location, 1, false, matrix, 0);
39 | }
40 |
41 | public static void setFloat(final int location, final float floatValue) {
42 | GLES20.glUniform1f(location, floatValue);
43 | }
44 |
45 | public static Bitmap createBitmapFromGLSurface(int x, int y, int w, int h, int glHeight)
46 | throws OutOfMemoryError {
47 | int bitmapBuffer[] = new int[w * h];
48 | int bitmapSource[] = new int[w * h];
49 | IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer);
50 | intBuffer.position(0);
51 |
52 | try {
53 | GLES11.glReadPixels(x, glHeight - h - y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, intBuffer);
54 | int offset1, offset2;
55 | for (int i = 0; i < h; i++) {
56 | offset1 = i * w;
57 | offset2 = (h - i - 1) * w;
58 | for (int j = 0; j < w; j++) {
59 | int texturePixel = bitmapBuffer[offset1 + j];
60 | int blue = (texturePixel >> 16) & 0xff;
61 | int red = (texturePixel << 16) & 0x00ff0000;
62 | int pixel = (texturePixel & 0xff00ff00) | red | blue;
63 | bitmapSource[offset2 + j] = pixel;
64 | }
65 | }
66 | } catch (GLException e) {
67 | return null;
68 | }
69 |
70 | return Bitmap.createBitmap(bitmapSource, w, h, Bitmap.Config.ARGB_8888);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/androidCanvas/AndroidCanvasHelperAsync.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.androidCanvas;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 |
6 | import java.util.concurrent.ExecutorService;
7 | import java.util.concurrent.Executors;
8 | import java.util.concurrent.locks.Lock;
9 | import java.util.concurrent.locks.ReentrantLock;
10 |
11 | /**
12 | * Created by Chilling on 2018/4/14.
13 | *
14 | * Draw text in another thread.
15 | * 这个类会另起一个线程,但会创建双份Bitmap,比较耗内存。
16 | */
17 | class AndroidCanvasHelperAsync implements IAndroidCanvasHelper {
18 |
19 | private int width;
20 | private int height;
21 | private Bitmap bitmapBoard;
22 | private Bitmap bitmapBoardCached;
23 | private Canvas canvas;
24 |
25 | private ExecutorService executors = Executors.newSingleThreadExecutor();
26 | // If textDrawee is not drawing, then it is available.
27 | private volatile boolean isAvailable = true;
28 | private Lock lock = new ReentrantLock();
29 |
30 | @Override
31 | public void init(int width, int height) {
32 | if (this.width != width || this.height != height) {
33 | this.width = width;
34 | this.height = height;
35 | bitmapBoard = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
36 | bitmapBoardCached = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
37 | canvas = new Canvas(bitmapBoard);
38 | }
39 | }
40 |
41 | /**
42 | * This must be in the same thread as {@link #getOutputBitmap()}
43 | */
44 | @Override
45 | public void draw(final CanvasPainter canvasPainter) {
46 | if (canvas == null) {
47 | throw new IllegalStateException("DrawTextHelper has not init.");
48 | }
49 | if (!isAvailable) {
50 | return;
51 | }
52 | swap();
53 | executors.execute(new Runnable() {
54 | @Override
55 | public void run() {
56 | lock.lock();
57 | isAvailable = false;
58 | canvasPainter.draw(canvas, bitmapBoard);
59 | isAvailable = true;
60 | lock.unlock();
61 | }
62 | });
63 | }
64 |
65 | /**
66 | * Swap bitmapBoard and bitmapBoardCached.
67 | */
68 | private void swap() {
69 | lock.lock();
70 | Bitmap temp = bitmapBoardCached;
71 | bitmapBoardCached = bitmapBoard;
72 | bitmapBoard = temp;
73 | canvas.setBitmap(bitmapBoard);
74 | lock.unlock();
75 | }
76 |
77 | @Override
78 | public Bitmap getOutputBitmap() {
79 | return bitmapBoardCached;
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/androidCanvas/AndroidCanvasHelperSync.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.androidCanvas;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 | /**
6 | * Created by Chilling on 2018/4/14.
7 | *
8 | * This will use a bitmap and draw in the thread you use.
9 | * 这个类不会另起一个线程。
10 | */
11 | class AndroidCanvasHelperSync implements IAndroidCanvasHelper {
12 |
13 | private int width;
14 | private int height;
15 | private Bitmap bitmapBoard;
16 | private Canvas canvas;
17 |
18 | @Override
19 | public void init(int width, int height) {
20 | if (this.width != width || this.height != height) {
21 | this.width = width;
22 | this.height = height;
23 | bitmapBoard = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
24 | canvas = new Canvas(bitmapBoard);
25 | }
26 | }
27 |
28 | @Override
29 | public void draw(CanvasPainter canvasPainter) {
30 | if (canvas == null) {
31 | throw new IllegalStateException("DrawTextHelper has not init.");
32 | }
33 | canvasPainter.draw(canvas, bitmapBoard);
34 | }
35 |
36 | @Override
37 | public Bitmap getOutputBitmap() {
38 | return bitmapBoard;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/androidCanvas/IAndroidCanvasHelper.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.androidCanvas;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Canvas;
5 |
6 | import static com.chillingvan.canvasgl.androidCanvas.IAndroidCanvasHelper.MODE.MODE_SYNC;
7 |
8 | /**
9 | * Created by Chilling on 2018/4/14.
10 | *
11 | * This is a helper class to use canvas for Android. This will use software rendering and generate at least one bitmap with specified width and height.
12 | * For async mode, it will generate 2 same bitmap. One for GLCanvas and one for itself.
13 | */
14 | public interface IAndroidCanvasHelper {
15 | void init(int width, int height);
16 | void draw(final CanvasPainter canvasPainter);
17 | Bitmap getOutputBitmap();
18 |
19 | interface CanvasPainter {
20 | void draw(Canvas androidCanvas, Bitmap drawBitmap);
21 | }
22 |
23 | interface MODE {
24 | String MODE_SYNC = "SYNC";
25 | String MODE_ASYNC = "ASYNC";
26 | }
27 |
28 | class Factory {
29 |
30 | /**
31 | * @param mode {@link MODE}
32 | * @return AndroidCanvasHelper
33 | */
34 | public static IAndroidCanvasHelper createAndroidCanvasHelper(String mode) {
35 | if (mode.equals(MODE_SYNC)) {
36 | return new AndroidCanvasHelperSync();
37 | } else {
38 | return new AndroidCanvasHelperAsync();
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/BitmapTexture.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glcanvas;
22 |
23 | import android.graphics.Bitmap;
24 |
25 | // BitmapTexture is a secondBitmap whose content is specified by a fixed Bitmap.
26 | //
27 | // The secondBitmap does not own the Bitmap. The user should make sure the Bitmap
28 | // is valid during the secondBitmap's lifetime. When the secondBitmap is recycled, it
29 | // does not free the Bitmap.
30 | public class BitmapTexture extends UploadedTexture {
31 | protected Bitmap mContentBitmap;
32 |
33 | public BitmapTexture(Bitmap bitmap) {
34 | this(bitmap, false);
35 | }
36 |
37 | public BitmapTexture(Bitmap bitmap, boolean hasBorder) {
38 | super(hasBorder);
39 | // Assert.assertTrue(bitmap != null && !bitmap.isRecycled());
40 | mContentBitmap = bitmap;
41 | }
42 |
43 | @Override
44 | protected void onFreeBitmap(Bitmap bitmap) {
45 | // Do nothing.
46 | }
47 |
48 | @Override
49 | protected Bitmap onGetBitmap() {
50 | return mContentBitmap;
51 | }
52 |
53 | public Bitmap getBitmap() {
54 | return mContentBitmap;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/GLES20IdImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glcanvas;
22 |
23 | import android.opengl.GLES20;
24 |
25 | public class GLES20IdImpl implements GLId {
26 | private final int[] mTempIntArray = new int[1];
27 |
28 | @Override
29 | public int generateTexture() {
30 | GLES20.glGenTextures(1, mTempIntArray, 0);
31 | GLES20Canvas.checkError();
32 | return mTempIntArray[0];
33 | }
34 |
35 | @Override
36 | public void glGenBuffers(int n, int[] buffers, int offset) {
37 | GLES20.glGenBuffers(n, buffers, offset);
38 | GLES20Canvas.checkError();
39 | }
40 |
41 | @Override
42 | public void glDeleteTextures(int n, int[] textures, int offset) {
43 | GLES20.glDeleteTextures(n, textures, offset);
44 | GLES20Canvas.checkError();
45 | }
46 |
47 |
48 | @Override
49 | public void glDeleteBuffers(int n, int[] buffers, int offset) {
50 | GLES20.glDeleteBuffers(n, buffers, offset);
51 | GLES20Canvas.checkError();
52 | }
53 |
54 | @Override
55 | public void glDeleteFramebuffers(int n, int[] buffers, int offset) {
56 | GLES20.glDeleteFramebuffers(n, buffers, offset);
57 | GLES20Canvas.checkError();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/GLId.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glcanvas;
22 |
23 | // This mimics corresponding GL functions.
24 | public interface GLId {
25 | public int generateTexture();
26 |
27 | public void glGenBuffers(int n, int[] buffers, int offset);
28 |
29 | public void glDeleteTextures(int n, int[] textures, int offset);
30 |
31 | public void glDeleteBuffers(int n, int[] buffers, int offset);
32 |
33 | public void glDeleteFramebuffers(int n, int[] buffers, int offset);
34 | }
35 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/GLPaint.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glcanvas;
22 |
23 | import android.graphics.Color;
24 | import android.graphics.Paint;
25 |
26 |
27 | public class GLPaint {
28 | private float mLineWidth = 1f;
29 | private int mColor = Color.WHITE;
30 | private Paint.Style style = Paint.Style.FILL;
31 |
32 | public void setColor(int color) {
33 | mColor = color;
34 | }
35 |
36 | public int getColor() {
37 | return mColor;
38 | }
39 |
40 | public void setLineWidth(float width) {
41 | mLineWidth = width;
42 | }
43 |
44 | public float getLineWidth() {
45 | return mLineWidth;
46 | }
47 |
48 | public void setStyle(Paint.Style style) {
49 | this.style = style;
50 | }
51 |
52 | public Paint.Style getStyle() {
53 | return style;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/IntArray.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glcanvas;
22 |
23 | public class IntArray {
24 | private static final int INIT_CAPACITY = 8;
25 |
26 | private int mData[] = new int[INIT_CAPACITY];
27 | private int mSize = 0;
28 |
29 | public void add(int value) {
30 | if (mData.length == mSize) {
31 | int temp[] = new int[mSize + mSize];
32 | System.arraycopy(mData, 0, temp, 0, mSize);
33 | mData = temp;
34 | }
35 | mData[mSize++] = value;
36 | }
37 |
38 | public int removeLast() {
39 | mSize--;
40 | return mData[mSize];
41 | }
42 |
43 | public int size() {
44 | return mSize;
45 | }
46 |
47 | // For testing only
48 | public int[] toArray(int[] result) {
49 | if (result == null || result.length < mSize) {
50 | result = new int[mSize];
51 | }
52 | System.arraycopy(mData, 0, result, 0, mSize);
53 | return result;
54 | }
55 |
56 | public int[] getInternalArray() {
57 | return mData;
58 | }
59 |
60 | public void clear() {
61 | mSize = 0;
62 | if (mData.length != INIT_CAPACITY) mData = new int[INIT_CAPACITY];
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/RawTexture.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glcanvas;
22 |
23 | import android.opengl.GLES20;
24 | import android.util.Log;
25 |
26 | import javax.microedition.khronos.opengles.GL11;
27 |
28 | public class RawTexture extends BasicTexture {
29 | private static final String TAG = "RawTexture";
30 |
31 | private final boolean mOpaque;
32 | private int target;
33 | protected boolean needInvalidate;
34 |
35 | public RawTexture(int width, int height, boolean opaque) {
36 | this(width, height, opaque, GL11.GL_TEXTURE_2D);
37 | }
38 |
39 | public RawTexture(int width, int height, boolean opaque, int target) {
40 | mOpaque = opaque;
41 | setSize(width, height);
42 | this.target = target;
43 | }
44 |
45 | @Override
46 | public boolean isOpaque() {
47 | return mOpaque;
48 | }
49 |
50 | public void prepare(GLCanvas canvas) {
51 | GLId glId = canvas.getGLId();
52 | mId = glId.generateTexture();
53 |
54 | if (target == GLES20.GL_TEXTURE_2D) {
55 | canvas.initializeTextureSize(this, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE);
56 | }
57 | canvas.setTextureParameters(this);
58 | mState = STATE_LOADED;
59 | setAssociatedCanvas(canvas);
60 | }
61 |
62 | @Override
63 | protected boolean onBind(GLCanvas canvas) {
64 | if (isLoaded()) return true;
65 | Log.w(TAG, "lost the content due to context change");
66 | return false;
67 | }
68 |
69 | @Override
70 | public void yield() {
71 | // we cannot free the secondBitmap because we have no backup.
72 | }
73 |
74 | @Override
75 | public int getTarget() {
76 | return target;
77 | }
78 |
79 | /**
80 | * Call this when surfaceTexture calls updateTexImage
81 | */
82 | public void setNeedInvalidate(boolean needInvalidate) {
83 | this.needInvalidate = needInvalidate;
84 | }
85 |
86 | public boolean isNeedInvalidate() {
87 | return needInvalidate;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/Texture.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glcanvas;
22 |
23 |
24 | // Texture is a rectangular image which can be drawn on GLCanvas.
25 | // The isOpaque() function gives a hint about whether the secondBitmap is opaque,
26 | // so the drawing can be done faster.
27 | //
28 | // This is the current secondBitmap hierarchy:
29 | //
30 | // Texture
31 | // -- ColorTexture
32 | // -- FadeInTexture
33 | // -- BasicTexture
34 | // -- UploadedTexture
35 | // -- BitmapTexture
36 | // -- Tile
37 | // -- ResourceTexture
38 | // -- NinePatchTexture
39 | // -- CanvasTexture
40 | // -- StringTexture
41 | //
42 | public interface Texture {
43 | public int getWidth();
44 | public int getHeight();
45 | public void draw(GLCanvas canvas, int x, int y);
46 | public void draw(GLCanvas canvas, int x, int y, int w, int h);
47 | public boolean isOpaque();
48 | }
49 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glcanvas/TextureMatrixTransformer.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glcanvas;
22 |
23 | import android.graphics.RectF;
24 |
25 | /**
26 | * Created by Chilling on 2016/11/6.
27 | */
28 |
29 | public class TextureMatrixTransformer {
30 | // This function changes the source coordinate to the secondBitmap coordinates.
31 | // It also clips the source and target coordinates if it is beyond the
32 | // bound of the secondBitmap.
33 | public static void convertCoordinate(RectF source, BasicTexture texture) {
34 | int width = texture.getWidth();
35 | int height = texture.getHeight();
36 | int texWidth = texture.getTextureWidth();
37 | int texHeight = texture.getTextureHeight();
38 | // Convert to secondBitmap coordinates
39 | source.left /= texWidth;
40 | source.right /= texWidth;
41 | source.top /= texHeight;
42 | source.bottom /= texHeight;
43 |
44 | // Clip if the rendering range is beyond the bound of the secondBitmap.
45 | float xBound = (float) width / texWidth;
46 | if (source.right > xBound) {
47 | source.right = xBound;
48 | }
49 | float yBound = (float) height / texHeight;
50 | if (source.bottom > yBound) {
51 | source.bottom = yBound;
52 | }
53 | }
54 |
55 | public static void setTextureMatrix(RectF source, float[] textureMatrix) {
56 | textureMatrix[0] = source.width();
57 | textureMatrix[5] = source.height();
58 | textureMatrix[12] = source.left;
59 | textureMatrix[13] = source.top;
60 | }
61 |
62 | public static void copyTextureCoordinates(BasicTexture texture, RectF outRect) {
63 | int left = 0;
64 | int top = 0;
65 | int right = texture.getWidth();
66 | int bottom = texture.getHeight();
67 | if (texture.hasBorder()) {
68 | left = 1;
69 | top = 1;
70 | right -= 1;
71 | bottom -= 1;
72 | }
73 | outRect.set(left, top, right, bottom);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glview/GLContinuousView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glview;
22 |
23 | import android.content.Context;
24 | import android.opengl.GLSurfaceView;
25 | import android.util.AttributeSet;
26 |
27 | import com.chillingvan.canvasgl.ICanvasGL;
28 |
29 | /**
30 | * Created by Chilling on 2016/10/24.
31 | */
32 |
33 | public abstract class GLContinuousView extends GLView {
34 | public GLContinuousView(Context context) {
35 | super(context);
36 | }
37 |
38 | public GLContinuousView(Context context, AttributeSet attrs) {
39 | super(context, attrs);
40 | }
41 |
42 | @Override
43 | protected void init() {
44 | super.init();
45 | setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
46 | }
47 |
48 |
49 | protected abstract void onGLDraw(ICanvasGL canvas);
50 | }
51 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/GLContinuousTextureView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glview.texture;
22 |
23 | import android.content.Context;
24 | import android.util.AttributeSet;
25 |
26 | import com.chillingvan.canvasgl.glview.texture.gles.GLThread;
27 |
28 | /**
29 | * Created by Chilling on 2016/11/1.
30 | *
31 | * {@link com.chillingvan.canvasgl.glview.GLContinuousView} is better.
32 | */
33 |
34 | public abstract class GLContinuousTextureView extends GLTextureView {
35 | public GLContinuousTextureView(Context context) {
36 | super(context);
37 | }
38 |
39 | public GLContinuousTextureView(Context context, AttributeSet attrs) {
40 | super(context, attrs);
41 | }
42 |
43 | public GLContinuousTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
44 | super(context, attrs, defStyleAttr);
45 | }
46 |
47 | @Override
48 | protected int getRenderMode() {
49 | return GLThread.RENDERMODE_CONTINUOUSLY;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/GLSharedContextView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glview.texture;
22 |
23 | import android.content.Context;
24 | import android.graphics.SurfaceTexture;
25 | import android.util.AttributeSet;
26 |
27 | import com.chillingvan.canvasgl.ICanvasGL;
28 | import com.chillingvan.canvasgl.glcanvas.BasicTexture;
29 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
30 |
31 | import java.util.List;
32 |
33 | import androidx.annotation.Nullable;
34 |
35 | /**
36 | * This class is used to accept eglContext and texture from outside. Then it can use them to draw.
37 | * @deprecated Use {@link GLMultiTexConsumerView} instead.
38 | */
39 | public abstract class GLSharedContextView extends GLMultiTexConsumerView {
40 |
41 |
42 | protected BasicTexture outsideSharedTexture;
43 | protected SurfaceTexture outsideSharedSurfaceTexture;
44 |
45 | public GLSharedContextView(Context context) {
46 | super(context);
47 | }
48 |
49 | public GLSharedContextView(Context context, AttributeSet attrs) {
50 | super(context, attrs);
51 | }
52 |
53 | public GLSharedContextView(Context context, AttributeSet attrs, int defStyleAttr) {
54 | super(context, attrs, defStyleAttr);
55 | }
56 |
57 | public void setSharedTexture(RawTexture outsideTexture, SurfaceTexture outsideSurfaceTexture) {
58 | this.outsideSharedTexture = outsideTexture;
59 | this.outsideSharedSurfaceTexture = outsideSurfaceTexture;
60 | if (consumedTextures.isEmpty()) {
61 | consumedTextures.add(new GLTexture(outsideTexture, outsideSurfaceTexture));
62 | }
63 | }
64 |
65 | /**
66 | *
67 | * Will not call until @param surfaceTexture not null
68 | */
69 | protected abstract void onGLDraw(ICanvasGL canvas, @Nullable SurfaceTexture sharedSurfaceTexture, BasicTexture sharedTexture);
70 |
71 | @Override
72 | protected final void onGLDraw(ICanvasGL canvas, List consumedTextures) {
73 | if (outsideSharedTexture != null && outsideSharedTexture.isRecycled()) {
74 | outsideSharedTexture = null;
75 | outsideSharedSurfaceTexture = null;
76 | }
77 | onGLDraw(canvas, outsideSharedSurfaceTexture, outsideSharedTexture);
78 | }
79 |
80 |
81 | @Override
82 | protected void surfaceDestroyed() {
83 | super.surfaceDestroyed();
84 | outsideSharedSurfaceTexture = null;
85 | outsideSharedTexture = null;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/GLTexture.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.glview.texture;
2 |
3 | import android.graphics.SurfaceTexture;
4 |
5 | import com.chillingvan.canvasgl.ICanvasGL;
6 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
7 |
8 | /**
9 | * Created by Chilling on 2018/5/19.
10 | */
11 | public class GLTexture {
12 |
13 | private RawTexture rawTexture;
14 | private SurfaceTexture surfaceTexture;
15 |
16 | public GLTexture(RawTexture outsideTexture, SurfaceTexture outsideSurfaceTexture) {
17 | this.rawTexture = outsideTexture;
18 | this.surfaceTexture = outsideSurfaceTexture;
19 | }
20 |
21 | public RawTexture getRawTexture() {
22 | return rawTexture;
23 | }
24 |
25 | public SurfaceTexture getSurfaceTexture() {
26 | return surfaceTexture;
27 | }
28 |
29 | public static GLTexture createRaw(int width, int height, boolean opaque, int target, ICanvasGL canvasGL) {
30 | RawTexture rawTexture = new RawTexture(width, height, opaque, target);
31 | if (!rawTexture.isLoaded()) {
32 | rawTexture.prepare(canvasGL.getGlCanvas());
33 | }
34 | SurfaceTexture surfaceTexture = new SurfaceTexture(rawTexture.getId());
35 | return new GLTexture(rawTexture, surfaceTexture);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/GLTextureView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.glview.texture;
22 |
23 | import android.content.Context;
24 | import android.graphics.SurfaceTexture;
25 | import android.util.AttributeSet;
26 |
27 | /**
28 | * Created by Chilling on 2016/11/5.
29 | */
30 |
31 | public abstract class GLTextureView extends BaseGLCanvasTextureView {
32 | public GLTextureView(Context context) {
33 | super(context);
34 | }
35 |
36 | public GLTextureView(Context context, AttributeSet attrs) {
37 | super(context, attrs);
38 | }
39 |
40 | public GLTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
41 | super(context, attrs, defStyleAttr);
42 | }
43 |
44 |
45 | @Override
46 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
47 | super.onSurfaceTextureAvailable(surface, width, height);
48 | if (mGLThread == null) {
49 | createGLThread();
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/GLViewRenderer.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.glview.texture;
2 |
3 | /**
4 | * Created by Chilling on 2016/12/29.
5 | */
6 |
7 | public interface GLViewRenderer {
8 |
9 | void onSurfaceCreated();
10 |
11 | void onSurfaceChanged(int width, int height);
12 |
13 | void onDrawFrame();
14 | }
15 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/gles/EglContextWrapper.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.glview.texture.gles;
2 |
3 | import android.opengl.EGL14;
4 | import android.os.Build;
5 |
6 | import javax.microedition.khronos.egl.EGL10;
7 | import javax.microedition.khronos.egl.EGLContext;
8 |
9 | /**
10 | * Created by Chilling on 2016/12/29.
11 | */
12 |
13 | public class EglContextWrapper {
14 |
15 | protected EGLContext eglContextOld;
16 | protected android.opengl.EGLContext eglContext;
17 | public static EglContextWrapper EGL_NO_CONTEXT_WRAPPER = new EGLNoContextWrapper();
18 |
19 | public EGLContext getEglContextOld() {
20 | return eglContextOld;
21 | }
22 |
23 | public void setEglContextOld(EGLContext eglContextOld) {
24 | this.eglContextOld = eglContextOld;
25 | }
26 |
27 | public android.opengl.EGLContext getEglContext() {
28 | return eglContext;
29 | }
30 |
31 | public void setEglContext(android.opengl.EGLContext eglContext) {
32 | this.eglContext = eglContext;
33 | }
34 |
35 |
36 | public static class EGLNoContextWrapper extends EglContextWrapper {
37 |
38 | public EGLNoContextWrapper() {
39 | eglContextOld = EGL10.EGL_NO_CONTEXT;
40 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
41 | eglContext = EGL14.EGL_NO_CONTEXT;
42 | }
43 | }
44 |
45 | @Override
46 | public void setEglContext(android.opengl.EGLContext eglContext) {
47 | }
48 |
49 | @Override
50 | public void setEglContextOld(EGLContext eglContextOld) {
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/gles/EglHelperFactory.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.glview.texture.gles;
2 |
3 | import android.os.Build;
4 |
5 | /**
6 | * Created by Chilling on 2017/1/2.
7 | */
8 |
9 | public class EglHelperFactory {
10 |
11 | public static IEglHelper create(GLThread.EGLConfigChooser configChooser, GLThread.EGLContextFactory eglContextFactory
12 | , GLThread.EGLWindowSurfaceFactory eglWindowSurfaceFactory) {
13 |
14 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
15 | return new EglHelperAPI17(configChooser, eglContextFactory, eglWindowSurfaceFactory);
16 | } else {
17 | return new EglHelper(configChooser, eglContextFactory, eglWindowSurfaceFactory);
18 | }
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/gles/IEglHelper.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.glview.texture.gles;
2 |
3 | /**
4 | * Created by Chilling on 2016/12/29.
5 | */
6 | public interface IEglHelper {
7 | EglContextWrapper start(EglContextWrapper eglContext);
8 |
9 | boolean createSurface(Object surface);
10 |
11 | int swap();
12 |
13 | void destroySurface();
14 |
15 | void finish();
16 |
17 | void setPresentationTime(long nsecs);
18 | }
19 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/matrix/BaseBitmapMatrix.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.matrix;
2 |
3 | import android.opengl.Matrix;
4 |
5 | import java.util.Arrays;
6 |
7 | /**
8 | * Created by Chilling on 2018/11/17.
9 | */
10 | public abstract class BaseBitmapMatrix implements IBitmapMatrix {
11 |
12 | public static final int TRANSLATE_X = 0;
13 | public static final int TRANSLATE_Y = 1;
14 | public static final int SCALE_X = 2;
15 | public static final int SCALE_Y = 3;
16 | public static final int ROTATE_X = 4;
17 | public static final int ROTATE_Y = 5;
18 | public static final int ROTATE_Z = 6;
19 | public static final int MATRIX_SIZE = 16;
20 | public final static float NEAR = 1;
21 | public final static float FAR = 10; // The plane is at -10
22 | public final static float EYEZ = 5;
23 | public final static float Z_RATIO = (FAR + NEAR) / 2 / NEAR; // The scale ratio when the picture moved to the middle of the perspective projection.
24 | protected float[] transform = new float[7];
25 | protected float[] tempMultiplyMatrix4 = new float[MATRIX_SIZE];
26 | protected float[] mViewMatrix = new float[MATRIX_SIZE];
27 | protected float[] mProjectionMatrix = new float[MATRIX_SIZE];
28 | protected float[] mModelMatrix = new float[MATRIX_SIZE];
29 | protected float[] viewProjectionMatrix = new float[MATRIX_SIZE];
30 | protected float[] mvp = new float[MATRIX_SIZE];
31 |
32 | public void reset() {
33 | Matrix.setIdentityM(mViewMatrix, 0);
34 | Matrix.setIdentityM(mProjectionMatrix, 0);
35 | Matrix.setIdentityM(mModelMatrix, 0);
36 | Matrix.setIdentityM(viewProjectionMatrix, 0);
37 | Matrix.setIdentityM(mvp, 0);
38 |
39 | Matrix.setIdentityM(tempMultiplyMatrix4, 0);
40 | Arrays.fill(transform, 0);
41 | transform[SCALE_X] = 1;
42 | transform[SCALE_Y] = 1;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/matrix/IBitmapMatrix.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.matrix;
2 |
3 | /**
4 | * Created by Chilling on 2018/11/17.
5 | *
6 | * The output is MVP matrix of OpenGL, which is used to calculate gl_position.
7 | * gl_position = MVP * [x,y,z,w]
8 | */
9 | public interface IBitmapMatrix {
10 | float[] obtainResultMatrix(int viewportW, int viewportH, float x, float y, float drawW, float drawH);
11 | }
12 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/shapeFilter/BasicDrawShapeFilter.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.shapeFilter;
2 |
3 | import com.chillingvan.canvasgl.ICanvasGL;
4 | import com.chillingvan.canvasgl.glcanvas.GLES20Canvas;
5 |
6 | /**
7 | * Created by Chilling on 2016/11/11.
8 | */
9 |
10 | public class BasicDrawShapeFilter implements DrawShapeFilter {
11 | public static final String MATRIX_UNIFORM = GLES20Canvas.MATRIX_UNIFORM;
12 | public static final String POSITION_ATTRIBUTE = GLES20Canvas.POSITION_ATTRIBUTE;
13 | public static final String COLOR_UNIFORM = GLES20Canvas.COLOR_UNIFORM;
14 |
15 | public static final String DRAW_VERTEX_SHADER = ""
16 | + "uniform mat4 " + MATRIX_UNIFORM + ";\n"
17 | + "attribute vec2 " + POSITION_ATTRIBUTE + ";\n"
18 | + "void main() {\n"
19 | + " vec4 pos = vec4(" + POSITION_ATTRIBUTE + ", 0.0, 1.0);\n"
20 | + " gl_Position = " + MATRIX_UNIFORM + " * pos;\n"
21 | + "}\n";
22 |
23 | public static final String DRAW_FRAGMENT_SHADER = ""
24 | + "precision mediump float;\n"
25 | + "uniform vec4 " + COLOR_UNIFORM + ";\n"
26 | + "void main() {\n"
27 | + " gl_FragColor = " + COLOR_UNIFORM + ";\n"
28 | + "}\n";
29 |
30 | @Override
31 | public String getVertexShader() {
32 | return DRAW_VERTEX_SHADER;
33 | }
34 |
35 | @Override
36 | public String getFragmentShader() {
37 | return DRAW_FRAGMENT_SHADER;
38 | }
39 |
40 | @Override
41 | public void onPreDraw(int program, ICanvasGL canvas) {
42 |
43 | }
44 |
45 | @Override
46 | public void destroy() {
47 |
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/shapeFilter/DrawCircleFilter.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.shapeFilter;
2 |
3 | import android.opengl.GLES20;
4 |
5 | import com.chillingvan.canvasgl.ICanvasGL;
6 | import com.chillingvan.canvasgl.OpenGLUtil;
7 |
8 | import androidx.annotation.FloatRange;
9 |
10 | /**
11 | * Created by Chilling on 2016/11/11.
12 | */
13 |
14 | public class DrawCircleFilter extends BasicDrawShapeFilter {
15 |
16 | public static final String VARYING_DRAW_REGION_COORD = "vDrawRegionCoord";
17 |
18 | public static final String CIRCLE_VERTEX_SHADER = ""
19 | + "uniform mat4 " + MATRIX_UNIFORM + ";\n"
20 | + "attribute vec2 " + POSITION_ATTRIBUTE + ";\n"
21 | + "varying vec2 " + VARYING_DRAW_REGION_COORD + ";\n"
22 | + "void main() {\n"
23 | + " vec4 pos = vec4(" + POSITION_ATTRIBUTE + ", 0.0, 1.0);\n"
24 | + " gl_Position = " + MATRIX_UNIFORM + " * pos;\n"
25 | + " " + VARYING_DRAW_REGION_COORD + " = pos.xy;\n"
26 | + "}\n";
27 |
28 | public static final String UNIFORM_LINE_WIDTH = "lineWidth";
29 | public static final String CIRCLE_FRAGMENT_SHADER = ""
30 | + "precision mediump float;\n"
31 | + "varying vec2 " + VARYING_DRAW_REGION_COORD + ";\n"
32 | + "uniform vec4 " + COLOR_UNIFORM + ";\n"
33 | + "uniform float " + UNIFORM_LINE_WIDTH + ";\n"
34 | + "void main() {\n"
35 | + " float dx = " + VARYING_DRAW_REGION_COORD + ".x - 0.5;\n"
36 | + " float dy = " + VARYING_DRAW_REGION_COORD + ".y - 0.5;\n"
37 | + " float powVal = dx*dx + dy*dy; \n"
38 | + " float subRadius = 0.5 - " + UNIFORM_LINE_WIDTH + "; \n"
39 | + " if(powVal >= subRadius * subRadius && powVal <= 0.5 * 0.5) {\n"
40 | + " gl_FragColor = " + COLOR_UNIFORM + ";\n"
41 | + " } else {\n"
42 | + " gl_FragColor = vec4(0, 0, 0, 0);\n"
43 | + " }\n"
44 | + " \n"
45 | + "}\n";
46 |
47 | private float lineWidth;
48 |
49 | public void setLineWidth(@FloatRange(from = 0, to = 0.5) float lineWidth) {
50 | this.lineWidth = lineWidth;
51 | }
52 |
53 | @Override
54 | public String getVertexShader() {
55 | return CIRCLE_VERTEX_SHADER;
56 | }
57 |
58 | @Override
59 | public String getFragmentShader() {
60 | return CIRCLE_FRAGMENT_SHADER;
61 | }
62 |
63 | @Override
64 | public void onPreDraw(int program, ICanvasGL canvas) {
65 | super.onPreDraw(program, canvas);
66 | int lineWidthLocation = GLES20.glGetUniformLocation(program, UNIFORM_LINE_WIDTH);
67 | OpenGLUtil.setFloat(lineWidthLocation, lineWidth);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/shapeFilter/DrawShapeFilter.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.shapeFilter;
2 |
3 | import com.chillingvan.canvasgl.ICanvasGL;
4 |
5 | /**
6 | * Created by Chilling on 2016/11/11.
7 | */
8 |
9 | public interface DrawShapeFilter {
10 | String getVertexShader();
11 | String getFragmentShader();
12 |
13 | void onPreDraw(int program, ICanvasGL canvas);
14 | void destroy();
15 | }
16 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/textureFilter/ColorMatrixFilter.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.textureFilter;
2 |
3 | import android.opengl.GLES20;
4 |
5 | import com.chillingvan.canvasgl.ICanvasGL;
6 | import com.chillingvan.canvasgl.OpenGLUtil;
7 | import com.chillingvan.canvasgl.glcanvas.BasicTexture;
8 |
9 | import androidx.annotation.FloatRange;
10 |
11 | /**
12 | * Created by Chilling on 2017/4/15.
13 | */
14 |
15 | public class ColorMatrixFilter extends BasicTextureFilter implements OneValueFilter{
16 |
17 | public static final String UNIFORM_COLOR_MATRIX = "colorMatrix";
18 | public static final String UNIFORM_INTENSITY = "intensity";
19 | public static final String COLOR_MATRIX_FRAGMENT_SHADER = "" +
20 | "precision mediump float; \n"+
21 | "varying highp vec2 " + VARYING_TEXTURE_COORD + ";\n" +
22 | "\n" +
23 | "uniform sampler2D " + TEXTURE_SAMPLER_UNIFORM + ";\n" +
24 | "\n" +
25 | "uniform lowp mat4 " + UNIFORM_COLOR_MATRIX + ";\n" +
26 | "uniform lowp float " + UNIFORM_INTENSITY + ";\n" +
27 | " uniform float " + ALPHA_UNIFORM + ";\n" +
28 | "\n" +
29 | "void main() {\n" +
30 | "" +
31 | " lowp vec4 textureColor = texture2D(" + TEXTURE_SAMPLER_UNIFORM + ", " + VARYING_TEXTURE_COORD + ");\n" +
32 | " lowp vec4 outputColor = textureColor * " + UNIFORM_COLOR_MATRIX + ";\n" +
33 | " \n" +
34 | " gl_FragColor = (" + UNIFORM_INTENSITY + " * outputColor) + ((1.0 - intensity) * textureColor);\n" +
35 | " gl_FragColor *= " + ALPHA_UNIFORM + ";\n" +
36 | "}";
37 |
38 | private float mIntensity;
39 | private float[] mColorMatrix;
40 |
41 | public ColorMatrixFilter(@FloatRange(from = 0, to = 1) final float intensity, final float[] colorMatrix) {
42 | mIntensity = intensity;
43 | mColorMatrix = colorMatrix;
44 | }
45 |
46 | public void setIntensity(@FloatRange(from = 0, to = 1) final float intensity) {
47 | mIntensity = intensity;
48 | }
49 |
50 | public void setColorMatrix(final float[] colorMatrix) {
51 | mColorMatrix = colorMatrix;
52 | }
53 |
54 | @Override
55 | public String getFragmentShader() {
56 | return COLOR_MATRIX_FRAGMENT_SHADER;
57 | }
58 |
59 | @Override
60 | public void onPreDraw(int program, BasicTexture texture, ICanvasGL canvas) {
61 | super.onPreDraw(program, texture, canvas);
62 | OpenGLUtil.setFloat(GLES20.glGetUniformLocation(program, UNIFORM_INTENSITY), mIntensity);
63 | OpenGLUtil.setUniformMatrix4f(GLES20.glGetUniformLocation(program, UNIFORM_COLOR_MATRIX), mColorMatrix);
64 | }
65 |
66 | @Override
67 | public void setValue(float value) {
68 | setIntensity(value);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/textureFilter/ContrastFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.textureFilter;
22 |
23 | import android.opengl.GLES20;
24 |
25 | import com.chillingvan.canvasgl.ICanvasGL;
26 | import com.chillingvan.canvasgl.OpenGLUtil;
27 | import com.chillingvan.canvasgl.glcanvas.BasicTexture;
28 |
29 | import androidx.annotation.FloatRange;
30 |
31 | /**
32 | * Created by Matthew on 2016/10/14.
33 | */
34 |
35 |
36 | /**
37 | * Changes the contrast of the image.
38 | *
39 | * contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
40 | */
41 | public class ContrastFilter extends BasicTextureFilter implements OneValueFilter{
42 |
43 | public static final String UNIFORM_CONTRAST = "contrast";
44 | public static final String CONTRAST_FRAGMENT_SHADER = ""
45 | + "precision mediump float;\n"
46 | + "varying vec2 " + VARYING_TEXTURE_COORD + ";\n"
47 | + "uniform float " + ALPHA_UNIFORM + ";\n"
48 | + "uniform float " + UNIFORM_CONTRAST + ";\n"
49 | + "uniform sampler2D " + TEXTURE_SAMPLER_UNIFORM + ";\n"
50 | + "void main() {\n"
51 | + " vec4 textureColor = texture2D(" + TEXTURE_SAMPLER_UNIFORM + ", " + VARYING_TEXTURE_COORD + ");\n"
52 | + " gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * " + UNIFORM_CONTRAST + "+ vec3(0.5)), textureColor.w);\n"
53 | + " gl_FragColor *= " + ALPHA_UNIFORM + ";\n"
54 | + "}\n";
55 |
56 | private float mContrast;
57 |
58 |
59 | public ContrastFilter(@FloatRange(from = 0.0, to = 4.0f) float contrast) {
60 | super();
61 | mContrast = contrast;
62 | }
63 |
64 |
65 | @Override
66 | public String getFragmentShader() {
67 | return CONTRAST_FRAGMENT_SHADER;
68 | }
69 |
70 |
71 | @Override
72 | public void onPreDraw(int program, BasicTexture texture, ICanvasGL canvas) {
73 | super.onPreDraw(program, texture, canvas);
74 | int contrastLocation = GLES20.glGetUniformLocation(program, UNIFORM_CONTRAST);
75 | OpenGLUtil.setFloat(contrastLocation, mContrast);
76 | }
77 |
78 | @Override
79 | public void setValue(@FloatRange(from = 0.0, to = 4.0f) final float contrast) {
80 | mContrast = contrast;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/textureFilter/CropFilter.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.textureFilter;
2 |
3 | import android.opengl.GLES20;
4 |
5 | import com.chillingvan.canvasgl.ICanvasGL;
6 | import com.chillingvan.canvasgl.OpenGLUtil;
7 | import com.chillingvan.canvasgl.glcanvas.BasicTexture;
8 |
9 | /**
10 | * Created by Chilling on 2018/7/5.
11 | */
12 | public class CropFilter extends BasicTextureFilter {
13 |
14 | private static final String UNIFORM_LEFT = "left";
15 | private static final String UNIFORM_TOP = "top";
16 | private static final String UNIFORM_RIGHT = "right";
17 | private static final String UNIFORM_BOTTOM = "bottom";
18 |
19 | private static final String CROP_FRAGMENT_SHADER = ""
20 | + "precision mediump float;\n"
21 | + "varying vec2 " + VARYING_TEXTURE_COORD + ";\n"
22 | + "uniform float " + ALPHA_UNIFORM + ";\n"
23 | + "uniform " + SAMPLER_2D + " " + TEXTURE_SAMPLER_UNIFORM + ";\n"
24 | + " uniform highp float " + UNIFORM_LEFT + ";\n"
25 | + " uniform highp float " + UNIFORM_TOP + ";\n"
26 | + " uniform highp float " + UNIFORM_RIGHT + ";\n"
27 | + " uniform highp float " + UNIFORM_BOTTOM + ";\n"
28 | + "void main() {\n"
29 | + "if( " + VARYING_TEXTURE_COORD + ".x > " + UNIFORM_LEFT + " && " + VARYING_TEXTURE_COORD + ".x < " + UNIFORM_RIGHT +
30 | " && " + VARYING_TEXTURE_COORD + ".y > " + UNIFORM_TOP + " && " + VARYING_TEXTURE_COORD + ".y < " + UNIFORM_BOTTOM + ") {"
31 | + " gl_FragColor = texture2D(" + TEXTURE_SAMPLER_UNIFORM + ", " + VARYING_TEXTURE_COORD + ");\n"
32 | + "} else {"
33 | + " gl_FragColor = " + "vec4(0, 0, 0, 0)" + ";\n"
34 | + "}"
35 | + "}\n";
36 |
37 | private float left;
38 | private float right;
39 | private float top;
40 | private float bottom;
41 |
42 |
43 | public CropFilter(float left, float top, float right, float bottom) {
44 | this.left = left;
45 | this.right = right;
46 | this.top = top;
47 | this.bottom = bottom;
48 | }
49 |
50 | @Override
51 | public String getFragmentShader() {
52 | return CROP_FRAGMENT_SHADER;
53 | }
54 |
55 | @Override
56 | public void onPreDraw(int program, BasicTexture texture, ICanvasGL canvas) {
57 | super.onPreDraw(program, texture, canvas);
58 | OpenGLUtil.setFloat(GLES20.glGetUniformLocation(program, UNIFORM_LEFT), left);
59 | OpenGLUtil.setFloat(GLES20.glGetUniformLocation(program, UNIFORM_TOP), top);
60 | OpenGLUtil.setFloat(GLES20.glGetUniformLocation(program, UNIFORM_RIGHT), right);
61 | OpenGLUtil.setFloat(GLES20.glGetUniformLocation(program, UNIFORM_BOTTOM), bottom);
62 | }
63 |
64 |
65 | public void setLeft(float left) {
66 |
67 | this.left = left;
68 | }
69 |
70 | public void setRight(float right) {
71 |
72 | this.right = right;
73 | }
74 |
75 | public void setTop(float top) {
76 |
77 | this.top = top;
78 | }
79 |
80 | public void setBottom(float bottom) {
81 |
82 | this.bottom = bottom;
83 | }
84 |
85 | public static float calc(int wantCoord, int size) {
86 | return (float)wantCoord / size;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/textureFilter/DarkenBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.textureFilter;
22 |
23 | import android.graphics.Bitmap;
24 | import androidx.annotation.NonNull;
25 |
26 | /**
27 | * Created by Chilling on 2016/10/17.
28 | */
29 |
30 | public class DarkenBlendFilter extends TwoTextureFilter {
31 |
32 | public static final String DARKEN_BLEND_FRAGMENT_SHADER =
33 | "precision mediump float; \n" +
34 | "varying vec2 " + VARYING_TEXTURE_COORD + ";\n" +
35 | " varying vec2 " + VARYING_TEXTURE_COORD2 + ";\n" +
36 | "\n" +
37 | " uniform sampler2D " + TEXTURE_SAMPLER_UNIFORM + ";\n" +
38 | " uniform sampler2D " + UNIFORM_TEXTURE_SAMPLER2 + ";\n" +
39 | " \n" +
40 | " void main() {\n" +
41 | " " +
42 | " lowp vec4 base = texture2D(" + TEXTURE_SAMPLER_UNIFORM + ", " + VARYING_TEXTURE_COORD + ");\n" +
43 | " lowp vec4 overlayer = texture2D(" + UNIFORM_TEXTURE_SAMPLER2 + ", " + VARYING_TEXTURE_COORD2 + ");\n" +
44 | " \n" +
45 | " gl_FragColor = vec4(min(overlayer.rgb * base.a, base.rgb * overlayer.a) + overlayer.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlayer.a), 1.0);\n" +
46 | " }";
47 |
48 | public DarkenBlendFilter(@NonNull Bitmap bitmap) {
49 | super(bitmap);
50 | }
51 |
52 | public DarkenBlendFilter() {
53 | super();
54 | }
55 |
56 | @Override
57 | public String getFragmentShader() {
58 | return DARKEN_BLEND_FRAGMENT_SHADER;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/textureFilter/GammaFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.textureFilter;
22 |
23 | import android.opengl.GLES20;
24 |
25 | import com.chillingvan.canvasgl.ICanvasGL;
26 | import com.chillingvan.canvasgl.OpenGLUtil;
27 | import com.chillingvan.canvasgl.glcanvas.BasicTexture;
28 |
29 | import androidx.annotation.FloatRange;
30 |
31 | /**
32 | * Created by Chilling on 2016/11/2.
33 | */
34 |
35 |
36 | /**
37 | * gamma value ranges from 0.0 to 3.0, with 1.0 as the normal level
38 | */
39 | public class GammaFilter extends BasicTextureFilter implements OneValueFilter {
40 |
41 | public static final String UNIFORM_GAMMA = "gamma";
42 | public static final String GAMMA_FRAGMENT_SHADER = "" +
43 | "precision mediump float; \n" +
44 | "varying vec2 " + VARYING_TEXTURE_COORD + ";\n" +
45 | " \n" +
46 | " uniform sampler2D " + TEXTURE_SAMPLER_UNIFORM + ";\n" +
47 | " uniform lowp float " + UNIFORM_GAMMA + ";\n" +
48 | " uniform float " + ALPHA_UNIFORM + ";\n" +
49 | " \n" +
50 | " void main() {\n" +
51 | " " +
52 | " lowp vec4 textureColor = texture2D(" + TEXTURE_SAMPLER_UNIFORM + ", " + VARYING_TEXTURE_COORD + ");\n" +
53 | " \n" +
54 | " gl_FragColor = vec4(pow(textureColor.rgb, vec3(" + UNIFORM_GAMMA + ")), textureColor.w);\n" +
55 | " gl_FragColor *= " + ALPHA_UNIFORM + ";\n" +
56 | " }";
57 | private float mGamma;
58 | private int mGammaLocation;
59 |
60 | public GammaFilter(@FloatRange(from = 0, to = 3) float mGamma) {
61 | this.mGamma = mGamma;
62 | }
63 |
64 | @Override
65 | public String getFragmentShader() {
66 | return GAMMA_FRAGMENT_SHADER;
67 | }
68 |
69 | @Override
70 | public void onPreDraw(int program, BasicTexture texture, ICanvasGL canvas) {
71 | super.onPreDraw(program, texture, canvas);
72 | mGammaLocation = GLES20.glGetUniformLocation(program, UNIFORM_GAMMA);
73 | OpenGLUtil.setFloat(mGammaLocation, mGamma);
74 | }
75 |
76 | @Override
77 | public void setValue(@FloatRange(from = 0, to = 3) float gamma) {
78 | mGamma = gamma;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/textureFilter/LightenBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.textureFilter;
22 |
23 | import android.graphics.Bitmap;
24 | import androidx.annotation.NonNull;
25 |
26 | /**
27 | * Created by Chilling on 2016/10/23.
28 | */
29 |
30 | public class LightenBlendFilter extends TwoTextureFilter {
31 | public static final String LIGHTEN_BLEND_FRAGMENT_SHADER =
32 | "precision mediump float; \n"+
33 | "varying vec2 " + VARYING_TEXTURE_COORD + ";\n" +
34 | " varying vec2 " + VARYING_TEXTURE_COORD2 + ";\n" +
35 | "\n" +
36 | " uniform sampler2D " + TEXTURE_SAMPLER_UNIFORM + ";\n" +
37 | " uniform sampler2D " + UNIFORM_TEXTURE_SAMPLER2 + ";\n" +
38 | " \n" +
39 | " void main() {\n" +
40 | " " +
41 | " lowp vec4 textureColor = texture2D(" + TEXTURE_SAMPLER_UNIFORM + ", " + VARYING_TEXTURE_COORD + ");\n" +
42 | " lowp vec4 textureColor2 = texture2D(" + UNIFORM_TEXTURE_SAMPLER2 + ", " + VARYING_TEXTURE_COORD2 + ");\n" +
43 | " \n" +
44 | " gl_FragColor = max(textureColor, textureColor2);\n" +
45 | " }";
46 |
47 |
48 | public LightenBlendFilter(@NonNull Bitmap bitmap) {
49 | super(bitmap);
50 | }
51 |
52 | public LightenBlendFilter() {
53 | }
54 |
55 | @Override
56 | public String getFragmentShader() {
57 | return LIGHTEN_BLEND_FRAGMENT_SHADER;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/textureFilter/OneValueFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.textureFilter;
22 |
23 | /**
24 | * Created by Chilling on 2016/11/1.
25 | */
26 |
27 | public interface OneValueFilter {
28 |
29 | void setValue(float value);
30 | }
31 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/textureFilter/RGBFilter.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.textureFilter;
2 |
3 | import android.opengl.GLES20;
4 |
5 | import com.chillingvan.canvasgl.ICanvasGL;
6 | import com.chillingvan.canvasgl.OpenGLUtil;
7 | import com.chillingvan.canvasgl.glcanvas.BasicTexture;
8 |
9 | import androidx.annotation.FloatRange;
10 |
11 | /**
12 | * Created by Chilling on 2017/4/15.
13 | */
14 |
15 | public class RGBFilter extends BasicTextureFilter implements OneValueFilter {
16 |
17 | public static final String UNIFORM_RED = "red";
18 | public static final String UNIFORM_GREEN = "green";
19 | public static final String UNIFORM_BLUE = "blue";
20 | public static final String RGB_FRAGMENT_SHADER = "" +
21 | "precision mediump float; \n"+
22 | " varying highp vec2 " + VARYING_TEXTURE_COORD + ";\n" +
23 | " \n" +
24 | " uniform sampler2D " + TEXTURE_SAMPLER_UNIFORM + ";\n" +
25 | " uniform highp float " + UNIFORM_RED + ";\n" +
26 | " uniform highp float " + UNIFORM_GREEN + ";\n" +
27 | " uniform highp float " + UNIFORM_BLUE + ";\n" +
28 | " uniform float " + ALPHA_UNIFORM + ";\n" +
29 | " \n" +
30 | " void main() {\n" +
31 | " " +
32 | " highp vec4 textureColor = texture2D(" + TEXTURE_SAMPLER_UNIFORM + ", " + VARYING_TEXTURE_COORD + ");\n" +
33 | " \n" +
34 | " gl_FragColor = vec4(textureColor.r * " + UNIFORM_RED + ", textureColor.g * " + UNIFORM_GREEN + ", textureColor.b * " + UNIFORM_BLUE + ", textureColor.w);\n" +
35 | " gl_FragColor *= " + ALPHA_UNIFORM + ";\n" +
36 | " }\n";
37 | private float red;
38 | private float green;
39 | private float blue;
40 |
41 |
42 | public RGBFilter(@FloatRange(from = 0, to = 1) float red, float green, float blue) {
43 | this.red = red;
44 | this.green = green;
45 | this.blue = blue;
46 | }
47 |
48 |
49 | public void setRed(@FloatRange(from = 0, to = 1) final float value) {
50 | red = value;
51 | }
52 |
53 | public void setGreen(final float value) {
54 | green = value;
55 | }
56 |
57 | public void setBlue(final float value) {
58 | blue = value;
59 | }
60 |
61 | @Override
62 | public String getFragmentShader() {
63 | return RGB_FRAGMENT_SHADER;
64 | }
65 |
66 | @Override
67 | public void onPreDraw(int program, BasicTexture texture, ICanvasGL canvas) {
68 | super.onPreDraw(program, texture, canvas);
69 | OpenGLUtil.setFloat(GLES20.glGetUniformLocation(program, UNIFORM_RED), red);
70 | OpenGLUtil.setFloat(GLES20.glGetUniformLocation(program, UNIFORM_GREEN), green);
71 | OpenGLUtil.setFloat(GLES20.glGetUniformLocation(program, UNIFORM_BLUE), blue);
72 | }
73 |
74 | @Override
75 | public void setValue(float value) {
76 | setRed(value);
77 | setGreen(value);
78 | setBlue(value);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/textureFilter/TextureFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.textureFilter;
22 |
23 | import com.chillingvan.canvasgl.ICanvasGL;
24 | import com.chillingvan.canvasgl.glcanvas.BasicTexture;
25 | import com.chillingvan.canvasgl.glcanvas.GLCanvas;
26 |
27 | /**
28 | * Created by Matthew on 2016/10/14.
29 | */
30 |
31 | public interface TextureFilter {
32 | String getVertexShader();
33 | String getFragmentShader();
34 |
35 | String getOesFragmentProgram();
36 |
37 | void onPreDraw(int program, BasicTexture texture, ICanvasGL canvas);
38 | void destroy();
39 | }
40 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/util/FileUtil.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasgl.util;
2 |
3 | import android.text.TextUtils;
4 |
5 | import java.io.File;
6 | import java.io.FileWriter;
7 |
8 | public class FileUtil {
9 |
10 | public synchronized static File createFile(String path) {
11 | if (TextUtils.isEmpty(path)) {
12 | return null;
13 | }
14 |
15 | File file = new File(path);
16 | if (file.isFile()) {
17 | return file;
18 | }
19 |
20 | File parentFile = file.getParentFile();
21 | if (parentFile != null && (parentFile.isDirectory() || parentFile.mkdirs())) {
22 | try {
23 | if (file.createNewFile()) {
24 | return file;
25 | }
26 | } catch (Exception e) {
27 | e.printStackTrace();
28 | }
29 | }
30 |
31 | return null;
32 | }
33 |
34 | public synchronized static boolean delete(File path) {
35 | if (null == path) {
36 | return true;
37 | }
38 |
39 | if (path.isDirectory()) {
40 | File[] files = path.listFiles();
41 | if (null != files) {
42 | for (File file : files) {
43 | if (!delete(file)) {
44 | return false;
45 | }
46 | }
47 | }
48 | }
49 | return !path.exists() || path.delete();
50 | }
51 |
52 | public static void writeToFile(String content, String filePath) {
53 | FileWriter fileWriter = null;
54 | try {
55 | fileWriter = new FileWriter(filePath, true);
56 | fileWriter.write(content);
57 | fileWriter.flush();
58 | } catch (Throwable t) {
59 | t.printStackTrace();
60 | } finally {
61 | if (fileWriter != null) {
62 | try {
63 | fileWriter.close();
64 | } catch (Exception e) {
65 | e.printStackTrace();
66 | }
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/canvasgl/src/main/java/com/chillingvan/canvasgl/util/Loggers.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasgl.util;
22 |
23 | import android.util.Log;
24 |
25 | /**
26 | * Created by Chilling on 2016/11/4.
27 | */
28 |
29 | public class Loggers {
30 |
31 | public static boolean DEBUG = false;
32 |
33 | public static void d(String tag, String msg) {
34 | if (DEBUG) {
35 | Log.d(tag, msg);
36 | }
37 | }
38 |
39 | public static void v(String tag, String msg) {
40 | if (DEBUG) {
41 | Log.v(tag, msg);
42 | }
43 | }
44 |
45 | public static void i(String tag, String msg) {
46 | if (DEBUG) {
47 | Log.i(tag, msg);
48 | }
49 | }
50 |
51 | public static void w(String tag, String msg) {
52 | if (DEBUG) {
53 | Log.w(tag, msg);
54 | }
55 | }
56 |
57 | public static void e(String tag, String msg) {
58 | if (DEBUG) {
59 | Log.e(tag, msg);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/canvasglsample/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/canvasglsample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/canvasglsample/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | canvasglsample
4 | Project canvasglsample created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.buildship.core.gradleprojectbuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.buildship.core.gradleprojectnature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/canvasglsample/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | connection.project.dir=..
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/canvasglsample/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | apply plugin: 'com.android.application'
22 | apply plugin: 'kotlin-android'
23 | apply plugin: 'kotlin-android-extensions'
24 |
25 | android {
26 | compileSdkVersion 32
27 |
28 | defaultConfig {
29 | applicationId "com.chillingvan.canvasglsample"
30 | minSdkVersion 15
31 | targetSdkVersion 32
32 | versionCode 10
33 | versionName "1.5.3.0"
34 |
35 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
36 |
37 | }
38 | buildTypes {
39 | release {
40 | minifyEnabled false
41 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
42 | }
43 | }
44 | lintOptions {
45 | checkReleaseBuilds false
46 | // Or, if you prefer, you can continue to check for errors in release builds,
47 | // but continue the build even when errors are found:
48 | abortOnError false
49 | }
50 |
51 | }
52 |
53 | repositories {
54 | maven {
55 | url "https://jitpack.io"
56 | }
57 | }
58 |
59 | dependencies {
60 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
61 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
62 | implementation fileTree(include: ['*.jar'], dir: 'libs')
63 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
64 | exclude group: 'com.android.support', module: 'support-annotations'
65 | })
66 | implementation 'androidx.appcompat:appcompat:1.4.2'
67 | implementation 'androidx.recyclerview:recyclerview:1.2.1'
68 | implementation 'jp.co.cyberagent.android:gpuimage:2.1.0'
69 | implementation 'com.github.tajchert:nammu:1.5.1'
70 | implementation project(':canvasgl')
71 | }
72 |
--------------------------------------------------------------------------------
/canvasglsample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\develop-win\android\dev-tools-win\android-studio-windows\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/assets/test_video.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/assets/test_video.mp4
--------------------------------------------------------------------------------
/canvasglsample/src/main/assets/test_video_2.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/assets/test_video_2.mp4
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/CrashHandler.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample;
2 |
3 | import android.content.Context;
4 |
5 | import java.io.File;
6 | import java.io.FileOutputStream;
7 | import java.io.IOException;
8 | import java.io.PrintWriter;
9 | import java.io.StringWriter;
10 | import java.io.Writer;
11 | import java.text.DateFormat;
12 | import java.text.SimpleDateFormat;
13 | import java.util.Date;
14 |
15 | /**
16 | * Created by ling on 16-3-27.
17 | */
18 | public class CrashHandler implements Thread.UncaughtExceptionHandler {
19 |
20 | private static CrashHandler INSTANCE = new CrashHandler();
21 | private static Context mContext;
22 | public static String CRASH_PATH;
23 |
24 | private Thread.UncaughtExceptionHandler mDefaultHandler;
25 |
26 | private CrashHandler() {
27 | mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
28 | Thread.setDefaultUncaughtExceptionHandler(this);
29 | }
30 |
31 | public static CrashHandler init(Context applicationContext) {
32 | if (mContext == null) {
33 | mContext = applicationContext;
34 | CRASH_PATH = mContext.getExternalFilesDir(null) + File.separator + "crash";
35 | }
36 | return INSTANCE;
37 | }
38 |
39 | @Override
40 | public void uncaughtException(Thread thread, Throwable ex) {
41 | handleException(ex);
42 | mDefaultHandler.uncaughtException(thread, ex);
43 | }
44 |
45 | private boolean handleException(Throwable ex) {
46 | if (ex == null) {
47 | return false;
48 | }
49 | saveErrorInfo(ex);
50 |
51 | return true;
52 | }
53 |
54 | private void saveErrorInfo(Throwable ex) {
55 | File path = new File(CRASH_PATH);
56 | if (!path.exists()) {
57 | path.mkdirs();
58 | }
59 |
60 | File file = new File(CRASH_PATH + File.separator + convertYYMMDDHHmm(System.currentTimeMillis()) + ".txt");
61 | FileOutputStream fos = null;
62 | try {
63 | fos = new FileOutputStream(file);
64 | if (!file.exists()) {
65 | file.createNewFile();
66 | }
67 | Writer writer = new StringWriter();
68 | PrintWriter pw = new PrintWriter(writer);
69 | ex.printStackTrace(pw);
70 | pw.close();
71 | String error= writer.toString();
72 | fos.write(error.getBytes());
73 | } catch (IOException e) {
74 | e.printStackTrace();
75 | } finally {
76 | try {
77 | if (fos != null) {
78 | fos.close();
79 | }
80 | } catch (IOException e) {
81 | e.printStackTrace();
82 | }
83 | }
84 | }
85 |
86 | private static String convertYYMMDDHHmm(long time) {
87 | Date date = new Date(time);
88 | DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
89 | return dateFormat.format(date);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/MainApplication.kt:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample
2 |
3 | import android.app.Application
4 | import com.chillingvan.canvasgl.util.FileLogger
5 |
6 | /**
7 | * Created by Chilling on 2018/11/17.
8 | */
9 | class MainApplication : Application() {
10 | override fun onCreate() {
11 | super.onCreate()
12 | // Loggers.DEBUG = true;
13 | FileLogger.init(getExternalFilesDir(null)!!.absolutePath)
14 | FileLogger.d("MainActivity", "init -----------------")
15 | }
16 | }
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/animation/AnimGLTextureView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.animation;
22 |
23 | import android.content.Context;
24 | import android.util.AttributeSet;
25 |
26 | import com.chillingvan.canvasgl.ICanvasGL;
27 | import com.chillingvan.canvasgl.glview.texture.GLContinuousTextureView;
28 | import com.chillingvan.canvasglsample.animation.bubble.Bubble;
29 | import com.chillingvan.canvasglsample.animation.bubble.MovableObj;
30 | import com.chillingvan.canvasglsample.animation.bubble.Wall;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | import static com.chillingvan.canvasglsample.animation.AnimGLView.INTERNVAL_TIME_MS;
36 |
37 | /**
38 | * Created by Chilling on 2016/11/5.
39 | */
40 |
41 | public class AnimGLTextureView extends GLContinuousTextureView {
42 |
43 | private List bubbles = new ArrayList<>();
44 | private Wall wallTop = new Wall.WallY(0);
45 | private Wall wallLeft = new Wall.WallX(0);
46 | private Wall wallBottom;
47 | private Wall wallRight;
48 |
49 | public AnimGLTextureView(Context context) {
50 | super(context);
51 | }
52 |
53 | public AnimGLTextureView(Context context, AttributeSet attrs) {
54 | super(context, attrs);
55 | }
56 |
57 | public AnimGLTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
58 | super(context, attrs, defStyleAttr);
59 | }
60 |
61 | @Override
62 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
63 | super.onSizeChanged(w, h, oldw, oldh);
64 | wallBottom = new Wall.WallY(h);
65 | wallRight = new Wall.WallX(w);
66 | }
67 |
68 |
69 | public void setBubbles(List bubbles) {
70 | this.bubbles.addAll(bubbles);
71 | }
72 |
73 | @Override
74 | protected void onGLDraw(ICanvasGL canvas) {
75 | for (Bubble bubble : bubbles) {
76 | bubble.glDraw(canvas);
77 | if (wallTop.isTouch(bubble.point, bubble.collisionRadius) || wallBottom.isTouch(bubble.point, bubble.collisionRadius)) {
78 | bubble.onCollision(MovableObj.CollisionListener.DIRECTION_VERTICAL);
79 | } else if (wallLeft.isTouch(bubble.point, bubble.collisionRadius) || wallRight.isTouch(bubble.point, bubble.collisionRadius)) {
80 | bubble.onCollision(MovableObj.CollisionListener.DIRECTION_HORIZONTAL);
81 | }
82 | bubble.updatePosition(INTERNVAL_TIME_MS);
83 | }
84 |
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/animation/AnimGLView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.animation;
22 |
23 | import android.content.Context;
24 | import android.util.AttributeSet;
25 |
26 | import com.chillingvan.canvasgl.ICanvasGL;
27 | import com.chillingvan.canvasgl.glview.GLContinuousView;
28 | import com.chillingvan.canvasglsample.animation.bubble.Bubble;
29 | import com.chillingvan.canvasglsample.animation.bubble.MovableObj;
30 | import com.chillingvan.canvasglsample.animation.bubble.Wall;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | /**
36 | * Created by Chilling on 2016/10/24.
37 | */
38 |
39 | public class AnimGLView extends GLContinuousView {
40 | public static final int INTERNVAL_TIME_MS = 16;
41 | private List bubbles = new ArrayList<>();
42 | private Wall wallTop = new Wall.WallY(0);
43 | private Wall wallLeft = new Wall.WallX(0);
44 | private Wall wallBottom;
45 | private Wall wallRight;
46 |
47 | public AnimGLView(Context context) {
48 | super(context);
49 | }
50 |
51 | public AnimGLView(Context context, AttributeSet attrs) {
52 | super(context, attrs);
53 | }
54 |
55 |
56 | public void setBubbles(List bubbles) {
57 | this.bubbles.addAll(bubbles);
58 | }
59 |
60 | @Override
61 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
62 | super.onSizeChanged(w, h, oldw, oldh);
63 | wallBottom = new Wall.WallY(h);
64 | wallRight = new Wall.WallX(w);
65 | }
66 |
67 | @Override
68 | protected void onGLDraw(ICanvasGL canvas) {
69 | for (Bubble bubble : bubbles) {
70 | bubble.glDraw(canvas);
71 | if (wallTop.isTouch(bubble.point, bubble.collisionRadius) || wallBottom.isTouch(bubble.point, bubble.collisionRadius)) {
72 | bubble.onCollision(MovableObj.CollisionListener.DIRECTION_VERTICAL);
73 | } else if (wallLeft.isTouch(bubble.point, bubble.collisionRadius) || wallRight.isTouch(bubble.point, bubble.collisionRadius)) {
74 | bubble.onCollision(MovableObj.CollisionListener.DIRECTION_HORIZONTAL);
75 | }
76 | bubble.updatePosition(INTERNVAL_TIME_MS);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/animation/bubble/Bubble.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.animation.bubble;
22 |
23 | import android.graphics.Bitmap;
24 | import android.graphics.Canvas;
25 | import android.graphics.Paint;
26 | import android.graphics.PointF;
27 |
28 | import com.chillingvan.canvasgl.ICanvasGL;
29 | import com.chillingvan.canvasgl.textureFilter.BasicTextureFilter;
30 | import com.chillingvan.canvasgl.textureFilter.TextureFilter;
31 |
32 | /**
33 | * Created by Chilling on 2016/10/24.
34 | */
35 |
36 | public class Bubble extends MovableObj implements MovableObj.CollisionListener {
37 | private Bitmap bitmap;
38 | private TextureFilter textureFilter;
39 | private Paint paint = new Paint();
40 |
41 | public Bubble(PointF point, float vx, float vy, float vRotate, Bitmap bitmap, TextureFilter textureFilter) {
42 | super(point, vx, vy, vRotate, bitmap.getWidth()/(float)2);
43 | this.bitmap = bitmap;
44 | if (textureFilter == null) {
45 | this.textureFilter = new BasicTextureFilter();
46 | } else {
47 | this.textureFilter = textureFilter;
48 | }
49 | }
50 |
51 |
52 | public void glDraw(ICanvasGL canvas) {
53 | canvas.save();
54 | int left = (int) (point.x - bitmap.getWidth() / (float)2);
55 | int top = (int) (point.y - bitmap.getHeight() / (float)2);
56 |
57 | canvas.rotate(rotateDegree, point.x, point.y);
58 | canvas.drawBitmap(bitmap, left, top, textureFilter);
59 |
60 | canvas.restore();
61 | }
62 |
63 | public void normalDraw(Canvas canvas) {
64 | canvas.save();
65 | int left = (int) (point.x - bitmap.getWidth() / (float)2);
66 | int top = (int) (point.y - bitmap.getHeight() / (float)2);
67 |
68 | canvas.rotate(rotateDegree, point.x, point.y);
69 | canvas.drawBitmap(bitmap, left, top, paint);
70 |
71 | canvas.restore();
72 | }
73 |
74 | @Override
75 | public void updatePosition(int timeMs) {
76 | super.updatePosition(timeMs);
77 | }
78 |
79 | @Override
80 | public void onCollision(int direction) {
81 | if (direction == DIRECTION_HORIZONTAL) {
82 | vx = -vx;
83 | } else if (direction == DIRECTION_VERTICAL) {
84 | vy = -vy;
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/animation/bubble/MovableObj.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.animation.bubble;
22 |
23 | import android.graphics.PointF;
24 |
25 | /**
26 | * Created by Matthew on 2016/8/13.
27 | */
28 | public class MovableObj {
29 |
30 |
31 | public PointF point;
32 | public float vx;
33 | public float vy;
34 | public float collisionRadius;
35 |
36 | public float vRotate;
37 | public float rotateDegree;
38 |
39 |
40 | public MovableObj(PointF point, float vx, float vy, float vRotate, float collisionRadius) {
41 | this.point = point;
42 | this.vx = vx;
43 | this.vy = vy;
44 | this.vRotate = vRotate;
45 | this.collisionRadius = collisionRadius;
46 | }
47 |
48 | public void reset(PointF point, float vx, float vy, float vRotate, float collisionRadius) {
49 | this.point = point;
50 | this.vx = vx;
51 | this.vy = vy;
52 | this.vRotate = vRotate;
53 | this.collisionRadius = collisionRadius;
54 | }
55 |
56 | public void updatePosition(int timeMs) {
57 | point.x += vx * timeMs;
58 | point.y += vy * timeMs;
59 | rotateDegree += vRotate * timeMs;
60 | }
61 |
62 | public interface CollisionListener {
63 | int DIRECTION_HORIZONTAL = 0;
64 | int DIRECTION_VERTICAL = 1;
65 | void onCollision(int direction);
66 | }
67 |
68 | @Override
69 | public String toString() {
70 | return "MovableObj{" +
71 | "point=" + point +
72 | ", vx=" + vx +
73 | ", vy=" + vy +
74 | ", collisionRadius=" + collisionRadius +
75 | ", vRotate=" + vRotate +
76 | ", rotateDegree=" + rotateDegree +
77 | '}';
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/animation/bubble/Wall.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.animation.bubble;
22 |
23 | import android.graphics.PointF;
24 |
25 | /**
26 | * Created by Chilling on 2016/10/24.
27 | */
28 |
29 | public abstract class Wall {
30 |
31 | protected float value;
32 |
33 | public Wall(float value) {
34 | this.value = value;
35 | }
36 |
37 | public abstract boolean isTouch(PointF point, float objRadius);
38 |
39 | public static class WallX extends Wall {
40 |
41 | public WallX(float value) {
42 | super(value);
43 | }
44 |
45 | @Override
46 | public boolean isTouch(PointF point, float objRadius) {
47 | return Math.abs(point.x - this.value) <= objRadius;
48 | }
49 | }
50 |
51 | public static class WallY extends Wall {
52 |
53 | public WallY(float value) {
54 | super(value);
55 | }
56 |
57 | @Override
58 | public boolean isTouch(PointF point, float objRadius) {
59 | return Math.abs(point.y - this.value) <= objRadius;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/compareCanvas/CompareCanvasActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 | package com.chillingvan.canvasglsample.compareCanvas
21 |
22 | import androidx.appcompat.app.AppCompatActivity
23 | import android.os.Bundle
24 | import com.chillingvan.canvasglsample.R
25 |
26 | class CompareCanvasActivity : AppCompatActivity() {
27 | override fun onCreate(savedInstanceState: Bundle?) {
28 | super.onCreate(savedInstanceState)
29 | setContentView(R.layout.activity_compare_canvas)
30 | }
31 | }
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/compareCanvas/CompareNormalView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 | package com.chillingvan.canvasglsample.compareCanvas
21 |
22 | import android.content.Context
23 | import android.graphics.*
24 | import android.util.AttributeSet
25 | import android.view.View
26 | import com.chillingvan.canvasglsample.R
27 |
28 | /**
29 | * Created by Matthew on 2016/10/8.
30 | */
31 | class CompareNormalView @JvmOverloads constructor(
32 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
33 | ) : View(context, attrs, defStyleAttr) {
34 | private var baboon: Bitmap? = null
35 | private val mMatrix: Matrix = Matrix()
36 |
37 | init {
38 | init()
39 | }
40 |
41 | private fun init() {
42 | baboon = BitmapFactory.decodeResource(resources, R.drawable.baboon)
43 | }
44 |
45 | override fun onDraw(canvas: Canvas) {
46 | super.onDraw(canvas)
47 | mMatrix.reset()
48 | mMatrix.postScale(2.1f, 2.1f)
49 | mMatrix.postRotate(90f)
50 | mMatrix.postTranslate(90f, 120f)
51 | mMatrix.postScale(0.4f, 0.4f, 139f, 149f)
52 | mMatrix.postRotate(10f, 128f, 128f)
53 | mMatrix.postTranslate(90f, -120f)
54 | canvas.drawBitmap(baboon!!, mMatrix!!, Paint())
55 | val paint = Paint()
56 | paint.color = Color.parseColor("#88FF0000")
57 | paint.strokeWidth = 4f
58 | paint.style = Paint.Style.FILL
59 | canvas.drawRect(360f, 0f, 380f, 40f, paint)
60 | val paint2 = Paint()
61 | paint2.color = Color.parseColor("#8800FF00")
62 | paint2.strokeWidth = 4f
63 | paint2.style = Paint.Style.STROKE
64 | canvas.drawRect(360f, 40f, 380f, 80f, paint2)
65 | canvas.drawLine(360f, 80f, 360f, 120f, paint)
66 | val text = "text"
67 | val textPaint = Paint()
68 | textPaint.color = Color.BLUE
69 | textPaint.textSize = 30f
70 | canvas.drawText(text, 0, text.length, 500f, 80f, textPaint)
71 |
72 |
73 | //circle
74 | val circlePaint = Paint()
75 | circlePaint.color = Color.parseColor("#88FF0000")
76 | circlePaint.style = Paint.Style.FILL
77 | canvas.drawCircle(430f, 30f, 30f, circlePaint)
78 | val strokeCirclePaint = Paint()
79 | strokeCirclePaint.color = Color.parseColor("#88FF0000")
80 | strokeCirclePaint.strokeWidth = 4f
81 | strokeCirclePaint.style = Paint.Style.STROKE
82 | canvas.drawCircle(490f, 30f, 30f, strokeCirclePaint)
83 | }
84 | }
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/comparePerformance/ComparePerformanceActivity.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.comparePerformance;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.TextView;
8 |
9 | import com.chillingvan.canvasglsample.R;
10 |
11 | import java.util.Locale;
12 |
13 | import androidx.appcompat.app.AppCompatActivity;
14 |
15 | public class ComparePerformanceActivity extends AppCompatActivity {
16 |
17 | private NormalBubblesView hwBubblesView;
18 | private SurfaceBubblesView swBubblesView;
19 | private GLBubblesView glBubblesView;
20 | private Bitmap bitmap;
21 | private TextView oneText;
22 | private TextView twoText;
23 | private TextView threeText;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_compare_performace);
29 | hwBubblesView = (NormalBubblesView) findViewById(R.id.hw_bubble_view);
30 | swBubblesView = (SurfaceBubblesView) findViewById(R.id.sw_bubble_view);
31 | glBubblesView = (GLBubblesView) findViewById(R.id.gl_bubble_view);
32 |
33 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_robot);
34 | hwBubblesView.setBitmap(bitmap);
35 | swBubblesView.setBitmap(bitmap);
36 | glBubblesView.setBitmap(bitmap);
37 |
38 | oneText = (TextView) findViewById(R.id.count_one);
39 | twoText = (TextView) findViewById(R.id.count_two);
40 | threeText = (TextView) findViewById(R.id.count_three);
41 | threeText.postDelayed(new Runnable() {
42 | @Override
43 | public void run() {
44 | if (isFinishing()) {
45 | return;
46 | }
47 | oneText.setText(String.format(Locale.CHINA, "hw canvas:%d", hwBubblesView.getCnt()));
48 | twoText.setText(String.format(Locale.CHINA, "sw canvas:%d", swBubblesView.getCnt()));
49 | threeText.setText(String.format(Locale.CHINA, "gl canvas:%d", glBubblesView.getCnt()));
50 | threeText.postDelayed(this, 500);
51 | }
52 | }, 500);
53 | new Thread(new Runnable() {
54 | @Override
55 | public void run() {
56 | }
57 | }).start();
58 | }
59 |
60 |
61 | public void onFire(View view) {
62 | hwBubblesView.setAdd(true);
63 | swBubblesView.setAdd(true);
64 | glBubblesView.setAdd(true);
65 | }
66 |
67 | @Override
68 | protected void onResume() {
69 | super.onResume();
70 | hwBubblesView.onResume();
71 | swBubblesView.onResume();
72 | glBubblesView.onResume();
73 | }
74 |
75 | @Override
76 | protected void onPause() {
77 | super.onPause();
78 | hwBubblesView.onPause();
79 | swBubblesView.onPause();
80 | glBubblesView.onPause();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/comparePerformance/GLBubblesView.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.comparePerformance;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.PointF;
6 | import android.util.AttributeSet;
7 | import android.view.View;
8 |
9 | import com.chillingvan.canvasgl.ICanvasGL;
10 | import com.chillingvan.canvasgl.glview.GLContinuousView;
11 | import com.chillingvan.canvasglsample.animation.bubble.Bubble;
12 |
13 | import java.util.Iterator;
14 | import java.util.LinkedList;
15 | import java.util.Queue;
16 |
17 | import static com.chillingvan.canvasglsample.animation.AnimGLView.INTERNVAL_TIME_MS;
18 |
19 | /**
20 | * Created by Chilling on 2016/11/19.
21 | */
22 |
23 | public class GLBubblesView extends GLContinuousView {
24 |
25 | private Queue bubbles = new LinkedList<>();
26 | private Bitmap bitmap;
27 | private long last;
28 | private int cnt;
29 | private boolean isAdd;
30 |
31 |
32 | public GLBubblesView(Context context) {
33 | super(context);
34 | }
35 |
36 | public GLBubblesView(Context context, AttributeSet attrs) {
37 | super(context, attrs);
38 | }
39 |
40 | @Override
41 | protected void init() {
42 | super.init();
43 | }
44 |
45 |
46 | @Override
47 | protected void onGLDraw(ICanvasGL canvas) {
48 | long now = System.currentTimeMillis();
49 | if (last == 0) {
50 | last = now;
51 | return;
52 | }
53 | for (Bubble bubble : bubbles) {
54 | bubble.glDraw(canvas);
55 | bubble.updatePosition((int) (INTERNVAL_TIME_MS));
56 | }
57 | Iterator iterator = bubbles.iterator();
58 | while (iterator.hasNext()) {
59 | Bubble bubble = iterator.next();
60 | if (bubble.point.y < 0) {
61 | iterator.remove();
62 | cnt++;
63 | }
64 | }
65 |
66 | if (isAdd) {
67 | NormalBubblesView.create(bubbles, this, bitmap);
68 | isAdd = false;
69 | }
70 | last = now;
71 | }
72 |
73 | public static Bubble createBubble(View view, Bitmap bitmap) {
74 | float vx = 0;
75 | float vy = -0.3f;
76 | float vRotate = 1f;
77 |
78 | return new Bubble(new PointF(view.getWidth()/2, view.getHeight()), vx, vy, vRotate, bitmap, null);
79 | }
80 |
81 | public void setBitmap(Bitmap bitmap) {
82 | this.bitmap = bitmap;
83 | }
84 |
85 | @Override
86 | public void onResume() {
87 | super.onResume();
88 | }
89 |
90 | @Override
91 | public void onPause() {
92 | super.onPause();
93 | }
94 |
95 | public int getCnt() {
96 | return cnt;
97 | }
98 |
99 | public void setAdd(boolean add) {
100 | isAdd = add;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/comparePerformance/RefreshTimer.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.comparePerformance;
2 |
3 | import java.util.Timer;
4 | import java.util.TimerTask;
5 |
6 | public class RefreshTimer {
7 |
8 | private Timer refreshTimer;
9 | private TimerTask timerTask;
10 | private boolean isTimerRunning;
11 | private Runnable timerRunnable;
12 |
13 | public void init(Runnable timerRunnable, int refreshIntervalTime) {
14 | this.timerRunnable = timerRunnable;
15 | if (refreshIntervalTime > 0 && refreshTimer == null) {
16 | refreshTimer = new Timer();
17 | }
18 | }
19 |
20 | public void run(int refreshIntervalTime) {
21 | if (refreshTimer != null && !isTimerRunning) {
22 | this.timerTask = new TimerTask() {
23 | @Override
24 | public void run() {
25 | timerRunnable.run();
26 | }
27 | };
28 | isTimerRunning = true;
29 | refreshTimer.schedule(timerTask, refreshIntervalTime, refreshIntervalTime);
30 | }
31 | }
32 |
33 | public void stop() {
34 | if (timerTask != null) {
35 | isTimerRunning = false;
36 | timerTask.cancel();
37 | }
38 | }
39 |
40 | public void end() {
41 | if (refreshTimer != null) {
42 | refreshTimer.cancel();
43 | refreshTimer = null;
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/filter/CaseEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.filter;
22 |
23 | import android.graphics.Bitmap;
24 | import android.view.LayoutInflater;
25 | import android.view.ViewGroup;
26 |
27 | import com.chillingvan.canvasgl.textureFilter.TextureFilter;
28 | import com.chillingvan.canvasglsample.R;
29 | import com.chillingvan.canvasglsample.util.adapter.BaseItemView;
30 | import com.chillingvan.canvasglsample.util.adapter.RenderEntity;
31 |
32 | import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter;
33 |
34 |
35 | /**
36 | * Created by Chilling on 2016/10/24.
37 | */
38 |
39 | public class CaseEntity implements RenderEntity {
40 |
41 |
42 | private String filterName;
43 | private TextureFilter textureFilter;
44 | private GPUImageFilter gpuImageFilter;
45 | private Bitmap firstBitmap;
46 |
47 | public CaseEntity(TextureFilter textureFilter, GPUImageFilter gpuImageFilter, Bitmap firstBitmap) {
48 | this.filterName = textureFilter.getClass().getSimpleName();
49 | this.textureFilter = textureFilter;
50 | this.gpuImageFilter = gpuImageFilter;
51 | this.firstBitmap = firstBitmap;
52 | }
53 |
54 | public Bitmap getFirstBitmap() {
55 | return firstBitmap;
56 | }
57 |
58 | public GPUImageFilter getGpuImageFilter() {
59 | return gpuImageFilter;
60 | }
61 |
62 | public String getFilterName() {
63 | return filterName;
64 | }
65 |
66 | public TextureFilter getTextureFilter() {
67 | return textureFilter;
68 | }
69 |
70 | @Override
71 | public BaseItemView createView(ViewGroup parent) {
72 | return new CaseItemView(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_case_filter, parent, false));
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/filter/FilterGLView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.filter;
22 |
23 | import android.content.Context;
24 | import android.graphics.Bitmap;
25 | import android.util.AttributeSet;
26 |
27 | import com.chillingvan.canvasgl.ICanvasGL;
28 | import com.chillingvan.canvasgl.glview.texture.GLTextureView;
29 | import com.chillingvan.canvasgl.textureFilter.TextureFilter;
30 |
31 | /**
32 | * Created by Matthew on 2016/10/5.
33 | */
34 |
35 | public class FilterGLView extends GLTextureView {
36 |
37 |
38 | private TextureFilter textureFilter;
39 | private Bitmap bitmap;
40 |
41 | public FilterGLView(Context context) {
42 | super(context);
43 | }
44 |
45 | public FilterGLView(Context context, AttributeSet attrs) {
46 | super(context, attrs);
47 | }
48 |
49 | @Override
50 | protected void init() {
51 | super.init();
52 | setOpaque(false);
53 | }
54 |
55 | @Override
56 | protected void onGLDraw(ICanvasGL canvas) {
57 | canvas.drawBitmap(bitmap, 0, 0, getWidth(), getHeight(), textureFilter);
58 | }
59 |
60 | public void setTextureFilter(TextureFilter textureFilter) {
61 | this.textureFilter = textureFilter;
62 | }
63 |
64 | public void setBitmap(Bitmap bitmap) {
65 | this.bitmap = bitmap;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/listSample/ProviderOffScreenCanvas.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.listSample;
2 |
3 | import android.opengl.GLES11Ext;
4 |
5 | import com.chillingvan.canvasgl.ICanvasGL;
6 | import com.chillingvan.canvasgl.MultiTexOffScreenCanvas;
7 | import com.chillingvan.canvasgl.glview.texture.GLTexture;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * Created by Chilling on 2019/6/30.
13 | */
14 | public class ProviderOffScreenCanvas extends MultiTexOffScreenCanvas {
15 |
16 | {
17 | setProducedTextureTarget(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
18 | }
19 |
20 | public ProviderOffScreenCanvas(int width, int height) {
21 | super(width, height);
22 | }
23 |
24 | @Override
25 | protected void onGLDraw(ICanvasGL canvas, List producedTextures, List consumedTextures) {
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/listSample/TextureItemEntity.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.listSample;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.ViewGroup;
5 |
6 | import com.chillingvan.canvasgl.glview.texture.GLMultiTexConsumerView;
7 | import com.chillingvan.canvasglsample.R;
8 | import com.chillingvan.canvasglsample.util.adapter.BaseItemView;
9 | import com.chillingvan.canvasglsample.util.adapter.RenderEntity;
10 |
11 | /**
12 | * Created by Chilling on 2019/6/30.
13 | */
14 | public class TextureItemEntity implements RenderEntity {
15 | private OnClickShowCallback onClickShowCallback;
16 |
17 | public TextureItemEntity(OnClickShowCallback onClickShowCallback) {
18 | this.onClickShowCallback = onClickShowCallback;
19 | }
20 |
21 | @Override
22 | public BaseItemView createView(ViewGroup parent) {
23 | return new TextureItemView(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_texture_list, parent, false));
24 | }
25 |
26 | public OnClickShowCallback getOnClickShowCallback() {
27 | return onClickShowCallback;
28 | }
29 |
30 | public interface OnClickShowCallback {
31 | void onShow(GLMultiTexConsumerView textureView);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/listSample/TextureItemView.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.listSample;
2 |
3 | import android.view.View;
4 | import android.widget.Button;
5 |
6 | import com.chillingvan.canvasgl.glview.texture.GLMultiTexConsumerView;
7 | import com.chillingvan.canvasglsample.R;
8 | import com.chillingvan.canvasglsample.util.adapter.BaseItemView;
9 |
10 | /**
11 | * Created by Chilling on 2019/6/30.
12 | */
13 | public class TextureItemView extends BaseItemView {
14 |
15 | private final GLMultiTexConsumerView textureView;
16 | private final Button showTextureBtn;
17 |
18 | public TextureItemView(View itemView) {
19 | super(itemView);
20 | textureView = itemView.findViewById(R.id.texture_item);
21 | showTextureBtn = itemView.findViewById(R.id.btn_show_texture);
22 | }
23 |
24 | @Override
25 | public void render(final TextureItemEntity renderEntity) {
26 | showTextureBtn.setOnClickListener(new View.OnClickListener() {
27 | @Override
28 | public void onClick(View v) {
29 | renderEntity.getOnClickShowCallback().onShow(textureView);
30 | }
31 | });
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/multi/MultiVideoTexture.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.multi;
2 |
3 | import android.content.Context;
4 | import android.graphics.SurfaceTexture;
5 | import android.util.AttributeSet;
6 |
7 | import com.chillingvan.canvasgl.ICanvasGL;
8 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
9 | import com.chillingvan.canvasgl.glview.texture.GLMultiTexProducerView;
10 | import com.chillingvan.canvasgl.glview.texture.GLTexture;
11 | import com.chillingvan.canvasgl.glview.texture.gles.EglContextWrapper;
12 | import com.chillingvan.canvasgl.glview.texture.gles.GLThread;
13 | import com.chillingvan.canvasgl.textureFilter.LightenBlendFilter;
14 | import com.chillingvan.canvasgl.textureFilter.TwoTextureFilter;
15 |
16 | import java.util.List;
17 |
18 | /**
19 | * Created by Chilling on 2018/5/19.
20 | */
21 | public class MultiVideoTexture extends GLMultiTexProducerView {
22 |
23 | private TwoTextureFilter textureFilter = new LightenBlendFilter();
24 |
25 | public MultiVideoTexture(Context context) {
26 | super(context);
27 | }
28 |
29 | public MultiVideoTexture(Context context, AttributeSet attrs) {
30 | super(context, attrs);
31 | }
32 |
33 | public MultiVideoTexture(Context context, AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | }
36 |
37 | @Override
38 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
39 | super.onSurfaceTextureAvailable(surface, width, height);
40 | if (mSharedEglContext == null) {
41 | setSharedEglContext(EglContextWrapper.EGL_NO_CONTEXT_WRAPPER);
42 | }
43 | }
44 |
45 | @Override
46 | protected int getInitialTexCount() {
47 | return 3;
48 | }
49 |
50 | @Override
51 | protected int getRenderMode() {
52 | return GLThread.RENDERMODE_CONTINUOUSLY;
53 | }
54 |
55 | @Override
56 | protected void onGLDraw(ICanvasGL canvas, List producedTextures, List consumedTextures) {
57 | int size = producedTextures.size();
58 | for (int i = 0; i < producedTextures.size(); i++) {
59 | GLTexture texture = producedTextures.get(i);
60 | int left = getWidth() * i / size;
61 | RawTexture rawTexture = texture.getRawTexture();
62 | rawTexture.setIsFlippedVertically(true);
63 | // An example for two texture filter with RawTexture
64 | if (i == 2) {
65 | textureFilter.setSecondRawTexture(producedTextures.get(0));
66 | canvas.drawSurfaceTexture(rawTexture, texture.getSurfaceTexture(), left, 0, left + getWidth()/size, getHeight(), textureFilter);
67 | } else {
68 | canvas.drawSurfaceTexture(rawTexture, texture.getSurfaceTexture(), left, 0, left + getWidth()/size, getHeight());
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/offscreen/SimpleOffScreenActivity.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.offscreen;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.Rect;
6 | import android.graphics.SurfaceTexture;
7 | import android.os.Bundle;
8 | import android.widget.ImageView;
9 |
10 | import com.chillingvan.canvasgl.ICanvasGL;
11 | import com.chillingvan.canvasgl.OffScreenCanvas;
12 | import com.chillingvan.canvasgl.glcanvas.BasicTexture;
13 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
14 | import com.chillingvan.canvasgl.glview.GLView;
15 | import com.chillingvan.canvasglsample.R;
16 |
17 | import androidx.annotation.Nullable;
18 | import androidx.appcompat.app.AppCompatActivity;
19 |
20 | public class SimpleOffScreenActivity extends AppCompatActivity {
21 |
22 | private ImageView imageView;
23 | private Bitmap bitmap;
24 | private OffScreenCanvas offScreenCanvas;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_simple_off_screen);
30 |
31 | imageView = (ImageView) findViewById(R.id.off_screen_img_v);
32 | bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.lenna);
33 |
34 | offScreenCanvas = new OffScreenCanvas(400, 400) {
35 | @Override
36 | protected void onGLDraw(ICanvasGL canvas, SurfaceTexture producedSurfaceTexture, RawTexture producedRawTexture,
37 | @Nullable SurfaceTexture outsideSharedSurfaceTexture, @Nullable BasicTexture outsideSharedTexture) {
38 | canvas.drawBitmap(bitmap, 0, 0, 256, 256);
39 | }
40 | };
41 |
42 | offScreenCanvas.start();
43 | }
44 |
45 | @Override
46 | protected void onResume() {
47 | super.onResume();
48 | offScreenCanvas.onResume();
49 | offScreenCanvas.getDrawingBitmap(new Rect(0, 0, 300, 300), new GLView.GetDrawingCacheCallback() {
50 | @Override
51 | public void onFetch(final Bitmap bitmap) {
52 | imageView.setImageBitmap(bitmap);
53 | }
54 | });
55 | }
56 |
57 | @Override
58 | protected void onStop() {
59 | super.onStop();
60 | offScreenCanvas.onPause();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/offscreen/camera/CameraPreviewOffScreen.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.offscreen.camera;
2 |
3 | import android.graphics.SurfaceTexture;
4 | import android.opengl.GLES11Ext;
5 |
6 | import com.chillingvan.canvasgl.ICanvasGL;
7 | import com.chillingvan.canvasgl.OffScreenCanvas;
8 | import com.chillingvan.canvasgl.glcanvas.BasicTexture;
9 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
10 |
11 | import androidx.annotation.Nullable;
12 |
13 | /**
14 | * Created by Chilling on 2016/12/19.
15 | */
16 |
17 | public class CameraPreviewOffScreen extends OffScreenCanvas {
18 |
19 | public CameraPreviewOffScreen(int width, int height) {
20 | super(width, height);
21 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!! important
22 | setProducedTextureTarget(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
23 | }
24 |
25 | @Override
26 | protected void onGLDraw(ICanvasGL canvas, SurfaceTexture producedSurfaceTexture, RawTexture producedRawTexture, @Nullable SurfaceTexture outsideSharedSurfaceTexture, @Nullable BasicTexture outsideSharedTexture) {
27 | canvas.drawSurfaceTexture(producedRawTexture, producedSurfaceTexture, 0, 0, producedRawTexture.getWidth(), producedRawTexture.getHeight());
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/screenRecord/ScreenRecordTextureView.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.screenRecord;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.PorterDuff;
9 | import android.util.AttributeSet;
10 |
11 | import com.chillingvan.canvasgl.ICanvasGL;
12 | import com.chillingvan.canvasgl.androidCanvas.IAndroidCanvasHelper;
13 | import com.chillingvan.canvasgl.glview.texture.GLSurfaceTextureProducerView;
14 | import com.chillingvan.canvasgl.glview.texture.GLTexture;
15 | import com.chillingvan.canvasglsample.util.ScreenUtil;
16 |
17 | import androidx.annotation.Nullable;
18 |
19 | /**
20 | * Created by Chilling on 2020/3/7.
21 | */
22 | public class ScreenRecordTextureView extends GLSurfaceTextureProducerView {
23 |
24 | private IAndroidCanvasHelper drawTextHelper = IAndroidCanvasHelper.Factory.createAndroidCanvasHelper(IAndroidCanvasHelper.MODE.MODE_ASYNC);
25 | private IAndroidCanvasHelper.CanvasPainter mCanvasPainter;
26 | private Paint textPaint;
27 | private int drawCnt = 0;
28 |
29 | public ScreenRecordTextureView(Context context) {
30 | super(context);
31 | }
32 |
33 | public ScreenRecordTextureView(Context context, AttributeSet attrs) {
34 | super(context, attrs);
35 | }
36 |
37 | public ScreenRecordTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
38 | super(context, attrs, defStyleAttr);
39 | }
40 |
41 | @Override
42 | protected void init() {
43 | super.init();
44 | textPaint = new Paint();
45 | textPaint.setColor(Color.RED);
46 | textPaint.setTextSize(ScreenUtil.dpToPx(getContext(), 15));
47 | mCanvasPainter = new IAndroidCanvasHelper.CanvasPainter() {
48 | @Override
49 | public void draw(Canvas androidCanvas, Bitmap drawBitmap) {
50 | drawCnt++;
51 | androidCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
52 | androidCanvas.drawText("Cnt: " + drawCnt, 45, 45, textPaint);
53 | }
54 | };
55 | }
56 |
57 | @Override
58 | public void onSurfaceChanged(int width, int height) {
59 | super.onSurfaceChanged(width, height);
60 | drawTextHelper.init(width, height);
61 | }
62 |
63 | @Override
64 | protected void onGLDraw(ICanvasGL canvas, GLTexture producedGLTexture, @Nullable GLTexture outsideGLTexture) {
65 | super.onGLDraw(canvas, producedGLTexture, outsideGLTexture);
66 | canvas.drawSurfaceTexture(producedGLTexture.getRawTexture(), producedGLTexture.getSurfaceTexture(), 0, 0, getWidth(), getHeight());
67 | drawTextHelper.draw(mCanvasPainter);
68 | Bitmap outputBitmap = drawTextHelper.getOutputBitmap();
69 | canvas.invalidateTextureContent(outputBitmap);
70 | canvas.drawBitmap(outputBitmap, 0, 0);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/testcase/testMatrix/Camera2Util.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.testcase.testMatrix;
2 |
3 | import android.content.Context;
4 | import android.hardware.camera2.CameraAccessException;
5 | import android.hardware.camera2.CameraCharacteristics;
6 | import android.hardware.camera2.CameraManager;
7 | import android.hardware.camera2.params.StreamConfigurationMap;
8 | import android.os.Build;
9 | import android.util.Log;
10 |
11 | import androidx.annotation.RequiresApi;
12 |
13 | /**
14 | * Created by Chilling on 2019/11/24.
15 | */
16 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
17 | public class Camera2Util {
18 |
19 |
20 | public static String setUpCameraOutputs(Context context, int width, int height) {
21 | CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
22 | try {
23 | for (String cameraId : manager.getCameraIdList()) {
24 | // 获取指定摄像头的特性
25 | CameraCharacteristics characteristics
26 | = manager.getCameraCharacteristics(cameraId);
27 |
28 | // We don't use a back facing camera in this sample.
29 | Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
30 | if (facing != null && facing == CameraCharacteristics.LENS_FACING_BACK) {
31 | continue;
32 | }
33 |
34 | // 获取摄像头支持的配置属性
35 | StreamConfigurationMap map = characteristics.get(
36 | CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
37 | if (map == null) {
38 | continue;
39 | }
40 |
41 | return cameraId;
42 | }
43 | } catch (CameraAccessException e) {
44 | e.printStackTrace();
45 | } catch (NullPointerException e) {
46 | // Currently an NPE is thrown when the Camera2API is used but not supported on the
47 | // device this code runs.
48 | Log.e("TAG", e.getMessage());
49 | }
50 | return "";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/testcase/testMatrix/TestMatrixActivity.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.testcase.testMatrix;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.chillingvan.canvasglsample.R;
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 |
9 | public class TestMatrixActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_test_matrix);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/text/Dannmaku.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.text;
2 |
3 | import android.graphics.PointF;
4 |
5 | import com.chillingvan.canvasglsample.animation.bubble.MovableObj;
6 |
7 | /**
8 | * Created by Chilling on 2018/4/14.
9 | */
10 | public class Dannmaku extends MovableObj {
11 | private String text;
12 | private int color;
13 | private float length;
14 |
15 | public Dannmaku(PointF point, float vx) {
16 | super(point, vx, 0, 0, 0);
17 | }
18 |
19 |
20 | public String getText() {
21 | return text;
22 | }
23 |
24 | public int getColor() {
25 | return color;
26 | }
27 |
28 | public void setText(String text) {
29 | this.text = text;
30 | }
31 |
32 | public void setColor(int color) {
33 | this.color = color;
34 | }
35 |
36 | public void setLength(float length) {
37 | this.length = length;
38 | }
39 |
40 | public float getLength() {
41 | return length;
42 | }
43 |
44 | public float getRight() {
45 | return point.x + length;
46 | }
47 |
48 | public void reset(float x, float y, float vx) {
49 | point.x = x;
50 | point.y = y;
51 | super.reset(point, vx, 0, vRotate, collisionRadius);
52 | length = 0;
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return super.toString() + "Dannmaku{" +
58 | "text='" + text + '\'' +
59 | ", color=" + color +
60 | ", length=" + length +
61 | '}';
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/text/DannmakuFactory.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.text;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.PointF;
5 |
6 | import java.util.Random;
7 |
8 | import static com.chillingvan.canvasglsample.animation.AnimActivity.VY_MULTIPLIER;
9 |
10 | /**
11 | * Created by Chilling on 2018/4/14.
12 | */
13 | public class DannmakuFactory extends ObjectFactory {
14 | private final Random random = new Random();
15 | private static final float VX_MULTIPLIER = 0.001f;
16 | private final int width;
17 | private final int height;
18 | private static final String[] WORDS = new String[]{
19 | "23333", "66666666", "哈哈哈哈哈哈哈哈哈", "Awesome", "凄い"
20 | };
21 |
22 | private static final int[] COLORS = new int[]{
23 | Color.WHITE, Color.GREEN, Color.LTGRAY
24 | };
25 |
26 | public DannmakuFactory(int width, int height) {
27 | this.width = width;
28 | this.height = height;
29 | }
30 |
31 | @Override
32 | protected Dannmaku produce(Dannmaku dannmaku) {
33 | float vx = -(20 + random.nextInt(30)) * VY_MULTIPLIER;
34 | float y = 30 + random.nextInt(height/2);
35 | if (dannmaku == null) {
36 | dannmaku = new Dannmaku(new PointF(width, y), vx);
37 | } else {
38 | dannmaku.reset(width, y, vx);
39 | }
40 | dannmaku.setText(WORDS[random.nextInt(WORDS.length)]);
41 | dannmaku.setColor(COLORS[random.nextInt(COLORS.length)]);
42 | return dannmaku;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/text/DrawTextActivity.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.text;
2 |
3 | import android.graphics.SurfaceTexture;
4 | import android.os.Bundle;
5 | import android.os.CountDownTimer;
6 | import android.view.Surface;
7 | import android.view.View;
8 | import android.widget.TextView;
9 |
10 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
11 | import com.chillingvan.canvasgl.glview.texture.GLSurfaceTextureProducerView;
12 | import com.chillingvan.canvasglsample.R;
13 | import com.chillingvan.canvasglsample.video.MediaPlayerHelper;
14 |
15 | import androidx.appcompat.app.AppCompatActivity;
16 |
17 | public class DrawTextActivity extends AppCompatActivity {
18 |
19 | private MediaPlayerHelper mediaPlayer = new MediaPlayerHelper();
20 | private Surface mediaSurface;
21 | private DrawTextTextureView drawTextTextureView;
22 | private CountDownTimer countDownTimer;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_draw_text);
28 | initTextureView();
29 | }
30 |
31 | private void initTextureView() {
32 | drawTextTextureView = findViewById(R.id.media_player_texture_view);
33 | final TextView frameRateTxt = findViewById(R.id.frame_rate_txt);
34 |
35 | drawTextTextureView.setOnSurfaceTextureSet(new GLSurfaceTextureProducerView.OnSurfaceTextureSet() {
36 | @Override
37 | public void onSet(SurfaceTexture surfaceTexture, RawTexture surfaceTextureRelatedTexture) {
38 | // No need to request draw because it is continues GL View.
39 |
40 | mediaSurface = new Surface(surfaceTexture);
41 | }
42 | });
43 | countDownTimer = new CountDownTimer(1000 * 3600, 1000) {
44 | @Override
45 | public void onTick(long millisUntilFinished) {
46 | frameRateTxt.setText(String.valueOf(drawTextTextureView.getFrameRate()));
47 | }
48 |
49 | @Override
50 | public void onFinish() {
51 |
52 | }
53 | };
54 | countDownTimer.start();
55 | }
56 |
57 | @Override
58 | protected void onResume() {
59 | super.onResume();
60 | drawTextTextureView.onResume();
61 | }
62 |
63 | @Override
64 | protected void onPause() {
65 | super.onPause();
66 | if (mediaPlayer.isPlaying()) {
67 | mediaPlayer.stop();
68 | }
69 | drawTextTextureView.onPause();
70 | }
71 |
72 | @Override
73 | protected void onDestroy() {
74 | super.onDestroy();
75 | countDownTimer.cancel();
76 | if (mediaPlayer.isPlaying()) {
77 | mediaPlayer.release();
78 | }
79 | }
80 |
81 | public void onClickStart(View view) {
82 | if ((mediaPlayer.isPlaying() || mediaPlayer.isLooping())) {
83 | return;
84 | }
85 |
86 | playMedia();
87 |
88 | }
89 |
90 | private void playMedia() {
91 | mediaPlayer.playMedia(this, mediaSurface);
92 | drawTextTextureView.start();
93 |
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/textureView/CameraPreviewTextureView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.textureView;
22 |
23 | import android.content.Context;
24 | import android.graphics.SurfaceTexture;
25 | import android.util.AttributeSet;
26 |
27 | import com.chillingvan.canvasgl.ICanvasGL;
28 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
29 | import com.chillingvan.canvasgl.glview.texture.GLSurfaceTextureProducerView;
30 | import com.chillingvan.canvasgl.glview.texture.GLTexture;
31 | import com.chillingvan.canvasgl.textureFilter.BasicTextureFilter;
32 | import com.chillingvan.canvasgl.textureFilter.TextureFilter;
33 |
34 | import androidx.annotation.Nullable;
35 |
36 | /**
37 | * Created by Chilling on 2016/11/3.
38 | */
39 |
40 | public class CameraPreviewTextureView extends GLSurfaceTextureProducerView {
41 |
42 | private TextureFilter textureFilter = new BasicTextureFilter();
43 | private int mRotation = 0;
44 |
45 | public CameraPreviewTextureView(Context context) {
46 | super(context);
47 | }
48 |
49 | public CameraPreviewTextureView(Context context, AttributeSet attrs) {
50 | super(context, attrs);
51 | }
52 |
53 | public CameraPreviewTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
54 | super(context, attrs, defStyleAttr);
55 | }
56 |
57 | @Override
58 | public void onSurfaceChanged(int width, int height) {
59 | super.onSurfaceChanged(width, height);
60 | }
61 |
62 | public void setTextureFilter(TextureFilter textureFilter) {
63 | this.textureFilter = textureFilter;
64 | }
65 |
66 | @Override
67 | protected void onGLDraw(ICanvasGL canvas, GLTexture producedGLTexture, @Nullable GLTexture outsideGLTexture) {
68 | super.onGLDraw(canvas, producedGLTexture, outsideGLTexture);
69 | canvas.save();
70 | RawTexture producedRawTexture = producedGLTexture.getRawTexture();
71 | SurfaceTexture producedSurfaceTexture = producedGLTexture.getSurfaceTexture();
72 | // note the rotate center point.
73 | canvas.rotate(mRotation, getWidth() / 2f, getHeight() / 2f);
74 | canvas.drawSurfaceTexture(producedRawTexture, producedSurfaceTexture, 0, 0, producedRawTexture.getWidth(), producedRawTexture.getHeight(), textureFilter);
75 | canvas.restore();
76 | }
77 |
78 | public void rotateSurface(int rotation) {
79 | mRotation += rotation;
80 | if (mRotation >= 360) {
81 | mRotation = 0;
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/textureView/PreviewConsumerTextureView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.textureView;
22 |
23 | import android.content.Context;
24 | import android.graphics.Bitmap;
25 | import android.graphics.BitmapFactory;
26 | import android.graphics.SurfaceTexture;
27 | import android.util.AttributeSet;
28 |
29 | import com.chillingvan.canvasgl.ICanvasGL;
30 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
31 | import com.chillingvan.canvasgl.glview.texture.GLMultiTexConsumerView;
32 | import com.chillingvan.canvasgl.glview.texture.GLTexture;
33 | import com.chillingvan.canvasgl.textureFilter.BasicTextureFilter;
34 | import com.chillingvan.canvasgl.textureFilter.TextureFilter;
35 | import com.chillingvan.canvasglsample.R;
36 |
37 | import java.util.List;
38 |
39 | /**
40 | * Created by Chilling on 2016/11/5.
41 | */
42 |
43 | public class PreviewConsumerTextureView extends GLMultiTexConsumerView {
44 |
45 | private TextureFilter textureFilter = new BasicTextureFilter();
46 | private Bitmap robot;
47 |
48 | public PreviewConsumerTextureView(Context context) {
49 | super(context);
50 | }
51 |
52 | public PreviewConsumerTextureView(Context context, AttributeSet attrs) {
53 | super(context, attrs);
54 | }
55 |
56 | public PreviewConsumerTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
57 | super(context, attrs, defStyleAttr);
58 | }
59 |
60 | @Override
61 | protected void onGLDraw(ICanvasGL canvas, List consumedTextures) {
62 | if (!consumedTextures.isEmpty()) {
63 | GLTexture consumedTexture = consumedTextures.get(0);
64 | SurfaceTexture sharedSurfaceTexture = consumedTexture.getSurfaceTexture();
65 | RawTexture sharedTexture = consumedTexture.getRawTexture();
66 | canvas.drawSurfaceTexture(sharedTexture, sharedSurfaceTexture, 0, 0, sharedTexture.getWidth(), sharedTexture.getHeight(), textureFilter);
67 | canvas.drawBitmap(robot, 0, 0 , 60, 60);
68 | }
69 | }
70 |
71 | public void setTextureFilter(TextureFilter textureFilter) {
72 | this.textureFilter = textureFilter;
73 | }
74 |
75 | @Override
76 | protected void init() {
77 | super.init();
78 | robot = BitmapFactory.decodeResource(getResources(), R.drawable.ic_robot);
79 | }
80 |
81 | public void clearConsumedTextures() {
82 | consumedTextures.clear();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/util/ScreenUtil.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.util;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by Matthew on 2016/1/12.
7 | */
8 | public class ScreenUtil {
9 |
10 | public static float dpToPx(Context context, float dp) {
11 | if (context == null) {
12 | return -1;
13 | }
14 | return dp * context.getResources().getDisplayMetrics().density;
15 | }
16 |
17 | public static float pxToDp(Context context, float px) {
18 | if (context == null) {
19 | return -1;
20 | }
21 | return px / context.getResources().getDisplayMetrics().density;
22 | }
23 |
24 | public static int dpToPxInt(Context context, float dp) {
25 | return (int)(dpToPx(context, dp) + 0.5f);
26 | }
27 |
28 | public static int pxToDpCeilInt(Context context, float px) {
29 | return (int)(pxToDp(context, px) + 0.5f);
30 | }
31 |
32 | public static float getDensity(Context context) {
33 | return context.getResources().getDisplayMetrics().density;
34 | }
35 |
36 | public static int getScreenWidth(Context context) {
37 | return context.getResources().getDisplayMetrics().widthPixels;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/util/adapter/BaseItemView.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.util.adapter;
2 |
3 | import android.view.View;
4 |
5 | import androidx.recyclerview.widget.RecyclerView;
6 |
7 | /**
8 | * Created by Matthew on 2016/4/8.
9 | */
10 | public abstract class BaseItemView extends RecyclerView.ViewHolder implements CommonItemView{
11 |
12 | protected View itemView;
13 |
14 | public BaseItemView(View itemView) {
15 | super(itemView);
16 | this.itemView = itemView;
17 | }
18 |
19 | @Override
20 | public View getView() {
21 | return itemView;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/util/adapter/CommonAdapterInternal.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.util.adapter;
22 |
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | /**
27 | * Created by Matthew on 2016/5/31.
28 | */
29 | public class CommonAdapterInternal {
30 | private Map classMapViewType = new HashMap<>(10);
31 |
32 | public CommonAdapterInternal(Class extends RenderEntity>[] classArr) {
33 | for (int i = 0; classArr != null && i < classArr.length; i++) {
34 | classMapViewType.put(classArr[i], i);
35 | }
36 | }
37 |
38 | public int getItemViewType(Class entityCls) {
39 | Integer viewType = classMapViewType.get(entityCls);
40 | return viewType == null ? 0 : viewType;
41 | }
42 |
43 | public int getViewTypeCount() {
44 | return classMapViewType.size() == 0 ? 1 : classMapViewType.size();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/util/adapter/CommonBaseAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.util.adapter;
22 |
23 | import android.view.View;
24 | import android.view.ViewGroup;
25 | import android.widget.BaseAdapter;
26 |
27 | import java.util.List;
28 |
29 | public class CommonBaseAdapter extends BaseAdapter {
30 |
31 | protected final List entityList;
32 | private CommonAdapterInternal commonAdapterInternal;
33 |
34 | public CommonBaseAdapter(List entityList) {
35 | this(entityList, null);
36 | }
37 |
38 | public CommonBaseAdapter(List entityList, Class extends RenderEntity>[] classArr) {
39 | this.entityList = entityList;
40 | commonAdapterInternal = new CommonAdapterInternal(classArr);
41 | }
42 |
43 | @Override
44 | public int getCount() {
45 | return entityList.size();
46 | }
47 |
48 | @Override
49 | public Object getItem(int position) {
50 | return entityList.get(position);
51 | }
52 |
53 | @Override
54 | public long getItemId(int position) {
55 | return position;
56 | }
57 |
58 | @Override
59 | public int getItemViewType(int position) {
60 | return commonAdapterInternal.getItemViewType(entityList.get(position).getClass());
61 | }
62 |
63 | @Override
64 | public int getViewTypeCount() {
65 | return commonAdapterInternal.getViewTypeCount();
66 | }
67 |
68 | @Override
69 | public View getView(int position, View convertView, ViewGroup parent) {
70 | CommonItemView itemView;
71 | RenderEntity renderEntity = entityList.get(position);
72 | if (convertView == null) {
73 | itemView = renderEntity.createView(parent);
74 | convertView = itemView.getView();
75 | convertView.setTag(itemView);
76 | } else {
77 | itemView = (CommonItemView) convertView.getTag();
78 | }
79 | itemView.render(renderEntity);
80 | return convertView;
81 | }
82 | }
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/util/adapter/CommonItemView.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.util.adapter;
22 |
23 | import android.view.View;
24 |
25 | public interface CommonItemView {
26 |
27 |
28 | void render(T renderEntity);
29 |
30 | View getView();
31 | }
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/util/adapter/CommonRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.util.adapter;
2 |
3 | import android.util.SparseArray;
4 | import android.view.ViewGroup;
5 |
6 | import java.util.List;
7 |
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | /**
11 | * Created by Matthew on 2016/4/7.
12 | */
13 | public class CommonRecyclerAdapter extends RecyclerView.Adapter{
14 |
15 |
16 | protected final List entityList;
17 | private SparseArray viewTypeMapViewCreator = new SparseArray<>(10);
18 | private CommonAdapterInternal commonAdapterInternal;
19 |
20 | public CommonRecyclerAdapter(List entityList) {
21 | this(entityList, null);
22 | }
23 |
24 | public CommonRecyclerAdapter(List entityList, Class extends RenderEntity>[] classArr) {
25 | this.entityList = entityList;
26 | commonAdapterInternal = new CommonAdapterInternal(classArr);
27 | }
28 |
29 |
30 | @Override
31 | public BaseItemView onCreateViewHolder(ViewGroup parent, int viewType) {
32 | return viewTypeMapViewCreator.get(viewType).createView(parent);
33 | }
34 |
35 | @Override
36 | public void onBindViewHolder(BaseItemView holder, int position) {
37 | holder.render(entityList.get(position));
38 | }
39 |
40 | @Override
41 | public int getItemViewType(int position) {
42 | RenderEntity renderEntity = entityList.get(position);
43 | Integer viewType = commonAdapterInternal.getItemViewType(entityList.get(position).getClass());
44 | viewTypeMapViewCreator.put(viewType, renderEntity);
45 | return viewType;
46 | }
47 |
48 | @Override
49 | public int getItemCount() {
50 | return entityList.size();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/util/adapter/RenderEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | package com.chillingvan.canvasglsample.util.adapter;
22 |
23 | import android.view.ViewGroup;
24 |
25 | /**
26 | * Created by Matthew on 2016/4/6.
27 | */
28 | public interface RenderEntity {
29 | BaseItemView createView(ViewGroup parent);
30 | }
31 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/video/MediaPlayerActivity.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.video;
2 |
3 | import android.graphics.SurfaceTexture;
4 | import android.os.Bundle;
5 | import android.view.Surface;
6 | import android.view.View;
7 |
8 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
9 | import com.chillingvan.canvasgl.glview.texture.GLSurfaceTextureProducerView;
10 | import com.chillingvan.canvasgl.util.Loggers;
11 | import com.chillingvan.canvasglsample.R;
12 |
13 | import androidx.appcompat.app.AppCompatActivity;
14 |
15 | public class MediaPlayerActivity extends AppCompatActivity {
16 |
17 | private MediaPlayerHelper mediaPlayer = new MediaPlayerHelper();
18 | private Surface mediaSurface;
19 | private MediaPlayerTextureView mediaPlayerTextureView;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_media_player);
25 | initTextureView();
26 | }
27 |
28 | private void initTextureView() {
29 | mediaPlayerTextureView = findViewById(R.id.media_player_texture_view);
30 |
31 | mediaPlayerTextureView.setOnSurfaceTextureSet(new GLSurfaceTextureProducerView.OnSurfaceTextureSet() {
32 | @Override
33 | public void onSet(SurfaceTexture surfaceTexture, RawTexture surfaceTextureRelatedTexture) {
34 | surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
35 | @Override
36 | public void onFrameAvailable(SurfaceTexture surfaceTexture) {
37 | Loggers.i("MediaPlayerActivity", "onFrameAvailable: ");
38 | mediaPlayerTextureView.requestRenderAndWait();
39 | }
40 | });
41 |
42 | mediaSurface = new Surface(surfaceTexture);
43 | }
44 | });
45 |
46 | }
47 |
48 | @Override
49 | protected void onResume() {
50 | super.onResume();
51 | mediaPlayerTextureView.onResume();
52 | }
53 |
54 | @Override
55 | protected void onPause() {
56 | super.onPause();
57 | if (mediaPlayer.isPlaying()) {
58 | mediaPlayer.stop();
59 | }
60 | mediaPlayerTextureView.onPause();
61 | }
62 |
63 | @Override
64 | protected void onDestroy() {
65 | super.onDestroy();
66 | if (mediaPlayer.isPlaying()) {
67 | mediaPlayer.release();
68 | }
69 | }
70 |
71 | public void onClickStart(View view) {
72 | if ((mediaPlayer.isPlaying() || mediaPlayer.isLooping())) {
73 | return;
74 | }
75 |
76 | playMedia();
77 |
78 | }
79 |
80 | private void playMedia() {
81 | mediaPlayer.playMedia(this, mediaSurface);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/video/MediaPlayerProduceTextureView.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.video;
2 |
3 | import android.content.Context;
4 | import android.graphics.SurfaceTexture;
5 | import android.util.AttributeSet;
6 |
7 | import com.chillingvan.canvasgl.ICanvasGL;
8 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
9 | import com.chillingvan.canvasgl.glview.texture.GLMultiTexProducerView;
10 | import com.chillingvan.canvasgl.glview.texture.GLTexture;
11 | import com.chillingvan.canvasgl.textureFilter.BasicTextureFilter;
12 | import com.chillingvan.canvasgl.textureFilter.TextureFilter;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * Created by Chilling on 2017/12/16.
18 | */
19 |
20 | public class MediaPlayerProduceTextureView extends GLMultiTexProducerView {
21 |
22 | private TextureFilter textureFilter = new BasicTextureFilter();
23 |
24 | public MediaPlayerProduceTextureView(Context context) {
25 | super(context);
26 | }
27 |
28 | public MediaPlayerProduceTextureView(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | }
31 |
32 | public MediaPlayerProduceTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | }
35 |
36 |
37 | @Override
38 | protected void onGLDraw(ICanvasGL canvas, List producedTextures, List consumedTextures) {
39 | GLTexture glTexture = producedTextures.get(0);
40 | RawTexture producedRawTexture = glTexture.getRawTexture();
41 | SurfaceTexture surfaceTexture = glTexture.getSurfaceTexture();
42 | producedRawTexture.setIsFlippedVertically(true);
43 | canvas.drawSurfaceTexture(producedRawTexture, surfaceTexture, 0, 0, producedRawTexture.getWidth(), producedRawTexture.getHeight(), textureFilter);
44 | }
45 |
46 | @Override
47 | protected void init() {
48 | super.init();
49 | }
50 |
51 | public void setTextureFilter(TextureFilter textureFilter) {
52 | this.textureFilter = textureFilter;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/video/MediaPlayerTextureView.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.video;
2 |
3 | import android.content.Context;
4 | import android.graphics.SurfaceTexture;
5 | import android.util.AttributeSet;
6 |
7 | import com.chillingvan.canvasgl.ICanvasGL;
8 | import com.chillingvan.canvasgl.glcanvas.RawTexture;
9 | import com.chillingvan.canvasgl.glview.texture.GLSurfaceTextureProducerView;
10 | import com.chillingvan.canvasgl.glview.texture.GLTexture;
11 | import com.chillingvan.canvasgl.textureFilter.BasicTextureFilter;
12 | import com.chillingvan.canvasgl.textureFilter.TextureFilter;
13 |
14 | import androidx.annotation.Nullable;
15 |
16 | /**
17 | * Created by Chilling on 2017/12/16.
18 | */
19 |
20 | public class MediaPlayerTextureView extends GLSurfaceTextureProducerView {
21 |
22 | private TextureFilter textureFilter = new BasicTextureFilter();
23 |
24 | public MediaPlayerTextureView(Context context) {
25 | super(context);
26 | }
27 |
28 | public MediaPlayerTextureView(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | }
31 |
32 | public MediaPlayerTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | }
35 |
36 | @Override
37 | protected void init() {
38 | super.init();
39 | }
40 |
41 | public void setTextureFilter(TextureFilter textureFilter) {
42 | this.textureFilter = textureFilter;
43 | }
44 |
45 | @Override
46 | protected void onGLDraw(ICanvasGL canvas, GLTexture producedGLTexture, @Nullable GLTexture outsideGLTexture) {
47 | super.onGLDraw(canvas, producedGLTexture, outsideGLTexture);
48 | RawTexture producedRawTexture = producedGLTexture.getRawTexture();
49 | SurfaceTexture producedSurfaceTexture = producedGLTexture.getSurfaceTexture();
50 | producedRawTexture.setIsFlippedVertically(true);
51 | producedRawTexture.setIsFlippedHorizontally(true);
52 | canvas.drawSurfaceTexture(producedRawTexture, producedSurfaceTexture, 0, 0, producedRawTexture.getWidth(), producedRawTexture.getHeight(), textureFilter);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/java/com/chillingvan/canvasglsample/video/MergeVideoTextureView.java:
--------------------------------------------------------------------------------
1 | package com.chillingvan.canvasglsample.video;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import com.chillingvan.canvasgl.ICanvasGL;
7 | import com.chillingvan.canvasgl.glview.texture.GLMultiTexConsumerView;
8 | import com.chillingvan.canvasgl.glview.texture.GLTexture;
9 | import com.chillingvan.canvasgl.glview.texture.gles.GLThread;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Only used to consume textures from others.
15 | */
16 | public class MergeVideoTextureView extends GLMultiTexConsumerView {
17 |
18 | public MergeVideoTextureView(Context context) {
19 | super(context);
20 | }
21 |
22 | public MergeVideoTextureView(Context context, AttributeSet attrs) {
23 | super(context, attrs);
24 | }
25 |
26 | public MergeVideoTextureView(Context context, AttributeSet attrs, int defStyleAttr) {
27 | super(context, attrs, defStyleAttr);
28 | }
29 |
30 |
31 | @Override
32 | protected int getRenderMode() {
33 | return GLThread.RENDERMODE_CONTINUOUSLY;
34 | }
35 |
36 | @Override
37 | protected void onGLDraw(ICanvasGL canvas, List consumedTextures) {
38 | int size = consumedTextures.size();
39 | for (int i = 0; i < consumedTextures.size(); i++) {
40 | GLTexture texture = consumedTextures.get(i);
41 | int left = getWidth() * i / size;
42 | canvas.drawSurfaceTexture(texture.getRawTexture(), texture.getSurfaceTexture(), left, 0, left + getWidth()/size, getHeight());
43 | }
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/drawable-nodpi/baboon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/res/drawable-nodpi/baboon.png
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/drawable-nodpi/lenna.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/res/drawable-nodpi/lenna.png
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/drawable-nodpi/lookup_amatorka.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/res/drawable-nodpi/lookup_amatorka.png
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/drawable-xhdpi/ic_robot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/res/drawable-xhdpi/ic_robot.png
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
34 |
35 |
41 |
42 |
43 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_camera_offscreen.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 |
21 |
22 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_compare_canvas.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
34 |
35 |
40 |
41 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_compare_performace.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
25 |
26 |
33 |
34 |
35 |
43 |
44 |
45 |
53 |
54 |
55 |
56 |
61 |
62 |
68 |
69 |
75 |
76 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_draw_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
25 |
26 |
36 |
37 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
33 |
34 |
40 |
41 |
48 |
53 |
54 |
59 |
60 |
68 |
69 |
70 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_media_player.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
15 |
16 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_merge_video.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
17 |
18 |
24 |
25 |
32 |
33 |
34 |
35 |
36 |
42 |
43 |
44 |
53 |
54 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_multi_tex_off_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
27 |
28 |
38 |
39 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_multi_texture.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
16 |
17 |
25 |
26 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_off_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
33 |
34 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_screen_record.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
23 |
24 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_simple_off_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
33 |
34 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_test_matrix.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_test_matrix_surface.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/activity_texture_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/item_case_filter.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
28 |
29 |
36 |
37 |
43 |
44 |
50 |
51 |
52 |
53 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/layout/item_texture_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
21 |
22 |
35 |
36 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/canvasglsample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
25 | 64dp
26 |
27 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
23 |
24 | 需要权限,否则崩溃╮(╯▽╰)╭
25 | 选照片一
26 | 选照片二
27 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
23 | #3F51B5
24 | #303F9F
25 | #FF4081
26 |
27 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 | 16dp
24 | 16dp
25 |
26 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 | CanvasGLSample
23 | permission needed..╮(╯▽╰)╭
24 | firstImage
25 | secondImage
26 |
27 |
--------------------------------------------------------------------------------
/canvasglsample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
24 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # /*
3 | # *
4 | # * * Copyright (C) 2016 ChillingVan
5 | # * *
6 | # * * Licensed under the Apache License, Version 2.0 (the "License");
7 | # * * you may not use this file except in compliance with the License.
8 | # * * You may obtain a copy of the License at
9 | # * *
10 | # * * http://www.apache.org/licenses/LICENSE-2.0
11 | # * *
12 | # * * Unless required by applicable law or agreed to in writing, software
13 | # * * distributed under the License is distributed on an "AS IS" BASIS,
14 | # * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # * * See the License for the specific language governing permissions and
16 | # * * limitations under the License.
17 | # *
18 | # */
19 | #
20 |
21 | # Project-wide Gradle settings.
22 |
23 | # IDE (e.g. Android Studio) users:
24 | # Gradle settings configured through the IDE *will override*
25 | # any settings specified in this file.
26 |
27 | # For more details on how to configure your build environment visit
28 | # http://www.gradle.org/docs/current/userguide/build_environment.html
29 |
30 | # Specifies the JVM arguments used for the daemon process.
31 | # The setting is particularly useful for tweaking memory settings.
32 | android.enableJetifier=true
33 | android.useAndroidX=true
34 | org.gradle.jvmargs=-Xmx1536m
35 |
36 | # When configured, Gradle will run in incubating parallel mode.
37 | # This option should only be used with decoupled projects. More details, visit
38 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
39 | # org.gradle.parallel=true
40 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jun 02 13:39:04 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk11
--------------------------------------------------------------------------------
/screenshots/anim-activity-example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/screenshots/anim-activity-example.png
--------------------------------------------------------------------------------
/screenshots/camera-example-v1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/screenshots/camera-example-v1.jpg
--------------------------------------------------------------------------------
/screenshots/canvas-example-v1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/screenshots/canvas-example-v1.png
--------------------------------------------------------------------------------
/screenshots/filter_example-v1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChillingVan/android-openGL-canvas/228eb6905435147c723c99bdc8b6b51d7cc88602/screenshots/filter_example-v1.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * *
4 | * * * Copyright (C) 2016 ChillingVan
5 | * * *
6 | * * * Licensed under the Apache License, Version 2.0 (the "License");
7 | * * * you may not use this file except in compliance with the License.
8 | * * * You may obtain a copy of the License at
9 | * * *
10 | * * * http://www.apache.org/licenses/LICENSE-2.0
11 | * * *
12 | * * * Unless required by applicable law or agreed to in writing, software
13 | * * * distributed under the License is distributed on an "AS IS" BASIS,
14 | * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * * * See the License for the specific language governing permissions and
16 | * * * limitations under the License.
17 | * *
18 | *
19 | */
20 |
21 | include ':canvasgl', ':canvasglsample'
22 |
--------------------------------------------------------------------------------