Skip to content

Commit bfc721f

Browse files
committed
[2019.4.4]打印绘制时候的加载,贴图绘制的时间耗时
1 parent f2a0a56 commit bfc721f

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

app/src/main/cpp/image/ImageInput.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "ImageInput.h"
33
#include <GLES2/gl2ext.h>
44
#include <src/main/cpp/utils/TextureRotationUtil.h>
5+
#include <cinttypes>
56

67
#define LOG_TAG "ImageInput"
78
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
@@ -96,6 +97,7 @@ int ImageInput::onDrawFrame(const GLuint textureId, GLfloat *matrix,const float
9697
}
9798

9899
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
100+
99101
glDisableVertexAttribArray(mGLAttribPosition);
100102
glDisableVertexAttribArray(mGLAttribTextureCoordinate);
101103
glBindTexture(GL_TEXTURE_2D,0);
@@ -131,7 +133,9 @@ GLuint ImageInput::onDrawToTexture(const GLuint textureId, GLfloat *matrix) {
131133
glUniform1i(mGLUniformTexture,0);
132134
}
133135
//绘制图像(长方形)
136+
int64_t drawTime = getTimeMise();
134137
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
138+
ALOGV("getTime:drawTime Time = %" PRId64 "",getTimeMise() - drawTime);
135139
//关闭顶点缓冲
136140
glDisableVertexAttribArray(mGLAttribPosition);
137141
glDisableVertexAttribArray(mGLAttribTextureCoordinate);

app/src/main/cpp/utils/OpenglUtils.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
//引用stb库
1414
#define STB_IMAGE_IMPLEMENTATION
1515
#include "src/main/cpp/utils/stb_image.h"
16-
16+
#include <android/log.h>
17+
#include <cinttypes>
1718

1819
#define LOG_TAG "OpenglUtils"
1920
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
@@ -111,8 +112,11 @@ GLuint loadTextureFromFile(const char *fileName, int *w, int *h,int *n){
111112
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
112113
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
113114

115+
int64_t getDataBefore = getTimeMise();
114116
//读取图片长宽高数据
115117
unsigned char* data = stbi_load(fileName, w, h, n, 0);
118+
int64_t getDataAfter = getTimeMise();
119+
ALOGV("getTime:getImageData Time = %" PRId64 "",getDataAfter - getDataBefore);
116120

117121
ALOGV("loadTexture fileName = %s,width = %d,height=%d,n=%d",fileName,*w,*h,*n);
118122

@@ -124,6 +128,7 @@ GLuint loadTextureFromFile(const char *fileName, int *w, int *h,int *n){
124128
} else{
125129
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, *w, *h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
126130
}
131+
ALOGV("getTime:glTexImage2D Time = %" PRId64 "",getTimeMise() - getDataAfter);
127132
stbi_image_free(data);
128133
return textureHandler;
129134
} else{
@@ -136,6 +141,17 @@ GLuint loadTextureFromFile(const char *fileName, int *w, int *h,int *n){
136141
return textureHandler;
137142
}
138143

144+
int64_t getTimeNesc(){
145+
struct timespec now;
146+
clock_gettime(CLOCK_MONOTONIC,&now);
147+
return (int64_t) now.tv_sec * 1000000000LL + now.tv_nsec;
148+
}
149+
150+
int64_t getTimeMise(){
151+
struct timespec now;
152+
clock_gettime(CLOCK_MONOTONIC,&now);
153+
return (int64_t) now.tv_sec *1000LL + now.tv_nsec/1000000;
154+
}
139155

140156
GLuint loadTextureFromAssetsRepeat(AAssetManager *manager, const char *fileName){
141157
GLuint textureHandler=0;

app/src/main/cpp/utils/OpenglUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ std::string *readShaderFromAsset(AAssetManager *manager, const char *fileName);
2424
unsigned char* getAddressFromAsset(AAssetManager *manager, const char *fileName);
2525
int getSizeFromAsset(AAssetManager *manager, const char *fileName);
2626
unsigned char* getAddressFromAssetFilter(AAssetManager *manager, const char *fileName, int* length);
27+
int64_t getTimeNesc();
28+
int64_t getTimeMise();
2729

2830

0 commit comments

Comments
 (0)