Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 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 SkImageFilter_DEFINED | 8 #ifndef SkImageFilter_DEFINED |
| 9 #define SkImageFilter_DEFINED | 9 #define SkImageFilter_DEFINED |
| 10 | 10 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 static Cache* GetExternalCache(); | 198 static Cache* GetExternalCache(); |
| 199 | 199 |
| 200 SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter) | 200 SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter) |
| 201 | 201 |
| 202 protected: | 202 protected: |
| 203 class Common { | 203 class Common { |
| 204 public: | 204 public: |
| 205 Common() {} | 205 Common() {} |
| 206 ~Common(); | 206 ~Common(); |
| 207 | 207 |
| 208 /** | |
| 209 * Attempt to unflatten the cropRect and the expected number of input f ilters. | |
| 210 * If any number of input filters is valid, pass -1. | |
| 211 * If this fails (i.e. corrupt buffer or contents) then return false an d common will | |
| 212 * be left uninitialized. | |
| 213 * If this returns true, then inputCount() is the number of found input filters, each | |
| 214 * of which may be NULL or a valid imagefilter. | |
| 215 */ | |
| 208 bool unflatten(SkReadBuffer&, int expectedInputs = -1); | 216 bool unflatten(SkReadBuffer&, int expectedInputs = -1); |
| 209 | 217 |
| 210 CropRect cropRect() const { return fCropRect; } | 218 const CropRect& cropRect() const { return fCropRect; } |
| 211 int inputCount() const { return fInputs.count(); } | 219 int inputCount() const { return fInputs.count(); } |
| 212 SkImageFilter** inputs() const { return fInputs.get(); } | 220 SkImageFilter** inputs() const { return fInputs.get(); } |
| 213 uint32_t uniqueID() const { return fUniqueID; } | 221 uint32_t uniqueID() const { return fUniqueID; } |
| 214 | 222 |
| 223 SkImageFilter* inputAt(int index) const { return fInputs[index]; } | |
| 224 | |
| 215 // If the caller wants a copy of the inputs, call this and it will trans fer ownership | 225 // If the caller wants a copy of the inputs, call this and it will trans fer ownership |
| 216 // of the unflattened input filters to the caller. This is just a short- cut for copying | 226 // of the unflattened input filters to the caller. This is just a short- cut for copying |
| 217 // the inputs, calling ref() on each, and then waiting for Common's dest ructor to call | 227 // the inputs, calling ref() on each, and then waiting for Common's dest ructor to call |
| 218 // unref() on each. | 228 // unref() on each. |
| 219 void detachInputs(SkImageFilter** inputs); | 229 void detachInputs(SkImageFilter** inputs); |
| 220 | 230 |
| 221 private: | 231 private: |
| 222 CropRect fCropRect; | 232 CropRect fCropRect; |
| 223 // most filters accept at most 2 input-filters | 233 // most filters accept at most 2 input-filters |
| 224 SkAutoSTArray<2, SkImageFilter*> fInputs; | 234 SkAutoSTArray<2, SkImageFilter*> fInputs; |
| 225 uint32_t fUniqueID; | 235 uint32_t fUniqueID; |
| 226 | 236 |
| 227 void allocInputs(int count); | 237 void allocInputs(int count); |
| 228 }; | 238 }; |
| 229 | 239 |
| 230 SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRe ct = NULL); | 240 SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRe ct = NULL); |
| 231 | 241 |
| 232 virtual ~SkImageFilter(); | 242 virtual ~SkImageFilter(); |
| 233 | 243 |
| 234 /** | 244 /** |
| 235 * Constructs a new SkImageFilter read from an SkReadBuffer object. | 245 * Constructs a new SkImageFilter read from an SkReadBuffer object. |
| 236 * | 246 * |
| 237 * @param inputCount The exact number of inputs expected for this SkImag eFilter object. | 247 * @param inputCount The exact number of inputs expected for this SkImag eFilter object. |
| 238 * -1 can be used if the filter accepts any number of inputs. | 248 * -1 can be used if the filter accepts any number of inputs. |
| 239 * @param rb SkReadBuffer object from which the SkImageFilter is read. | 249 * @param rb SkReadBuffer object from which the SkImageFilter is read. |
| 240 */ | 250 */ |
| 241 explicit SkImageFilter(int inputCount, SkReadBuffer& rb); | 251 explicit SkImageFilter(int inputCount, SkReadBuffer& rb); |
| 242 | 252 |
| 243 virtual void flatten(SkWriteBuffer& wb) const SK_OVERRIDE; | 253 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 244 | 254 |
| 245 /** | 255 /** |
| 246 * This is the virtual which should be overridden by the derived class | 256 * This is the virtual which should be overridden by the derived class |
| 247 * to perform image filtering. | 257 * to perform image filtering. |
| 248 * | 258 * |
| 249 * src is the original primitive bitmap. If the filter has a connected | 259 * src is the original primitive bitmap. If the filter has a connected |
| 250 * input, it should recurse on that input and use that in place of src. | 260 * input, it should recurse on that input and use that in place of src. |
| 251 * | 261 * |
| 252 * The matrix is the current matrix on the canvas. | 262 * The matrix is the current matrix on the canvas. |
| 253 * | 263 * |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 bool usesSrcInput() const { return fUsesSrcInput; } | 323 bool usesSrcInput() const { return fUsesSrcInput; } |
| 314 | 324 |
| 315 typedef SkFlattenable INHERITED; | 325 typedef SkFlattenable INHERITED; |
| 316 int fInputCount; | 326 int fInputCount; |
| 317 SkImageFilter** fInputs; | 327 SkImageFilter** fInputs; |
| 318 bool fUsesSrcInput; | 328 bool fUsesSrcInput; |
| 319 CropRect fCropRect; | 329 CropRect fCropRect; |
| 320 uint32_t fUniqueID; // Globally unique | 330 uint32_t fUniqueID; // Globally unique |
| 321 }; | 331 }; |
| 322 | 332 |
| 333 /** | |
| 334 * Helper to unflatten the common data, and return NULL if we fail. | |
| 335 * | |
| 336 * Declares a local variable 'common', and expects a SkReadBuffer named 'buffer ' | |
| 337 */ | |
| 338 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(expectedCount) \ | |
|
Stephen White
2014/08/18 18:17:26
This macro is too much magic, IMHO: putting a vari
reed1
2014/08/18 22:39:16
A downside of copy/pasting 4 lines everywhere is t
| |
| 339 Common common; \ | |
| 340 do { \ | |
| 341 if (!common.unflatten(buffer, expectedCount)) { \ | |
| 342 return NULL; \ | |
| 343 } \ | |
| 344 } while (0) | |
| 345 | |
| 323 #endif | 346 #endif |
| OLD | NEW |