Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SkDrawLooper_DEFINED
     18 #define SkDrawLooper_DEFINED
     19 
     20 #include "SkFlattenable.h"
     21 
     22 ////////////////// EXPERIMENTAL //////////////////////////
     23 
     24 class SkCanvas;
     25 class SkPaint;
     26 
     27 /** \class SkDrawLooper
     28     Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are,
     29     and something is drawn to a canvas with that paint, the looper subclass will
     30     be called, allowing it to modify the canvas and/or paint for that draw call.
     31     More than that, via the next() method, the looper can modify the draw to be
     32     invoked multiple times (hence the name loop-er), allow it to perform effects
     33     like shadows or frame/fills, that require more than one pass.
     34 */
     35 class SkDrawLooper : public SkFlattenable {
     36 public:
     37     /** Called right before something is being drawn to the specified canvas
     38         with the specified paint. Subclass that want to modify either parameter
     39         can do so now.
     40     */
     41     virtual void init(SkCanvas*, SkPaint*) {}
     42     /** Called in a loop (after init()). Each time true is returned, the object
     43         is drawn (possibly with a modified canvas and/or paint). When false is
     44         finally returned, drawing for the object stops.
     45     */
     46     virtual bool next() { return false; }
     47     /** Called after the looper has finally returned false from next(), allowing
     48         the looper to restore the canvas/paint to their original states.
     49         is this required, since the subclass knows when it is done???
     50         should we pass the canvas/paint here, and/or to the next call
     51         so that subclasses don't need to retain pointers to them during the
     52         loop?
     53     */
     54     virtual void restore() {}
     55 
     56 protected:
     57     SkDrawLooper() {}
     58     SkDrawLooper(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
     59 
     60 private:
     61     typedef SkFlattenable INHERITED;
     62 };
     63 
     64 #endif
     65