1 /* 2 * Copyright 2019 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 #include <cutils/compiler.h> 22 #include <gui/BufferItem.h> 23 #include <gui/BufferQueueDefs.h> 24 #include <sys/cdefs.h> 25 #include <system/graphics.h> 26 27 namespace android { 28 29 class SurfaceTexture; 30 class DequeueBufferCallbacks; 31 32 /* 33 * ImageConsumer implements the parts of SurfaceTexture that deal with 34 * images consumed by HWUI view system. 35 */ 36 class ImageConsumer { 37 public: 38 typedef status_t (*SurfaceTexture_createReleaseFence)(bool useFenceSync, EGLSyncKHR* eglFence, 39 EGLDisplay* display, int* releaseFence, 40 void* fencePassThroughHandle); 41 42 typedef status_t (*SurfaceTexture_fenceWait)(int fence, void* fencePassThroughHandle); 43 44 sp<GraphicBuffer> dequeueBuffer(int* outSlotid, android_dataspace* outDataspace, 45 bool* outQueueEmpty, SurfaceTexture& cb, 46 SurfaceTexture_createReleaseFence createFence, 47 SurfaceTexture_fenceWait fenceWait, 48 void* fencePassThroughHandle); 49 50 /** 51 * onReleaseBufferLocked amends the ConsumerBase method to update the 52 * mImageSlots array in addition to the ConsumerBase. 53 */ 54 void onReleaseBufferLocked(int slot); 55 56 private: 57 /** 58 * ImageSlot contains the information and object references that 59 * ImageConsumer maintains about a BufferQueue buffer slot. 60 */ 61 class ImageSlot { 62 public: ImageSlot()63 ImageSlot() : mEglFence(EGL_NO_SYNC_KHR) {} 64 eglFence()65 inline EGLSyncKHR& eglFence() { return mEglFence; } 66 67 private: 68 /** 69 * mEglFence is the EGL sync object that must signal before the buffer 70 * associated with this buffer slot may be dequeued. 71 */ 72 EGLSyncKHR mEglFence; 73 }; 74 75 /** 76 * ImageConsumer stores the SkImages that have been allocated by the BufferQueue 77 * for each buffer slot. It is initialized to null pointers, and gets 78 * filled in with the result of BufferQueue::acquire when the 79 * client dequeues a buffer from a 80 * slot that has not yet been used. The buffer allocated to a slot will also 81 * be replaced if the requested buffer usage or geometry differs from that 82 * of the buffer allocated to a slot. 83 */ 84 ImageSlot mImageSlots[BufferQueueDefs::NUM_BUFFER_SLOTS]; 85 }; 86 87 } /* namespace android */ 88