Skip to content

Commit ba4f075

Browse files
jreckAndroid (Google) Code Review
authored andcommitted
Merge "Don't crash on makeCurrent fail" into mnc-dev
2 parents 532737d + f2dcc2a commit ba4f075

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

libs/hwui/renderthread/CanvasContext.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ void CanvasContext::setOpaque(bool opaque) {
145145
void CanvasContext::makeCurrent() {
146146
// TODO: Figure out why this workaround is needed, see b/13913604
147147
// In the meantime this matches the behavior of GLRenderer, so it is not a regression
148-
mHaveNewSurface |= mEglManager.makeCurrent(mEglSurface);
148+
EGLint error = 0;
149+
mHaveNewSurface |= mEglManager.makeCurrent(mEglSurface, &error);
150+
if (error) {
151+
setSurface(nullptr);
152+
}
149153
}
150154

151155
void CanvasContext::processLayerUpdate(DeferredLayerUpdater* layerUpdater) {

libs/hwui/renderthread/EglManager.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,22 @@ void EglManager::destroy() {
217217
mCurrentSurface = EGL_NO_SURFACE;
218218
}
219219

220-
bool EglManager::makeCurrent(EGLSurface surface) {
220+
bool EglManager::makeCurrent(EGLSurface surface, EGLint* errOut) {
221221
if (isCurrent(surface)) return false;
222222

223223
if (surface == EGL_NO_SURFACE) {
224224
// Ensure we always have a valid surface & context
225225
surface = mPBufferSurface;
226226
}
227227
if (!eglMakeCurrent(mEglDisplay, surface, surface, mEglContext)) {
228-
LOG_ALWAYS_FATAL("Failed to make current on surface %p, error=%s",
229-
(void*)surface, egl_error_str());
228+
if (errOut) {
229+
*errOut = eglGetError();
230+
ALOGW("Failed to make current on surface %p, error=%s",
231+
(void*)surface, egl_error_str(*errOut));
232+
} else {
233+
LOG_ALWAYS_FATAL("Failed to make current on surface %p, error=%s",
234+
(void*)surface, egl_error_str());
235+
}
230236
}
231237
mCurrentSurface = surface;
232238
return true;

libs/hwui/renderthread/EglManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class EglManager {
4444

4545
bool isCurrent(EGLSurface surface) { return mCurrentSurface == surface; }
4646
// Returns true if the current surface changed, false if it was already current
47-
bool makeCurrent(EGLSurface surface);
47+
bool makeCurrent(EGLSurface surface, EGLint* errOut = nullptr);
4848
void beginFrame(EGLSurface surface, EGLint* width, EGLint* height);
4949
bool swapBuffers(EGLSurface surface, const SkRect& dirty, EGLint width, EGLint height);
5050

0 commit comments

Comments
 (0)