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

Side by Side Diff: include/core/SkImageFilter.h

Issue 395603002: Simplify flattening to just write enough to call the factory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use friend class instead of function to better hide how we initialize Created 6 years, 4 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 unified diff | Download patch
OLDNEW
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
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);
Stephen White 2014/08/20 21:23:15 Unrelated to this CL, but we should probably remov
reed1 2014/08/20 22:04:15 Acknowledged.
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]; }
Stephen White 2014/08/20 21:23:15 This should be named getInput() to match SkImageFi
reed1 2014/08/20 22:04:15 Done.
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
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 #define SK_IMAGEFILTER_UNFLATTEN_COMMON(localVar, expectedCount) \
337 Common localVar; \
338 do { \
339 if (!localVar.unflatten(buffer, expectedCount)) { \
340 return NULL; \
341 } \
342 } while (0)
343
323 #endif 344 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698