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

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

Issue 414483003: Implement a persistent uniqueID-based cache for SkImageFilter. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix cross-process issue (revert those changes to HEAD^^) 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
« no previous file with comments | « include/core/SkDevice.h ('k') | include/core/SkPicture.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // By default, we cache only image filters with 2 or more children. 54 // By default, we cache only image filters with 2 or more children.
55 // Values less than 2 mean always cache; values greater than 2 are not s upported. 55 // Values less than 2 mean always cache; values greater than 2 are not s upported.
56 static Cache* Create(int minChildren = 2); 56 static Cache* Create(int minChildren = 2);
57 virtual ~Cache() {} 57 virtual ~Cache() {}
58 virtual bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* o ffset) = 0; 58 virtual bool get(const SkImageFilter* key, SkBitmap* result, SkIPoint* o ffset) = 0;
59 virtual void set(const SkImageFilter* key, 59 virtual void set(const SkImageFilter* key,
60 const SkBitmap& result, const SkIPoint& offset) = 0; 60 const SkBitmap& result, const SkIPoint& offset) = 0;
61 virtual void remove(const SkImageFilter* key) = 0; 61 virtual void remove(const SkImageFilter* key) = 0;
62 }; 62 };
63 63
64 // This cache maps from (filter's unique ID + CTM + clipBounds + src bitmap generation ID) to
65 // (result, offset).
66 class UniqueIDCache : public SkRefCnt {
67 public:
68 struct Key;
69 virtual ~UniqueIDCache() {}
70 static UniqueIDCache* Create(size_t maxBytes);
71 static UniqueIDCache* Get();
72 virtual bool get(const Key& key, SkBitmap* result, SkIPoint* offset) con st = 0;
73 virtual void set(const Key& key, const SkBitmap& result, const SkIPoint& offset) = 0;
74 };
75
64 class Context { 76 class Context {
65 public: 77 public:
66 Context(const SkMatrix& ctm, const SkIRect& clipBounds, Cache* cache) : 78 Context(const SkMatrix& ctm, const SkIRect& clipBounds, UniqueIDCache* c ache) :
67 fCTM(ctm), fClipBounds(clipBounds), fCache(cache) { 79 fCTM(ctm), fClipBounds(clipBounds), fCache(cache) {
68 } 80 }
69 const SkMatrix& ctm() const { return fCTM; } 81 const SkMatrix& ctm() const { return fCTM; }
70 const SkIRect& clipBounds() const { return fClipBounds; } 82 const SkIRect& clipBounds() const { return fClipBounds; }
71 Cache* cache() const { return fCache; } 83 UniqueIDCache* cache() const { return fCache; }
72 private: 84 private:
73 SkMatrix fCTM; 85 SkMatrix fCTM;
74 SkIRect fClipBounds; 86 SkIRect fClipBounds;
75 Cache* fCache; 87 UniqueIDCache* fCache;
76 }; 88 };
77 89
78 class Proxy { 90 class Proxy {
79 public: 91 public:
80 virtual ~Proxy() {}; 92 virtual ~Proxy() {};
81 93
82 virtual SkBaseDevice* createDevice(int width, int height) = 0; 94 virtual SkBaseDevice* createDevice(int width, int height) = 0;
83 // returns true if the proxy can handle this filter natively 95 // returns true if the proxy can handle this filter natively
84 virtual bool canHandleImageFilter(const SkImageFilter*) = 0; 96 virtual bool canHandleImageFilter(const SkImageFilter*) = 0;
85 // returns true if the proxy handled the filter itself. if this returns 97 // returns true if the proxy handled the filter itself. if this returns
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 class Common { 215 class Common {
204 public: 216 public:
205 Common() {} 217 Common() {}
206 ~Common(); 218 ~Common();
207 219
208 bool unflatten(SkReadBuffer&, int expectedInputs = -1); 220 bool unflatten(SkReadBuffer&, int expectedInputs = -1);
209 221
210 CropRect cropRect() const { return fCropRect; } 222 CropRect cropRect() const { return fCropRect; }
211 int inputCount() const { return fInputs.count(); } 223 int inputCount() const { return fInputs.count(); }
212 SkImageFilter** inputs() const { return fInputs.get(); } 224 SkImageFilter** inputs() const { return fInputs.get(); }
225 uint32_t uniqueID() const { return fUniqueID; }
213 226
214 // If the caller wants a copy of the inputs, call this and it will trans fer ownership 227 // If the caller wants a copy of the inputs, call this and it will trans fer ownership
215 // of the unflattened input filters to the caller. This is just a short- cut for copying 228 // of the unflattened input filters to the caller. This is just a short- cut for copying
216 // the inputs, calling ref() on each, and then waiting for Common's dest ructor to call 229 // the inputs, calling ref() on each, and then waiting for Common's dest ructor to call
217 // unref() on each. 230 // unref() on each.
218 void detachInputs(SkImageFilter** inputs); 231 void detachInputs(SkImageFilter** inputs);
219 232
220 private: 233 private:
221 CropRect fCropRect; 234 CropRect fCropRect;
222 // most filters accept at most 2 input-filters 235 // most filters accept at most 2 input-filters
223 SkAutoSTArray<2, SkImageFilter*> fInputs; 236 SkAutoSTArray<2, SkImageFilter*> fInputs;
237 uint32_t fUniqueID;
224 238
225 void allocInputs(int count); 239 void allocInputs(int count);
226 }; 240 };
227 241
228 SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRe ct = NULL); 242 SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRe ct = NULL);
229 243
230 virtual ~SkImageFilter(); 244 virtual ~SkImageFilter();
231 245
232 /** 246 /**
233 * Constructs a new SkImageFilter read from an SkReadBuffer object. 247 * Constructs a new SkImageFilter read from an SkReadBuffer object.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 * parameters before they are used in the effect. Note that this function 315 * parameters before they are used in the effect. Note that this function
302 * will be called with (NULL, NULL, SkMatrix::I()) to query for support, 316 * will be called with (NULL, NULL, SkMatrix::I()) to query for support,
303 * so returning "true" indicates support for all possible matrices. 317 * so returning "true" indicates support for all possible matrices.
304 */ 318 */
305 virtual bool asNewEffect(GrEffect** effect, 319 virtual bool asNewEffect(GrEffect** effect,
306 GrTexture*, 320 GrTexture*,
307 const SkMatrix& matrix, 321 const SkMatrix& matrix,
308 const SkIRect& bounds) const; 322 const SkIRect& bounds) const;
309 323
310 private: 324 private:
325 bool usesSrcInput() const { return fUsesSrcInput; }
326
311 typedef SkFlattenable INHERITED; 327 typedef SkFlattenable INHERITED;
312 int fInputCount; 328 int fInputCount;
313 SkImageFilter** fInputs; 329 SkImageFilter** fInputs;
330 bool fUsesSrcInput;
314 CropRect fCropRect; 331 CropRect fCropRect;
332 uint32_t fUniqueID; // Globally unique
315 }; 333 };
316 334
317 #endif 335 #endif
OLDNEW
« no previous file with comments | « include/core/SkDevice.h ('k') | include/core/SkPicture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698