widget/gonk/nativewindow/GonkNativeWindowClientKK.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/nativewindow/GonkNativeWindowClientKK.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,674 @@
     1.4 +/*
     1.5 + * Copyright (C) 2010 The Android Open Source Project
     1.6 + * Copyright (C) 2013 Mozilla Foundation
     1.7 + *
     1.8 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.9 + * you may not use this file except in compliance with the License.
    1.10 + * You may obtain a copy of the License at
    1.11 + *
    1.12 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.13 + *
    1.14 + * Unless required by applicable law or agreed to in writing, software
    1.15 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.16 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.17 + * See the License for the specific language governing permissions and
    1.18 + * limitations under the License.
    1.19 + */
    1.20 +
    1.21 +#define LOG_TAG "GonkNativeWindowClient"
    1.22 +#define ATRACE_TAG ATRACE_TAG_GRAPHICS
    1.23 +//#define LOG_NDEBUG 0
    1.24 +
    1.25 +#include <android/native_window.h>
    1.26 +
    1.27 +#include <binder/Parcel.h>
    1.28 +
    1.29 +#include <utils/Log.h>
    1.30 +#include <utils/Trace.h>
    1.31 +
    1.32 +#include <ui/Fence.h>
    1.33 +
    1.34 +#include "GonkNativeWindowClientKK.h"
    1.35 +
    1.36 +namespace android {
    1.37 +
    1.38 +GonkNativeWindowClient::GonkNativeWindowClient(
    1.39 +        const sp<IGraphicBufferProducer>& bufferProducer,
    1.40 +        bool controlledByApp)
    1.41 +    : mGraphicBufferProducer(bufferProducer)
    1.42 +{
    1.43 +    // Initialize the ANativeWindow function pointers.
    1.44 +    ANativeWindow::setSwapInterval  = hook_setSwapInterval;
    1.45 +    ANativeWindow::dequeueBuffer    = hook_dequeueBuffer;
    1.46 +    ANativeWindow::cancelBuffer     = hook_cancelBuffer;
    1.47 +    ANativeWindow::queueBuffer      = hook_queueBuffer;
    1.48 +    ANativeWindow::query            = hook_query;
    1.49 +    ANativeWindow::perform          = hook_perform;
    1.50 +
    1.51 +    ANativeWindow::dequeueBuffer_DEPRECATED = hook_dequeueBuffer_DEPRECATED;
    1.52 +    ANativeWindow::cancelBuffer_DEPRECATED  = hook_cancelBuffer_DEPRECATED;
    1.53 +    ANativeWindow::lockBuffer_DEPRECATED    = hook_lockBuffer_DEPRECATED;
    1.54 +    ANativeWindow::queueBuffer_DEPRECATED   = hook_queueBuffer_DEPRECATED;
    1.55 +
    1.56 +    const_cast<int&>(ANativeWindow::minSwapInterval) = 0;
    1.57 +    const_cast<int&>(ANativeWindow::maxSwapInterval) = 1;
    1.58 +
    1.59 +    mReqWidth = 0;
    1.60 +    mReqHeight = 0;
    1.61 +    mReqFormat = 0;
    1.62 +    mReqUsage = 0;
    1.63 +    mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO;
    1.64 +    mCrop.clear();
    1.65 +    mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
    1.66 +    mTransform = 0;
    1.67 +    mDefaultWidth = 0;
    1.68 +    mDefaultHeight = 0;
    1.69 +    mUserWidth = 0;
    1.70 +    mUserHeight = 0;
    1.71 +    mTransformHint = 0;
    1.72 +    mConsumerRunningBehind = false;
    1.73 +    mConnectedToCpu = false;
    1.74 +    mProducerControlledByApp = controlledByApp;
    1.75 +    mSwapIntervalZero = false;
    1.76 +}
    1.77 +
    1.78 +GonkNativeWindowClient::~GonkNativeWindowClient() {
    1.79 +    if (mConnectedToCpu) {
    1.80 +        GonkNativeWindowClient::disconnect(NATIVE_WINDOW_API_CPU);
    1.81 +    }
    1.82 +}
    1.83 +
    1.84 +sp<IGraphicBufferProducer> GonkNativeWindowClient::getIGraphicBufferProducer() const {
    1.85 +    return mGraphicBufferProducer;
    1.86 +}
    1.87 +
    1.88 +int GonkNativeWindowClient::hook_setSwapInterval(ANativeWindow* window, int interval) {
    1.89 +    GonkNativeWindowClient* c = getSelf(window);
    1.90 +    return c->setSwapInterval(interval);
    1.91 +}
    1.92 +
    1.93 +int GonkNativeWindowClient::hook_dequeueBuffer(ANativeWindow* window,
    1.94 +        ANativeWindowBuffer** buffer, int* fenceFd) {
    1.95 +    GonkNativeWindowClient* c = getSelf(window);
    1.96 +    return c->dequeueBuffer(buffer, fenceFd);
    1.97 +}
    1.98 +
    1.99 +int GonkNativeWindowClient::hook_cancelBuffer(ANativeWindow* window,
   1.100 +        ANativeWindowBuffer* buffer, int fenceFd) {
   1.101 +    GonkNativeWindowClient* c = getSelf(window);
   1.102 +    return c->cancelBuffer(buffer, fenceFd);
   1.103 +}
   1.104 +
   1.105 +int GonkNativeWindowClient::hook_queueBuffer(ANativeWindow* window,
   1.106 +        ANativeWindowBuffer* buffer, int fenceFd) {
   1.107 +    GonkNativeWindowClient* c = getSelf(window);
   1.108 +    return c->queueBuffer(buffer, fenceFd);
   1.109 +}
   1.110 +
   1.111 +int GonkNativeWindowClient::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
   1.112 +        ANativeWindowBuffer** buffer) {
   1.113 +    GonkNativeWindowClient* c = getSelf(window);
   1.114 +    ANativeWindowBuffer* buf;
   1.115 +    int fenceFd = -1;
   1.116 +    int result = c->dequeueBuffer(&buf, &fenceFd);
   1.117 +    sp<Fence> fence(new Fence(fenceFd));
   1.118 +    int waitResult = fence->waitForever("dequeueBuffer_DEPRECATED");
   1.119 +    if (waitResult != OK) {
   1.120 +        ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d",
   1.121 +                waitResult);
   1.122 +        c->cancelBuffer(buf, -1);
   1.123 +        return waitResult;
   1.124 +    }
   1.125 +    *buffer = buf;
   1.126 +    return result;
   1.127 +}
   1.128 +
   1.129 +int GonkNativeWindowClient::hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
   1.130 +        ANativeWindowBuffer* buffer) {
   1.131 +    GonkNativeWindowClient* c = getSelf(window);
   1.132 +    return c->cancelBuffer(buffer, -1);
   1.133 +}
   1.134 +
   1.135 +int GonkNativeWindowClient::hook_lockBuffer_DEPRECATED(ANativeWindow* window,
   1.136 +        ANativeWindowBuffer* buffer) {
   1.137 +    GonkNativeWindowClient* c = getSelf(window);
   1.138 +    return c->lockBuffer_DEPRECATED(buffer);
   1.139 +}
   1.140 +
   1.141 +int GonkNativeWindowClient::hook_queueBuffer_DEPRECATED(ANativeWindow* window,
   1.142 +        ANativeWindowBuffer* buffer) {
   1.143 +    GonkNativeWindowClient* c = getSelf(window);
   1.144 +    return c->queueBuffer(buffer, -1);
   1.145 +}
   1.146 +
   1.147 +int GonkNativeWindowClient::hook_query(const ANativeWindow* window,
   1.148 +                                int what, int* value) {
   1.149 +    const GonkNativeWindowClient* c = getSelf(window);
   1.150 +    return c->query(what, value);
   1.151 +}
   1.152 +
   1.153 +int GonkNativeWindowClient::hook_perform(ANativeWindow* window, int operation, ...) {
   1.154 +    va_list args;
   1.155 +    va_start(args, operation);
   1.156 +    GonkNativeWindowClient* c = getSelf(window);
   1.157 +    return c->perform(operation, args);
   1.158 +}
   1.159 +
   1.160 +int GonkNativeWindowClient::setSwapInterval(int interval) {
   1.161 +    ATRACE_CALL();
   1.162 +    // EGL specification states:
   1.163 +    //  interval is silently clamped to minimum and maximum implementation
   1.164 +    //  dependent values before being stored.
   1.165 +
   1.166 +    if (interval < minSwapInterval)
   1.167 +        interval = minSwapInterval;
   1.168 +
   1.169 +    if (interval > maxSwapInterval)
   1.170 +        interval = maxSwapInterval;
   1.171 +
   1.172 +    return NO_ERROR;
   1.173 +}
   1.174 +
   1.175 +int GonkNativeWindowClient::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) {
   1.176 +    ATRACE_CALL();
   1.177 +    ALOGV("GonkNativeWindowClient::dequeueBuffer");
   1.178 +    Mutex::Autolock lock(mMutex);
   1.179 +    int buf = -1;
   1.180 +    int reqW = mReqWidth ? mReqWidth : mUserWidth;
   1.181 +    int reqH = mReqHeight ? mReqHeight : mUserHeight;
   1.182 +    sp<Fence> fence;
   1.183 +    status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, mSwapIntervalZero,
   1.184 +            reqW, reqH, mReqFormat, mReqUsage);
   1.185 +    if (result < 0) {
   1.186 +        ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(%d, %d, %d, %d)"
   1.187 +             "failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage,
   1.188 +             result);
   1.189 +        return result;
   1.190 +    }
   1.191 +    sp<GraphicBuffer>& gbuf(mSlots[buf].buffer);
   1.192 +
   1.193 +    // this should never happen
   1.194 +    ALOGE_IF(fence == NULL, "Surface::dequeueBuffer: received null Fence! buf=%d", buf);
   1.195 +
   1.196 +    if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) {
   1.197 +        freeAllBuffers();
   1.198 +    }
   1.199 +
   1.200 +    if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
   1.201 +        result = mGraphicBufferProducer->requestBuffer(buf, &gbuf);
   1.202 +        if (result != NO_ERROR) {
   1.203 +            ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", result);
   1.204 +            return result;
   1.205 +        }
   1.206 +    }
   1.207 +
   1.208 +    if (fence->isValid()) {
   1.209 +        *fenceFd = fence->dup();
   1.210 +        if (*fenceFd == -1) {
   1.211 +            ALOGE("dequeueBuffer: error duping fence: %d", errno);
   1.212 +            // dup() should never fail; something is badly wrong. Soldier on
   1.213 +            // and hope for the best; the worst that should happen is some
   1.214 +            // visible corruption that lasts until the next frame.
   1.215 +        }
   1.216 +    } else {
   1.217 +        *fenceFd = -1;
   1.218 +    }
   1.219 +
   1.220 +    *buffer = gbuf.get();
   1.221 +    return OK;
   1.222 +}
   1.223 +
   1.224 +int GonkNativeWindowClient::cancelBuffer(android_native_buffer_t* buffer,
   1.225 +        int fenceFd) {
   1.226 +    ATRACE_CALL();
   1.227 +    ALOGV("GonkNativeWindowClient::cancelBuffer");
   1.228 +    Mutex::Autolock lock(mMutex);
   1.229 +    int i = getSlotFromBufferLocked(buffer);
   1.230 +    if (i < 0) {
   1.231 +        return i;
   1.232 +    }
   1.233 +    sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE);
   1.234 +    mGraphicBufferProducer->cancelBuffer(i, fence);
   1.235 +    return OK;
   1.236 +}
   1.237 +
   1.238 +int GonkNativeWindowClient::getSlotFromBufferLocked(
   1.239 +        android_native_buffer_t* buffer) const {
   1.240 +    bool dumpedState = false;
   1.241 +    for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
   1.242 +        if (mSlots[i].buffer != NULL &&
   1.243 +                mSlots[i].buffer->handle == buffer->handle) {
   1.244 +            return i;
   1.245 +        }
   1.246 +    }
   1.247 +    ALOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle);
   1.248 +    return BAD_VALUE;
   1.249 +}
   1.250 +
   1.251 +int GonkNativeWindowClient::lockBuffer_DEPRECATED(android_native_buffer_t* buffer) {
   1.252 +    ALOGV("GonkNativeWindowClient::lockBuffer");
   1.253 +    Mutex::Autolock lock(mMutex);
   1.254 +    return OK;
   1.255 +}
   1.256 +
   1.257 +int GonkNativeWindowClient::queueBuffer(android_native_buffer_t* buffer, int fenceFd) {
   1.258 +    ATRACE_CALL();
   1.259 +    ALOGV("GonkNativeWindowClient::queueBuffer");
   1.260 +    Mutex::Autolock lock(mMutex);
   1.261 +    int64_t timestamp;
   1.262 +    bool isAutoTimestamp = false;
   1.263 +    if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) {
   1.264 +        timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
   1.265 +        isAutoTimestamp = true;
   1.266 +        ALOGV("GonkNativeWindowClient::queueBuffer making up timestamp: %.2f ms",
   1.267 +             timestamp / 1000000.f);
   1.268 +    } else {
   1.269 +        timestamp = mTimestamp;
   1.270 +    }
   1.271 +    int i = getSlotFromBufferLocked(buffer);
   1.272 +    if (i < 0) {
   1.273 +        return i;
   1.274 +    }
   1.275 +
   1.276 +
   1.277 +    // Make sure the crop rectangle is entirely inside the buffer.
   1.278 +    Rect crop;
   1.279 +    mCrop.intersect(Rect(buffer->width, buffer->height), &crop);
   1.280 +
   1.281 +    sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE);
   1.282 +    IGraphicBufferProducer::QueueBufferOutput output;
   1.283 +    IGraphicBufferProducer::QueueBufferInput input(timestamp, isAutoTimestamp,
   1.284 +            crop, mScalingMode, mTransform, mSwapIntervalZero, fence);
   1.285 +    status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output);
   1.286 +    if (err != OK)  {
   1.287 +        ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err);
   1.288 +    }
   1.289 +    uint32_t numPendingBuffers = 0;
   1.290 +    output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint,
   1.291 +            &numPendingBuffers);
   1.292 +
   1.293 +    mConsumerRunningBehind = (numPendingBuffers >= 2);
   1.294 +
   1.295 +    return err;
   1.296 +}
   1.297 +
   1.298 +int GonkNativeWindowClient::query(int what, int* value) const {
   1.299 +    ATRACE_CALL();
   1.300 +    ALOGV("GonkNativeWindowClient::query");
   1.301 +    { // scope for the lock
   1.302 +        Mutex::Autolock lock(mMutex);
   1.303 +        switch (what) {
   1.304 +            case NATIVE_WINDOW_FORMAT:
   1.305 +                if (mReqFormat) {
   1.306 +                    *value = mReqFormat;
   1.307 +                    return NO_ERROR;
   1.308 +                }
   1.309 +                break;
   1.310 +            case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: {
   1.311 +                //sp<ISurfaceComposer> composer(
   1.312 +                //        ComposerService::getComposerService());
   1.313 +                //if (composer->authenticateSurfaceTexture(mGraphicBufferProducer)) {
   1.314 +                //    *value = 1;
   1.315 +                //} else {
   1.316 +                    *value = 0;
   1.317 +                //}
   1.318 +                return NO_ERROR;
   1.319 +            }
   1.320 +            case NATIVE_WINDOW_CONCRETE_TYPE:
   1.321 +                *value = NATIVE_WINDOW_SURFACE;
   1.322 +                return NO_ERROR;
   1.323 +            case NATIVE_WINDOW_DEFAULT_WIDTH:
   1.324 +                *value = mUserWidth ? mUserWidth : mDefaultWidth;
   1.325 +                return NO_ERROR;
   1.326 +            case NATIVE_WINDOW_DEFAULT_HEIGHT:
   1.327 +                *value = mUserHeight ? mUserHeight : mDefaultHeight;
   1.328 +                return NO_ERROR;
   1.329 +            case NATIVE_WINDOW_TRANSFORM_HINT:
   1.330 +                *value = mTransformHint;
   1.331 +                return NO_ERROR;
   1.332 +            case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: {
   1.333 +                status_t err = NO_ERROR;
   1.334 +                if (!mConsumerRunningBehind) {
   1.335 +                    *value = 0;
   1.336 +                } else {
   1.337 +                    err = mGraphicBufferProducer->query(what, value);
   1.338 +                    if (err == NO_ERROR) {
   1.339 +                        mConsumerRunningBehind = *value;
   1.340 +                    }
   1.341 +                }
   1.342 +                return err;
   1.343 +            }
   1.344 +        }
   1.345 +    }
   1.346 +    return mGraphicBufferProducer->query(what, value);
   1.347 +}
   1.348 +
   1.349 +int GonkNativeWindowClient::perform(int operation, va_list args)
   1.350 +{
   1.351 +    int res = NO_ERROR;
   1.352 +    switch (operation) {
   1.353 +    case NATIVE_WINDOW_CONNECT:
   1.354 +        // deprecated. must return NO_ERROR.
   1.355 +        break;
   1.356 +    case NATIVE_WINDOW_DISCONNECT:
   1.357 +        // deprecated. must return NO_ERROR.
   1.358 +        break;
   1.359 +    case NATIVE_WINDOW_SET_USAGE:
   1.360 +        res = dispatchSetUsage(args);
   1.361 +        break;
   1.362 +    case NATIVE_WINDOW_SET_CROP:
   1.363 +        res = dispatchSetCrop(args);
   1.364 +        break;
   1.365 +    case NATIVE_WINDOW_SET_BUFFER_COUNT:
   1.366 +        res = dispatchSetBufferCount(args);
   1.367 +        break;
   1.368 +    case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
   1.369 +        res = dispatchSetBuffersGeometry(args);
   1.370 +        break;
   1.371 +    case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
   1.372 +        res = dispatchSetBuffersTransform(args);
   1.373 +        break;
   1.374 +    case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
   1.375 +        res = dispatchSetBuffersTimestamp(args);
   1.376 +        break;
   1.377 +    case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
   1.378 +        res = dispatchSetBuffersDimensions(args);
   1.379 +        break;
   1.380 +    case NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS:
   1.381 +        res = dispatchSetBuffersUserDimensions(args);
   1.382 +        break;
   1.383 +    case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
   1.384 +        res = dispatchSetBuffersFormat(args);
   1.385 +        break;
   1.386 +    case NATIVE_WINDOW_LOCK:
   1.387 +        res = dispatchLock(args);
   1.388 +        break;
   1.389 +    case NATIVE_WINDOW_UNLOCK_AND_POST:
   1.390 +        res = dispatchUnlockAndPost(args);
   1.391 +        break;
   1.392 +    case NATIVE_WINDOW_SET_SCALING_MODE:
   1.393 +        res = dispatchSetScalingMode(args);
   1.394 +        break;
   1.395 +    case NATIVE_WINDOW_API_CONNECT:
   1.396 +        res = dispatchConnect(args);
   1.397 +        break;
   1.398 +    case NATIVE_WINDOW_API_DISCONNECT:
   1.399 +        res = dispatchDisconnect(args);
   1.400 +        break;
   1.401 +    default:
   1.402 +        res = NAME_NOT_FOUND;
   1.403 +        break;
   1.404 +    }
   1.405 +    return res;
   1.406 +}
   1.407 +
   1.408 +int GonkNativeWindowClient::dispatchConnect(va_list args) {
   1.409 +    int api = va_arg(args, int);
   1.410 +    return connect(api);
   1.411 +}
   1.412 +
   1.413 +int GonkNativeWindowClient::dispatchDisconnect(va_list args) {
   1.414 +    int api = va_arg(args, int);
   1.415 +    return disconnect(api);
   1.416 +}
   1.417 +
   1.418 +int GonkNativeWindowClient::dispatchSetUsage(va_list args) {
   1.419 +    int usage = va_arg(args, int);
   1.420 +    return setUsage(usage);
   1.421 +}
   1.422 +
   1.423 +int GonkNativeWindowClient::dispatchSetCrop(va_list args) {
   1.424 +    android_native_rect_t const* rect = va_arg(args, android_native_rect_t*);
   1.425 +    return setCrop(reinterpret_cast<Rect const*>(rect));
   1.426 +}
   1.427 +
   1.428 +int GonkNativeWindowClient::dispatchSetBufferCount(va_list args) {
   1.429 +    size_t bufferCount = va_arg(args, size_t);
   1.430 +    return setBufferCount(bufferCount);
   1.431 +}
   1.432 +
   1.433 +int GonkNativeWindowClient::dispatchSetBuffersGeometry(va_list args) {
   1.434 +    int w = va_arg(args, int);
   1.435 +    int h = va_arg(args, int);
   1.436 +    int f = va_arg(args, int);
   1.437 +    int err = setBuffersDimensions(w, h);
   1.438 +    if (err != 0) {
   1.439 +        return err;
   1.440 +    }
   1.441 +    return setBuffersFormat(f);
   1.442 +}
   1.443 +
   1.444 +int GonkNativeWindowClient::dispatchSetBuffersDimensions(va_list args) {
   1.445 +    int w = va_arg(args, int);
   1.446 +    int h = va_arg(args, int);
   1.447 +    return setBuffersDimensions(w, h);
   1.448 +}
   1.449 +
   1.450 +int GonkNativeWindowClient::dispatchSetBuffersUserDimensions(va_list args) {
   1.451 +    int w = va_arg(args, int);
   1.452 +    int h = va_arg(args, int);
   1.453 +    return setBuffersUserDimensions(w, h);
   1.454 +}
   1.455 +
   1.456 +int GonkNativeWindowClient::dispatchSetBuffersFormat(va_list args) {
   1.457 +    int f = va_arg(args, int);
   1.458 +    return setBuffersFormat(f);
   1.459 +}
   1.460 +
   1.461 +int GonkNativeWindowClient::dispatchSetScalingMode(va_list args) {
   1.462 +    int m = va_arg(args, int);
   1.463 +    return setScalingMode(m);
   1.464 +}
   1.465 +
   1.466 +int GonkNativeWindowClient::dispatchSetBuffersTransform(va_list args) {
   1.467 +    int transform = va_arg(args, int);
   1.468 +    return setBuffersTransform(transform);
   1.469 +}
   1.470 +
   1.471 +int GonkNativeWindowClient::dispatchSetBuffersTimestamp(va_list args) {
   1.472 +    int64_t timestamp = va_arg(args, int64_t);
   1.473 +    return setBuffersTimestamp(timestamp);
   1.474 +}
   1.475 +
   1.476 +int GonkNativeWindowClient::dispatchLock(va_list args) {
   1.477 +    ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*);
   1.478 +    ARect* inOutDirtyBounds = va_arg(args, ARect*);
   1.479 +    return lock(outBuffer, inOutDirtyBounds);
   1.480 +}
   1.481 +
   1.482 +int GonkNativeWindowClient::dispatchUnlockAndPost(va_list args) {
   1.483 +    return unlockAndPost();
   1.484 +}
   1.485 +
   1.486 +
   1.487 +int GonkNativeWindowClient::connect(int api) {
   1.488 +    ATRACE_CALL();
   1.489 +    ALOGV("GonkNativeWindowClient::connect");
   1.490 +    static sp<BBinder> sLife = new BBinder();
   1.491 +    Mutex::Autolock lock(mMutex);
   1.492 +    IGraphicBufferProducer::QueueBufferOutput output;
   1.493 +    int err = mGraphicBufferProducer->connect(sLife, api, true, &output);
   1.494 +    if (err == NO_ERROR) {
   1.495 +        uint32_t numPendingBuffers = 0;
   1.496 +        output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint,
   1.497 +                &numPendingBuffers);
   1.498 +        mConsumerRunningBehind = (numPendingBuffers >= 2);
   1.499 +    }
   1.500 +    if (!err && api == NATIVE_WINDOW_API_CPU) {
   1.501 +        mConnectedToCpu = true;
   1.502 +    }
   1.503 +    return err;
   1.504 +}
   1.505 +
   1.506 +
   1.507 +int GonkNativeWindowClient::disconnect(int api) {
   1.508 +    ATRACE_CALL();
   1.509 +    ALOGV("GonkNativeWindowClient::disconnect");
   1.510 +    Mutex::Autolock lock(mMutex);
   1.511 +    freeAllBuffers();
   1.512 +    int err = mGraphicBufferProducer->disconnect(api);
   1.513 +    if (!err) {
   1.514 +        mReqFormat = 0;
   1.515 +        mReqWidth = 0;
   1.516 +        mReqHeight = 0;
   1.517 +        mReqUsage = 0;
   1.518 +        mCrop.clear();
   1.519 +        mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
   1.520 +        mTransform = 0;
   1.521 +        if (api == NATIVE_WINDOW_API_CPU) {
   1.522 +            mConnectedToCpu = false;
   1.523 +        }
   1.524 +    }
   1.525 +    return err;
   1.526 +}
   1.527 +
   1.528 +int GonkNativeWindowClient::setUsage(uint32_t reqUsage)
   1.529 +{
   1.530 +    ALOGV("GonkNativeWindowClient::setUsage");
   1.531 +    Mutex::Autolock lock(mMutex);
   1.532 +    mReqUsage = reqUsage;
   1.533 +    return OK;
   1.534 +}
   1.535 +
   1.536 +int GonkNativeWindowClient::setCrop(Rect const* rect)
   1.537 +{
   1.538 +    ATRACE_CALL();
   1.539 +
   1.540 +    Rect realRect;
   1.541 +    if (rect == NULL || rect->isEmpty()) {
   1.542 +        realRect.clear();
   1.543 +    } else {
   1.544 +        realRect = *rect;
   1.545 +    }
   1.546 +
   1.547 +    ALOGV("GonkNativeWindowClient::setCrop rect=[%d %d %d %d]",
   1.548 +            realRect.left, realRect.top, realRect.right, realRect.bottom);
   1.549 +
   1.550 +    Mutex::Autolock lock(mMutex);
   1.551 +    mCrop = realRect;
   1.552 +    return NO_ERROR;
   1.553 +}
   1.554 +
   1.555 +int GonkNativeWindowClient::setBufferCount(int bufferCount)
   1.556 +{
   1.557 +    ATRACE_CALL();
   1.558 +    ALOGV("GonkNativeWindowClient::setBufferCount");
   1.559 +    Mutex::Autolock lock(mMutex);
   1.560 +
   1.561 +    status_t err = mGraphicBufferProducer->setBufferCount(bufferCount);
   1.562 +    ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s",
   1.563 +            bufferCount, strerror(-err));
   1.564 +
   1.565 +    if (err == NO_ERROR) {
   1.566 +        freeAllBuffers();
   1.567 +    }
   1.568 +
   1.569 +    return err;
   1.570 +}
   1.571 +
   1.572 +int GonkNativeWindowClient::setBuffersDimensions(int w, int h)
   1.573 +{
   1.574 +    ATRACE_CALL();
   1.575 +    ALOGV("GonkNativeWindowClient::setBuffersDimensions");
   1.576 +
   1.577 +    if (w<0 || h<0)
   1.578 +        return BAD_VALUE;
   1.579 +
   1.580 +    if ((w && !h) || (!w && h))
   1.581 +        return BAD_VALUE;
   1.582 +
   1.583 +    Mutex::Autolock lock(mMutex);
   1.584 +    mReqWidth = w;
   1.585 +    mReqHeight = h;
   1.586 +    return NO_ERROR;
   1.587 +}
   1.588 +
   1.589 +int GonkNativeWindowClient::setBuffersUserDimensions(int w, int h)
   1.590 +{
   1.591 +    ATRACE_CALL();
   1.592 +    ALOGV("GonkNativeWindowClient::setBuffersUserDimensions");
   1.593 +
   1.594 +    if (w<0 || h<0)
   1.595 +        return BAD_VALUE;
   1.596 +
   1.597 +    if ((w && !h) || (!w && h))
   1.598 +        return BAD_VALUE;
   1.599 +
   1.600 +    Mutex::Autolock lock(mMutex);
   1.601 +    mUserWidth = w;
   1.602 +    mUserHeight = h;
   1.603 +    return NO_ERROR;
   1.604 +}
   1.605 +
   1.606 +int GonkNativeWindowClient::setBuffersFormat(int format)
   1.607 +{
   1.608 +    ALOGV("GonkNativeWindowClient::setBuffersFormat");
   1.609 +
   1.610 +    if (format<0)
   1.611 +        return BAD_VALUE;
   1.612 +
   1.613 +    Mutex::Autolock lock(mMutex);
   1.614 +    mReqFormat = format;
   1.615 +    return NO_ERROR;
   1.616 +}
   1.617 +
   1.618 +int GonkNativeWindowClient::setScalingMode(int mode)
   1.619 +{
   1.620 +    ATRACE_CALL();
   1.621 +    ALOGV("GonkNativeWindowClient::setScalingMode(%d)", mode);
   1.622 +
   1.623 +    switch (mode) {
   1.624 +        case NATIVE_WINDOW_SCALING_MODE_FREEZE:
   1.625 +        case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
   1.626 +        case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
   1.627 +            break;
   1.628 +        default:
   1.629 +            ALOGE("unknown scaling mode: %d", mode);
   1.630 +            return BAD_VALUE;
   1.631 +    }
   1.632 +
   1.633 +    Mutex::Autolock lock(mMutex);
   1.634 +    mScalingMode = mode;
   1.635 +    return NO_ERROR;
   1.636 +}
   1.637 +
   1.638 +int GonkNativeWindowClient::setBuffersTransform(int transform)
   1.639 +{
   1.640 +    ATRACE_CALL();
   1.641 +    ALOGV("GonkNativeWindowClient::setBuffersTransform");
   1.642 +    Mutex::Autolock lock(mMutex);
   1.643 +    mTransform = transform;
   1.644 +    return NO_ERROR;
   1.645 +}
   1.646 +
   1.647 +int GonkNativeWindowClient::setBuffersTimestamp(int64_t timestamp)
   1.648 +{
   1.649 +    ALOGV("GonkNativeWindowClient::setBuffersTimestamp");
   1.650 +    Mutex::Autolock lock(mMutex);
   1.651 +    mTimestamp = timestamp;
   1.652 +    return NO_ERROR;
   1.653 +}
   1.654 +
   1.655 +void GonkNativeWindowClient::freeAllBuffers() {
   1.656 +    for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
   1.657 +        mSlots[i].buffer = 0;
   1.658 +    }
   1.659 +}
   1.660 +
   1.661 +// ----------------------------------------------------------------------
   1.662 +// the lock/unlock APIs must be used from the same thread
   1.663 +
   1.664 +// ----------------------------------------------------------------------------
   1.665 +
   1.666 +status_t GonkNativeWindowClient::lock(
   1.667 +        ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds)
   1.668 +{
   1.669 +    return INVALID_OPERATION;
   1.670 +}
   1.671 +
   1.672 +status_t GonkNativeWindowClient::unlockAndPost()
   1.673 +{
   1.674 +    return INVALID_OPERATION;
   1.675 +}
   1.676 +
   1.677 +}; // namespace android

mercurial