Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 1 | /* |
| 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 |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 19 | |
| 20 | #include "SurfaceFlingerConsumer.h" |
| 21 | |
| 22 | #include <utils/Trace.h> |
| 23 | #include <utils/Errors.h> |
| 24 | |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | // --------------------------------------------------------------------------- |
| 29 | |
| 30 | status_t SurfaceFlingerConsumer::updateTexImage(BufferRejecter* rejecter) |
| 31 | { |
| 32 | ATRACE_CALL(); |
| 33 | ALOGV("updateTexImage"); |
| 34 | Mutex::Autolock lock(mMutex); |
| 35 | |
| 36 | if (mAbandoned) { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 37 | ALOGE("updateTexImage: GLConsumer is abandoned!"); |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 38 | return NO_INIT; |
| 39 | } |
| 40 | |
| 41 | // Make sure the EGL state is the same as in previous calls. |
| 42 | status_t err = checkAndUpdateEglStateLocked(); |
| 43 | if (err != NO_ERROR) { |
| 44 | return err; |
| 45 | } |
| 46 | |
| 47 | BufferQueue::BufferItem item; |
| 48 | |
| 49 | // Acquire the next buffer. |
| 50 | // In asynchronous mode the list is guaranteed to be one buffer |
| 51 | // deep, while in synchronous mode we use the oldest buffer. |
| 52 | err = acquireBufferLocked(&item); |
| 53 | if (err != NO_ERROR) { |
| 54 | if (err == BufferQueue::NO_BUFFER_AVAILABLE) { |
| 55 | // This variant of updateTexImage does not guarantee that the |
| 56 | // texture is bound, so no need to call glBindTexture. |
| 57 | err = NO_ERROR; |
| 58 | } else { |
| 59 | ALOGE("updateTexImage: acquire failed: %s (%d)", |
| 60 | strerror(-err), err); |
| 61 | } |
| 62 | return err; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | // We call the rejecter here, in case the caller has a reason to |
| 67 | // not accept this buffer. This is used by SurfaceFlinger to |
| 68 | // reject buffers which have the wrong size |
| 69 | int buf = item.mBuf; |
| 70 | if (rejecter && rejecter->reject(mSlots[buf].mGraphicBuffer, item)) { |
| 71 | releaseBufferLocked(buf, EGL_NO_SYNC_KHR); |
| 72 | return NO_ERROR; |
| 73 | } |
| 74 | |
| 75 | // Release the previous buffer. |
| 76 | err = releaseAndUpdateLocked(item); |
| 77 | if (err != NO_ERROR) { |
| 78 | return err; |
| 79 | } |
| 80 | |
Andy McFadden | 97eba89 | 2012-12-11 15:21:45 -0800 | [diff] [blame] | 81 | if (!sUseNativeFenceSync) { |
| 82 | // Bind the new buffer to the GL texture. |
| 83 | // |
| 84 | // Older devices require the "implicit" synchronization provided |
| 85 | // by glEGLImageTargetTexture2DOES, which this method calls. Newer |
| 86 | // devices will either call this in Layer::onDraw, or (if it's not |
| 87 | // a GL-composited layer) not at all. |
| 88 | err = bindTextureImageLocked(); |
| 89 | } |
| 90 | |
| 91 | return err; |
| 92 | } |
| 93 | |
| 94 | status_t SurfaceFlingerConsumer::bindTextureImage() |
| 95 | { |
| 96 | Mutex::Autolock lock(mMutex); |
| 97 | |
| 98 | return bindTextureImageLocked(); |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | // --------------------------------------------------------------------------- |
| 102 | }; // namespace android |
| 103 | |