static VALUE rcl_mem_create_image_2d(VALUE mod, VALUE context, VALUE flags, VALUE image_format, VALUE width, VALUE height, VALUE row_pitch, VALUE host_ptr) { EXPECT_RCL_TYPE(context, Context); EXPECT_FIXNUM(flags); EXTRACT_SIZE(width, w); EXTRACT_SIZE(height, h); EXTRACT_SIZE(row_pitch, rp); cl_context cxt = ContextPtr(context); cl_mem_flags mf = FIX2INT(flags); EXTRACT_IMAGE_FORMAT(image_format, imgfmt); EXTRACT_POINTER(host_ptr, hp); cl_int res; cl_mem img = clCreateImage2D(cxt, mf, &imgfmt, w, h, rp, hp, &res); CHECK_AND_RAISE(res); return RMemory(img); }
static VALUE rcl_mem_create_image_3d(VALUE mod, VALUE context, VALUE flags, VALUE image_format, VALUE width, VALUE height, VALUE depth, VALUE row_pitch, VALUE slice_pitch, VALUE host_ptr) { EXPECT_RCL_TYPE(context, Context); EXPECT_FIXNUM(flags); if (CLASS_OF(image_format) != rcl_cImageFormat) { rb_raise(rb_eTypeError, "expected argument 3 is a ImageFormat."); } cl_mem_flags mf = FIX2INT(flags); EXTRACT_SIZE(width, w); EXTRACT_SIZE(height, h); EXTRACT_SIZE(depth, d); EXTRACT_SIZE(row_pitch, rp); EXTRACT_SIZE(slice_pitch, sp); cl_context cxt = ContextPtr(context); EXTRACT_IMAGE_FORMAT(image_format, imgfmt); EXTRACT_POINTER(host_ptr, hp); cl_int res; cl_mem img = clCreateImage3D(cxt, mf, &imgfmt, w, h, d, rp, sp, hp, &res); CHECK_AND_RAISE(res); return RMemory(img); }
ContextPtr EglDisplay::getContext(EGLContext ctx) const { emugl::Mutex::AutoLock mutex(m_lock); /* ctx is "key" in map<unsigned int, ContextPtr>. */ unsigned int hndl = SafeUIntFromPointer(ctx); ContextsHndlMap::const_iterator it = m_contexts.find(hndl); return it != m_contexts.end() ? (*it).second : ContextPtr(NULL); }
ContextPtr createContext(int clDeviceType, cl::Platform platform) { if (clDeviceType == CL_DEVICE_TYPE_GPU) return createGpuContext(platform); else if (clDeviceType == CL_DEVICE_TYPE_CPU) return createCpuContext(platform); assert(!"Unhandled CL_DEVICE_TYPE"); return ContextPtr(); }
P2pNode::ContextPtr P2pNode::tryToConnectPeer(const NetworkAddress& address) { try { TcpConnector connector(m_dispatcher); TcpConnection tcpConnection; doWithTimeoutAndThrow(m_dispatcher, m_cfg.getConnectTimeout(), [&] { tcpConnection = connector.connect( Ipv4Address(Common::ipAddressToString(address.ip)), static_cast<uint16_t>(address.port)); }); logger(DEBUGGING) << "connection established to " << address; return ContextPtr(new P2pContext(m_dispatcher, std::move(tcpConnection), false, address, m_cfg.getTimedSyncInterval(), getGenesisPayload())); } catch (std::exception& e) { logger(DEBUGGING) << "Connection to " << address << " failed: " << e.what(); } return ContextPtr(); }
ContextPtr EglDisplay::getContext(EGLContext ctx) { android::Mutex::Autolock mutex(m_lock); /* ctx is "key" in map<unsigned int, ContextPtr>. In 64-bit the upper 32-bit should be all zero. Assert for that. */ uintptr_t hndlptr = (uintptr_t)ctx; unsigned int hndl = (unsigned int)hndlptr; assert(sizeof(hndl) == sizeof(hndlptr) || hndl == hndlptr); ContextsHndlMap::iterator it = m_contexts.find(hndl); return it != m_contexts.end() ? (*it).second : ContextPtr(NULL); }
void async_set() { for (int i = 0; i < MAX_USER_NUM; ++ i) { std::ostringstream oss; oss << "user:"******"fuckyou.......................!"; myredis::async_call(new myredis::Set(key, value), ContextPtr()); } }
static VALUE rcl_mem_create_from_gl_buffer(VALUE self, VALUE context, VALUE flags, VALUE bufobj) { EXPECT_RCL_TYPE(context, Context); EXPECT_FIXNUM(flags); EXPECT_FIXNUM(bufobj); cl_context cxt = ContextPtr(context); cl_mem_flags mf = FIX2INT(flags); cl_GLuint glbuf = FIX2UINT(bufobj); cl_int res; cl_mem mem = clCreateFromGLBuffer(cxt, mf, glbuf, &res); CHECK_AND_RAISE(res); return RMemory(mem); }
void P2pNode::acceptLoop() { while (!m_stopRequested) { try { auto connection = m_listener.accept(); auto ctx = new P2pContext(m_dispatcher, std::move(connection), true, getRemoteAddress(connection), m_cfg.getTimedSyncInterval(), getGenesisPayload()); logger(INFO) << "Incoming connection from " << ctx->getRemoteAddress(); workingContextGroup.spawn([this, ctx] { preprocessIncomingConnection(ContextPtr(ctx)); }); } catch (InterruptedException&) { break; } catch (const std::exception& e) { logger(WARNING) << "Exception in acceptLoop: " << e.what(); } } logger(DEBUGGING) << "acceptLoop finished"; }
void EglDisplayImpl::Initialize() { Mutex::Autolock mutex(&lock_); if (initialized_) { return; } window_ = Native::CreateNativeWindow(); LOG_ALWAYS_FATAL_IF(!window_, "Could not create native window."); EGLConfig cfg = NULL; for (ConfigSet::iterator it = configs_.begin(); it != configs_.end(); ++it) { const EGLint r = it->GetValue(EGL_RED_SIZE); const EGLint g = it->GetValue(EGL_GREEN_SIZE); const EGLint b = it->GetValue(EGL_BLUE_SIZE); if (r > 0 && g > 0 && b > 0) { cfg = it->GetKey(); break; } } EGLint err = 0; global_context_ = EglContextImpl::Create(kDefaultDisplay, cfg, NULL, 2, &err); // Bind the window surface here in order for the compositor to be associated // with the correct context. (The compositor associates itself to the first // surface that is bound.) ContextPtr ctx = contexts_.Get(global_context_); Native::BindNativeWindow(window_, ctx->GetNativeContext()); // Force the GlesContext owned by the global context to be initialized at // least once. EglThreadInfo& info = EglThreadInfo::GetInstance(); info.SetCurrentContext(ctx); ctx->GetGlesContext()->OnMakeCurrent(); info.SetCurrentContext(ContextPtr()); initialized_ = true; }
/* * call-seq: * Memory.create_buffer(aContext, CL_MEM_FLAG_READ_WRITE, 0, aPointer) */ static VALUE rcl_mem_create_buffer(VALUE mod, VALUE context, VALUE flags, VALUE size, VALUE host_ptr) { EXPECT_RCL_TYPE(context, Context); EXPECT_FIXNUM(flags); if (!NIL_P(host_ptr)) EXPECT_RCL_TYPE(host_ptr, Pointer); cl_context cxt = ContextPtr(context); cl_mem_flags mf = FIX2INT(flags); EXTRACT_SIZE(size, sz); EXTRACT_POINTER(host_ptr, hp); if (NULL != hp && sz == 0) { sz = FIX2UINT(rb_funcall(host_ptr, rb_intern("byte_size"), 0)); } cl_int res; cl_mem mem = clCreateBuffer(cxt, mf, sz, hp, &res); CHECK_AND_RAISE(res); return RMemory(mem); }
EGLint EglDisplayImpl::MakeCurrent(EGLContext egl_ctx, EGLSurface egl_draw, EGLSurface egl_read) { if (egl_read != egl_draw) { LOG_ALWAYS_FATAL("Read and draw surfaces must be the same."); return EGL_BAD_MATCH; } ContextPtr ctx = contexts_.Get(egl_ctx); SurfacePtr sfc = surfaces_.Get(egl_draw); bool release = ctx == NULL && sfc == NULL; // If a context is being set, then a surface must be set. Similarly, if a // context is being cleared, the surface must be cleared. Any other // combination is an error. const bool invalid_surface = ctx != NULL ? sfc == NULL : sfc != NULL; if (!release && invalid_surface) { return EGL_BAD_MATCH; } EglThreadInfo& info = EglThreadInfo::GetInstance(); ContextPtr prev_ctx = info.GetCurrentContext(); SurfacePtr prev_sfc = prev_ctx != NULL ? prev_ctx->GetSurface() : SurfacePtr(); if (release) { if (prev_ctx != NULL) { prev_ctx->Flush(); info.SetCurrentContext(ContextPtr()); } } else { if (ctx == NULL) { return EGL_BAD_CONTEXT; } if (ctx->config != sfc->config) { return EGL_BAD_MATCH; } if (ctx != NULL && prev_ctx != NULL) { if (ctx == prev_ctx) { if (sfc == prev_sfc) { // Reassigning the same context and surface. return EGL_SUCCESS; } } else { // Make sure to clear the previous context. release = true; } } if (prev_ctx != NULL) { prev_ctx->Flush(); } if (!ctx->SetCurrent()) { return EGL_BAD_ACCESS; } info.SetCurrentContext(ctx); ctx->SetSurface(sfc); } if (prev_ctx != NULL && release) { prev_ctx->ClearCurrent(); prev_ctx->ClearSurface(); } return EGL_SUCCESS; }
const ContextPtr Window::getContext() const { return ContextPtr(m_context, nullptr, true, &m_context); }
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context) { VALIDATE_DISPLAY(display); bool releaseContext = EglValidate::releaseContext(context, read, draw); if(!releaseContext && EglValidate::badContextMatch(context, read, draw)) { RETURN_ERROR(EGL_FALSE, EGL_BAD_MATCH); } ThreadInfo* thread = getThreadInfo(); ContextPtr prevCtx = thread->eglContext; if(releaseContext) { //releasing current context if(prevCtx.Ptr()) { g_eglInfo->getIface(prevCtx->version())->flush(); if(!dpy->nativeType()->makeCurrent(NULL,NULL,NULL)) { RETURN_ERROR(EGL_FALSE,EGL_BAD_ACCESS); } thread->updateInfo(ContextPtr(NULL),dpy,NULL,ShareGroupPtr(NULL),dpy->getManager(prevCtx->version())); } } else { //assining new context VALIDATE_CONTEXT(context); VALIDATE_SURFACE(draw,newDrawSrfc); VALIDATE_SURFACE(read,newReadSrfc); EglSurface* newDrawPtr = newDrawSrfc.Ptr(); EglSurface* newReadPtr = newReadSrfc.Ptr(); ContextPtr newCtx = ctx; if (newCtx.Ptr() && prevCtx.Ptr()) { if (newCtx.Ptr() == prevCtx.Ptr()) { if (newDrawPtr == prevCtx->draw().Ptr() && newReadPtr == prevCtx->read().Ptr()) { // nothing to do return EGL_TRUE; } } else { // Make sure previous context is detached from surfaces releaseContext = true; } } //surfaces compatibility check if(!((*ctx->getConfig()).compatibleWith((*newDrawPtr->getConfig()))) || !((*ctx->getConfig()).compatibleWith((*newReadPtr->getConfig())))) { RETURN_ERROR(EGL_FALSE,EGL_BAD_MATCH); } EglOS::Display* nativeDisplay = dpy->nativeType(); EglOS::Surface* nativeRead = newReadPtr->native(); EglOS::Surface* nativeDraw = newDrawPtr->native(); //checking native window validity if(newReadPtr->type() == EglSurface::WINDOW && !nativeDisplay->isValidNativeWin(nativeRead)) { RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW); } if(newDrawPtr->type() == EglSurface::WINDOW && !nativeDisplay->isValidNativeWin(nativeDraw)) { RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW); } if(prevCtx.Ptr()) { g_eglInfo->getIface(prevCtx->version())->flush(); } if (!dpy->nativeType()->makeCurrent( newReadPtr->native(), newDrawPtr->native(), newCtx->nativeType())) { RETURN_ERROR(EGL_FALSE,EGL_BAD_ACCESS); } //TODO: handle the following errors // EGL_BAD_CURRENT_SURFACE , EGL_CONTEXT_LOST , EGL_BAD_ACCESS thread->updateInfo(newCtx,dpy,newCtx->getGlesContext(),newCtx->getShareGroup(),dpy->getManager(newCtx->version())); newCtx->setSurfaces(newReadSrfc,newDrawSrfc); g_eglInfo->getIface(newCtx->version())->initContext(newCtx->getGlesContext(),newCtx->getShareGroup()); // Initialize the GLES extension function table used in // eglGetProcAddress for the context's GLES version if not // yet initialized. We initialize it here to make sure we call the // GLES getProcAddress after when a context is bound. g_eglInfo->initClientExtFuncTable(newCtx->version()); } // release previous context surface binding if(prevCtx.Ptr() && releaseContext) { prevCtx->setSurfaces(SurfacePtr(NULL),SurfacePtr(NULL)); } return EGL_TRUE; }