SkDrawLooper.h revision e3beb6bd7de7fa211681abbb0be58e80b19885e0
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; 17c73dd5c6880739f26216f198c757028fd28df1a4djsollen@google.comstruct SkRect; 184991b8f23482afc1494fd17647421ce68de53331robertphillips@google.comclass SkString; 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkDrawLooper 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are, 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and something is drawn to a canvas with that paint, the looper subclass will 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com be called, allowing it to modify the canvas and/or paint for that draw call. 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com More than that, via the next() method, the looper can modify the draw to be 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com invoked multiple times (hence the name loop-er), allow it to perform effects 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com like shadows or frame/fills, that require more than one pass. 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 287ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkDrawLooper : public SkFlattenable { 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 300456e0b7b85060e9b9597ce414c4c2b19aff4f58robertphillips@google.com SK_DECLARE_INST_COUNT(SkDrawLooper) 310456e0b7b85060e9b9597ce414c4c2b19aff4f58robertphillips@google.com 324e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com /** 3379fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * Holds state during a draw. Users call next() until it returns false. 3479fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * 3579fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * Subclasses of SkDrawLooper should create a subclass of this object to 3679fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * hold state specific to their subclass. 374e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com */ 38e3beb6bd7de7fa211681abbb0be58e80b19885e0commit-bot@chromium.org class SK_API Context : ::SkNoncopyable { 3979fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org public: 4079fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org Context() {} 4179fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org virtual ~Context() {} 4279fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org 4379fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org /** 4479fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * Called in a loop on objects returned by SkDrawLooper::createContext(). 4579fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * Each time true is returned, the object is drawn (possibly with a modified 4679fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * canvas and/or paint). When false is finally returned, drawing for the object 4779fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * stops. 4879fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * 4979fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * On each call, the paint will be in its original state, but the 5079fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * canvas will be as it was following the previous call to next() or 5179fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * createContext(). 5279fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * 5379fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * The implementation must ensure that, when next() finally returns 5479fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * false, the canvas has been restored to the state it was 5579fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * initially, before createContext() was first called. 5679fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org */ 5779fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org virtual bool next(SkCanvas* canvas, SkPaint* paint) = 0; 5879fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org }; 594e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com 604e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com /** 6179fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * Called right before something is being drawn. Returns a Context 6279fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * whose next() method should be called until it returns false. 6379fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * The caller has to ensure that the storage pointer provides enough 6479fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * memory for the Context. The required size can be queried by calling 6579fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * contextSize(). It is also the caller's responsibility to destroy the 6679fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * object after use. 674e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com */ 6879fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org virtual Context* createContext(SkCanvas*, void* storage) const = 0; 6979fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org 7079fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org /** 7179fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * Returns the number of bytes needed to store subclasses of Context (belonging to the 7279fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org * corresponding SkDrawLooper subclass). 7379fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org */ 7479fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org virtual size_t contextSize() const = 0; 7579fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org 76fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 779efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com /** 789efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * The fast bounds functions are used to enable the paint to be culled early 799efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * in the drawing pipeline. If a subclass can support this feature it must 809efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * return true for the canComputeFastBounds() function. If that function 819efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * returns false then computeFastBounds behavior is undefined otherwise it 829efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * is expected to have the following behavior. Given the parent paint and 839efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * the parent's bounding rect the subclass must fill in and return the 849efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * storage rect, where the storage rect is with the union of the src rect 859efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * and the looper's bounding rect. 869efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com */ 8779fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org virtual bool canComputeFastBounds(const SkPaint& paint) const; 889efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com virtual void computeFastBounds(const SkPaint& paint, 8979fbb40bca9d815ef79b896b31ba6ee736817e0fcommit-bot@chromium.org const SkRect& src, SkRect* dst) const; 909efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com 910f10f7bf1fb43ca6346dc220a076773b1f19a367commit-bot@chromium.org SK_TO_STRING_PUREVIRT() 92c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) 934991b8f23482afc1494fd17647421ce68de53331robertphillips@google.com 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawLooper() {} 968b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} 978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkFlattenable INHERITED; 1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 103