summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaƫl Moll <raphael@google.com>2023-11-22 19:11:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-11-22 19:11:00 +0000
commit3b3bd6ad264b7f773ab3ceef08ebde69d9162d96 (patch)
tree2ed315350b2bae0d66b3205a7b9dfa588a0fa07a
parentb5e171dda6e144052637b01bcf30a5a0867b43cf (diff)
parent3d664c52fba5e1ea2edbb0be8211b3c5b44b8261 (diff)
downloadbase-3b3bd6ad264b7f773ab3ceef08ebde69d9162d96.tar.gz
Merge "[RNG] Merge ifdef support layers from sc-layoutlib-native." into android12-hostruntime-dev
-rw-r--r--libs/hwui/Android.bp4
-rw-r--r--libs/hwui/Properties.cpp1
-rw-r--r--libs/hwui/Properties.h1
-rw-r--r--libs/hwui/RenderNode.cpp2
-rw-r--r--libs/hwui/pipeline/skia/RenderNodeDrawable.cpp35
-rw-r--r--libs/hwui/pipeline/skia/SkiaPipeline.cpp18
-rw-r--r--libs/hwui/renderthread/EglManager.cpp3
7 files changed, 42 insertions, 22 deletions
diff --git a/libs/hwui/Android.bp b/libs/hwui/Android.bp
index 955ef13eb0ab..4eda9ed10db9 100644
--- a/libs/hwui/Android.bp
+++ b/libs/hwui/Android.bp
@@ -546,6 +546,8 @@ cc_defaults {
"FrameInfo.cpp",
"DamageAccumulator.cpp",
"Interpolator.cpp",
+ "Layer.cpp",
+ "LayerUpdateQueue.cpp",
"LightingInfo.cpp",
"Matrix.cpp",
"PathParser.cpp",
@@ -600,8 +602,6 @@ cc_defaults {
"HardwareBitmapUploader.cpp",
"HWUIProperties.sysprop",
"JankTracker.cpp",
- "Layer.cpp",
- "LayerUpdateQueue.cpp",
"ProfileData.cpp",
"ProfileDataContainer.cpp",
"Readback.cpp",
diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp
index b8fa55a18dac..2f7564f79f26 100644
--- a/libs/hwui/Properties.cpp
+++ b/libs/hwui/Properties.cpp
@@ -50,6 +50,7 @@ bool Properties::showDirtyRegions = false;
bool Properties::skipEmptyFrames = true;
bool Properties::useBufferAge = true;
bool Properties::enablePartialUpdates = true;
+bool Properties::enableRenderEffectCache = false;
DebugLevel Properties::debugLevel = kDebugDisabled;
OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index 7df6e2c92247..d224a547ab4d 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -224,6 +224,7 @@ public:
static bool skipEmptyFrames;
static bool useBufferAge;
static bool enablePartialUpdates;
+ static bool enableRenderEffectCache;
// TODO: Move somewhere else?
static constexpr float textGamma = 1.45f;
diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp
index bb700c4e4f7c..feb93e49cea6 100644
--- a/libs/hwui/RenderNode.cpp
+++ b/libs/hwui/RenderNode.cpp
@@ -166,7 +166,6 @@ void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) {
}
void RenderNode::pushLayerUpdate(TreeInfo& info) {
-#ifdef __ANDROID__ // Layoutlib does not support CanvasContext and Layers
LayerType layerType = properties().effectiveLayerType();
// If we are not a layer OR we cannot be rendered (eg, view was detached)
// we need to destroy any Layers we may have had previously
@@ -198,7 +197,6 @@ void RenderNode::pushLayerUpdate(TreeInfo& info) {
// That might be us, so tell CanvasContext that this layer is in the
// tree and should not be destroyed.
info.canvasContext.markLayerInUse(this);
-#endif
}
/**
diff --git a/libs/hwui/pipeline/skia/RenderNodeDrawable.cpp b/libs/hwui/pipeline/skia/RenderNodeDrawable.cpp
index 7556af918170..48145d2331ee 100644
--- a/libs/hwui/pipeline/skia/RenderNodeDrawable.cpp
+++ b/libs/hwui/pipeline/skia/RenderNodeDrawable.cpp
@@ -231,14 +231,33 @@ void RenderNodeDrawable::drawContent(SkCanvas* canvas) const {
SkASSERT(properties.effectiveLayerType() == LayerType::RenderLayer);
SkPaint paint;
layerNeedsPaint(layerProperties, alphaMultiplier, &paint);
- const auto snapshotResult = renderNode->updateSnapshotIfRequired(
- canvas->recordingContext(),
- layerProperties.getImageFilter(),
- clipBounds.roundOut()
- );
- sk_sp<SkImage> snapshotImage = snapshotResult->snapshot;
- srcBounds = snapshotResult->outSubset;
- offset = snapshotResult->outOffset;
+ sk_sp<SkImage> snapshotImage;
+ auto* imageFilter = layerProperties.getImageFilter();
+ auto recordingContext = canvas->recordingContext();
+ // On some GL vendor implementations, caching the result of
+ // getLayerSurface->makeImageSnapshot() causes a call to
+ // Fence::waitForever without a corresponding signal. This would
+ // lead to ANRs throughout the system.
+ // Instead only cache the SkImage created with the SkImageFilter
+ // for supported devices. Otherwise just create a new SkImage with
+ // the corresponding SkImageFilter each time.
+ // See b/193145089 and b/197263715
+ if (!Properties::enableRenderEffectCache) {
+ snapshotImage = renderNode->getLayerSurface()->makeImageSnapshot();
+ if (imageFilter) {
+ auto subset = SkIRect::MakeWH(srcBounds.width(), srcBounds.height());
+ snapshotImage = snapshotImage->makeWithFilter(recordingContext, imageFilter,
+ subset, clipBounds.roundOut(),
+ &srcBounds, &offset);
+ }
+ } else {
+ const auto snapshotResult = renderNode->updateSnapshotIfRequired(
+ recordingContext, layerProperties.getImageFilter(), clipBounds.roundOut());
+ snapshotImage = snapshotResult->snapshot;
+ srcBounds = snapshotResult->outSubset;
+ offset = snapshotResult->outOffset;
+ }
+
const auto dstBounds = SkIRect::MakeXYWH(offset.x(),
offset.y(),
srcBounds.width(),
diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.cpp b/libs/hwui/pipeline/skia/SkiaPipeline.cpp
index 6ac71e028501..51720277b0de 100644
--- a/libs/hwui/pipeline/skia/SkiaPipeline.cpp
+++ b/libs/hwui/pipeline/skia/SkiaPipeline.cpp
@@ -90,9 +90,7 @@ void SkiaPipeline::renderLayers(const LightGeometry& lightGeometry,
LightingInfo::updateLighting(lightGeometry, lightInfo);
ATRACE_NAME("draw layers");
renderLayersImpl(*layerUpdateQueue, opaque);
-#ifdef __ANDROID__ // Layoutlib does not support Layers
layerUpdateQueue->clear();
-#endif
}
void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque) {
@@ -165,7 +163,7 @@ void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque)
}
#endif
}
-#ifdef __ANDROID__ // Layoutlib dose not support Layers
+#ifdef __ANDROID__ // Layoutlib dose not support Gr
if (cachedContext.get()) {
ATRACE_NAME("flush layers");
cachedContext->flushAndSubmit();
@@ -175,7 +173,6 @@ void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque)
bool SkiaPipeline::createOrUpdateLayer(RenderNode* node, const DamageAccumulator& damageAccumulator,
ErrorHandler* errorHandler) {
-#ifdef __ANDROID__ // Layoutlib dose not support Layers
// compute the size of the surface (i.e. texture) to be allocated for this layer
const int surfaceWidth = ceilf(node->getWidth() / float(LAYER_SIZE)) * LAYER_SIZE;
const int surfaceHeight = ceilf(node->getHeight() / float(LAYER_SIZE)) * LAYER_SIZE;
@@ -186,10 +183,14 @@ bool SkiaPipeline::createOrUpdateLayer(RenderNode* node, const DamageAccumulator
info = SkImageInfo::Make(surfaceWidth, surfaceHeight, getSurfaceColorType(),
kPremul_SkAlphaType, getSurfaceColorSpace());
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
+#ifdef __ANDROID__ // Layoutlib does not support Gr
SkASSERT(mRenderThread.getGrContext() != nullptr);
node->setLayerSurface(SkSurface::MakeRenderTarget(mRenderThread.getGrContext(),
SkBudgeted::kYes, info, 0,
this->getSurfaceOrigin(), &props));
+#else
+ node->setLayerSurface(SkSurface::MakeRaster(info, &props));
+#endif
if (node->getLayerSurface()) {
// update the transform in window of the layer to reset its origin wrt light source
// position
@@ -197,6 +198,7 @@ bool SkiaPipeline::createOrUpdateLayer(RenderNode* node, const DamageAccumulator
damageAccumulator.computeCurrentTransform(&windowTransform);
node->getSkiaLayer()->inverseTransformInWindow.loadInverse(windowTransform);
} else {
+#ifdef __ANDROID__ // Layoutlib does not support Gr
String8 cachesOutput;
mRenderThread.cacheManager().dumpMemoryUsage(cachesOutput,
&mRenderThread.renderState());
@@ -210,10 +212,10 @@ bool SkiaPipeline::createOrUpdateLayer(RenderNode* node, const DamageAccumulator
<< (int)(mRenderThread.getGrContext() != nullptr);
errorHandler->onError(err.str());
}
+#endif
}
return true;
}
-#endif
return false;
}
@@ -315,7 +317,6 @@ bool SkiaPipeline::setupMultiFrameCapture() {
}
#endif
-#ifdef __ANDROID__ // Layoutlib does not support Layers
// recurse through the rendernode's children, add any nodes which are layers to the queue.
static void collectLayers(RenderNode* node, LayerUpdateQueue* layers) {
SkiaDisplayList* dl = node->getDisplayList().asSkiaDl();
@@ -358,16 +359,15 @@ static void recordLayers(const LayerUpdateQueue& layers,
}
LightingInfo::setLightCenterRaw(savedLightCenter);
}
-#endif
SkCanvas* SkiaPipeline::tryCapture(SkSurface* surface, RenderNode* root,
const LayerUpdateQueue& dirtyLayers) {
if (CC_LIKELY(!Properties::skpCaptureEnabled)) {
return surface->getCanvas(); // Bail out early when capture is not turned on.
}
-#ifdef __ANDROID__ // Layoutlib does not support multiframe capture
// Note that shouldStartNewFileCapture tells us if this is the *first* frame of a capture.
bool firstFrameOfAnim = false;
+#ifdef __ANDROID__ // Layoutlib does not support multiframe capture
if (shouldStartNewFileCapture() && mCaptureMode == CaptureMode::MultiFrameSKP) {
// set a reminder to record every layer near the end of this method, after we have set up
// the nway canvas.
@@ -402,7 +402,6 @@ SkCanvas* SkiaPipeline::tryCapture(SkSurface* surface, RenderNode* root,
mNwayCanvas->addCanvas(surface->getCanvas());
mNwayCanvas->addCanvas(pictureCanvas);
-#ifdef __ANDROID__ // Layoutlib does not support Layers
if (firstFrameOfAnim) {
// On the first frame of any mskp capture we want to record any layers that are needed in
// frame but may have been rendered offscreen before recording began.
@@ -415,7 +414,6 @@ SkCanvas* SkiaPipeline::tryCapture(SkSurface* surface, RenderNode* root,
// on non-first frames, we record any normal layer draws (dirty regions)
recordLayers(dirtyLayers, mNwayCanvas.get());
}
-#endif
return mNwayCanvas.get();
}
diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp
index a11678189bad..383c79b27918 100644
--- a/libs/hwui/renderthread/EglManager.cpp
+++ b/libs/hwui/renderthread/EglManager.cpp
@@ -146,6 +146,9 @@ void EglManager::initialize() {
LOG_ALWAYS_FATAL("Unsupported wide color space.");
}
mHasWideColorGamutSupport = EglExtensions.glColorSpace && hasWideColorSpaceExtension;
+
+ auto* vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
+ Properties::enableRenderEffectCache = (strcmp(vendor, "Qualcomm") != 0);
}
EGLConfig EglManager::load8BitsConfig(EGLDisplay display, EglManager::SwapBehavior swapBehavior) {