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 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 10 | #include "SkDrawCommand.h" |
| 11 | #include "SkObjectParser.h" |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 12 | #include "SkPicture.h" |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 13 | #include "SkTextBlob.h" |
| 14 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 15 | // TODO(chudy): Refactor into non subclass model. |
| 16 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 17 | SkDrawCommand::SkDrawCommand(OpType type) |
| 18 | : fOpType(type) |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 19 | , fVisible(true) { |
| 20 | } |
| 21 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 22 | SkDrawCommand::~SkDrawCommand() { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 23 | fInfo.deleteAll(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 24 | } |
| 25 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 26 | const char* SkDrawCommand::GetCommandString(OpType type) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 27 | switch (type) { |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 28 | case kBeginDrawPicture_OpType: return "BeginDrawPicture"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 29 | case kClipPath_OpType: return "ClipPath"; |
| 30 | case kClipRegion_OpType: return "ClipRegion"; |
| 31 | case kClipRect_OpType: return "ClipRect"; |
| 32 | case kClipRRect_OpType: return "ClipRRect"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 33 | case kConcat_OpType: return "Concat"; |
| 34 | case kDrawBitmap_OpType: return "DrawBitmap"; |
| 35 | case kDrawBitmapNine_OpType: return "DrawBitmapNine"; |
| 36 | case kDrawBitmapRect_OpType: return "DrawBitmapRect"; |
| 37 | case kDrawClear_OpType: return "DrawClear"; |
| 38 | case kDrawDRRect_OpType: return "DrawDRRect"; |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame^] | 39 | case kDrawImage_OpType: return "DrawImage"; |
| 40 | case kDrawImageRect_OpType: return "DrawImageRect"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 41 | case kDrawOval_OpType: return "DrawOval"; |
| 42 | case kDrawPaint_OpType: return "DrawPaint"; |
| 43 | case kDrawPatch_OpType: return "DrawPatch"; |
| 44 | case kDrawPath_OpType: return "DrawPath"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 45 | case kDrawPoints_OpType: return "DrawPoints"; |
| 46 | case kDrawPosText_OpType: return "DrawPosText"; |
| 47 | case kDrawPosTextH_OpType: return "DrawPosTextH"; |
| 48 | case kDrawRect_OpType: return "DrawRect"; |
| 49 | case kDrawRRect_OpType: return "DrawRRect"; |
| 50 | case kDrawSprite_OpType: return "DrawSprite"; |
| 51 | case kDrawText_OpType: return "DrawText"; |
| 52 | case kDrawTextBlob_OpType: return "DrawTextBlob"; |
| 53 | case kDrawTextOnPath_OpType: return "DrawTextOnPath"; |
| 54 | case kDrawVertices_OpType: return "DrawVertices"; |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 55 | case kEndDrawPicture_OpType: return "EndDrawPicture"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 56 | case kRestore_OpType: return "Restore"; |
| 57 | case kSave_OpType: return "Save"; |
| 58 | case kSaveLayer_OpType: return "SaveLayer"; |
| 59 | case kSetMatrix_OpType: return "SetMatrix"; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 60 | default: |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 61 | SkDebugf("OpType error 0x%08x\n", type); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 62 | SkASSERT(0); |
| 63 | break; |
| 64 | } |
| 65 | SkDEBUGFAIL("DrawType UNUSED\n"); |
| 66 | return NULL; |
| 67 | } |
| 68 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 69 | SkString SkDrawCommand::toString() const { |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 70 | return SkString(GetCommandString(fOpType)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 71 | } |
| 72 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 73 | SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 74 | fColor = color; |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 75 | fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 76 | } |
| 77 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 78 | void SkClearCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 79 | canvas->clear(fColor); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 80 | } |
| 81 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 82 | namespace { |
| 83 | |
| 84 | void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) { |
| 85 | const SkISize& size = canvas->getDeviceSize(); |
| 86 | |
| 87 | static const SkScalar kInsetFrac = 0.9f; // Leave a border around object |
| 88 | |
| 89 | canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f); |
| 90 | if (bounds.width() > bounds.height()) { |
| 91 | canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()), |
| 92 | SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width())); |
| 93 | } else { |
| 94 | canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()), |
| 95 | SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height())); |
| 96 | } |
| 97 | canvas->translate(-bounds.centerX(), -bounds.centerY()); |
| 98 | } |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 99 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 100 | |
| 101 | void render_path(SkCanvas* canvas, const SkPath& path) { |
| 102 | canvas->clear(0xFFFFFFFF); |
| 103 | canvas->save(); |
| 104 | |
| 105 | const SkRect& bounds = path.getBounds(); |
| 106 | |
| 107 | xlate_and_scale_to_bounds(canvas, bounds); |
| 108 | |
| 109 | SkPaint p; |
| 110 | p.setColor(SK_ColorBLACK); |
| 111 | p.setStyle(SkPaint::kStroke_Style); |
| 112 | |
| 113 | canvas->drawPath(path, p); |
| 114 | canvas->restore(); |
| 115 | } |
| 116 | |
| 117 | void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = NULL) { |
| 118 | const SkISize& size = canvas->getDeviceSize(); |
| 119 | |
| 120 | SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width(); |
| 121 | SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height(); |
| 122 | |
| 123 | if (input.width() > input.height()) { |
| 124 | yScale *= input.height() / (float) input.width(); |
| 125 | } else { |
| 126 | xScale *= input.width() / (float) input.height(); |
| 127 | } |
| 128 | |
| 129 | SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1, |
| 130 | xScale * input.width(), |
| 131 | yScale * input.height()); |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 132 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 133 | canvas->clear(0xFFFFFFFF); |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 134 | canvas->drawBitmapRect(input, dst); |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 135 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 136 | if (srcRect) { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 137 | SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1, |
| 138 | srcRect->fTop * yScale + SK_Scalar1, |
| 139 | srcRect->fRight * xScale + SK_Scalar1, |
| 140 | srcRect->fBottom * yScale + SK_Scalar1); |
| 141 | SkPaint p; |
| 142 | p.setColor(SK_ColorRED); |
| 143 | p.setStyle(SkPaint::kStroke_Style); |
| 144 | |
| 145 | canvas->drawRect(r, p); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | void render_rrect(SkCanvas* canvas, const SkRRect& rrect) { |
| 150 | canvas->clear(0xFFFFFFFF); |
| 151 | canvas->save(); |
| 152 | |
| 153 | const SkRect& bounds = rrect.getBounds(); |
| 154 | |
| 155 | xlate_and_scale_to_bounds(canvas, bounds); |
| 156 | |
| 157 | SkPaint p; |
| 158 | p.setColor(SK_ColorBLACK); |
| 159 | p.setStyle(SkPaint::kStroke_Style); |
| 160 | |
| 161 | canvas->drawRRect(rrect, p); |
| 162 | canvas->restore(); |
| 163 | } |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 164 | |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 165 | void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) { |
| 166 | canvas->clear(0xFFFFFFFF); |
| 167 | canvas->save(); |
| 168 | |
| 169 | const SkRect& bounds = outer.getBounds(); |
| 170 | |
| 171 | xlate_and_scale_to_bounds(canvas, bounds); |
| 172 | |
| 173 | SkPaint p; |
| 174 | p.setColor(SK_ColorBLACK); |
| 175 | p.setStyle(SkPaint::kStroke_Style); |
| 176 | |
| 177 | canvas->drawDRRect(outer, inner, p); |
| 178 | canvas->restore(); |
| 179 | } |
| 180 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 184 | SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 185 | : INHERITED(kClipPath_OpType) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 186 | fPath = path; |
| 187 | fOp = op; |
| 188 | fDoAA = doAA; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 189 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 190 | fInfo.push(SkObjectParser::PathToString(path)); |
| 191 | fInfo.push(SkObjectParser::RegionOpToString(op)); |
| 192 | fInfo.push(SkObjectParser::BoolToString(doAA)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 193 | } |
| 194 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 195 | void SkClipPathCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 196 | canvas->clipPath(fPath, fOp, fDoAA); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 197 | } |
| 198 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 199 | bool SkClipPathCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 200 | render_path(canvas, fPath); |
| 201 | return true; |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 202 | } |
| 203 | |
skia.committer@gmail.com | db35dab | 2014-03-27 03:02:48 +0000 | [diff] [blame] | 204 | SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 205 | : INHERITED(kClipRegion_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 206 | fRegion = region; |
| 207 | fOp = op; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 208 | |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 209 | fInfo.push(SkObjectParser::RegionToString(region)); |
| 210 | fInfo.push(SkObjectParser::RegionOpToString(op)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 211 | } |
| 212 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 213 | void SkClipRegionCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 214 | canvas->clipRegion(fRegion, fOp); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 215 | } |
| 216 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 217 | SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 218 | : INHERITED(kClipRect_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 219 | fRect = rect; |
| 220 | fOp = op; |
| 221 | fDoAA = doAA; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 222 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 223 | fInfo.push(SkObjectParser::RectToString(rect)); |
| 224 | fInfo.push(SkObjectParser::RegionOpToString(op)); |
| 225 | fInfo.push(SkObjectParser::BoolToString(doAA)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 226 | } |
| 227 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 228 | void SkClipRectCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 229 | canvas->clipRect(fRect, fOp, fDoAA); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 230 | } |
| 231 | |
skia.committer@gmail.com | db35dab | 2014-03-27 03:02:48 +0000 | [diff] [blame] | 232 | SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 233 | : INHERITED(kClipRRect_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 234 | fRRect = rrect; |
| 235 | fOp = op; |
| 236 | fDoAA = doAA; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 237 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 238 | fInfo.push(SkObjectParser::RRectToString(rrect)); |
| 239 | fInfo.push(SkObjectParser::RegionOpToString(op)); |
| 240 | fInfo.push(SkObjectParser::BoolToString(doAA)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 241 | } |
| 242 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 243 | void SkClipRRectCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 244 | canvas->clipRRect(fRRect, fOp, fDoAA); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 245 | } |
| 246 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 247 | bool SkClipRRectCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 248 | render_rrect(canvas, fRRect); |
| 249 | return true; |
| 250 | } |
| 251 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 252 | SkConcatCommand::SkConcatCommand(const SkMatrix& matrix) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 253 | : INHERITED(kConcat_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 254 | fMatrix = matrix; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 255 | |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 256 | fInfo.push(SkObjectParser::MatrixToString(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 257 | } |
| 258 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 259 | void SkConcatCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 260 | canvas->concat(fMatrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 261 | } |
| 262 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 263 | SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 264 | const SkPaint* paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 265 | : INHERITED(kDrawBitmap_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 266 | fBitmap = bitmap; |
| 267 | fLeft = left; |
| 268 | fTop = top; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 269 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 270 | fPaint = *paint; |
| 271 | fPaintPtr = &fPaint; |
| 272 | } else { |
| 273 | fPaintPtr = NULL; |
| 274 | } |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 275 | |
| 276 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 277 | fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: ")); |
| 278 | fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: ")); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 279 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 280 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 281 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 282 | } |
| 283 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 284 | void SkDrawBitmapCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 285 | canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 286 | } |
| 287 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 288 | bool SkDrawBitmapCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 289 | render_bitmap(canvas, fBitmap); |
| 290 | return true; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 291 | } |
| 292 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 293 | SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center, |
skia.committer@gmail.com | db35dab | 2014-03-27 03:02:48 +0000 | [diff] [blame] | 294 | const SkRect& dst, const SkPaint* paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 295 | : INHERITED(kDrawBitmapNine_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 296 | fBitmap = bitmap; |
| 297 | fCenter = center; |
| 298 | fDst = dst; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 299 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 300 | fPaint = *paint; |
| 301 | fPaintPtr = &fPaint; |
| 302 | } else { |
| 303 | fPaintPtr = NULL; |
| 304 | } |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 305 | |
| 306 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 307 | fInfo.push(SkObjectParser::IRectToString(center)); |
| 308 | fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 309 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 310 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 311 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 312 | } |
| 313 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 314 | void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 315 | canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 316 | } |
| 317 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 318 | bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 319 | render_bitmap(canvas, fBitmap); |
| 320 | return true; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 321 | } |
| 322 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 323 | SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 324 | const SkRect& dst, const SkPaint* paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 325 | SkCanvas::SrcRectConstraint constraint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 326 | : INHERITED(kDrawBitmapRect_OpType) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 327 | fBitmap = bitmap; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 328 | if (src) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 329 | fSrc = *src; |
| 330 | } else { |
| 331 | fSrc.setEmpty(); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 332 | } |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 333 | fDst = dst; |
| 334 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 335 | if (paint) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 336 | fPaint = *paint; |
| 337 | fPaintPtr = &fPaint; |
| 338 | } else { |
| 339 | fPaintPtr = NULL; |
| 340 | } |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 341 | fConstraint = constraint; |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 342 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 343 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 344 | if (src) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 345 | fInfo.push(SkObjectParser::RectToString(*src, "Src: ")); |
| 346 | } |
| 347 | fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 348 | if (paint) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 349 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 350 | } |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 351 | fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 352 | } |
| 353 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 354 | void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const { |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 355 | canvas->drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 356 | } |
| 357 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 358 | bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 359 | render_bitmap(canvas, fBitmap, this->srcRect()); |
| 360 | return true; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 361 | } |
| 362 | |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame^] | 363 | SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top, |
| 364 | const SkPaint* paint) |
| 365 | : INHERITED(kDrawImage_OpType) |
| 366 | , fImage(SkRef(image)) |
| 367 | , fLeft(left) |
| 368 | , fTop(top) { |
| 369 | |
| 370 | if (paint) { |
| 371 | fPaint.set(*paint); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | void SkDrawImageCommand::execute(SkCanvas* canvas) const { |
| 376 | canvas->drawImage(fImage, fLeft, fTop, fPaint.getMaybeNull()); |
| 377 | } |
| 378 | |
| 379 | bool SkDrawImageCommand::render(SkCanvas* canvas) const { |
| 380 | SkAutoCanvasRestore acr(canvas, true); |
| 381 | canvas->clear(0xFFFFFFFF); |
| 382 | |
| 383 | xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop, |
| 384 | SkIntToScalar(fImage->width()), |
| 385 | SkIntToScalar(fImage->height()))); |
| 386 | this->execute(canvas); |
| 387 | return true; |
| 388 | } |
| 389 | |
| 390 | SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRect* src, |
| 391 | const SkRect& dst, const SkPaint* paint, |
| 392 | SkCanvas::SrcRectConstraint constraint) |
| 393 | : INHERITED(kDrawImageRect_OpType) |
| 394 | , fImage(SkRef(image)) |
| 395 | , fDst(dst) |
| 396 | , fConstraint(constraint) { |
| 397 | |
| 398 | if (src) { |
| 399 | fSrc.set(*src); |
| 400 | } |
| 401 | |
| 402 | if (paint) { |
| 403 | fPaint.set(*paint); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | void SkDrawImageRectCommand::execute(SkCanvas* canvas) const { |
| 408 | canvas->drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(), fConstraint); |
| 409 | } |
| 410 | |
| 411 | bool SkDrawImageRectCommand::render(SkCanvas* canvas) const { |
| 412 | SkAutoCanvasRestore acr(canvas, true); |
| 413 | canvas->clear(0xFFFFFFFF); |
| 414 | |
| 415 | xlate_and_scale_to_bounds(canvas, fDst); |
| 416 | |
| 417 | this->execute(canvas); |
| 418 | return true; |
| 419 | } |
| 420 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 421 | SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 422 | : INHERITED(kDrawOval_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 423 | fOval = oval; |
| 424 | fPaint = paint; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 425 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 426 | fInfo.push(SkObjectParser::RectToString(oval)); |
| 427 | fInfo.push(SkObjectParser::PaintToString(paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 428 | } |
| 429 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 430 | void SkDrawOvalCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 431 | canvas->drawOval(fOval, fPaint); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 432 | } |
| 433 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 434 | bool SkDrawOvalCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 435 | canvas->clear(0xFFFFFFFF); |
| 436 | canvas->save(); |
| 437 | |
| 438 | xlate_and_scale_to_bounds(canvas, fOval); |
| 439 | |
| 440 | SkPaint p; |
| 441 | p.setColor(SK_ColorBLACK); |
| 442 | p.setStyle(SkPaint::kStroke_Style); |
| 443 | |
| 444 | canvas->drawOval(fOval, p); |
| 445 | canvas->restore(); |
| 446 | |
| 447 | return true; |
| 448 | } |
| 449 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 450 | SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 451 | : INHERITED(kDrawPaint_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 452 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 453 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 454 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 455 | } |
| 456 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 457 | void SkDrawPaintCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 458 | canvas->drawPaint(fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 459 | } |
| 460 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 461 | bool SkDrawPaintCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 462 | canvas->clear(0xFFFFFFFF); |
| 463 | canvas->drawPaint(fPaint); |
| 464 | return true; |
| 465 | } |
| 466 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 467 | SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 468 | : INHERITED(kDrawPath_OpType) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 469 | fPath = path; |
| 470 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 471 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 472 | fInfo.push(SkObjectParser::PathToString(path)); |
| 473 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 474 | } |
| 475 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 476 | void SkDrawPathCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 477 | canvas->drawPath(fPath, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 478 | } |
| 479 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 480 | bool SkDrawPathCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 481 | render_path(canvas, fPath); |
| 482 | return true; |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 483 | } |
| 484 | |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 485 | SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture, |
| 486 | const SkMatrix* matrix, |
| 487 | const SkPaint* paint) |
| 488 | : INHERITED(kBeginDrawPicture_OpType) |
| 489 | , fPicture(SkRef(picture)) { |
| 490 | |
| 491 | SkString* str = new SkString; |
| 492 | str->appendf("SkPicture: L: %f T: %f R: %f B: %f", |
| 493 | picture->cullRect().fLeft, picture->cullRect().fTop, |
| 494 | picture->cullRect().fRight, picture->cullRect().fBottom); |
| 495 | fInfo.push(str); |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 496 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 497 | if (matrix) { |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 498 | fMatrix.set(*matrix); |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 499 | fInfo.push(SkObjectParser::MatrixToString(*matrix)); |
| 500 | } |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 501 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 502 | if (paint) { |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 503 | fPaint.set(*paint); |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 504 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 505 | } |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 506 | |
| 507 | } |
| 508 | |
| 509 | void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const { |
| 510 | if (fPaint.isValid()) { |
| 511 | SkRect bounds = fPicture->cullRect(); |
| 512 | if (fMatrix.isValid()) { |
| 513 | fMatrix.get()->mapRect(&bounds); |
| 514 | } |
| 515 | canvas->saveLayer(&bounds, fPaint.get()); |
| 516 | } |
| 517 | |
| 518 | if (fMatrix.isValid()) { |
| 519 | if (!fPaint.isValid()) { |
| 520 | canvas->save(); |
| 521 | } |
| 522 | canvas->concat(*fMatrix.get()); |
| 523 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 524 | } |
| 525 | |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 526 | bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const { |
commit-bot@chromium.org | e898e9c | 2013-11-21 17:08:12 +0000 | [diff] [blame] | 527 | canvas->clear(0xFFFFFFFF); |
| 528 | canvas->save(); |
| 529 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 530 | xlate_and_scale_to_bounds(canvas, fPicture->cullRect()); |
commit-bot@chromium.org | e898e9c | 2013-11-21 17:08:12 +0000 | [diff] [blame] | 531 | |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 532 | canvas->drawPicture(fPicture.get()); |
commit-bot@chromium.org | e898e9c | 2013-11-21 17:08:12 +0000 | [diff] [blame] | 533 | |
| 534 | canvas->restore(); |
| 535 | |
| 536 | return true; |
| 537 | } |
| 538 | |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 539 | SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore) |
| 540 | : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { } |
| 541 | |
| 542 | void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const { |
| 543 | if (fRestore) { |
| 544 | canvas->restore(); |
| 545 | } |
| 546 | } |
| 547 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 548 | SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 549 | const SkPoint pts[], const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 550 | : INHERITED(kDrawPoints_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 551 | fMode = mode; |
| 552 | fCount = count; |
| 553 | fPts = new SkPoint[count]; |
| 554 | memcpy(fPts, pts, count * sizeof(SkPoint)); |
| 555 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 556 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 557 | fInfo.push(SkObjectParser::PointsToString(pts, count)); |
| 558 | fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count), |
| 559 | "Points: ")); |
| 560 | fInfo.push(SkObjectParser::PointModeToString(mode)); |
| 561 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 562 | } |
| 563 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 564 | void SkDrawPointsCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 565 | canvas->drawPoints(fMode, fCount, fPts, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 566 | } |
| 567 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 568 | bool SkDrawPointsCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 569 | canvas->clear(0xFFFFFFFF); |
| 570 | canvas->save(); |
| 571 | |
| 572 | SkRect bounds; |
| 573 | |
| 574 | bounds.setEmpty(); |
| 575 | for (unsigned int i = 0; i < fCount; ++i) { |
| 576 | bounds.growToInclude(fPts[i].fX, fPts[i].fY); |
| 577 | } |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 578 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 579 | xlate_and_scale_to_bounds(canvas, bounds); |
| 580 | |
| 581 | SkPaint p; |
| 582 | p.setColor(SK_ColorBLACK); |
| 583 | p.setStyle(SkPaint::kStroke_Style); |
| 584 | |
| 585 | canvas->drawPoints(fMode, fCount, fPts, p); |
| 586 | canvas->restore(); |
| 587 | |
| 588 | return true; |
| 589 | } |
| 590 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 591 | SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 592 | const SkPoint pos[], const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 593 | : INHERITED(kDrawPosText_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 594 | size_t numPts = paint.countText(text, byteLength); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 595 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 596 | fText = new char[byteLength]; |
| 597 | memcpy(fText, text, byteLength); |
| 598 | fByteLength = byteLength; |
| 599 | |
| 600 | fPos = new SkPoint[numPts]; |
| 601 | memcpy(fPos, pos, numPts * sizeof(SkPoint)); |
| 602 | |
| 603 | fPaint = paint; |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 604 | |
| 605 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 606 | // TODO(chudy): Test that this works. |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 607 | fInfo.push(SkObjectParser::PointsToString(pos, 1)); |
| 608 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 609 | } |
| 610 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 611 | void SkDrawPosTextCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 612 | canvas->drawPosText(fText, fByteLength, fPos, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 616 | SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength, |
| 617 | const SkScalar xpos[], SkScalar constY, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 618 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 619 | : INHERITED(kDrawPosTextH_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 620 | size_t numPts = paint.countText(text, byteLength); |
| 621 | |
| 622 | fText = new char[byteLength]; |
| 623 | memcpy(fText, text, byteLength); |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 624 | fByteLength = byteLength; |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 625 | |
| 626 | fXpos = new SkScalar[numPts]; |
| 627 | memcpy(fXpos, xpos, numPts * sizeof(SkScalar)); |
| 628 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 629 | fConstY = constY; |
| 630 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 631 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 632 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 633 | fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: ")); |
| 634 | fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: ")); |
| 635 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 636 | } |
| 637 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 638 | void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 639 | canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 640 | } |
| 641 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 642 | SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 643 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 644 | : INHERITED(kDrawTextBlob_OpType) |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 645 | , fBlob(blob) |
| 646 | , fXPos(x) |
| 647 | , fYPos(y) |
| 648 | , fPaint(paint) { |
| 649 | |
| 650 | blob->ref(); |
| 651 | |
| 652 | // FIXME: push blob info |
| 653 | fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: ")); |
fmalita | ff3106c | 2014-12-09 05:28:20 -0800 | [diff] [blame] | 654 | fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: ")); |
| 655 | fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: ")); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 656 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 657 | } |
| 658 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 659 | void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const { |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 660 | canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint); |
| 661 | } |
| 662 | |
fmalita | 5577387 | 2014-08-29 15:08:20 -0700 | [diff] [blame] | 663 | bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const { |
| 664 | canvas->clear(SK_ColorWHITE); |
| 665 | canvas->save(); |
| 666 | |
| 667 | SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos); |
| 668 | xlate_and_scale_to_bounds(canvas, bounds); |
| 669 | |
| 670 | canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint); |
| 671 | |
| 672 | canvas->restore(); |
| 673 | |
| 674 | return true; |
| 675 | } |
| 676 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 677 | SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4], |
| 678 | const SkPoint texCoords[4], SkXfermode* xfermode, |
| 679 | const SkPaint& paint) |
| 680 | : INHERITED(kDrawPatch_OpType) { |
| 681 | memcpy(fCubics, cubics, sizeof(fCubics)); |
| 682 | memcpy(fColors, colors, sizeof(fColors)); |
| 683 | memcpy(fTexCoords, texCoords, sizeof(fTexCoords)); |
| 684 | fXfermode.reset(xfermode); |
| 685 | fPaint = paint; |
| 686 | |
| 687 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 688 | } |
| 689 | |
| 690 | void SkDrawPatchCommand::execute(SkCanvas* canvas) const { |
| 691 | canvas->drawPatch(fCubics, fColors, fTexCoords, fXfermode, fPaint); |
| 692 | } |
| 693 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 694 | SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 695 | : INHERITED(kDrawRect_OpType) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 696 | fRect = rect; |
| 697 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 698 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 699 | fInfo.push(SkObjectParser::RectToString(rect)); |
| 700 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 701 | } |
| 702 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 703 | void SkDrawRectCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 704 | canvas->drawRect(fRect, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 705 | } |
| 706 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 707 | SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 708 | : INHERITED(kDrawRRect_OpType) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 709 | fRRect = rrect; |
| 710 | fPaint = paint; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 711 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 712 | fInfo.push(SkObjectParser::RRectToString(rrect)); |
| 713 | fInfo.push(SkObjectParser::PaintToString(paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 714 | } |
| 715 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 716 | void SkDrawRRectCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 717 | canvas->drawRRect(fRRect, fPaint); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 718 | } |
| 719 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 720 | bool SkDrawRRectCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 721 | render_rrect(canvas, fRRect); |
| 722 | return true; |
| 723 | } |
| 724 | |
skia.committer@gmail.com | 90667ba | 2014-02-25 03:05:18 +0000 | [diff] [blame] | 725 | SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer, |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 726 | const SkRRect& inner, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 727 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 728 | : INHERITED(kDrawDRRect_OpType) { |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 729 | fOuter = outer; |
| 730 | fInner = inner; |
| 731 | fPaint = paint; |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 732 | |
| 733 | fInfo.push(SkObjectParser::RRectToString(outer)); |
| 734 | fInfo.push(SkObjectParser::RRectToString(inner)); |
| 735 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 736 | } |
| 737 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 738 | void SkDrawDRRectCommand::execute(SkCanvas* canvas) const { |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 739 | canvas->drawDRRect(fOuter, fInner, fPaint); |
| 740 | } |
| 741 | |
| 742 | bool SkDrawDRRectCommand::render(SkCanvas* canvas) const { |
| 743 | render_drrect(canvas, fOuter, fInner); |
| 744 | return true; |
| 745 | } |
| 746 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 747 | SkDrawSpriteCommand::SkDrawSpriteCommand(const SkBitmap& bitmap, int left, int top, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 748 | const SkPaint* paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 749 | : INHERITED(kDrawSprite_OpType) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 750 | fBitmap = bitmap; |
| 751 | fLeft = left; |
| 752 | fTop = top; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 753 | if (paint) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 754 | fPaint = *paint; |
| 755 | fPaintPtr = &fPaint; |
| 756 | } else { |
| 757 | fPaintPtr = NULL; |
| 758 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 759 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 760 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 761 | fInfo.push(SkObjectParser::IntToString(left, "Left: ")); |
| 762 | fInfo.push(SkObjectParser::IntToString(top, "Top: ")); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 763 | if (paint) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 764 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 765 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 766 | } |
| 767 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 768 | void SkDrawSpriteCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 769 | canvas->drawSprite(fBitmap, fLeft, fTop, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 770 | } |
| 771 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 772 | bool SkDrawSpriteCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 773 | render_bitmap(canvas, fBitmap); |
| 774 | return true; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 775 | } |
| 776 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 777 | SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 778 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 779 | : INHERITED(kDrawText_OpType) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 780 | fText = new char[byteLength]; |
| 781 | memcpy(fText, text, byteLength); |
| 782 | fByteLength = byteLength; |
| 783 | fX = x; |
| 784 | fY = y; |
| 785 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 786 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 787 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 788 | fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); |
| 789 | fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); |
| 790 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 791 | } |
| 792 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 793 | void SkDrawTextCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 794 | canvas->drawText(fText, fByteLength, fX, fY, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 795 | } |
| 796 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 797 | SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength, |
| 798 | const SkPath& path, const SkMatrix* matrix, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 799 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 800 | : INHERITED(kDrawTextOnPath_OpType) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 801 | fText = new char[byteLength]; |
| 802 | memcpy(fText, text, byteLength); |
| 803 | fByteLength = byteLength; |
| 804 | fPath = path; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 805 | if (matrix) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 806 | fMatrix = *matrix; |
| 807 | } else { |
| 808 | fMatrix.setIdentity(); |
| 809 | } |
| 810 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 811 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 812 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 813 | fInfo.push(SkObjectParser::PathToString(path)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 814 | if (matrix) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 815 | fInfo.push(SkObjectParser::MatrixToString(*matrix)); |
| 816 | } |
| 817 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 818 | } |
| 819 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 820 | void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 821 | canvas->drawTextOnPath(fText, fByteLength, fPath, |
| 822 | fMatrix.isIdentity() ? NULL : &fMatrix, |
| 823 | fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 824 | } |
| 825 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 826 | SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount, |
| 827 | const SkPoint vertices[], const SkPoint texs[], |
| 828 | const SkColor colors[], SkXfermode* xfermode, |
| 829 | const uint16_t indices[], int indexCount, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 830 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 831 | : INHERITED(kDrawVertices_OpType) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 832 | fVmode = vmode; |
| 833 | |
| 834 | fVertexCount = vertexCount; |
| 835 | |
| 836 | fVertices = new SkPoint[vertexCount]; |
| 837 | memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint)); |
| 838 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 839 | if (texs) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 840 | fTexs = new SkPoint[vertexCount]; |
| 841 | memcpy(fTexs, texs, vertexCount * sizeof(SkPoint)); |
| 842 | } else { |
| 843 | fTexs = NULL; |
| 844 | } |
| 845 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 846 | if (colors) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 847 | fColors = new SkColor[vertexCount]; |
| 848 | memcpy(fColors, colors, vertexCount * sizeof(SkColor)); |
| 849 | } else { |
| 850 | fColors = NULL; |
| 851 | } |
| 852 | |
| 853 | fXfermode = xfermode; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 854 | if (fXfermode) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 855 | fXfermode->ref(); |
| 856 | } |
| 857 | |
| 858 | if (indexCount > 0) { |
| 859 | fIndices = new uint16_t[indexCount]; |
| 860 | memcpy(fIndices, indices, indexCount * sizeof(uint16_t)); |
| 861 | } else { |
| 862 | fIndices = NULL; |
| 863 | } |
| 864 | |
| 865 | fIndexCount = indexCount; |
| 866 | fPaint = paint; |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 867 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 868 | // TODO(chudy) |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 869 | fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); |
| 870 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 871 | } |
| 872 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 873 | SkDrawVerticesCommand::~SkDrawVerticesCommand() { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 874 | delete [] fVertices; |
| 875 | delete [] fTexs; |
| 876 | delete [] fColors; |
| 877 | SkSafeUnref(fXfermode); |
| 878 | delete [] fIndices; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 879 | } |
| 880 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 881 | void SkDrawVerticesCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 882 | canvas->drawVertices(fVmode, fVertexCount, fVertices, |
| 883 | fTexs, fColors, fXfermode, fIndices, |
| 884 | fIndexCount, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 885 | } |
| 886 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 887 | SkRestoreCommand::SkRestoreCommand() |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 888 | : INHERITED(kRestore_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 889 | fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 890 | } |
| 891 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 892 | void SkRestoreCommand::execute(SkCanvas* canvas) const { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 893 | canvas->restore(); |
| 894 | } |
| 895 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 896 | SkSaveCommand::SkSaveCommand() |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 897 | : INHERITED(kSave_OpType) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 898 | } |
| 899 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 900 | void SkSaveCommand::execute(SkCanvas* canvas) const { |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 901 | canvas->save(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 902 | } |
| 903 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 904 | SkSaveLayerCommand::SkSaveLayerCommand(const SkRect* bounds, const SkPaint* paint, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 905 | SkCanvas::SaveFlags flags) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 906 | : INHERITED(kSaveLayer_OpType) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 907 | if (bounds) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 908 | fBounds = *bounds; |
| 909 | } else { |
| 910 | fBounds.setEmpty(); |
| 911 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 912 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 913 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 914 | fPaint = *paint; |
| 915 | fPaintPtr = &fPaint; |
| 916 | } else { |
| 917 | fPaintPtr = NULL; |
| 918 | } |
| 919 | fFlags = flags; |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 920 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 921 | if (bounds) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 922 | fInfo.push(SkObjectParser::RectToString(*bounds, "Bounds: ")); |
| 923 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 924 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 925 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 926 | } |
| 927 | fInfo.push(SkObjectParser::SaveFlagsToString(flags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 928 | } |
| 929 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 930 | void SkSaveLayerCommand::execute(SkCanvas* canvas) const { |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 931 | canvas->saveLayer(fBounds.isEmpty() ? NULL : &fBounds, |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 932 | fPaintPtr, |
| 933 | fFlags); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 934 | } |
| 935 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 936 | void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const { |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 937 | canvas->save(); |
| 938 | } |
| 939 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 940 | SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 941 | : INHERITED(kSetMatrix_OpType) { |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 942 | fUserMatrix.reset(); |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 943 | fMatrix = matrix; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 944 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 945 | fInfo.push(SkObjectParser::MatrixToString(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 946 | } |
| 947 | |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 948 | void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) { |
| 949 | fUserMatrix = userMatrix; |
| 950 | } |
| 951 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 952 | void SkSetMatrixCommand::execute(SkCanvas* canvas) const { |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 953 | SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix); |
| 954 | canvas->setMatrix(temp); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 955 | } |
| 956 | |