void tvserviceDestroy() { if (!initialized) return; free(tvstate); vc_tv_unregister_callback(&tvserviceCallback); logInfo(LOG_TVSERVICE, "before vc_vchi_tv_stop\n"); vc_vchi_tv_stop(); logInfo(LOG_TVSERVICE, "afters vc_vchi_tv_stop\n"); }
GLUSvoid _glusDestroyNativeWindow() { if (_nativeWindowCreated) { DISPMANX_UPDATE_HANDLE_T dispmanUpdate; dispmanUpdate = vc_dispmanx_update_start(0); vc_dispmanx_element_remove(dispmanUpdate, _nativeWindow.element); vc_dispmanx_update_submit_sync(dispmanUpdate); _nativeWindowCreated = GLUS_FALSE; } memset(&_nativeWindow, 0, sizeof(_nativeWindow)); if (_nativeDisplay) { vc_dispmanx_display_close(_nativeDisplay); _nativeDisplay = 0; } if (_fullscreen) { vc_tv_register_callback(resizeDone, 0); if (vc_tv_hdmi_power_on_preferred() == 0) { waitResizeDone(); } vc_tv_unregister_callback(resizeDone); _fullscreen = GLUS_FALSE; } SDL_ShowCursor(SDL_ENABLE); SDL_Quit(); bcm_host_deinit(); }
EGLNativeWindowType _glusCreateNativeWindowType(const char* title, const GLUSint width, const GLUSint height, const GLUSboolean fullscreen, const GLUSboolean noResize) { const SDL_VideoInfo* videoInfo; // DISPMANX_UPDATE_HANDLE_T dispmanUpdate; DISPMANX_ELEMENT_HANDLE_T dispmanElement; VC_RECT_T dstRect; VC_RECT_T srcRect; VC_DISPMANX_ALPHA_T dispmanAlpha; int32_t success; int32_t windowWidth; int32_t windowHeight; glusLogPrint(GLUS_LOG_INFO, "Parameters 'title' and 'noResize' are not used"); // Initialize graphics system bcm_host_init(); // Set fullscreen, if wanted if (fullscreen) { const uint32_t MAX_SUPPORTED_MODES = 128; HDMI_RES_GROUP_T group = HDMI_RES_GROUP_DMT; TV_SUPPORTED_MODE_NEW_T supportedModes[MAX_SUPPORTED_MODES]; int32_t i, numberSupportedModes; numberSupportedModes = vc_tv_hdmi_get_supported_modes_new(group, supportedModes, MAX_SUPPORTED_MODES, 0, 0); for (i = 0; i < numberSupportedModes; i++) { if (supportedModes[i].width == (uint32_t)width && supportedModes[i].height == (uint32_t)height && supportedModes[i].frame_rate >= 60) { break; } } if (i == numberSupportedModes) { glusLogPrint(GLUS_LOG_ERROR, "No matching display resolution found: ", width, height); return EGL_NO_SURFACE ; } vc_tv_register_callback(resizeDone, 0); if (vc_tv_hdmi_power_on_explicit_new(group, supportedModes[i].group, supportedModes[i].code) != 0) { vc_tv_unregister_callback(resizeDone); glusLogPrint(GLUS_LOG_ERROR, "Could not switch to full screen: ", width, height); return EGL_NO_SURFACE ; } waitResizeDone(); vc_tv_unregister_callback(resizeDone); windowWidth = width; windowHeight = height; _fullscreen = GLUS_TRUE; } else { windowWidth = width; windowHeight = height; } // _nativeDisplay = vc_dispmanx_display_open(0 /* LCD */); if (!_nativeDisplay) { glusLogPrint(GLUS_LOG_ERROR, "Could not open display"); return EGL_NO_SURFACE ; } // if (SDL_Init(SDL_INIT_VIDEO) != 0) { glusLogPrint(GLUS_LOG_ERROR, "Could not initialize SDL"); return EGL_NO_SURFACE ; } videoInfo = SDL_GetVideoInfo(); if (!videoInfo) { glusLogPrint(GLUS_LOG_ERROR, "Could not get video info for SDL"); return EGL_NO_SURFACE ; } if (!SDL_SetVideoMode(videoInfo->current_w, videoInfo->current_h, videoInfo->vfmt->BitsPerPixel, SDL_HWSURFACE)) { glusLogPrint(GLUS_LOG_ERROR, "Set video mode for SDL failed"); return EGL_NO_SURFACE ; } SDL_ShowCursor(SDL_DISABLE); // dstRect.x = 0; dstRect.y = 0; dstRect.width = windowWidth; dstRect.height = windowHeight; srcRect.x = 0; srcRect.y = 0; srcRect.width = windowWidth << 16; srcRect.height = windowHeight << 16; dispmanAlpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS; dispmanAlpha.mask = 0xFFFFFFFF; dispmanAlpha.opacity = 255; dispmanUpdate = vc_dispmanx_update_start(0); dispmanElement = vc_dispmanx_element_add(dispmanUpdate, _nativeDisplay, 0 /*layer*/, &dstRect, 0 /*src*/, &srcRect, DISPMANX_PROTECTION_NONE, &dispmanAlpha, 0/*clamp*/, 0/*transform*/); success = vc_dispmanx_update_submit_sync(dispmanUpdate); if (!dispmanElement || success < 0) { glusLogPrint(GLUS_LOG_ERROR, "Could not add element"); return EGL_NO_SURFACE ; } _width = windowWidth; _height = windowHeight; _nativeWindow.element = dispmanElement; _nativeWindow.width = windowWidth; _nativeWindow.height = windowHeight; _nativeWindowCreated = GLUS_TRUE; return (EGLNativeWindowType)&_nativeWindow; }