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