std::string RenderingDevices::xml() { // We cache the results if(m_hasRenderingInformation) { std::cout << m_xml<<std::endl; return m_xml; } std::stringstream xml; xml << " <renderingDevices>\n"; DIR* dir = opendir( "/tmp/.X11-unix" ); if( dir == NULL ) { if( m_logger != NULL ) { m_logger( m_logger_data, 0, package.c_str(), "opendir failed: %s.", strerror( errno ) ); } xml << " <error>INTERNAL_ERROR</error>\n"; } else { struct dirent* entry = NULL; while( (entry = readdir( dir )) != NULL ) { if( entry->d_name[0] != 'X' ) { continue; } std::string display_id = ":" + std::string( entry->d_name ).substr(1); Display* display = XOpenDisplay( display_id.c_str() ); if( display == NULL ) { xml << " <renderingDevice id=\"" << display_id << "\">\n"; xml << " <error>FAILED_TO_OPEN_DISPLAY</error>\n"; xml << " </renderingDevice>\n"; continue; } #ifdef TINIA_AMAZON int screen_count = 1; #else int screen_count = ScreenCount ( display ); #endif XCloseDisplay( display ); if( screen_count < 1 ) { xml << " <renderingDevice id=\"" << display_id << "\">\n"; xml << " <error>NO_SCREENS</error>\n"; xml << " </renderingDevice>\n"; continue; } for(int screen=0; screen<screen_count; screen++) { std::stringstream screen_id_ss; screen_id_ss << display_id << '.' << screen; std::string screen_id = screen_id_ss.str(); xml << " <renderingDevice id=\"" << screen_id << "\">\n"; OffscreenGL gl( m_logger, m_logger_data ); if( !gl.setupContext( screen_id ) || !gl.bindContext() ) { switch ( gl.state() ) { case OffscreenGL::STATE_INSUFFICIENT_GLX: xml << " <error>INSUFFICIENT_GLX</error>\n"; break; case OffscreenGL::STATE_X_ERROR: xml << " <error>X_ERROR</error>\n"; break; default: xml << " <error>INTERNAL_ERROR</error>\n"; break; } } else { int glx_major = 0; int glx_minor = 0; glXQueryVersion( gl.display(), &glx_major, &glx_minor ); xml << " <glx major=\"" << glx_major << "\" minor=\"" << glx_minor << "\" direct=\"" << (glXIsDirect(gl.display(), gl.context())==True?'1':'0') << "\">\n"; xml << " <client>\n"; xml << " <vendor>" << glXGetClientString( gl.display(), GLX_VENDOR ) << "</vendor>\n"; xml << " <version>" << glXGetClientString( gl.display(), GLX_VERSION ) << "</version>\n"; xml << " </client>\n"; xml << " <server>\n"; xml << " <vendor>" << glXQueryServerString( gl.display(), screen, GLX_VENDOR ) << "</vendor>\n"; xml << " <version>" << glXQueryServerString( gl.display(), screen, GLX_VERSION ) << "</version>\n"; xml << " </server>\n"; std::list<std::string> glx_extensions = parseExtensions( glXQueryExtensionsString( gl.display(), screen ) ); for( std::list<std::string>::iterator it=glx_extensions.begin(); it!=glx_extensions.end(); ++it ) { //xml << " <extension>" << *it << "</extension>\n"; } xml << " </glx>\n"; GLint gl_major = 0; glGetIntegerv( GL_MAJOR_VERSION, &gl_major ); GLint gl_minor = 0; glGetIntegerv( GL_MINOR_VERSION, &gl_minor ); xml << " <opengl major=\"" << gl_major << "\" minor=\"" << gl_minor << "\">\n"; xml << " <vendor>" << (const char*)glGetString( GL_VENDOR ) << "</vendor>\n"; xml << " <version>" << (const char*)glGetString( GL_VERSION ) << "</version>\n"; xml << " <renderer>" << (const char*)glGetString( GL_RENDERER) << "</renderer>\n"; if( gl_major >= 2 ) { xml << " <glsl><version>" << (const char*)glGetString( GL_SHADING_LANGUAGE_VERSION ) << "</version></glsl>\n"; } std::list<std::string> gl_extensions = parseExtensions( (const char*)glGetString( GL_EXTENSIONS ) ); for( std::list<std::string>::iterator it=gl_extensions.begin(); it!=gl_extensions.end(); ++it ) { //xml << " <extension>" << *it << "</extension>\n"; } xml << " </opengl>\n"; } xml << " </renderingDevice>\n"; } } closedir( dir ); } xml << " </renderingDevices>\n"; m_hasRenderingInformation = true; m_xml = xml.str(); return xml.str(); }
bool GLTextureSource::IsValid() const { return !!gl() && mTextureHandle != 0; }
SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend) : fContext(EGL_NO_CONTEXT) , fDisplay(EGL_NO_DISPLAY) , fSurface(EGL_NO_SURFACE) { EGLint numConfigs; static const EGLint configAttribs[] = { EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_NONE }; fIsGLBackend = useGLBackend; fDisplay = GetD3DEGLDisplay(EGL_DEFAULT_DISPLAY, useGLBackend); if (EGL_NO_DISPLAY == fDisplay) { SkDebugf("Could not create EGL display!"); return; } EGLint majorVersion; EGLint minorVersion; eglInitialize(fDisplay, &majorVersion, &minorVersion); EGLConfig surfaceConfig; eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs); static const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; fContext = eglCreateContext(fDisplay, surfaceConfig, nullptr, contextAttribs); static const EGLint surfaceAttribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs); eglMakeCurrent(fDisplay, fSurface, fSurface, fContext); SkAutoTUnref<const GrGLInterface> gl(GrGLCreateANGLEInterface()); if (nullptr == gl.get()) { SkDebugf("Could not create ANGLE GL interface!\n"); this->destroyGLContext(); return; } if (!gl->validate()) { SkDebugf("Could not validate ANGLE GL interface!\n"); this->destroyGLContext(); return; } this->init(gl.detach()); }
void CompositorOGL::CreateFBOWithTexture(const IntRect& aRect, SurfaceInitMode aInit, GLuint aSourceFrameBuffer, GLuint *aFBO, GLuint *aTexture) { GLuint tex, fbo; mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0); mGLContext->fGenTextures(1, &tex); mGLContext->fBindTexture(mFBOTextureTarget, tex); if (aInit == INIT_MODE_COPY) { GLuint curFBO = mCurrentRenderTarget->GetFBO(); if (curFBO != aSourceFrameBuffer) { mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, aSourceFrameBuffer); } // We're going to create an RGBA temporary fbo. But to // CopyTexImage() from the current framebuffer, the framebuffer's // format has to be compatible with the new texture's. So we // check the format of the framebuffer here and take a slow path // if it's incompatible. GLenum format = GetFrameBufferInternalFormat(gl(), aSourceFrameBuffer, mWidget); bool isFormatCompatibleWithRGBA = gl()->IsGLES2() ? (format == LOCAL_GL_RGBA) : true; if (isFormatCompatibleWithRGBA) { mGLContext->fCopyTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.x, aRect.y, aRect.width, aRect.height, 0); } else { // Curses, incompatible formats. Take a slow path. // RGBA size_t bufferSize = aRect.width * aRect.height * 4; nsAutoArrayPtr<uint8_t> buf(new uint8_t[bufferSize]); mGLContext->fReadPixels(aRect.x, aRect.y, aRect.width, aRect.height, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, buf); mGLContext->fTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.width, aRect.height, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, buf); } GLenum error = mGLContext->GetAndClearError(); if (error != LOCAL_GL_NO_ERROR) { nsAutoCString msg; msg.AppendPrintf("Texture initialization failed! -- error 0x%x, Source %d, Source format %d, RGBA Compat %d", error, aSourceFrameBuffer, format, isFormatCompatibleWithRGBA); NS_ERROR(msg.get()); } } else { mGLContext->fTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.width, aRect.height, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, nullptr); } mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE); mGLContext->fBindTexture(mFBOTextureTarget, 0); mGLContext->fGenFramebuffers(1, &fbo); *aFBO = fbo; *aTexture = tex; }
int YS_Evolution2D::evolveSurface(YieldSurface_BC *ys, double lamda, Vector &G, Vector &F_Surface, int flag) { // first and fore-most: tmpYSPtr = ys; // int loc = ys->ele_Location; // opserr << " evolve surface [" << opserr << loc << "]\n"; // opserr << *ys; //freezeEvolution = false; -> have set this in commitState -> don't change // first save the vlues on stack // static vectors could get reallocated elsewhere Vector f_sur(2); f_sur(0) = F_Surface(0); f_sur(1) = F_Surface(1); Vector gl(2); gl(0) = G(0); gl(1) = G(1); setTrialPlasticStrains(lamda, f_sur, gl); if(freezeEvolution) return 0; //deformable = true; double kinX = gl(0)*getKinPlasticStiffness(0)/ys->getCap(0); double kinY = gl(1)*getKinPlasticStiffness(1)/ys->getCap(1); double isoX = gl(0)*getIsoPlasticStiffness(0)/ys->getCap(0); double isoY = gl(1)*getIsoPlasticStiffness(1)/ys->getCap(1); // opserr << "isoX = " << isoX << ", isoY = " << isoY << endln; // kinematic hardening double lamda_kin = kinematicRatio*lamda; double dfx_kin = lamda_kin*kinX; double dfy_kin = lamda_kin*kinY; // isotropic hardening double lamda_iso = isotropicRatio*lamda; double dfx_iso = lamda_iso*isoX; double dfy_iso = lamda_iso*isoY; double dfx_total = dfx_kin + dfx_iso; double dfy_total = dfy_kin + dfy_iso; double fx_new = f_sur(0) + dfx_total; double fy_new = f_sur(1) + dfy_total; double fx_iso_new = f_sur(0) + dfx_iso; double fy_iso_new = f_sur(1) + dfy_iso; // check 1: for cross-over -> same as: |F_sur + df| > |F_sur| && Kp < 0 // sign change //cout << "f_sur = " << f_sur(0) << ", f new = " << fx_new << endln; bool ys_harden = true; toOriginalCoord(fx_new, fy_new); if(ys->getDrift(fx_new, fy_new) < 0) ys_harden = false; bool iso_harden = true; toOriginalCoord(fx_iso_new, fy_iso_new); if(ys->getDrift(fx_iso_new, fy_iso_new) < 0) iso_harden = false; if(!ys_harden && (sign(f_sur(0)) != sign(fx_new))) // risky to use for fy -> P { // need to fix this dfx_iso = 0.0; dfx_kin = 0.0; opserr << "Condition happened..\n"; opserr << *ys; freezeEvolution = true; //cerr << "F_Surface(0) = " << f_sur(0) << ", F_New = " << fx_new << endln; //cin.get(); // if(!deformable) //nothing to do // return anyway for now { return 0; // dfy_iso = 0.0; // dfy_kin = 0.0; } } if(!ys_harden && (kinematicRatio != kinematicRatio_shrink) && (isotropicRatio != isotropicRatio_shrink) ) { double kinRatio = kinematicRatio_shrink; double isoRatio = isotropicRatio_shrink; // here it might be a good idea to redo the above step // will not make difference for peak-oriented but for // others may cause convergence problems (Kp_iso != Kp_kin) // what if its not softening anymore? lamda_iso = isoRatio*lamda; dfx_iso = lamda_iso*isoX; dfy_iso = lamda_iso*isoY; lamda_kin = kinRatio*lamda; dfx_kin = lamda_kin*kinX; dfy_kin = lamda_kin*kinY; dfx_total = dfx_kin + dfx_iso; dfy_total = dfy_kin + dfy_iso; fx_new = f_sur(0) + dfx_total; fy_new = f_sur(1) + dfy_total; toOriginalCoord(fx_new, fy_new); if(ys->getDrift(fx_new, fy_new) > 0) { opserr << "oops: YS_Evolution2D::evolveSurface() - softens->hardens\n"; ys_harden = true; } } // Update the isotropicFactor vector /* // This way does not work! int x_grow = 1; if(fabs(f_sur(0) + dfx_iso) < fabs(f_sur(0))) { // opserr << "Softening!\n"; x_grow = -1; } int y_grow = 1; if(fabs(f_sur(1) + dfy_iso) < fabs(f_sur(1))) y_grow = -1; */ int x_grow = 1, y_grow = 1; if(getIsoPlasticStiffness(0) < 0) x_grow = -1; if(getIsoPlasticStiffness(1) < 0) y_grow = -1; if(evolDebug) { opserr << "F_Surface Vector: " << f_sur; opserr << "Fx_new = " << fx_new << ", Fy_new = " << fy_new << endln; opserr << "Gradient: " << gl; opserr << "KpxIso = " << getIsoPlasticStiffness(0) << ", KpyIso = " << getIsoPlasticStiffness(1) << endln; opserr << "F_surf(1) = " << f_sur(1) << ", dfy_iso = " << dfy_iso << endln; opserr << "x_grow = " << x_grow << ", y_grow = " << y_grow << endln; opserr << "---------------------------------------------------------" << endln; } Vector mgnf(2); mgnf = isotropicFactor_hist; if(flag==1) mgnf = isotropicFactor; Vector delMag(2); if(deformable) { delMag(0) = x_grow*fabs(dfx_iso); delMag(1) = y_grow*fabs(dfy_iso); } else { double dR = sqrt(dfx_iso*dfx_iso + dfy_iso*dfy_iso); if(!iso_harden) dR = -1*dR; delMag(0) = dR; delMag(1) = dR; } Vector isoFact = mgnf + delMag; //check 2: For min isotropic factor if( (isotropicFactor(0) + delMag(0)) <= minIsoFactor) { delMag(0) = 0.0; dfx_kin = 0.0; freezeEvolution = true; if(!deformable)// nothing to do return 0; } if( (isotropicFactor(1) + delMag(1)) <= minIsoFactor) { delMag(1) = 0.0; dfy_kin = 0.0; freezeEvolution = true; if(!deformable) return 0; } // update the translation vector double fx_aim = f_sur(0) + dfx_kin; double fy_aim = f_sur(1) + dfy_kin; //cout << "YS_Evolution2D - F_Surface = " << F_Surface; toOriginalCoord(fx_aim, fy_aim); Vector f_aim(2); f_aim(0) = fx_aim; f_aim(1) = fy_aim; v2 = getEvolDirection(f_aim); Vector df_kin = ys->translationTo(f_aim, v2); // correct for isotropic factor Vector trans(2); trans = translate_hist; if(flag==1) trans = translate; // Update the quantities translate(0) = trans(0) + df_kin(0)*isotropicFactor(0); translate(1) = trans(1) + df_kin(1)*isotropicFactor(1); isotropicFactor = mgnf + delMag; return 0; }
long getCurrentWindowId() { DelayedCallGuard dg; CSingleLock gl(g_graphicsContext); return g_windowManager.GetActiveWindow(); }
void check_opengl_features(void) { GL_vendor = xstrdup((char*)gl(GetString, GL_VENDOR)); GL_renderer = xstrdup((char*)gl(GetString, GL_RENDERER)); GL_version = xstrdup((char*)gl(GetString, GL_VERSION)); /* according to opengl spec, the version string of opengl and * glsl is * * <version number> <space> <vendor spec information> * * and <version number> is * * major.minor * * or * * major.minor.release * * */ /* build gl version */ int err; err = sscanf(GL_version, "%d.%d", &GL_major_version, &GL_minor_version); assert(err == 2); assert((GL_major_version > 0) && (GL_major_version <= 3)); assert(GL_minor_version > 0); GL_full_version = MKVER(GL_major_version, GL_minor_version); const char * tmp = (const char *)gl(GetString, GL_SHADING_LANGUAGE_VERSION); if (GL_POP_ERROR() != GL_NO_ERROR) { WARNING(OPENGL, "Doesn't support glsl\n"); GL_glsl_version = NULL; } else { GL_glsl_version = xstrdup(tmp); err = sscanf(GL_glsl_version, "%d.%d", &GLSL_major_version, &GLSL_minor_version); assert(err == 2); assert(GLSL_major_version > 0); assert(GLSL_minor_version > 0); GLSL_full_version = MKVER(GLSL_major_version, GLSL_minor_version); } VERBOSE(OPENGL, "OpenGL engine information:\n"); VERBOSE(OPENGL, "\tvendor: %s\n", GL_vendor); VERBOSE(OPENGL, "\trenderer: %s\n", GL_renderer); VERBOSE(OPENGL, "\tversion: %s\n", GL_version); VERBOSE(OPENGL, "\tglsl version: %s\n", GL_glsl_version); int x; gl(GetIntegerv, GL_SAMPLES, &x); VERBOSE(OPENGL, "\tSamples : %d\n", x); gl(GetIntegerv, GL_SAMPLE_BUFFERS, &x); VERBOSE(OPENGL, "\tSample buffers : %d\n", x); if (x > 0) gl(Enable, GL_MULTISAMPLE); if (GL_POP_ERROR()) WARNING(OPENGL, "platform does not support multisample\n"); gl(GetIntegerv, GL_MAX_TEXTURE_SIZE, &GL_max_texture_size); DEBUG(OPENGL, "system max texture size: %d\n", GL_max_texture_size); int conf_mts = conf_get_int("video.opengl.texture.maxsize", 0); if (conf_mts != 0) { conf_mts = pow2roundup(conf_mts); if (conf_mts < GL_max_texture_size) GL_max_texture_size = conf_mts; } DEBUG(OPENGL, "max texture size is set to %d\n", GL_max_texture_size); gl(GetIntegerv, GL_MAX_VERTEX_ATTRIBS, &GL_max_vertex_attribs); DEBUG(OPENGL, "max vertex attributes is set to %d\n", GL_max_vertex_attribs); build_extensions(); assert(GL_extensions_dict != NULL); GL_POP_ERROR(); #define verbose_feature(name, exp) do {\ if (exp) \ DEBUG(OPENGL, name " is enabled\n"); \ else \ DEBUG(OPENGL, name " is disabled\n"); \ } while(0) GL_texture_NPOT = check_extension("video.opengl.texture.enableNPOT", "GL_ARB_texture_non_power_of_two", NULL); verbose_feature("NPOT texture", GL_texture_NPOT); GL_texture_RECT = check_extension("video.opengl.texture.enableRECT", "GL_ARB_texture_rectangle", "GL_EXT_texture_rectangle", "GL_NV_texture_rectangle", NULL); verbose_feature("RECT texture", GL_texture_RECT); GL_texture_COMPRESSION = check_extension("video.opengl.texture.enableCOMPRESSION", "GL_ARB_texture_compression", NULL); verbose_feature("texture compression", GL_texture_COMPRESSION); GL_vertex_buffer_object = check_extension("video.opengl.enableVBO", "GL_ARB_vertex_buffer_object", NULL); GL_pixel_buffer_object = check_extension("video.opengl.enablePBO", "GL_ARB_pixel_buffer_object", NULL); GL_vertex_array_object = check_extension("video.opengl.enableVAO", "GL_ARB_vertex_array_object", NULL); #undef verbose_feature }
void ContainerLayerOGL::RenderLayer(int aPreviousFrameBuffer, const nsIntPoint& aOffset) { /** * Setup our temporary texture for rendering the contents of this container. */ GLuint containerSurface; GLuint frameBuffer; nsIntPoint childOffset(aOffset); nsIntRect visibleRect = GetEffectiveVisibleRegion().GetBounds(); nsIntRect cachedScissor = gl()->ScissorRect(); gl()->PushScissorRect(); mSupportsComponentAlphaChildren = false; float opacity = GetEffectiveOpacity(); const gfx3DMatrix& transform = GetEffectiveTransform(); bool needsFramebuffer = UseIntermediateSurface(); if (needsFramebuffer) { nsIntRect framebufferRect = visibleRect; // we're about to create a framebuffer backed by textures to use as an intermediate // surface. What to do if its size (as given by framebufferRect) would exceed the // maximum texture size supported by the GL? The present code chooses the compromise // of just clamping the framebuffer's size to the max supported size. // This gives us a lower resolution rendering of the intermediate surface (children layers). // See bug 827170 for a discussion. GLint maxTexSize; gl()->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &maxTexSize); framebufferRect.width = std::min(framebufferRect.width, maxTexSize); framebufferRect.height = std::min(framebufferRect.height, maxTexSize); LayerManagerOGL::InitMode mode = LayerManagerOGL::InitModeClear; if (GetEffectiveVisibleRegion().GetNumRects() == 1 && (GetContentFlags() & Layer::CONTENT_OPAQUE)) { // don't need a background, we're going to paint all opaque stuff mSupportsComponentAlphaChildren = true; mode = LayerManagerOGL::InitModeNone; } else { const gfx3DMatrix& transform3D = GetEffectiveTransform(); gfxMatrix transform; // If we have an opaque ancestor layer, then we can be sure that // all the pixels we draw into are either opaque already or will be // covered by something opaque. Otherwise copying up the background is // not safe. if (HasOpaqueAncestorLayer(this) && transform3D.Is2D(&transform) && !transform.HasNonIntegerTranslation()) { mode = gfxPlatform::ComponentAlphaEnabled() ? LayerManagerOGL::InitModeCopy : LayerManagerOGL::InitModeClear; framebufferRect.x += transform.x0; framebufferRect.y += transform.y0; mSupportsComponentAlphaChildren = gfxPlatform::ComponentAlphaEnabled(); } } gl()->PushViewportRect(); framebufferRect -= childOffset; if (!mOGLManager->CompositingDisabled()) { if (!mOGLManager->CreateFBOWithTexture(framebufferRect, mode, aPreviousFrameBuffer, &frameBuffer, &containerSurface)) { gl()->PopViewportRect(); gl()->PopScissorRect(); gl()->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, aPreviousFrameBuffer); return; } } childOffset.x = visibleRect.x; childOffset.y = visibleRect.y; } else { frameBuffer = aPreviousFrameBuffer; mSupportsComponentAlphaChildren = (GetContentFlags() & Layer::CONTENT_OPAQUE) || (GetParent() && GetParent()->SupportsComponentAlphaChildren()); } nsAutoTArray<Layer*, 12> children; SortChildrenBy3DZOrder(children); /** * Render this container's contents. */ for (uint32_t i = 0; i < children.Length(); i++) { LayerOGL* layerToRender = static_cast<LayerOGL*>(children.ElementAt(i)->ImplData()); if (layerToRender->GetLayer()->GetEffectiveVisibleRegion().IsEmpty()) { continue; } nsIntRect scissorRect = layerToRender->GetLayer()-> CalculateScissorRect(cachedScissor, &mOGLManager->GetWorldTransform()); if (scissorRect.IsEmpty()) { continue; } gl()->fScissor(scissorRect.x, scissorRect.y, scissorRect.width, scissorRect.height); layerToRender->RenderLayer(frameBuffer, childOffset); gl()->MakeCurrent(); } if (needsFramebuffer) { // Unbind the current framebuffer and rebind the previous one. #ifdef MOZ_DUMP_PAINTING if (gfxUtils::sDumpPainting) { nsRefPtr<gfxImageSurface> surf = gl()->GetTexImage(containerSurface, true, mOGLManager->GetFBOTextureFormat()); WriteSnapshotToDumpFile(this, surf); } #endif // Restore the viewport gl()->PopViewportRect(); nsIntRect viewport = gl()->ViewportRect(); mOGLManager->SetupPipeline(viewport.width, viewport.height, LayerManagerOGL::ApplyWorldTransform); gl()->PopScissorRect(); if (!mOGLManager->CompositingDisabled()) { gl()->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, aPreviousFrameBuffer); gl()->fDeleteFramebuffers(1, &frameBuffer); gl()->fActiveTexture(LOCAL_GL_TEXTURE0); gl()->fBindTexture(mOGLManager->FBOTextureTarget(), containerSurface); MaskType maskType = MaskNone; if (GetMaskLayer()) { if (!GetTransform().CanDraw2D()) { maskType = Mask3d; } else { maskType = Mask2d; } } ShaderProgramOGL *rgb = mOGLManager->GetFBOLayerProgram(maskType); rgb->Activate(); rgb->SetLayerQuadRect(visibleRect); rgb->SetLayerTransform(transform); rgb->SetTextureTransform(gfx3DMatrix()); rgb->SetLayerOpacity(opacity); rgb->SetRenderOffset(aOffset); rgb->SetTextureUnit(0); rgb->LoadMask(GetMaskLayer()); if (rgb->GetTexCoordMultiplierUniformLocation() != -1) { // 2DRect case, get the multiplier right for a sampler2DRect rgb->SetTexCoordMultiplier(visibleRect.width, visibleRect.height); } // Drawing is always flipped, but when copying between surfaces we want to avoid // this. Pass true for the flip parameter to introduce a second flip // that cancels the other one out. mOGLManager->BindAndDrawQuad(rgb, true); // Clean up resources. This also unbinds the texture. gl()->fDeleteTextures(1, &containerSurface); } } else { gl()->PopScissorRect(); } }
Texture::~Texture() { assert(isInitialized()); gl(glDeleteTextures(1, &m_id)); }
void ReflowPage::drawProfile(FlashGraphics& flash) const { uint8_t i; Point p1,p2,p; Panel::LcdPanel& gl(_panel.getGraphicsLibrary()); AxisNumberWriter writer; // constants used later const uint32_t width=X_AXIS_WIDTH-1; const uint32_t height=Y_AXIS_HEIGHT; // starting point (all the reflow profiles have a desired start of 25C) p1.X=LEFT_MARGIN; p1.Y=Panel::HEIGHT-BOTTOM_MARGIN-1-((height*25)/_reflowProfile->getMaxTemperature());; // the segments describe the ending condition, loop for each one for(i=0; i<_reflowProfile->getSegmentCount(); i++) { const ReflowProfile::Segment& s((*_reflowProfile)[i]); // calculate the end point and plot the line p2.X=LEFT_MARGIN+((width*s.EndingTime)/_reflowProfile->getTotalDuration()); p2.Y=Panel::HEIGHT-BOTTOM_MARGIN-1-((height*s.Temperature)/_reflowProfile->getMaxTemperature()); wideLine(gl,p1,p2,0x00cd99); // plot a horizontal dotted grey line to the Y axis. these plotters are far from optimal // for plotting a straight dotted line but they're sufficient for this light load. p=p2; gl.setForeground(ColourNames::GREY40); while(p.X>LEFT_MARGIN) { gl.plotPoint(p); p.X-=2; } // plot a vertical line down to the X axis p=p2; gl.setForeground(ColourNames::GREY40); while(p.Y<Panel::HEIGHT-BOTTOM_MARGIN-1) { gl.plotPoint(p); p.Y+=2; } // draw the temperature on the Y axis p.X=10; p.Y=p2.Y; writer.write(flash,p,s.Temperature); // draw the time on the X axis p.X=p2.X; p.Y=Panel::HEIGHT-BOTTOM_MARGIN+4; writer.write(flash,p,s.EndingTime); // starting point is now the ending point p1=p2; } }
int glhard() { cl(); return gl(); }
tCmd * pC() { tCmd * cmd; simpleCmd * smpl = newCommand(); clearLexList(pSt.list); if (cur_l->type != LEX_WORD) { setParserError(PE_EXPECTED_WORD); delCommand(&smpl); return NULL; } addLex(pSt.list, pSt.l); for(;;) { if (gl()) { clearLexList(pSt.list); delCommand(&smpl); return NULL; } if (cur_l->type == LEX_WORD) addLex(pSt.list, pSt.l); else if (cur_l->type == LEX_REDIRECT_INPUT || cur_l->type == LEX_REDIRECT_OUTPUT || cur_l->type == LEX_REDIRECT_OUTPUT_APPEND) { int type = cur_l->type; if (glhard()) { clearLexList(pSt.list); delCommand(&smpl); return NULL; } if (cur_l->type != LEX_WORD) { setParserError(PE_EXPECTED_WORD); if(smpl->rdrInputFile != NULL) free(smpl->rdrInputFile); if(smpl->rdrOutputFile != NULL) free(smpl->rdrOutputFile); delCommand(&smpl); delLex(cur_l); clearLexList(pSt.list); return NULL; } if (type == LEX_REDIRECT_INPUT) { if(smpl->rdrInputFile != NULL) free(smpl->rdrInputFile); smpl->rdrInputFile = cur_l->str; } else if (type == LEX_REDIRECT_OUTPUT || type == LEX_REDIRECT_OUTPUT_APPEND) { if (type == LEX_REDIRECT_OUTPUT_APPEND) smpl->rdrOutputAppend = 1; else smpl->rdrOutputAppend = 0; if(smpl->rdrOutputFile != NULL) free(smpl->rdrOutputFile); smpl->rdrOutputFile = cur_l->str; } } else break; } genArgVector(smpl, pSt.list); smpl->file = smpl->argv[0]; cmd = genTCmd(smpl); cmd->cmdType = TCMD_SIMPLE; return cmd; }
bool qt_resolve_gl_symbols(bool fatal) { static bool gl_syms_resolved = FALSE; if (gl_syms_resolved) return TRUE; QLibrary gl("GL"); gl.setAutoUnload(FALSE); qt_glCallLists = (_glCallLists) gl.resolve("glCallLists"); if (!qt_glCallLists) { // if this fails the rest will surely fail if (fatal) qFatal("Unable to resolve GL/GLX symbols - please check your GL library installation."); return FALSE; } qt_glClearColor = (_glClearColor) gl.resolve("glClearColor"); qt_glClearIndex = (_glClearIndex) gl.resolve("glClearIndex"); qt_glColor3ub = (_glColor3ub) gl.resolve("glColor3ub"); qt_glDeleteLists = (_glDeleteLists) gl.resolve("glDeleteLists"); qt_glDrawBuffer = (_glDrawBuffer) gl.resolve("glDrawBuffer"); qt_glFlush = (_glFlush) gl.resolve("glFlush"); qt_glIndexi = (_glIndexi) gl.resolve("glIndexi"); qt_glListBase = (_glListBase) gl.resolve("glListBase"); qt_glLoadIdentity = (_glLoadIdentity) gl.resolve("glLoadIdentity"); qt_glMatrixMode = (_glMatrixMode) gl.resolve("glMatrixMode"); qt_glOrtho = (_glOrtho) gl.resolve("glOrtho"); qt_glPopAttrib = (_glPopAttrib) gl.resolve("glPopAttrib"); qt_glPopMatrix = (_glPopMatrix) gl.resolve("glPopMatrix"); qt_glPushAttrib = (_glPushAttrib) gl.resolve("glPushAttrib"); qt_glPushMatrix = (_glPushMatrix) gl.resolve("glPushMatrix"); qt_glRasterPos2i = (_glRasterPos2i) gl.resolve("glRasterPos2i"); qt_glRasterPos3d = (_glRasterPos3d) gl.resolve("glRasterPos3d"); qt_glReadPixels = (_glReadPixels) gl.resolve("glReadPixels"); qt_glViewport = (_glViewport) gl.resolve("glViewport"); qt_glPixelStorei = (_glPixelStorei) gl.resolve("glPixelStorei"); qt_glBitmap = (_glBitmap) gl.resolve("glBitmap"); qt_glDrawPixels = (_glDrawPixels) gl.resolve("glDrawPixels"); qt_glNewList = (_glNewList) gl.resolve("glNewList"); qt_glGetFloatv = (_glGetFloatv) gl.resolve("glGetFloatv"); qt_glGetIntegerv = (_glGetIntegerv) gl.resolve("glGetIntegerv"); qt_glEndList = (_glEndList) gl.resolve("glEndList"); qt_glXChooseVisual = (_glXChooseVisual) gl.resolve("glXChooseVisual"); qt_glXCreateContext = (_glXCreateContext) gl.resolve("glXCreateContext"); qt_glXCreateGLXPixmap = (_glXCreateGLXPixmap) gl.resolve("glXCreateGLXPixmap"); qt_glXDestroyContext = (_glXDestroyContext) gl.resolve("glXDestroyContext"); qt_glXDestroyGLXPixmap = (_glXDestroyGLXPixmap) gl.resolve("glXDestroyGLXPixmap"); qt_glXGetClientString = (_glXGetClientString) gl.resolve("glXGetClientString"); qt_glXGetConfig = (_glXGetConfig) gl.resolve("glXGetConfig"); qt_glXIsDirect = (_glXIsDirect) gl.resolve("glXIsDirect"); qt_glXMakeCurrent = (_glXMakeCurrent) gl.resolve("glXMakeCurrent"); qt_glXQueryExtension = (_glXQueryExtension) gl.resolve("glXQueryExtension"); qt_glXQueryExtensionsString = (_glXQueryExtensionsString) gl.resolve("glXQueryExtensionsString"); qt_glXQueryServerString = (_glXQueryServerString) gl.resolve("glXQueryServerString"); qt_glXSwapBuffers = (_glXSwapBuffers) gl.resolve("glXSwapBuffers"); qt_glXUseXFont = (_glXUseXFont) gl.resolve("glXUseXFont"); qt_glXWaitX = (_glXWaitX) gl.resolve("glXWaitX"); gl_syms_resolved = TRUE; return TRUE; }
bool SurfaceTextureSource::IsValid() const { return !!gl(); }
GLenum gl_pop_error_nodebug(void) { return gl(GetError); }
bool EGLImageTextureSource::IsValid() const { return !!gl(); }
int main(int argc, char **argv) { int ch, idx, goggles; int (*gl)(int, char * const *, const char *, const struct option *, int *); struct option longopts[] = { { "force", no_argument, 0, 0 }, { "fast", no_argument, 0, '1' }, { "best", no_argument, 0, '9' }, { "input", required_argument, 0, 'i' }, { "illiterate", no_argument, 0, 0 }, { "drinking", required_argument, &goggles, 42 }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; if (getenv("LONG_ONLY")) { gl = getopt_long_only; printf("getopt_long_only"); } else { gl = getopt_long; printf("getopt_long"); } if (getenv("POSIXLY_CORRECT")) printf(" (POSIXLY_CORRECT)"); printf(": "); for (idx = 1; idx < argc; idx++) printf("%s ", argv[idx]); printf("\n"); goggles = 0; for (;;) { idx = -1; ch = gl(argc, argv, "19bf:i:hW;-", longopts, &idx); if (ch == -1) break; switch (ch) { case 0: case '1': case '9': case 'h': case 'b': case '-': if (idx != -1) { if (goggles == 42) printf("option %s, arg %s\n", longopts[idx].name, optarg); else printf("option %s\n", longopts[idx].name); } else printf("option %c\n", ch); break; case 'f': case 'i': if (idx != -1) printf("option %s, arg %s\n", longopts[idx].name, optarg); else printf("option %c, arg %s\n", ch, optarg); break; case '?': break; default: printf("unexpected return value: %c\n", ch); break; } } argc -= optind; argv += optind; if (argc > 0) { printf("remaining ARGV: "); while (argc--) printf("%s ", *argv++); printf("\n"); } printf("\n"); exit (0); }
Texture::~Texture() { CECE_ASSERT(isInitialized()); gl(glDeleteTextures(1, &m_id)); }
bool GLTextureSource::IsValid() const { return !!gl(); }
void LayerManagerOGL::CreateFBOWithTexture(const nsIntRect& aRect, InitMode aInit, GLuint aCurrentFrameBuffer, GLuint *aFBO, GLuint *aTexture) { GLuint tex, fbo; mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0); mGLContext->fGenTextures(1, &tex); mGLContext->fBindTexture(mFBOTextureTarget, tex); if (aInit == InitModeCopy) { // We're going to create an RGBA temporary fbo. But to // CopyTexImage() from the current framebuffer, the framebuffer's // format has to be compatible with the new texture's. So we // check the format of the framebuffer here and take a slow path // if it's incompatible. GLenum format = GetFrameBufferInternalFormat(gl(), aCurrentFrameBuffer, mWidget); if (AreFormatsCompatibleForCopyTexImage2D(format, LOCAL_GL_RGBA)) { mGLContext->fCopyTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.x, aRect.y, aRect.width, aRect.height, 0); } else { // Curses, incompatible formats. Take a slow path. // // XXX Technically CopyTexSubImage2D also has the requirement of // matching formats, but it doesn't seem to affect us in the // real world. mGLContext->fTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.width, aRect.height, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, NULL); mGLContext->fCopyTexSubImage2D(mFBOTextureTarget, 0, // level 0, 0, // offset aRect.x, aRect.y, aRect.width, aRect.height); } } else { mGLContext->fTexImage2D(mFBOTextureTarget, 0, LOCAL_GL_RGBA, aRect.width, aRect.height, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, NULL); } mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE); mGLContext->fTexParameteri(mFBOTextureTarget, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE); mGLContext->fBindTexture(mFBOTextureTarget, 0); mGLContext->fGenFramebuffers(1, &fbo); mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, fbo); mGLContext->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0, mFBOTextureTarget, tex, 0); // Making this call to fCheckFramebufferStatus prevents a crash on // PowerVR. See bug 695246. GLenum result = mGLContext->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER); if (result != LOCAL_GL_FRAMEBUFFER_COMPLETE) { nsCAutoString msg; msg.Append("Framebuffer not complete -- error 0x"); msg.AppendInt(result, 16); msg.Append(", mFBOTextureTarget 0x"); msg.AppendInt(mFBOTextureTarget, 16); msg.Append(", aRect.width "); msg.AppendInt(aRect.width); msg.Append(", aRect.height "); msg.AppendInt(aRect.height); NS_RUNTIMEABORT(msg.get()); } SetupPipeline(aRect.width, aRect.height, DontApplyWorldTransform); mGLContext->fScissor(0, 0, aRect.width, aRect.height); if (aInit == InitModeClear) { mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0); mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT); } *aFBO = fbo; *aTexture = tex; }
bool SharedTextureSourceOGL::IsValid() const { return !!gl(); }
long getCurrentWindowDialogId() { DelayedCallGuard dg; CSingleLock gl(g_graphicsContext); return g_windowManager.GetTopMostModalDialogID(); }
bool StreamTextureSourceOGL::RetrieveTextureFromStream() { gl()->MakeCurrent(); SharedSurface* sharedSurf = mStream->SwapConsumer(); if (!sharedSurf) { // We don't have a valid surf to show yet. return false; } gl()->MakeCurrent(); mSize = IntSize(sharedSurf->Size().width, sharedSurf->Size().height); DataSourceSurface* toUpload = nullptr; switch (sharedSurf->Type()) { case SharedSurfaceType::GLTextureShare: { SharedSurface_GLTexture* glTexSurf = SharedSurface_GLTexture::Cast(sharedSurf); mTextureHandle = glTexSurf->ConsTexture(gl()); mTextureTarget = glTexSurf->ConsTextureTarget(); MOZ_ASSERT(mTextureHandle); mFormat = sharedSurf->HasAlpha() ? SurfaceFormat::R8G8B8A8 : SurfaceFormat::R8G8B8X8; break; } case SharedSurfaceType::EGLImageShare: { SharedSurface_EGLImage* eglImageSurf = SharedSurface_EGLImage::Cast(sharedSurf); eglImageSurf->AcquireConsumerTexture(gl(), &mTextureHandle, &mTextureTarget); MOZ_ASSERT(mTextureHandle); mFormat = sharedSurf->HasAlpha() ? SurfaceFormat::R8G8B8A8 : SurfaceFormat::R8G8B8X8; break; } #ifdef XP_MACOSX case SharedSurfaceType::IOSurface: { SharedSurface_IOSurface* glTexSurf = SharedSurface_IOSurface::Cast(sharedSurf); mTextureHandle = glTexSurf->ConsTexture(gl()); mTextureTarget = glTexSurf->ConsTextureTarget(); MOZ_ASSERT(mTextureHandle); mFormat = sharedSurf->HasAlpha() ? SurfaceFormat::R8G8B8A8 : SurfaceFormat::R8G8B8X8; break; } #endif case SharedSurfaceType::Basic: { toUpload = SharedSurface_Basic::Cast(sharedSurf)->GetData(); MOZ_ASSERT(toUpload); break; } default: MOZ_CRASH("Invalid SharedSurface type."); } if (toUpload) { // mBounds seems to end up as (0,0,0,0) a lot, so don't use it? nsIntSize size(ThebesIntSize(toUpload->GetSize())); nsIntRect rect(nsIntPoint(0,0), size); nsIntRegion bounds(rect); mFormat = UploadSurfaceToTexture(gl(), toUpload, bounds, mUploadTexture, true); mTextureHandle = mUploadTexture; mTextureTarget = LOCAL_GL_TEXTURE_2D; } MOZ_ASSERT(mTextureHandle); gl()->fBindTexture(mTextureTarget, mTextureHandle); gl()->fTexParameteri(mTextureTarget, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE); gl()->fTexParameteri(mTextureTarget, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE); ClearCachedFilter(); return true; }
bool GrallocDeprecatedTextureHostOGL::IsValid() const { return !!gl() && !!mGraphicBuffer.get(); }
void CompositorOGL::BeginFrame(const Rect *aClipRectIn, const gfxMatrix& aTransform, const Rect& aRenderBounds, Rect *aClipRectOut, Rect *aRenderBoundsOut) { MOZ_ASSERT(!mFrameInProgress, "frame still in progress (should have called EndFrame or AbortFrame"); mVBOs.Reset(); mFrameInProgress = true; gfxRect rect; if (mUseExternalSurfaceSize) { rect = gfxRect(0, 0, mSurfaceSize.width, mSurfaceSize.height); } else { rect = gfxRect(aRenderBounds.x, aRenderBounds.y, aRenderBounds.width, aRenderBounds.height); // If render bounds is not updated explicitly, try to infer it from widget if (rect.width == 0 || rect.height == 0) { // FIXME/bug XXXXXX this races with rotation changes on the main // thread, and undoes all the care we take with layers txns being // sent atomically with rotation changes nsIntRect intRect; mWidget->GetClientBounds(intRect); rect = gfxRect(0, 0, intRect.width, intRect.height); } } rect = aTransform.TransformBounds(rect); if (aRenderBoundsOut) { *aRenderBoundsOut = Rect(rect.x, rect.y, rect.width, rect.height); } GLint width = rect.width; GLint height = rect.height; // We can't draw anything to something with no area // so just return if (width == 0 || height == 0) return; // If the widget size changed, we have to force a MakeCurrent // to make sure that GL sees the updated widget size. if (mWidgetSize.width != width || mWidgetSize.height != height) { MakeCurrent(ForceMakeCurrent); mWidgetSize.width = width; mWidgetSize.height = height; } else { MakeCurrent(); } #if MOZ_ANDROID_OMTC TexturePoolOGL::Fill(gl()); #endif mCurrentRenderTarget = CompositingRenderTargetOGL::RenderTargetForWindow(this, IntSize(width, height), aTransform); mCurrentRenderTarget->BindRenderTarget(); #ifdef DEBUG mWindowRenderTarget = mCurrentRenderTarget; #endif // Default blend function implements "OVER" mGLContext->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA, LOCAL_GL_ONE, LOCAL_GL_ONE); mGLContext->fEnable(LOCAL_GL_BLEND); if (!aClipRectIn) { mGLContext->fScissor(0, 0, width, height); if (aClipRectOut) { aClipRectOut->SetRect(0, 0, width, height); } } else { mGLContext->fScissor(aClipRectIn->x, aClipRectIn->y, aClipRectIn->width, aClipRectIn->height); } mGLContext->fEnable(LOCAL_GL_SCISSOR_TEST); // If the Android compositor is being used, this clear will be done in // DrawWindowUnderlay. Make sure the bits used here match up with those used // in mobile/android/base/gfx/LayerRenderer.java #ifndef MOZ_ANDROID_OMTC mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0); mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT); #endif }