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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ allprojects {

// module build.gradle
dependencies {
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.5.2.0'
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.5.3.0'
}
```

Expand Down Expand Up @@ -127,6 +127,7 @@ It has sync and async modes.

You can use canvasGL.invalidateTextureContent(bitmap) to rebind the bitmap to texture.
This is kind of heavy so I do not update call this for every drawn.
* The CanvasGL doesn't support drawPath or drawText. You can try IAndroidCanvasHelper but this just uses Android canvas to generate a Bitmap. So heed the performance.

## Latest Update
* Add record screen demo
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


## 使用要求
* Android API 14 以上(OpenGL ES 2.0 以上)
* Android API 14 以上(OpenGL ES 2.0 以上)。 建议21以上

## 用法

Expand All @@ -48,7 +48,7 @@ allprojects {

// module build.gradle
dependencies {
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.5.2.0'
implementation 'com.github.ChillingVan:android-openGL-canvas:v1.5.3.0'
}
```

Expand Down Expand Up @@ -126,10 +126,11 @@ public class MyGLView extends GLView {

## 注意事项和常见问题
* 每一个View的onGLDraw都运行在自己的线程而非主线程。
* 目前的Filter没有GPUImage里那么多,后续会陆续增加,如果有需要,参照我的代码自己实现即可,难度不高。
* 目前的Filter没有GPUImage里那么多,如果有需要,参照我的代码自己实现即可,难度不高。
* 为什么Bitmap修改后,再次绘制时并没更新?

因为没有调用canvasGL的invalidateTextureContent(bitmap)。改变了的Bitmap需要重新绑定texture。因为绑定需要耗时,所以库里面才不做成每次都重新绑定。
* CanvasGL里面没有drawPath或者drawText,要实现的话本库提供了IAndroidCanvasHelper,但这个只是用安卓自己的canvas生成一个Bitmap,所以要注意性能

## 相关博客文章
* [OpenGL绘制一张图片的流程](http://www.jianshu.com/p/40521c92ef85)
Expand Down
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.6.21'
repositories {
maven{url"https://maven.google.com"}
jcenter()
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:4.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
maven{url"https://maven.google.com"}
jcenter()
google()
mavenCentral()
}
}

Expand Down
43 changes: 26 additions & 17 deletions canvasgl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
*/

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.ChillingVan'
def VERSION_NAME="1.5.2.0"
apply plugin: 'maven-publish'
def NAMESPACE="com.github.ChillingVan"
group = NAMESPACE
def VERSION_NAME="1.5.3.0"

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
namespace = NAMESPACE
compileSdkVersion 32
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 105020
targetSdkVersion 32
versionCode 105030
versionName VERSION_NAME
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
Expand All @@ -46,13 +47,17 @@ android {
// but continue the build even when errors are found:
abortOnError false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'androidx.annotation:annotation:1.3.0'
}


Expand Down Expand Up @@ -81,14 +86,18 @@ artifacts {
archives javadocJar
}

/**
* Used to support other project uses mavenLocal() to refer this project which is convenient to debug
*/
install {
repositories.mavenInstaller {
pom.version = 'v' + VERSION_NAME
pom.artifactId = 'android-openGL-canvas'

afterEvaluate {
publishing {
publications {
// Creates a Maven publication called "release".
release(MavenPublication) {
from components.release
groupId = NAMESPACE
artifactId = 'android-openGL-canvas'
version = VERSION_NAME
}
}
}
}


7 changes: 4 additions & 3 deletions canvasgl/src/main/java/com/chillingvan/canvasgl/CanvasGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import android.graphics.SurfaceTexture;
import android.opengl.GLES20;
import android.os.Build;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.chillingvan.canvasgl.glcanvas.BasicTexture;
import com.chillingvan.canvasgl.glcanvas.BitmapTexture;
Expand All @@ -50,6 +47,10 @@
import java.util.Map;
import java.util.WeakHashMap;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
* All the depth of textures are the same. So the texture drawn after will cover the texture drawn before.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import android.graphics.SurfaceTexture;
import android.opengl.GLES20;
import android.opengl.Matrix;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chillingvan.canvasgl.glcanvas.BasicTexture;
import com.chillingvan.canvasgl.glcanvas.BitmapTexture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.chillingvan.canvasgl;

import android.graphics.SurfaceTexture;
import android.support.annotation.Nullable;

import com.chillingvan.canvasgl.glcanvas.BasicTexture;
import com.chillingvan.canvasgl.glcanvas.RawTexture;
Expand All @@ -32,6 +31,8 @@

import java.util.List;

import androidx.annotation.Nullable;

/**
* @deprecated use {@link MultiTexOffScreenCanvas} instead
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ public abstract class BasicTexture implements Texture {
private boolean isRecycled;

protected GLCanvas mCanvasRef = null;
private static WeakHashMap<BasicTexture, Object> sAllTextures
private static final WeakHashMap<BasicTexture, Object> sAllTextures
= new WeakHashMap<BasicTexture, Object>();
private static ThreadLocal sInFinalizer = new ThreadLocal();
private static final ThreadLocal sInFinalizer = new ThreadLocal();
private boolean mIsFlippedVertically;
private boolean mIsFlippedHorizontally;

protected BasicTexture(GLCanvas canvas, int id, int state) {
setAssociatedCanvas(canvas);
Expand Down Expand Up @@ -91,10 +93,6 @@ public void setSize(int width, int height) {
}
}

public boolean isFlippedVertically() {
return false;
}

public int getId() {
return mId;
}
Expand Down Expand Up @@ -148,6 +146,29 @@ public void draw(GLCanvas canvas, int x, int y, int w, int h) {
canvas.drawTexture(this, x, y, w, h, new BasicTextureFilter(), null);
}

public boolean isFlippedVertically() {
return mIsFlippedVertically;
}
public boolean isFlippedHorizontally() {
return mIsFlippedHorizontally;
}

/**
*
* @param isFlipped whether vertically flip this texture
*/
public void setIsFlippedVertically(boolean isFlipped) {
mIsFlippedVertically = isFlipped;
}

/**
*
* @param isFlipped whether horizontally flip this texture
*/
public void setIsFlippedHorizontally(boolean isFlipped) {
mIsFlippedHorizontally = isFlipped;
}

// onBind is called before GLCanvas binds this secondBitmap.
// It should make sure the data is uploaded to GL memory.
abstract protected boolean onBind(GLCanvas canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import androidx.annotation.Nullable;

import com.chillingvan.canvasgl.shapeFilter.DrawShapeFilter;
import com.chillingvan.canvasgl.textureFilter.TextureFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public void restore() {
@Override
public void drawCircle(float x, float y, float radius, GLPaint paint, DrawShapeFilter drawShapeFilter) {
setupDrawShapeFilter(drawShapeFilter);
draw(GLES20.GL_TRIANGLE_STRIP, OFFSET_FILL_RECT, COUNT_FILL_VERTEX, x, y, 2*radius, 2*radius, paint.getColor(), 0f);
draw(GLES20.GL_TRIANGLE_STRIP, OFFSET_FILL_RECT, COUNT_FILL_VERTEX, x, y, 2 * radius, 2 * radius, paint.getColor(), 0f);
}

@Override
Expand Down Expand Up @@ -639,15 +639,22 @@ private void drawTextureRect(BasicTexture texture, float[] textureMatrix, RectF
onPreDrawTextureListener.onPreDraw(texture.getTarget() == GLES20.GL_TEXTURE_2D ? mTextureProgram : mOesTextureProgram, texture, mTextureFilter);
}
checkError();
if (texture.isFlippedVertically()) {
if (texture.isFlippedVertically() || texture.isFlippedHorizontally()) {
save(SAVE_FLAG_MATRIX);
}
if (texture.isFlippedVertically()) {
translate(0, target.centerY());
scale(1, -1, 1);
translate(0, -target.centerY());
}
if (texture.isFlippedHorizontally()) {
translate(target.centerX(), 0);
scale(-1, 1, 1);
translate(-target.centerX(), 0);
}
draw(params, GLES20.GL_TRIANGLE_STRIP, COUNT_FILL_VERTEX, target.left, target.top,
target.width(), target.height(), customMVPMatrix);
if (texture.isFlippedVertically()) {
if (texture.isFlippedVertically() || texture.isFlippedHorizontally()) {
restore();
}
mCountTextureRect++;
Expand Down Expand Up @@ -995,12 +1002,12 @@ public static void printMatrix(String message, float[] m, int offset) {
String format = "%.6f";
b.append(String.format(format, m[offset + i]));
b.append(", ");
b.append(String.format(format, m[offset + 4+i]));
b.append(String.format(format, m[offset + 4 + i]));
b.append(", ");
b.append(String.format(format, m[offset + 8+i]));
b.append(String.format(format, m[offset + 8 + i]));
b.append(", ");
b.append(String.format(format, m[offset + 12+i]));
if (i<size-1) {
b.append(String.format(format, m[offset + 12 + i]));
if (i < size - 1) {
b.append(", ");
}
b.append('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class RawTexture extends BasicTexture {
private static final String TAG = "RawTexture";

private final boolean mOpaque;
private boolean mIsFlipped;
private int target = GL11.GL_TEXTURE_2D;
private int target;
protected boolean needInvalidate;

public RawTexture(int width, int height, boolean opaque) {
Expand All @@ -48,19 +47,6 @@ public boolean isOpaque() {
return mOpaque;
}

@Override
public boolean isFlippedVertically() {
return mIsFlipped;
}

/**
*
* @param isFlipped whether vertically flip this texture
*/
public void setIsFlippedVertically(boolean isFlipped) {
mIsFlipped = isFlipped;
}

public void prepare(GLCanvas canvas) {
GLId glId = canvas.getGLId();
mId = glId.generateTexture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.support.annotation.ColorInt;
import android.util.AttributeSet;

import com.chillingvan.canvasgl.CanvasGL;
Expand All @@ -13,6 +12,8 @@
import com.chillingvan.canvasgl.glview.GLView;
import com.chillingvan.canvasgl.util.Loggers;

import androidx.annotation.ColorInt;

/**
*
* From init to run: onSizeChange --> onSurfaceTextureAvailable --> createGLThread --> createSurface --> onSurfaceCreated --> onSurfaceChanged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.TextureView;

import com.chillingvan.canvasgl.ICanvasGL;
import com.chillingvan.canvasgl.util.Loggers;
import com.chillingvan.canvasgl.glview.texture.gles.EglContextWrapper;
import com.chillingvan.canvasgl.glview.texture.gles.GLThread;
import com.chillingvan.canvasgl.util.Loggers;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;

/**
* Created by Chilling on 2016/10/31.
* Can be used in ScrollView or ListView.
Expand Down
Loading