SkDrawLooper.h revision 8b0e8ac5f582de80356019406e2975079bf0829d
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 /** 334e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * Called right before something is being drawn. This will be followed by 344e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * calls to next() until next() returns false. 354e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com */ 364e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com virtual void init(SkCanvas*) = 0; 374e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com 384e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com /** 394e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * Called in a loop (after init()). Each time true is returned, the object 404e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * is drawn (possibly with a modified canvas and/or paint). When false is 414e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * finally returned, drawing for the object stops. 424e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * 434e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * On each call, the paint will be in its original state, but the canvas 444e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * will be as it was following the previous call to next() or init(). 454e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * 464e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * The implementation must ensure that, when next() finally returns false, 474e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * that the canvas has been restored to the state it was initially, before 484e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * init() was first called. 494e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com */ 504e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com virtual bool next(SkCanvas*, SkPaint* paint) = 0; 51fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 529efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com /** 539efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * The fast bounds functions are used to enable the paint to be culled early 549efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * in the drawing pipeline. If a subclass can support this feature it must 559efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * return true for the canComputeFastBounds() function. If that function 569efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * returns false then computeFastBounds behavior is undefined otherwise it 579efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * is expected to have the following behavior. Given the parent paint and 589efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * the parent's bounding rect the subclass must fill in and return the 599efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * storage rect, where the storage rect is with the union of the src rect 609efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com * and the looper's bounding rect. 619efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com */ 629efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com virtual bool canComputeFastBounds(const SkPaint& paint); 639efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com virtual void computeFastBounds(const SkPaint& paint, 649efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com const SkRect& src, SkRect* dst); 659efd9a048aebaa6681afb76b18e1a7dd642078d3reed@google.com 664991b8f23482afc1494fd17647421ce68de53331robertphillips@google.com SkDEVCODE(virtual void toString(SkString* str) const = 0;) 67c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org SK_DEFINE_FLATTENABLE_TYPE(SkDrawLooper) 684991b8f23482afc1494fd17647421ce68de53331robertphillips@google.com 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawLooper() {} 718b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org SkDrawLooper(SkReadBuffer& buffer) : INHERITED(buffer) {} 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkFlattenable INHERITED; 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 78