Add scale support
This commit is contained in:
@@ -53,6 +53,7 @@ int main(int argc, char **argv)
|
||||
obs_data_set_int(settings, "width", 64);
|
||||
obs_data_set_int(settings, "height", 64);
|
||||
obs_data_set_int(settings, "fps", 10);
|
||||
obs_data_set_int(settings, "zoom", 175);
|
||||
obs_data_set_bool(settings, "transparent", true);
|
||||
obs_data_set_bool(settings, "hardware_acceleration", false);
|
||||
obs_source_t *source = obs_source_create_private("webkit_browser_source", "smoke", settings);
|
||||
@@ -61,6 +62,16 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, "source lifecycle setup failed\n");
|
||||
valid = false;
|
||||
}
|
||||
obs_properties_t *properties = source ? obs_source_properties(source) : NULL;
|
||||
obs_property_t *zoom = properties ? obs_properties_get(properties, "zoom") : NULL;
|
||||
if (!zoom || obs_property_get_type(zoom) != OBS_PROPERTY_INT ||
|
||||
obs_property_int_type(zoom) != OBS_NUMBER_SLIDER || obs_property_int_min(zoom) != 25 ||
|
||||
obs_property_int_max(zoom) != 500 || obs_property_int_step(zoom) != 5) {
|
||||
fprintf(stderr, "page zoom property is missing or invalid\n");
|
||||
valid = false;
|
||||
}
|
||||
if (properties)
|
||||
obs_properties_destroy(properties);
|
||||
if (source) {
|
||||
usleep(500000);
|
||||
obs_source_release(source);
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(sizeof(struct owb_config_header) == 36);
|
||||
assert(sizeof(struct owb_config_header) == 40);
|
||||
assert(offsetof(struct owb_config_header, zoom_percent) == 20);
|
||||
assert(sizeof(struct owb_command) == 100);
|
||||
assert(offsetof(struct owb_shared_frames, pixels) == 40);
|
||||
assert(owb_shared_size(2, 2) == 72);
|
||||
|
||||
@@ -109,6 +109,7 @@ int main(int argc, char **argv)
|
||||
struct owb_config_header config = {
|
||||
.magic = OWB_CONFIG_MAGIC, .version = OWB_PROTOCOL_VERSION,
|
||||
.width = width, .height = height, .fps = requested_fps, .transparent = 1,
|
||||
.zoom_percent = 100,
|
||||
.hardware_acceleration = 1,
|
||||
.url_length = sizeof(url) - 1, .css_length = (uint32_t)css_length,
|
||||
};
|
||||
|
||||
@@ -56,12 +56,13 @@ int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2 || argc > 4) {
|
||||
fprintf(stderr,
|
||||
"usage: %s /path/to/obs-webkit-renderer [opaque | opaque-url URL]\n",
|
||||
"usage: %s /path/to/obs-webkit-renderer [opaque | zoom | opaque-url URL]\n",
|
||||
argv[0]);
|
||||
return 2;
|
||||
}
|
||||
bool external_url = argc == 4 && strcmp(argv[2], "opaque-url") == 0;
|
||||
bool opaque = external_url || (argc == 3 && strcmp(argv[2], "opaque") == 0);
|
||||
bool zoom = argc == 3 && strcmp(argv[2], "zoom") == 0;
|
||||
bool opaque = external_url || zoom || (argc == 3 && strcmp(argv[2], "opaque") == 0);
|
||||
int control[2];
|
||||
int frames[2];
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, control) || pipe(frames)) {
|
||||
@@ -108,14 +109,18 @@ int main(int argc, char **argv)
|
||||
const char opaque_css[] = "html,body{margin:0;background:rgb(7,19,31)!important}"
|
||||
"#box{position:fixed;left:16px;top:16px;width:32px;height:32px;"
|
||||
"background:rgb(241,23,17);transform:translateZ(0);filter:blur(.1px)}";
|
||||
const char zoom_css[] = "html,body{margin:0;background:rgb(7,19,31)!important}"
|
||||
"#box{position:fixed;left:0;top:0;width:10px;height:10px;"
|
||||
"background:rgb(241,23,17)}";
|
||||
const char *url = external_url ? argv[3] : internal_url;
|
||||
const char *css = external_url ? "" : opaque ? opaque_css : transparent_css;
|
||||
const char *css = external_url ? "" : zoom ? zoom_css : opaque ? opaque_css : transparent_css;
|
||||
struct owb_config_header config = {
|
||||
.magic = OWB_CONFIG_MAGIC,
|
||||
.version = OWB_PROTOCOL_VERSION,
|
||||
.width = width,
|
||||
.height = height,
|
||||
.fps = 10,
|
||||
.zoom_percent = zoom ? 200 : 100,
|
||||
.transparent = opaque ? 0 : 1,
|
||||
/* GPU rendering must still produce an invisible captured frame. */
|
||||
.hardware_acceleration = 1,
|
||||
@@ -158,10 +163,17 @@ int main(int argc, char **argv)
|
||||
nonuniform ? "content" : "uniform");
|
||||
continue;
|
||||
}
|
||||
size_t center = ((size_t)(height / 2) * width + width / 2) * 4;
|
||||
size_t center = zoom ? ((size_t)5 * width + 15) * 4
|
||||
: ((size_t)(height / 2) * width + width / 2) * 4;
|
||||
memcpy(last_bgra, frame + center, sizeof(last_bgra));
|
||||
memcpy(last_corner_bgra, frame, sizeof(last_corner_bgra));
|
||||
bool expected = opaque
|
||||
size_t corner = zoom ? ((size_t)5 * width + 25) * 4 : 0;
|
||||
memcpy(last_corner_bgra, frame + corner, sizeof(last_corner_bgra));
|
||||
bool expected = zoom
|
||||
? last_bgra[0] < 32 && last_bgra[1] < 40 && last_bgra[2] > 210 &&
|
||||
last_bgra[3] == 255 && last_corner_bgra[0] > 20 &&
|
||||
last_corner_bgra[1] < 32 && last_corner_bgra[2] < 32 &&
|
||||
last_corner_bgra[3] == 255
|
||||
: opaque
|
||||
? last_bgra[0] < 32 && last_bgra[1] < 40 && last_bgra[2] > 210 &&
|
||||
last_bgra[3] == 255
|
||||
: last_bgra[0] < 8 && last_bgra[1] < 8 && last_bgra[2] > 248 &&
|
||||
@@ -192,7 +204,8 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr,
|
||||
"renderer did not produce the expected %s red BGRA frame "
|
||||
"(center BGRA=%u,%u,%u,%u; corner BGRA=%u,%u,%u,%u)\n",
|
||||
opaque ? "opaque" : "transparent", last_bgra[0], last_bgra[1],
|
||||
zoom ? "200%-zoomed" : opaque ? "opaque" : "transparent",
|
||||
last_bgra[0], last_bgra[1],
|
||||
last_bgra[2], last_bgra[3], last_corner_bgra[0], last_corner_bgra[1],
|
||||
last_corner_bgra[2], last_corner_bgra[3]);
|
||||
return 1;
|
||||
|
||||
@@ -114,6 +114,7 @@ static bool start_view(struct view *view, const char *renderer, const char *url)
|
||||
struct owb_config_header config = {
|
||||
.magic = OWB_CONFIG_MAGIC, .version = OWB_PROTOCOL_VERSION,
|
||||
.width = width, .height = height, .fps = 20, .transparent = 0,
|
||||
.zoom_percent = 100,
|
||||
.hardware_acceleration = 1, .url_length = (uint32_t)strlen(url), .css_length = 0,
|
||||
};
|
||||
return write_all(view->control, &config, sizeof(config)) &&
|
||||
|
||||
Reference in New Issue
Block a user