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