예제 #1
0
BOOL CglWnd::OnInitDialog()
{
	// First invoke initialization of parent class
	if (!CMzWndEx::OnInitDialog())
	{
		return FALSE;
	}

	// 注册所有硬按键消息 WM_MZSH_ALL_KEY_EVENT
	//RegisterShellMessage(m_hWnd, WM_MZSH_ALL_KEY_EVENT);
	// 获取所有硬按键消息值
	//m_allkeyEvent = GetShellNotifyMsg_AllKeyEvent();

	//SetScreenAlwaysOn(m_hWnd);
	
	//开启acc功能
	MzAccOpen(); 

	m_ff = DEFINE_FF;
	m_k = DEFINE_K;
	m_bEdit = false;
	initEGL();
	initGL();
	m_toolbar.init(GetParent());

#ifdef OUTPUTPTS
	SetTimer(m_hWnd, TIMER_PTS, 1000, NULL);
#endif // OUTPUTPTS

	SetTimer(m_hWnd, TIMER_ACC, 100, NULL);
	SetTimer(m_hWnd, TIMER_DRAW, 30, NULL);
	m_bActive = true;
	return TRUE;
}
status_t OverlayComposer::readyToRun()
{
    static bool initGFXFlag = false;

    if (initGFXFlag == false)
    {
        bool ret = initEGL();
        if (!ret)
        {
            ALOGE("Init EGL ENV failed");
            return -1;
        }

        initOpenGLES();

        initGFXFlag = true;
    }

    sem_init(&cmdSem, 0, 0);
    sem_init(&doneSem, 0, 0);
    sem_init(&displaySem, 0, 0);

    InitSem();

    return NO_ERROR;
}
예제 #3
0
    int OpenGLThread::initBPS() {
        //Initialize BPS library
        bps_initialize();
        m_api = GL_ES_1;
        //Create a screen context that will be used to create an EGL surface to to receive libscreen events
        if (EXIT_SUCCESS != screen_create_context(&m_screen_ctx, 0)) {
            fprintf(stderr, "screen_request_events failed\n");
            return EXIT_FAILURE;
        }

        // wait for rendering API to be set
        while (m_api == GL_UNKNOWN) {
            usleep(10);
        };

        // initialize EGL
        if (EXIT_SUCCESS != initEGL()) {
            fprintf(stderr, "initialize EGL failed\n");
            return EXIT_FAILURE;
        }

        //Signal BPS library that screen events will be requested
        if (BPS_SUCCESS != screen_request_events(m_screen_ctx)) {
            fprintf(stderr, "screen_request_events failed\n");
            return EXIT_FAILURE;
        }

        setInitialized(true);

        return EXIT_SUCCESS;
    }
/*!****************************************************************************
 @Function		main
 @Return		int			result code to OS
 @Description	Main function of the program
******************************************************************************/
int main()
{
    initEGL();
    Init();
    //create_texture();

	for(;;)
	{
		glClear(GL_COLOR_BUFFER_BIT);
		/*
			Clears the color buffer.
			glClear() can also be used to clear the depth or stencil buffer
			(GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT)
		*/
		glClearColor(0.0, 0.5, 0.5, 1.0);
		glClear(GL_DEPTH_BUFFER_BIT);
		if (!TestEGLError("glClear"))
		{
			goto cleanup;
		}


		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glColorMask(false, true, true, true);
		Light(0); 
		Render(0); 
		glClear( GL_DEPTH_BUFFER_BIT) ;
		glColorMask(true, false, false, true);
		Light(1); 
		Render(1); 
		glColorMask( true, true, true, true);

		XRotate+=0.5; 
		/*
			Swap Buffers.
			Brings to the native display the current render surface.
		*/
		eglSwapBuffers(eglDisplay, eglSurface);
		if (!TestEGLError("eglSwapBuffers"))
		{
			goto cleanup;
		}
	}

	/*
		Step 8 - Terminate OpenGL ES and destroy the window (if present).
		eglTerminate takes care of destroying any context or surface created
	*/
cleanup:
	// Delete the VBO as it is no longer needed
	glDeleteBuffers(1, &ui32Vbo);
	eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) ;
	eglTerminate(eglDisplay);

	return 0;
}
/*!****************************************************************************
 @Function		initApplication
 @Return		bool		1 if no error occured
 @Description		Code in initApplication() is used to initialize egl.
******************************************************************************/
int initApplication()
{
	#if defined XORG_BUILD
	initX();
	#endif
	if (initEGL(NULL, NULL, 0)) 
	{
        	printf("ERROR: init EGL failed\n");
	        return (0);
    	}
	return 1;
}
예제 #6
0
void AbstractEglBackend::initKWinGL()
{
    initEGL();
    GLPlatform *glPlatform = GLPlatform::instance();
    glPlatform->detect(EglPlatformInterface);
    if (GLPlatform::instance()->driver() == Driver_Intel)
        options->setUnredirectFullscreen(false); // bug #252817
    options->setGlPreferBufferSwap(options->glPreferBufferSwap()); // resolve autosetting
    if (options->glPreferBufferSwap() == Options::AutoSwapStrategy)
        options->setGlPreferBufferSwap('e'); // for unknown drivers - should not happen
    glPlatform->printResults();
    initGL(EglPlatformInterface);
}
예제 #7
0
WaylandCore::WaylandCore( int width, int height, const char* title )
: mDisplay(NULL),mRegistry(NULL),mCompositor(NULL),mShm(NULL),
  mSeat(NULL),mPointer(NULL),
  mEglDisplay(EGL_NO_DISPLAY), mEglContext(EGL_NO_CONTEXT),mEglWindow(0),mShellSurface(NULL),
  mShouldClose(false),mWidth(0),mHeight(0)
{
  mDisplay = wl_display_connect(NULL);
  setup_registry_handlers();
  
  if( mDisplay ) {
    mRegistry = wl_display_get_registry( mDisplay );
  }
  
  initEGL();
  
  createWindow( width, height, title );
}
예제 #8
0
void EglWaylandBackend::init()
{
    if (!initRenderingContext()) {
        setFailed("Could not initialize rendering context");
        return;
    }

    initEGL();
    GLPlatform *glPlatform = GLPlatform::instance();
    glPlatform->detect(EglPlatformInterface);
    glPlatform->printResults();
    initGL(EglPlatformInterface);

    setSupportsBufferAge(false);

    if (hasGLExtension("EGL_EXT_buffer_age")) {
        const QByteArray useBufferAge = qgetenv("KWIN_USE_BUFFER_AGE");

        if (useBufferAge != "0")
            setSupportsBufferAge(true);
    }
}
예제 #9
0
void EglOnXBackend::init()
{
    if (!initRenderingContext()) {
        setFailed(QStringLiteral("Could not initialize rendering context"));
        return;
    }

    initEGL();
    if (!hasGLExtension(QStringLiteral("EGL_KHR_image")) &&
        (!hasGLExtension(QStringLiteral("EGL_KHR_image_base")) ||
         !hasGLExtension(QStringLiteral("EGL_KHR_image_pixmap")))) {
        setFailed(QStringLiteral("Required support for binding pixmaps to EGLImages not found, disabling compositing"));
        return;
    }
    GLPlatform *glPlatform = GLPlatform::instance();
    glPlatform->detect(EglPlatformInterface);
    if (GLPlatform::instance()->driver() == Driver_Intel)
        options->setUnredirectFullscreen(false); // bug #252817
    options->setGlPreferBufferSwap(options->glPreferBufferSwap()); // resolve autosetting
    if (options->glPreferBufferSwap() == Options::AutoSwapStrategy)
        options->setGlPreferBufferSwap('e'); // for unknown drivers - should not happen
    glPlatform->printResults();
    initGL(EglPlatformInterface);
    if (!hasGLExtension(QStringLiteral("GL_OES_EGL_image"))) {
        setFailed(QStringLiteral("Required extension GL_OES_EGL_image not found, disabling compositing"));
        return;
    }

    // check for EGL_NV_post_sub_buffer and whether it can be used on the surface
    if (eglPostSubBufferNV) {
        if (eglQuerySurface(dpy, surface, EGL_POST_SUB_BUFFER_SUPPORTED_NV, &surfaceHasSubPost) == EGL_FALSE) {
            EGLint error = eglGetError();
            if (error != EGL_SUCCESS && error != EGL_BAD_ATTRIBUTE) {
                setFailed(QStringLiteral("query surface failed"));
                return;
            } else {
                surfaceHasSubPost = EGL_FALSE;
            }
        }
    }

    setSupportsBufferAge(false);

    if (hasGLExtension("EGL_EXT_buffer_age")) {
        const QByteArray useBufferAge = qgetenv("KWIN_USE_BUFFER_AGE");

        if (useBufferAge != "0")
            setSupportsBufferAge(true);
    }

    setSyncsToVBlank(false);
    setBlocksForRetrace(false);
    gs_tripleBufferNeedsDetection = false;
    m_swapProfiler.init();
    if (surfaceHasSubPost) {
        qDebug() << "EGL implementation and surface support eglPostSubBufferNV, let's use it";

        if (options->glPreferBufferSwap() != Options::NoSwapEncourage) {
            // check if swap interval 1 is supported
            EGLint val;
            eglGetConfigAttrib(dpy, config, EGL_MAX_SWAP_INTERVAL, &val);
            if (val >= 1) {
                if (eglSwapInterval(dpy, 1)) {
                    qDebug() << "Enabled v-sync";
                    setSyncsToVBlank(true);
                    const QByteArray tripleBuffer = qgetenv("KWIN_TRIPLE_BUFFER");
                    if (!tripleBuffer.isEmpty()) {
                        setBlocksForRetrace(qstrcmp(tripleBuffer, "0") == 0);
                        gs_tripleBufferUndetected = false;
                    }
                    gs_tripleBufferNeedsDetection = gs_tripleBufferUndetected;
                }
            } else {
                qWarning() << "Cannot enable v-sync as max. swap interval is" << val;
            }
        } else {
            // disable v-sync
            eglSwapInterval(dpy, 0);
        }
    } else {
        /* In the GLX backend, we fall back to using glCopyPixels if we have no extension providing support for partial screen updates.
         * However, that does not work in EGL - glCopyPixels with glDrawBuffer(GL_FRONT); does nothing.
         * Hence we need EGL to preserve the backbuffer for us, so that we can draw the partial updates on it and call
         * eglSwapBuffers() for each frame. eglSwapBuffers() then does the copy (no page flip possible in this mode),
         * which means it is slow and not synced to the v-blank. */
        qWarning() << "eglPostSubBufferNV not supported, have to enable buffer preservation - which breaks v-sync and performance";
        eglSurfaceAttrib(dpy, surface, EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
    }
}
예제 #10
0
bool Renderer::initialize()
{
    LOGI("Initializing context");

    const EGLint attribs[] = {
        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
        EGL_BLUE_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_RED_SIZE, 8,
        EGL_NONE
    };

	if (myGame == NULL)
	{
		rendererInitializePlatform(mAssetManager, mActivityExternalFilesDir);
	}

	if (samplesGame == NULL)
	{
		rendererInitializeSamplesGame();
	}

	if (attribs != NULL)
	{
		initEGL(_window);
		//return true;
	}

    /*
    EGLDisplay display;
    EGLConfig config;
    EGLint numConfigs;
    EGLint format;
    EGLSurface surface;
    EGLContext context;
    EGLint width;
    EGLint height;
    GLfloat ratio;

    LOGI("Initializing context");

    if ((display = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) {
        LOGE("eglGetDisplay() returned error %d", eglGetError());
        return false;
    }
    if (!eglInitialize(display, 0, 0)) {
        LOGE("eglInitialize() returned error %d", eglGetError());
        return false;
    }

    if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs)) {
        LOGE("eglChooseConfig() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) {
        LOGE("eglGetConfigAttrib() returned error %d", eglGetError());
        destroy();
        return false;
    }

    ANativeWindow_setBuffersGeometry(_window, 0, 0, format);

    if (!(surface = eglCreateWindowSurface(display, config, _window, 0))) {
        LOGE("eglCreateWindowSurface() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!(context = eglCreateContext(display, config, 0, 0))) {
        LOGE("eglCreateContext() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglMakeCurrent(display, surface, surface, context)) {
        LOGE("eglMakeCurrent() returned error %d", eglGetError());
        destroy();
        return false;
    }

    if (!eglQuerySurface(display, surface, EGL_WIDTH, &width) ||
        !eglQuerySurface(display, surface, EGL_HEIGHT, &height)) {
        LOGE("eglQuerySurface() returned error %d", eglGetError());
        destroy();
        return false;
    }

    _display = display;
    _surface = surface;
    _context = context;

    glDisable(GL_DITHER);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
    glClearColor(0, 0, 0, 0);
    glEnable(GL_CULL_FACE);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);

    glViewport(0, 0, width, height);

    ratio = (GLfloat) width / height;
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustumf(-ratio, ratio, -1, 1, 1, 10);

*/
    return true;
}
// Main function with event loop
int main(void)
{
	int n = -1;
	int count = 0;
	static bc_buf_ptr_t buf_pa;
	int dev_fd;
	unsigned long chunkSize;

	printf("Initializing egl..\n\n");
	if( 0 == initEGL(0)) //No profiling
	{	
		printf("EGL init failed");
		goto exitNone;
	}
	
	//Also initialise the pipes
	n = initPipes(&initAttrib);
	if(n) 	{ 		goto exitPipes; 	}

	//Initialise CMEM allocator - TODO check err status
	mem_cmem_init();
	//Allocate mem
	chunkSize = initAttrib.widthPixels* 
							initAttrib.heightPixels* 
							initAttrib.bytesPerPixel*  
							initAttrib.numBuffers;
	if(mem_cmem_alloc( chunkSize, &virtualAddress, &physicalAddress )) {goto exitCMEMInit;}

	paArray = (unsigned long*)malloc(initAttrib.numBuffers * sizeof(unsigned long));
	freeArray = (unsigned long*)malloc(initAttrib.numBuffers * sizeof(unsigned long));	
	if(!paArray || !freeArray) {goto exitCMEMAlloc;}

	for(count = 0; count < initAttrib.numBuffers; count++)
	{
		paArray[count]  = physicalAddress + count*(chunkSize/initAttrib.numBuffers);
		freeArray[count] = 0;
	}
	//TODO - give the allocated buffers back to requestor via answer
	//write_init_buffer_pipe();
	
	init_view();

	//Loop reading new data and rendering, till something happens
	//TODO - exit cleanly using last msg
	while(read_pipe() != -1)
	{
		render(bcbuf.index);
		
		//TODO - clean up message passing
		//if( write_pipe() != sizeof(GstBufferClassBuffer *))
		{	
			printf("Error Writing into Init Queue\n");
			//TODO - try again n times ?
			break;
		}
	}
exit:
	release_view();
	deInitEGL();
exitCMEMAlloc:
	mem_cmem_free( virtualAddress);
exitPipes:	
	if(paArray) free(paArray);
	if(freeArray) free(freeArray);
	deinit_pipes();
exitCMEMInit:
	mem_cmem_deinit();
exitNone:
	return 0;
}
예제 #12
0
파일: imgsdk.c 프로젝트: zhangkari/imagesdk
/**
 * Initialize the specified SdkEnv instance
 */
int initSdkEnv(SdkEnv *env) 
{
    VALIDATE_NOT_NULL(env);

	Log("initSdkEnv pthead self = %lx\n", pthread_self());
	Log("initSdkEnv gettid = %x\n", gettid());

    uint32_t t_begin, t_finish;

    if (env->type == SDK_STATUS_OK) {
        LogE("SDK is already initialized\n");
        return -1;
    }

    if (NULL == env->userData.platformData) {
        LogE("Please call setPlatformData first!\n");
        return -1;
    }

	chrbuf_t *userCmd = newChrbuf (USER_CMD_CAPABILITY);
    if (NULL == userCmd) {
        LogE ("Failed newChrbuf for userCmd\n");
        freeSdkEnv (env);
        return -1;
    }
    env->userCmd = userCmd;

    bool result = initEffectCmd(&env->effectCmd);
    assert(result);

    if (NULL != env->egl.window) {	// On-screen render
        t_begin = getCurrentTime();
        if (initEGL(env) < 0) {
            LogE("Failed initEGL\n");
            return -1;
        }
        t_finish = getCurrentTime();
        Log("Initialize EGL OK cost %d ms.\n", t_finish - t_begin);

        ANativeWindow *window = env->egl.window;
        env->userData.width = ANativeWindow_getWidth(window);
        env->userData.height = ANativeWindow_getHeight(window);
        Log ("Native window %d x %d\n", 
                env->userData.width, env->userData.height);

        if (env->egl.width != env->userData.width ||
                env->egl.height != env->userData.height) {
            LogE("EGL and Native window size are not equal\n");
            return -1;
        }
    } else {	// Off-screen render
        t_begin = getCurrentTime();
        if (initDefaultEGL(env) < 0) {
            LogE("Failed initDefaultEGL\n");
            return -1;
        }
        t_finish = getCurrentTime();
        Log("Initialize Default EGL OK cost %d ms.\n", t_finish - t_begin);
    }

#define VERT_SHDR_NAME "vert.shdr"
    t_begin = getCurrentTime();
    char *vertSource = NULL;
    int nVertSource = readFileFromAssets (env, VERT_SHDR_NAME, &vertSource);
    if (nVertSource < 0) {
        LogE ("Failed read assets file:%s\n", VERT_SHDR_NAME);
    }
    env->userData.nVertSource = nVertSource;
    env->userData.vertSource = vertSource; 
    t_finish = getCurrentTime();
    Log("Load %s OK cost %d ms.\n", VERT_SHDR_NAME, t_finish - t_begin);

#define FRAG_SHDR_NAME "frag.shdr"
    char *fragSource = NULL;
    int nFragSource = readFileFromAssets (env, FRAG_SHDR_NAME, &fragSource);
    if (nFragSource < 0) {
        LogE("Failed read assets file:%s\n", FRAG_SHDR_NAME);
    }
    env->userData.nFragSource = nFragSource;
    env->userData.fragSource = fragSource;
    t_finish = getCurrentTime();
    Log("Load %s OK cost %d ms.\n", FRAG_SHDR_NAME, t_finish - t_begin);

    if (attachShader(env, vertSource, fragSource) < 0) {
        LogE("Failed attachShader\n");
        return -1;
    }

    if (initGlBuffers (env) < 0) {
        LogE ("Failed init OpenGL buffers\n");
    }

    env->status = SDK_STATUS_OK;

    return 0;
}
예제 #13
0
파일: webcam.c 프로젝트: yesj/J5_A8
int main(int argc, char *argv[])
{
    int bcfd = -1; 
    char bcdev_name[] = "/dev/bccatX";
    BCIO_package ioctl_var;
    bc_buf_params_t buf_param;
    bc_buf_ptr_t buf_pa;

    unsigned long buf_paddr[MAX_BUFFERS];
    char *buf_vaddr[MAX_BUFFERS] = { MAP_FAILED };
    char *frame = NULL;
    int buf_size = 0;
    int c, idx, ret = -1;
    char opts[] = "c:pw:t:b:h";

    int   ii;
    int   frame_w, frame_h;
    int   min_w = 0, min_h = 0;;
    int   cp_offset = 0;

    struct timeval tvp, tv, tv0 = {0,0};
    unsigned long tdiff = 0;
    unsigned long fcount = 0;

    for (;;) {
        c = getopt_long(argc, argv, opts, (void *)NULL, &idx);

        if (-1 == c)
            break;

        switch (c) {
            case 0:
                break;
            case 'b':
                bcdev_id = atoi(optarg) % 10;
                break;
            case 'c':
                cap_dev = optarg;
                printf("INFO: capture device is %s\n", cap_dev);
                break;
            case 'p':
                profiling = TRUE;
                printf("INFO: profiling enabled\n");
                break;
            case 'w':
                min_w = atoi(optarg);
                break;
            case 't':
                min_h = atoi(optarg);
                break;
            default:
                usage(argv[0]);
                return 0;
        }
    }

    signal(SIGINT, signalHandler);

    if (frame_init(&buf_param))
        return -1;

    bcdev_name[strlen(bcdev_name)-1] = '0' + bcdev_id;

    if ((bcfd = open(bcdev_name, O_RDWR|O_NDELAY)) == -1) {
        printf("ERROR: open %s failed\n", bcdev_name);
        goto err_ret;
    }

    frame_w = buf_param.width;
    frame_h = buf_param.height;

    if (min_w > 0 && !(min_w % 8))
        buf_param.width = min_w;

    if (min_h > 0)
        buf_param.height = min_h;
 
    if (ioctl(bcfd, BCIOREQ_BUFFERS, &buf_param) != 0) {
        printf("ERROR: BCIOREQ_BUFFERS failed\n");
        goto err_ret;
    }

    if (ioctl(bcfd, BCIOGET_BUFFERCOUNT, &ioctl_var) != 0) {
        goto err_ret;
    }

    if (ioctl_var.output == 0) {
        printf("ERROR: no texture buffer available\n");
        goto err_ret;
    }

    /* for BC_MEMORY_USERPTR, BCIOSET_BUFFERPHYADDR must be called
     * before init IMG_extensions in initTexExt()*/
    if (buf_param.type == BC_MEMORY_USERPTR) {
        for (idx = 0; idx < buf_param.count; idx++) {
            while ((frame = frame_get(&buf_pa)) == NULL) { }

            if (frame == (char *)-1)
                goto err_ret;

            if (ioctl(bcfd, BCIOSET_BUFFERPHYADDR, &buf_pa) != 0) {
                frame_restore(frame);
                printf("ERROR: BCIOSET_BUFFERADDR[%d]: failed (0x%lx)\n",
                       buf_pa.index, buf_pa.pa);
                goto err_ret;
            }

            if (frame_restore(frame))
                goto err_ret;
        }
    }

    if (initEGL(buf_param.count)) {
        printf("ERROR: init EGL failed\n");
        goto err_ret;
    }
 
    if ((ret = initTexExt(bcdev_id, &buf_info)) < 0) {
        printf("ERROR: initTexExt() failed [%d]\n", ret);
        goto err_ret;
    }

    if (buf_info.n > MAX_BUFFERS) {
        printf("ERROR: number of texture buffer exceeds the limit\n");
        goto err_ret;
    }

    /*FIXME calc stride instead of 2*/
    buf_size = buf_info.w * buf_info.h * 2;
    min_w    = buf_info.w < frame_w ? buf_info.w : frame_w;
    min_h    = buf_info.h < frame_h ? buf_info.h : frame_h;

    if (buf_info.h > frame_h)
        cp_offset = (buf_info.h - frame_h) * buf_info.w;

    if (buf_info.w > frame_w)
        cp_offset += buf_info.w - frame_w;

    if (buf_param.type == BC_MEMORY_MMAP) {
        for (idx = 0; idx < buf_info.n; idx++) {
            ioctl_var.input = idx;

            if (ioctl(bcfd, BCIOGET_BUFFERPHYADDR, &ioctl_var) != 0) {
                printf("ERROR: BCIOGET_BUFFERADDR failed\n");
                goto err_ret;
            }

            buf_paddr[idx] = ioctl_var.output;
            buf_vaddr[idx] = (char *)mmap(NULL, buf_size,
                              PROT_READ | PROT_WRITE, MAP_SHARED,
                              bcfd, buf_paddr[idx]);

            if (buf_vaddr[idx] == MAP_FAILED) {
                printf("ERROR: mmap failed\n");
                goto err_ret;
            }
        }
    }

    ret = 0;
    idx = 0;

    if (profiling == TRUE) {
        gettimeofday(&tvp, NULL);
        tv0 = tvp;
    }

    while (!gQuit) {
#ifdef USE_SOLID_PATTERN
        usleep(1000 * 1000);
#endif
        frame = frame_get(&buf_pa);

        if (frame == (char *) -1)
            break;

        if (frame) {
            if (buf_param.type == BC_MEMORY_MMAP) {
                for (ii = 0; ii < min_h; ii++)
                      /*FIXME calc stride instead of 2*/
                    memcpy(buf_vaddr[idx] + buf_info.w * 2 * ii + cp_offset,
                           frame + frame_w * 2 * ii, min_w * 2);
            }
            else    /*buf_param.type == BC_MEMORY_USERPTR*/
                idx = buf_pa.index;
        }

        drawCube(idx);

        if (frame_restore(frame))
            break;

#ifdef X11
        if (doX11Events())
            gQuit = TRUE;
#endif

        idx = (idx + 1) % buf_info.n;

        if (profiling == FALSE)
            continue;

        gettimeofday(&tv, NULL);

        fcount++;

        if (!(fcount % 60)) {
            tdiff = (unsigned long)(tv.tv_sec*1000 + tv.tv_usec/1000 -
                                tvp.tv_sec*1000 - tvp.tv_usec/1000);
            if (tdiff < 1800)   /*print fps every 2 sec*/
                continue;

            fprintf(stderr, "\rAvg FPS: %ld",
                    fcount / (tv.tv_sec - tv0.tv_sec));
            tvp = tv;
        }
    }
    printf("\n");

err_ret:
    if (buf_param.type == BC_MEMORY_MMAP) {
        for (idx = 0; idx < buf_info.n; idx++) {
            if (buf_vaddr[idx] != MAP_FAILED)
                munmap(buf_vaddr[idx], buf_size);
        }
    }
    if (bcfd > -1)
        close(bcfd);

    deInitEGL(buf_info.n);
#ifdef X11
    deInitX11();
#endif
    frame_cleanup();

    printf("done\n");
    return ret;
}
예제 #14
0
int GLinitialize(void *ext_gles_display, void *ext_gles_surface)
{
 if(ext_gles_display != NULL && ext_gles_surface != NULL) { 
  display = (EGLDisplay)ext_gles_display;
  surface = (EGLSurface)ext_gles_surface;
 }
 else {
  if(initEGL()!=0)
   return -1;
  created_gles_context=1;
 }

 //----------------------------------------------------// 

 glDepthRangef(0.0f, 1.0f);glError();

 glViewport(rRatioRect.left,                           // init viewport by ratio rect
            iResY-(rRatioRect.top+rRatioRect.bottom),
            rRatioRect.right, 
            rRatioRect.bottom); glError();

 glScissor(0, 0, iResX, iResY); glError();             // init clipping (fullscreen)
 glEnable(GL_SCISSOR_TEST); glError();

#ifndef OWNSCALE
 glMatrixMode(GL_TEXTURE);                             // init psx tex sow and tow if not "ownscale"
 glLoadIdentity();
 glScalef(1.0f/255.99f,1.0f/255.99f,1.0f);             // geforce precision hack
#endif 
 
 //glPolygonOffset( -0.2f, -0.2f );glError();

 glMatrixMode(GL_PROJECTION); glError();               // init projection with psx resolution
 glLoadIdentity(); glError();

 glOrtho(0,PSXDisplay.DisplayMode.x,
         PSXDisplay.DisplayMode.y, 0, -1, 1); glError();

 if(iZBufferDepth)                                     // zbuffer?
  {
   uiBufferBits=GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT;
   glEnable(GL_DEPTH_TEST); glError();
   glDepthFunc(GL_ALWAYS); glError();
   iDepthFunc=1;
  }
 else                                                  // no zbuffer?
  {
   uiBufferBits=GL_COLOR_BUFFER_BIT;
   glDisable(GL_DEPTH_TEST); glError();
  }

 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glError();      // first buffer clear
 glClear(uiBufferBits); glError();

 GetExtInfos();                                        // get ext infos
 SetExtGLFuncs();                                      // init all kind of stuff (tex function pointers)
 
 glEnable(GL_ALPHA_TEST); glError();                   // wanna alpha test

  {
   glDisable(GL_LINE_SMOOTH); glError();
   glDisable(GL_POINT_SMOOTH); glError();
  }

 ubGloAlpha=127;                                       // init some drawing vars
 ubGloColAlpha=127;
 TWin.UScaleFactor = 1;
 TWin.VScaleFactor = 1;
 bDrawMultiPass=FALSE;
 bTexEnabled=FALSE;
 bUsingTWin=FALSE;
      
 if(bDrawDither)  glEnable(GL_DITHER);                 // dither mode
 else             glDisable(GL_DITHER); 
 glError(); 
 glDisable(GL_FOG); glError();                          // turn all (currently) unused modes off
 glDisable(GL_LIGHTING); glError();  
 glDisable(GL_STENCIL_TEST); glError();  
 glDisable(GL_TEXTURE_2D); glError();
 glDisable(GL_CULL_FACE);

 glFlush(); glError();                                 // we are done...
 glFinish(); glError();                           

 CreateScanLines();                                    // setup scanline stuff (if wanted)

 CheckTextureMemory();                                 // check available tex memory

 if(bKeepRatio) SetAspectRatio();                      // set ratio

 
 bIsFirstFrame = FALSE;                                // we have survived the first frame :)

 return 0;
}
예제 #15
0
GraphicsContext3DInternal::GraphicsContext3DInternal(HTMLCanvasElement* canvas,
                                                     GraphicsContext3D::Attributes attrs,
                                                     HostWindow* hostWindow)
    : m_proxy(adoptRef(new GraphicsContext3DProxy()))
    , m_compositingLayer(new WebGLLayer(m_proxy))
    , m_canvas(canvas)
    , m_attrs(attrs)
    , m_layerComposited(false)
    , m_canvasDirty(false)
    , m_width(1)
    , m_height(1)
    , m_maxwidth(CANVAS_MAX_WIDTH)
    , m_maxheight(CANVAS_MAX_HEIGHT)
    , m_dpy(EGL_NO_DISPLAY)
    , m_config(0)
    , m_surface(EGL_NO_SURFACE)
    , m_context(EGL_NO_CONTEXT)
    , m_syncThread(0)
    , m_threadState(THREAD_STATE_STOPPED)
    , m_syncTimer(this, &GraphicsContext3DInternal::syncTimerFired)
    , m_syncRequested(false)
    , m_webGLFPSTimer(0)
    , m_extensions(0)
    , m_contextId(0)
    //[CAPPFIX_WEB_WEBGL] - Handle FBO creation failure
    , m_nfbo(0)
    //[CAPPFIX_WEB_WEBGL_END]
    //[CAPPFIX_WEB_WEBGL] - Improve UI Response Begin
    , m_needImproveUIResponseMode(false)
    //[CAPPFIX_WEB_WEBGL_END]
{
    enableLogging();

    LOGWEBGL("GraphicsContext3DInternal() = %p, m_compositingLayer = %p", this, m_compositingLayer);
    m_proxy->setGraphicsContext(this);

    if (!m_canvas || !m_canvas->document() || !m_canvas->document()->view())
        return;
    JNIEnv* env = JSC::Bindings::getJNIEnv();
    WebViewCore* core = WebViewCore::getWebViewCore(m_canvas->document()->view());
    if (!core)
        return;
    jobject tmp = core->getWebViewJavaObject();
    m_webView = env->NewGlobalRef(tmp);
    if (!m_webView)
        return;
    jclass webViewClass = env->GetObjectClass(m_webView);
    m_postInvalidate = env->GetMethodID(webViewClass, "postInvalidate", "()V");
    env->DeleteLocalRef(webViewClass);
    if (!m_postInvalidate)
        return;

    if (!initEGL())
        return;
    //[CAPPFIX_WEB_WEBGL] - for WebGL Conformance Test
    if (contextCounter > 10)
    {
        LOGWEBGL("call m_canvas->document()->frame()->script()->lowMemoryNotification()");
        m_canvas->document()->frame()->script()->lowMemoryNotification();
    }
    // [CAPPFIX_WEB_WEBGL_END] - end
    if (!createContext(true)) {
        LOGWEBGL("Create context failed. Perform JS garbage collection and try again.");
        // Probably too many contexts. Force a JS garbage collection, and then try again.
        // This typically only happens in Khronos Conformance tests.
        m_canvas->document()->frame()->script()->lowMemoryNotification();
        if (!createContext(true)) {
            LOGWEBGL("Create context still failed: aborting.");
            return;
        }
    }

    m_webGLFPSTimer.set(new WebGLFPSTimer());

    const char *ext = (const char *)glGetString(GL_EXTENSIONS);
    LOGWEBGL("GL_EXTENSIONS = %s", ext);
    // Want to keep control of which extensions are used
    String extensions = "";
    if (strstr(ext, "GL_OES_texture_npot"))
        extensions.append("GL_OES_texture_npot");
    //[CAPPFIX_WEB_WEBGL] - Do not support extension at this time.
#if 0
    if (strstr(ext, "GL_OES_packed_depth_stencil"))
        extensions.append(" GL_OES_packed_depth_stencil");
    if (strstr(ext, "GL_OES_texture_float"))
        extensions.append(" GL_OES_texture_float");
#endif
    m_extensions.set(new Extensions3DAndroid(extensions));
    //[CAPPFIX_WEB_WEBGL_END]
    // ANGLE initialization.
    ShBuiltInResources resources;
    ShInitBuiltInResources(&resources);

    glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &resources.MaxVertexAttribs);
    glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &resources.MaxVertexUniformVectors);
    glGetIntegerv(GL_MAX_VARYING_VECTORS, &resources.MaxVaryingVectors);
    glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &resources.MaxVertexTextureImageUnits);
    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &resources.MaxCombinedTextureImageUnits);
    glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &resources.MaxTextureImageUnits);
    glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &resources.MaxFragmentUniformVectors);

    resources.MaxDrawBuffers = 1;
    m_compiler.setResources(resources);

    m_savedViewport.x = 0;
    m_savedViewport.y = 0;
    m_savedViewport.width = m_width;
    m_savedViewport.height = m_height;

    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    startSyncThread();
    //[CAPPFIX_WEB_WEBGL] - for WebGL Conformance Test
    //static int contextCounter = 1;
    m_contextId = contextCounter++;
}