Example #1
0
JNIEXPORT int JNICALL Java_com_mediatek_ut_SurfaceFlingerTest_connect(JNIEnv *_env, jobject /*_this*/,
    jobject native_window, jboolean useDefaultSize, jint w, jint h, jboolean updateScreen, jint api, jint format, jint colorIndex) {
    if (utProc == NULL)
        utProc = new SfUtProc();

    sp<ANativeWindow> window;
    utProc->mId++;
    LOGD("connect, native_window=%p, useDefaultSize=%d, w=%d, h=%d, updateScreen=%d, api=%d, format=%x, colorIndex=%d",
        native_window, useDefaultSize, w, h, updateScreen, api, format, colorIndex);

    if (native_window == NULL) {
        LOGW("native_window is null");
//not_valid_surface:
//        jniThrowException(_env, "java/lang/IllegalArgumentException",
//                "[SFT_jni] Make sure the SurfaceView or associated SurfaceHolder has a valid Surface");
        return -1;
    }

//    window = android_view_Surface_getNativeWindow(_env, native_window);
    window = ANativeWindow_fromSurface(_env, native_window);
    if (window == NULL) {
        LOGW("getNative window is null");
//        goto not_valid_surface;
        return -1;
    }

    utProc->connect(utProc->mId, window, useDefaultSize, w, h, updateScreen, api, format, colorIndex);

    return utProc->mId;
}
Example #2
0
// construct a camera client from an existing camera remote
sp<Camera> Camera::create(const sp<ICamera>& camera)
{
     LOGV("create");
     if (camera == 0) {
         LOGE("camera remote is a NULL pointer");
         return 0;
     }

    sp<Camera> c = new Camera();
    if (camera->connect(c) == NO_ERROR) {
        c->mStatus = NO_ERROR;
        c->mCamera = camera;
        camera->asBinder()->linkToDeath(c);
    }
    return c;
}
 AfterConnect() {
     cs = getCameraService();
     cc = new MCameraClient();
     c = cs->connect(cc);
     ASSERT(c != 0);
 }
status_t Camera3StreamSplitter::addOutputLocked(const sp<Surface>& outputQueue) {
    ATRACE_CALL();
    if (outputQueue == nullptr) {
        SP_LOGE("addOutput: outputQueue must not be NULL");
        return BAD_VALUE;
    }

    sp<IGraphicBufferProducer> gbp = outputQueue->getIGraphicBufferProducer();
    // Connect to the buffer producer
    sp<OutputListener> listener(new OutputListener(this, gbp));
    IInterface::asBinder(gbp)->linkToDeath(listener);
    status_t res = outputQueue->connect(NATIVE_WINDOW_API_CAMERA, listener);
    if (res != NO_ERROR) {
        SP_LOGE("addOutput: failed to connect (%d)", res);
        return res;
    }

    // Query consumer side buffer count, and update overall buffer count
    int maxConsumerBuffers = 0;
    res = static_cast<ANativeWindow*>(outputQueue.get())->query(
            outputQueue.get(),
            NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &maxConsumerBuffers);
    if (res != OK) {
        SP_LOGE("%s: Unable to query consumer undequeued buffer count"
              " for surface", __FUNCTION__);
        return res;
    }

    SP_LOGV("%s: Consumer wants %d buffers, Producer wants %zu", __FUNCTION__,
            maxConsumerBuffers, mMaxHalBuffers);
    size_t totalBufferCount = maxConsumerBuffers + mMaxHalBuffers;
    res = native_window_set_buffer_count(outputQueue.get(),
            totalBufferCount);
    if (res != OK) {
        SP_LOGE("%s: Unable to set buffer count for surface %p",
                __FUNCTION__, outputQueue.get());
        return res;
    }

    // Set dequeueBuffer/attachBuffer timeout if the consumer is not hw composer or hw texture.
    // We need skip these cases as timeout will disable the non-blocking (async) mode.
    uint64_t usage = 0;
    res = native_window_get_consumer_usage(static_cast<ANativeWindow*>(outputQueue.get()), &usage);
    if (!(usage & (GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_TEXTURE))) {
        outputQueue->setDequeueTimeout(kDequeueBufferTimeout);
    }

    res = gbp->allowAllocation(false);
    if (res != OK) {
        SP_LOGE("%s: Failed to turn off allocation for outputQueue", __FUNCTION__);
        return res;
    }

    // Add new entry into mOutputs
    mOutputs.push_back(gbp);
    mNotifiers[gbp] = listener;
    mOutputSlots[gbp] = std::make_unique<OutputSlots>(totalBufferCount);

    mMaxConsumerBuffers += maxConsumerBuffers;
    return NO_ERROR;
}