void nuiFontManager::ScanFolders(bool rescanAllFolders /* = false */) { NGL_LOG("font", NGL_LOG_INFO, "Scan font folders (rescanAllFolders: %s)", YESNO(rescanAllFolders)); nuiContextInfo ContextInfo(nuiContextInfo::StandardContext3D); nglWindowInfo Info; Info.Flags = nglWindow::NoBorder | nglWindow::NoResize; Info.Width = 320; Info.Height = 60; Info.Pos = nglWindowInfo::ePosCenter; Info.Title = _T("nui test"); Info.XPos = 0; Info.YPos = 0; #if 0 #ifndef _UIKIT_ gpWin = new nuiMainWindow(ContextInfo, Info); nuiVBox* pBox = new nuiVBox(); pBox->SetPosition(nuiCenter); nuiLabel* pLabel = new nuiLabel(_T("Please wait. Scaning fonts...")); gpFontPathLabel = new nuiLabel(_T("...searching...")); //pLabel->SetTextColor(nuiColor(255, 255, 255)); pBox->AddCell(pLabel, nuiCenter); pBox->AddCell(gpFontPathLabel, nuiCenter); gpWin->AddChild(pBox); gpWin->SetState(nglWindow::eShow); #endif #endif NGL_DEBUG( NGL_LOG("font", NGL_LOG_INFO, "Scan system fonts....\n"); )
ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions options) { for (int i = 0; i < fContexts.count(); ++i) { Context& context = fContexts[i]; if (context.fType == type && context.fOptions == options && !context.fAbandoned) { if (context.fGLContext) { context.fGLContext->makeCurrent(); } return ContextInfo(context.fGrContext, context.fGLContext); } } SkAutoTDelete<GLTestContext> glCtx; sk_sp<GrContext> grCtx; GrBackendContext backendContext = 0; sk_sp<const GrGLInterface> glInterface; #ifdef SK_VULKAN sk_sp<const GrVkBackendContext> vkBackend; #endif GrBackend backend = ContextTypeBackend(type); switch (backend) { case kOpenGL_GrBackend: switch (type) { case kGL_ContextType: glCtx.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); break; case kGLES_ContextType: glCtx.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); break; #if SK_ANGLE # ifdef SK_BUILD_FOR_WIN case kANGLE_ContextType: glCtx.reset(CreateANGLEDirect3DGLTestContext()); break; # endif case kANGLE_GL_ContextType: glCtx.reset(CreateANGLEOpenGLGLTestContext()); break; #endif #if SK_COMMAND_BUFFER case kCommandBuffer_ContextType: glCtx.reset(CommandBufferGLTestContext::Create()); break; #endif #if SK_MESA case kMESA_ContextType: glCtx.reset(CreateMesaGLTestContext()); break; #endif case kNullGL_ContextType: glCtx.reset(CreateNullGLTestContext()); break; case kDebugGL_ContextType: glCtx.reset(CreateDebugGLTestContext()); break; default: return ContextInfo(); } if (nullptr == glCtx.get()) { return ContextInfo(); } glInterface.reset(SkRef(glCtx->gl())); // Block NVPR from non-NVPR types. if (!(kEnableNVPR_ContextOptions & options)) { glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface.get())); if (!glInterface) { return ContextInfo(); } } backendContext = reinterpret_cast<GrBackendContext>(glInterface.get()); glCtx->makeCurrent(); break; #ifdef SK_VULKAN case kVulkan_GrBackend: SkASSERT(kVulkan_ContextType == type); if ((kEnableNVPR_ContextOptions & options) || (kRequireSRGBSupport_ContextOptions & options)) { return ContextInfo(); } vkBackend.reset(GrVkBackendContext::Create()); if (!vkBackend) { return ContextInfo(); } backendContext = reinterpret_cast<GrBackendContext>(vkBackend.get()); // There is some bug (either in Skia or the NV Vulkan driver) where VkDevice // destruction will hang occaisonally. For some reason having an existing GL // context fixes this. if (!fSentinelGLContext) { fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); if (!fSentinelGLContext) { fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); } } break; #endif default: return ContextInfo(); } grCtx.reset(GrContext::Create(backend, backendContext, fGlobalOptions)); if (!grCtx.get()) { return ContextInfo(); } if (kEnableNVPR_ContextOptions & options) { if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { return ContextInfo(); } } if (kRequireSRGBSupport_ContextOptions & options) { if (!grCtx->caps()->srgbSupport()) { return ContextInfo(); } } Context& context = fContexts.push_back(); context.fGLContext = glCtx.release(); context.fGrContext = SkRef(grCtx.get()); context.fType = type; context.fOptions = options; context.fAbandoned = false; return ContextInfo(context.fGrContext, context.fGLContext); }
ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions options) { for (int i = 0; i < fContexts.count(); ++i) { Context& context = fContexts[i]; if (context.fType == type && context.fOptions == options && !context.fAbandoned) { context.fTestContext->makeCurrent(); return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext); } } SkAutoTDelete<TestContext> testCtx; sk_sp<GrContext> grCtx; GrBackendContext backendContext = 0; sk_sp<const GrGLInterface> glInterface; GrBackend backend = ContextTypeBackend(type); switch (backend) { case kOpenGL_GrBackend: { GLTestContext* glCtx; switch (type) { case kGL_ContextType: glCtx = CreatePlatformGLTestContext(kGL_GrGLStandard); break; case kGLES_ContextType: glCtx = CreatePlatformGLTestContext(kGLES_GrGLStandard); break; #if SK_ANGLE # ifdef SK_BUILD_FOR_WIN case kANGLE_ContextType: glCtx = CreateANGLEDirect3DGLTestContext(); break; # endif case kANGLE_GL_ContextType: glCtx = CreateANGLEOpenGLGLTestContext(); break; #endif #if SK_COMMAND_BUFFER case kCommandBuffer_ContextType: glCtx = CommandBufferGLTestContext::Create(); break; #endif #if SK_MESA case kMESA_ContextType: glCtx = CreateMesaGLTestContext(); break; #endif case kNullGL_ContextType: glCtx = CreateNullGLTestContext(kEnableNVPR_ContextOptions & options); break; case kDebugGL_ContextType: glCtx = CreateDebugGLTestContext(); break; default: return ContextInfo(); } if (!glCtx) { return ContextInfo(); } testCtx.reset(glCtx); glInterface.reset(SkRef(glCtx->gl())); // Block NVPR from non-NVPR types. We don't block NVPR from contexts that will use // instanced rendering because that would prevent us from testing mixed samples. if (!((kEnableNVPR_ContextOptions | kUseInstanced_ContextOptions) & options)) { glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface.get())); if (!glInterface) { return ContextInfo(); } } backendContext = reinterpret_cast<GrBackendContext>(glInterface.get()); break; } #ifdef SK_VULKAN case kVulkan_GrBackend: SkASSERT(kVulkan_ContextType == type); if (kEnableNVPR_ContextOptions & options) { return ContextInfo(); } testCtx.reset(CreatePlatformVkTestContext()); if (!testCtx) { return ContextInfo(); } // There is some bug (either in Skia or the NV Vulkan driver) where VkDevice // destruction will hang occaisonally. For some reason having an existing GL // context fixes this. if (!fSentinelGLContext) { fSentinelGLContext.reset(CreatePlatformGLTestContext(kGL_GrGLStandard)); if (!fSentinelGLContext) { fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard)); } } backendContext = testCtx->backendContext(); break; #endif default: return ContextInfo(); } testCtx->makeCurrent(); SkASSERT(testCtx && testCtx->backend() == backend); GrContextOptions grOptions = fGlobalOptions; if (kUseInstanced_ContextOptions & options) { grOptions.fEnableInstancedRendering = true; } grCtx.reset(GrContext::Create(backend, backendContext, grOptions)); if (!grCtx.get()) { return ContextInfo(); } if (kEnableNVPR_ContextOptions & options) { if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { return ContextInfo(); } } if (kUseInstanced_ContextOptions & options) { if (GrCaps::InstancedSupport::kNone == grCtx->caps()->instancedSupport()) { return ContextInfo(); } } if (kRequireSRGBSupport_ContextOptions & options) { if (!grCtx->caps()->srgbSupport()) { return ContextInfo(); } } Context& context = fContexts.push_back(); context.fBackend = backend; context.fTestContext = testCtx.release(); context.fGrContext = SkRef(grCtx.get()); context.fType = type; context.fOptions = options; context.fAbandoned = false; return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext); }
void Application::OnInit() { nuiInit(NULL); uint Width = 0, Height = 0; bool HasSize = false; bool IsFullScreen = false; bool DebugObject = false; bool DebugInfo = false; bool ShowFPS = false; nuiRenderer Renderer = eOpenGL; // nuiRenderer Renderer = eSoftware; // nuiRenderer Renderer = eDirect3D; // Accept NGL default options ParseDefaultArgs(); GetLog().UseConsole(true); GetLog().SetLevel(_T("font"), 100); // Manual if ( (GetArgCount() == 1) && ((!GetArg(0).Compare(_T("-h"))) || (!GetArg(0).Compare(_T("--help")))) ) { NGL_OUT(_T("no params\n")); Quit (0); return; } // Parse args int i = 0; while (i < GetArgCount()) { nglString arg = GetArg(i); if ((!arg.Compare(_T("--size")) || !arg.Compare(_T("-s"))) && ((i+1) < GetArgCount())) { int w, h; std::string str(GetArg(i+1).GetStdString()); sscanf(str.c_str(), "%dx%d", &w, &h); if (w > 0) Width = w; if (h > 0) Height = h; HasSize = true; i++; } else if (!arg.Compare(_T("--showfps")) || !arg.Compare(_T("-fps"))) ShowFPS = true; else if (!arg.Compare(_T("--fullscreen")) || !arg.Compare(_T("-f"))) IsFullScreen = true; else if (!arg.Compare(_T("--debugobject")) || !arg.Compare(_T("-d"))) DebugObject = true; else if (!arg.Compare(_T("--debuginfo")) || !arg.Compare(_T("-i"))) DebugInfo = true; else if (!arg.Compare(_T("--renderer")) || !arg.Compare(_T("-r"))) { arg = GetArg(i+1); if (!arg.Compare(_T("opengl"))) Renderer = eOpenGL; else if (!arg.Compare(_T("direct3d"))) Renderer = eDirect3D; else if (!arg.Compare(_T("software"))) Renderer = eSoftware; i++; } i++; } nuiMainWindow::SetRenderer(Renderer); if (!HasSize) { if (IsFullScreen) { nglVideoMode current_mode; Width = current_mode.GetWidth(); Height = current_mode.GetHeight(); } else { #ifdef NUI_IPHONE Width = 320; Height = 480; #else Width = 800; Height = 600; #endif } } /* Create the nglWindow (and thus a GL context, don't even try to * instantiate the gui (or nglFont) before the nuiWin !) */ nuiContextInfo ContextInfo(nuiContextInfo::StandardContext3D); nglWindowInfo Info; Info.Flags = IsFullScreen ? nglWindow::FullScreen : 0; Info.Width = Width; Info.Height = Height; Info.Pos = nglWindowInfo::ePosCenter; Info.Title = APPLICATION_TITLE; Info.XPos = 0; Info.YPos = 0; mpMainWindow = new MainWindow(ContextInfo,Info, ShowFPS); if ((!mpMainWindow) || (mpMainWindow->GetError())) { if (mpMainWindow) NGL_OUT(_T("Error: cannot create window (%s)\n"), mpMainWindow->GetErrorStr()); Quit (1); return; } mpMainWindow->Acquire(); mpMainWindow->DBG_SetMouseOverInfo(DebugInfo); mpMainWindow->DBG_SetMouseOverObject(DebugObject); mpMainWindow->SetState(nglWindow::eShow); }
void nuiApp::OnInit() { nuiInit(NULL); nuiRenderer Renderer = eOpenGL; // Accept NGL default options ParseDefaultArgs(); uint Width = 0, Height = 0; uint Angle = 0; //Angle = 90; //Angle = 180; Angle = 0; bool HasSize = false; bool IsFullScreen = false; bool DebugObject = false; bool DebugInfo = false; bool ShowFPS = false; bool PartialRedraw = false; // bool PartialRedraw = true; nuiMainWindow::SetRenderer(Renderer); nuiContextInfo ContextInfo(nuiContextInfo::StandardContext3D); ContextInfo.FrameBitsR = 5; ContextInfo.FrameBitsG = 6; ContextInfo.FrameBitsB = 5; ContextInfo.FrameBitsA = 0; ContextInfo.DepthBits = 0; ///< If false partial redraw cannot be achieved ContextInfo.CopyOnSwap = PartialRedraw; nglWindowInfo Info; Info.Flags = IsFullScreen ? nglWindow::FullScreen : 0; Info.Width = Width; Info.Height = Height; Info.Rotate = Angle; Info.Pos = nglWindowInfo::ePosCenter; Info.Title = _T("nuiApp"); Info.XPos = 0; Info.YPos = 0; nuiWin* pWin = new nuiWin(ContextInfo, Info); if ((!pWin) || (pWin->GetError())) { if (pWin) { NGL_OUT(_T("[nuiApp] Error: cannot create window (%s)\n"), pWin->GetErrorStr()); } Quit (1); return; } pWin->SetState(nglWindow::eShow); pWin->EnablePartialRedraw(PartialRedraw); // mpWindow->SetFrameRateLimit(20.f); }