michael@0: /* michael@0: * Copyright (C) 2010 The Android Open Source Project michael@0: * Copyright (C) 2013 Mozilla Foundation michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #define LOG_TAG "GonkNativeWindowClient" michael@0: #define ATRACE_TAG ATRACE_TAG_GRAPHICS michael@0: //#define LOG_NDEBUG 0 michael@0: michael@0: #include michael@0: michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: michael@0: #include "GonkNativeWindowClientKK.h" michael@0: michael@0: namespace android { michael@0: michael@0: GonkNativeWindowClient::GonkNativeWindowClient( michael@0: const sp& bufferProducer, michael@0: bool controlledByApp) michael@0: : mGraphicBufferProducer(bufferProducer) michael@0: { michael@0: // Initialize the ANativeWindow function pointers. michael@0: ANativeWindow::setSwapInterval = hook_setSwapInterval; michael@0: ANativeWindow::dequeueBuffer = hook_dequeueBuffer; michael@0: ANativeWindow::cancelBuffer = hook_cancelBuffer; michael@0: ANativeWindow::queueBuffer = hook_queueBuffer; michael@0: ANativeWindow::query = hook_query; michael@0: ANativeWindow::perform = hook_perform; michael@0: michael@0: ANativeWindow::dequeueBuffer_DEPRECATED = hook_dequeueBuffer_DEPRECATED; michael@0: ANativeWindow::cancelBuffer_DEPRECATED = hook_cancelBuffer_DEPRECATED; michael@0: ANativeWindow::lockBuffer_DEPRECATED = hook_lockBuffer_DEPRECATED; michael@0: ANativeWindow::queueBuffer_DEPRECATED = hook_queueBuffer_DEPRECATED; michael@0: michael@0: const_cast(ANativeWindow::minSwapInterval) = 0; michael@0: const_cast(ANativeWindow::maxSwapInterval) = 1; michael@0: michael@0: mReqWidth = 0; michael@0: mReqHeight = 0; michael@0: mReqFormat = 0; michael@0: mReqUsage = 0; michael@0: mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO; michael@0: mCrop.clear(); michael@0: mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; michael@0: mTransform = 0; michael@0: mDefaultWidth = 0; michael@0: mDefaultHeight = 0; michael@0: mUserWidth = 0; michael@0: mUserHeight = 0; michael@0: mTransformHint = 0; michael@0: mConsumerRunningBehind = false; michael@0: mConnectedToCpu = false; michael@0: mProducerControlledByApp = controlledByApp; michael@0: mSwapIntervalZero = false; michael@0: } michael@0: michael@0: GonkNativeWindowClient::~GonkNativeWindowClient() { michael@0: if (mConnectedToCpu) { michael@0: GonkNativeWindowClient::disconnect(NATIVE_WINDOW_API_CPU); michael@0: } michael@0: } michael@0: michael@0: sp GonkNativeWindowClient::getIGraphicBufferProducer() const { michael@0: return mGraphicBufferProducer; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_setSwapInterval(ANativeWindow* window, int interval) { michael@0: GonkNativeWindowClient* c = getSelf(window); michael@0: return c->setSwapInterval(interval); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_dequeueBuffer(ANativeWindow* window, michael@0: ANativeWindowBuffer** buffer, int* fenceFd) { michael@0: GonkNativeWindowClient* c = getSelf(window); michael@0: return c->dequeueBuffer(buffer, fenceFd); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_cancelBuffer(ANativeWindow* window, michael@0: ANativeWindowBuffer* buffer, int fenceFd) { michael@0: GonkNativeWindowClient* c = getSelf(window); michael@0: return c->cancelBuffer(buffer, fenceFd); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_queueBuffer(ANativeWindow* window, michael@0: ANativeWindowBuffer* buffer, int fenceFd) { michael@0: GonkNativeWindowClient* c = getSelf(window); michael@0: return c->queueBuffer(buffer, fenceFd); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, michael@0: ANativeWindowBuffer** buffer) { michael@0: GonkNativeWindowClient* c = getSelf(window); michael@0: ANativeWindowBuffer* buf; michael@0: int fenceFd = -1; michael@0: int result = c->dequeueBuffer(&buf, &fenceFd); michael@0: sp fence(new Fence(fenceFd)); michael@0: int waitResult = fence->waitForever("dequeueBuffer_DEPRECATED"); michael@0: if (waitResult != OK) { michael@0: ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d", michael@0: waitResult); michael@0: c->cancelBuffer(buf, -1); michael@0: return waitResult; michael@0: } michael@0: *buffer = buf; michael@0: return result; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_cancelBuffer_DEPRECATED(ANativeWindow* window, michael@0: ANativeWindowBuffer* buffer) { michael@0: GonkNativeWindowClient* c = getSelf(window); michael@0: return c->cancelBuffer(buffer, -1); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_lockBuffer_DEPRECATED(ANativeWindow* window, michael@0: ANativeWindowBuffer* buffer) { michael@0: GonkNativeWindowClient* c = getSelf(window); michael@0: return c->lockBuffer_DEPRECATED(buffer); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_queueBuffer_DEPRECATED(ANativeWindow* window, michael@0: ANativeWindowBuffer* buffer) { michael@0: GonkNativeWindowClient* c = getSelf(window); michael@0: return c->queueBuffer(buffer, -1); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_query(const ANativeWindow* window, michael@0: int what, int* value) { michael@0: const GonkNativeWindowClient* c = getSelf(window); michael@0: return c->query(what, value); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::hook_perform(ANativeWindow* window, int operation, ...) { michael@0: va_list args; michael@0: va_start(args, operation); michael@0: GonkNativeWindowClient* c = getSelf(window); michael@0: return c->perform(operation, args); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setSwapInterval(int interval) { michael@0: ATRACE_CALL(); michael@0: // EGL specification states: michael@0: // interval is silently clamped to minimum and maximum implementation michael@0: // dependent values before being stored. michael@0: michael@0: if (interval < minSwapInterval) michael@0: interval = minSwapInterval; michael@0: michael@0: if (interval > maxSwapInterval) michael@0: interval = maxSwapInterval; michael@0: michael@0: return NO_ERROR; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::dequeueBuffer"); michael@0: Mutex::Autolock lock(mMutex); michael@0: int buf = -1; michael@0: int reqW = mReqWidth ? mReqWidth : mUserWidth; michael@0: int reqH = mReqHeight ? mReqHeight : mUserHeight; michael@0: sp fence; michael@0: status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, mSwapIntervalZero, michael@0: reqW, reqH, mReqFormat, mReqUsage); michael@0: if (result < 0) { michael@0: ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(%d, %d, %d, %d)" michael@0: "failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage, michael@0: result); michael@0: return result; michael@0: } michael@0: sp& gbuf(mSlots[buf].buffer); michael@0: michael@0: // this should never happen michael@0: ALOGE_IF(fence == NULL, "Surface::dequeueBuffer: received null Fence! buf=%d", buf); michael@0: michael@0: if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) { michael@0: freeAllBuffers(); michael@0: } michael@0: michael@0: if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) { michael@0: result = mGraphicBufferProducer->requestBuffer(buf, &gbuf); michael@0: if (result != NO_ERROR) { michael@0: ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", result); michael@0: return result; michael@0: } michael@0: } michael@0: michael@0: if (fence->isValid()) { michael@0: *fenceFd = fence->dup(); michael@0: if (*fenceFd == -1) { michael@0: ALOGE("dequeueBuffer: error duping fence: %d", errno); michael@0: // dup() should never fail; something is badly wrong. Soldier on michael@0: // and hope for the best; the worst that should happen is some michael@0: // visible corruption that lasts until the next frame. michael@0: } michael@0: } else { michael@0: *fenceFd = -1; michael@0: } michael@0: michael@0: *buffer = gbuf.get(); michael@0: return OK; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::cancelBuffer(android_native_buffer_t* buffer, michael@0: int fenceFd) { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::cancelBuffer"); michael@0: Mutex::Autolock lock(mMutex); michael@0: int i = getSlotFromBufferLocked(buffer); michael@0: if (i < 0) { michael@0: return i; michael@0: } michael@0: sp fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); michael@0: mGraphicBufferProducer->cancelBuffer(i, fence); michael@0: return OK; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::getSlotFromBufferLocked( michael@0: android_native_buffer_t* buffer) const { michael@0: bool dumpedState = false; michael@0: for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { michael@0: if (mSlots[i].buffer != NULL && michael@0: mSlots[i].buffer->handle == buffer->handle) { michael@0: return i; michael@0: } michael@0: } michael@0: ALOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle); michael@0: return BAD_VALUE; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::lockBuffer_DEPRECATED(android_native_buffer_t* buffer) { michael@0: ALOGV("GonkNativeWindowClient::lockBuffer"); michael@0: Mutex::Autolock lock(mMutex); michael@0: return OK; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::queueBuffer"); michael@0: Mutex::Autolock lock(mMutex); michael@0: int64_t timestamp; michael@0: bool isAutoTimestamp = false; michael@0: if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) { michael@0: timestamp = systemTime(SYSTEM_TIME_MONOTONIC); michael@0: isAutoTimestamp = true; michael@0: ALOGV("GonkNativeWindowClient::queueBuffer making up timestamp: %.2f ms", michael@0: timestamp / 1000000.f); michael@0: } else { michael@0: timestamp = mTimestamp; michael@0: } michael@0: int i = getSlotFromBufferLocked(buffer); michael@0: if (i < 0) { michael@0: return i; michael@0: } michael@0: michael@0: michael@0: // Make sure the crop rectangle is entirely inside the buffer. michael@0: Rect crop; michael@0: mCrop.intersect(Rect(buffer->width, buffer->height), &crop); michael@0: michael@0: sp fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); michael@0: IGraphicBufferProducer::QueueBufferOutput output; michael@0: IGraphicBufferProducer::QueueBufferInput input(timestamp, isAutoTimestamp, michael@0: crop, mScalingMode, mTransform, mSwapIntervalZero, fence); michael@0: status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output); michael@0: if (err != OK) { michael@0: ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err); michael@0: } michael@0: uint32_t numPendingBuffers = 0; michael@0: output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint, michael@0: &numPendingBuffers); michael@0: michael@0: mConsumerRunningBehind = (numPendingBuffers >= 2); michael@0: michael@0: return err; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::query(int what, int* value) const { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::query"); michael@0: { // scope for the lock michael@0: Mutex::Autolock lock(mMutex); michael@0: switch (what) { michael@0: case NATIVE_WINDOW_FORMAT: michael@0: if (mReqFormat) { michael@0: *value = mReqFormat; michael@0: return NO_ERROR; michael@0: } michael@0: break; michael@0: case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: { michael@0: //sp composer( michael@0: // ComposerService::getComposerService()); michael@0: //if (composer->authenticateSurfaceTexture(mGraphicBufferProducer)) { michael@0: // *value = 1; michael@0: //} else { michael@0: *value = 0; michael@0: //} michael@0: return NO_ERROR; michael@0: } michael@0: case NATIVE_WINDOW_CONCRETE_TYPE: michael@0: *value = NATIVE_WINDOW_SURFACE; michael@0: return NO_ERROR; michael@0: case NATIVE_WINDOW_DEFAULT_WIDTH: michael@0: *value = mUserWidth ? mUserWidth : mDefaultWidth; michael@0: return NO_ERROR; michael@0: case NATIVE_WINDOW_DEFAULT_HEIGHT: michael@0: *value = mUserHeight ? mUserHeight : mDefaultHeight; michael@0: return NO_ERROR; michael@0: case NATIVE_WINDOW_TRANSFORM_HINT: michael@0: *value = mTransformHint; michael@0: return NO_ERROR; michael@0: case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: { michael@0: status_t err = NO_ERROR; michael@0: if (!mConsumerRunningBehind) { michael@0: *value = 0; michael@0: } else { michael@0: err = mGraphicBufferProducer->query(what, value); michael@0: if (err == NO_ERROR) { michael@0: mConsumerRunningBehind = *value; michael@0: } michael@0: } michael@0: return err; michael@0: } michael@0: } michael@0: } michael@0: return mGraphicBufferProducer->query(what, value); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::perform(int operation, va_list args) michael@0: { michael@0: int res = NO_ERROR; michael@0: switch (operation) { michael@0: case NATIVE_WINDOW_CONNECT: michael@0: // deprecated. must return NO_ERROR. michael@0: break; michael@0: case NATIVE_WINDOW_DISCONNECT: michael@0: // deprecated. must return NO_ERROR. michael@0: break; michael@0: case NATIVE_WINDOW_SET_USAGE: michael@0: res = dispatchSetUsage(args); michael@0: break; michael@0: case NATIVE_WINDOW_SET_CROP: michael@0: res = dispatchSetCrop(args); michael@0: break; michael@0: case NATIVE_WINDOW_SET_BUFFER_COUNT: michael@0: res = dispatchSetBufferCount(args); michael@0: break; michael@0: case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY: michael@0: res = dispatchSetBuffersGeometry(args); michael@0: break; michael@0: case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM: michael@0: res = dispatchSetBuffersTransform(args); michael@0: break; michael@0: case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: michael@0: res = dispatchSetBuffersTimestamp(args); michael@0: break; michael@0: case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS: michael@0: res = dispatchSetBuffersDimensions(args); michael@0: break; michael@0: case NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS: michael@0: res = dispatchSetBuffersUserDimensions(args); michael@0: break; michael@0: case NATIVE_WINDOW_SET_BUFFERS_FORMAT: michael@0: res = dispatchSetBuffersFormat(args); michael@0: break; michael@0: case NATIVE_WINDOW_LOCK: michael@0: res = dispatchLock(args); michael@0: break; michael@0: case NATIVE_WINDOW_UNLOCK_AND_POST: michael@0: res = dispatchUnlockAndPost(args); michael@0: break; michael@0: case NATIVE_WINDOW_SET_SCALING_MODE: michael@0: res = dispatchSetScalingMode(args); michael@0: break; michael@0: case NATIVE_WINDOW_API_CONNECT: michael@0: res = dispatchConnect(args); michael@0: break; michael@0: case NATIVE_WINDOW_API_DISCONNECT: michael@0: res = dispatchDisconnect(args); michael@0: break; michael@0: default: michael@0: res = NAME_NOT_FOUND; michael@0: break; michael@0: } michael@0: return res; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchConnect(va_list args) { michael@0: int api = va_arg(args, int); michael@0: return connect(api); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchDisconnect(va_list args) { michael@0: int api = va_arg(args, int); michael@0: return disconnect(api); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetUsage(va_list args) { michael@0: int usage = va_arg(args, int); michael@0: return setUsage(usage); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetCrop(va_list args) { michael@0: android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); michael@0: return setCrop(reinterpret_cast(rect)); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetBufferCount(va_list args) { michael@0: size_t bufferCount = va_arg(args, size_t); michael@0: return setBufferCount(bufferCount); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetBuffersGeometry(va_list args) { michael@0: int w = va_arg(args, int); michael@0: int h = va_arg(args, int); michael@0: int f = va_arg(args, int); michael@0: int err = setBuffersDimensions(w, h); michael@0: if (err != 0) { michael@0: return err; michael@0: } michael@0: return setBuffersFormat(f); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetBuffersDimensions(va_list args) { michael@0: int w = va_arg(args, int); michael@0: int h = va_arg(args, int); michael@0: return setBuffersDimensions(w, h); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetBuffersUserDimensions(va_list args) { michael@0: int w = va_arg(args, int); michael@0: int h = va_arg(args, int); michael@0: return setBuffersUserDimensions(w, h); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetBuffersFormat(va_list args) { michael@0: int f = va_arg(args, int); michael@0: return setBuffersFormat(f); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetScalingMode(va_list args) { michael@0: int m = va_arg(args, int); michael@0: return setScalingMode(m); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetBuffersTransform(va_list args) { michael@0: int transform = va_arg(args, int); michael@0: return setBuffersTransform(transform); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchSetBuffersTimestamp(va_list args) { michael@0: int64_t timestamp = va_arg(args, int64_t); michael@0: return setBuffersTimestamp(timestamp); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchLock(va_list args) { michael@0: ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*); michael@0: ARect* inOutDirtyBounds = va_arg(args, ARect*); michael@0: return lock(outBuffer, inOutDirtyBounds); michael@0: } michael@0: michael@0: int GonkNativeWindowClient::dispatchUnlockAndPost(va_list args) { michael@0: return unlockAndPost(); michael@0: } michael@0: michael@0: michael@0: int GonkNativeWindowClient::connect(int api) { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::connect"); michael@0: static sp sLife = new BBinder(); michael@0: Mutex::Autolock lock(mMutex); michael@0: IGraphicBufferProducer::QueueBufferOutput output; michael@0: int err = mGraphicBufferProducer->connect(sLife, api, true, &output); michael@0: if (err == NO_ERROR) { michael@0: uint32_t numPendingBuffers = 0; michael@0: output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint, michael@0: &numPendingBuffers); michael@0: mConsumerRunningBehind = (numPendingBuffers >= 2); michael@0: } michael@0: if (!err && api == NATIVE_WINDOW_API_CPU) { michael@0: mConnectedToCpu = true; michael@0: } michael@0: return err; michael@0: } michael@0: michael@0: michael@0: int GonkNativeWindowClient::disconnect(int api) { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::disconnect"); michael@0: Mutex::Autolock lock(mMutex); michael@0: freeAllBuffers(); michael@0: int err = mGraphicBufferProducer->disconnect(api); michael@0: if (!err) { michael@0: mReqFormat = 0; michael@0: mReqWidth = 0; michael@0: mReqHeight = 0; michael@0: mReqUsage = 0; michael@0: mCrop.clear(); michael@0: mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; michael@0: mTransform = 0; michael@0: if (api == NATIVE_WINDOW_API_CPU) { michael@0: mConnectedToCpu = false; michael@0: } michael@0: } michael@0: return err; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setUsage(uint32_t reqUsage) michael@0: { michael@0: ALOGV("GonkNativeWindowClient::setUsage"); michael@0: Mutex::Autolock lock(mMutex); michael@0: mReqUsage = reqUsage; michael@0: return OK; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setCrop(Rect const* rect) michael@0: { michael@0: ATRACE_CALL(); michael@0: michael@0: Rect realRect; michael@0: if (rect == NULL || rect->isEmpty()) { michael@0: realRect.clear(); michael@0: } else { michael@0: realRect = *rect; michael@0: } michael@0: michael@0: ALOGV("GonkNativeWindowClient::setCrop rect=[%d %d %d %d]", michael@0: realRect.left, realRect.top, realRect.right, realRect.bottom); michael@0: michael@0: Mutex::Autolock lock(mMutex); michael@0: mCrop = realRect; michael@0: return NO_ERROR; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setBufferCount(int bufferCount) michael@0: { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::setBufferCount"); michael@0: Mutex::Autolock lock(mMutex); michael@0: michael@0: status_t err = mGraphicBufferProducer->setBufferCount(bufferCount); michael@0: ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s", michael@0: bufferCount, strerror(-err)); michael@0: michael@0: if (err == NO_ERROR) { michael@0: freeAllBuffers(); michael@0: } michael@0: michael@0: return err; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setBuffersDimensions(int w, int h) michael@0: { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::setBuffersDimensions"); michael@0: michael@0: if (w<0 || h<0) michael@0: return BAD_VALUE; michael@0: michael@0: if ((w && !h) || (!w && h)) michael@0: return BAD_VALUE; michael@0: michael@0: Mutex::Autolock lock(mMutex); michael@0: mReqWidth = w; michael@0: mReqHeight = h; michael@0: return NO_ERROR; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setBuffersUserDimensions(int w, int h) michael@0: { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::setBuffersUserDimensions"); michael@0: michael@0: if (w<0 || h<0) michael@0: return BAD_VALUE; michael@0: michael@0: if ((w && !h) || (!w && h)) michael@0: return BAD_VALUE; michael@0: michael@0: Mutex::Autolock lock(mMutex); michael@0: mUserWidth = w; michael@0: mUserHeight = h; michael@0: return NO_ERROR; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setBuffersFormat(int format) michael@0: { michael@0: ALOGV("GonkNativeWindowClient::setBuffersFormat"); michael@0: michael@0: if (format<0) michael@0: return BAD_VALUE; michael@0: michael@0: Mutex::Autolock lock(mMutex); michael@0: mReqFormat = format; michael@0: return NO_ERROR; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setScalingMode(int mode) michael@0: { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::setScalingMode(%d)", mode); michael@0: michael@0: switch (mode) { michael@0: case NATIVE_WINDOW_SCALING_MODE_FREEZE: michael@0: case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: michael@0: case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP: michael@0: break; michael@0: default: michael@0: ALOGE("unknown scaling mode: %d", mode); michael@0: return BAD_VALUE; michael@0: } michael@0: michael@0: Mutex::Autolock lock(mMutex); michael@0: mScalingMode = mode; michael@0: return NO_ERROR; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setBuffersTransform(int transform) michael@0: { michael@0: ATRACE_CALL(); michael@0: ALOGV("GonkNativeWindowClient::setBuffersTransform"); michael@0: Mutex::Autolock lock(mMutex); michael@0: mTransform = transform; michael@0: return NO_ERROR; michael@0: } michael@0: michael@0: int GonkNativeWindowClient::setBuffersTimestamp(int64_t timestamp) michael@0: { michael@0: ALOGV("GonkNativeWindowClient::setBuffersTimestamp"); michael@0: Mutex::Autolock lock(mMutex); michael@0: mTimestamp = timestamp; michael@0: return NO_ERROR; michael@0: } michael@0: michael@0: void GonkNativeWindowClient::freeAllBuffers() { michael@0: for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { michael@0: mSlots[i].buffer = 0; michael@0: } michael@0: } michael@0: michael@0: // ---------------------------------------------------------------------- michael@0: // the lock/unlock APIs must be used from the same thread michael@0: michael@0: // ---------------------------------------------------------------------------- michael@0: michael@0: status_t GonkNativeWindowClient::lock( michael@0: ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds) michael@0: { michael@0: return INVALID_OPERATION; michael@0: } michael@0: michael@0: status_t GonkNativeWindowClient::unlockAndPost() michael@0: { michael@0: return INVALID_OPERATION; michael@0: } michael@0: michael@0: }; // namespace android