| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#include <android-base/unique_fd.h> |
| 20 |
#include <system/window.h> |
| 21 |
#include <apex/window.h> |
| 22 |
#include <utils/Errors.h> |
| 23 |
#include <utils/Macros.h> |
| 24 |
#include <utils/NdkUtils.h> |
| 25 |
#include <utils/StrongPointer.h> |
| 26 |
|
| 27 |
#include <memory> |
| 28 |
#include <mutex> |
| 29 |
|
| 30 |
namespace android::uirenderer::renderthread { |
| 31 |
|
| 32 |
class ReliableSurface { |
| 33 |
PREVENT_COPY_AND_ASSIGN(ReliableSurface); |
| 34 |
|
| 35 |
public: |
| 36 |
ReliableSurface(ANativeWindow* window); |
| 37 |
~ReliableSurface(); |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
void init(); |
| 43 |
|
| 44 |
ANativeWindow* getNativeWindow() { return mWindow; } |
| 45 |
|
| 46 |
int reserveNext(); |
| 47 |
|
| 48 |
int getAndClearError() { |
| 49 |
int ret = mBufferQueueState; |
| 50 |
mBufferQueueState = OK; |
| 51 |
return ret; |
| 52 |
} |
| 53 |
|
| 54 |
bool didSetExtraBuffers() const { |
| 55 |
std::lock_guard _lock{mMutex}; |
| 56 |
return mDidSetExtraBuffers; |
| 57 |
} |
| 58 |
|
| 59 |
private: |
| 60 |
ANativeWindow* mWindow; |
| 61 |
|
| 62 |
mutable std::mutex mMutex; |
| 63 |
|
| 64 |
uint64_t mUsage = AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER; |
| 65 |
AHardwareBuffer_Format mFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM; |
| 66 |
UniqueAHardwareBuffer mScratchBuffer; |
| 67 |
ANativeWindowBuffer* mReservedBuffer = nullptr; |
| 68 |
base::unique_fd mReservedFenceFd; |
| 69 |
bool mHasDequeuedBuffer = false; |
| 70 |
int mBufferQueueState = OK; |
| 71 |
size_t mExpectedBufferCount = 0; |
| 72 |
bool mDidSetExtraBuffers = false; |
| 73 |
|
| 74 |
bool isFallbackBuffer(const ANativeWindowBuffer* windowBuffer) const; |
| 75 |
ANativeWindowBuffer* acquireFallbackBuffer(int error); |
| 76 |
void clearReservedBuffer(); |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
static int hook_cancelBuffer(ANativeWindow* window, ANativeWindow_cancelBufferFn cancelBuffer, |
| 83 |
void* data, ANativeWindowBuffer* buffer, int fenceFd); |
| 84 |
static int hook_dequeueBuffer(ANativeWindow* window, |
| 85 |
ANativeWindow_dequeueBufferFn dequeueBuffer, void* data, |
| 86 |
ANativeWindowBuffer** buffer, int* fenceFd); |
| 87 |
static int hook_queueBuffer(ANativeWindow* window, ANativeWindow_queueBufferFn queueBuffer, |
| 88 |
void* data, ANativeWindowBuffer* buffer, int fenceFd); |
| 89 |
|
| 90 |
static int hook_perform(ANativeWindow* window, ANativeWindow_performFn perform, void* data, |
| 91 |
int operation, va_list args); |
| 92 |
static int hook_query(const ANativeWindow* window, ANativeWindow_queryFn query, void* data, |
| 93 |
int what, int* value); |
| 94 |
}; |
| 95 |
|
| 96 |
}; |