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

Commit 0b722fe9 authored by Jeff Brown's avatar Jeff Brown
Browse files

Use new surface flinger API.

Change-Id: Ic888577408a59a36481a48010e19c5e77c24e211
parent d59db50a
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include <ui/DisplayInfo.h>
#include <ui/FramebufferNativeWindow.h>

#include <gui/ISurfaceComposer.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>

@@ -216,14 +217,16 @@ status_t BootAnimation::initTexture(void* buffer, size_t len)
status_t BootAnimation::readyToRun() {
    mAssets.addDefaultAssets();

    sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
            ISurfaceComposer::eDisplayIdMain));
    DisplayInfo dinfo;
    status_t status = SurfaceComposerClient::getDisplayInfo(0, &dinfo);
    status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
    if (status)
        return -1;

    // create the native surface
    sp<SurfaceControl> control = session()->createSurface(
            0, dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
    sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
            dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);

    SurfaceComposerClient::openGlobalTransaction();
    control->setLayer(0x40000000);
+13 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

#include <binder/IMemory.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/ISurfaceComposer.h>

#include <SkImageEncoder.h>
#include <SkBitmap.h>
@@ -33,15 +34,18 @@

using namespace android;

static uint32_t DEFAULT_DISPLAY_ID = ISurfaceComposer::eDisplayIdMain;

static void usage(const char* pname)
{
    fprintf(stderr,
            "usage: %s [-hp] [FILENAME]\n"
            "usage: %s [-hp] [-d display-id] [FILENAME]\n"
            "   -h: this message\n"
            "   -p: save the file as a png.\n"
            "   -d: specify the display id to capture, default %d.\n"
            "If FILENAME ends with .png it will be saved as a png.\n"
            "If FILENAME is not given, the results will be printed to stdout.\n",
            pname
            pname, DEFAULT_DISPLAY_ID
    );
}

@@ -87,12 +91,16 @@ int main(int argc, char** argv)
{
    const char* pname = argv[0];
    bool png = false;
    int32_t displayId = DEFAULT_DISPLAY_ID;
    int c;
    while ((c = getopt(argc, argv, "ph")) != -1) {
    while ((c = getopt(argc, argv, "phd:")) != -1) {
        switch (c) {
            case 'p':
                png = true;
                break;
            case 'd':
                displayId = atoi(optarg);
                break;
            case '?':
            case 'h':
                usage(pname);
@@ -131,7 +139,8 @@ int main(int argc, char** argv)
    size_t size = 0;

    ScreenshotClient screenshot;
    if (screenshot.update() == NO_ERROR) {
    sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay(displayId);
    if (display != NULL && screenshot.update(display) == NO_ERROR) {
        base = screenshot.getPixels();
        w = screenshot.getWidth();
        h = screenshot.getHeight();
+17 −4
Original line number Diff line number Diff line
@@ -17,9 +17,15 @@
package android.view;

import android.content.res.CompatibilityInfo.Translator;
import android.graphics.*;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.SurfaceTexture;
import android.os.Parcelable;
import android.os.Parcel;
import android.os.Process;
import android.os.SystemProperties;
import android.util.Log;

@@ -250,13 +256,20 @@ public class Surface implements Parcelable {
    public Surface(SurfaceSession s,
            int pid, String name, int layerStack, int w, int h, int format, int flags)
        throws OutOfResourcesException {
        // FIXME: remove pid and layerstack arguments
        checkHeadless();

        if (DEBUG_RELEASE) {
            mCreationStack = new Exception();
        }

        if (name == null) {
            name = "<pid " + Process.myPid() + ">";
        }

        mCanvas = new CompatibleCanvas();
        init(s, pid, name, layerStack, w, h, format, flags);
        init(s, name, w, h, format, flags);
        setLayerStack(layerStack);
        mName = name;
    }

@@ -496,8 +509,8 @@ public class Surface implements Parcelable {
        }
    }
    
    private native void init(SurfaceSession s,
            int pid, String name, int layerStack, int w, int h, int format, int flags)
    private native void init(SurfaceSession s, String name,
            int w, int h, int format, int flags)
            throws OutOfResourcesException;

    private native void init(Parcel source) throws OutOfResourcesException;
+21 −13
Original line number Diff line number Diff line
@@ -24,26 +24,34 @@ package android.view;
 * {@hide}
 */
public class SurfaceSession {
    private int mClient;

    private native void nativeInit();
    private native void nativeDestroy();
    private native void nativeKill();

    /** Create a new connection with the surface flinger. */
    public SurfaceSession() {
        init();
        nativeInit();
    }

    /** Forcibly detach native resources associated with this object.
     *  Unlike destroy(), after this call any surfaces that were created
     *  from the session will no longer work. The session itself is destroyed.
     */
    public native void kill();

    /* no user serviceable parts here ... */
    @Override
    protected void finalize() throws Throwable {
        destroy();
        try {
            nativeDestroy();
        } finally {
            super.finalize();
        }
    }

    private native void init();
    private native void destroy();
    
    private int mClient;
    /**
     * Forcibly detach native resources associated with this object.
     * Unlike destroy(), after this call any surfaces that were created
     * from the session will no longer work. The session itself is destroyed.
     */
    public void kill() {
        nativeKill();
    }
}
+32 −30
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@

#include <binder/IMemory.h>

#include <gui/ISurfaceComposer.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/SurfaceTexture.h>
@@ -107,14 +108,14 @@ static no_t no;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------

static void SurfaceSession_init(JNIEnv* env, jobject clazz)
static void SurfaceSession_nativeInit(JNIEnv* env, jobject clazz)
{
    sp<SurfaceComposerClient> client = new SurfaceComposerClient;
    client->incStrong(clazz);
    env->SetIntField(clazz, sso.client, (int)client.get());
}

static void SurfaceSession_destroy(JNIEnv* env, jobject clazz)
static void SurfaceSession_nativeDestroy(JNIEnv* env, jobject clazz)
{
    SurfaceComposerClient* client =
            (SurfaceComposerClient*)env->GetIntField(clazz, sso.client);
@@ -124,7 +125,7 @@ static void SurfaceSession_destroy(JNIEnv* env, jobject clazz)
    }
}

static void SurfaceSession_kill(JNIEnv* env, jobject clazz)
static void SurfaceSession_nativeKill(JNIEnv* env, jobject clazz)
{
    SurfaceComposerClient* client =
            (SurfaceComposerClient*)env->GetIntField(clazz, sso.client);
@@ -221,7 +222,7 @@ void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& surface)
static void Surface_init(
        JNIEnv* env, jobject clazz,
        jobject session,
        jint, jstring jname, jint layerStack, jint w, jint h, jint format, jint flags)
        jstring jname, jint w, jint h, jint format, jint flags)
{
    if (session == NULL) {
        doThrowNPE(env);
@@ -231,15 +232,10 @@ static void Surface_init(
    SurfaceComposerClient* client =
            (SurfaceComposerClient*)env->GetIntField(session, sso.client);

    sp<SurfaceControl> surface;
    if (jname == NULL) {
        surface = client->createSurface(layerStack, w, h, format, flags);
    } else {
    const jchar* str = env->GetStringCritical(jname, 0);
    const String8 name(str, env->GetStringLength(jname));
    env->ReleaseStringCritical(jname, str);
        surface = client->createSurface(name, layerStack, w, h, format, flags);
    }
    sp<SurfaceControl> surface = client->createSurface(name, w, h, format, flags);

    if (surface == 0) {
        jniThrowException(env, OutOfResourcesException, NULL);
@@ -473,12 +469,11 @@ static void Surface_closeTransaction(
}

static void Surface_setOrientation(
        JNIEnv* env, jobject clazz, jint display, jint orientation)
        JNIEnv* env, jobject clazz, jint, jint orientation)
{
    int err = SurfaceComposerClient::setOrientation(display, orientation, 0);
    if (err < 0) {
        doThrowIAE(env);
    }
    sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay(
            ISurfaceComposer::eDisplayIdMain);
    SurfaceComposerClient::setDisplayOrientation(display, orientation);
}

class ScreenshotPixelRef : public SkPixelRef {
@@ -492,12 +487,13 @@ public:
        SkSafeUnref(fCTable);
    }

    status_t update(int width, int height, int minLayer, int maxLayer, bool allLayers) {
    status_t update(const sp<IBinder>& display, int width, int height,
            int minLayer, int maxLayer, bool allLayers) {
        status_t res = (width > 0 && height > 0)
                ? (allLayers
                        ? mScreenshot.update(width, height)
                        : mScreenshot.update(width, height, minLayer, maxLayer))
                : mScreenshot.update();
                        ? mScreenshot.update(display, width, height)
                        : mScreenshot.update(display, width, height, minLayer, maxLayer))
                : mScreenshot.update(display);
        if (res != NO_ERROR) {
            return res;
        }
@@ -538,11 +534,15 @@ private:
    typedef SkPixelRef INHERITED;
};

static jobject doScreenshot(JNIEnv* env, jobject clazz, jint width, jint height,
static jobject doScreenshot(JNIEnv* env, jobject clazz,
        jint width, jint height,
        jint minLayer, jint maxLayer, bool allLayers)
{
    sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay(
            ISurfaceComposer::eDisplayIdMain);
    ScreenshotPixelRef* pixels = new ScreenshotPixelRef(NULL);
    if (pixels->update(width, height, minLayer, maxLayer, allLayers) != NO_ERROR) {
    if (pixels->update(display, width, height,
            minLayer, maxLayer, allLayers) != NO_ERROR) {
        delete pixels;
        return 0;
    }
@@ -721,8 +721,10 @@ static void Surface_setLayerStack(JNIEnv* env, jobject thiz, jint layerStack)
{
    const sp<SurfaceControl>& surface(getSurfaceControl(env, thiz));
    if (surface == 0) return;

    // TODO(mathias): Everything.
    status_t err = surface->setLayerStack(layerStack);
    if (err<0 && err!=NO_INIT) {
        doThrowIAE(env);
    }
}

// ----------------------------------------------------------------------------
@@ -826,14 +828,14 @@ static void Surface_writeToParcel(
static void nativeClassInit(JNIEnv* env, jclass clazz);

static JNINativeMethod gSurfaceSessionMethods[] = {
    {"init",     "()V",  (void*)SurfaceSession_init },
    {"destroy",  "()V",  (void*)SurfaceSession_destroy },
    {"kill",     "()V",  (void*)SurfaceSession_kill },
    {"nativeInit",     "()V",  (void*)SurfaceSession_nativeInit },
    {"nativeDestroy",  "()V",  (void*)SurfaceSession_nativeDestroy },
    {"nativeKill",     "()V",  (void*)SurfaceSession_nativeKill },
};

static JNINativeMethod gSurfaceMethods[] = {
    {"nativeClassInit",     "()V",  (void*)nativeClassInit },
    {"init",                "(Landroid/view/SurfaceSession;ILjava/lang/String;IIIII)V",  (void*)Surface_init },
    {"init",                "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)V",  (void*)Surface_init },
    {"init",                "(Landroid/os/Parcel;)V",  (void*)Surface_initParcel },
    {"initFromSurfaceTexture", "(Landroid/graphics/SurfaceTexture;)V", (void*)Surface_initFromSurfaceTexture },
    {"getIdentity",         "()I",  (void*)Surface_getIdentity },
Loading