[client/obs] update to support downscaled frames coming from the host

This commit is contained in:
Geoffrey McRae
2022-05-01 19:41:46 +10:00
parent 3134ec84de
commit eae559b4c9
6 changed files with 99 additions and 77 deletions

View File

@@ -280,14 +280,14 @@ bool egl_desktopSetup(EGL_Desktop * desktop, const LG_RendererFormat format)
return false;
}
desktop->width = format.width;
desktop->height = format.height;
desktop->width = format.frameWidth;
desktop->height = format.frameHeight;
if (!egl_textureSetup(
desktop->texture,
pixFmt,
format.width,
format.height,
format.frameWidth,
format.frameHeight,
format.pitch
))
{

View File

@@ -340,18 +340,18 @@ static void egl_calc_mouse_size(struct Inst * this)
{
case LG_ROTATE_0:
case LG_ROTATE_180:
this->mouseScaleX = 2.0f / this->format.width;
this->mouseScaleY = 2.0f / this->format.height;
w = this->format.width;
h = this->format.height;
this->mouseScaleX = 2.0f / this->format.screenWidth;
this->mouseScaleY = 2.0f / this->format.screenHeight;
w = this->format.screenWidth;
h = this->format.screenHeight;
break;
case LG_ROTATE_90:
case LG_ROTATE_270:
this->mouseScaleX = 2.0f / this->format.height;
this->mouseScaleY = 2.0f / this->format.width;
w = this->format.height;
h = this->format.width;
this->mouseScaleX = 2.0f / this->format.screenHeight;
this->mouseScaleY = 2.0f / this->format.screenWidth;
w = this->format.screenHeight;
h = this->format.screenWidth;
break;
default:
@@ -419,14 +419,14 @@ static void egl_update_scale_type(struct Inst * this)
{
case LG_ROTATE_0:
case LG_ROTATE_180:
width = this->format.width;
height = this->format.height;
width = this->format.frameWidth;
height = this->format.frameHeight;
break;
case LG_ROTATE_90:
case LG_ROTATE_270:
width = this->format.height;
height = this->format.width;
width = this->format.frameHeight;
height = this->format.frameWidth;
break;
}
@@ -482,8 +482,10 @@ static void egl_onResize(LG_Renderer * renderer, const int width, const int heig
{
float scale = max(1.0f,
this->formatValid ?
max((float)this->format.width / this->width, (float)this->format.height / this->height)
: 1.0f);
max(
(float)this->format.screenWidth / this->width,
(float)this->format.screenHeight / this->height)
: 1.0f);
egl_cursorSetScale(this->cursor, scale);
}
@@ -561,12 +563,12 @@ static bool egl_onFrameFormat(LG_Renderer * renderer, const LG_RendererFormat fo
if (this->scalePointer)
{
float scale = max(1.0f, (float)format.width / this->width);
float scale = max(1.0f, (float)format.screenWidth / this->width);
egl_cursorSetScale(this->cursor, scale);
}
egl_update_scale_type(this);
egl_damageSetup(this->damage, format.width, format.height);
egl_damageSetup(this->damage, format.frameWidth, format.frameHeight);
/* we need full screen damage when the format changes */
INTERLOCKED_SECTION(this->desktopDamageLock, {
@@ -1043,8 +1045,8 @@ static bool egl_render(LG_Renderer * renderer, LG_RendererRotate rotate,
int y = rect->y > 0 ? rect->y - 1 : 0;
accumulated->rects[accumulated->count++] = (struct FrameDamageRect) {
.x = x, .y = y,
.width = min(this->format.width - x, rect->width + 2),
.height = min(this->format.height - y, rect->height + 2),
.width = min(this->format.frameWidth - x, rect->width + 2),
.height = min(this->format.frameHeight - y, rect->height + 2),
};
}
}
@@ -1057,7 +1059,8 @@ static bool egl_render(LG_Renderer * renderer, LG_RendererRotate rotate,
if (!renderAll)
{
double matrix[6];
egl_screenToDesktopMatrix(matrix, this->format.width, this->format.height,
egl_screenToDesktopMatrix(matrix,
this->format.frameWidth, this->format.frameHeight,
this->translateX, this->translateY, this->scaleX, this->scaleY, rotate,
this->width, this->height);
@@ -1076,7 +1079,7 @@ static bool egl_render(LG_Renderer * renderer, LG_RendererRotate rotate,
for (int j = 0; j < count; ++j)
accumulated->count += egl_screenToDesktop(
accumulated->rects + accumulated->count, matrix, damage + j,
this->format.width, this->format.height
this->format.frameWidth, this->format.frameHeight
);
}
@@ -1184,7 +1187,8 @@ static bool egl_render(LG_Renderer * renderer, LG_RendererRotate rotate,
else
{
double matrix[6];
egl_desktopToScreenMatrix(matrix, this->format.width, this->format.height,
egl_desktopToScreenMatrix(matrix,
this->format.frameWidth, this->format.frameHeight,
this->translateX, this->translateY, this->scaleX, this->scaleY, rotate,
this->width, this->height);

View File

@@ -299,8 +299,8 @@ void opengl_onResize(LG_Renderer * renderer, const int width, const int height,
{
glTranslatef(this->destRect.x, this->destRect.y, 0.0f);
glScalef(
(float)this->destRect.w / (float)this->format.width,
(float)this->destRect.h / (float)this->format.height,
(float)this->destRect.w / (float)this->format.frameWidth,
(float)this->destRect.h / (float)this->format.frameHeight,
1.0f
);
}
@@ -738,7 +738,7 @@ static enum ConfigStatus configure(struct Inst * this)
}
// calculate the texture size in bytes
this->texSize = this->format.height * this->format.pitch;
this->texSize = this->format.frameHeight * this->format.pitch;
this->texPos = 0;
g_gl_dynProcs.glGenBuffers(BUFFER_COUNT, this->vboID);
@@ -835,8 +835,8 @@ static enum ConfigStatus configure(struct Inst * this)
GL_TEXTURE_2D,
0,
this->intFormat,
this->format.width,
this->format.height,
this->format.frameWidth,
this->format.frameHeight,
0,
this->vboFormat,
this->dataFormat,
@@ -859,10 +859,11 @@ static enum ConfigStatus configure(struct Inst * this)
glBindTexture(GL_TEXTURE_2D, this->frames[i]);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0f, 0.0f); glVertex2i(0 , 0 );
glTexCoord2f(1.0f, 0.0f); glVertex2i(this->format.width, 0 );
glTexCoord2f(0.0f, 1.0f); glVertex2i(0 , this->format.height);
glTexCoord2f(1.0f, 1.0f); glVertex2i(this->format.width, this->format.height);
glTexCoord2f(0.0f, 0.0f); glVertex2i(0, 0);
glTexCoord2f(1.0f, 0.0f); glVertex2i(this->format.frameWidth, 0);
glTexCoord2f(0.0f, 1.0f); glVertex2i(0, this->format.frameHeight);
glTexCoord2f(1.0f, 1.0f);
glVertex2i(this->format.frameWidth, this->format.frameHeight);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glEndList();
@@ -1119,14 +1120,14 @@ static bool drawFrame(struct Inst * this)
const int bpp = this->format.bpp / 8;
glPixelStorei(GL_UNPACK_ALIGNMENT , bpp);
glPixelStorei(GL_UNPACK_ROW_LENGTH, this->format.width);
glPixelStorei(GL_UNPACK_ROW_LENGTH, this->format.frameWidth);
this->texPos = 0;
framebuffer_read_fn(
this->frame,
this->format.height,
this->format.width,
this->format.frameHeight,
this->format.frameWidth,
bpp,
this->format.pitch,
opengl_bufferFn,
@@ -1141,8 +1142,8 @@ static bool drawFrame(struct Inst * this)
0,
0,
0,
this->format.width ,
this->format.height,
this->format.frameWidth ,
this->format.frameHeight,
this->vboFormat,
this->dataFormat,
(void*)0
@@ -1150,7 +1151,8 @@ static bool drawFrame(struct Inst * this)
if (check_gl_error("glTexSubImage2D"))
{
DEBUG_ERROR("texWIndex: %u, width: %u, height: %u, vboFormat: %x, texSize: %lu",
this->texWIndex, this->format.width, this->format.height, this->vboFormat, this->texSize
this->texWIndex, this->format.frameWidth, this->format.frameHeight,
this->vboFormat, this->texSize
);
}
@@ -1158,8 +1160,8 @@ static bool drawFrame(struct Inst * this)
g_gl_dynProcs.glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
const bool mipmap = this->opt.mipmap && (
(this->format.width > this->destRect.w) ||
(this->format.height > this->destRect.h));
(this->format.frameWidth > this->destRect.w) ||
(this->format.frameHeight > this->destRect.h));
if (mipmap)
{