diff options
author | Alec Mouri <alecmouri@google.com> | 2019-12-23 07:46:19 -0800 |
---|---|---|
committer | Alec Mouri <alecmouri@google.com> | 2020-02-14 15:24:16 -0800 |
commit | 43fe6fcde5cb2630a8d1ffa47d3e6e58e11999ae (patch) | |
tree | 212c6c6fa2959b3288a5031f5271048d10c8734a /libs/hwui/renderthread | |
parent | 112dfb3f1606b2033cdec7fc0b829d6cac31838e (diff) |
[HWUI] Remove references to gui/Surface.
ANativeWindow usage now has enough feature parity so that we can use
that instead.
Bug: 137012798
Test: builds
Test: Scroll through settings
Change-Id: I0054315058b28bcb5e779a6f71a3cfb164625a5f
Diffstat (limited to 'libs/hwui/renderthread')
-rw-r--r-- | libs/hwui/renderthread/CanvasContext.cpp | 10 | ||||
-rw-r--r-- | libs/hwui/renderthread/CanvasContext.h | 3 | ||||
-rw-r--r-- | libs/hwui/renderthread/ReliableSurface.cpp | 33 | ||||
-rw-r--r-- | libs/hwui/renderthread/ReliableSurface.h | 14 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderProxy.cpp | 13 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderProxy.h | 9 |
6 files changed, 41 insertions, 41 deletions
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index 1df3336bb5e5..4299dd3b46fe 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -139,15 +139,15 @@ void CanvasContext::destroy() { mAnimationContext->destroy(); } -void CanvasContext::setSurface(sp<Surface>&& surface, bool enableTimeout) { +void CanvasContext::setSurface(ANativeWindow* window, bool enableTimeout) { ATRACE_CALL(); - if (surface) { - mNativeSurface = std::make_unique<ReliableSurface>(std::move(surface)); + if (window) { + mNativeSurface = std::make_unique<ReliableSurface>(window); mNativeSurface->init(); if (enableTimeout) { // TODO: Fix error handling & re-shorten timeout - ANativeWindow_setDequeueTimeout(mNativeSurface->getNativeWindow(), 4000_ms); + ANativeWindow_setDequeueTimeout(window, 4000_ms); } } else { mNativeSurface = nullptr; @@ -167,7 +167,7 @@ void CanvasContext::setSurface(sp<Surface>&& surface, bool enableTimeout) { mFrameNumber = -1; - if (hasSurface) { + if (window != nullptr && hasSurface) { mHaveNewSurface = true; mSwapHistory.clear(); // Enable frame stats after the surface has been bound to the appropriate graphics API. diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h index 629c741e8757..0f1b8aebf56c 100644 --- a/libs/hwui/renderthread/CanvasContext.h +++ b/libs/hwui/renderthread/CanvasContext.h @@ -35,7 +35,6 @@ #include <SkRect.h> #include <SkSize.h> #include <cutils/compiler.h> -#include <gui/Surface.h> #include <utils/Functor.h> #include <functional> @@ -111,7 +110,7 @@ public: // Won't take effect until next EGLSurface creation void setSwapBehavior(SwapBehavior swapBehavior); - void setSurface(sp<Surface>&& surface, bool enableTimeout = true); + void setSurface(ANativeWindow* window, bool enableTimeout = true); bool pauseSurface(); void setStopped(bool stopped); bool hasSurface() const { return mNativeSurface.get(); } diff --git a/libs/hwui/renderthread/ReliableSurface.cpp b/libs/hwui/renderthread/ReliableSurface.cpp index e92500f5be51..8a0b4e8455bd 100644 --- a/libs/hwui/renderthread/ReliableSurface.cpp +++ b/libs/hwui/renderthread/ReliableSurface.cpp @@ -16,7 +16,10 @@ #include "ReliableSurface.h" +#include <log/log_main.h> #include <private/android/AHardwareBufferHelpers.h> +// TODO: this should be including apex instead. +#include <vndk/window.h> namespace android::uirenderer::renderthread { @@ -26,8 +29,9 @@ namespace android::uirenderer::renderthread { // to propagate this error back to the caller constexpr bool DISABLE_BUFFER_PREFETCH = true; -ReliableSurface::ReliableSurface(sp<Surface>&& surface) : mSurface(std::move(surface)) { - LOG_ALWAYS_FATAL_IF(!mSurface, "Error, unable to wrap a nullptr"); +ReliableSurface::ReliableSurface(ANativeWindow* window) : mWindow(window) { + LOG_ALWAYS_FATAL_IF(!mWindow, "Error, unable to wrap a nullptr"); + ANativeWindow_acquire(mWindow); } ReliableSurface::~ReliableSurface() { @@ -36,26 +40,27 @@ ReliableSurface::~ReliableSurface() { // As a concrete example, if the underlying ANativeWindow is associated with // an EGLSurface that is still in use, then if we don't clear out the // interceptors then we walk into undefined behavior. - ANativeWindow_setCancelBufferInterceptor(mSurface.get(), nullptr, nullptr); - ANativeWindow_setDequeueBufferInterceptor(mSurface.get(), nullptr, nullptr); - ANativeWindow_setQueueBufferInterceptor(mSurface.get(), nullptr, nullptr); - ANativeWindow_setPerformInterceptor(mSurface.get(), nullptr, nullptr); + ANativeWindow_setCancelBufferInterceptor(mWindow, nullptr, nullptr); + ANativeWindow_setDequeueBufferInterceptor(mWindow, nullptr, nullptr); + ANativeWindow_setQueueBufferInterceptor(mWindow, nullptr, nullptr); + ANativeWindow_setPerformInterceptor(mWindow, nullptr, nullptr); + ANativeWindow_release(mWindow); } void ReliableSurface::init() { - int result = ANativeWindow_setCancelBufferInterceptor(mSurface.get(), hook_cancelBuffer, this); + int result = ANativeWindow_setCancelBufferInterceptor(mWindow, hook_cancelBuffer, this); LOG_ALWAYS_FATAL_IF(result != NO_ERROR, "Failed to set cancelBuffer interceptor: error = %d", result); - result = ANativeWindow_setDequeueBufferInterceptor(mSurface.get(), hook_dequeueBuffer, this); + result = ANativeWindow_setDequeueBufferInterceptor(mWindow, hook_dequeueBuffer, this); LOG_ALWAYS_FATAL_IF(result != NO_ERROR, "Failed to set dequeueBuffer interceptor: error = %d", result); - result = ANativeWindow_setQueueBufferInterceptor(mSurface.get(), hook_queueBuffer, this); + result = ANativeWindow_setQueueBufferInterceptor(mWindow, hook_queueBuffer, this); LOG_ALWAYS_FATAL_IF(result != NO_ERROR, "Failed to set queueBuffer interceptor: error = %d", result); - result = ANativeWindow_setPerformInterceptor(mSurface.get(), hook_perform, this); + result = ANativeWindow_setPerformInterceptor(mWindow, hook_perform, this); LOG_ALWAYS_FATAL_IF(result != NO_ERROR, "Failed to set perform interceptor: error = %d", result); } @@ -87,7 +92,7 @@ int ReliableSurface::reserveNext() { ANativeWindowBuffer* buffer = nullptr; // Note that this calls back into our own hooked method. - int result = ANativeWindow_dequeueBuffer(mSurface.get(), &buffer, &fenceFd); + int result = ANativeWindow_dequeueBuffer(mWindow, &buffer, &fenceFd); { std::lock_guard _lock{mMutex}; @@ -117,7 +122,7 @@ void ReliableSurface::clearReservedBuffer() { // Note that clearReservedBuffer may be reentrant here, so // mReservedBuffer must be cleared once we reach here to avoid recursing // forever. - ANativeWindow_cancelBuffer(mSurface.get(), buffer, releaseFd); + ANativeWindow_cancelBuffer(mWindow, buffer, releaseFd); } } @@ -239,10 +244,10 @@ int ReliableSurface::hook_perform(ANativeWindow* window, ANativeWindow_performFn case ANATIVEWINDOW_PERFORM_SET_BUFFERS_GEOMETRY: /* width */ va_arg(args, uint32_t); /* height */ va_arg(args, uint32_t); - rs->mFormat = va_arg(args, PixelFormat); + rs->mFormat = static_cast<AHardwareBuffer_Format>(va_arg(args, int32_t)); break; case ANATIVEWINDOW_PERFORM_SET_BUFFERS_FORMAT: - rs->mFormat = va_arg(args, PixelFormat); + rs->mFormat = static_cast<AHardwareBuffer_Format>(va_arg(args, int32_t)); break; } } diff --git a/libs/hwui/renderthread/ReliableSurface.h b/libs/hwui/renderthread/ReliableSurface.h index e3cd8c019a23..58cd06730123 100644 --- a/libs/hwui/renderthread/ReliableSurface.h +++ b/libs/hwui/renderthread/ReliableSurface.h @@ -16,12 +16,14 @@ #pragma once +#include <android-base/unique_fd.h> #include <apex/window.h> -#include <gui/Surface.h> +#include <utils/Errors.h> #include <utils/Macros.h> #include <utils/StrongPointer.h> #include <memory> +#include <mutex> namespace android::uirenderer::renderthread { @@ -29,7 +31,7 @@ class ReliableSurface { PREVENT_COPY_AND_ASSIGN(ReliableSurface); public: - ReliableSurface(sp<Surface>&& surface); + ReliableSurface(ANativeWindow* window); ~ReliableSurface(); // Performs initialization that is not safe to do in the constructor. @@ -37,12 +39,10 @@ public: // passed as the data pointer is not safe. void init(); - ANativeWindow* getNativeWindow() { return mSurface.get(); } + ANativeWindow* getNativeWindow() { return mWindow; } int reserveNext(); - int query(int what, int* value) const { return mSurface->query(what, value); } - int getAndClearError() { int ret = mBufferQueueState; mBufferQueueState = OK; @@ -50,12 +50,12 @@ public: } private: - 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; diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index 1e7fc71a7f04..b66a13d1efda 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -16,8 +16,6 @@ #include "RenderProxy.h" -#include <gui/Surface.h> - #include "DeferredLayerUpdater.h" #include "DisplayList.h" #include "Properties.h" @@ -78,9 +76,11 @@ void RenderProxy::setName(const char* name) { mRenderThread.queue().runSync([this, name]() { mContext->setName(std::string(name)); }); } -void RenderProxy::setSurface(const sp<Surface>& surface, bool enableTimeout) { - mRenderThread.queue().post([this, surf = surface, enableTimeout]() mutable { - mContext->setSurface(std::move(surf), enableTimeout); +void RenderProxy::setSurface(ANativeWindow* window, bool enableTimeout) { + ANativeWindow_acquire(window); + mRenderThread.queue().post([this, win = window, enableTimeout]() mutable { + mContext->setSurface(win, enableTimeout); + ANativeWindow_release(win); }); } @@ -314,10 +314,9 @@ void RenderProxy::setRenderAheadDepth(int renderAhead) { [context = mContext, renderAhead] { context->setRenderAheadDepth(renderAhead); }); } -int RenderProxy::copySurfaceInto(sp<Surface>& surface, int left, int top, int right, int bottom, +int RenderProxy::copySurfaceInto(ANativeWindow* window, int left, int top, int right, int bottom, SkBitmap* bitmap) { auto& thread = RenderThread::getInstance(); - ANativeWindow* window = surface.get(); return static_cast<int>(thread.queue().runSync([&]() -> auto { return thread.readback().copySurfaceInto(window, Rect(left, top, right, bottom), bitmap); })); diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index ab0dd2bcc8f5..3baeb2f7a476 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -18,6 +18,7 @@ #define RENDERPROXY_H_ #include <SkBitmap.h> +#include <android/native_window.h> #include <cutils/compiler.h> #include <utils/Functor.h> @@ -69,7 +70,7 @@ public: ANDROID_API bool loadSystemProperties(); ANDROID_API void setName(const char* name); - ANDROID_API void setSurface(const sp<Surface>& surface, bool enableTimeout = true); + ANDROID_API void setSurface(ANativeWindow* window, bool enableTimeout = true); ANDROID_API void allocateBuffers(); ANDROID_API bool pause(); ANDROID_API void setStopped(bool stopped); @@ -140,11 +141,7 @@ public: */ ANDROID_API void setRenderAheadDepth(int renderAhead); - // TODO: This api will need to take in an ANativeWindow instead, but the - // caller, ThreadedRenderer, doesn't have access to libandroid due to a - // circular dependency, so it can't use the JNI ANativeWindow methods. Once - // that is resolved then replace the surface type here. - ANDROID_API static int copySurfaceInto(sp<Surface>& surface, int left, int top, int right, + ANDROID_API static int copySurfaceInto(ANativeWindow* window, int left, int top, int right, int bottom, SkBitmap* bitmap); ANDROID_API static void prepareToDraw(Bitmap& bitmap); |