Files
ppsspp/android/jni/AndroidEGLGraphicsContext.h
T
Henrik RydgårdandClaude Opus 5.5 34da53de5a Android GL: Support PresentMode::IMMEDIATE with eglSwapInterval
Now that EGL is ours rather than GLSurfaceView's, the swap interval can be set,
so turning vsync off (and fast-forward without skipping flips) works on Android
GL too. Not in VR, where OpenXR presents, and not with a config whose minimum
swap interval is 1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 15:45:27 +02:00

62 lines
2.7 KiB
C++

// Copyright (c) 2026- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include <EGL/egl.h>
#include "Common/GPU/OpenGL/OpenGLGraphicsContext.h"
struct ANativeWindow;
// Owns EGL for the OpenGL backend on Android. Until 2026 this was Java's job, through a
// GLSurfaceView (NativeRenderer.java / NativeGLSurfaceView.java, the "JavaGL" path).
//
// The point is not EGL itself but who owns the render thread. With GLSurfaceView, Java created
// the thread and the context and called us back, so a lost context was only ever observable
// after the fact, as a second onSurfaceCreated - which forced app-android.cpp to tear down and
// restart the emu thread from inside a JNI callback. Owning EGL here lets the GL backend use the
// same lifecycle as Vulkan: we start a render thread when we get a surface and join it when the
// surface goes away, which is the whole reason this exists.
class AndroidEGLGraphicsContext : public OpenGLGraphicsContext {
public:
// Note: not just DestroyEGL(). The base destructor deletes the thin3d context, which still
// makes GL calls, so EGL has to outlive it - ShutdownSurface() gets that order right, and is
// a no-op if the render loop already called it.
~AndroidEGLGraphicsContext() override { ShutdownSurface(); }
// Must be called on the thread that will become the render thread - the GL context ends up
// current on the calling thread. data1 is the ANativeWindow, as on the Vulkan path.
bool InitSurface(WindowSystem winsys, void *data1, void *data2, std::string *errorMessage) override;
void ShutdownSurface() override;
protected:
bool CanChangeSwapInterval() const override;
private:
// Picks a config, from the most to the least desirable. Fills in config_.
bool ChooseConfig(bool wantGLES3, std::string *errorMessage);
void DestroyEGL();
EGLDisplay display_ = EGL_NO_DISPLAY;
EGLSurface surface_ = EGL_NO_SURFACE;
EGLContext context_ = EGL_NO_CONTEXT;
EGLConfig config_ = nullptr;
// Not owned - the caller releases it after the render loop exits.
ANativeWindow *wnd_ = nullptr;
};