From e2fc3b325cf295d04b3c3a8aec413abb28b40f64 Mon Sep 17 00:00:00 2001 From: Tomas Jakobsson Date: Thu, 18 Jan 2018 18:30:00 +0100 Subject: [PATCH 1/3] Add support for --screenrotate --- es-app/src/main.cpp | 11 +++++ es-core/src/Renderer.h | 1 + es-core/src/Renderer_draw_gl.cpp | 16 +++++++- es-core/src/Renderer_init_sdlgl.cpp | 62 +++++++++++++++++++++++++++-- 4 files changed, 85 insertions(+), 5 deletions(-) diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 0827e5932..23f8e982b 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -70,6 +70,17 @@ bool parseArgs(int argc, char* argv[]) i += 2; // skip the argument value Settings::getInstance()->setInt("ScreenOffsetX", x); Settings::getInstance()->setInt("ScreenOffsetY", y); + }else if (strcmp(argv[i], "--screenrotate") == 0) + { + if (i >= argc - 1) + { + std::cerr << "Invalid screenrotate supplied."; + return false; + } + + int rotate = atoi(argv[i + 1]); + ++i; // skip the argument value + Settings::getInstance()->setInt("ScreenRotate", rotate); }else if(strcmp(argv[i], "--gamelist-only") == 0) { Settings::getInstance()->setBool("ParseGamelistOnly", true); diff --git a/es-core/src/Renderer.h b/es-core/src/Renderer.h index 6114163d6..358cf4031 100644 --- a/es-core/src/Renderer.h +++ b/es-core/src/Renderer.h @@ -24,6 +24,7 @@ namespace Renderer unsigned int getScreenHeight(); unsigned int getScreenOffsetX(); unsigned int getScreenOffsetY(); + unsigned int getScreenRotate(); void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount); diff --git a/es-core/src/Renderer_draw_gl.cpp b/es-core/src/Renderer_draw_gl.cpp index 9ed671a2b..afa7ffdd6 100644 --- a/es-core/src/Renderer_draw_gl.cpp +++ b/es-core/src/Renderer_draw_gl.cpp @@ -69,7 +69,13 @@ namespace Renderer { box.h = 0; clipStack.push(box); - glScissor(box.x, box.y, box.w, box.h); + switch(Renderer::getScreenRotate()) + { + case 0: { glScissor(box.x, box.y, box.w, box.h); } break; + case 1: { glScissor(box.y, Renderer::getScreenWidth() - box.x - box.w, box.h, box.w); } break; + case 2: { glScissor(Renderer::getScreenWidth() - box.x - box.w, Renderer::getScreenHeight() - box.y - box.h, box.w, box.h); } break; + case 3: { glScissor(Renderer::getScreenHeight() - box.y - box.h, box.x, box.h, box.w); } break; + } glEnable(GL_SCISSOR_TEST); } @@ -87,7 +93,13 @@ namespace Renderer { glDisable(GL_SCISSOR_TEST); }else{ const ClipRect& top = clipStack.top(); - glScissor(top.x, top.y, top.w, top.h); + switch(Renderer::getScreenRotate()) + { + case 0: { glScissor(top.x, top.y, top.w, top.h); } break; + case 1: { glScissor(top.y, Renderer::getScreenWidth() - top.x - top.w, top.h, top.w); } break; + case 2: { glScissor(Renderer::getScreenWidth() - top.x - top.w, Renderer::getScreenHeight() - top.y - top.h, top.w, top.h); } break; + case 3: { glScissor(Renderer::getScreenHeight() - top.y - top.h, top.x, top.h, top.w); } break; + } } } diff --git a/es-core/src/Renderer_init_sdlgl.cpp b/es-core/src/Renderer_init_sdlgl.cpp index b8fb9136e..a456e93c0 100644 --- a/es-core/src/Renderer_init_sdlgl.cpp +++ b/es-core/src/Renderer_init_sdlgl.cpp @@ -20,6 +20,7 @@ namespace Renderer unsigned int screenHeight = 0; unsigned int screenOffsetX = 0; unsigned int screenOffsetY = 0; + unsigned int screenRotate = 0; unsigned int getWindowWidth() { return windowWidth; } unsigned int getWindowHeight() { return windowHeight; } @@ -27,6 +28,7 @@ namespace Renderer unsigned int getScreenHeight() { return screenHeight; } unsigned int getScreenOffsetX() { return screenOffsetX; } unsigned int getScreenOffsetY() { return screenOffsetY; } + unsigned int getScreenRotate() { return screenRotate; } SDL_Window* sdlWindow = NULL; SDL_GLContext sdlContext = NULL; @@ -66,6 +68,7 @@ namespace Renderer screenHeight = Settings::getInstance()->getInt("ScreenHeight") ? Settings::getInstance()->getInt("ScreenHeight") : windowHeight; screenOffsetX = Settings::getInstance()->getInt("ScreenOffsetX") ? Settings::getInstance()->getInt("ScreenOffsetX") : 0; screenOffsetY = Settings::getInstance()->getInt("ScreenOffsetY") ? Settings::getInstance()->getInt("ScreenOffsetY") : 0; + screenRotate = Settings::getInstance()->getInt("ScreenRotate") ? Settings::getInstance()->getInt("ScreenRotate") : 0; sdlWindow = SDL_CreateWindow("EmulationStation", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, @@ -80,6 +83,21 @@ namespace Renderer LOG(LogInfo) << "Created window successfully."; + //support screen rotation + if((screenRotate == 1) || (screenRotate == 3)) + { + int temp; + temp = windowWidth; + windowWidth = windowHeight; + windowHeight = temp; + temp = screenWidth; + screenWidth = screenHeight; + screenHeight = temp; + temp = screenOffsetX; + screenOffsetX = screenOffsetY; + screenOffsetY = temp; + } + //set an icon for the window size_t width = 0; size_t height = 0; @@ -143,9 +161,47 @@ namespace Renderer return false; //gotta flip y since y=0 is at the bottom - glViewport(screenOffsetX, windowHeight - screenHeight - screenOffsetY, screenWidth, screenHeight); - glMatrixMode(GL_PROJECTION); - glOrtho(0, screenWidth, screenHeight, 0, -1.0, 1.0); + switch(screenRotate) + { + case 0: + { + glViewport(screenOffsetX, windowHeight - screenHeight - screenOffsetY, screenWidth, screenHeight); + glMatrixMode(GL_PROJECTION); + glOrtho(0, screenWidth, screenHeight, 0, -1.0, 1.0); + } + break; + + case 1: + { + glViewport(screenOffsetY, windowWidth - screenWidth - screenOffsetX, screenHeight, screenWidth); + glMatrixMode(GL_PROJECTION); + glOrtho(0, screenHeight, screenWidth, 0, -1.0, 1.0); + glRotatef(90, 0, 0, 1); + glTranslatef(0, screenHeight * -1.0f, 0); + } + break; + + case 2: + { + glViewport(screenOffsetX, windowHeight - screenHeight - screenOffsetY, screenWidth, screenHeight); + glMatrixMode(GL_PROJECTION); + glOrtho(0, screenWidth, screenHeight, 0, -1.0, 1.0); + glRotatef(180, 0, 0, 1); + glTranslatef(screenWidth * -1.0f, screenHeight * -1.0f, 0); + } + break; + + case 3: + { + glViewport(screenOffsetY, windowWidth - screenWidth - screenOffsetX, screenHeight, screenWidth); + glMatrixMode(GL_PROJECTION); + glOrtho(0, screenHeight, screenWidth, 0, -1.0, 1.0); + glRotatef(270, 0, 0, 1); + glTranslatef(screenWidth * -1.0f, 0, 0); + } + break; + } + glMatrixMode(GL_MODELVIEW); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); From ec8ebf07f31027cf42533aa8babb15649b285fd0 Mon Sep 17 00:00:00 2001 From: Tomas Jakobsson Date: Fri, 19 Jan 2018 00:50:15 +0100 Subject: [PATCH 2/3] Fix --screenrotate to work with --screensize and --screenoffset --- es-core/src/Renderer_draw_gl.cpp | 35 ++++++++++++++++---------------- es-core/src/Settings.cpp | 4 +++- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/es-core/src/Renderer_draw_gl.cpp b/es-core/src/Renderer_draw_gl.cpp index afa7ffdd6..cac28c5d4 100644 --- a/es-core/src/Renderer_draw_gl.cpp +++ b/es-core/src/Renderer_draw_gl.cpp @@ -45,9 +45,21 @@ namespace Renderer { //glScissor starts at the bottom left of the window //so (0, 0, 1, 1) is the bottom left pixel //everything else uses y+ = down, so flip it to be consistent - //also take screen height and offset into account - box.x = Renderer::getScreenOffsetX() + box.x; - box.y = Renderer::getWindowHeight() - Renderer::getScreenOffsetY() - box.y - box.h; + switch(Renderer::getScreenRotate()) + { + case 0: { box = ClipRect(box.x, Renderer::getWindowHeight() - (box.y + box.h), box.w, box.h); } break; + case 1: { box = ClipRect(Renderer::getScreenHeight() - (box.y + box.h), Renderer::getWindowWidth() - (box.x + box.w), box.h, box.w); } break; + case 2: { box = ClipRect(Renderer::getScreenWidth() - (box.x + box.w), Renderer::getWindowHeight() - Renderer::getScreenHeight() + box.y, box.w, box.h); } break; + case 3: { box = ClipRect(box.y, Renderer::getWindowWidth() - Renderer::getScreenWidth() + box.x, box.h, box.w); } break; + } + + switch(Renderer::getScreenRotate()) + { + case 0: { box.x += Renderer::getScreenOffsetX(); box.y -= Renderer::getScreenOffsetY(); } break; + case 1: { box.x += Renderer::getScreenOffsetY(); box.y -= Renderer::getScreenOffsetX(); } break; + case 2: { box.x += Renderer::getScreenOffsetX(); box.y -= Renderer::getScreenOffsetY(); } break; + case 3: { box.x += Renderer::getScreenOffsetY(); box.y -= Renderer::getScreenOffsetX(); } break; + } //make sure the box fits within clipStack.top(), and clip further accordingly if(clipStack.size()) @@ -69,13 +81,8 @@ namespace Renderer { box.h = 0; clipStack.push(box); - switch(Renderer::getScreenRotate()) - { - case 0: { glScissor(box.x, box.y, box.w, box.h); } break; - case 1: { glScissor(box.y, Renderer::getScreenWidth() - box.x - box.w, box.h, box.w); } break; - case 2: { glScissor(Renderer::getScreenWidth() - box.x - box.w, Renderer::getScreenHeight() - box.y - box.h, box.w, box.h); } break; - case 3: { glScissor(Renderer::getScreenHeight() - box.y - box.h, box.x, box.h, box.w); } break; - } + + glScissor(box.x, box.y, box.w, box.h); glEnable(GL_SCISSOR_TEST); } @@ -93,13 +100,7 @@ namespace Renderer { glDisable(GL_SCISSOR_TEST); }else{ const ClipRect& top = clipStack.top(); - switch(Renderer::getScreenRotate()) - { - case 0: { glScissor(top.x, top.y, top.w, top.h); } break; - case 1: { glScissor(top.y, Renderer::getScreenWidth() - top.x - top.w, top.h, top.w); } break; - case 2: { glScissor(Renderer::getScreenWidth() - top.x - top.w, Renderer::getScreenHeight() - top.y - top.h, top.w, top.h); } break; - case 3: { glScissor(Renderer::getScreenHeight() - top.y - top.h, top.x, top.h, top.w); } break; - } + glScissor(top.x, top.y, top.w, top.h); } } diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 75bf095cd..a18f002f3 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -26,7 +26,8 @@ std::vector settings_dont_save { { "ScreenWidth" }, { "ScreenHeight" }, { "ScreenOffsetX" }, - { "ScreenOffsetY" } + { "ScreenOffsetY" }, + { "ScreenRotate" } }; Settings::Settings() @@ -140,6 +141,7 @@ void Settings::setDefaults() mIntMap["ScreenHeight"] = 0; mIntMap["ScreenOffsetX"] = 0; mIntMap["ScreenOffsetY"] = 0; + mIntMap["ScreenRotate"] = 0; } template From 4428ddaa6dabaa3daf5659bf3dda80325f56a091 Mon Sep 17 00:00:00 2001 From: Tomas Jakobsson Date: Fri, 19 Jan 2018 02:09:49 +0100 Subject: [PATCH 3/3] Fix omxplayer when using --screensize, --screenoffset and --screenrotate --- .../src/components/VideoPlayerComponent.cpp | 71 ++++++++++++++++--- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/es-core/src/components/VideoPlayerComponent.cpp b/es-core/src/components/VideoPlayerComponent.cpp index 64a67793f..8f0ef8df2 100644 --- a/es-core/src/components/VideoPlayerComponent.cpp +++ b/es-core/src/components/VideoPlayerComponent.cpp @@ -3,6 +3,7 @@ #include "utils/StringUtil.h" #include "AudioManager.h" +#include "Renderer.h" #include "Settings.h" #include #include @@ -93,14 +94,68 @@ void VideoPlayerComponent::startVideo() // Find out the pixel position of the video view and build a command line for // omxplayer to position it in the right place - char buf[32]; + char buf1[32]; + char buf2[32]; float x = mPosition.x() - (mOrigin.x() * mSize.x()); float y = mPosition.y() - (mOrigin.y() * mSize.y()); - sprintf(buf, "%d,%d,%d,%d", (int)x, (int)y, (int)(x + mSize.x()), (int)(y + mSize.y())); + + // fix x and y + switch(Renderer::getScreenRotate()) + { + case 0: + { + const int x1 = (int)(Renderer::getScreenOffsetX() + x); + const int y1 = (int)(Renderer::getScreenOffsetY() + y); + const int x2 = (int)(x1 + mSize.x()); + const int y2 = (int)(y1 + mSize.y()); + sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); + } + break; + + case 1: + { + const int x1 = (int)(Renderer::getScreenOffsetY() + Renderer::getScreenHeight() - y - mSize.y()); + const int y1 = (int)(Renderer::getScreenOffsetX() + x); + const int x2 = (int)(x1 + mSize.y()); + const int y2 = (int)(y1 + mSize.x()); + sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); + } + break; + + case 2: + { + const int x1 = (int)(Renderer::getScreenOffsetX() + Renderer::getScreenWidth() - x - mSize.x()); + const int y1 = (int)(Renderer::getScreenOffsetY() + Renderer::getScreenHeight() - y - mSize.y()); + const int x2 = (int)(x1 + mSize.x()); + const int y2 = (int)(y1 + mSize.y()); + sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); + } + break; + + case 3: + { + const int x1 = (int)(Renderer::getScreenOffsetY() + y); + const int y1 = (int)(Renderer::getScreenOffsetX() + Renderer::getScreenWidth() - x - mSize.x()); + const int x2 = (int)(x1 + mSize.y()); + const int y2 = (int)(y1 + mSize.x()); + sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); + } + break; + } + + // rotate the video + switch(Renderer::getScreenRotate()) + { + case 0: { sprintf(buf2, "%d", (int) 0); } break; + case 1: { sprintf(buf2, "%d", (int) 90); } break; + case 2: { sprintf(buf2, "%d", (int)180); } break; + case 3: { sprintf(buf2, "%d", (int)270); } break; + } + // We need to specify the layer of 10000 or above to ensure the video is displayed on top // of our SDL display - const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "-o", "both","--win", buf, "--no-ghost-box", "", "", "", "", NULL }; + const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "-o", "both","--win", buf1, "--orientation", buf2, "", "", "", "", NULL }; // check if we want to mute the audio if (!Settings::getInstance()->getBool("VideoAudio") || (float)VolumeControl::getInstance()->getVolume() == 0) @@ -128,14 +183,14 @@ void VideoPlayerComponent::startVideo() if (Settings::getInstance()->getString("ScreenSaverGameInfo") != "never") { // if we have chosen to render subtitles - argv[13] = "--subtitles"; - argv[14] = subtitlePath.c_str(); - argv[15] = mPlayingVideoPath.c_str(); + argv[15] = "--subtitles"; + argv[16] = subtitlePath.c_str(); + argv[17] = mPlayingVideoPath.c_str(); } else { // if we have chosen NOT to render subtitles in the screensaver - argv[13] = mPlayingVideoPath.c_str(); + argv[15] = mPlayingVideoPath.c_str(); } } else @@ -145,7 +200,7 @@ void VideoPlayerComponent::startVideo() { argv[6] = "stretch"; } - argv[13] = mPlayingVideoPath.c_str(); + argv[15] = mPlayingVideoPath.c_str(); } argv[10] = Settings::getInstance()->getString("OMXAudioDev").c_str();