SkDrawLooper.h revision 8a1c16ff38322f0210116fa7293eb8817c7e477e
18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * Copyright (C) 2008 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.com////////////////// EXPERIMENTAL ////////////////////////// 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkCanvas; 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPaint; 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkDrawLooper 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are, 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and something is drawn to a canvas with that paint, the looper subclass will 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com be called, allowing it to modify the canvas and/or paint for that draw call. 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com More than that, via the next() method, the looper can modify the draw to be 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com invoked multiple times (hence the name loop-er), allow it to perform effects 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com like shadows or frame/fills, that require more than one pass. 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDrawLooper : public SkFlattenable { 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Called right before something is being drawn to the specified canvas 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com with the specified paint. Subclass that want to modify either parameter 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com can do so now. 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void init(SkCanvas*, SkPaint*) {} 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Called in a loop (after init()). Each time true is returned, the object 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is drawn (possibly with a modified canvas and/or paint). When false is 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com finally returned, drawing for the object stops. 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual bool next() { return false; } 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Called after the looper has finally returned false from next(), allowing 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com the looper to restore the canvas/paint to their original states. 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is this required, since the subclass knows when it is done??? 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com should we pass the canvas/paint here, and/or to the next call 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com so that subclasses don't need to retain pointers to them during the 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com loop? 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual void restore() {} 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprotected: 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawLooper() {} 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDrawLooper(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {} 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com typedef SkFlattenable INHERITED; 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 65