Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #pragma once |
| 18 | |
| 19 | #include <EGL/egl.h> |
| 20 | #include <EGL/eglext.h> |
| 21 | |
| 22 | #include <gui/BufferQueueDefs.h> |
| 23 | |
| 24 | #include <SkImage.h> |
| 25 | #include <cutils/compiler.h> |
| 26 | #include <gui/BufferItem.h> |
| 27 | #include <system/graphics.h> |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | namespace uirenderer { |
| 32 | class RenderState; |
| 33 | } |
| 34 | |
| 35 | class SurfaceTexture; |
| 36 | |
| 37 | /* |
| 38 | * ImageConsumer implements the parts of SurfaceTexture that deal with |
| 39 | * images consumed by HWUI view system. |
| 40 | */ |
| 41 | class ImageConsumer { |
| 42 | public: |
| 43 | sk_sp<SkImage> dequeueImage(bool* queueEmpty, SurfaceTexture& cb, |
| 44 | uirenderer::RenderState& renderState); |
| 45 | |
| 46 | /** |
| 47 | * onAcquireBufferLocked amends the ConsumerBase method to update the |
| 48 | * mImageSlots array in addition to the ConsumerBase behavior. |
| 49 | */ |
| 50 | void onAcquireBufferLocked(BufferItem* item); |
| 51 | |
| 52 | /** |
| 53 | * onReleaseBufferLocked amends the ConsumerBase method to update the |
| 54 | * mImageSlots array in addition to the ConsumerBase. |
| 55 | */ |
| 56 | void onReleaseBufferLocked(int slot); |
| 57 | |
| 58 | /** |
| 59 | * onFreeBufferLocked frees up the given buffer slot. If the slot has been |
| 60 | * initialized this will release the reference to the GraphicBuffer in that |
| 61 | * slot and destroy the SkImage in that slot. Otherwise it has no effect. |
| 62 | */ |
| 63 | void onFreeBufferLocked(int slotIndex); |
| 64 | |
| 65 | private: |
| 66 | /** |
| 67 | * ImageSlot contains the information and object references that |
| 68 | * ImageConsumer maintains about a BufferQueue buffer slot. |
| 69 | */ |
| 70 | struct ImageSlot { |
| 71 | ImageSlot() : mEglFence(EGL_NO_SYNC_KHR) {} |
| 72 | |
| 73 | // mImage is the SkImage created from mGraphicBuffer. |
| 74 | sk_sp<SkImage> mImage; |
| 75 | |
| 76 | /** |
| 77 | * mEglFence is the EGL sync object that must signal before the buffer |
| 78 | * associated with this buffer slot may be dequeued. |
| 79 | */ |
| 80 | EGLSyncKHR mEglFence; |
| 81 | |
| 82 | void createIfNeeded(sp<GraphicBuffer> graphicBuffer); |
| 83 | }; |
| 84 | |
| 85 | /** |
| 86 | * ImageConsumer stores the SkImages that have been allocated by the BufferQueue |
| 87 | * for each buffer slot. It is initialized to null pointers, and gets |
| 88 | * filled in with the result of BufferQueue::acquire when the |
| 89 | * client dequeues a buffer from a |
| 90 | * slot that has not yet been used. The buffer allocated to a slot will also |
| 91 | * be replaced if the requested buffer usage or geometry differs from that |
| 92 | * of the buffer allocated to a slot. |
| 93 | */ |
| 94 | ImageSlot mImageSlots[BufferQueueDefs::NUM_BUFFER_SLOTS]; |
| 95 | }; |
| 96 | |
| 97 | }; /* namespace android */ |