Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: src/core/SkColorFilter.cpp

Issue 972153010: add impl limit for number of leaf-nodes in composecolorfilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: simplify using base-1 Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkColorFilter.cpp
diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp
index fd76dd1c9be033912a2cae899079fff73ccc2f7b..0a9cd93e34edb34203801d69465dfc82042028ac 100644
--- a/src/core/SkColorFilter.cpp
+++ b/src/core/SkColorFilter.cpp
@@ -39,13 +39,18 @@ SkColor SkColorFilter::filterColor(SkColor c) const {
///////////////////////////////////////////////////////////////////////////////////////////////////
+/*
+ * Since colorfilters may be used on the GPU backend, and in that case we may string together
+ * many GrFragmentProcessors, we might exceed some internal instruction/resource limit.
+ *
+ * Since we don't yet know *what* those limits might be when we construct the final shader,
+ * we just set an arbitrary limit during construction. If later we find smarter ways to know what
+ * the limnits are, we can change this constant (or remove it).
+ */
+#define SK_MAX_COMPOSE_COLORFILTER_COUNT 4
+
class SkComposeColorFilter : public SkColorFilter {
public:
- SkComposeColorFilter(SkColorFilter* outer, SkColorFilter* inner)
- : fOuter(SkRef(outer))
- , fInner(SkRef(inner))
- {}
-
uint32_t getFlags() const SK_OVERRIDE {
// Can only claim alphaunchanged and 16bit support if both our proxys do.
return fOuter->getFlags() & fInner->getFlags();
@@ -89,8 +94,22 @@ protected:
}
private:
+ SkComposeColorFilter(SkColorFilter* outer, SkColorFilter* inner, int composedFilterCount)
+ : fOuter(SkRef(outer))
+ , fInner(SkRef(inner))
+ , fComposedFilterCount(composedFilterCount)
+ {
+ SkASSERT(composedFilterCount >= 2);
+ SkASSERT(composedFilterCount <= SK_MAX_COMPOSE_COLORFILTER_COUNT);
+ }
+
+ int privateComposedFilterCount() const SK_OVERRIDE {
+ return fComposedFilterCount;
+ }
+
SkAutoTUnref<SkColorFilter> fOuter;
SkAutoTUnref<SkColorFilter> fInner;
+ const int fComposedFilterCount;
friend class SkColorFilter;
@@ -115,10 +134,15 @@ SkColorFilter* SkColorFilter::CreateComposeFilter(SkColorFilter* outer, SkColorF
// Give the subclass a shot at a more optimal composition...
SkColorFilter* composition = outer->newComposed(inner);
- if (NULL == composition) {
- composition = SkNEW_ARGS(SkComposeColorFilter, (outer, inner));
+ if (composition) {
+ return composition;
+ }
+
+ int count = inner->privateComposedFilterCount() + outer->privateComposedFilterCount();
+ if (count > SK_MAX_COMPOSE_COLORFILTER_COUNT) {
+ return NULL;
}
- return composition;
+ return SkNEW_ARGS(SkComposeColorFilter, (outer, inner, count));
}
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter)

Powered by Google App Engine
This is Rietveld 408576698