OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkColorFilter.h" | 8 #include "SkColorFilter.h" |
| 9 |
9 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| 11 #include "SkWriteBuffer.h" |
| 12 #include "SkShader.h" |
| 13 #include "SkUnPreMultiply.h" |
10 #include "SkString.h" | 14 #include "SkString.h" |
11 #include "SkWriteBuffer.h" | |
12 | 15 |
13 bool SkColorFilter::asColorMode(SkColor* color, SkXfermode::Mode* mode) const { | 16 bool SkColorFilter::asColorMode(SkColor* color, SkXfermode::Mode* mode) const { |
14 return false; | 17 return false; |
15 } | 18 } |
16 | 19 |
17 bool SkColorFilter::asColorMatrix(SkScalar matrix[20]) const { | 20 bool SkColorFilter::asColorMatrix(SkScalar matrix[20]) const { |
18 return false; | 21 return false; |
19 } | 22 } |
20 | 23 |
21 bool SkColorFilter::asComponentTable(SkBitmap*) const { | 24 bool SkColorFilter::asComponentTable(SkBitmap*) const { |
(...skipping 11 matching lines...) Expand all Loading... |
33 | 36 |
34 SkColor SkColorFilter::filterColor(SkColor c) const { | 37 SkColor SkColorFilter::filterColor(SkColor c) const { |
35 SkPMColor dst, src = SkPreMultiplyColor(c); | 38 SkPMColor dst, src = SkPreMultiplyColor(c); |
36 this->filterSpan(&src, 1, &dst); | 39 this->filterSpan(&src, 1, &dst); |
37 return SkUnPreMultiply::PMColorToColor(dst); | 40 return SkUnPreMultiply::PMColorToColor(dst); |
38 } | 41 } |
39 | 42 |
40 GrFragmentProcessor* SkColorFilter::asFragmentProcessor(GrContext*) const { | 43 GrFragmentProcessor* SkColorFilter::asFragmentProcessor(GrContext*) const { |
41 return NULL; | 44 return NULL; |
42 } | 45 } |
43 | |
44 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | |
45 | |
46 class SkComposeColorFilter : public SkColorFilter { | |
47 public: | |
48 SkComposeColorFilter(SkColorFilter* outer, SkColorFilter* inner) | |
49 : fOuter(SkRef(outer)) | |
50 , fInner(SkRef(inner)) | |
51 {} | |
52 | |
53 uint32_t getFlags() const SK_OVERRIDE { | |
54 // Can only claim alphaunchanged and 16bit support if both our proxys do
. | |
55 return fOuter->getFlags() & fInner->getFlags(); | |
56 } | |
57 | |
58 void filterSpan(const SkPMColor shader[], int count, SkPMColor result[]) con
st SK_OVERRIDE { | |
59 fInner->filterSpan(shader, count, result); | |
60 fOuter->filterSpan(result, count, result); | |
61 } | |
62 | |
63 void filterSpan16(const uint16_t shader[], int count, uint16_t result[]) con
st SK_OVERRIDE { | |
64 SkASSERT(this->getFlags() & kHasFilter16_Flag); | |
65 fInner->filterSpan16(shader, count, result); | |
66 fOuter->filterSpan16(result, count, result); | |
67 } | |
68 | |
69 #ifndef SK_IGNORE_TO_STRING | |
70 void toString(SkString* str) const SK_OVERRIDE { | |
71 SkString outerS, innerS; | |
72 fOuter->toString(&outerS); | |
73 fInner->toString(&innerS); | |
74 str->appendf("SkComposeColorFilter: outer(%s) inner(%s)", outerS.c_str()
, innerS.c_str()); | |
75 } | |
76 #endif | |
77 | |
78 #if 0 // TODO: should we support composing the fragments? | |
79 #if SK_SUPPORT_GPU | |
80 GrFragmentProcessor* asFragmentProcessor(GrContext*) const SK_OVERRIDE; | |
81 #endif | |
82 #endif | |
83 | |
84 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposeColorFilter) | |
85 | |
86 protected: | |
87 void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE { | |
88 buffer.writeFlattenable(fOuter); | |
89 buffer.writeFlattenable(fInner); | |
90 } | |
91 | |
92 private: | |
93 SkAutoTUnref<SkColorFilter> fOuter; | |
94 SkAutoTUnref<SkColorFilter> fInner; | |
95 | |
96 typedef SkColorFilter INHERITED; | |
97 }; | |
98 | |
99 SkFlattenable* SkComposeColorFilter::CreateProc(SkReadBuffer& buffer) { | |
100 SkAutoTUnref<SkColorFilter> outer(buffer.readColorFilter()); | |
101 SkAutoTUnref<SkColorFilter> inner(buffer.readColorFilter()); | |
102 return CreateComposeFilter(outer, inner); | |
103 } | |
104 | |
105 SkColorFilter* SkColorFilter::CreateComposeFilter(SkColorFilter* outer, SkColorF
ilter* inner) { | |
106 if (!outer) { | |
107 return SkSafeRef(inner); | |
108 } | |
109 if (!inner) { | |
110 return SkSafeRef(outer); | |
111 } | |
112 return SkNEW_ARGS(SkComposeColorFilter, (outer, inner)); | |
113 } | |
114 | |
115 | |
OLD | NEW |