SkDrawLooper.h revision 4e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7b
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 24e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * Copyright (C) 2011 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Licensed under the Apache License, Version 2.0 (the "License"); 58a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * you may not use this file except in compliance with the License. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * You may obtain a copy of the License at 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * http://www.apache.org/licenses/LICENSE-2.0 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Unless required by applicable law or agreed to in writing, software 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * distributed under the License is distributed on an "AS IS" BASIS, 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * See the License for the specific language governing permissions and 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * limitations under the License. 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkDrawLooper_DEFINED 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkDrawLooper_DEFINED 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkFlattenable.h" 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkCanvas; 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPaint; 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkDrawLooper 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are, 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and something is drawn to a canvas with that paint, the looper subclass will 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com be called, allowing it to modify the canvas and/or paint for that draw call. 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com More than that, via the next() method, the looper can modify the draw to be 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com invoked multiple times (hence the name loop-er), allow it to perform effects 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com like shadows or frame/fills, that require more than one pass. 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 337ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkDrawLooper : public SkFlattenable { 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 354e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com /** 364e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * Called right before something is being drawn. This will be followed by 374e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * calls to next() until next() returns false. 384e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com */ 394e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com virtual void init(SkCanvas*) = 0; 404e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com 414e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com /** 424e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * Called in a loop (after init()). Each time true is returned, the object 434e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * is drawn (possibly with a modified canvas and/or paint). When false is 444e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * finally returned, drawing for the object stops. 454e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * 464e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * On each call, the paint will be in its original state, but the canvas 474e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * will be as it was following the previous call to next() or init(). 484e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * 494e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * The implementation must ensure that, when next() finally returns false, 504e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * that the canvas has been restored to the state it was initially, before 514e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com * init() was first called. 524e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com */ 534e2b3d3fb1288c6dc0f3ea1c0aa4a0d7c603bd7breed@google.com virtual bool next(SkCanvas*, SkPaint* paint) = 0; 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawLooper() {} 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawLooper(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkFlattenable INHERITED; 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 64