예제 #1
0
EGLBoolean egl_window_surface_t::swapBuffers()
{
    DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);

    rcEnc->rcFlushWindowColorBuffer(rcEnc, rcSurface);

    nativeWindow->queueBuffer(nativeWindow, buffer);
    if (nativeWindow->dequeueBuffer(nativeWindow, &buffer)) {
        buffer = NULL;
        setErrorReturn(EGL_BAD_ALLOC, EGL_FALSE);
    }
    nativeWindow->lockBuffer(nativeWindow, buffer);

    rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface,
            ((cb_handle_t *)(buffer->handle))->hostHandle);

    return EGL_TRUE;
}
예제 #2
0
int IOMXHWBuffer_Lock( void *window, void *p_handle )
{
    ANativeWindow *anw = (ANativeWindow *)window;
    ANativeWindowBuffer_t *anb = (ANativeWindowBuffer_t *)p_handle;
    status_t err = NO_ERROR;

    CHECK_ANW();
    CHECK_ANB();

#if ANDROID_API >= 18
    err = anw->lockBuffer_DEPRECATED( anw, anb );
#else
    err = anw->lockBuffer( anw, anb );
#endif
    CHECK_ERR();

    return 0;
}
예제 #3
0
EGLBoolean egl_window_surface_t::init()
{
    if (nativeWindow->dequeueBuffer(nativeWindow, &buffer) != NO_ERROR) {
        setErrorReturn(EGL_BAD_ALLOC, EGL_FALSE);
    }
    nativeWindow->lockBuffer(nativeWindow, buffer);

    DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);
    rcSurface = rcEnc->rcCreateWindowSurface(rcEnc, (uint32_t)config,
            getWidth(), getHeight());
    if (!rcSurface) {
        ALOGE("rcCreateWindowSurface returned 0");
        return EGL_FALSE;
    }
    rcEnc->rcSetWindowColorBuffer(rcEnc, rcSurface,
            ((cb_handle_t*)(buffer->handle))->hostHandle);

    return EGL_TRUE;
}
extern "C" void
Java_org_mozilla_testuniversalsurfacetexture_TestUniversalSurfaceTexture_attachTexture(JNIEnv*
    aJEnv, jclass klass, jobject aSurface, int aDestroyed)
{
    __android_log_print(ANDROID_LOG_ERROR, "TUST", "### point a");

    if (!sSurfaceClass) {
        sSurfaceClass = reinterpret_cast<jclass>
            (aJEnv->NewGlobalRef(aJEnv->FindClass("android/view/Surface")));
        sNativeSurfaceField = aJEnv->GetFieldID(sSurfaceClass, "mNativeSurface", "I");
        sSurfaceControlField = aJEnv->GetFieldID(sSurfaceClass, "mSurfaceControl", "I");

        void* lib = dlopen("libui.so", RTLD_LAZY);
        sw_gralloc_handle_t_lock = (typeof(sw_gralloc_handle_t_lock))
            dlsym(lib, "_ZN7android19sw_gralloc_handle_t4lockEPS0_iiiiiPPv");
        sw_gralloc_handle_t_unlock = (typeof(sw_gralloc_handle_t_unlock))
            dlsym(lib, "_ZN7android19sw_gralloc_handle_t6unlockEPS0_");
        __android_log_print(ANDROID_LOG_ERROR, "TUST", "### Lock=%p, unlock=%p",
                            sw_gralloc_handle_t_lock, sw_gralloc_handle_t_unlock);

        lib = dlopen("libhardware.so", RTLD_LAZY);
        hw_get_module = (typeof(hw_get_module))dlsym(lib, "hw_get_module");

        hw_module_t* pModule;
        hw_get_module("gralloc", &pModule);
        sModule = reinterpret_cast<gralloc_module_t*>(pModule);
        __android_log_print(ANDROID_LOG_ERROR, "TUST", "### Gralloc module=%p", pModule);
    }

    if (!sImage) {
        ANativeWindow* nativeWindow = reinterpret_cast<ANativeWindow*>
            (aJEnv->GetIntField(aSurface, sNativeSurfaceField) + 8);

        /*Rect rect;
        rect.left = rect.top = rect.right = rect.bottom = 0;
        nativeWindow->perform(nativeWindow, NATIVE_WINDOW_SET_CROP, &rect);*/

        // NB: nativeWindow->common.magic is '_wnd' as a FourCC.
        // My version is 104.

        __android_log_print(ANDROID_LOG_ERROR, "TUST",
                            "### Native window ptr %p, magic %08x, version %d, reserved %p, flags %d, dpi %g\n",
                            nativeWindow, (unsigned)nativeWindow->common.magic,
                            nativeWindow->common.version, nativeWindow->common.reserved[0],
                            (int)nativeWindow->flags, (double)nativeWindow->xdpi);

        nativeWindow->dequeueBuffer(nativeWindow, &sBuffer);
        nativeWindow->lockBuffer(nativeWindow, sBuffer);

        // Must increment the refcount on the native window to avoid crashes on Mali (Galaxy S2).
        nativeWindow->common.incRef(&nativeWindow->common);

        const EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };

        sBuffer->common.incRef(&sBuffer->common);

        sImage = eglCreateImageKHR(eglGetDisplay(EGL_DEFAULT_DISPLAY), EGL_NO_CONTEXT,
                                     EGL_NATIVE_BUFFER_ANDROID,
                                     reinterpret_cast<EGLClientBuffer>(sBuffer), eglImgAttrs);

        //nativeWindow->queueBuffer(nativeWindow, sBuffer);
    }

    uint8_t *bits = 0;
    int err = sModule->lock(sModule, sBuffer->handle, GRALLOC_USAGE_SW_READ_OFTEN |
                            GRALLOC_USAGE_SW_WRITE_OFTEN, 0, 0, 512, 512, (void**)&bits);
    __android_log_print(ANDROID_LOG_ERROR, "TUST",
                "### Buffer width=%d height=%d stride=%d format=%d usage=%d Bits are: %p, err=%d",
                sBuffer->width, sBuffer->height, sBuffer->stride, sBuffer->format, sBuffer->usage,
                bits, err);

    struct timeval tv;
    gettimeofday(&tv, NULL);

    static int x = 0;

    for (int i = 0; i < 512*512*2; i += 2) {
        bits[i] = bits[i+1] = (tv.tv_usec / 100000) % 256;
    }
    sModule->unlock(sModule, sBuffer->handle);

    glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, sImage);

    __android_log_print(ANDROID_LOG_ERROR, "TUST", "### Success! GL error is: %d",
                        (int)glGetError());
}