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