blob: d6028ff94c7cc4c086b65f84a8d1f14681129722 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkDrawLooper_DEFINED
11#define SkDrawLooper_DEFINED
12
13#include "SkFlattenable.h"
14
reed@android.com8a1c16f2008-12-17 15:59:43 +000015class SkCanvas;
16class SkPaint;
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000017struct SkRect;
robertphillips@google.com4991b8f2013-01-28 20:21:59 +000018class SkString;
reed@android.com8a1c16f2008-12-17 15:59:43 +000019
20/** \class SkDrawLooper
21 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
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
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.
27*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000028class SK_API SkDrawLooper : public SkFlattenable {
reed@android.com8a1c16f2008-12-17 15:59:43 +000029public:
robertphillips@google.com0456e0b2012-06-27 14:03:26 +000030 SK_DECLARE_INST_COUNT(SkDrawLooper)
31
reed@google.com4e2b3d32011-04-07 14:18:59 +000032 /**
33 * Called right before something is being drawn. This will be followed by
34 * calls to next() until next() returns false.
35 */
36 virtual void init(SkCanvas*) = 0;
37
38 /**
39 * Called in a loop (after init()). Each time true is returned, the object
40 * is drawn (possibly with a modified canvas and/or paint). When false is
41 * finally returned, drawing for the object stops.
42 *
43 * On each call, the paint will be in its original state, but the canvas
44 * will be as it was following the previous call to next() or init().
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 */
50 virtual bool next(SkCanvas*, SkPaint* paint) = 0;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000051
reed@google.com9efd9a02012-01-30 15:41:43 +000052 /**
53 * 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
55 * return true for the canComputeFastBounds() function. If that function
56 * returns false then computeFastBounds behavior is undefined otherwise it
57 * 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
59 * storage rect, where the storage rect is with the union of the src rect
60 * and the looper's bounding rect.
61 */
62 virtual bool canComputeFastBounds(const SkPaint& paint);
63 virtual void computeFastBounds(const SkPaint& paint,
64 const SkRect& src, SkRect* dst);
65
robertphillips@google.com4991b8f2013-01-28 20:21:59 +000066 SkDEVCODE(virtual void toString(SkString* str) const = 0;)
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +000067 SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper)
robertphillips@google.com4991b8f2013-01-28 20:21:59 +000068
reed@android.com8a1c16f2008-12-17 15:59:43 +000069protected:
70 SkDrawLooper() {}
71 SkDrawLooper(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
72
73private:
74 typedef SkFlattenable INHERITED;
75};
76
77#endif