Skip to content

Commit

Permalink
fx issues
Browse files Browse the repository at this point in the history
  • Loading branch information
weihuoya committed Apr 9, 2021
1 parent 0c177ef commit 6971dc2
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 75 deletions.
3 changes: 2 additions & 1 deletion src/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

<activity
android:name=".ui.MainActivity"
android:launchMode="singleTop"
android:configChanges="orientation|screenSize"
android:theme="@style/CitraBase">

<!-- This intentfilter marks this Activity as the one that gets launched from Home screen. -->
Expand Down Expand Up @@ -89,7 +91,6 @@
<activity
android:name=".ui.MemoryActivity"
android:screenOrientation="behind"
android:configChanges="orientation|screenSize"
android:label="@string/emulation_memory_viewer"
android:theme="@style/CitraBase"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ public static void addNetPlayMessage(int type, String message) {

public static native void SurfaceDestroyed();

public static native void WindowChanged();

public static native void DoFrame();

public static native void Run(String path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void setRect(Rect rect) {
points[3].x = rect.left;
points[3].y = rect.bottom;

if (mListener != null) {
if (getVisibility() == VISIBLE && mListener != null) {
mListener.onResize(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ private ArrayList<SettingsItem> loadSettingsList() {
R.string.setting_system_language, 0,
R.array.languageNames, R.array.languageValues, 1,
language));
sl.add(new SingleChoiceSetting(SettingsFile.KEY_SYSTEM_LANGUAGE, Settings.SECTION_INI_CORE,
R.string.setting_system_language, 0,
R.array.languageNames, R.array.languageValues, 1,
language));

// theme
stringValues = getThemeValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected Map<Integer, Bitmap> doInBackground(Context... contexts) {
settings.loadSettings(mGameId);
SettingSection section = settings.getSection(Settings.SECTION_INI_CORE);
Setting setting = section.getSetting(SettingsFile.KEY_THEME_PACKAGE);
String theme = setting.getValueAsString();
String theme = setting != null ? setting.getValueAsString() : "";
return DirectoryInitialization.loadInputOverlay(contexts[0], theme);
}

Expand Down Expand Up @@ -111,8 +111,6 @@ protected void onCreate(Bundle savedInstanceState) {
mGamePath = savedInstanceState.getString(EXTRA_GAME_PATH);
}

hideSystemUI();

// Find or create the EmulationFragment
mEmulationFragment = (EmulationFragment)getSupportFragmentManager().findFragmentById(
R.id.fragment_emulation);
Expand Down Expand Up @@ -153,6 +151,12 @@ public void onBackPressed() {
}
}

@Override
protected void onResume() {
super.onResume();
hideSystemUI();
}

private void hideSystemUI() {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void onGlobalLayout() {
EmulationActivity activity = (EmulationActivity)getActivity();
activity.updateDisplayConfig();
activity.updateBackgroundImage();
NativeLibrary.SurfaceChanged(mSurface);
NativeLibrary.WindowChanged();
mResizeOverlayTop.setRect(NativeLibrary.getCustomLayout(true));
mResizeOverlayBottom.setRect(NativeLibrary.getCustomLayout(false));
observer.removeOnGlobalLayoutListener(this);
Expand Down
11 changes: 11 additions & 0 deletions src/android/app/src/main/java/org/citra/emu/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
Expand All @@ -24,6 +25,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -316,6 +318,15 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions,
}
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//mAdapter.notifyDataSetChanged();
int columns = getResources().getInteger(R.integer.game_grid_columns);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, columns);
mGameListView.setLayoutManager(layoutManager);
}

private void loadTitleDB() {
String lan = Locale.getDefault().getLanguage();
if (lan.equals("zh")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ public static void saveInputOverlay(Context context) {
ZipEntry entry = new ZipEntry(inputNames[i]);
zipOut.putNextEntry(entry);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), inputIds[i]);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, zipOut);
Bitmap.CompressFormat format = Bitmap.CompressFormat.PNG;
if (inputNames[i].endsWith(".jpg")) {
format = Bitmap.CompressFormat.JPEG;
}
bitmap.compress(format, 90, zipOut);
}
zipOut.close();
} catch (IOException e) {
Expand Down
10 changes: 10 additions & 0 deletions src/android/jni/egl_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ void EGLAndroid::UpdateSurface(ANativeWindow* surface) {
StopPresenting();
}

void EGLAndroid::UpdateWindow() {
window_width = ANativeWindow_getWidth(host_window);
window_height = ANativeWindow_getHeight(host_window);
safe_inset_left = static_cast<u32>(NativeLibrary::GetSafeInsetLeft());
safe_inset_top = static_cast<u32>(NativeLibrary::GetSafeInsetTop());
safe_inset_right = static_cast<u32>(NativeLibrary::GetSafeInsetRight());
safe_inset_bottom = static_cast<u32>(NativeLibrary::GetSafeInsetBottom());
UpdateLayout();
}

void EGLAndroid::UpdateLayout() {
UpdateFramebufferLayout(window_width, window_height);
}
Expand Down
1 change: 1 addition & 0 deletions src/android/jni/egl_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class EGLAndroid : public Frontend::EmuWindow {

bool Initialize(ANativeWindow* surface);
void UpdateSurface(ANativeWindow* surface);
void UpdateWindow();
void UpdateLayout();

void MakeCurrent() override;
Expand Down
9 changes: 8 additions & 1 deletion src/android/jni/main_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ JNIEXPORT void JNICALL Java_org_citra_emu_NativeLibrary_SurfaceDestroyed(JNIEnv*
}
}

JNIEXPORT void JNICALL Java_org_citra_emu_NativeLibrary_WindowChanged(JNIEnv* env, jclass obj) {
if (s_render_window) {
UpdateDisplayRotation();
s_render_window->UpdateWindow();
}
}

JNIEXPORT void JNICALL Java_org_citra_emu_NativeLibrary_DoFrame(JNIEnv* env, jclass obj) {
if (!s_is_running || s_stop_running) {
return;
Expand Down Expand Up @@ -528,7 +535,7 @@ JNIEXPORT void JNICALL Java_org_citra_emu_NativeLibrary_setRunningSettings(JNIEn
// Frame Limit
Settings::values.frame_limit = settings[i++] * 2;

s_render_window->UpdateLayout();
VideoCore::SettingUpdate();

env->ReleaseIntArrayElements(array, settings, 0);
}
Expand Down
71 changes: 28 additions & 43 deletions src/video_core/renderer_opengl/renderer_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ void main() {
static const char fragment_shader[] = R"(
in vec2 frag_tex_coord;
out vec4 color;
uniform sampler2D color_texture;
void main() {
color = texture(color_texture, frag_tex_coord);
}
Expand Down Expand Up @@ -529,42 +527,34 @@ void RendererOpenGL::LoadBackgroundImage(u32* pixels, u32 width, u32 height) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
OpenGLState::BindTexture2D(0, old_tex);
LoadBackgroundShader();
}

void RendererOpenGL::LoadBackgroundShader() {
if (!bg_shader.handle) {
std::string frag_source;
if (GLES) {
frag_source = fragment_shader_precision_OES;
frag_source += fragment_shader;
} else {
frag_source = fragment_shader;
}
bg_shader.Create(vertex_shader, frag_source.c_str());
const char bg_vertex_shader[] = R"(
out vec2 frag_tex_coord;
void main() {
vec2 rawpos = vec2(gl_VertexID & 1, (gl_VertexID & 2) >> 1);
frag_tex_coord = vec2(rawpos.x, rawpos.y);
mat2 rotate = mat2(0, -1, 1, 0); // rotate -90¡ã
gl_Position = vec4((rawpos * 2.0 - 1.0) * rotate, 0.0, 1.0);
}
)";
const char bg_fragment_shader[] = R"(
in vec2 frag_tex_coord;
out vec4 color;
layout(binding = 0) uniform sampler2D color_texture;
void main() {
color = texture(color_texture, frag_tex_coord);
}
)";
std::string frag_source;
if (GLES) {
frag_source = fragment_shader_precision_OES;
frag_source += bg_fragment_shader;
} else {
frag_source = bg_fragment_shader;
}

OpenGLState::BindShaderProgram(bg_shader.handle);
GLuint modelview_matrix = glGetUniformLocation(shader.handle, "modelview_matrix");
GLuint color_texture = glGetUniformLocation(shader.handle, "color_texture");
GLuint attrib_position = glGetAttribLocation(shader.handle, "vert_position");
GLuint attrib_tex_coord = glGetAttribLocation(shader.handle, "vert_tex_coord");

// Set projection matrix
auto layout = render_window.GetFramebufferLayout();
std::array<GLfloat, 3 * 2> ortho_matrix = MakeOrthographicMatrix(layout.width, layout.height);
glUniformMatrix3x2fv(modelview_matrix, 1, GL_FALSE, ortho_matrix.data());

// Bind texture in Texture Unit 0
glUniform1i(color_texture, 0);

// Attach vertex data to VAO
glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, sizeof(ScreenRectVertex),
(GLvoid*)offsetof(ScreenRectVertex, position));
glVertexAttribPointer(attrib_tex_coord, 2, GL_FLOAT, GL_FALSE, sizeof(ScreenRectVertex),
(GLvoid*)offsetof(ScreenRectVertex, tex_coord));
glEnableVertexAttribArray(attrib_position);
glEnableVertexAttribArray(attrib_tex_coord);
bg_shader.Create(bg_vertex_shader, frag_source.c_str());
}

/**
Expand Down Expand Up @@ -710,12 +700,12 @@ void RendererOpenGL::InitOpenGLObjects() {

uniform_modelview_matrix = glGetUniformLocation(shader.handle, "modelview_matrix");
uniform_resolution = glGetUniformLocation(shader.handle, "resolution");
GLuint uniform_color_texture = glGetUniformLocation(shader.handle, "color_texture");
GLuint color_texture = glGetUniformLocation(shader.handle, "color_texture");
GLuint attrib_position = glGetAttribLocation(shader.handle, "vert_position");
GLuint attrib_tex_coord = glGetAttribLocation(shader.handle, "vert_tex_coord");

// Bind texture in Texture Unit 0
glUniform1i(uniform_color_texture, 0);
glUniform1i(color_texture, 0);

// Attach vertex data to VAO
glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, sizeof(ScreenRectVertex),
Expand Down Expand Up @@ -857,7 +847,7 @@ void RendererOpenGL::DrawScreens(const Layout::FramebufferLayout& layout) {
const auto& bottom_screen = layout.bottom_screen;
const auto& bottom_texcoords = screen_infos[2].display_texcoords;

const std::array<ScreenRectVertex, 12> vertices = {{
const std::array<ScreenRectVertex, 8> vertices = {{
// top screen
ScreenRectVertex(top_screen.left, top_screen.top, top_texcoords.bottom, top_texcoords.left),
ScreenRectVertex(top_screen.left, top_screen.top + top_screen.GetHeight(),
Expand All @@ -877,19 +867,14 @@ void RendererOpenGL::DrawScreens(const Layout::FramebufferLayout& layout) {
ScreenRectVertex(bottom_screen.left + bottom_screen.GetWidth(),
bottom_screen.top + bottom_screen.GetHeight(), bottom_texcoords.top,
bottom_texcoords.right),
// background
ScreenRectVertex(0, 0, 1, 1),
ScreenRectVertex(0, layout.height, 0, 1),
ScreenRectVertex(layout.width, 0, 1, 0),
ScreenRectVertex(layout.width, layout.height, 0, 0),
}};
// prefer `glBufferData` than `glBufferSubData` on mobile device
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices.data(), GL_STREAM_DRAW);

// background
GLuint handle = OpenGLState::BindShaderProgram(bg_shader.handle);
OpenGLState::BindTexture2D(0, bg_texture.handle);
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
OpenGLState::BindShaderProgram(handle);

if (layout.top_screen_enabled) {
Expand Down
48 changes: 28 additions & 20 deletions src/video_core/video_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace VideoCore {
static std::unique_ptr<RendererBase> g_renderer;
static std::unique_ptr<RasterizerInterface> g_rasterizer;
static Memory::MemorySystem* g_memory = nullptr;
static bool g_setting_update = false;
static u16 g_scale_factor = 1;
static u32 g_current_frame = 0;

Expand All @@ -33,6 +34,26 @@ std::atomic<bool> g_hw_shader_enabled;
std::function<void(u32 width, u32 height, const std::vector<u32>& pixels)>
g_screenshot_complete_callback;

static void ApplySetting() {
Frontend::EmuWindow& window = g_renderer->GetRenderWindow();
const Layout::FramebufferLayout& layout = window.GetFramebufferLayout();
window.UpdateFramebufferLayout(layout.width, layout.height);

if (Settings::values.use_hw_renderer) {
g_scale_factor = Settings::values.resolution_factor
? Settings::values.resolution_factor
: window.GetFramebufferLayout().GetScalingRatio();
} else {
// Software renderer always render at native resolution
g_scale_factor = 1;
}

g_rasterizer->CheckForConfigChanges();
g_hw_shader_enabled = Settings::values.use_hw_shader;

g_setting_update = false;
}

/// Initialize the video core
ResultStatus Init(Frontend::EmuWindow& window, Memory::MemorySystem& memory) {
g_memory = &memory;
Expand All @@ -46,7 +67,7 @@ ResultStatus Init(Frontend::EmuWindow& window, Memory::MemorySystem& memory) {
} else {
g_rasterizer = std::make_unique<VideoCore::SWRasterizer>();
}
SettingUpdate();
ApplySetting();
g_current_frame = 0;
} else {
g_renderer.reset();
Expand Down Expand Up @@ -83,28 +104,15 @@ void FrameUpdate() {
g_background_width = 0;
g_background_height = 0;
}
}

void SettingUpdate() {
if (!g_renderer) {
return;
}

Frontend::EmuWindow& window = g_renderer->GetRenderWindow();
const Layout::FramebufferLayout& layout = window.GetFramebufferLayout();
window.UpdateFramebufferLayout(layout.width, layout.height);

if (Settings::values.use_hw_renderer) {
g_scale_factor = Settings::values.resolution_factor
? Settings::values.resolution_factor
: window.GetFramebufferLayout().GetScalingRatio();
} else {
// Software renderer always render at native resolution
g_scale_factor = 1;
// settings
if (g_setting_update) {
ApplySetting();
}
}

g_rasterizer->CheckForConfigChanges();
g_hw_shader_enabled = Settings::values.use_hw_shader;
void SettingUpdate() {
g_setting_update = (g_renderer != nullptr);
}

u16 GetResolutionScaleFactor() {
Expand Down

0 comments on commit 6971dc2

Please sign in to comment.