SkDrawLooper.h revision 9efd9a048aebaa6681afb76b18e1a7dd642078d3
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkDrawLooper_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkDrawLooper_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkFlattenable.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkCanvas;
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPaint;
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkDrawLooper
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are,
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    and something is drawn to a canvas with that paint, the looper subclass will
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    be called, allowing it to modify the canvas and/or paint for that draw call.
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    More than that, via the next() method, the looper can modify the draw to be
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    invoked multiple times (hence the name loop-er), allow it to perform effects
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    like shadows or frame/fills, that require more than one pass.
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/
267ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkDrawLooper : public SkFlattenable {
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
284e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com    /**
294e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  Called right before something is being drawn. This will be followed by
304e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  calls to next() until next() returns false.
314e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     */
324e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com    virtual void init(SkCanvas*) = 0;
334e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com
344e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com    /**
354e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  Called in a loop (after init()). Each time true is returned, the object
364e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  is drawn (possibly with a modified canvas and/or paint). When false is
374e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  finally returned, drawing for the object stops.
384e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *
394e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  On each call, the paint will be in its original state, but the canvas
404e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  will be as it was following the previous call to next() or init().
414e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *
424e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  The implementation must ensure that, when next() finally returns false,
434e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  that the canvas has been restored to the state it was initially, before
444e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     *  init() was first called.
454e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com     */
464e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com    virtual bool next(SkCanvas*, SkPaint* paint) = 0;
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
489efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com    /**
499efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com     * The fast bounds functions are used to enable the paint to be culled early
509efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com     * in the drawing pipeline. If a subclass can support this feature it must
519efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com     * return true for the canComputeFastBounds() function.  If that function
529efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com     * returns false then computeFastBounds behavior is undefined otherwise it
539efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com     * is expected to have the following behavior. Given the parent paint and
549efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com     * the parent's bounding rect the subclass must fill in and return the
559efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com     * storage rect, where the storage rect is with the union of the src rect
569efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com     * and the looper's bounding rect.
579efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com     */
589efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com    virtual bool canComputeFastBounds(const SkPaint& paint);
599efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com    virtual void computeFastBounds(const SkPaint& paint,
609efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com                                   const SkRect& src, SkRect* dst);
619efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected:
638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawLooper() {}
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDrawLooper(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    typedef SkFlattenable INHERITED;
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
71