aboutsummaryrefslogtreecommitdiffhomepage
path: root/debugger/SkDrawCommand.cpp
blob: 74c92588d09458d42e132931717bbe87397188b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489

/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#include "SkDrawCommand.h"
#include "SkObjectParser.h"

// TODO(chudy): Refactor into non subclass model.

SkDrawCommand::SkDrawCommand() {
    fVisible = true;
}

SkDrawCommand::~SkDrawCommand() {
    fInfo.deleteAll();
}

const char* SkDrawCommand::GetCommandString(DrawType type) {
    switch (type) {
        case UNUSED: SkDEBUGFAIL("DrawType UNUSED\n"); break;
        case DRAW_CLEAR: return "Clear";
        case CLIP_PATH: return "Clip Path";
        case CLIP_REGION: return "Clip Region";
        case CLIP_RECT: return "Clip Rect";
        case CONCAT: return "Concat";
        case DRAW_BITMAP: return "Draw Bitmap";
        case DRAW_BITMAP_MATRIX: return "Draw Bitmap Matrix";
        case DRAW_BITMAP_NINE: return "Draw Bitmap Nine";
        case DRAW_BITMAP_RECT_TO_RECT: return "Draw Bitmap Rect";
        case DRAW_DATA: return "Draw Data";
        case DRAW_PAINT: return "Draw Paint";
        case DRAW_PATH: return "Draw Path";
        case DRAW_PICTURE: return "Draw Picture";
        case DRAW_POINTS: return "Draw Points";
        case DRAW_POS_TEXT: return "Draw Pos Text";
        case DRAW_POS_TEXT_H: return "Draw Pos Text H";
        case DRAW_RECT: return "Draw Rect";
        case DRAW_SPRITE: return "Draw Sprite";
        case DRAW_TEXT: return "Draw Text";
        case DRAW_TEXT_ON_PATH: return "Draw Text On Path";
        case DRAW_VERTICES: return "Draw Vertices";
        case RESTORE: return "Restore";
        case ROTATE: return "Rotate";
        case SAVE: return "Save";
        case SAVE_LAYER: return "Save Layer";
        case SCALE: return "Scale";
        case SET_MATRIX: return "Set Matrix";
        case SKEW: return "Skew";
        case TRANSLATE: return "Translate";
        default:
            SkDebugf("DrawType error 0x%08x\n", type);
            SkASSERT(0);
            break;
    }
    SkDEBUGFAIL("DrawType UNUSED\n");
    return NULL;
}

SkString SkDrawCommand::toString() {
    return SkString(GetCommandString(fDrawType));
}

Clear::Clear(SkColor color) {
    this->fColor = color;
    this->fDrawType = DRAW_CLEAR;
    this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
}

void Clear::execute(SkCanvas* canvas) {
    canvas->clear(this->fColor);
}

ClipPath::ClipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
    this->fPath = &path;
    this->fOp = op;
    this->fDoAA = doAA;
    this->fDrawType = CLIP_PATH;

    this->fInfo.push(SkObjectParser::PathToString(path));
    this->fInfo.push(SkObjectParser::RegionOpToString(op));
    this->fInfo.push(SkObjectParser::BoolToString(doAA));
}

void ClipPath::execute(SkCanvas* canvas) {
    canvas->clipPath(*this->fPath, this->fOp, this->fDoAA);
}

ClipRegion::ClipRegion(const SkRegion& region, SkRegion::Op op) {
    this->fRegion = &region;
    this->fOp = op;
    this->fDrawType = CLIP_REGION;

    this->fInfo.push(SkObjectParser::RegionToString(region));
    this->fInfo.push(SkObjectParser::RegionOpToString(op));
}

void ClipRegion::execute(SkCanvas* canvas) {
    canvas->clipRegion(*this->fRegion, this->fOp);
}

ClipRect::ClipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
    this->fRect = ▭
    this->fOp = op;
    this->fDoAA = doAA;
    this->fDrawType = CLIP_RECT;

    this->fInfo.push(SkObjectParser::RectToString(rect));
    this->fInfo.push(SkObjectParser::RegionOpToString(op));
    this->fInfo.push(SkObjectParser::BoolToString(doAA));
}

void ClipRect::execute(SkCanvas* canvas) {
    canvas->clipRect(*this->fRect, this->fOp, this->fDoAA);
}

Concat::Concat(const SkMatrix& matrix) {
    this->fMatrix = &matrix;
    this->fDrawType = CONCAT;

    this->fInfo.push(SkObjectParser::MatrixToString(matrix));
}

void Concat::execute(SkCanvas* canvas) {
    canvas->concat(*this->fMatrix);
}

DrawBitmap::DrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
        const SkPaint* paint) {
    this->fBitmap = &bitmap;
    this->fLeft = left;
    this->fTop = top;
    this->fPaint = paint;
    this->fDrawType = DRAW_BITMAP;

    this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
    this->fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
    this->fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
}

void DrawBitmap::execute(SkCanvas* canvas) {
    canvas->drawBitmap(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
}

DrawBitmapMatrix::DrawBitmapMatrix(const SkBitmap& bitmap,
        const SkMatrix& matrix, const SkPaint* paint) {
    this->fBitmap = &bitmap;
    this->fMatrix = &matrix;
    this->fPaint = paint;
    this->fDrawType = DRAW_BITMAP_MATRIX;

    this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
    this->fInfo.push(SkObjectParser::MatrixToString(matrix));
    if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
}

void DrawBitmapMatrix::execute(SkCanvas* canvas) {
    canvas->drawBitmapMatrix(*this->fBitmap, *this->fMatrix, this->fPaint);
}

DrawBitmapNine::DrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
        const SkRect& dst, const SkPaint* paint) {
    this->fBitmap = &bitmap;
    this->fCenter = &center;
    this->fDst = &dst;
    this->fPaint = paint;
    this->fDrawType = DRAW_BITMAP_NINE;

    this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
    this->fInfo.push(SkObjectParser::IRectToString(center));
    this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
    if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
}

void DrawBitmapNine::execute(SkCanvas* canvas) {
    canvas->drawBitmapNine(*this->fBitmap, *this->fCenter, *this->fDst, this->fPaint);
}

DrawBitmapRect::DrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
        const SkRect& dst, const SkPaint* paint) {
    this->fBitmap = &bitmap;
    this->fSrc = src;
    this->fDst = &dst;
    this->fPaint = paint;
    this->fDrawType = DRAW_BITMAP_RECT_TO_RECT;

    this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
    if (src) this->fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
    this->fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
    if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
}

void DrawBitmapRect::execute(SkCanvas* canvas) {
    canvas->drawBitmapRectToRect(*this->fBitmap, this->fSrc, *this->fDst, this->fPaint);
}

DrawData::DrawData(const void* data, size_t length) {
    this->fData = data;
    this->fLength = length;
    this->fDrawType = DRAW_DATA;
    // TODO(chudy): See if we can't display data and length.
}

void DrawData::execute(SkCanvas* canvas) {
    canvas->drawData(this->fData, this->fLength);
}

DrawPaint::DrawPaint(const SkPaint& paint) {
    this->fPaint = &paint;
    this->fDrawType = DRAW_PAINT;

    this->fInfo.push(SkObjectParser::PaintToString(paint));
}

void DrawPaint::execute(SkCanvas* canvas) {
    canvas->drawPaint(*this->fPaint);
}

DrawPath::DrawPath(const SkPath& path, const SkPaint& paint) {
    this->fPath = &path;
    this->fPaint = &paint;
    this->fDrawType = DRAW_PATH;

    this->fInfo.push(SkObjectParser::PathToString(path));
    this->fInfo.push(SkObjectParser::PaintToString(paint));
}

void DrawPath::execute(SkCanvas* canvas) {
    canvas->drawPath(*this->fPath, *this->fPaint);
}

DrawPicture::DrawPicture(SkPicture& picture) {
    this->fPicture = &picture;
    this->fDrawType = DRAW_PICTURE;
    this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
}

void DrawPicture::execute(SkCanvas* canvas) {
    canvas->drawPicture(*this->fPicture);
}

DrawPoints::DrawPoints(SkCanvas::PointMode mode, size_t count,
        const SkPoint pts[], const SkPaint& paint) {
    this->fMode = mode;
    this->fCount = count;
    this->fPts = pts;
    this->fPaint = &paint;
    this->fDrawType = DRAW_POINTS;

    this->fInfo.push(SkObjectParser::PointsToString(pts, count));
    this->fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar(count),
                                                    "Points: "));
    this->fInfo.push(SkObjectParser::PointModeToString(mode));
}

void DrawPoints::execute(SkCanvas* canvas) {
    canvas->drawPoints(this->fMode, this->fCount, this->fPts, *this->fPaint);
}

DrawPosText::DrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
        const SkPaint& paint) {
    this->fText = text;
    this->fByteLength = byteLength;
    this->fPos = pos;
    this->fPaint = &paint;
    this->fDrawType = DRAW_POS_TEXT;

    this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
    // TODO(chudy): Test that this works.
    this->fInfo.push(SkObjectParser::PointsToString(pos, 1));
    this->fInfo.push(SkObjectParser::PaintToString(paint));
}

void DrawPosText::execute(SkCanvas* canvas) {
    canvas->drawPosText(this->fText, this->fByteLength, this->fPos, *this->fPaint);
}


DrawPosTextH::DrawPosTextH(const void* text, size_t byteLength,
        const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
    this->fText = text;
    this->fByteLength = byteLength;
    this->fXpos = xpos;
    this->fConstY = constY;
    this->fPaint = &paint;
    this->fDrawType = DRAW_POS_TEXT_H;

    this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
    this->fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
    this->fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
    this->fInfo.push(SkObjectParser::PaintToString(paint));
}

void DrawPosTextH::execute(SkCanvas* canvas) {
    canvas->drawPosTextH(this->fText, this->fByteLength, this->fXpos, this->fConstY,
            *this->fPaint);
}

DrawRectC::DrawRectC(const SkRect& rect, const SkPaint& paint) {
    this->fRect = ▭
    this->fPaint = &paint;
    this->fDrawType = DRAW_RECT;

    this->fInfo.push(SkObjectParser::RectToString(rect));
    this->fInfo.push(SkObjectParser::PaintToString(paint));
}

void DrawRectC::execute(SkCanvas* canvas) {
    canvas->drawRect(*this->fRect, *this->fPaint);
}

DrawSprite::DrawSprite(const SkBitmap& bitmap, int left, int top,
        const SkPaint* paint) {
    this->fBitmap = &bitmap;
    this->fLeft = left;
    this->fTop = top;
    this->fPaint = paint;
    this->fDrawType = DRAW_SPRITE;

    this->fInfo.push(SkObjectParser::BitmapToString(bitmap));
    this->fInfo.push(SkObjectParser::IntToString(left, "Left: "));
    this->fInfo.push(SkObjectParser::IntToString(top, "Top: "));
}

void DrawSprite::execute(SkCanvas* canvas) {
    canvas->drawSprite(*this->fBitmap, this->fLeft, this->fTop, this->fPaint);
}

DrawTextC::DrawTextC(const void* text, size_t byteLength, SkScalar x, SkScalar y,
        const SkPaint& paint) {
    this->fText = text;
    this->fByteLength = byteLength;
    this->fX = x;
    this->fY = y;
    this->fPaint = &paint;
    this->fDrawType = DRAW_TEXT;

    this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
    this->fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
    this->fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
    this->fInfo.push(SkObjectParser::PaintToString(paint));
}

void DrawTextC::execute(SkCanvas* canvas) {
    canvas->drawText(this->fText, this->fByteLength, this->fX, this->fY, *this->fPaint);
}

DrawTextOnPath::DrawTextOnPath(const void* text, size_t byteLength,
        const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
    this->fText = text;
    this->fByteLength = byteLength;
    this->fPath = &path;
    this->fMatrix = matrix;
    this->fPaint = &paint;
    this->fDrawType = DRAW_TEXT_ON_PATH;

    this->fInfo.push(SkObjectParser::TextToString(text, byteLength));
    this->fInfo.push(SkObjectParser::PathToString(path));
    if (matrix) this->fInfo.push(SkObjectParser::MatrixToString(*matrix));
    this->fInfo.push(SkObjectParser::PaintToString(paint));
}

void DrawTextOnPath::execute(SkCanvas* canvas) {
    canvas->drawTextOnPath(this->fText, this->fByteLength, *this->fPath,
            this->fMatrix, *this->fPaint);
}

DrawVertices::DrawVertices(SkCanvas::VertexMode vmode, int vertexCount,
        const SkPoint vertices[], const SkPoint texs[], const SkColor colors[],
        SkXfermode* xfermode, const uint16_t indices[], int indexCount,
        const SkPaint& paint) {
    this->fVmode = vmode;
    this->fVertexCount = vertexCount;
    this->fTexs = texs;
    this->fColors = colors;
    this->fXfermode = xfermode;
    this->fIndices = indices;
    this->fIndexCount = indexCount;
    this->fPaint = &paint;
    this->fDrawType = DRAW_VERTICES;
    // TODO(chudy)
    this->fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
}

void DrawVertices::execute(SkCanvas* canvas) {
    canvas->drawVertices(this->fVmode, this->fVertexCount, this->fVertices,
            this->fTexs, this->fColors, this->fXfermode, this->fIndices,
            this->fIndexCount, *this->fPaint);
}

Restore::Restore() {
    this->fDrawType = RESTORE;
    this->fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
}

void Restore::execute(SkCanvas* canvas) {
    canvas->restore();
}

Rotate::Rotate(SkScalar degrees) {
    this->fDegrees = degrees;
    this->fDrawType = ROTATE;

    this->fInfo.push(SkObjectParser::ScalarToString(degrees, "SkScalar degrees: "));
}

void Rotate::execute(SkCanvas* canvas) {
    canvas->rotate(this->fDegrees);
}

Save::Save(SkCanvas::SaveFlags flags) {
    this->fFlags = flags;
    this->fDrawType = SAVE;
    this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
}

void Save::execute(SkCanvas* canvas) {
    canvas->save(this->fFlags);
}

SaveLayer::SaveLayer(const SkRect* bounds, const SkPaint* paint,
        SkCanvas::SaveFlags flags) {
    this->fBounds = bounds;
    this->fPaint = paint;
    this->fFlags = flags;
    this->fDrawType = SAVE_LAYER;

    if (bounds) this->fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: "));
    if (paint) this->fInfo.push(SkObjectParser::PaintToString(*paint));
    this->fInfo.push(SkObjectParser::SaveFlagsToString(flags));
}

void SaveLayer::execute(SkCanvas* canvas) {
    canvas->saveLayer(this->fBounds, this->fPaint, this->fFlags);
}

Scale::Scale(SkScalar sx, SkScalar sy) {
    this->fSx = sx;
    this->fSy = sy;
    this->fDrawType = SCALE;

    this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
    this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
}

void Scale::execute(SkCanvas* canvas) {
    canvas->scale(this->fSx, this->fSy);
}

SetMatrix::SetMatrix(const SkMatrix& matrix) {
    this->fMatrix = &matrix;
    this->fDrawType = SET_MATRIX;

    this->fInfo.push(SkObjectParser::MatrixToString(matrix));
}

void SetMatrix::execute(SkCanvas* canvas) {
    canvas->setMatrix(*this->fMatrix);
}

Skew::Skew(SkScalar sx, SkScalar sy) {
    this->fSx = sx;
    this->fSy = sy;
    this->fDrawType = SKEW;

    this->fInfo.push(SkObjectParser::ScalarToString(sx, "SkScalar sx: "));
    this->fInfo.push(SkObjectParser::ScalarToString(sy, "SkScalar sy: "));
}

void Skew::execute(SkCanvas* canvas) {
    canvas->skew(this->fSx, this->fSy);
}

Translate::Translate(SkScalar dx, SkScalar dy) {
    this->fDx = dx;
    this->fDy = dy;
    this->fDrawType = TRANSLATE;

    this->fInfo.push(SkObjectParser::ScalarToString(dx, "SkScalar dx: "));
    this->fInfo.push(SkObjectParser::ScalarToString(dy, "SkScalar dy: "));
}

void Translate::execute(SkCanvas* canvas) {
    canvas->translate(this->fDx, this->fDy);
}