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

Commit 52800617 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

Refactoring: Rename SurfaceTextureClient to Surface

Change-Id: I5a218ca11abeeec05e3a4c3cfc581bcc788814ea
parent 29479ebe
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -32,8 +32,9 @@ import dalvik.system.CloseGuard;
public class Surface implements Parcelable {
    private static final String TAG = "Surface";

    private native int nativeCreateFromSurfaceTexture(SurfaceTexture surfaceTexture)
    private static native int nativeCreateFromSurfaceTexture(SurfaceTexture surfaceTexture)
            throws OutOfResourcesException;

    private native Canvas nativeLockCanvas(int nativeObject, Rect dirty);
    private native void nativeUnlockCanvasAndPost(int nativeObject, Canvas canvas);

+3 −3
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
#include <stdio.h>

#include <gui/GLConsumer.h>
#include <gui/SurfaceTextureClient.h>
#include <gui/Surface.h>

#include <android_runtime/AndroidRuntime.h>

@@ -86,8 +86,8 @@ sp<ANativeWindow> android_SurfaceTexture_getNativeWindow(
        JNIEnv* env, jobject thiz)
{
    sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
    sp<SurfaceTextureClient> surfaceTextureClient(surfaceTexture != NULL ?
            new SurfaceTextureClient(surfaceTexture->getBufferQueue()) : NULL);
    sp<Surface> surfaceTextureClient(surfaceTexture != NULL ?
            new Surface(surfaceTexture->getBufferQueue()) : NULL);
    return surfaceTextureClient;
}

+2 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@

#include <gui/Surface.h>
#include <gui/GLConsumer.h>
#include <gui/SurfaceTextureClient.h>
#include <gui/Surface.h>

#include <ui/ANativeObjectBase.h>

@@ -631,7 +631,7 @@ not_valid_surface:
    if (surfaceTexture == NULL)
        goto not_valid_surface;

    window = new android::SurfaceTextureClient(surfaceTexture->getBufferQueue());
    window = new android::Surface(surfaceTexture->getBufferQueue());

    if (window == NULL)
        goto not_valid_surface;
+23 −14
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <android_runtime/android_graphics_SurfaceTexture.h>

#include <gui/Surface.h>
#include <gui/SurfaceControl.h>
#include <gui/GLConsumer.h>

#include <ui/Rect.h>
@@ -111,7 +112,13 @@ jobject android_view_Surface_createFromIGraphicBufferProducer(JNIEnv* env,

// ----------------------------------------------------------------------------

static jint nativeCreateFromSurfaceTexture(JNIEnv* env, jobject surfaceObj,
static bool isSurfaceValid(const sp<Surface>& sur) {
    return sur != 0 && sur->getISurfaceTexture() != 0;
}

// ----------------------------------------------------------------------------

static jint nativeCreateFromSurfaceTexture(JNIEnv* env, jclass clazz,
        jobject surfaceTextureObj) {
    sp<GLConsumer> st(SurfaceTexture_getSurfaceTexture(env, surfaceTextureObj));
    if (st == NULL) {
@@ -127,7 +134,7 @@ static jint nativeCreateFromSurfaceTexture(JNIEnv* env, jobject surfaceObj,
        return 0;
    }

    surface->incStrong(surfaceObj);
    surface->incStrong(clazz);
    return int(surface.get());
}

@@ -143,12 +150,12 @@ static void nativeDestroy(JNIEnv* env, jclass clazz, jint nativeObject) {

static jboolean nativeIsValid(JNIEnv* env, jclass clazz, jint nativeObject) {
    sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject));
    return Surface::isValid(sur) ? JNI_TRUE : JNI_FALSE;
    return isSurfaceValid(sur) ? JNI_TRUE : JNI_FALSE;
}

static jboolean nativeIsConsumerRunningBehind(JNIEnv* env, jclass clazz, jint nativeObject) {
    sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject));
    if (!Surface::isValid(sur)) {
    if (!isSurfaceValid(sur)) {
        doThrowIAE(env);
        return JNI_FALSE;
    }
@@ -176,7 +183,7 @@ static inline SkBitmap::Config convertPixelFormat(PixelFormat format) {
static jobject nativeLockCanvas(JNIEnv* env, jobject surfaceObj, jint nativeObject, jobject dirtyRectObj) {
    sp<Surface> surface(reinterpret_cast<Surface *>(nativeObject));

    if (!Surface::isValid(surface)) {
    if (!isSurfaceValid(surface)) {
        doThrowIAE(env);
        return NULL;
    }
@@ -196,9 +203,11 @@ static jobject nativeLockCanvas(JNIEnv* env, jobject surfaceObj, jint nativeObje
        dirtyRegion.set(Rect(0x3FFF, 0x3FFF));
    }

    Surface::SurfaceInfo info;
    status_t err = surface->lock(&info, &dirtyRegion);
    ANativeWindow_Buffer outBuffer;
    Rect dirtyBounds(dirtyRegion.getBounds());
    status_t err = surface->lock(&outBuffer, &dirtyBounds);
    if (err < 0) {
        dirtyRegion.set(dirtyBounds);
        const char* const exception = (err == NO_MEMORY) ?
                OutOfResourcesException :
                "java/lang/IllegalArgumentException";
@@ -208,18 +217,18 @@ static jobject nativeLockCanvas(JNIEnv* env, jobject surfaceObj, jint nativeObje

    // Associate a SkCanvas object to this surface
    jobject canvasObj = env->GetObjectField(surfaceObj, gSurfaceClassInfo.mCanvas);
    env->SetIntField(canvasObj, gCanvasClassInfo.mSurfaceFormat, info.format);
    env->SetIntField(canvasObj, gCanvasClassInfo.mSurfaceFormat, outBuffer.format);

    SkCanvas* nativeCanvas = reinterpret_cast<SkCanvas*>(
            env->GetIntField(canvasObj, gCanvasClassInfo.mNativeCanvas));
    SkBitmap bitmap;
    ssize_t bpr = info.s * bytesPerPixel(info.format);
    bitmap.setConfig(convertPixelFormat(info.format), info.w, info.h, bpr);
    if (info.format == PIXEL_FORMAT_RGBX_8888) {
    ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
    bitmap.setConfig(convertPixelFormat(outBuffer.format), outBuffer.width, outBuffer.height, bpr);
    if (outBuffer.format == PIXEL_FORMAT_RGBX_8888) {
        bitmap.setIsOpaque(true);
    }
    if (info.w > 0 && info.h > 0) {
        bitmap.setPixels(info.bits);
    if (outBuffer.width > 0 && outBuffer.height > 0) {
        bitmap.setPixels(outBuffer.bits);
    } else {
        // be safe with an empty bitmap.
        bitmap.setPixels(NULL);
@@ -263,7 +272,7 @@ static void nativeUnlockCanvasAndPost(JNIEnv* env, jobject surfaceObj, jint nati
    }

    sp<Surface> surface(reinterpret_cast<Surface *>(nativeObject));
    if (!Surface::isValid(surface)) {
    if (!isSurfaceValid(surface)) {
        return;
    }

+1 −1
Original line number Diff line number Diff line
@@ -320,7 +320,7 @@ static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
    sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
    if (token == NULL) return;
    sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
    sp<IGraphicBufferProducer> bufferProducer(sur->getSurfaceTexture());
    sp<IGraphicBufferProducer> bufferProducer(sur->getIGraphicBufferProducer());
    SurfaceComposerClient::setDisplaySurface(token, bufferProducer);
}

Loading