void detachEGLImage(unsigned int imageId) { ThreadInfo* thread = getThreadInfo(); ContextPtr ctx = thread->eglContext; if (ctx.Ptr()) { ctx->detachImage(imageId); } }
ConstPathMatcherDataPtr ScenePlug::set( const IECore::InternedString &setName ) const { ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); tmpContext->set( setNameContextName, setName ); removeNonGlobalContextVariables( tmpContext.get() ); Context::Scope scopedContext( tmpContext.get() ); return setPlug()->getValue(); }
IECore::MurmurHash ScenePlug::objectHash( const ScenePath &scenePath ) const { ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); tmpContext->set( scenePathContextName, scenePath ); Context::Scope scopedContext( tmpContext.get() ); return objectPlug()->hash(); }
IECore::MurmurHash ImagePlug::channelDataHash( const std::string &channelName, const Imath::V2i &tile ) const { ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); tmpContext->set( ImagePlug::channelNameContextName, channelName ); tmpContext->set( ImagePlug::tileOriginContextName, tile ); Context::Scope scopedContext( tmpContext.get() ); return channelDataPlug()->hash(); }
// Get the current rendering context. EGLContext eglGetCurrentContext() { EGL_API_ENTRY(""); ContextPtr context = GetContext(); if (context == NULL) { return EGL_NO_CONTEXT; } return context->GetKey(); }
IECore::MurmurHash ScenePlug::setHash( const IECore::InternedString &setName ) const { ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); tmpContext->set( setNameContextName, setName ); removeNonGlobalContextVariables( tmpContext.get() ); Context::Scope scopedContext( tmpContext.get() ); return setPlug()->hash(); }
void CodeGenerator::generateJSServerImp(const ContextPtr &cPtr) { string sFileName = TC_File::excludeFileExt(_sToPath + TC_File::extractFileName(cPtr->getFileName())) + "Imp.js"; if (TC_File::isFileExist(sFileName)) { return ; } ostringstream str; str << printHeaderRemark("Imp"); str << "\"use strict\";" << endl << endl; vector<NamespacePtr> namespaces = cPtr->getNamespaces(); set<string> setNamespace; for(size_t i = 0; i < namespaces.size(); i++) { if (setNamespace.count(namespaces[i]->getId()) != 0) { continue; } setNamespace.insert(namespaces[i]->getId()); str << "var " << namespaces[i]->getId() << " = require(\"./" << TC_File::excludeFileExt(TC_File::extractFileName(cPtr->getFileName())) << ".js\")." << namespaces[i]->getId() << ";" << endl; str << "module.exports." << namespaces[i]->getId() << " = " << namespaces[i]->getId() << ";" << endl; } str << endl; set<string> setInterface; for(size_t i = 0; i < namespaces.size(); i++) { vector<InterfacePtr> & is = namespaces[i]->getAllInterfacePtr(); for (size_t ii = 0; ii < is.size(); ii++) { if (setInterface.count(namespaces[i]->getId() + "::" + is[ii]->getId()) != 0) { continue; } setInterface.insert(namespaces[i]->getId() + "::" + is[ii]->getId()); str << namespaces[i]->getId() << "." << is[ii]->getId() << "Imp.prototype.initialize = function () {" << endl; INC_TAB; str << TAB << "//TODO::" << endl; DEL_TAB; str << "};" << endl << endl; } } for(size_t i = 0; i < namespaces.size(); i++) { str << generateJSServerImp(cPtr, namespaces[i]); } TC_File::makeDirRecursive(_sToPath, 0755); makeUTF8File(sFileName, str.str()); }
void ImageReader::hashMaskedOutput( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h, bool alwaysClampToFrame ) const { ContextPtr maskedContext = NULL; if( !computeFrameMask( context, maskedContext ) || alwaysClampToFrame ) { Context::Scope scope( maskedContext.get() ); h = intermediateImagePlug()->getChild<ValuePlug>( output->getName() )->hash(); } }
ContextPtr CreateCudaDeviceStream(int argc, char** argv, bool printInfo) { int ordinal = 0; if(argc >= 2 && !sscanf(argv[1], "%d", &ordinal)) { fprintf(stderr, "INVALID COMMAND LINE ARGUMENT - NOT A CUDA ORDINAL\n"); exit(0); } ContextPtr context = CreateCudaDeviceStream(ordinal); if(printInfo) printf("%s", context->DeviceString().c_str()); return context; }
void ColorProcessor::hashColorData( const Gaffer::Context *context, IECore::MurmurHash &h ) const { ContextPtr tmpContext = new Context( *context, Context::Borrowed ); Context::Scope scopedContext( tmpContext.get() ); tmpContext->set( ImagePlug::channelNameContextName, string( "R" ) ); inPlug()->channelDataPlug()->hash( h ); tmpContext->set( ImagePlug::channelNameContextName, string( "G" ) ); inPlug()->channelDataPlug()->hash( h ); tmpContext->set( ImagePlug::channelNameContextName, string( "B" ) ); inPlug()->channelDataPlug()->hash( h ); }
void ExecutableNode::executeSequence( const std::vector<float> &frames ) const { ContextPtr context = new Context( *Context::current(), Context::Borrowed ); Context::Scope scopedContext( context.get() ); for ( std::vector<float>::const_iterator it = frames.begin(); it != frames.end(); ++it ) { context->setFrame( *it ); execute(); } }
bool AnyQuantifier::Calc( ContextPtr context ) { for (ValueSet::Iterator it = mValues->Begin(); it != mValues->End(); ++it) { context->PushParam(mIdentifier, *it); bool result = mTerm->Calc(context); context->PopParam(mIdentifier); if (!result) return false; } return true; }
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay display, EGLConfig config, EGLContext share_context, const EGLint *attrib_list) { VALIDATE_DISPLAY_RETURN(display,EGL_NO_CONTEXT); VALIDATE_CONFIG_RETURN(config,EGL_NO_CONTEXT); GLESVersion version = GLES_1_1; if(!EglValidate::noAttribs(attrib_list)) { int i = 0; while(attrib_list[i] != EGL_NONE) { switch(attrib_list[i]) { case EGL_CONTEXT_CLIENT_VERSION: if(attrib_list[i+1] == 2) { version = GLES_2_0; } else { version = GLES_1_1; } break; default: RETURN_ERROR(EGL_NO_CONTEXT,EGL_BAD_ATTRIBUTE); } i+=2; } } const GLESiface* iface = g_eglInfo->getIface(version); GLEScontext* glesCtx = NULL; if(iface) { glesCtx = iface->createGLESContext(); } else { // there is no interface for this gles version RETURN_ERROR(EGL_NO_CONTEXT,EGL_BAD_ATTRIBUTE); } ContextPtr sharedCtxPtr; if(share_context != EGL_NO_CONTEXT) { sharedCtxPtr = dpy->getContext(share_context); if(!sharedCtxPtr.Ptr()) { RETURN_ERROR(EGL_NO_CONTEXT,EGL_BAD_CONTEXT); } } EglOS::Context* globalSharedContext = dpy->getGlobalSharedContext(); EglOS::Context* nativeContext = dpy->nativeType()->createContext( cfg->nativeFormat(), globalSharedContext); if(nativeContext) { ContextPtr ctx(new EglContext(dpy, nativeContext,sharedCtxPtr,cfg,glesCtx,version,dpy->getManager(version))); return dpy->addContext(ctx); } else { iface->deleteGLESContext(glesCtx); } return EGL_NO_CONTEXT; }
void ImageReader::computeMaskedOutput( Gaffer::ValuePlug *output, const Gaffer::Context *context, bool alwaysClampToFrame ) const { ContextPtr maskedContext = NULL; bool blackOutside = computeFrameMask( context, maskedContext ); if( blackOutside && !alwaysClampToFrame ) { output->setToDefault(); return; } Context::Scope scope( maskedContext.get() ); output->setFrom( intermediateImagePlug()->getChild<ValuePlug>( output->getName() ) ); }
void Unpremultiply::hashChannelData( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const { std::string alphaChannel = alphaChannelPlug()->getValue(); ChannelDataProcessor::hashChannelData( output, context, h ); inPlug()->channelDataPlug()->hash( h ); ContextPtr tmpContext = new Context( *context, Context::Borrowed ); tmpContext->set( ImagePlug::channelNameContextName, alphaChannel ); Context::Scope scopedContext( tmpContext.get() ); inPlug()->channelDataPlug()->hash( h ); }
/************************** KHR IMAGE *************************************************************/ EglImage *attachEGLImage(unsigned int imageId) { ThreadInfo* thread = getThreadInfo(); EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); ContextPtr ctx = thread->eglContext; if (ctx.Ptr()) { ImagePtr img = dpy->getImage(reinterpret_cast<EGLImageKHR>(imageId)); if(img.Ptr()) { ctx->attachImage(imageId,img); return img.Ptr(); } } return NULL; }
IECore::ConstFloatVectorDataPtr ImagePlug::channelData( const std::string &channelName, const Imath::V2i &tile ) const { if( direction()==In && !getInput<Plug>() ) { return channelDataPlug()->defaultValue(); } ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); tmpContext->set( ImagePlug::channelNameContextName, channelName ); tmpContext->set( ImagePlug::tileOriginContextName, tile ); Context::Scope scopedContext( tmpContext.get() ); return channelDataPlug()->getValue(); }
ValueSetPtr ExtQuntifier::Subset( std::string id, ValueSetPtr values, AtomPtr term, ContextPtr context) { ValueSetPtr subSet(new ValueSet()); for (ValueSet::Iterator it = values->Begin(); it != values->End(); ++it) { context->PushParam(id, *it); bool result = term->Calc(context); context->PopParam(id); if (result) subSet->AddValue(*it); } return subSet; }
void OSLImage::hashChannelNames( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const { ImageProcessor::hashChannelNames( output, context, h ); inPlug()->channelNamesPlug()->hash( h ); const Box2i dataWindow = inPlug()->dataWindowPlug()->getValue(); if( !dataWindow.isEmpty() ) { ContextPtr c = new Context( *context, Context::Borrowed ); c->set( ImagePlug::tileOriginContextName, ImagePlug::tileOrigin( dataWindow.min ) ); Context::Scope s( c.get() ); shadingPlug()->hash( h ); } }
EglContext::EglContext(EGLNativeContextType context,ContextPtr shared_context, EglConfig* config,GLEScontext* glesCtx,GLESVersion ver,ObjectNameManager* mngr): m_native(context), m_config(config), m_glesContext(glesCtx), m_read(NULL), m_draw(NULL), m_destroy(false), m_version(ver) { m_shareGroup = shared_context.Ptr()? mngr->attachShareGroup(context,shared_context.Ptr()->getShareGroup().Ptr()): mngr->createShareGroup(context); m_hndl = ++s_nextContextHndl; }
EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void) { ThreadInfo* thread = getThreadInfo(); EglDisplay* dpy = static_cast<EglDisplay*>(thread->eglDisplay); ContextPtr ctx = thread->eglContext; if(dpy && ctx.Ptr()){ // This double check is required because a context might still be current after it is destroyed - in which case // its handle should be invalid, that is EGL_NO_CONTEXT should be returned even though the context is current EGLContext c = (EGLContext)SafePointerFromUInt(ctx->getHndl()); if(dpy->getContext(c).Ptr()) { return c; } } return EGL_NO_CONTEXT; }
void Group::hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const { SceneProcessor::hash( output, context, h ); if( output == mappingPlug() ) { ContextPtr tmpContext = new Context( *context, Context::Borrowed ); tmpContext->set( ScenePlug::scenePathContextName, ScenePath() ); Context::Scope scopedContext( tmpContext.get() ); for( vector<ScenePlugPtr>::const_iterator it = m_inPlugs.inputs().begin(), eIt = m_inPlugs.inputs().end(); it!=eIt; it++ ) { (*it)->childNamesPlug()->hash( h ); } } }
void Group::hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const { SceneProcessor::hash( output, context, h ); if( output == mappingPlug() ) { ContextPtr tmpContext = new Context( *context, Context::Borrowed ); tmpContext->set( ScenePlug::scenePathContextName, ScenePath() ); Context::Scope scopedContext( tmpContext.get() ); for( ScenePlugIterator it( inPlugs() ); it != it.end(); ++it ) { (*it)->childNamesPlug()->hash( h ); } } }
int main(int argc, char** argv) { cuInit(0); DevicePtr device; CUresult result = CreateCuDevice(0, &device); ContextPtr context; result = CreateCuContext(device, 0, &context); std::auto_ptr<MaxIndexEngine> engine; result = CreateMaxIndexEngine("../../src/maxindex/maxindex.cubin", &engine); if(CUDA_SUCCESS != result) { printf("Could not create max index engine.\n"); return 0; } // Search through 5 million elements. const int NumElements = 5000000; std::vector<float> data(NumElements); std::tr1::uniform_real<float> r(-1e9, 1e9); for(int i(0); i < NumElements; ++i) data[i] = r(mt19937); // Use CPU to find the max element and index. float maxX = -1e37f; int maxIndex = 0; for(int i(0); i < NumElements; ++i) if(data[i] > maxX) { maxX = data[i]; maxIndex = i; } printf("CPU says max x = %f, max index = %d.\n", maxX, maxIndex); // Use GPU to find the max element and index. DeviceMemPtr deviceData; context->MemAlloc(data, &deviceData); result = FindGlobalMax(engine.get(), deviceData->Handle(), NumElements, &maxX, &maxIndex); if(CUDA_SUCCESS != result) { printf("Failure running max index kernel.\n"); return 0; } printf("GPU says max x = %f, max index = %d.\n", maxX, maxIndex); }
int console_filter_selection(ContextPtr env, char *cmd) { if(!cmd) return 0; LinkList<Filter> &list = env->getFilters(); LinkList<Filter>::iterator it = std::find_if(list.begin(), list.end(), [&](FilterPtr filter) { return filter->getName() == cmd; }); if(it == list.end()) { ::error("filter not found: %s", cmd); return 0; } FilterPtr filt = *it; ViewPortPtr screen = getSelectedScreen(); if(!screen) { ::error("no screen currently selected"); return 0; } LayerPtr lay = getSelectedLayer(); if(!lay) { ::error("no layer selected for effect %s", filt->getName().c_str()); return 0; } if(!filt->new_instance()->apply(lay)) { ::error("error applying filter %s on layer %s", filt->getName().c_str(), lay->getName().c_str()); return 0; } // select automatically the new filter // lay->filters.sel(0); // ff->sel(true); return 1; }
// Get the surface associated with the current rendering context. EGLSurface eglGetCurrentSurface(EGLint readdraw) { EGL_API_ENTRY("0x%x", readdraw); if (readdraw != EGL_READ && readdraw != EGL_DRAW) { SetError(EGL_BAD_PARAMETER); return EGL_NO_SURFACE; } ContextPtr context = GetContext(); if (context == NULL) { return EGL_NO_SURFACE; } SurfacePtr surface = context->GetSurface(); if (surface == NULL) { return EGL_NO_SURFACE; } return surface->GetKey(); }
Imath::M44f ScenePlug::fullTransform( const ScenePath &scenePath ) const { ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); Context::Scope scopedContext( tmpContext.get() ); Imath::M44f result; ScenePath path( scenePath ); while( path.size() ) { tmpContext->set( scenePathContextName, path ); result = result * transformPlug()->getValue(); path.pop_back(); } return result; }
IECore::MurmurHash ScenePlug::fullAttributesHash( const ScenePath &scenePath ) const { ContextPtr tmpContext = new Context( *Context::current(), Context::Borrowed ); Context::Scope scopedContext( tmpContext.get() ); IECore::MurmurHash result; ScenePath path( scenePath ); while( path.size() ) { tmpContext->set( scenePathContextName, path ); attributesPlug()->hash( result ); path.pop_back(); } return result; }
int console_generator_selection(ContextPtr env, char *cmd) { GeneratorLayerPtr tmp = MakeShared<GeneratorLayer>(); if(!tmp) return 0; ViewPortPtr screen = getSelectedScreen(); if(!screen) { ::error("no screen currently selected"); return 0; } const Geometry &geo = screen->getGeometry(); if(!tmp->init(geo.getSize().x(), geo.getSize().y(), geo.getBpp())) { error("can't initialize generator layer"); return 0; } // this is something specific to the generator layer // it needs this from the environment.. tmp->register_generators(&env->getGenerators()); if(!tmp->open(cmd)) { error("generator %s is not found", cmd); return 0; } screen->add_layer(tmp); notice("generator %s successfully created", tmp->getName().c_str()); return 1; }
IECore::MurmurHash ScenePlug::fullTransformHash( const ScenePath &scenePath ) const { ContextPtr tmpContext = new Context( *Context::current() ); Context::Scope scopedContext( tmpContext ); IECore::MurmurHash result; ScenePath path( scenePath ); while( path.size() ) { tmpContext->set( scenePathContextName, path ); transformPlug()->hash( result ); path.pop_back(); } return result; }