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 #ifndef SkColorFilter_DEFINED | 8 #ifndef SkColorFilter_DEFINED |
9 #define SkColorFilter_DEFINED | 9 #define SkColorFilter_DEFINED |
10 | 10 |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkFlattenable.h" | 12 #include "SkFlattenable.h" |
| 13 #include "SkRefCnt.h" |
13 #include "SkXfermode.h" | 14 #include "SkXfermode.h" |
14 | 15 |
15 class GrContext; | 16 class GrContext; |
16 class GrFragmentProcessor; | 17 class GrFragmentProcessor; |
17 class SkBitmap; | 18 class SkBitmap; |
18 | 19 |
19 /** | 20 /** |
20 * ColorFilters are optional objects in the drawing pipeline. When present in | 21 * ColorFilters are optional objects in the drawing pipeline. When present in |
21 * a paint, they are called with the "src" colors, and return new colors, which | 22 * a paint, they are called with the "src" colors, and return new colors, which |
22 * are then passed onto the next stage (either ImageFilter or Xfermode). | 23 * are then passed onto the next stage (either ImageFilter or Xfermode). |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 return MakeComposeFilter(sk_ref_sp(outer), sk_ref_sp(inner)).release(); | 136 return MakeComposeFilter(sk_ref_sp(outer), sk_ref_sp(inner)).release(); |
136 } | 137 } |
137 static SkColorFilter* CreateMatrixFilterRowMajor255(const SkScalar array[20]
) { | 138 static SkColorFilter* CreateMatrixFilterRowMajor255(const SkScalar array[20]
) { |
138 return MakeMatrixFilterRowMajor255(array).release(); | 139 return MakeMatrixFilterRowMajor255(array).release(); |
139 } | 140 } |
140 virtual SkColorFilter* newComposed(const SkColorFilter* inner) const { | 141 virtual SkColorFilter* newComposed(const SkColorFilter* inner) const { |
141 return this->makeComposed(sk_ref_sp(const_cast<SkColorFilter*>(inner))).
release(); | 142 return this->makeComposed(sk_ref_sp(const_cast<SkColorFilter*>(inner))).
release(); |
142 } | 143 } |
143 #endif | 144 #endif |
144 | 145 |
| 146 #if SK_SUPPORT_GPU |
145 /** | 147 /** |
146 * A subclass may implement this factory function to work with the GPU back
end. It returns | 148 * A subclass may implement this factory function to work with the GPU back
end. It returns |
147 * a GrFragmentProcessor that implemets the color filter in GPU shader code
. | 149 * a GrFragmentProcessor that implemets the color filter in GPU shader code
. |
148 * | 150 * |
149 * The fragment processor receives a premultiplied input color and produces
a premultiplied | 151 * The fragment processor receives a premultiplied input color and produces
a premultiplied |
150 * output color. | 152 * output color. |
151 * | 153 * |
152 * A null return indicates that the color filter isn't implemented for the
GPU backend. | 154 * A null return indicates that the color filter isn't implemented for the
GPU backend. |
153 */ | 155 */ |
154 virtual const GrFragmentProcessor* asFragmentProcessor(GrContext*) const { | 156 virtual sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*) const; |
155 return nullptr; | 157 #endif |
156 } | |
157 | 158 |
158 bool affectsTransparentBlack() const { | 159 bool affectsTransparentBlack() const { |
159 return this->filterColor(0) != 0; | 160 return this->filterColor(0) != 0; |
160 } | 161 } |
161 | 162 |
162 SK_TO_STRING_PUREVIRT() | 163 SK_TO_STRING_PUREVIRT() |
163 | 164 |
164 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 165 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
165 SK_DEFINE_FLATTENABLE_TYPE(SkColorFilter) | 166 SK_DEFINE_FLATTENABLE_TYPE(SkColorFilter) |
166 | 167 |
167 protected: | 168 protected: |
168 SkColorFilter() {} | 169 SkColorFilter() {} |
169 | 170 |
170 private: | 171 private: |
171 /* | 172 /* |
172 * Returns 1 if this is a single filter (not a composition of other filters
), otherwise it | 173 * Returns 1 if this is a single filter (not a composition of other filters
), otherwise it |
173 * reutrns the number of leaf-node filters in a composition. This should be
the same value | 174 * reutrns the number of leaf-node filters in a composition. This should be
the same value |
174 * as the number of GrFragmentProcessors returned by asFragmentProcessors's
array parameter. | 175 * as the number of GrFragmentProcessors returned by asFragmentProcessors's
array parameter. |
175 * | 176 * |
176 * e.g. compose(filter, compose(compose(filter, filter), filter)) --> 4 | 177 * e.g. compose(filter, compose(compose(filter, filter), filter)) --> 4 |
177 */ | 178 */ |
178 virtual int privateComposedFilterCount() const { return 1; } | 179 virtual int privateComposedFilterCount() const { return 1; } |
179 friend class SkComposeColorFilter; | 180 friend class SkComposeColorFilter; |
180 | 181 |
181 typedef SkFlattenable INHERITED; | 182 typedef SkFlattenable INHERITED; |
182 }; | 183 }; |
183 | 184 |
184 #endif | 185 #endif |
OLD | NEW |