diff options
author | 2024-02-13 16:33:00 +0000 | |
---|---|---|
committer | 2024-02-22 16:44:01 +0000 | |
commit | 87ef524058b8e30e59ac944016168ea4113744ca (patch) | |
tree | cd9d7e588f3d6c3fa836935fcc69b1f2ea1cfbc7 | |
parent | 56ca544750274320bdd51d17dbaa1dc9010f6b13 (diff) |
Implement RenderThread for host
This creates a host implementation of RenderThread in libhwui.
In order to do this, it also implements ThreadBase, ReadBack,
CacheManager. Most of those implementations are no-op.
Bug: 322360037
Test: build libandroid_runtime on host
Change-Id: If72f46fe9baa645ff95330b971a102c2db554bb6
-rw-r--r-- | libs/hwui/Android.bp | 41 | ||||
-rw-r--r-- | libs/hwui/ProfileData.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/platform/android/thread/ThreadBase.h (renamed from libs/hwui/thread/ThreadBase.h) | 6 | ||||
-rw-r--r-- | libs/hwui/platform/host/ProfileDataContainer.cpp | 40 | ||||
-rw-r--r-- | libs/hwui/platform/host/Readback.cpp | 50 | ||||
-rw-r--r-- | libs/hwui/platform/host/WebViewFunctorManager.cpp | 75 | ||||
-rw-r--r-- | libs/hwui/platform/host/renderthread/CacheManager.cpp | 64 | ||||
-rw-r--r-- | libs/hwui/platform/host/renderthread/RenderThread.cpp | 141 | ||||
-rw-r--r-- | libs/hwui/platform/host/thread/ThreadBase.h | 76 | ||||
-rw-r--r-- | libs/hwui/private/hwui/WebViewFunctor.h | 8 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderThread.cpp | 3 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderThread.h | 3 |
12 files changed, 488 insertions, 21 deletions
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp index e4f3e2defb25..abd84de7da3c 100644 --- a/libs/hwui/Android.bp +++ b/libs/hwui/Android.bp @@ -155,6 +155,7 @@ cc_defaults { host: { static_libs: [ "libandroidfw", + "libhostgraphics", "libutils", ], }, @@ -501,6 +502,17 @@ cc_library_headers { ], header_libs: ["android_graphics_jni_headers"], export_header_lib_headers: ["android_graphics_jni_headers"], + target: { + android: { + export_include_dirs: ["platform/android"], + }, + host: { + export_include_dirs: ["platform/host"], + }, + windows: { + enabled: true, + }, + }, } cc_defaults { @@ -538,6 +550,7 @@ cc_defaults { "utils/Blur.cpp", "utils/Color.cpp", "utils/LinearAllocator.cpp", + "utils/StringUtils.cpp", "utils/TypefaceUtils.cpp", "utils/VectorDrawableUtils.cpp", "AnimationContext.cpp", @@ -552,6 +565,7 @@ cc_defaults { "Mesh.cpp", "MemoryPolicy.cpp", "PathParser.cpp", + "ProfileData.cpp", "Properties.cpp", "PropertyValuesAnimatorSet.cpp", "PropertyValuesHolder.cpp", @@ -569,12 +583,13 @@ cc_defaults { export_proto_headers: true, }, + header_libs: ["libandroid_headers_private"], + target: { android: { - header_libs: [ - "libandroid_headers_private", - "libtonemap_headers", - ], + header_libs: ["libtonemap_headers"], + + local_include_dirs: ["platform/android"], srcs: [ "hwui/AnimatedImageThread.cpp", @@ -605,7 +620,6 @@ cc_defaults { "thread/CommonPool.cpp", "utils/GLUtils.cpp", "utils/NdkUtils.cpp", - "utils/StringUtils.cpp", "AutoBackendTextureRelease.cpp", "DeferredLayerUpdater.cpp", "DeviceInfo.cpp", @@ -617,7 +631,6 @@ cc_defaults { "FrameMetricsReporter.cpp", "Layer.cpp", "LayerUpdateQueue.cpp", - "ProfileData.cpp", "ProfileDataContainer.cpp", "Readback.cpp", "TreeInfo.cpp", @@ -628,6 +641,21 @@ cc_defaults { // Allow implicit fallthroughs in HardwareBitmapUploader.cpp until they are fixed. cflags: ["-Wno-implicit-fallthrough"], }, + host: { + header_libs: ["libnativebase_headers"], + + local_include_dirs: ["platform/host"], + + srcs: [ + "platform/host/renderthread/CacheManager.cpp", + "platform/host/renderthread/RenderThread.cpp", + "platform/host/ProfileDataContainer.cpp", + "platform/host/Readback.cpp", + "platform/host/WebViewFunctorManager.cpp", + ], + + cflags: ["-Wno-unused-private-field"], + }, }, } @@ -663,6 +691,7 @@ cc_defaults { header_libs: ["libandroid_headers_private"], target: { android: { + local_include_dirs: ["platform/android"], shared_libs: [ "libgui", "libui", diff --git a/libs/hwui/ProfileData.cpp b/libs/hwui/ProfileData.cpp index 3d0ca0a10851..7be9541f6b99 100644 --- a/libs/hwui/ProfileData.cpp +++ b/libs/hwui/ProfileData.cpp @@ -110,6 +110,7 @@ void ProfileData::mergeWith(const ProfileData& other) { } void ProfileData::dump(int fd) const { +#ifdef __ANDROID__ dprintf(fd, "\nStats since: %" PRIu64 "ns", mStatStartTime); dprintf(fd, "\nTotal frames rendered: %u", mTotalFrameCount); dprintf(fd, "\nJanky frames: %u (%.2f%%)", mJankFrameCount, @@ -138,6 +139,7 @@ void ProfileData::dump(int fd) const { dprintf(fd, " %ums=%u", entry.renderTimeMs, entry.frameCount); }); dprintf(fd, "\n"); +#endif } uint32_t ProfileData::findPercentile(int percentile) const { diff --git a/libs/hwui/thread/ThreadBase.h b/libs/hwui/platform/android/thread/ThreadBase.h index 0289d3fd2ef7..2f3581f8b355 100644 --- a/libs/hwui/thread/ThreadBase.h +++ b/libs/hwui/platform/android/thread/ThreadBase.h @@ -17,14 +17,14 @@ #ifndef HWUI_THREADBASE_H #define HWUI_THREADBASE_H -#include "WorkQueue.h" -#include "utils/Macros.h" - #include <utils/Looper.h> #include <utils/Thread.h> #include <algorithm> +#include "thread/WorkQueue.h" +#include "utils/Macros.h" + namespace android::uirenderer { class ThreadBase : public Thread { diff --git a/libs/hwui/platform/host/ProfileDataContainer.cpp b/libs/hwui/platform/host/ProfileDataContainer.cpp new file mode 100644 index 000000000000..9ed1b02a8082 --- /dev/null +++ b/libs/hwui/platform/host/ProfileDataContainer.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ProfileDataContainer.h" + +#include <log/log.h> + +namespace android { +namespace uirenderer { + +void ProfileDataContainer::freeData() REQUIRES(mJankDataMutex) { + delete mData; + mIsMapped = false; + mData = nullptr; +} + +void ProfileDataContainer::rotateStorage() { + std::lock_guard lock(mJankDataMutex); + mData->reset(); +} + +void ProfileDataContainer::switchStorageToAshmem(int ashmemfd) { + ALOGE("Ashmem is not supported for non-Android configurations"); +} + +} /* namespace uirenderer */ +} /* namespace android */ diff --git a/libs/hwui/platform/host/Readback.cpp b/libs/hwui/platform/host/Readback.cpp new file mode 100644 index 000000000000..b024ec02efc3 --- /dev/null +++ b/libs/hwui/platform/host/Readback.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Readback.h" + +using namespace android::uirenderer::renderthread; + +namespace android { +namespace uirenderer { + +void Readback::copySurfaceInto(ANativeWindow* window, const std::shared_ptr<CopyRequest>& request) { +} + +CopyResult Readback::copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap) { + return CopyResult::UnknownError; +} + +CopyResult Readback::copyLayerInto(DeferredLayerUpdater* deferredLayer, SkBitmap* bitmap) { + return CopyResult::UnknownError; +} + +CopyResult Readback::copyImageInto(const sk_sp<SkImage>& image, SkBitmap* bitmap) { + return CopyResult::UnknownError; +} + +CopyResult Readback::copyImageInto(const sk_sp<SkImage>& image, const Rect& srcRect, + SkBitmap* bitmap) { + return CopyResult::UnknownError; +} + +bool Readback::copyLayerInto(Layer* layer, const SkRect* srcRect, const SkRect* dstRect, + SkBitmap* bitmap) { + return false; +} + +} /* namespace uirenderer */ +} /* namespace android */ diff --git a/libs/hwui/platform/host/WebViewFunctorManager.cpp b/libs/hwui/platform/host/WebViewFunctorManager.cpp new file mode 100644 index 000000000000..1d16655bf73c --- /dev/null +++ b/libs/hwui/platform/host/WebViewFunctorManager.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "WebViewFunctorManager.h" + +namespace android::uirenderer { + +WebViewFunctor::WebViewFunctor(void* data, const WebViewFunctorCallbacks& callbacks, + RenderMode functorMode) + : mData(data) {} + +WebViewFunctor::~WebViewFunctor() {} + +void WebViewFunctor::sync(const WebViewSyncData& syncData) const {} + +void WebViewFunctor::onRemovedFromTree() {} + +bool WebViewFunctor::prepareRootSurfaceControl() { + return true; +} + +void WebViewFunctor::drawGl(const DrawGlInfo& drawInfo) {} + +void WebViewFunctor::initVk(const VkFunctorInitParams& params) {} + +void WebViewFunctor::drawVk(const VkFunctorDrawParams& params) {} + +void WebViewFunctor::postDrawVk() {} + +void WebViewFunctor::destroyContext() {} + +void WebViewFunctor::removeOverlays() {} + +ASurfaceControl* WebViewFunctor::getSurfaceControl() { + return mSurfaceControl; +} + +void WebViewFunctor::mergeTransaction(ASurfaceTransaction* transaction) {} + +void WebViewFunctor::reparentSurfaceControl(ASurfaceControl* parent) {} + +WebViewFunctorManager& WebViewFunctorManager::instance() { + static WebViewFunctorManager sInstance; + return sInstance; +} + +int WebViewFunctorManager::createFunctor(void* data, const WebViewFunctorCallbacks& callbacks, + RenderMode functorMode) { + return 0; +} + +void WebViewFunctorManager::releaseFunctor(int functor) {} + +void WebViewFunctorManager::onContextDestroyed() {} + +void WebViewFunctorManager::destroyFunctor(int functor) {} + +sp<WebViewFunctor::Handle> WebViewFunctorManager::handleFor(int functor) { + return nullptr; +} + +} // namespace android::uirenderer diff --git a/libs/hwui/platform/host/renderthread/CacheManager.cpp b/libs/hwui/platform/host/renderthread/CacheManager.cpp new file mode 100644 index 000000000000..b03f400cd7d6 --- /dev/null +++ b/libs/hwui/platform/host/renderthread/CacheManager.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "renderthread/CacheManager.h" + +namespace android { +namespace uirenderer { +namespace renderthread { + +CacheManager::CacheManager(RenderThread& thread) + : mRenderThread(thread), mMemoryPolicy(loadMemoryPolicy()) {} + +void CacheManager::setupCacheLimits() {} + +void CacheManager::destroy() {} + +void CacheManager::trimMemory(TrimLevel mode) {} + +void CacheManager::trimCaches(CacheTrimLevel mode) {} + +void CacheManager::trimStaleResources() {} + +void CacheManager::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) {} + +void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState) {} + +void CacheManager::onFrameCompleted() {} + +void CacheManager::onThreadIdle() {} + +void CacheManager::scheduleDestroyContext() {} + +void CacheManager::cancelDestroyContext() {} + +bool CacheManager::areAllContextsStopped() { + return false; +} + +void CacheManager::checkUiHidden() {} + +void CacheManager::registerCanvasContext(CanvasContext* context) {} + +void CacheManager::unregisterCanvasContext(CanvasContext* context) {} + +void CacheManager::onContextStopped(CanvasContext* context) {} + +void CacheManager::notifyNextFrameSize(int width, int height) {} + +} /* namespace renderthread */ +} /* namespace uirenderer */ +} /* namespace android */ diff --git a/libs/hwui/platform/host/renderthread/RenderThread.cpp b/libs/hwui/platform/host/renderthread/RenderThread.cpp new file mode 100644 index 000000000000..6f08b5979772 --- /dev/null +++ b/libs/hwui/platform/host/renderthread/RenderThread.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "renderthread/RenderThread.h" + +#include "Readback.h" +#include "renderthread/VulkanManager.h" + +namespace android { +namespace uirenderer { +namespace renderthread { + +static bool gHasRenderThreadInstance = false; +static JVMAttachHook gOnStartHook = nullptr; + +ASurfaceControlFunctions::ASurfaceControlFunctions() {} + +bool RenderThread::hasInstance() { + return gHasRenderThreadInstance; +} + +void RenderThread::setOnStartHook(JVMAttachHook onStartHook) { + LOG_ALWAYS_FATAL_IF(hasInstance(), "can't set an onStartHook after we've started..."); + gOnStartHook = onStartHook; +} + +JVMAttachHook RenderThread::getOnStartHook() { + return gOnStartHook; +} + +RenderThread& RenderThread::getInstance() { + [[clang::no_destroy]] static sp<RenderThread> sInstance = []() { + sp<RenderThread> thread = sp<RenderThread>::make(); + thread->start("RenderThread"); + return thread; + }(); + gHasRenderThreadInstance = true; + return *sInstance; +} + +RenderThread::RenderThread() + : ThreadBase() + , mVsyncSource(nullptr) + , mVsyncRequested(false) + , mFrameCallbackTaskPending(false) + , mRenderState(nullptr) + , mEglManager(nullptr) + , mFunctorManager(WebViewFunctorManager::instance()) + , mGlobalProfileData(mJankDataMutex) { + Properties::load(); +} + +RenderThread::~RenderThread() {} + +void RenderThread::initThreadLocals() { + mCacheManager = new CacheManager(*this); +} + +void RenderThread::requireGlContext() {} + +void RenderThread::requireVkContext() {} + +void RenderThread::initGrContextOptions(GrContextOptions& options) {} + +void RenderThread::destroyRenderingContext() {} + +VulkanManager& RenderThread::vulkanManager() { + return *mVkManager; +} + +void RenderThread::dumpGraphicsMemory(int fd, bool includeProfileData) {} + +void RenderThread::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) {} + +Readback& RenderThread::readback() { + if (!mReadback) { + mReadback = new Readback(*this); + } + + return *mReadback; +} + +void RenderThread::setGrContext(sk_sp<GrDirectContext> context) {} + +sk_sp<GrDirectContext> RenderThread::requireGrContext() { + return mGrContext; +} + +bool RenderThread::threadLoop() { + if (gOnStartHook) { + gOnStartHook("RenderThread"); + } + initThreadLocals(); + + while (true) { + waitForWork(); + processQueue(); + mCacheManager->onThreadIdle(); + } + + return false; +} + +void RenderThread::postFrameCallback(IFrameCallback* callback) {} + +bool RenderThread::removeFrameCallback(IFrameCallback* callback) { + return false; +} + +void RenderThread::pushBackFrameCallback(IFrameCallback* callback) {} + +sk_sp<Bitmap> RenderThread::allocateHardwareBitmap(SkBitmap& skBitmap) { + return nullptr; +} + +bool RenderThread::isCurrent() { + return true; +} + +void RenderThread::preload() {} + +void RenderThread::trimMemory(TrimLevel level) {} + +void RenderThread::trimCaches(CacheTrimLevel level) {} + +} /* namespace renderthread */ +} /* namespace uirenderer */ +} /* namespace android */ diff --git a/libs/hwui/platform/host/thread/ThreadBase.h b/libs/hwui/platform/host/thread/ThreadBase.h new file mode 100644 index 000000000000..d709430cc9b6 --- /dev/null +++ b/libs/hwui/platform/host/thread/ThreadBase.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HWUI_THREADBASE_H +#define HWUI_THREADBASE_H + +#include <utils/Thread.h> + +#include <algorithm> + +#include "thread/WorkQueue.h" +#include "utils/Macros.h" + +namespace android::uirenderer { + +class ThreadBase : public Thread { + PREVENT_COPY_AND_ASSIGN(ThreadBase); + +public: + ThreadBase() : Thread(false), mQueue([this]() { mCondition.notify_all(); }, mLock) {} + + WorkQueue& queue() { return mQueue; } + + void requestExit() { Thread::requestExit(); } + + void start(const char* name = "ThreadBase") { Thread::run(name); } + + void join() { Thread::join(); } + + bool isRunning() const { return Thread::isRunning(); } + +protected: + void waitForWork() { + std::unique_lock lock{mLock}; + nsecs_t nextWakeup = mQueue.nextWakeup(lock); + std::chrono::nanoseconds duration = std::chrono::nanoseconds::max(); + if (nextWakeup < std::numeric_limits<nsecs_t>::max()) { + int timeout = nextWakeup - WorkQueue::clock::now(); + if (timeout < 0) timeout = 0; + duration = std::chrono::nanoseconds(timeout); + } + mCondition.wait_for(lock, duration); + } + + void processQueue() { mQueue.process(); } + + virtual bool threadLoop() override { + while (!exitPending()) { + waitForWork(); + processQueue(); + } + return false; + } + +private: + WorkQueue mQueue; + std::mutex mLock; + std::condition_variable mCondition; +}; + +} // namespace android::uirenderer + +#endif // HWUI_THREADBASE_H diff --git a/libs/hwui/private/hwui/WebViewFunctor.h b/libs/hwui/private/hwui/WebViewFunctor.h index 22ae59e5137b..493c943079ab 100644 --- a/libs/hwui/private/hwui/WebViewFunctor.h +++ b/libs/hwui/private/hwui/WebViewFunctor.h @@ -17,15 +17,7 @@ #ifndef FRAMEWORKS_BASE_WEBVIEWFUNCTOR_H #define FRAMEWORKS_BASE_WEBVIEWFUNCTOR_H -#ifdef __ANDROID__ // Layoutlib does not support surface control #include <android/surface_control.h> -#else -// To avoid ifdefs around overlay implementation all over the place we typedef these to void *. They -// won't be used. -typedef void* ASurfaceControl; -typedef void* ASurfaceTransaction; -#endif - #include <cutils/compiler.h> #include <private/hwui/DrawGlInfo.h> #include <private/hwui/DrawVkInfo.h> diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index 623ee4e6c27e..a024aeb285f9 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -17,11 +17,12 @@ #include "RenderThread.h" #include <GrContextOptions.h> -#include <include/gpu/ganesh/gl/GrGLDirectContext.h> #include <android-base/properties.h> #include <dlfcn.h> #include <gl/GrGLInterface.h> #include <gui/TraceUtils.h> +#include <include/gpu/ganesh/gl/GrGLDirectContext.h> +#include <private/android/choreographer.h> #include <sys/resource.h> #include <ui/FatVector.h> #include <utils/Condition.h> diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h index 79e57de9d66f..045d26f1d329 100644 --- a/libs/hwui/renderthread/RenderThread.h +++ b/libs/hwui/renderthread/RenderThread.h @@ -20,10 +20,7 @@ #include <GrDirectContext.h> #include <SkBitmap.h> #include <cutils/compiler.h> -#include <private/android/choreographer.h> #include <surface_control_private.h> -#include <thread/ThreadBase.h> -#include <utils/Looper.h> #include <utils/Thread.h> #include <memory> |