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

Unified Diff: src/core/SkColorFilter.cpp

Issue 970753002: add compose-colorfilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« no previous file with comments | « include/effects/SkModeColorFilter.h ('k') | src/effects/SkColorFilters.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColorFilter.cpp
diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp
index aadb29cb2df1af9af60d0c909c2d2fd7e33d0af1..d49fc52fa1b68aea0a15b116dc08bb3c1c80daf8 100644
--- a/src/core/SkColorFilter.cpp
+++ b/src/core/SkColorFilter.cpp
@@ -6,12 +6,9 @@
*/
#include "SkColorFilter.h"
-
#include "SkReadBuffer.h"
-#include "SkWriteBuffer.h"
-#include "SkShader.h"
-#include "SkUnPreMultiply.h"
#include "SkString.h"
+#include "SkWriteBuffer.h"
bool SkColorFilter::asColorMode(SkColor* color, SkXfermode::Mode* mode) const {
return false;
@@ -43,3 +40,81 @@ SkColor SkColorFilter::filterColor(SkColor c) const {
GrFragmentProcessor* SkColorFilter::asFragmentProcessor(GrContext*) const {
return NULL;
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+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();
+ }
+
+ void filterSpan(const SkPMColor shader[], int count, SkPMColor result[]) const SK_OVERRIDE {
+ fInner->filterSpan(shader, count, result);
+ fOuter->filterSpan(result, count, result);
+ }
+
+ void filterSpan16(const uint16_t shader[], int count, uint16_t result[]) const SK_OVERRIDE {
+ SkASSERT(this->getFlags() & kHasFilter16_Flag);
+ fInner->filterSpan16(shader, count, result);
+ fOuter->filterSpan16(result, count, result);
+ }
+
+#ifndef SK_IGNORE_TO_STRING
+ void toString(SkString* str) const SK_OVERRIDE {
+ SkString outerS, innerS;
+ fOuter->toString(&outerS);
+ fInner->toString(&innerS);
+ str->appendf("SkComposeColorFilter: outer(%s) inner(%s)", outerS.c_str(), innerS.c_str());
+ }
+#endif
+
+#if 0 // TODO: should we support composing the fragments?
+#if SK_SUPPORT_GPU
+ GrFragmentProcessor* asFragmentProcessor(GrContext*) const SK_OVERRIDE;
+#endif
+#endif
+
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeColorFilter)
+
+protected:
+ void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE {
+ buffer.writeFlattenable(fOuter);
+ buffer.writeFlattenable(fInner);
+ }
+
+private:
+ SkAutoTUnref<SkColorFilter> fOuter;
+ SkAutoTUnref<SkColorFilter> fInner;
+
+ friend class SkColorFilter;
+
+ typedef SkColorFilter INHERITED;
+};
+
+SkFlattenable* SkComposeColorFilter::CreateProc(SkReadBuffer& buffer) {
+ SkAutoTUnref<SkColorFilter> outer(buffer.readColorFilter());
+ SkAutoTUnref<SkColorFilter> inner(buffer.readColorFilter());
+ return CreateComposeFilter(outer, inner);
+}
+
+SkColorFilter* SkColorFilter::CreateComposeFilter(SkColorFilter* outer, SkColorFilter* inner) {
+ if (!outer) {
+ return SkSafeRef(inner);
+ }
+ if (!inner) {
+ return SkSafeRef(outer);
+ }
+ return SkNEW_ARGS(SkComposeColorFilter, (outer, inner));
+}
+
+SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter)
+SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkComposeColorFilter)
+SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
+
« no previous file with comments | « include/effects/SkModeColorFilter.h ('k') | src/effects/SkColorFilters.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698