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

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: static allocation of DrawContext; update rest of code. Created 6 years, 10 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') | include/effects/SkLayerDrawLooper.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
11 #define SkDrawLooper_DEFINED 11 #define SkDrawLooper_DEFINED
12 12
13 #include "SkFlattenable.h" 13 #include "SkFlattenable.h"
14 14
15 #define kDrawLooperContextStorageLongCount (sizeof(void*) + sizeof(int))
Dominik Grewe 2014/02/07 11:57:15 It's not particularly nice to hardcode the size of
reed1 2014/02/07 14:46:02 1. I think callers have to be able to survive subc
Dominik Grewe 2014/02/07 16:59:17 I'll move it into the cpp files instead.
16
15 class SkCanvas; 17 class SkCanvas;
16 class SkPaint; 18 class SkPaint;
17 struct SkRect; 19 struct SkRect;
18 class SkString; 20 class SkString;
19 21
20 /** \class SkDrawLooper 22 /** \class SkDrawLooper
21 Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are, 23 Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are,
22 and something is drawn to a canvas with that paint, the looper subclass will 24 and something is drawn to a canvas with that paint, the looper subclass will
23 be called, allowing it to modify the canvas and/or paint for that draw call. 25 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 26 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 27 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. 28 like shadows or frame/fills, that require more than one pass.
27 */ 29 */
28 class SK_API SkDrawLooper : public SkFlattenable { 30 class SK_API SkDrawLooper : public SkFlattenable {
29 public: 31 public:
30 SK_DECLARE_INST_COUNT(SkDrawLooper) 32 SK_DECLARE_INST_COUNT(SkDrawLooper)
31 33
32 /** 34 /**
33 * Called right before something is being drawn. This will be followed by 35 * Holds state during a draw. Users call next() until it returns false. The
34 * calls to next() until next() returns false. 36 * final call to next() will also delete the context.
37 *
38 * Subclasses of SkDrawLooper should create a subclass of this object to
39 * hold state specific to their subclass.
35 */ 40 */
36 virtual void init(SkCanvas*) = 0; 41 class SK_API DrawContext {
42 public:
43 DrawContext() {}
44 virtual ~DrawContext() {}
45
46 /**
47 * Called in a loop (after init()). Each time true is returned, the
48 * object is drawn (possibly with a modified canvas and/or paint). When
49 * false is finally returned, drawing for the object stops. When the
50 * context is no longer in use, call cleanup().
51 *
52 * On each call, the paint will be in its original state, but the
53 * canvas will be as it was following the previous call to next() or
54 * init().
55 *
56 * The implementation must ensure that, when next() finally returns
57 * false, that the canvas has been restored to the state it was
58 * initially, before init() was first called.
59 */
60 virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0;
61
62 void cleanup(void* storage);
Dominik Grewe 2014/02/07 11:57:15 I've added this so the user is in charge of when t
63 };
37 64
38 /** 65 /**
39 * Called in a loop (after init()). Each time true is returned, the object 66 * Called right before something is being drawn. Returns a DrawContext
40 * is drawn (possibly with a modified canvas and/or paint). When false is 67 * whose next() method should be called until it returns false.
41 * finally returned, drawing for the object stops.
42 * 68 *
43 * On each call, the paint will be in its original state, but the canvas 69 * Pass a pointer to pre-allocated memory to avoid dynamic memory
44 * will be as it was following the previous call to next() or init(). 70 * allocation.
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 */ 71 */
50 virtual bool next(SkCanvas*, SkPaint* paint) = 0; 72 virtual DrawContext* init(SkCanvas*, void* storage, size_t storageSize)
73 const = 0;
74
51 75
52 /** 76 /**
53 * The fast bounds functions are used to enable the paint to be culled early 77 * 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 78 * in the drawing pipeline. If a subclass can support this feature it must
55 * return true for the canComputeFastBounds() function. If that function 79 * return true for the canComputeFastBounds() function. If that function
56 * returns false then computeFastBounds behavior is undefined otherwise it 80 * returns false then computeFastBounds behavior is undefined otherwise it
57 * is expected to have the following behavior. Given the parent paint and 81 * 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 82 * 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 83 * storage rect, where the storage rect is with the union of the src rect
60 * and the looper's bounding rect. 84 * and the looper's bounding rect.
61 */ 85 */
62 virtual bool canComputeFastBounds(const SkPaint& paint); 86 virtual bool canComputeFastBounds(const SkPaint& paint);
63 virtual void computeFastBounds(const SkPaint& paint, 87 virtual void computeFastBounds(const SkPaint& paint,
64 const SkRect& src, SkRect* dst); 88 const SkRect& src, SkRect* dst);
65 89
66 SkDEVCODE(virtual void toString(SkString* str) const = 0;) 90 SkDEVCODE(virtual void toString(SkString* str) const = 0;)
67 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) 91 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper)
68 92
69 protected: 93 protected:
70 SkDrawLooper() {} 94 SkDrawLooper() {}
71 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} 95 SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {}
72 96
73 private: 97 private:
74 typedef SkFlattenable INHERITED; 98 typedef SkFlattenable INHERITED;
75 }; 99 };
76 100
77 #endif 101 #endif
OLDNEW
« no previous file with comments | « no previous file | include/effects/SkBlurDrawLooper.h » ('j') | include/effects/SkLayerDrawLooper.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698