blob: 79cd0c31408a40b4202f7871d11a6d0ba86a8f5c [file] [log] [blame]
Mathias Agopiana67932f2011-04-20 14:20:59 -07001/*
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
26namespace android {
27// ---------------------------------------------------------------------------
28
29
30SurfaceTextureLayer::SurfaceTextureLayer(GLuint tex, const sp<Layer>& layer)
31 : SurfaceTexture(tex), mLayer(layer) {
32}
33
34SurfaceTextureLayer::~SurfaceTextureLayer() {
35}
36
37
38status_t SurfaceTextureLayer::setDefaultBufferSize(uint32_t w, uint32_t h)
39{
40 //LOGD("%s, w=%u, h=%u", __PRETTY_FUNCTION__, w, h);
41 return SurfaceTexture::setDefaultBufferSize(w, h);
42}
43
44status_t SurfaceTextureLayer::setDefaultBufferFormat(uint32_t format)
45{
46 mDefaultFormat = format;
47 return NO_ERROR;
48}
49
50status_t SurfaceTextureLayer::setBufferCount(int bufferCount) {
51 status_t res = SurfaceTexture::setBufferCount(bufferCount);
52 return res;
53}
54
Mathias Agopian97c602c2011-07-19 15:24:46 -070055status_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);
60
61 sp<Layer> layer(mLayer.promote());
62 if (layer != NULL) {
Mathias Agopianbb66c9b2011-07-21 14:50:29 -070063 uint32_t orientation = layer->getOrientation();
64 if (orientation & Transform::ROT_INVALID) {
65 orientation = 0;
66 }
Mathias Agopian6dc49c02011-07-22 15:25:20 -070067 *outTransform = orientation;
Mathias Agopian97c602c2011-07-19 15:24:46 -070068 }
69
70 return res;
71}
72
Mathias Agopiana67932f2011-04-20 14:20:59 -070073status_t SurfaceTextureLayer::dequeueBuffer(int *buf,
74 uint32_t w, uint32_t h, uint32_t format, uint32_t usage) {
75
76 status_t res(NO_INIT);
77 sp<Layer> layer(mLayer.promote());
78 if (layer != NULL) {
79 if (format == 0)
80 format = mDefaultFormat;
81 uint32_t effectiveUsage = layer->getEffectiveUsage(usage);
82 //LOGD("%s, w=%u, h=%u, format=%u, usage=%08x, effectiveUsage=%08x",
83 // __PRETTY_FUNCTION__, w, h, format, usage, effectiveUsage);
84 res = SurfaceTexture::dequeueBuffer(buf, w, h, format, effectiveUsage);
Mathias Agopiana67932f2011-04-20 14:20:59 -070085 }
86 return res;
87}
88
Mathias Agopian5bfc2452011-08-08 19:14:03 -070089status_t SurfaceTextureLayer::connect(int api,
90 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
91 status_t err = SurfaceTexture::connect(api,
92 outWidth, outHeight, outTransform);
Jamie Genniscb6c7552011-07-30 15:06:10 -070093 if (err == NO_ERROR) {
Mathias Agopian5bfc2452011-08-08 19:14:03 -070094 sp<Layer> layer(mLayer.promote());
95 if (layer != NULL) {
96 uint32_t orientation = layer->getOrientation();
97 if (orientation & Transform::ROT_INVALID) {
98 orientation = 0;
99 }
100 *outTransform = orientation;
101 }
Jamie Genniscb6c7552011-07-30 15:06:10 -0700102 switch(api) {
103 case NATIVE_WINDOW_API_MEDIA:
104 case NATIVE_WINDOW_API_CAMERA:
105 // Camera preview and videos are rate-limited on the producer
106 // side. If enabled for this build, we use async mode to always
107 // show the most recent frame at the cost of requiring an
108 // additional buffer.
109#ifndef NEVER_DEFAULT_TO_ASYNC_MODE
110 err = setSynchronousMode(false);
111 break;
112#endif
113 // fall through to set synchronous mode when not defaulting to
114 // async mode.
115 deafult:
116 err = setSynchronousMode(true);
117 break;
118 }
119 if (err != NO_ERROR) {
120 disconnect(api);
121 }
122 }
123 return err;
124}
Mathias Agopiana67932f2011-04-20 14:20:59 -0700125
126// ---------------------------------------------------------------------------
127}; // namespace android