Revert of [SVGDom] Opacity optimization (patchset #4 id:60001 of https://codereview.chromium.org/2353503005/ )

Reason for revert:
Failing assertion

Original issue's description:
> [SVGDom] Opacity optimization
>
> Apply opacity as fill/stroke paint alpha instead of saveLayer, when
> possible.
>
> R=robertphillips@google.com,stephana@google.com,reed@google.com
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2353503005
>
> Committed: https://skia.googlesource.com/skia/+/3dbb7b9f196d793fbd16243157ee67638891f5dc

TBR=reed@google.com,robertphillips@google.com,stephana@google.com,fmalita@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review-Url: https://codereview.chromium.org/2359603002
This commit is contained in:
borenet 2016-09-20 13:39:46 -07:00 committed by Commit bot
parent a627b5c3b9
commit a5344ee50a
6 changed files with 6 additions and 47 deletions

View File

@ -14,10 +14,6 @@ void SkSVGContainer::appendChild(sk_sp<SkSVGNode> node) {
fChildren.push_back(std::move(node));
}
bool SkSVGContainer::hasChildren() const {
return !fChildren.empty();
}
void SkSVGContainer::onRender(const SkSVGRenderContext& ctx) const {
for (int i = 0; i < fChildren.count(); ++i) {
fChildren[i]->render(ctx);

View File

@ -22,8 +22,6 @@ protected:
void onRender(const SkSVGRenderContext&) const override;
bool hasChildren() const final;
// TODO: add some sort of child iterator, and hide the container.
SkSTArray<1, sk_sp<SkSVGNode>, true> fChildren;

View File

@ -31,8 +31,7 @@ bool SkSVGNode::asPaint(const SkSVGRenderContext& ctx, SkPaint* paint) const {
}
bool SkSVGNode::onPrepareToRender(SkSVGRenderContext* ctx) const {
ctx->applyPresentationAttributes(fPresentationAttributes,
this->hasChildren() ? 0 : SkSVGRenderContext::kLeaf);
ctx->applyPresentationAttributes(fPresentationAttributes);
return true;
}

View File

@ -69,8 +69,6 @@ protected:
virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
virtual bool hasChildren() const { return false; }
private:
SkSVGTag fTag;

View File

@ -239,8 +239,7 @@ const SkSVGNode* SkSVGRenderContext::findNodeById(const SkString& id) const {
return v ? v->get() : nullptr;
}
void SkSVGRenderContext::applyPresentationAttributes(const SkSVGPresentationAttributes& attrs,
uint32_t flags) {
void SkSVGRenderContext::applyPresentationAttributes(const SkSVGPresentationAttributes& attrs) {
#define ApplyLazyInheritedAttribute(ATTR) \
do { \
@ -268,36 +267,10 @@ void SkSVGRenderContext::applyPresentationAttributes(const SkSVGPresentationAttr
// Uninherited attributes. Only apply to the current context.
if (auto* opacity = attrs.fOpacity.getMaybeNull()) {
this->applyOpacity(opacity->value(), flags);
}
}
void SkSVGRenderContext::applyOpacity(SkScalar opacity, uint32_t flags) {
if (opacity >= 1) {
return;
}
const bool hasFill = SkToBool(this->fillPaint());
const bool hasStroke = SkToBool(this->strokePaint());
// We can apply the opacity as paint alpha iif it only affects one atomic draw.
// For now, this means a) the target node doesn't have any descendants, and
// b) it only has a stroke or a fill (but not both). Going forward, we may need
// to refine this heuristic (e.g. to accommodate markers).
if ((flags & kLeaf) && (hasFill ^ hasStroke)) {
auto* pctx = fPresentationContext.writable();
if (hasFill) {
pctx->fFillPaint.setAlpha(
SkScalarRoundToInt(opacity * pctx->fFillPaint.getAlpha()));
} else {
pctx->fStrokePaint.setAlpha(
SkScalarRoundToInt(opacity * pctx->fStrokePaint.getAlpha()));
}
} else {
// Expensive, layer-based fall back.
auto* opacity = attrs.fOpacity.getMaybeNull();
if (opacity && opacity->value() < 1) {
SkPaint opacityPaint;
opacityPaint.setAlpha(opacity_to_alpha(opacity));
opacityPaint.setAlpha(opacity_to_alpha(opacity->value()));
// Balanced in the destructor, via restoreToCount().
fCanvas->saveLayer(nullptr, &opacityPaint);
}

View File

@ -67,10 +67,7 @@ public:
SkCanvas* canvas() const { return fCanvas; }
enum ApplyFlags {
kLeaf = 1 << 0, // the target node doesn't have descendants
};
void applyPresentationAttributes(const SkSVGPresentationAttributes&, uint32_t flags);
void applyPresentationAttributes(const SkSVGPresentationAttributes&);
const SkSVGNode* findNodeById(const SkString&) const;
@ -83,8 +80,6 @@ private:
void* operator new(size_t, void*) = delete;
SkSVGRenderContext& operator=(const SkSVGRenderContext&) = delete;
void applyOpacity(SkScalar opacity, uint32_t flags);
const SkSVGIDMapper& fIDMapper;
SkTCopyOnFirstWrite<SkSVGLengthContext> fLengthContext;
SkTCopyOnFirstWrite<SkSVGPresentationContext> fPresentationContext;