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

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

Issue 155513012: [WIP] Add Context to SkDrawLooper. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make SkSmallAllocator private again. Created 6 years, 9 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 | « no previous file | include/effects/SkBlurDrawLooper.h » ('j') | src/core/SkSmallAllocator.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 The Android Open Source Project 3 * Copyright 2011 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkDrawLooper_DEFINED 10 #ifndef SkDrawLooper_DEFINED
(...skipping 12 matching lines...) Expand all
23 be called, allowing it to modify the canvas and/or paint for that draw call. 23 be called, allowing it to modify the canvas and/or paint for that draw call.
24 More than that, via the next() method, the looper can modify the draw to be 24 More than that, via the next() method, the looper can modify the draw to be
25 invoked multiple times (hence the name loop-er), allow it to perform effects 25 invoked multiple times (hence the name loop-er), allow it to perform effects
26 like shadows or frame/fills, that require more than one pass. 26 like shadows or frame/fills, that require more than one pass.
27 */ 27 */
28 class SK_API SkDrawLooper : public SkFlattenable { 28 class SK_API SkDrawLooper : public SkFlattenable {
29 public: 29 public:
30 SK_DECLARE_INST_COUNT(SkDrawLooper) 30 SK_DECLARE_INST_COUNT(SkDrawLooper)
31 31
32 /** 32 /**
33 * Called right before something is being drawn. This will be followed by 33 * Holds state during a draw. Users call next() until it returns false.
34 * calls to next() until next() returns false. 34 * When the context is no longer needed, call cleanup() to ensure memory
scroggo 2014/03/11 14:08:05 No need for comment about cleanup()
Dominik Grewe 2014/03/11 18:28:17 Done.
35 * is released correctly.
36 *
37 * Subclasses of SkDrawLooper should create a subclass of this object to
38 * hold state specific to their subclass.
35 */ 39 */
36 virtual void init(SkCanvas*) = 0; 40 class SK_API Context : public SkNoncopyable {
41 public:
42 Context() {}
43 virtual ~Context() {}
44
45 /**
46 * Called in a loop (after init()). Each time true is returned, the
47 * object is drawn (possibly with a modified canvas and/or paint). When
48 * false is finally returned, drawing for the object stops.
49 *
50 * On each call, the paint will be in its original state, but the
51 * canvas will be as it was following the previous call to next() or
52 * init().
53 *
54 * The implementation must ensure that, when next() finally returns
55 * false, that the canvas has been restored to the state it was
56 * initially, before init() was first called.
57 */
58 virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0;
59 };
37 60
38 /** 61 /**
39 * Called in a loop (after init()). Each time true is returned, the object 62 * Called right before something is being drawn. Returns a Context
40 * is drawn (possibly with a modified canvas and/or paint). When false is 63 * whose next() method should be called until it returns false.
41 * finally returned, drawing for the object stops. 64 * The caller has to ensure that the storage pointer provides enough
42 * 65 * memory for the Context. The required size can be queried by calling
43 * On each call, the paint will be in its original state, but the canvas 66 * contextSize(). It is also the caller's responsibility to destroy the
44 * will be as it was following the previous call to next() or init(). 67 * object after use.
45 *
46 * The implementation must ensure that, when next() finally returns false,
47 * that the canvas has been restored to the state it was initially, before
48 * init() was first called.
49 */ 68 */
50 virtual bool next(SkCanvas*, SkPaint* paint) = 0; 69 virtual Context* init(SkCanvas*, void* storage) const = 0;
reed1 2014/03/11 14:23:31 Rename to something that reflects its "factory" na
scroggo 2014/03/11 15:51:02 Personally I like not having the size there. Passi
Dominik Grewe 2014/03/11 18:28:17 Done.
70
71 /**
72 * Returns the number of bytes needed to store a Context object.
scroggo 2014/03/11 14:08:05 I think it might be clearer to state that this is
Dominik Grewe 2014/03/11 18:28:17 Done.
73 */
74 virtual size_t contextSize() const = 0;
75
51 76
52 /** 77 /**
53 * The fast bounds functions are used to enable the paint to be culled early 78 * The fast bounds functions are used to enable the paint to be culled early
54 * in the drawing pipeline. If a subclass can support this feature it must 79 * in the drawing pipeline. If a subclass can support this feature it must
55 * return true for the canComputeFastBounds() function. If that function 80 * return true for the canComputeFastBounds() function. If that function
56 * returns false then computeFastBounds behavior is undefined otherwise it 81 * returns false then computeFastBounds behavior is undefined otherwise it
57 * is expected to have the following behavior. Given the parent paint and 82 * is expected to have the following behavior. Given the parent paint and
58 * the parent's bounding rect the subclass must fill in and return the 83 * the parent's bounding rect the subclass must fill in and return the
59 * storage rect, where the storage rect is with the union of the src rect 84 * storage rect, where the storage rect is with the union of the src rect
60 * and the looper's bounding rect. 85 * and the looper's bounding rect.
61 */ 86 */
62 virtual bool canComputeFastBounds(const SkPaint& paint); 87 virtual bool canComputeFastBounds(const SkPaint& paint);
reed1 2014/03/11 14:23:31 What is the plan for these? Will they become const
Dominik Grewe 2014/03/11 18:28:17 Good point. Yes, they can now be const.
63 virtual void computeFastBounds(const SkPaint& paint, 88 virtual void computeFastBounds(const SkPaint& paint,
64 const SkRect& src, SkRect* dst); 89 const SkRect& src, SkRect* dst);
65 90
66 SkDEVCODE(virtual void toString(SkString* str) const = 0;) 91 SkDEVCODE(virtual void toString(SkString* str) const = 0;)
67 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) 92 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper)
68 93
69 protected: 94 protected:
70 SkDrawLooper() {} 95 SkDrawLooper() {}
71 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} 96 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {}
72 97
73 private: 98 private:
74 typedef SkFlattenable INHERITED; 99 typedef SkFlattenable INHERITED;
75 }; 100 };
76 101
77 #endif 102 #endif
OLDNEW
« no previous file with comments | « no previous file | include/effects/SkBlurDrawLooper.h » ('j') | src/core/SkSmallAllocator.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698