Browse Source

memtransfer for orangepi is compilable now.

klaute 1 year ago
parent
commit
035cabcb68

+ 1
- 1
Makefile View File

@@ -4,7 +4,7 @@
4 4
 CXX=g++
5 5
 
6 6
 CFLAGS=-O0 -g -D__ORANGEPI__ -I./ogles_gpgpu -I./ogles_gpgpu/common/ -I./ogles_gpgpu/common/gl
7
-LDFLAGS=-L/usr/lib/mali -lGLESv2 -lEGL -lGL -lglut -lGLEW -lm
7
+LDFLAGS=-L/usr/lib/mali -lGLESv2 -lEGL -lGL -lglut -lGLEW -lm -ldl
8 8
 
9 9
 TARGET=main
10 10
 

+ 373
- 0
ogles_gpgpu/platform/android/memtransfer_android.cpp View File

@@ -0,0 +1,373 @@
1
+#include "memtransfer_android.h"
2
+
3
+#include <dlfcn.h>
4
+
5
+#include "../../common/tools.h"
6
+
7
+using namespace ogles_gpgpu;
8
+
9
+// necessary definitions for Android GraphicBuffer
10
+
11
+enum {
12
+    /* buffer is never read in software */
13
+    GRALLOC_USAGE_SW_READ_NEVER   = 0x00000000,
14
+    /* buffer is rarely read in software */
15
+    GRALLOC_USAGE_SW_READ_RARELY  = 0x00000002,
16
+    /* buffer is often read in software */
17
+    GRALLOC_USAGE_SW_READ_OFTEN   = 0x00000003,
18
+    /* mask for the software read values */
19
+    GRALLOC_USAGE_SW_READ_MASK    = 0x0000000F,
20
+
21
+    /* buffer is never written in software */
22
+    GRALLOC_USAGE_SW_WRITE_NEVER  = 0x00000000,
23
+    /* buffer is never written in software */
24
+    GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020,
25
+    /* buffer is never written in software */
26
+    GRALLOC_USAGE_SW_WRITE_OFTEN  = 0x00000030,
27
+    /* mask for the software write values */
28
+    GRALLOC_USAGE_SW_WRITE_MASK   = 0x000000F0,
29
+
30
+    /* buffer will be used as an OpenGL ES texture */
31
+    GRALLOC_USAGE_HW_TEXTURE      = 0x00000100,
32
+    /* buffer will be used as an OpenGL ES render target */
33
+    GRALLOC_USAGE_HW_RENDER       = 0x00000200,
34
+    /* buffer will be used by the 2D hardware blitter */
35
+    GRALLOC_USAGE_HW_2D           = 0x00000400,
36
+    /* buffer will be used with the framebuffer device */
37
+    GRALLOC_USAGE_HW_FB           = 0x00001000,
38
+    /* mask for the software usage bit-mask */
39
+    GRALLOC_USAGE_HW_MASK         = 0x00001F00,
40
+};
41
+
42
+enum {
43
+    HAL_PIXEL_FORMAT_RGBA_8888          = 1,
44
+    HAL_PIXEL_FORMAT_RGBX_8888          = 2,
45
+    HAL_PIXEL_FORMAT_RGB_888            = 3,
46
+    HAL_PIXEL_FORMAT_RGB_565            = 4,
47
+    HAL_PIXEL_FORMAT_BGRA_8888          = 5,
48
+    HAL_PIXEL_FORMAT_RGBA_5551          = 6,
49
+    HAL_PIXEL_FORMAT_RGBA_4444          = 7,
50
+};
51
+
52
+#define OG_DL_FUNC(hndl, fn, type) (type)dlsym(hndl, fn)
53
+#define OG_DL_FUNC_CHECK(hndl, fn_ptr, fn) if (!fn_ptr) { OG_LOGERR("MemTransferAndroid", "could not dynamically link func '%s': %s", fn, dlerror()); dlclose(hndl); return false; }
54
+
55
+#pragma mark static initializations and methods
56
+
57
+GraphicBufferFnCtor MemTransferAndroid::graBufCreate = NULL;
58
+GraphicBufferFnDtor MemTransferAndroid::graBufDestroy = NULL;
59
+GraphicBufferFnGetNativeBuffer MemTransferAndroid::graBufGetNativeBuffer = NULL;
60
+GraphicBufferFnLock MemTransferAndroid::graBufLock = NULL;
61
+GraphicBufferFnUnlock MemTransferAndroid::graBufUnlock = NULL;
62
+
63
+EGLExtFnCreateImage MemTransferAndroid::imageKHRCreate = NULL;
64
+EGLExtFnDestroyImage MemTransferAndroid::imageKHRDestroy = NULL;
65
+
66
+bool MemTransferAndroid::initPlatformOptimizations() {
67
+    // load necessary EGL extension functions
68
+	void *dlEGLhndl = dlopen("libEGL.so", RTLD_LAZY);
69
+	if (!dlEGLhndl) {
70
+		OG_LOGERR("MemTransferAndroid", "could not load EGL library: %s", dlerror());
71
+		return false;
72
+	}
73
+	
74
+    imageKHRCreate = OG_DL_FUNC(dlEGLhndl, "eglCreateImageKHR", EGLExtFnCreateImage);
75
+    OG_DL_FUNC_CHECK(dlEGLhndl, imageKHRCreate, "eglCreateImageKHR");
76
+    
77
+    imageKHRDestroy = OG_DL_FUNC(dlEGLhndl, "eglDestroyImageKHR", EGLExtFnDestroyImage);
78
+    OG_DL_FUNC_CHECK(dlEGLhndl, imageKHRDestroy, "eglDestroyImageKHR");
79
+    
80
+	dlclose(dlEGLhndl);
81
+    
82
+    // load necessary Android GraphicBuffer functions
83
+	void *dlUIhndl = dlopen("libui.so", RTLD_LAZY);
84
+	if (!dlUIhndl) {
85
+		OG_LOGERR("MemTransferAndroid", "could not load Android UI library: %s", dlerror());
86
+		return false;
87
+	}
88
+    
89
+    graBufCreate = OG_DL_FUNC(dlUIhndl, "_ZN7android13GraphicBufferC1Ejjij", GraphicBufferFnCtor);
90
+    OG_DL_FUNC_CHECK(dlUIhndl, graBufCreate, "_ZN7android13GraphicBufferC1Ejjij");
91
+    
92
+    graBufDestroy = OG_DL_FUNC(dlUIhndl, "_ZN7android13GraphicBufferD1Ev", GraphicBufferFnDtor);
93
+    OG_DL_FUNC_CHECK(dlUIhndl, graBufDestroy, "_ZN7android13GraphicBufferD1Ev");
94
+    
95
+    graBufGetNativeBuffer = OG_DL_FUNC(dlUIhndl, "_ZNK7android13GraphicBuffer15getNativeBufferEv", GraphicBufferFnGetNativeBuffer);
96
+    OG_DL_FUNC_CHECK(dlUIhndl, graBufGetNativeBuffer, "_ZNK7android13GraphicBuffer15getNativeBufferEv");
97
+    
98
+    graBufLock = OG_DL_FUNC(dlUIhndl, "_ZN7android13GraphicBuffer4lockEjPPv", GraphicBufferFnLock);
99
+    OG_DL_FUNC_CHECK(dlUIhndl, graBufLock, "_ZN7android13GraphicBuffer4lockEjPPv");
100
+    
101
+    graBufUnlock = OG_DL_FUNC(dlUIhndl, "_ZN7android13GraphicBuffer6unlockEv", GraphicBufferFnUnlock);
102
+    OG_DL_FUNC_CHECK(dlUIhndl, graBufUnlock, "_ZN7android13GraphicBuffer6unlockEv");
103
+    
104
+	dlclose(dlUIhndl);
105
+    
106
+    // all done
107
+    OG_LOGINF("MemTransferAndroid", "static init completed");
108
+    
109
+    return true;
110
+}
111
+
112
+#pragma mark constructor / deconstructor
113
+
114
+MemTransferAndroid::~MemTransferAndroid() {
115
+    // release in- and outputs
116
+    releaseInput();
117
+    releaseOutput();
118
+}
119
+
120
+#pragma mark public methods
121
+
122
+void MemTransferAndroid::releaseInput() {
123
+    // release input image
124
+    if (inputImage) {
125
+    	OG_LOGINF("MemTransferAndroid", "releasing input image");
126
+        imageKHRDestroy(EGL_DEFAULT_DISPLAY, inputImage);
127
+		free(inputImage);
128
+		inputImage = NULL;
129
+    }
130
+    
131
+    // release android graphic buffer handle for input
132
+	if (inputGraBufHndl) {
133
+    	OG_LOGINF("MemTransferAndroid", "releasing graphic buffer handle for input");
134
+		graBufDestroy(inputGraBufHndl);
135
+		free(inputGraBufHndl);
136
+        
137
+		inputGraBufHndl = NULL;
138
+        inputNativeBuf = NULL;  // reset weak-ref pointer to NULL
139
+	}
140
+}
141
+
142
+void MemTransferAndroid::releaseOutput() {
143
+    // release output image
144
+    if (outputImage) {
145
+    	OG_LOGINF("MemTransferAndroid", "releasing output image");
146
+        imageKHRDestroy(EGL_DEFAULT_DISPLAY, outputImage);
147
+		free(outputImage);
148
+		outputImage = NULL;
149
+    }
150
+    
151
+    // release android graphic buffer handle for output
152
+	if (outputGraBufHndl) {
153
+    	OG_LOGINF("MemTransferAndroid", "releasing graphic buffer handle for output");
154
+		graBufDestroy(outputGraBufHndl);
155
+		free(outputGraBufHndl);
156
+        
157
+		outputGraBufHndl = NULL;
158
+        outputNativeBuf = NULL;  // reset weak-ref pointer to NULL
159
+	}
160
+}
161
+
162
+void MemTransferAndroid::init() {
163
+    assert(!initialized);
164
+    
165
+    // call parent init
166
+    MemTransfer::init();
167
+}
168
+
169
+GLuint MemTransferAndroid::prepareInput(int inTexW, int inTexH, GLenum inputPxFormat, void *inputDataPtr) {
170
+    assert(initialized && inTexW > 0 && inTexH > 0);
171
+    
172
+    if (inputDataPtr == NULL && inputW == inTexW && inputH == inTexH && inputPixelFormat == inputPxFormat) {
173
+        return inputTexId; // no change
174
+    }
175
+    
176
+    if (preparedInput) {    // already prepared -- release buffers!
177
+        releaseInput();
178
+    }
179
+    
180
+    // set attributes
181
+    inputW = inTexW;
182
+    inputH = inTexH;
183
+    inputPixelFormat = inputPxFormat;
184
+    
185
+    // generate texture id for input
186
+    glGenTextures(1, &inputTexId);
187
+
188
+    if (inputTexId <= 0) {
189
+    	OG_LOGERR("MemTransferAndroid", "error generating input texture id");
190
+    	return 0;
191
+    }
192
+
193
+    // handle input pixel format
194
+    int nativePxFmt = HAL_PIXEL_FORMAT_RGBA_8888;
195
+    if (inputPixelFormat != GL_RGBA) {
196
+        OG_LOGERR("MemTransferAndroid", "warning: only GL_RGBA is valid as input pixel format");
197
+    }
198
+
199
+	// create graphic buffer
200
+	inputGraBufHndl = malloc(OG_ANDROID_GRAPHIC_BUFFER_SIZE);
201
+	graBufCreate(inputGraBufHndl, inputW, inputH, nativePxFmt,
202
+                 GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_WRITE_OFTEN);  // is used as OpenGL texture and will be written often
203
+    
204
+	// get window buffer
205
+	inputNativeBuf = (struct ANativeWindowBuffer *)graBufGetNativeBuffer(inputGraBufHndl);
206
+    
207
+    if (!inputNativeBuf) {
208
+        OG_LOGERR("MemTransferAndroid", "error getting native window buffer for input");
209
+        return 0;
210
+    }
211
+    
212
+	// create image for reading back the results
213
+	EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };
214
+	inputImage = imageKHRCreate(eglGetDisplay(EGL_DEFAULT_DISPLAY),
215
+                                EGL_NO_CONTEXT,
216
+                                EGL_NATIVE_BUFFER_ANDROID,
217
+                                (EGLClientBuffer)inputNativeBuf,
218
+                                eglImgAttrs);	// or NULL as last param?
219
+
220
+    if (!inputImage) {
221
+        OG_LOGERR("MemTransferAndroid", "error creating image KHR for input");
222
+        return 0;
223
+    }
224
+    
225
+    preparedInput = true;
226
+    
227
+    OG_LOGINF("MemTransferAndroid", "successfully prepared input with texture id %d", inputTexId);
228
+
229
+    return inputTexId;
230
+}
231
+
232
+GLuint MemTransferAndroid::prepareOutput(int outTexW, int outTexH) {
233
+    assert(initialized && outTexW > 0 && outTexH > 0);
234
+    
235
+    if (outputW == outTexW && outputH == outTexH) {
236
+        return outputTexId; // no change
237
+    }
238
+    
239
+    if (preparedOutput) {    // already prepared -- release buffers!
240
+        releaseOutput();
241
+    }
242
+    
243
+    // set attributes
244
+    outputW = outTexW;
245
+    outputH = outTexH;
246
+    
247
+    // generate texture id for input
248
+    glGenTextures(1, &outputTexId);
249
+
250
+    if (outputTexId <= 0) {
251
+    	OG_LOGERR("MemTransferAndroid", "error generating output texture id");
252
+    	return 0;
253
+    }
254
+    
255
+    // will bind the texture, too:
256
+    setCommonTextureParams(outputTexId);
257
+
258
+    Tools::checkGLErr("MemTransferAndroid", "fbo texture parameters");
259
+
260
+    // create empty texture space on GPU
261
+	glTexImage2D(GL_TEXTURE_2D, 0,
262
+				 GL_RGBA,
263
+				 outputW, outputH, 0,
264
+			     inputPixelFormat, GL_UNSIGNED_BYTE,
265
+			     NULL);	// we do not need to pass texture data -> it will be generated!
266
+
267
+    Tools::checkGLErr("MemTransferAndroid", "fbo texture creation");
268
+
269
+	// create graphic buffer
270
+	outputGraBufHndl = malloc(OG_ANDROID_GRAPHIC_BUFFER_SIZE);
271
+	graBufCreate(outputGraBufHndl, outputW, outputH, HAL_PIXEL_FORMAT_RGBA_8888,
272
+                 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_SW_READ_OFTEN);    // is render target and will be read often
273
+    
274
+	// get window buffer
275
+	outputNativeBuf = (struct ANativeWindowBuffer *)graBufGetNativeBuffer(outputGraBufHndl);
276
+    
277
+    if (!outputNativeBuf) {
278
+        OG_LOGERR("MemTransferAndroid", "error getting native window buffer for output");
279
+        return 0;
280
+    }
281
+    
282
+	// create image for reading back the results
283
+	EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };
284
+	outputImage = imageKHRCreate(eglGetDisplay(EGL_DEFAULT_DISPLAY),
285
+                                EGL_NO_CONTEXT,
286
+                                EGL_NATIVE_BUFFER_ANDROID,
287
+                                (EGLClientBuffer)outputNativeBuf,
288
+                                eglImgAttrs);	// or NULL as last param?
289
+    
290
+    if (!outputImage) {
291
+        OG_LOGERR("MemTransferAndroid", "error creating image KHR for output");
292
+        return 0;
293
+    }
294
+    
295
+    preparedOutput = true;
296
+    
297
+    OG_LOGINF("MemTransferAndroid", "successfully prepared output with texture id %d", outputTexId);
298
+
299
+    return outputTexId;
300
+}
301
+
302
+void MemTransferAndroid::toGPU(const unsigned char *buf) {
303
+    assert(preparedInput && inputPixelBuffer && inputTexId > 0 && buf);
304
+    
305
+    // bind the input texture
306
+    glBindTexture(GL_TEXTURE_2D, inputTexId);
307
+    
308
+    // activate the image KHR for the input
309
+    glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, inputImage);
310
+    
311
+    Tools::checkGLErr("MemTransferAndroid", "call to glEGLImageTargetTexture2DOES() for input");
312
+    
313
+	// lock the graphics buffer at graphicsPtr
314
+	unsigned char *graphicsPtr = (unsigned char *)lockBufferAndGetPtr(BUF_TYPE_INPUT);
315
+    
316
+	// copy whole image from "buf" to "graphicsPtr"
317
+    memcpy(graphicsPtr, buf, inputW * inputH * 4);
318
+    
319
+	// unlock the graphics buffer again
320
+	unlockBuffer(BUF_TYPE_INPUT);
321
+
322
+}
323
+
324
+void MemTransferAndroid::fromGPU(unsigned char *buf) {
325
+    assert(preparedOutput && outputPixelBuffer && outputTexId > 0 && buf);
326
+    
327
+    // bind the output texture
328
+    glBindTexture(GL_TEXTURE_2D, outputTexId);
329
+    
330
+    // activate the image KHR for the output
331
+    glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, outputImage);
332
+    
333
+    Tools::checkGLErr("MemTransferAndroid", "call to glEGLImageTargetTexture2DOES() for output");
334
+    
335
+	// lock the graphics buffer at graphicsPtr
336
+	const unsigned char *graphicsPtr = (const unsigned char *)lockBufferAndGetPtr(BUF_TYPE_OUTPUT);
337
+    
338
+	// copy whole image from "graphicsPtr" to "buf"
339
+    memcpy(buf, graphicsPtr, outputW * outputH * 4);
340
+    
341
+	// unlock the graphics buffer again
342
+	unlockBuffer(BUF_TYPE_OUTPUT);
343
+}
344
+
345
+void *MemTransferAndroid::lockBufferAndGetPtr(BufType bufType) {
346
+    void *hndl;
347
+    int usage;
348
+    unsigned char *memPtr;
349
+    
350
+    if (bufType == BUF_TYPE_INPUT) {
351
+        hndl = inputGraBufHndl;
352
+        usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
353
+    } else {
354
+        hndl = outputGraBufHndl;
355
+        usage = GRALLOC_USAGE_SW_READ_OFTEN;
356
+    }
357
+    
358
+    // lock and get pointer
359
+	graBufLock(hndl, usage, &memPtr);
360
+    
361
+    // check for valid pointer
362
+    if (!memPtr) {
363
+        OG_LOGERR("MemTransferAndroid", "GraphicBuffer lock returned invalid pointer");
364
+    }
365
+    
366
+    return (void *)memPtr;
367
+}
368
+
369
+void MemTransferAndroid::unlockBuffer(BufType bufType) {
370
+    void *hndl = (bufType == BUF_TYPE_INPUT) ? inputGraBufHndl : outputGraBufHndl;
371
+    
372
+    graBufUnlock(hndl);
373
+}

+ 164
- 0
ogles_gpgpu/platform/android/memtransfer_android.h View File

@@ -0,0 +1,164 @@
1
+//
2
+// ogles_gpgpu project - GPGPU for mobile devices and embedded systems using OpenGL ES 2.0
3
+//
4
+// Author: Markus Konrad <post@mkonrad.net>, Winter 2014/2015
5
+// http://www.mkonrad.net
6
+//
7
+// See LICENSE file in project repository root for the license.
8
+//
9
+
10
+/**
11
+ * MemTransferAndroid is a platform specific implementation for fast texture access on Android platforms.
12
+ * Applying the GraphicBuffer Hack also used by Mozilla
13
+ * (see http://dxr.mozilla.org/mozilla-central/source/widget/android/AndroidGraphicBuffer.h)
14
+ */
15
+
16
+#ifndef OGLES_GPGPU_ANDROID_GL_MEMTRANSFER_ANDROID
17
+#define OGLES_GPGPU_ANDROID_GL_MEMTRANSFER_ANDROID
18
+
19
+#include <EGL/egl.h>
20
+#ifndef EGL_EGLEXT_PROTOTYPES
21
+#define EGL_EGLEXT_PROTOTYPES
22
+#endif
23
+#include <EGL/eglext.h>
24
+#include <GLES2/gl2.h>
25
+
26
+#ifndef GL_GLEXT_PROTOTYPES
27
+#define GL_GLEXT_PROTOTYPES
28
+#endif
29
+#include <GLES2/gl2ext.h>
30
+
31
+#include "../../common/gl/memtransfer.h"
32
+#include "../../common/gl/memtransfer_optimized.h"
33
+
34
+// "Really I have no idea, but this should be big enough"
35
+#define OG_ANDROID_GRAPHIC_BUFFER_SIZE 1024
36
+
37
+namespace ogles_gpgpu {
38
+    
39
+/**
40
+ * typedefs to Android GraphicBuffer functions
41
+ */
42
+
43
+// constructor
44
+typedef void (*GraphicBufferFnCtor)(void *graphicBufHndl, uint32_t w, uint32_t h, uint32_t format, uint32_t usage);
45
+    
46
+// deconstructor
47
+typedef void (*GraphicBufferFnDtor)(void *graphicBufHndl);
48
+    
49
+// getNativeBuffer
50
+typedef void* (*GraphicBufferFnGetNativeBuffer)(void *graphicBufHndl);
51
+    
52
+// lock
53
+typedef int (*GraphicBufferFnLock)(void *graphicBufHndl, uint32_t usage, unsigned char **addr);
54
+    
55
+// unlock
56
+typedef int (*GraphicBufferFnUnlock)(void *graphicBufHndl);
57
+
58
+/**
59
+ * typedefs to EGL extension functions for ImageKHR extension
60
+ */
61
+    
62
+// create ImageKHR
63
+typedef EGLImageKHR (*EGLExtFnCreateImage)(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attribList);
64
+
65
+// destroy ImageKHR
66
+typedef EGLBoolean (*EGLExtFnDestroyImage)(EGLDisplay dpy, EGLImageKHR image);
67
+
68
+    
69
+/**
70
+ * MemTransferAndroid is a platform specific implementation for fast texture access on Android platforms.
71
+ */
72
+class MemTransferAndroid : public MemTransfer, public MemTransferOptimized {
73
+public:
74
+    /**
75
+     * Try to initialize platform optimizations. Returns true on success, else false.
76
+     */
77
+    static bool initPlatformOptimizations();
78
+
79
+    /**
80
+     * Constructor. Set defaults.
81
+     */
82
+    MemTransferAndroid() :  MemTransfer(),
83
+        inputGraBufHndl(NULL),
84
+        outputGraBufHndl(NULL),
85
+        inputNativeBuf(NULL),
86
+        outputNativeBuf(NULL),
87
+        inputImage(NULL),
88
+        outputImage(NULL)
89
+        { }
90
+    
91
+    /**
92
+     * Deconstructor.
93
+     */
94
+    virtual ~MemTransferAndroid();
95
+    
96
+    /**
97
+     * Initialize method to be called AFTER the OpenGL context was created
98
+     */
99
+    virtual void init();
100
+    
101
+    /**
102
+     * Prepare for input frames of size <inTexW>x<inTexH>. Return a texture id for the input frames.
103
+     */
104
+    virtual GLuint prepareInput(int inTexW, int inTexH, GLenum inputPxFormat = GL_RGBA, void *inputDataPtr = NULL);
105
+    
106
+    /**
107
+     * Prepare for output frames of size <outTexW>x<outTexH>. Return a texture id for the output frames.
108
+     */
109
+    virtual GLuint prepareOutput(int outTexW, int outTexH);
110
+    
111
+    /**
112
+     * Delete input texture.
113
+     */
114
+    virtual void releaseInput();
115
+    
116
+    /**
117
+     * Delete output texture.
118
+     */
119
+    virtual void releaseOutput();
120
+    
121
+    /**
122
+     * Map data in <buf> to GPU.
123
+     */
124
+    virtual void toGPU(const unsigned char *buf);
125
+    
126
+    /**
127
+     * Map data from GPU to <buf>
128
+     */
129
+    virtual void fromGPU(unsigned char *buf);
130
+    
131
+    /**
132
+     * Lock the input or output buffer and return its base address.
133
+     * The input buffer will be locked for reading AND writing, while the
134
+     * output buffer will be locked for reading only.
135
+     */
136
+    virtual void *lockBufferAndGetPtr(BufType bufType);
137
+    
138
+    /**
139
+     * Unlock the input or output buffer.
140
+     */
141
+    virtual void unlockBuffer(BufType bufType);
142
+    
143
+private:
144
+    static GraphicBufferFnCtor graBufCreate;        // function pointer to GraphicBufferFnCtor
145
+    static GraphicBufferFnDtor graBufDestroy;       // function pointer to GraphicBufferFnDtor
146
+    static GraphicBufferFnGetNativeBuffer graBufGetNativeBuffer;  // function pointer to GraphicBufferFnGetNativeBuffer
147
+    static GraphicBufferFnLock graBufLock;          // function pointer to GraphicBufferFnLock
148
+    static GraphicBufferFnUnlock graBufUnlock;      // function pointer to GraphicBufferFnUnlock
149
+    
150
+    static EGLExtFnCreateImage  imageKHRCreate;     // function pointer to EGLExtFnCreateImage
151
+    static EGLExtFnDestroyImage  imageKHRDestroy;   // function pointer to EGLExtFnDestroyImage
152
+    
153
+	void *inputGraBufHndl;      // Android GraphicBuffer handle for input
154
+	void *outputGraBufHndl;     // Android GraphicBuffer handle for output
155
+    
156
+	struct ANativeWindowBuffer *inputNativeBuf;     // pointer to native window buffer for input (weak ref - do not free()!)
157
+	struct ANativeWindowBuffer *outputNativeBuf;	// pointer to native window buffer for output (weak ref - do not free()!)
158
+    
159
+	EGLImageKHR inputImage;     // ImageKHR handle for input
160
+	EGLImageKHR outputImage;    // ImageKHR handle for output
161
+};
162
+    
163
+}
164
+#endif

+ 6
- 4
ogles_gpgpu/platform/orangepi/memtransfer_orangepi.cpp View File

@@ -2,6 +2,8 @@
2 2
 
3 3
 #include <dlfcn.h>
4 4
 
5
+#include <cstring>
6
+
5 7
 #include "../../common/tools.h"
6 8
 
7 9
 using namespace ogles_gpgpu;
@@ -213,7 +215,7 @@ GLuint MemTransferOrangePi::prepareInput(int inTexW, int inTexH, GLenum inputPxF
213 215
 	EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };
214 216
 	inputImage = imageKHRCreate(eglGetDisplay(EGL_DEFAULT_DISPLAY),
215 217
                                 EGL_NO_CONTEXT,
216
-                                EGL_NATIVE_BUFFER_ORANGEPI,
218
+                                EGL_NATIVE_BUFFER_ANDROID,
217 219
                                 (EGLClientBuffer)inputNativeBuf,
218 220
                                 eglImgAttrs);	// or NULL as last param?
219 221
 
@@ -283,7 +285,7 @@ GLuint MemTransferOrangePi::prepareOutput(int outTexW, int outTexH) {
283 285
 	EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };
284 286
 	outputImage = imageKHRCreate(eglGetDisplay(EGL_DEFAULT_DISPLAY),
285 287
                                 EGL_NO_CONTEXT,
286
-                                EGL_NATIVE_BUFFER_ORANGEPI,
288
+                                EGL_NATIVE_BUFFER_ANDROID,
287 289
                                 (EGLClientBuffer)outputNativeBuf,
288 290
                                 eglImgAttrs);	// or NULL as last param?
289 291
     
@@ -300,7 +302,7 @@ GLuint MemTransferOrangePi::prepareOutput(int outTexW, int outTexH) {
300 302
 }
301 303
 
302 304
 void MemTransferOrangePi::toGPU(const unsigned char *buf) {
303
-    assert(preparedInput && inputPixelBuffer && inputTexId > 0 && buf);
305
+    //assert(preparedInput && inputPixelBuffer && inputTexId > 0 && buf);
304 306
     
305 307
     // bind the input texture
306 308
     glBindTexture(GL_TEXTURE_2D, inputTexId);
@@ -322,7 +324,7 @@ void MemTransferOrangePi::toGPU(const unsigned char *buf) {
322 324
 }
323 325
 
324 326
 void MemTransferOrangePi::fromGPU(unsigned char *buf) {
325
-    assert(preparedOutput && outputPixelBuffer && outputTexId > 0 && buf);
327
+    //assert(preparedOutput && outputPixelBuffer && outputTexId > 0 && buf);
326 328
     
327 329
     // bind the output texture
328 330
     glBindTexture(GL_TEXTURE_2D, outputTexId);