int main(int argc, char **argv) { static const int bad_attributes[] = { 0xffff0000, GLX_SAMPLE_BUFFERS }; bool pass = true; unsigned i; GLX_ARB_create_context_setup(); for (i = 0; i < ARRAY_SIZE(bad_attributes); i++) { pass = try_attribute(bad_attributes[i]) && pass; } /* The GLX_ARB_create_context spec says: * * "If GLX_ARB_create_context_profile is not supported, then the * GLX_CONTEXT_PROFILE_MASK_ARB attribute [is] not defined, and * specifying the attribute in <attribList> attribute will * generate BadValue." */ if (!piglit_is_glx_extension_supported(dpy, "GLX_ARB_create_context_profile")) { pass = try_attribute(GLX_CONTEXT_PROFILE_MASK_ARB) && pass; } GLX_ARB_create_context_teardown(); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); return 0; }
void CascadeStyles ( const XMLIterator &i, XMLCreatorEnv *env, XMLAttributes &attributes, XMLStyle &branch_style, XMLCreatorEnv &ch_env ) { XMLStyle *parent_style=0; const std::string &name = (*i)._name; const XMLParser::Node &node = (*i); XMLAttributes::iterator attr_i = attributes.end(); insert( node._attributes.begin(), node._attributes.end(), attributes, attr_i ); std::string style_name; if ( try_attribute( (*i)._attributes, "style", &style_name ) ) { const XMLStyle &ref_style = QueryStyle( style_name ); XMLStyle::iterator sty_i = branch_style.end(); insert( ref_style.begin(), ref_style.end(), branch_style, sty_i ); } if ( (*env).Query("parent_style", parent_style ) ) { XMLStyle::iterator sty_i = branch_style.end(); insert( parent_style->begin(), parent_style->end(), branch_style, sty_i ); } XMLStyle::iterator st_it = branch_style.find(name); if ( st_it != branch_style.end() ) { XMLAttributes::iterator attr_i = attributes.end(); insert( (*st_it).second.begin(), (*st_it).second.end(), attributes, attr_i ); } std::string inner_style_name; if ( try_attribute( (*i)._attributes, "inner_style", &inner_style_name ) ) { const XMLStyle &ref_style = QueryStyle( inner_style_name ); ch_env.Set("parent_style", &ref_style ); } else if ( !branch_style.empty() ) { int disable_style = false; try_attribute_i( (*i)._attributes, "disable_style", &disable_style ); if ( !disable_style ) // apply Cascading Style Derivation for children { ch_env.Set("parent_style", &branch_style); } } }
/*! Create resources in in given category */ void CategoryFromXML( const std::string &category, XMLIterator i ) { try{ for ( i.StepInto(); !!i; ++i ) { XMLCreatorEnv environment; environment.Set( "category", category.c_str() ); std::string id = (*i)._name; //< Default id is name[n] if ( try_attribute( (*i)._attributes, "id", &id ) ) { environment.Set( "name", id.c_str() ); } if ( Resource *ptr = XMLCreators::Instance().Create( category, i, &environment )) { Resources::Instance().Insert( category, id, ptr ); } } } catch( Error &e ) { throw XMLParser::XMLError( (*i)._source, (*i)._line, e.GetError() ); } }
int main(int argc, char **argv) { EGLint bad_attributes[] = { 0xffff0000, EGL_SAMPLE_BUFFERS }; bool pass = true; unsigned i; if (!EGL_KHR_create_context_setup(EGL_OPENGL_BIT)) { fprintf(stderr, "Desktop GL not available.\n"); piglit_report_result(PIGLIT_SKIP); } eglBindAPI(EGL_OPENGL_API); for (i = 0; i < ARRAY_SIZE(bad_attributes); i++) { pass = try_attribute(bad_attributes[i]) && pass; } EGL_KHR_create_context_teardown(); piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); return EXIT_SUCCESS; }
Resource* CreateSysOutputImage( XMLIterator i, XMLCreatorEnv *env ) { std::string layer = get_attribute( (*i)._attributes, "layer" ); std::string source = get_attribute( (*i)._attributes, "src" ); std::vector< int > sRc = to_integer_vector( get_attribute( (*i)._attributes, "srcRect" )); std::vector< int > dRc = to_integer_vector( get_attribute( (*i)._attributes, "dstRect" )); std::string target("color"); try_attribute( (*i)._attributes, "target", &target ); Rect &srcRect = (Rect&)sRc[0]; Rect &dstRect = (Rect&)dRc[0]; if ( s_SysOut._sources.find( source ) == s_SysOut._sources.end() ) { if ( target == "color" ) { s_SysOut._sources[ source ] = new Image( source.c_str() ); } else if ( target == "color+alpha" ) { s_SysOut._sources[ source ] = new TransparentImage( source.c_str(), source.c_str() ); } } SPointer< IGraphics > img = s_SysOut._sources[ source ]; s_SysOut._imageOuts[ layer ]._image = img->Copy( srcRect ); s_SysOut._imageOuts[ layer ]._dstRect = dstRect; s_SysOut.UpdateDisplay(); return 0; }
void SiblingsFromXML( XMLIterator i, XMLCreatorEnv *env ) { try{ std::string branch; const char *p_branch; if ( (*env).Query( "branch", p_branch ) ) { branch = p_branch; } for ( /*i.StepInto()*/; !!i; ++i ) { const char *p_cat; (*env).Query("category", p_cat ); std::string category( p_cat ); std::string name( (*i)._name ); int posCat = name.find("::"); if ( -1 != posCat ) { category = name.substr( 0, posCat ); name = name.substr( posCat+2, name.size()-(posCat+2)); #pragma message("use of category::name changes const xml-node") const_cast< std::string & >( (*i)._name ) = name; } std::string id = (branch.empty() ? name : branch + "." + name); if ( try_attribute( (*i)._attributes, "id", &id ) ) { id = (branch.empty() ? id : branch + "." + id ); (*env).Set( "name", id.c_str() ); } else { (*env).Set( "name", branch.c_str() ); } if ( Resource *ptr = XMLCreators::Instance().Create( category, i, env ) ) { Resources::Instance().Insert( category, id, ptr ); } _DispatchSystemMessages(); } } catch( XMLParser::XMLError & ) { throw; } catch( Error &e ) { throw XMLParser::XMLError( (*i)._source, (*i)._line, e.GetError() ); } }
/*! Create all resources from XML string */ void CreateFromXML( const std::string &xml_sring, const std::string &source ) { XMLDocument _xml( xml_sring, source); for ( XMLIterator i=_xml.Root().StepInto(); !!i; ++i ) { const std::string name = (*i)._name; if ( name == "include") { std::string oldPath; std::string newPath; if ( try_attribute( (*i)._attributes, "chroot", &newPath )) { int brOpen = newPath.find("$(", 0 ); if ( -1 != brOpen ) { int brClose = newPath.find(")", brOpen+2 ); if ( -1 != brClose ) { std::string envName = newPath.substr( brOpen+2, brClose-( brOpen+2 )); const char *cEnv = getenv( envName.c_str() ); if (! cEnv ) { throw Error("$(%s) is not set.", envName.c_str() ); } newPath = newPath.substr( 0, brOpen ) + cEnv + newPath.substr( brClose+1, -1 ); } } if ( !IFS::Instance().IsDir( newPath )) { throw Error("\"%s\" is not directory.", newPath.c_str()); } char cwd[_MAX_PATH]; _getcwd( cwd, _MAX_PATH ); oldPath = cwd; _chdir( newPath.c_str() ); } std::string src = get_attribute( (*i)._attributes, "src"); if ( s_includedFiles.insert( src ).second ) { CreateFromXMLFile( src ); } if ( !oldPath.empty() ) { _chdir( oldPath.c_str() ); } } else { CategoryFromXML( name, i ); } } }
Resource* CreateScrolledWidget( XMLIterator i, XMLCreatorEnv *env ) { XMLCreatorEnv ch_env; const char *p_name = "create popup"; BeginParentWidget( env, p_name, ch_env ); XMLAttributes attributes; XMLStyle branch_style; CascadeStyles( i, env, attributes, branch_style, ch_env ); int speed = ScrolledWidget::DEFFAULT_SPEED; try_attribute_i( attributes, "speed", &speed ); int dragSliding = false; try_attribute_i( attributes, "drag_slide", &dragSliding ); std::vector<int> adv = to_integer_vector( "0,0" ); std::string advance; if ( try_attribute( attributes, "advance", &advance ) ) { adv = to_integer_vector( advance ); if ( adv.size() != 2 ) { throw Error("Advance attribute must have x and y coordinates"); } } //temporary hub SPointer<HubWidget> ptr = new HubWidget( 100, 100 ); ch_env["parent_hub"] = ptr.get(); // create children elements ChildsFromXML( i, &ch_env ); if( ptr->ChildrenCount( ) > 1 ) throw Error("Scrolled widget %s has more than 1 content.", (*i)._name.c_str()); ScrolledWidget *scrollee = new ScrolledWidget(); if( ptr->ChildrenCount( ) > 0 ) { Widget* content = ptr->FirstChild(); ptr->Retrieve( content ); scrollee->AttachWidget( content ); } scrollee->SetSpeed(speed); scrollee->SetNoDragSliding( !dragSliding ); scrollee->HScrollTo(adv[0]); scrollee->VScrollTo(adv[1]); InsertChildWidget( scrollee, attributes, env); SetHint(scrollee, attributes); return new AnyResource<ScrolledWidget*>( scrollee ); }
Resource* CreateGraphWidget( XMLIterator i, XMLCreatorEnv *env ) { XMLCreatorEnv ch_env; XMLAttributes attributes; XMLStyle branch_style; CascadeStyles( i, env, attributes, branch_style, ch_env ); std::string color = get_attribute( attributes, "color" ); NormalPixel ncolor( to_hex( color )); int dotted = 0; try_attribute_i( attributes, "dotted", &dotted ); GraphWidget *ptr = new GraphWidget( Dim2i( 100, 100 ), ncolor.c, ( dotted ? GraphWidget::GT_POINTS : GraphWidget::GT_LINES ) ); std::string bounds; if ( try_attribute( attributes, "bounds", &bounds )) { std::vector< int > b = to_integer_vector( bounds ); ptr->SetValueBounds( b[0], b[1], b[2], b[3] ); } Useless::GraphWidget::tpe_input_vector initData( 100 ); initData.resize(0); for ( double f=0.0; f <= 6.28; f += 3.14/100.0 ) { double y = sin( f ); initData.push_back( y ); } ptr->SetInputData( initData ); InsertChildWidget( ptr, attributes, env); return new AnyResource<GraphWidget*>( ptr ); }
Resource* CreateSkinMixer( XMLIterator i, XMLCreatorEnv *env) { SPointer<SkinMan> sp_skin_man; SkinMixer *p_mixer = new SkinMixer; const XMLNode &node = *i; std::map< std::string, int > skin_IDs; std::string map_name = get_attribute( node._attributes, "mapping"); std::vector<int> *p_map; Resources::Instance().Query( "mappings", map_name, p_map); int ni = 0; for ( i.StepInto(); !!i; ++i, ++ni) { int oid = (*p_map)[ni]; if ( (*i)._name == "state" ) { XMLIterator j = i; for ( j.StepInto(); !!j; ++j) { if ( (*j)._name == "mix") { int iid; std::string id = get_attribute( (*j)._attributes, "id"); if ( skin_IDs.find( id) == skin_IDs.end()) { Skin &skin = QuerySkin( id); iid = p_mixer->Insert( skin); skin_IDs[id] = iid; } else { iid = skin_IDs[id]; } int alignment = -1; Pos offset(0,0); std::string tmp; if ( try_attribute( (*j)._attributes, "halign", &tmp )) { if ( tmp == "left" ) { alignment = Rect::HALIGNLEFT; } else if ( tmp == "center" ) { alignment = Rect::HALIGNCENTER; } else if ( tmp == "right" ) { alignment = Rect::HALIGNRIGHT; } else if ( tmp == "fill" ) { alignment = -1; } } if ( try_attribute( (*j)._attributes, "valign", &tmp )) { if ( alignment == -1 ) { alignment = 0; } if ( tmp == "top" ) { alignment |= Rect::VALIGNTOP; } else if ( tmp == "center" ) { alignment |= Rect::VALIGNCENTER; } else if ( tmp == "bottom" ) { alignment |= Rect::VALIGNBOTTOM; } else if ( tmp == "fill" ) { alignment = -1; } } p_mixer->Mix( oid, iid, alignment, offset); } else { C_verify( !"CreateSkinMixer: Tag <mix /> was excpected."); } } } } return new AnyResource< SPointer<SkinMan> >( p_mixer); }
Resource* CreateTextWidget( XMLIterator i, XMLCreatorEnv *env ) { XMLCreatorEnv ch_env; XMLAttributes attributes; XMLStyle branch_style; CascadeStyles( i, env, attributes, branch_style, ch_env ); std::string font = get_attribute( attributes, "font" ); int bodyAsLink = 0; try_attribute_i( attributes, "body_as_link", &bodyAsLink ); Text text; if ( bodyAsLink ) text = QueryText( make_string( (*i)._value )); else text = MakeText(to_chars( (*i)._value )); Widget *ptr; XMLIterator ch_i = i; int line_spacing = 0; std::string alignment; bool adv_text = try_attribute_i( attributes, "spacing", &line_spacing ); adv_text |= try_attribute( attributes, "align", &alignment ); // create DualText if ( !!ch_i.StepInto() ) { int shift = 2; try_attribute_i( attributes, "shift", &shift ); std::wstring left, right; for ( ; !!ch_i; ++ch_i ) { if ( (*ch_i)._name == "left" ) left = to_chars( (*ch_i)._value ); else if ( (*ch_i)._name == "right" ) right = to_chars( (*ch_i)._value ); } int bodyAsLink = 0; try_attribute_i( attributes, "body_as_link", &bodyAsLink ); Text leftT, rightT; if ( bodyAsLink ) { leftT = QueryText( make_string( left )); rightT = QueryText( make_string( right )); } else { leftT = MakeText(left); rightT = MakeText(right); } DualTextWidget *p_dual; ptr = p_dual = new DualTextWidget( 100, QueryFont(font), leftT, rightT, shift ); std::string dotcode; if ( try_attribute( attributes, "dot", &dotcode ) ) p_dual->SetDotCode( ( dotcode.size()>0 ? dotcode[0] : ' ' ) ); } else if ( adv_text ) { int align = 0; if ( alignment == "left" ) { align = 0; } else if ( alignment == "right" ) { align = 1; } else if ( alignment == "center" ) { align = 2; } if ( (*i)._name == "activetext" ) { ptr = new ActiveText( QueryFont(font), text, line_spacing, align ); } else { ptr = new AdvTextWidget( QueryFont(font), text, line_spacing, align ); } } else { TextWidget *ptrTW = new TextWidget( QueryFont(font), text ); ptr = ptrTW; ptrTW->SetText( text ); } InsertChildWidget( ptr, attributes, env); return new AnyResource<Widget*>( ptr ); }
Resource * CreateDropDown( XMLIterator i, XMLCreatorEnv *env ) { XMLCreatorEnv ch_env; const char *p_name = "create dropdown"; BeginParentWidget( env, p_name, ch_env ); XMLAttributes attributes; XMLStyle branch_style; CascadeStyles( i, env, attributes, branch_style, ch_env); // skins & fonts for caption std::string skinName = get_attribute( attributes, "title_skin"); std::string fontName = get_attribute( attributes, "title_font"); SkinMan &skins = QuerySkinMan( skinName ); FontSet &fonts = QueryFontSet( fontName ); // caption position int titleAlign = 0; try_attribute_i( attributes, "title_align", &titleAlign ); std::vector<int> pos = to_integer_vector( "0,0" ); std::string position; if ( try_attribute( attributes, "title_distance", &position ) ) { pos = to_integer_vector( position ); if ( pos.size() != 2 ) { throw Error("pos attribute must have x and y coordinates"); } } CaptionStyle style( skins, fonts, titleAlign, Pos(pos[0], pos[1]) ); // temporary hub for child widget SPointer<HubWidget> ptr = new HubWidget( 100, 100 ); ch_env["parent_hub"] = ptr.get(); // create child element ChildsFromXML( i, &ch_env ); if( ptr->ChildrenCount() != 1 ) throw Error("DropDown widget %s must have one and only content.", (*i)._name.c_str()); Widget *content = ptr->FirstChild(); ptr->Retrieve( content ); if ( IWList *p_items = dynamic_cast< IWList *>( content )) { typedef DropButton< ListMenu, RadioLogic > ListMenuButton; ListMenu *lm = new ListMenuButton( style, p_items ); p_items->Items().SetFollowMode( ListLogic::FULL_FOLLOW ); p_items->Items().AllwaysSelected( 1 ); InsertChildWidget( lm, attributes, env ); SetHint( lm, attributes ); return new AnyResource< Widget *>( lm ); } else if ( IWTableList *p_table = dynamic_cast< IWTableList *>( content )) { Share< DataConnector > dataCon = dynamic_cast< DataTableWidget &>( p_table->Table() ) .GetDataConnector(); typedef DropButton< TableMenu, RadioLogic > TableMenuButton; TableMenu *tm = new TableMenuButton( style, p_table, dataCon.GetTarget() ); dynamic_cast< ListLogic &>( p_table->Enumerator() ) .SetFollowMode( ListLogic::FULL_FOLLOW ); dynamic_cast< ListLogic &>( p_table->Enumerator() ) .AllwaysSelected( 1 ); InsertChildWidget( tm, attributes, env ); SetHint( tm, attributes ); return new AnyResource< Widget *>( tm ); } return NULL; }