Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkLayerDrawLooper_DEFINED | 8 #ifndef SkLayerDrawLooper_DEFINED |
| 9 #define SkLayerDrawLooper_DEFINED | 9 #define SkLayerDrawLooper_DEFINED |
| 10 | 10 |
| 11 #include "SkDrawLooper.h" | 11 #include "SkDrawLooper.h" |
| 12 #include "SkPaint.h" | |
| 13 #include "SkPoint.h" | |
| 14 #include "SkXfermode.h" | 12 #include "SkXfermode.h" |
| 15 | 13 |
| 14 #include <stddef.h> | |
| 15 #include <vector> | |
|
mtklein
2015/09/25 11:47:21
We don't use std::vector in Skia (yet?) but SkTArr
mdempsky
2015/09/25 16:40:17
Hm, right. Somehow I thought I saw STL usage else
| |
| 16 | |
| 17 class SkPaint; | |
| 18 | |
| 16 class SK_API SkLayerDrawLooper : public SkDrawLooper { | 19 class SK_API SkLayerDrawLooper : public SkDrawLooper { |
| 17 public: | 20 public: |
| 18 virtual ~SkLayerDrawLooper(); | 21 virtual ~SkLayerDrawLooper(); |
| 19 | 22 |
| 20 /** | 23 /** |
| 21 * Bits specifies which aspects of the layer's paint should replace the | 24 * Bits specifies which aspects of the layer's paint should replace the |
| 22 * corresponding aspects on the draw's paint. | 25 * corresponding aspects on the draw's paint. |
| 23 * kEntirePaint_Bits means use the layer's paint completely. | 26 * kEntirePaint_Bits means use the layer's paint completely. |
| 24 * 0 means ignore the layer's paint... except for fColorMode, which is | 27 * 0 means ignore the layer's paint... except for fColorMode, which is |
| 25 * always applied. | 28 * always applied. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 | 84 |
| 82 Factory getFactory() const override { return CreateProc; } | 85 Factory getFactory() const override { return CreateProc; } |
| 83 static SkFlattenable* CreateProc(SkReadBuffer& buffer); | 86 static SkFlattenable* CreateProc(SkReadBuffer& buffer); |
| 84 | 87 |
| 85 protected: | 88 protected: |
| 86 SkLayerDrawLooper(); | 89 SkLayerDrawLooper(); |
| 87 | 90 |
| 88 void flatten(SkWriteBuffer&) const override; | 91 void flatten(SkWriteBuffer&) const override; |
| 89 | 92 |
| 90 private: | 93 private: |
| 91 struct Rec { | 94 struct Rec; |
| 92 Rec* fNext; | 95 std::vector<Rec> fRecs; |
| 93 SkPaint fPaint; | |
| 94 LayerInfo fInfo; | |
| 95 }; | |
| 96 Rec* fRecs; | |
| 97 int fCount; | |
| 98 | 96 |
| 99 // state-machine during the init/next cycle | 97 // state-machine during the init/next cycle |
| 100 class LayerDrawLooperContext : public SkDrawLooper::Context { | 98 class LayerDrawLooperContext : public SkDrawLooper::Context { |
| 101 public: | 99 public: |
| 102 explicit LayerDrawLooperContext(const SkLayerDrawLooper* looper); | 100 explicit LayerDrawLooperContext(const SkLayerDrawLooper* looper); |
| 103 | 101 |
| 104 protected: | 102 protected: |
| 105 bool next(SkCanvas*, SkPaint* paint) override; | 103 bool next(SkCanvas*, SkPaint* paint) override; |
| 106 | 104 |
| 107 private: | 105 private: |
| 108 Rec* fCurrRec; | 106 std::vector<Rec>::const_iterator fCurr; |
| 107 const std::vector<Rec>::const_iterator fEnd; | |
| 109 | 108 |
| 110 static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo& ); | 109 static void ApplyInfo(SkPaint* dst, const SkPaint& src, const LayerInfo& ); |
| 111 }; | 110 }; |
| 112 | 111 |
| 113 typedef SkDrawLooper INHERITED; | 112 typedef SkDrawLooper INHERITED; |
| 114 | 113 |
| 115 public: | 114 public: |
| 116 class SK_API Builder { | 115 class SK_API Builder { |
| 117 public: | 116 public: |
| 118 Builder(); | 117 Builder(); |
| 119 ~Builder(); | 118 ~Builder(); |
| 120 | 119 |
| 121 /** | 120 /** |
| 122 * Call for each layer you want to add (from top to bottom). | 121 * Requests that the builder reserve space for at least n layers. |
| 122 */ | |
| 123 void reserve(size_t n); | |
| 124 | |
| 125 /** | |
| 126 * Call for each layer you want to add (from bottom to top). | |
| 123 * This returns a paint you can modify, but that ptr is only valid unti l | 127 * This returns a paint you can modify, but that ptr is only valid unti l |
| 124 * the next call made to addLayer(). | 128 * the next call made to addLayerOnTop(). |
| 125 */ | 129 */ |
| 126 SkPaint* addLayer(const LayerInfo&); | 130 SkPaint* addLayerOnTop(const LayerInfo&); |
|
mtklein
2015/09/25 11:47:21
Can we keep the API oriented top to bottom while k
mdempsky
2015/09/25 16:40:17
Yeah that's possible too if you think that's bette
| |
| 127 | 131 |
| 128 /** | 132 /** |
| 129 * This layer will draw with the original paint, at the specified offse t | 133 * This layer will draw with the original paint, at the specified offse t |
| 130 */ | 134 */ |
| 131 void addLayer(SkScalar dx, SkScalar dy); | 135 void addLayerOnTop(SkScalar dx, SkScalar dy); |
| 132 | 136 |
| 133 /** | 137 /** |
| 134 * This layer will with the original paint and no offset. | 138 * This layer will with the original paint and no offset. |
| 135 */ | 139 */ |
| 136 void addLayer() { this->addLayer(0, 0); } | 140 void addLayerOnTop() { this->addLayerOnTop(0, 0); } |
| 137 | |
| 138 /// Similar to addLayer, but adds a layer to the top. | |
| 139 SkPaint* addLayerOnTop(const LayerInfo&); | |
| 140 | 141 |
| 141 /** | 142 /** |
| 142 * Pass list of layers on to newly built looper and return it. This wil l | 143 * Pass list of layers on to newly built looper and return it. This wil l |
| 143 * also reset the builder, so it can be used to build another looper. | 144 * also reset the builder, so it can be used to build another looper. |
| 144 */ | 145 */ |
| 145 SkLayerDrawLooper* detachLooper(); | 146 SkLayerDrawLooper* detachLooper(); |
| 146 | 147 |
| 147 private: | 148 private: |
| 148 Rec* fRecs; | 149 std::vector<Rec> fRecs; |
| 149 Rec* fTopRec; | |
| 150 int fCount; | |
| 151 }; | 150 }; |
| 152 }; | 151 }; |
| 153 | 152 |
| 154 #endif | 153 #endif |
| OLD | NEW |