blob: dbe187b6aedf67e4f018265dbc73485755edc4f6 [file] [log] [blame]
Andy McFaddenbf974ab2012-12-04 16:51:15 -08001/*
2 * Copyright (C) 2012 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#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18
19#include "SurfaceFlingerConsumer.h"
20
21#include <utils/Trace.h>
22#include <utils/Errors.h>
23
24
25namespace android {
26
27// ---------------------------------------------------------------------------
28
29status_t SurfaceFlingerConsumer::updateTexImage(BufferRejecter* rejecter)
30{
31 ATRACE_CALL();
32 ALOGV("updateTexImage");
33 Mutex::Autolock lock(mMutex);
34
35 if (mAbandoned) {
36 ALOGE("updateTexImage: SurfaceTexture is abandoned!");
37 return NO_INIT;
38 }
39
40 // Make sure the EGL state is the same as in previous calls.
41 status_t err = checkAndUpdateEglStateLocked();
42 if (err != NO_ERROR) {
43 return err;
44 }
45
46 BufferQueue::BufferItem item;
47
48 // Acquire the next buffer.
49 // In asynchronous mode the list is guaranteed to be one buffer
50 // deep, while in synchronous mode we use the oldest buffer.
51 err = acquireBufferLocked(&item);
52 if (err != NO_ERROR) {
53 if (err == BufferQueue::NO_BUFFER_AVAILABLE) {
54 // This variant of updateTexImage does not guarantee that the
55 // texture is bound, so no need to call glBindTexture.
56 err = NO_ERROR;
57 } else {
58 ALOGE("updateTexImage: acquire failed: %s (%d)",
59 strerror(-err), err);
60 }
61 return err;
62 }
63
64
65 // We call the rejecter here, in case the caller has a reason to
66 // not accept this buffer. This is used by SurfaceFlinger to
67 // reject buffers which have the wrong size
68 int buf = item.mBuf;
69 if (rejecter && rejecter->reject(mSlots[buf].mGraphicBuffer, item)) {
70 releaseBufferLocked(buf, EGL_NO_SYNC_KHR);
71 return NO_ERROR;
72 }
73
74 // Release the previous buffer.
75 err = releaseAndUpdateLocked(item);
76 if (err != NO_ERROR) {
77 return err;
78 }
79
80 // Bind the new buffer to the GL texture.
81 // TODO: skip this on devices that support explicit sync
82 // (glEGLImageTargetTexture2DOES provides required implicit sync;
83 // without this we get wedged on older devices, but newer devices
84 // don't need it.)
85 return bindTextureImage();
86}
87
88// ---------------------------------------------------------------------------
89}; // namespace android
90