summaryrefslogtreecommitdiff
path: root/libs/hwui/renderthread/RenderProxy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/renderthread/RenderProxy.cpp')
-rw-r--r--libs/hwui/renderthread/RenderProxy.cpp94
1 files changed, 67 insertions, 27 deletions
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index b66a13d1efda..6fd644bfa28e 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -16,6 +16,7 @@
#include "RenderProxy.h"
+#include <gui/TraceUtils.h>
#include "DeferredLayerUpdater.h"
#include "DisplayList.h"
#include "Properties.h"
@@ -27,7 +28,6 @@
#include "renderthread/RenderThread.h"
#include "utils/Macros.h"
#include "utils/TimeUtils.h"
-#include "utils/TraceUtils.h"
namespace android {
namespace uirenderer {
@@ -76,11 +76,30 @@ void RenderProxy::setName(const char* name) {
mRenderThread.queue().runSync([this, name]() { mContext->setName(std::string(name)); });
}
+void RenderProxy::setHintSessionCallbacks(std::function<void(int64_t)> updateTargetWorkDuration,
+ std::function<void(int64_t)> reportActualWorkDuration) {
+ mDrawFrameTask.setHintSessionCallbacks(std::move(updateTargetWorkDuration),
+ std::move(reportActualWorkDuration));
+}
+
void RenderProxy::setSurface(ANativeWindow* window, bool enableTimeout) {
- ANativeWindow_acquire(window);
+ if (window) { ANativeWindow_acquire(window); }
mRenderThread.queue().post([this, win = window, enableTimeout]() mutable {
mContext->setSurface(win, enableTimeout);
- ANativeWindow_release(win);
+ if (win) { ANativeWindow_release(win); }
+ });
+}
+
+void RenderProxy::setSurfaceControl(ASurfaceControl* surfaceControl) {
+ auto funcs = mRenderThread.getASurfaceControlFunctions();
+ if (surfaceControl) {
+ funcs.acquireFunc(surfaceControl);
+ }
+ mRenderThread.queue().post([this, control = surfaceControl, funcs]() mutable {
+ mContext->setSurfaceControl(control);
+ if (control) {
+ funcs.releaseFunc(control);
+ }
});
}
@@ -109,8 +128,8 @@ void RenderProxy::setOpaque(bool opaque) {
mRenderThread.queue().post([=]() { mContext->setOpaque(opaque); });
}
-void RenderProxy::setWideGamut(bool wideGamut) {
- mRenderThread.queue().post([=]() { mContext->setWideGamut(wideGamut); });
+void RenderProxy::setColorMode(ColorMode mode) {
+ mRenderThread.queue().post([=]() { mContext->setColorMode(mode); });
}
int64_t* RenderProxy::frameInfo() {
@@ -128,20 +147,6 @@ void RenderProxy::destroy() {
mRenderThread.queue().runSync([=]() { mContext->destroy(); });
}
-void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
- ATRACE_CALL();
- RenderThread& thread = RenderThread::getInstance();
- auto invoke = [&thread, functor]() { CanvasContext::invokeFunctor(thread, functor); };
- if (waitForCompletion) {
- // waitForCompletion = true is expected to be fairly rare and only
- // happen in destruction. Thus it should be fine to temporarily
- // create a Mutex
- thread.queue().runSync(std::move(invoke));
- } else {
- thread.queue().post(std::move(invoke));
- }
-}
-
void RenderProxy::destroyFunctor(int functor) {
ATRACE_CALL();
RenderThread& thread = RenderThread::getInstance();
@@ -190,6 +195,17 @@ void RenderProxy::trimMemory(int level) {
}
}
+void RenderProxy::purgeCaches() {
+ if (RenderThread::hasInstance()) {
+ RenderThread& thread = RenderThread::getInstance();
+ thread.queue().post([&thread]() {
+ if (thread.getGrContext()) {
+ thread.cacheManager().trimMemory(CacheManager::TrimMemoryMode::Complete);
+ }
+ });
+ }
+}
+
void RenderProxy::overrideProperty(const char* name, const char* value) {
// expensive, but block here since name/value pointers owned by caller
RenderThread::getInstance().queue().runSync(
@@ -216,6 +232,7 @@ void RenderProxy::notifyFramePending() {
void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
mRenderThread.queue().runSync([&]() {
+ std::lock_guard lock(mRenderThread.getJankDataMutex());
mContext->profiler().dumpData(fd);
if (dumpFlags & DumpFlags::FrameStats) {
mContext->dumpFrames(fd);
@@ -230,19 +247,30 @@ void RenderProxy::dumpProfileInfo(int fd, int dumpFlags) {
}
void RenderProxy::resetProfileInfo() {
- mRenderThread.queue().runSync([=]() { mContext->resetFrameStats(); });
+ mRenderThread.queue().runSync([=]() {
+ std::lock_guard lock(mRenderThread.getJankDataMutex());
+ mContext->resetFrameStats();
+ });
}
uint32_t RenderProxy::frameTimePercentile(int percentile) {
return mRenderThread.queue().runSync([&]() -> auto {
+ std::lock_guard lock(mRenderThread.globalProfileData().getDataMutex());
return mRenderThread.globalProfileData()->findPercentile(percentile);
});
}
-void RenderProxy::dumpGraphicsMemory(int fd) {
+void RenderProxy::dumpGraphicsMemory(int fd, bool includeProfileData) {
if (RenderThread::hasInstance()) {
auto& thread = RenderThread::getInstance();
- thread.queue().runSync([&]() { thread.dumpGraphicsMemory(fd); });
+ thread.queue().runSync([&]() { thread.dumpGraphicsMemory(fd, includeProfileData); });
+ }
+}
+
+void RenderProxy::getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage) {
+ if (RenderThread::hasInstance()) {
+ auto& thread = RenderThread::getInstance();
+ thread.queue().runSync([&]() { thread.getMemoryUsage(cpuUsage, gpuUsage); });
}
}
@@ -285,6 +313,12 @@ void RenderProxy::setPictureCapturedCallback(
[this, cb = callback]() { mContext->setPictureCapturedCallback(cb); });
}
+void RenderProxy::setASurfaceTransactionCallback(
+ const std::function<void(int64_t, int64_t, int64_t)>& callback) {
+ mRenderThread.queue().post(
+ [this, cb = callback]() { mContext->setASurfaceTransactionCallback(cb); });
+}
+
void RenderProxy::setFrameCallback(std::function<void(int64_t)>&& callback) {
mDrawFrameTask.setFrameCallback(std::move(callback));
}
@@ -309,11 +343,6 @@ void RenderProxy::setForceDark(bool enable) {
mRenderThread.queue().post([this, enable]() { mContext->setForceDark(enable); });
}
-void RenderProxy::setRenderAheadDepth(int renderAhead) {
- mRenderThread.queue().post(
- [context = mContext, renderAhead] { context->setRenderAheadDepth(renderAhead); });
-}
-
int RenderProxy::copySurfaceInto(ANativeWindow* window, int left, int top, int right, int bottom,
SkBitmap* bitmap) {
auto& thread = RenderThread::getInstance();
@@ -361,6 +390,17 @@ int RenderProxy::copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap) {
}
}
+int RenderProxy::copyImageInto(const sk_sp<SkImage>& image, SkBitmap* bitmap) {
+ RenderThread& thread = RenderThread::getInstance();
+ if (gettid() == thread.getTid()) {
+ // TODO: fix everything that hits this. We should never be triggering a readback ourselves.
+ return (int)thread.readback().copyImageInto(image, bitmap);
+ } else {
+ return thread.queue().runSync(
+ [&]() -> int { return (int)thread.readback().copyImageInto(image, bitmap); });
+ }
+}
+
void RenderProxy::disableVsync() {
Properties::disableVsync = true;
}