void XCompcapMain::render(gs_effect_t *effect) { if (!p->win) return; PLock lock(&p->lock, true); effect = obs_get_base_effect(OBS_EFFECT_OPAQUE); if (!lock.isLocked() || !p->tex) return; gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image"); gs_effect_set_texture(image, p->tex); while (gs_effect_loop(effect, "Draw")) { gs_draw_sprite(p->tex, 0, 0, 0); } if (p->cursor && p->gltex && p->show_cursor && !p->cursor_outside) { effect = obs_get_base_effect(OBS_EFFECT_DEFAULT); while (gs_effect_loop(effect, "Draw")) { xcursor_render(p->cursor); } } }
static void duplicator_capture_render(void *data, gs_effect_t *effect) { struct duplicator_capture *capture = data; gs_texture_t *texture; int rot; if (!capture->duplicator) return; texture = gs_duplicator_get_texture(capture->duplicator); if (!texture) return; effect = obs_get_base_effect(OBS_EFFECT_OPAQUE); rot = capture->rot; while (gs_effect_loop(effect, "Draw")) { if (rot != 0) { float x = 0.0f; float y = 0.0f; switch (rot) { case 90: x = (float)capture->height; break; case 180: x = (float)capture->width; y = (float)capture->height; break; case 270: y = (float)capture->width; break; } gs_matrix_push(); gs_matrix_translate3f(x, y, 0.0f); gs_matrix_rotaa4f(0.0f, 0.0f, 1.0f, RAD((float)rot)); } obs_source_draw(texture, 0, 0, 0, 0, false); if (rot != 0) gs_matrix_pop(); } if (capture->capture_cursor) { effect = obs_get_base_effect(OBS_EFFECT_DEFAULT); while (gs_effect_loop(effect, "Draw")) { draw_cursor(capture); } } }
static void scale_filter_tick(void *data, float seconds) { struct scale_filter_data *filter = data; enum obs_base_effect type; obs_source_t *target; bool lower_than_2x; double cx_f; double cy_f; int cx; int cy; if (filter->base_canvas_resolution) { struct obs_video_info ovi; obs_get_video_info(&ovi); filter->cx_in = ovi.base_width; filter->cy_in = ovi.base_height; } target = obs_filter_get_target(filter->context); filter->cx_out = 0; filter->cy_out = 0; filter->target_valid = !!target; if (!filter->target_valid) return; cx = obs_source_get_base_width(target); cy = obs_source_get_base_height(target); if (!cx || !cy) { filter->target_valid = false; return; } filter->cx_out = cx; filter->cy_out = cy; if (!filter->valid) return; /* ------------------------- */ cx_f = (double)cx; cy_f = (double)cy; double old_aspect = cx_f / cy_f; double new_aspect = (double)filter->cx_in / (double)filter->cy_in; if (filter->aspect_ratio_only) { if (fabs(old_aspect - new_aspect) <= EPSILON) { filter->target_valid = false; return; } else { if (new_aspect > old_aspect) { filter->cx_out = (int)(cy_f * new_aspect); filter->cy_out = cy; } else { filter->cx_out = cx; filter->cy_out = (int)(cx_f / new_aspect); } } } else { filter->cx_out = filter->cx_in; filter->cy_out = filter->cy_in; } vec2_set(&filter->dimension_i, 1.0f / (float)cx, 1.0f / (float)cy); if (filter->undistort) { filter->undistort_factor = new_aspect / old_aspect; } else { filter->undistort_factor = 1.0; } /* ------------------------- */ lower_than_2x = filter->cx_out < cx / 2 || filter->cy_out < cy / 2; if (lower_than_2x && filter->sampling != OBS_SCALE_POINT) { type = OBS_EFFECT_BILINEAR_LOWRES; } else { switch (filter->sampling) { default: case OBS_SCALE_POINT: case OBS_SCALE_BILINEAR: type = OBS_EFFECT_DEFAULT; break; case OBS_SCALE_BICUBIC: type = OBS_EFFECT_BICUBIC; break; case OBS_SCALE_LANCZOS: type = OBS_EFFECT_LANCZOS; break; } } filter->effect = obs_get_base_effect(type); filter->image_param = gs_effect_get_param_by_name(filter->effect, "image"); if (type != OBS_EFFECT_DEFAULT) { filter->dimension_param = gs_effect_get_param_by_name( filter->effect, "base_dimension_i"); } else { filter->dimension_param = NULL; } if (type == OBS_EFFECT_BICUBIC || type == OBS_EFFECT_LANCZOS) { filter->undistort_factor_param = gs_effect_get_param_by_name( filter->effect, "undistort_factor"); } else { filter->undistort_factor_param = NULL; } UNUSED_PARAMETER(seconds); }
OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor, QString title, ProjectorType type_) : OBSQTDisplay (widget, Qt::Window), source (source_), removedSignal (obs_source_get_signal_handler(source), "remove", OBSSourceRemoved, this) { projectorTitle = std::move(title); savedMonitor = monitor; isWindow = savedMonitor < 0; type = type_; if (isWindow) { setWindowIcon(QIcon::fromTheme("obs", QIcon(":/res/images/obs.png"))); UpdateProjectorTitle(projectorTitle); windowedProjectors.push_back(this); resize(480, 270); } else { setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); QScreen *screen = QGuiApplication::screens()[savedMonitor]; setGeometry(screen->geometry()); QAction *action = new QAction(this); action->setShortcut(Qt::Key_Escape); addAction(action); connect(action, SIGNAL(triggered()), this, SLOT(EscapeTriggered())); } SetAlwaysOnTop(this, config_get_bool(GetGlobalConfig(), "BasicWindow", "ProjectorAlwaysOnTop")); setAttribute(Qt::WA_DeleteOnClose, true); //disable application quit when last window closed setAttribute(Qt::WA_QuitOnClose, false); installEventFilter(CreateShortcutFilter()); auto addDrawCallback = [this] () { bool isMultiview = type == ProjectorType::Multiview; obs_display_add_draw_callback(GetDisplay(), isMultiview ? OBSRenderMultiview : OBSRender, this); obs_display_set_background_color(GetDisplay(), 0x000000); }; connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback); bool hideCursor = config_get_bool(GetGlobalConfig(), "BasicWindow", "HideProjectorCursor"); if (hideCursor && !isWindow) { QPixmap empty(16, 16); empty.fill(Qt::transparent); setCursor(QCursor(empty)); } if (type == ProjectorType::Multiview) { obs_enter_graphics(); // All essential action should be placed inside this area gs_render_start(true); gs_vertex2f(actionSafePercentage, actionSafePercentage); gs_vertex2f(actionSafePercentage, 1 - actionSafePercentage); gs_vertex2f(1 - actionSafePercentage, 1 - actionSafePercentage); gs_vertex2f(1 - actionSafePercentage, actionSafePercentage); gs_vertex2f(actionSafePercentage, actionSafePercentage); actionSafeMargin = gs_render_save(); // All graphics should be placed inside this area gs_render_start(true); gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage); gs_vertex2f(graphicsSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(1 - graphicsSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(1 - graphicsSafePercentage, graphicsSafePercentage); gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage); graphicsSafeMargin = gs_render_save(); // 4:3 safe area for widescreen gs_render_start(true); gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage); gs_vertex2f(1 - fourByThreeSafePercentage, graphicsSafePercentage); gs_vertex2f(1 - fourByThreeSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(fourByThreeSafePercentage, 1 - graphicsSafePercentage); gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage); fourByThreeSafeMargin = gs_render_save(); gs_render_start(true); gs_vertex2f(0.0f, 0.5f); gs_vertex2f(lineLength, 0.5f); leftLine = gs_render_save(); gs_render_start(true); gs_vertex2f(0.5f, 0.0f); gs_vertex2f(0.5f, lineLength); topLine = gs_render_save(); gs_render_start(true); gs_vertex2f(1.0f, 0.5f); gs_vertex2f(1 - lineLength, 0.5f); rightLine = gs_render_save(); obs_leave_graphics(); solid = obs_get_base_effect(OBS_EFFECT_SOLID); color = gs_effect_get_param_by_name(solid, "color"); UpdateMultiview(); multiviewProjectors.push_back(this); } App()->IncrementSleepInhibition(); if (source) obs_source_inc_showing(source); ready = true; show(); // We need it here to allow keyboard input in X11 to listen to Escape if (!isWindow) activateWindow(); }