EGLDisplaySurface::EGLDisplaySurface() : EGLNativeSurface<EGLDisplaySurface>() { egl_native_window_t::version = sizeof(egl_native_window_t); egl_native_window_t::ident = 0; egl_native_window_t::incRef = &EGLDisplaySurface::hook_incRef; egl_native_window_t::decRef = &EGLDisplaySurface::hook_decRef; egl_native_window_t::swapBuffers = &EGLDisplaySurface::hook_swapBuffers; egl_native_window_t::setSwapRectangle = &EGLDisplaySurface::hook_setSwapRectangle; egl_native_window_t::nextBuffer = &EGLDisplaySurface::hook_nextBuffer; egl_native_window_t::connect = 0; egl_native_window_t::disconnect = 0; mFb[0].data = 0; mFb[1].data = 0; mBlitEngine = 0; egl_native_window_t::fd = mapFrameBuffer(); if (egl_native_window_t::fd >= 0) { hw_module_t const* module; if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) { copybit_open(module, &mBlitEngine); } const float in2mm = 25.4f; float refreshRate = 1000000000000000LLU / ( float( mInfo.upper_margin + mInfo.lower_margin + mInfo.yres ) * ( mInfo.left_margin + mInfo.right_margin + mInfo.xres ) * mInfo.pixclock); const GGLSurface& buffer = mFb[1 - mIndex]; egl_native_window_t::width = buffer.width; egl_native_window_t::height = buffer.height; egl_native_window_t::stride = buffer.stride; egl_native_window_t::format = buffer.format; egl_native_window_t::base = intptr_t(mFb[0].data); egl_native_window_t::offset = intptr_t(buffer.data) - egl_native_window_t::base; egl_native_window_t::flags = 0; egl_native_window_t::xdpi = (mInfo.xres * in2mm) / mInfo.width; egl_native_window_t::ydpi = (mInfo.yres * in2mm) / mInfo.height; egl_native_window_t::fps = refreshRate; egl_native_window_t::memory_type = NATIVE_MEMORY_TYPE_FB; // no error, set the magic word egl_native_window_t::magic = 0x600913; } mSwapCount = -1; mPageFlipCount = 0; }
ogles_context_t *ogles_init(size_t extra) { void* const base = malloc(extra + sizeof(ogles_context_t) + 32); if (!base) return 0; ogles_context_t *c = (ogles_context_t *)((ptrdiff_t(base) + extra + 31) & ~0x1FL); memset(c, 0, sizeof(ogles_context_t)); ggl_init_context(&(c->rasterizer)); // XXX: this should be passed as an argument sp<EGLSurfaceManager> smgr(new EGLSurfaceManager()); c->surfaceManager = smgr.get(); c->surfaceManager->incStrong(c); sp<EGLBufferObjectManager> bomgr(new EGLBufferObjectManager()); c->bufferObjectManager = bomgr.get(); c->bufferObjectManager->incStrong(c); ogles_init_array(c); ogles_init_matrix(c); ogles_init_vertex(c); ogles_init_light(c); ogles_init_texture(c); c->rasterizer.base = base; c->point.size = TRI_ONE; c->line.width = TRI_ONE; // in OpenGL, writing to the depth buffer is enabled by default. c->rasterizer.procs.depthMask(c, 1); // OpenGL enables dithering by default c->rasterizer.procs.enable(c, GL_DITHER); c->copybits.blitEngine = NULL; c->copybits.minScale = 0; c->copybits.maxScale = 0; c->copybits.drawSurfaceBuffer = 0; #ifdef LIBAGL_USE_GRALLOC_COPYBITS hw_module_t const* module; if (hw_get_module(COPYBIT_HARDWARE_MODULE_ID, &module) == 0) { struct copybit_device_t* copyBits; if (copybit_open(module, ©Bits) == 0) { c->copybits.blitEngine = copyBits; { int minLim = copyBits->get(copyBits, COPYBIT_MINIFICATION_LIMIT); if (minLim != -EINVAL && minLim > 0) { c->copybits.minScale = (1 << 16) / minLim; } } { int magLim = copyBits->get(copyBits, COPYBIT_MAGNIFICATION_LIMIT); if (magLim != -EINVAL && magLim > 0) { c->copybits.maxScale = min(32*1024-1, magLim) << 16; } } } } #endif // LIBAGL_USE_GRALLOC_COPYBITS return c; }