Skip to content

Commit

Permalink
[XB1] Add device lost handling
Browse files Browse the repository at this point in the history
This change adds handler function that trigger graphics recreation if EGL_CONTEXT_LOST error occurred.

b/329326128
  • Loading branch information
alexanderbobrovnik committed Jan 10, 2025
1 parent 2ee62f0 commit f5df859
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cobalt/renderer/backend/egl/graphics_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ void GraphicsContextEGL::SafeEglMakeCurrent(RenderTargetEGL* surface) {
// a thread can result in global allocations being made that are never freed.
ANNOTATE_SCOPED_MEMORY_LEAK;

#ifdef HANDLE_EGL_CONTEXT_LOST
if (error_context_lost_) {
return;
}
#endif
EGLSurface egl_surface = surface->GetSurface();

// This should only be used with egl surfaces (not framebuffer objects).
Expand Down Expand Up @@ -279,6 +284,13 @@ void GraphicsContextEGL::SafeEglMakeCurrent(RenderTargetEGL* surface) {
surface->set_surface_bad();
egl_surface = null_surface_->GetSurface();
EGL_CALL(eglMakeCurrent(display_, egl_surface, egl_surface, context_));
#ifdef HANDLE_EGL_CONTEXT_LOST
} else if (make_current_error == EGL_CONTEXT_LOST) {
error_context_lost_ = true;
EGL_CALL(eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT));
SbHandleEglContextLost();
#endif
} else {
NOTREACHED() << "Unexpected error when calling eglMakeCurrent().";
}
Expand Down
2 changes: 2 additions & 0 deletions cobalt/renderer/backend/egl/graphics_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class GraphicsContextEGL : public GraphicsContext {
// OpenGL ES implementation.
bool bgra_format_supported_;

bool error_context_lost_ = false;

// Data required to provide BlitToRenderTarget() functionality via OpenGL ES.
GLuint blit_vertex_shader_;
GLuint blit_fragment_shader_;
Expand Down
4 changes: 4 additions & 0 deletions starboard/egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ typedef void* SbEglSurface;
typedef void* SbEglSync;
typedef uint64_t SbEglTime;

#ifdef HANDLE_EGL_CONTEXT_LOST
void SbHandleEglContextLost();
#endif

typedef struct SbEglInterface {
SbEglBoolean (*eglChooseConfig)(SbEglDisplay dpy,
const SbEglInt32* attrib_list,
Expand Down
19 changes: 19 additions & 0 deletions starboard/shared/uwp/application_uwp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,25 @@ void OnDeviceRemoved(DeviceWatcher ^, DeviceInformationUpdate ^) {

} // namespace

extern "C" void SbHandleEglContextLost()
{
MimeSupportabilityCache::GetInstance()->ClearCachedMimeSupportabilities();

ApplicationUwp::Get()->Inject(
new ApplicationUwp::Event(kSbEventTypeBlur, NULL, NULL));
ApplicationUwp::Get()->Inject(
new ApplicationUwp::Event(kSbEventTypeConceal, NULL, NULL));
ApplicationUwp::Get()->Inject(
new ApplicationUwp::Event(kSbEventTypeFreeze, NULL, NULL));

ApplicationUwp::Get()->Inject(
new ApplicationUwp::Event(kSbEventTypeUnfreeze, NULL, NULL));
ApplicationUwp::Get()->Inject(
new ApplicationUwp::Event(kSbEventTypeReveal, NULL, NULL));
ApplicationUwp::Get()->Inject(
new ApplicationUwp::Event(kSbEventTypeFocus, NULL, NULL));
}

namespace shared {
namespace win32 {
// Called into drm_system_playready.cc
Expand Down
2 changes: 2 additions & 0 deletions starboard/xb1/configuration_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@

#include "starboard/xb1/shared/configuration_public.h"

#define HANDLE_EGL_CONTEXT_LOST

#endif // STARBOARD_XB1_CONFIGURATION_PUBLIC_H_

0 comments on commit f5df859

Please sign in to comment.