chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #ifndef SKDRAWCOMMAND_H_ |
| 10 | #define SKDRAWCOMMAND_H_ |
| 11 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 12 | #include "SkPictureFlat.h" |
| 13 | #include "SkCanvas.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 14 | |
| 15 | class SkDrawCommand { |
| 16 | public: |
| 17 | /* TODO(chudy): Remove subclasses. */ |
| 18 | SkDrawCommand(); |
| 19 | |
| 20 | virtual ~SkDrawCommand(); |
| 21 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 22 | virtual SkString toString(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 23 | |
| 24 | virtual const char* toCString() { |
| 25 | return GetCommandString(fDrawType); |
| 26 | } |
| 27 | |
chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 28 | bool isVisible() const { |
| 29 | return fVisible; |
| 30 | } |
| 31 | |
| 32 | void setVisible(bool toggle) { |
| 33 | fVisible = toggle; |
| 34 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 35 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 36 | SkTDArray<SkString*>* Info() {return &fInfo; }; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 37 | virtual void execute(SkCanvas* canvas)=0; |
| 38 | DrawType getType() { return fDrawType; }; |
| 39 | |
| 40 | protected: |
| 41 | DrawType fDrawType; |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 42 | SkTDArray<SkString*> fInfo; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 43 | |
| 44 | private: |
| 45 | bool fVisible; |
| 46 | static const char* GetCommandString(DrawType type); |
| 47 | }; |
| 48 | |
| 49 | class Restore : public SkDrawCommand { |
| 50 | public: |
| 51 | Restore(); |
| 52 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 53 | }; |
| 54 | |
| 55 | class Clear : public SkDrawCommand { |
| 56 | public: |
| 57 | Clear(SkColor color); |
| 58 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 59 | private: |
| 60 | SkColor fColor; |
| 61 | }; |
| 62 | |
| 63 | class ClipPath : public SkDrawCommand { |
| 64 | public: |
| 65 | ClipPath(const SkPath& path, SkRegion::Op op, bool doAA); |
| 66 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 67 | private: |
| 68 | const SkPath* fPath; |
| 69 | SkRegion::Op fOp; |
| 70 | bool fDoAA; |
| 71 | }; |
| 72 | |
| 73 | class ClipRegion : public SkDrawCommand { |
| 74 | public: |
| 75 | ClipRegion(const SkRegion& region, SkRegion::Op op); |
| 76 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 77 | private: |
| 78 | const SkRegion* fRegion; |
| 79 | SkRegion::Op fOp; |
| 80 | }; |
| 81 | |
| 82 | class ClipRect : public SkDrawCommand { |
| 83 | public: |
| 84 | ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA); |
| 85 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 86 | private: |
| 87 | const SkRect* fRect; |
| 88 | SkRegion::Op fOp; |
| 89 | bool fDoAA; |
| 90 | }; |
| 91 | |
| 92 | class Concat : public SkDrawCommand { |
| 93 | public: |
| 94 | Concat(const SkMatrix& matrix); |
| 95 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 96 | private: |
| 97 | const SkMatrix* fMatrix; |
| 98 | }; |
| 99 | |
| 100 | class DrawBitmap : public SkDrawCommand { |
| 101 | public: |
| 102 | DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
| 103 | const SkPaint* paint); |
| 104 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 105 | private: |
| 106 | const SkPaint* fPaint; |
| 107 | const SkBitmap* fBitmap; |
| 108 | SkScalar fLeft; |
| 109 | SkScalar fTop; |
| 110 | }; |
| 111 | |
| 112 | class DrawBitmapMatrix : public SkDrawCommand { |
| 113 | public: |
| 114 | DrawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix, |
| 115 | const SkPaint* paint); |
| 116 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 117 | private: |
| 118 | const SkPaint* fPaint; |
| 119 | const SkBitmap* fBitmap; |
| 120 | const SkMatrix* fMatrix; |
| 121 | }; |
| 122 | |
| 123 | class DrawBitmapNine : public SkDrawCommand { |
| 124 | public: |
| 125 | DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
| 126 | const SkRect& dst, const SkPaint* paint); |
| 127 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 128 | private: |
| 129 | const SkBitmap* fBitmap; |
| 130 | const SkIRect* fCenter; |
| 131 | const SkRect* fDst; |
| 132 | const SkPaint* fPaint; |
| 133 | }; |
| 134 | |
| 135 | class DrawBitmapRect : public SkDrawCommand { |
| 136 | public: |
| 137 | DrawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, |
| 138 | const SkRect& dst, const SkPaint* paint); |
| 139 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 140 | private: |
| 141 | const SkIRect* fSrc; |
| 142 | const SkPaint* fPaint; |
| 143 | const SkBitmap* fBitmap; |
| 144 | const SkRect* fDst; |
| 145 | }; |
| 146 | |
| 147 | class DrawData : public SkDrawCommand { |
| 148 | public: |
| 149 | DrawData(const void* data, size_t length); |
| 150 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 151 | private: |
| 152 | const void* fData; |
| 153 | size_t fLength; |
| 154 | }; |
| 155 | |
| 156 | class DrawPaint : public SkDrawCommand { |
| 157 | public: |
| 158 | DrawPaint(const SkPaint& paint); |
| 159 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 160 | private: |
| 161 | const SkPaint* fPaint; |
| 162 | }; |
| 163 | |
| 164 | class DrawPath : public SkDrawCommand { |
| 165 | public: |
| 166 | DrawPath(const SkPath& path, const SkPaint& paint); |
| 167 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 168 | private: |
| 169 | const SkPath* fPath; |
| 170 | const SkPaint* fPaint; |
| 171 | }; |
| 172 | |
| 173 | class DrawPicture : public SkDrawCommand { |
| 174 | public: |
| 175 | DrawPicture(SkPicture& picture); |
| 176 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 177 | private: |
| 178 | SkPicture* fPicture; |
| 179 | }; |
| 180 | |
| 181 | class DrawPoints : public SkDrawCommand { |
| 182 | public: |
| 183 | DrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], |
| 184 | const SkPaint& paint); |
| 185 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 186 | private: |
| 187 | const SkPoint* fPts; |
| 188 | SkCanvas::PointMode fMode; |
| 189 | size_t fCount; |
| 190 | const SkPaint* fPaint; |
| 191 | }; |
| 192 | |
| 193 | /* TODO(chudy): DrawText is a predefined macro and was breaking something |
| 194 | * in the windows build of the debugger. |
| 195 | */ |
| 196 | class DrawTextC : public SkDrawCommand { |
| 197 | public: |
| 198 | DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 199 | const SkPaint& paint); |
| 200 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 201 | private: |
| 202 | const void* fText; |
| 203 | size_t fByteLength; |
| 204 | SkScalar fX; |
| 205 | SkScalar fY; |
| 206 | const SkPaint* fPaint; |
| 207 | }; |
| 208 | |
| 209 | class DrawPosText : public SkDrawCommand { |
| 210 | public: |
| 211 | DrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 212 | const SkPaint& paint); |
| 213 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 214 | private: |
| 215 | const SkPoint* fPos; |
| 216 | const void* fText; |
| 217 | size_t fByteLength; |
| 218 | const SkPaint* fPaint; |
| 219 | }; |
| 220 | |
| 221 | class DrawTextOnPath : public SkDrawCommand { |
| 222 | public: |
| 223 | DrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 224 | const SkMatrix* matrix, const SkPaint& paint); |
| 225 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 226 | private: |
| 227 | const SkMatrix* fMatrix; |
| 228 | const void* fText; |
| 229 | size_t fByteLength; |
| 230 | const SkPath* fPath; |
| 231 | const SkPaint* fPaint; |
| 232 | }; |
| 233 | |
| 234 | class DrawPosTextH : public SkDrawCommand { |
| 235 | public: |
| 236 | DrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 237 | SkScalar constY, const SkPaint& paint); |
| 238 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 239 | private: |
| 240 | const SkScalar* fXpos; |
| 241 | const void* fText; |
| 242 | size_t fByteLength; |
| 243 | SkScalar fConstY; |
| 244 | const SkPaint* fPaint; |
| 245 | }; |
| 246 | |
| 247 | class DrawRectC : public SkDrawCommand { |
| 248 | public: |
| 249 | DrawRectC(const SkRect& rect, const SkPaint& paint); |
| 250 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 251 | private: |
| 252 | const SkRect* fRect; |
| 253 | const SkPaint* fPaint; |
| 254 | }; |
| 255 | |
| 256 | class DrawSprite : public SkDrawCommand { |
| 257 | public: |
| 258 | DrawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint); |
| 259 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 260 | private: |
| 261 | const SkPaint* fPaint; |
| 262 | int fLeft; |
| 263 | int fTop; |
| 264 | const SkBitmap* fBitmap; |
| 265 | }; |
| 266 | |
| 267 | class DrawVertices : public SkDrawCommand { |
| 268 | public: |
| 269 | DrawVertices(SkCanvas::VertexMode vmode, int vertexCount, |
| 270 | const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], |
| 271 | SkXfermode* xfermode, const uint16_t indices[], int indexCount, |
| 272 | const SkPaint& paint); |
| 273 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 274 | private: |
| 275 | SkCanvas::VertexMode fVmode; |
| 276 | int fVertexCount; |
| 277 | int fIndexCount; |
| 278 | const SkPoint* fVertices; |
| 279 | const SkPoint* fTexs; |
| 280 | const SkColor* fColors; |
| 281 | const uint16_t* fIndices; |
| 282 | SkXfermode* fXfermode; |
| 283 | const SkPaint* fPaint; |
| 284 | }; |
| 285 | |
| 286 | class Rotate : public SkDrawCommand { |
| 287 | public: |
| 288 | Rotate(SkScalar degrees); |
| 289 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 290 | private: |
| 291 | SkScalar fDegrees; |
| 292 | }; |
| 293 | |
| 294 | class Save : public SkDrawCommand { |
| 295 | public: |
| 296 | Save(SkCanvas::SaveFlags flags); |
| 297 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 298 | private: |
| 299 | SkCanvas::SaveFlags fFlags; |
| 300 | }; |
| 301 | |
| 302 | class SaveLayer : public SkDrawCommand { |
| 303 | public: |
| 304 | SaveLayer(const SkRect* bounds, const SkPaint* paint, |
| 305 | SkCanvas::SaveFlags flags); |
| 306 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 307 | private: |
| 308 | const SkRect* fBounds; |
| 309 | const SkPaint* fPaint; |
| 310 | SkCanvas::SaveFlags fFlags; |
| 311 | }; |
| 312 | |
| 313 | class Scale : public SkDrawCommand { |
| 314 | public: |
| 315 | Scale(SkScalar sx, SkScalar sy); |
| 316 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 317 | private: |
| 318 | SkScalar fSx; |
| 319 | SkScalar fSy; |
| 320 | }; |
| 321 | |
| 322 | class SetMatrix : public SkDrawCommand { |
| 323 | public: |
| 324 | SetMatrix(const SkMatrix& matrix); |
| 325 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 326 | private: |
| 327 | const SkMatrix* fMatrix; |
| 328 | }; |
| 329 | |
| 330 | class Skew : public SkDrawCommand { |
| 331 | public: |
| 332 | Skew(SkScalar sx, SkScalar sy); |
| 333 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 334 | private: |
| 335 | SkScalar fSx; |
| 336 | SkScalar fSy; |
| 337 | }; |
| 338 | |
| 339 | class Translate : public SkDrawCommand { |
| 340 | public: |
| 341 | Translate(SkScalar dx, SkScalar dy); |
| 342 | virtual void execute(SkCanvas* canvas) SK_OVERRIDE; |
| 343 | private: |
| 344 | SkScalar fDx; |
| 345 | SkScalar fDy; |
| 346 | }; |
| 347 | |
| 348 | #endif |