Skip to content

Commit

Permalink
Fix the wrong rendering size queried from EGLSurface on Android platf…
Browse files Browse the repository at this point in the history
…orm. (#505)

Co-authored-by: kevingpqi <kevingpqi@tencent.com>
(cherry picked from commit 1310ce5)
  • Loading branch information
kevingpqi123 committed Aug 31, 2022
1 parent d9178d2 commit 1aaf277
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/platform/android/GPUDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ void GPUDrawable::updateSize() {
_width = ANativeWindow_getWidth(nativeWindow);
_height = ANativeWindow_getHeight(nativeWindow);
}
window = nullptr;
}

std::shared_ptr<tgfx::Device> GPUDrawable::getDevice() {
Expand Down
2 changes: 2 additions & 0 deletions tgfx/include/tgfx/gpu/opengl/egl/EGLWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class EGLWindow : public Window {
void onPresent(Context* context, int64_t presentationTime) override;

private:
EGLNativeWindowType nativeWindow;

explicit EGLWindow(std::shared_ptr<Device> device);
};
} // namespace tgfx
25 changes: 21 additions & 4 deletions tgfx/src/gpu/opengl/egl/EGLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "tgfx/gpu/opengl/egl/EGLWindow.h"

#if defined(__ANDROID__) || defined(ANDROID)
#include <android/native_window.h>
#endif
#include <EGL/eglext.h>
#include <GLES3/gl3.h>
#include "tgfx/gpu/opengl/GLRenderTarget.h"
Expand All @@ -39,7 +43,9 @@ std::shared_ptr<EGLWindow> EGLWindow::MakeFrom(EGLNativeWindowType nativeWindow,
if (device == nullptr) {
return nullptr;
}
return std::shared_ptr<EGLWindow>(new EGLWindow(device));
auto eglWindow = std::shared_ptr<EGLWindow>(new EGLWindow(device));
eglWindow->nativeWindow = nativeWindow;
return eglWindow;
}

EGLWindow::EGLWindow(std::shared_ptr<Device> device) : Window(std::move(device)) {
Expand All @@ -48,9 +54,20 @@ EGLWindow::EGLWindow(std::shared_ptr<Device> device) : Window(std::move(device))
std::shared_ptr<Surface> EGLWindow::onCreateSurface(Context* context) {
EGLint width = 0;
EGLint height = 0;
auto eglDevice = static_cast<EGLDevice*>(device.get());
eglQuerySurface(eglDevice->eglDisplay, eglDevice->eglSurface, EGL_WIDTH, &width);
eglQuerySurface(eglDevice->eglDisplay, eglDevice->eglSurface, EGL_HEIGHT, &height);

// If the rendering size changes,eglQuerySurface based on ANativeWindow may give the wrong size.
#if defined(__ANDROID__) || defined(ANDROID)
if (nativeWindow) {
width = ANativeWindow_getWidth(nativeWindow);
height = ANativeWindow_getHeight(nativeWindow);
}
#endif
if (width <= 0 || height <= 0) {
auto eglDevice = static_cast<EGLDevice*>(device.get());
eglQuerySurface(eglDevice->eglDisplay, eglDevice->eglSurface, EGL_WIDTH, &width);
eglQuerySurface(eglDevice->eglDisplay, eglDevice->eglSurface, EGL_HEIGHT, &height);
}

if (width <= 0 || height <= 0) {
return nullptr;
}
Expand Down

0 comments on commit 1aaf277

Please sign in to comment.