Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XB1] Add device lost handling #4628

Open
wants to merge 1 commit into
base: 24.lts.1+
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a starboard interface change. It would need approval from @y4vor, @kaidokert, @xiaomings. I don't think we should change it at this moment.

#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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've seen regression b/370914120 for a similar change https://lbshell-internal-review.git.corp.google.com/c/cobalt_src/+/281544. Is that a safe way to reset DX11 device?

}

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_
Loading