Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53bacf5a authored by Romain Guy's avatar Romain Guy
Browse files

Handle Surface::lock errors in TextureView

Bug #8689535

Change-Id: I6d16e13903a58e93940160e7656147656ab79982
parent ea633ce2
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -649,12 +649,18 @@ public class TextureView extends View {
     * pixels outside the dirty rectangle will be preserved by the next call
     * to lockCanvas().
     *
     * This method can return null if the underlying surface texture is not
     * available (see {@link #isAvailable()} or if the surface texture is
     * already connected to an image producer (for instance: the camera,
     * OpenGL, a media player, etc.)
     * 
     * @param dirty Area of the surface that will be modified.

     * @return A Canvas used to draw into the surface.
     * 
     * @see #lockCanvas() 
     * @see #unlockCanvasAndPost(android.graphics.Canvas)
     * @see #isAvailable()
     */
    public Canvas lockCanvas(Rect dirty) {
        if (!isAvailable()) return null;
@@ -664,7 +670,9 @@ public class TextureView extends View {
        }

        synchronized (mNativeWindowLock) {
            nLockCanvas(mNativeWindow, mCanvas, dirty);
            if (!nLockCanvas(mNativeWindow, mCanvas, dirty)) {
                return null;
            }
        }
        mSaveCount = mCanvas.save();

@@ -803,6 +811,6 @@ public class TextureView extends View {
    private static native void nSetDefaultBufferSize(SurfaceTexture surfaceTexture,
            int width, int height);

    private static native void nLockCanvas(int nativeWindow, Canvas canvas, Rect dirty);
    private static native boolean nLockCanvas(int nativeWindow, Canvas canvas, Rect dirty);
    private static native void nUnlockCanvasAndPost(int nativeWindow, Canvas canvas);
}
+9 −5
Original line number Diff line number Diff line
@@ -134,11 +134,11 @@ static inline void swapCanvasPtr(JNIEnv* env, jobject canvasObj, SkCanvas* newCa
  SkSafeUnref(previousCanvas);
}

static void android_view_TextureView_lockCanvas(JNIEnv* env, jobject,
static jboolean android_view_TextureView_lockCanvas(JNIEnv* env, jobject,
        jint nativeWindow, jobject canvas, jobject dirtyRect) {

    if (!nativeWindow) {
        return;
        return false;
    }

    ANativeWindow_Buffer buffer;
@@ -154,7 +154,8 @@ static void android_view_TextureView_lockCanvas(JNIEnv* env, jobject,
    }

    sp<ANativeWindow> window((ANativeWindow*) nativeWindow);
    native_window_lock(window.get(), &buffer, &rect);
    int32_t status = native_window_lock(window.get(), &buffer, &rect);
    if (status) return false;

    ssize_t bytesCount = buffer.stride * bytesPerPixel(buffer.format);

@@ -184,6 +185,8 @@ static void android_view_TextureView_lockCanvas(JNIEnv* env, jobject,
        INVOKEV(dirtyRect, gRectClassInfo.set,
                int(rect.left), int(rect.top), int(rect.right), int(rect.bottom));
    }

    return true;
}

static void android_view_TextureView_unlockCanvasAndPost(JNIEnv* env, jobject,
@@ -213,7 +216,7 @@ static JNINativeMethod gMethods[] = {
    {   "nDestroyNativeWindow", "()V",
            (void*) android_view_TextureView_destroyNativeWindow },

    {   "nLockCanvas", "(ILandroid/graphics/Canvas;Landroid/graphics/Rect;)V",
    {   "nLockCanvas", "(ILandroid/graphics/Canvas;Landroid/graphics/Rect;)Z",
            (void*) android_view_TextureView_lockCanvas },
    {   "nUnlockCanvasAndPost", "(ILandroid/graphics/Canvas;)V",
            (void*) android_view_TextureView_unlockCanvasAndPost },
@@ -241,7 +244,8 @@ int register_android_view_TextureView(JNIEnv* env) {
    GET_FIELD_ID(gRectClassInfo.bottom, clazz, "bottom", "I");

    FIND_CLASS(clazz, "android/graphics/Canvas");
    GET_FIELD_ID(gCanvasClassInfo.mFinalizer, clazz, "mFinalizer", "Landroid/graphics/Canvas$CanvasFinalizer;");
    GET_FIELD_ID(gCanvasClassInfo.mFinalizer, clazz, "mFinalizer",
            "Landroid/graphics/Canvas$CanvasFinalizer;");
    GET_FIELD_ID(gCanvasClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "I");
    GET_FIELD_ID(gCanvasClassInfo.mSurfaceFormat, clazz, "mSurfaceFormat", "I");