diff options
author | Xin Li <delphij@google.com> | 2020-08-31 21:21:38 -0700 |
---|---|---|
committer | Xin Li <delphij@google.com> | 2020-08-31 21:21:38 -0700 |
commit | 628590d7ec80e10a3fc24b1c18a1afb55cca10a8 (patch) | |
tree | 4b1c3f52d86d7fb53afbe9e9438468588fa489f8 /libs/hwui/renderthread/ReliableSurface.h | |
parent | b11b8ec3aec8bb42f2c07e1c5ac7942da293baa8 (diff) | |
parent | d2d3a20624d968199353ccf6ddbae6f3ac39c9af (diff) |
Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507
Merged-In: I3d92a6de21a938f6b352ec26dc23420c0fe02b27
Change-Id: Ifdb80563ef042738778ebb8a7581a97c4e3d96e2
Diffstat (limited to 'libs/hwui/renderthread/ReliableSurface.h')
-rw-r--r-- | libs/hwui/renderthread/ReliableSurface.h | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/libs/hwui/renderthread/ReliableSurface.h b/libs/hwui/renderthread/ReliableSurface.h index 0bfc72ef61cb..f699eb1fe6b3 100644 --- a/libs/hwui/renderthread/ReliableSurface.h +++ b/libs/hwui/renderthread/ReliableSurface.h @@ -16,72 +16,87 @@ #pragma once -#include <gui/Surface.h> +#include <android-base/unique_fd.h> +#include <system/window.h> +#include <apex/window.h> +#include <utils/Errors.h> #include <utils/Macros.h> #include <utils/StrongPointer.h> #include <memory> +#include <mutex> namespace android::uirenderer::renderthread { -class ReliableSurface : public ANativeObjectBase<ANativeWindow, ReliableSurface, RefBase> { +class ReliableSurface { PREVENT_COPY_AND_ASSIGN(ReliableSurface); public: - ReliableSurface(sp<Surface>&& surface); + ReliableSurface(ANativeWindow* window); ~ReliableSurface(); - void setDequeueTimeout(nsecs_t timeout) { mSurface->setDequeueTimeout(timeout); } + // Performs initialization that is not safe to do in the constructor. + // For instance, registering ANativeWindow interceptors with ReliableSurface + // passed as the data pointer is not safe. + void init(); - int reserveNext(); + ANativeWindow* getNativeWindow() { return mWindow; } - void allocateBuffers() { mSurface->allocateBuffers(); } + int reserveNext(); - int query(int what, int* value) const { return mSurface->query(what, value); } + int getAndClearError() { + int ret = mBufferQueueState; + mBufferQueueState = OK; + return ret; + } - nsecs_t getLastDequeueStartTime() const { return mSurface->getLastDequeueStartTime(); } + void setExtraBufferCount(size_t extraBuffers) { + std::lock_guard _lock{mMutex}; + mExtraBuffers = extraBuffers; + } - uint64_t getNextFrameNumber() const { return mSurface->getNextFrameNumber(); } + bool didSetExtraBuffers() const { + std::lock_guard _lock{mMutex}; + return mDidSetExtraBuffers; + } private: - const sp<Surface> mSurface; + ANativeWindow* mWindow; mutable std::mutex mMutex; uint64_t mUsage = AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER; - PixelFormat mFormat = PIXEL_FORMAT_RGBA_8888; + AHardwareBuffer_Format mFormat = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM; std::unique_ptr<AHardwareBuffer, void (*)(AHardwareBuffer*)> mScratchBuffer{ nullptr, AHardwareBuffer_release}; ANativeWindowBuffer* mReservedBuffer = nullptr; base::unique_fd mReservedFenceFd; bool mHasDequeuedBuffer = false; - bool mInErrorState = false; + int mBufferQueueState = OK; + size_t mExtraBuffers = 0; + size_t mExpectedBufferCount = 0; + bool mDidSetExtraBuffers = false; bool isFallbackBuffer(const ANativeWindowBuffer* windowBuffer) const; - ANativeWindowBuffer* acquireFallbackBuffer(); + ANativeWindowBuffer* acquireFallbackBuffer(int error); void clearReservedBuffer(); - void perform(int operation, va_list args); - int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd); - int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd); - int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd); - - static Surface* getWrapped(const ANativeWindow*); - - // ANativeWindow hooks - static int hook_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd); - static int hook_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, - int* fenceFd); - static int hook_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd); - - static int hook_perform(ANativeWindow* window, int operation, ...); - static int hook_query(const ANativeWindow* window, int what, int* value); - static int hook_setSwapInterval(ANativeWindow* window, int interval); - - static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer* buffer); - static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer** buffer); - static int hook_lockBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer* buffer); - static int hook_queueBuffer_DEPRECATED(ANativeWindow* window, ANativeWindowBuffer* buffer); + // ANativeWindow hooks. When an ANativeWindow_* method is called on the + // underlying ANativeWindow, these methods will intercept the original call. + // For example, an EGL driver would call into these hooks instead of the + // original methods. + static int hook_cancelBuffer(ANativeWindow* window, ANativeWindow_cancelBufferFn cancelBuffer, + void* data, ANativeWindowBuffer* buffer, int fenceFd); + static int hook_dequeueBuffer(ANativeWindow* window, + ANativeWindow_dequeueBufferFn dequeueBuffer, void* data, + ANativeWindowBuffer** buffer, int* fenceFd); + static int hook_queueBuffer(ANativeWindow* window, ANativeWindow_queueBufferFn queueBuffer, + void* data, ANativeWindowBuffer* buffer, int fenceFd); + + static int hook_perform(ANativeWindow* window, ANativeWindow_performFn perform, void* data, + int operation, va_list args); + static int hook_query(const ANativeWindow* window, ANativeWindow_queryFn query, void* data, + int what, int* value); }; -}; // namespace android::uirenderer::renderthread
\ No newline at end of file +}; // namespace android::uirenderer::renderthread |