Avoid creating a layer for linear stretch

Bug: 187718492
Test: manual logging no layer updates during benchmark
Change-Id: I9a231625142e404882be6c53fa6d01b2fb81af1a
This commit is contained in:
John Reck
2021-05-10 19:34:58 -04:00
parent a8427802f5
commit 09d9ccadc3
3 changed files with 8 additions and 7 deletions

View File

@@ -553,7 +553,7 @@ public:
bool promotedToLayer() const {
return mLayerProperties.mType == LayerType::None && fitsOnLayer() &&
(mComputedFields.mNeedLayerForFunctors || mLayerProperties.mImageFilter != nullptr ||
!mLayerProperties.getStretchEffect().isEmpty() ||
mLayerProperties.getStretchEffect().requiresLayer() ||
(!MathUtils::isZero(mPrimitiveFields.mAlpha) && mPrimitiveFields.mAlpha < 1 &&
mPrimitiveFields.mHasOverlappingRendering));
}

View File

@@ -16,6 +16,7 @@
#pragma once
#include "Properties.h"
#include "utils/MathUtils.h"
#include <SkImage.h>
@@ -108,6 +109,11 @@ public:
return matrix;
}
bool requiresLayer() const {
return !(isEmpty() ||
Properties::stretchEffectBehavior == StretchEffectBehavior::LinearScale);
}
private:
static sk_sp<SkRuntimeEffect> getStretchEffect();
mutable SkVector mStretchDirection{0, 0};

View File

@@ -171,16 +171,11 @@ void RenderNodeDrawable::forceDraw(SkCanvas* canvas) const {
displayList->mProjectedOutline = nullptr;
}
static bool stretchNeedsLayer(const LayerProperties& properties) {
return Properties::stretchEffectBehavior != StretchEffectBehavior::LinearScale &&
!properties.getStretchEffect().isEmpty();
}
static bool layerNeedsPaint(const sk_sp<SkImage>& snapshotImage, const LayerProperties& properties,
float alphaMultiplier, SkPaint* paint) {
if (alphaMultiplier < 1.0f || properties.alpha() < 255 ||
properties.xferMode() != SkBlendMode::kSrcOver || properties.getColorFilter() != nullptr ||
properties.getImageFilter() != nullptr || stretchNeedsLayer(properties)) {
properties.getImageFilter() != nullptr || properties.getStretchEffect().requiresLayer()) {
paint->setAlpha(properties.alpha() * alphaMultiplier);
paint->setBlendMode(properties.xferMode());
paint->setColorFilter(sk_ref_sp(properties.getColorFilter()));