Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdlib.h> |
| 18 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
| 20 | |
| 21 | #include <utils/Errors.h> |
| 22 | |
| 23 | #include "Layer.h" |
| 24 | #include "SurfaceTextureLayer.h" |
| 25 | |
| 26 | namespace android { |
| 27 | // --------------------------------------------------------------------------- |
| 28 | |
| 29 | |
| 30 | SurfaceTextureLayer::SurfaceTextureLayer(GLuint tex, const sp<Layer>& layer) |
Jamie Gennis | 86edf4f | 2011-11-14 14:51:01 -0800 | [diff] [blame] | 31 | : SurfaceTexture(tex, true, GL_TEXTURE_EXTERNAL_OES, false), mLayer(layer) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | SurfaceTextureLayer::~SurfaceTextureLayer() { |
| 35 | } |
| 36 | |
| 37 | |
| 38 | status_t SurfaceTextureLayer::setDefaultBufferSize(uint32_t w, uint32_t h) |
| 39 | { |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 40 | //ALOGD("%s, w=%u, h=%u", __PRETTY_FUNCTION__, w, h); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 41 | return SurfaceTexture::setDefaultBufferSize(w, h); |
| 42 | } |
| 43 | |
| 44 | status_t SurfaceTextureLayer::setDefaultBufferFormat(uint32_t format) |
| 45 | { |
| 46 | mDefaultFormat = format; |
| 47 | return NO_ERROR; |
| 48 | } |
| 49 | |
| 50 | status_t SurfaceTextureLayer::setBufferCount(int bufferCount) { |
| 51 | status_t res = SurfaceTexture::setBufferCount(bufferCount); |
| 52 | return res; |
| 53 | } |
| 54 | |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 55 | status_t SurfaceTextureLayer::queueBuffer(int buf, int64_t timestamp, |
| 56 | uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { |
| 57 | |
| 58 | status_t res = SurfaceTexture::queueBuffer(buf, timestamp, |
| 59 | outWidth, outHeight, outTransform); |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 60 | sp<Layer> layer(mLayer.promote()); |
| 61 | if (layer != NULL) { |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 62 | *outTransform = layer->getTransformHint(); |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 63 | } |
Mathias Agopian | 97c602c | 2011-07-19 15:24:46 -0700 | [diff] [blame] | 64 | return res; |
| 65 | } |
| 66 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 67 | status_t SurfaceTextureLayer::dequeueBuffer(int *buf, |
| 68 | uint32_t w, uint32_t h, uint32_t format, uint32_t usage) { |
| 69 | |
| 70 | status_t res(NO_INIT); |
| 71 | sp<Layer> layer(mLayer.promote()); |
| 72 | if (layer != NULL) { |
| 73 | if (format == 0) |
| 74 | format = mDefaultFormat; |
| 75 | uint32_t effectiveUsage = layer->getEffectiveUsage(usage); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 76 | //ALOGD("%s, w=%u, h=%u, format=%u, usage=%08x, effectiveUsage=%08x", |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 77 | // __PRETTY_FUNCTION__, w, h, format, usage, effectiveUsage); |
| 78 | res = SurfaceTexture::dequeueBuffer(buf, w, h, format, effectiveUsage); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 79 | } |
| 80 | return res; |
| 81 | } |
| 82 | |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 83 | status_t SurfaceTextureLayer::connect(int api, |
| 84 | uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { |
| 85 | status_t err = SurfaceTexture::connect(api, |
| 86 | outWidth, outHeight, outTransform); |
Jamie Gennis | cb6c755 | 2011-07-30 15:06:10 -0700 | [diff] [blame] | 87 | if (err == NO_ERROR) { |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 88 | sp<Layer> layer(mLayer.promote()); |
| 89 | if (layer != NULL) { |
| 90 | uint32_t orientation = layer->getOrientation(); |
| 91 | if (orientation & Transform::ROT_INVALID) { |
| 92 | orientation = 0; |
| 93 | } |
| 94 | *outTransform = orientation; |
| 95 | } |
Jamie Gennis | cb6c755 | 2011-07-30 15:06:10 -0700 | [diff] [blame] | 96 | switch(api) { |
| 97 | case NATIVE_WINDOW_API_MEDIA: |
| 98 | case NATIVE_WINDOW_API_CAMERA: |
| 99 | // Camera preview and videos are rate-limited on the producer |
| 100 | // side. If enabled for this build, we use async mode to always |
| 101 | // show the most recent frame at the cost of requiring an |
| 102 | // additional buffer. |
| 103 | #ifndef NEVER_DEFAULT_TO_ASYNC_MODE |
| 104 | err = setSynchronousMode(false); |
| 105 | break; |
| 106 | #endif |
| 107 | // fall through to set synchronous mode when not defaulting to |
| 108 | // async mode. |
| 109 | deafult: |
| 110 | err = setSynchronousMode(true); |
| 111 | break; |
| 112 | } |
| 113 | if (err != NO_ERROR) { |
| 114 | disconnect(api); |
| 115 | } |
| 116 | } |
| 117 | return err; |
| 118 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 119 | |
| 120 | // --------------------------------------------------------------------------- |
| 121 | }; // namespace android |