Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2011 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef SkLayerDrawLooper_DEFINED |
michael@0 | 9 | #define SkLayerDrawLooper_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkDrawLooper.h" |
michael@0 | 12 | #include "SkPaint.h" |
michael@0 | 13 | #include "SkPoint.h" |
michael@0 | 14 | #include "SkXfermode.h" |
michael@0 | 15 | |
michael@0 | 16 | class SK_API SkLayerDrawLooper : public SkDrawLooper { |
michael@0 | 17 | public: |
michael@0 | 18 | SK_DECLARE_INST_COUNT(SkLayerDrawLooper) |
michael@0 | 19 | |
michael@0 | 20 | SkLayerDrawLooper(); |
michael@0 | 21 | virtual ~SkLayerDrawLooper(); |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * Bits specifies which aspects of the layer's paint should replace the |
michael@0 | 25 | * corresponding aspects on the draw's paint. |
michael@0 | 26 | * kEntirePaint_Bits means use the layer's paint completely. |
michael@0 | 27 | * 0 means ignore the layer's paint... except for fColorMode, which is |
michael@0 | 28 | * always applied. |
michael@0 | 29 | */ |
michael@0 | 30 | enum Bits { |
michael@0 | 31 | kStyle_Bit = 1 << 0, //!< use this layer's Style/stroke settings |
michael@0 | 32 | kTextSkewX_Bit = 1 << 1, //!< use this layer's textskewx |
michael@0 | 33 | kPathEffect_Bit = 1 << 2, //!< use this layer's patheffect |
michael@0 | 34 | kMaskFilter_Bit = 1 << 3, //!< use this layer's maskfilter |
michael@0 | 35 | kShader_Bit = 1 << 4, //!< use this layer's shader |
michael@0 | 36 | kColorFilter_Bit = 1 << 5, //!< use this layer's colorfilter |
michael@0 | 37 | kXfermode_Bit = 1 << 6, //!< use this layer's xfermode |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * Use the layer's paint entirely, with these exceptions: |
michael@0 | 41 | * - We never override the draw's paint's text_encoding, since that is |
michael@0 | 42 | * used to interpret the text/len parameters in draw[Pos]Text. |
michael@0 | 43 | * - Color is always computed using the LayerInfo's fColorMode. |
michael@0 | 44 | */ |
michael@0 | 45 | kEntirePaint_Bits = -1 |
michael@0 | 46 | |
michael@0 | 47 | }; |
michael@0 | 48 | typedef int32_t BitFlags; |
michael@0 | 49 | |
michael@0 | 50 | /** |
michael@0 | 51 | * Info for how to apply the layer's paint and offset. |
michael@0 | 52 | * |
michael@0 | 53 | * fColorMode controls how we compute the final color for the layer: |
michael@0 | 54 | * The layer's paint's color is treated as the SRC |
michael@0 | 55 | * The draw's paint's color is treated as the DST |
michael@0 | 56 | * final-color = Mode(layers-color, draws-color); |
michael@0 | 57 | * Any SkXfermode::Mode will work. Two common choices are: |
michael@0 | 58 | * kSrc_Mode: to use the layer's color, ignoring the draw's |
michael@0 | 59 | * kDst_Mode: to just keep the draw's color, ignoring the layer's |
michael@0 | 60 | */ |
michael@0 | 61 | struct SK_API LayerInfo { |
michael@0 | 62 | BitFlags fPaintBits; |
michael@0 | 63 | SkXfermode::Mode fColorMode; |
michael@0 | 64 | SkVector fOffset; |
michael@0 | 65 | bool fPostTranslate; //!< applies to fOffset |
michael@0 | 66 | |
michael@0 | 67 | /** |
michael@0 | 68 | * Initial the LayerInfo. Defaults to settings that will draw the |
michael@0 | 69 | * layer with no changes: e.g. |
michael@0 | 70 | * fPaintBits == 0 |
michael@0 | 71 | * fColorMode == kDst_Mode |
michael@0 | 72 | * fOffset == (0, 0) |
michael@0 | 73 | */ |
michael@0 | 74 | LayerInfo(); |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * Call for each layer you want to add (from top to bottom). |
michael@0 | 79 | * This returns a paint you can modify, but that ptr is only valid until |
michael@0 | 80 | * the next call made to addLayer(). |
michael@0 | 81 | */ |
michael@0 | 82 | SkPaint* addLayer(const LayerInfo&); |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * This layer will draw with the original paint, at the specified offset |
michael@0 | 86 | */ |
michael@0 | 87 | void addLayer(SkScalar dx, SkScalar dy); |
michael@0 | 88 | |
michael@0 | 89 | /** |
michael@0 | 90 | * This layer will with the original paint and no offset. |
michael@0 | 91 | */ |
michael@0 | 92 | void addLayer() { this->addLayer(0, 0); } |
michael@0 | 93 | |
michael@0 | 94 | /// Similar to addLayer, but adds a layer to the top. |
michael@0 | 95 | SkPaint* addLayerOnTop(const LayerInfo&); |
michael@0 | 96 | |
michael@0 | 97 | virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const SK_OVERRIDE; |
michael@0 | 98 | |
michael@0 | 99 | virtual size_t contextSize() const SK_OVERRIDE { return sizeof(LayerDrawLooperContext); } |
michael@0 | 100 | |
michael@0 | 101 | SK_TO_STRING_OVERRIDE() |
michael@0 | 102 | |
michael@0 | 103 | /// Implements Flattenable. |
michael@0 | 104 | virtual Factory getFactory() const SK_OVERRIDE { return CreateProc; } |
michael@0 | 105 | static SkFlattenable* CreateProc(SkReadBuffer& buffer); |
michael@0 | 106 | |
michael@0 | 107 | protected: |
michael@0 | 108 | virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
michael@0 | 109 | |
michael@0 | 110 | private: |
michael@0 | 111 | struct Rec { |
michael@0 | 112 | Rec* fNext; |
michael@0 | 113 | SkPaint fPaint; |
michael@0 | 114 | LayerInfo fInfo; |
michael@0 | 115 | }; |
michael@0 | 116 | Rec* fRecs; |
michael@0 | 117 | Rec* fTopRec; |
michael@0 | 118 | int fCount; |
michael@0 | 119 | |
michael@0 | 120 | // state-machine during the init/next cycle |
michael@0 | 121 | class LayerDrawLooperContext : public SkDrawLooper::Context { |
michael@0 | 122 | public: |
michael@0 | 123 | explicit LayerDrawLooperContext(const SkLayerDrawLooper* looper); |
michael@0 | 124 | |
michael@0 | 125 | protected: |
michael@0 | 126 | virtual bool next(SkCanvas*, SkPaint* paint) SK_OVERRIDE; |
michael@0 | 127 | |
michael@0 | 128 | private: |
michael@0 | 129 | Rec* fCurrRec; |
michael@0 | 130 | |
michael@0 | 131 | static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo&); |
michael@0 | 132 | }; |
michael@0 | 133 | |
michael@0 | 134 | class MyRegistrar : public SkFlattenable::Registrar { |
michael@0 | 135 | public: |
michael@0 | 136 | MyRegistrar(); |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | typedef SkDrawLooper INHERITED; |
michael@0 | 140 | |
michael@0 | 141 | public: |
michael@0 | 142 | class SK_API Builder { |
michael@0 | 143 | public: |
michael@0 | 144 | Builder(); |
michael@0 | 145 | ~Builder(); |
michael@0 | 146 | |
michael@0 | 147 | /** |
michael@0 | 148 | * Call for each layer you want to add (from top to bottom). |
michael@0 | 149 | * This returns a paint you can modify, but that ptr is only valid until |
michael@0 | 150 | * the next call made to addLayer(). |
michael@0 | 151 | */ |
michael@0 | 152 | SkPaint* addLayer(const LayerInfo&); |
michael@0 | 153 | |
michael@0 | 154 | /** |
michael@0 | 155 | * This layer will draw with the original paint, at the specified offset |
michael@0 | 156 | */ |
michael@0 | 157 | void addLayer(SkScalar dx, SkScalar dy); |
michael@0 | 158 | |
michael@0 | 159 | /** |
michael@0 | 160 | * This layer will with the original paint and no offset. |
michael@0 | 161 | */ |
michael@0 | 162 | void addLayer() { this->addLayer(0, 0); } |
michael@0 | 163 | |
michael@0 | 164 | /// Similar to addLayer, but adds a layer to the top. |
michael@0 | 165 | SkPaint* addLayerOnTop(const LayerInfo&); |
michael@0 | 166 | |
michael@0 | 167 | /** |
michael@0 | 168 | * Pass list of layers on to newly built looper and return it. This will |
michael@0 | 169 | * also reset the builder, so it can be used to build another looper. |
michael@0 | 170 | */ |
michael@0 | 171 | SkLayerDrawLooper* detachLooper(); |
michael@0 | 172 | |
michael@0 | 173 | private: |
michael@0 | 174 | Rec* fRecs; |
michael@0 | 175 | Rec* fTopRec; |
michael@0 | 176 | int fCount; |
michael@0 | 177 | }; |
michael@0 | 178 | }; |
michael@0 | 179 | |
michael@0 | 180 | #endif |