-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skottie] Initial Fill layer effect support
Overwrite the layer content color with a color filter. TBR= Change-Id: I39f920225affb2641cc11ab1f0c1456d89b47cb7 Reviewed-on: https://skia-review.googlesource.com/145730 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
- Loading branch information
Showing
4 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
#ifndef SkSGColorFilter_DEFINED | ||
#define SkSGColorFilter_DEFINED | ||
|
||
#include "SkSGEffectNode.h" | ||
|
||
#include "SkBlendMode.h" | ||
|
||
class SkColorFilter; | ||
|
||
namespace sksg { | ||
|
||
class Color; | ||
|
||
/** | ||
* Base class for nodes which apply a color filter when rendering their descendants. | ||
* | ||
*/ | ||
class ColorFilter : public EffectNode { | ||
protected: | ||
explicit ColorFilter(sk_sp<RenderNode>); | ||
|
||
void onRender(SkCanvas*) const final; | ||
|
||
sk_sp<SkColorFilter> fColorFilter; | ||
|
||
private: | ||
typedef EffectNode INHERITED; | ||
}; | ||
|
||
/** | ||
* Concrete SkModeColorFilter Effect node. | ||
* | ||
*/ | ||
class ColorModeFilter final : public ColorFilter { | ||
public: | ||
~ColorModeFilter() override; | ||
|
||
static sk_sp<ColorModeFilter> Make(sk_sp<RenderNode> child, sk_sp<Color> color, | ||
SkBlendMode mode) { | ||
return (child && color) | ||
? sk_sp<ColorModeFilter>(new ColorModeFilter(std::move(child), std::move(color), mode)) | ||
: nullptr; | ||
} | ||
|
||
SG_ATTRIBUTE(Mode , SkBlendMode, fMode ) | ||
|
||
protected: | ||
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; | ||
|
||
private: | ||
ColorModeFilter(sk_sp<RenderNode>, sk_sp<Color>, SkBlendMode); | ||
|
||
sk_sp<Color> fColor; | ||
SkBlendMode fMode; | ||
|
||
typedef ColorFilter INHERITED; | ||
}; | ||
|
||
} // namespace sksg | ||
|
||
#endif // SkSGColorFilter_DEFINED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
#include "SkSGColorFilter.h" | ||
|
||
#include "SkCanvas.h" | ||
#include "SkColorFilter.h" | ||
#include "SkSGColor.h" | ||
|
||
namespace sksg { | ||
|
||
ColorFilter::ColorFilter(sk_sp<RenderNode> child) | ||
: INHERITED(std::move(child)) {} | ||
|
||
void ColorFilter::onRender(SkCanvas* canvas) const { | ||
if (this->bounds().isEmpty()) | ||
return; | ||
|
||
SkAutoCanvasRestore acr(canvas, false); | ||
|
||
if (fColorFilter) { | ||
SkPaint p; | ||
p.setColorFilter(fColorFilter); | ||
canvas->saveLayer(this->bounds(), &p); | ||
} | ||
|
||
this->INHERITED::onRender(canvas); | ||
} | ||
|
||
ColorModeFilter::ColorModeFilter(sk_sp<RenderNode> child, sk_sp<Color> color, SkBlendMode mode) | ||
: INHERITED(std::move(child)) | ||
, fColor(std::move(color)) | ||
, fMode(mode) { | ||
this->observeInval(fColor); | ||
} | ||
|
||
ColorModeFilter::~ColorModeFilter() { | ||
this->unobserveInval(fColor); | ||
} | ||
|
||
SkRect ColorModeFilter::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { | ||
SkASSERT(this->hasInval()); | ||
|
||
fColor->revalidate(ic, ctm); | ||
fColorFilter = SkColorFilter::MakeModeFilter(fColor->getColor(), fMode); | ||
|
||
return this->INHERITED::onRevalidate(ic, ctm); | ||
} | ||
|
||
} // namespace sksg |