robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 8 | #include "SkDebugCanvas.h" |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 9 | #include "SkDevice.h" |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 10 | #include "SkGraphics.h" |
robertphillips@google.com | 4e4d75b | 2012-11-12 18:03:19 +0000 | [diff] [blame] | 11 | #include "SkImageDecoder.h" |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 12 | #include "SkImageEncoder.h" |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 13 | #include "SkOSFile.h" |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 14 | #include "SkPicture.h" |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 15 | #include "SkPicturePlayback.h" |
| 16 | #include "SkPictureRecord.h" |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 17 | #include "SkStream.h" |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 18 | #include "picture_utils.h" |
robertphillips@google.com | d3d377f | 2012-12-07 20:56:13 +0000 | [diff] [blame] | 19 | #include "path_utils.h" |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 20 | |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 21 | static void usage() { |
robertphillips@google.com | d3d377f | 2012-12-07 20:56:13 +0000 | [diff] [blame] | 22 | SkDebugf("Usage: filter -i inFile [-o outFile] [--input-dir path] [--output-dir path]\n"); |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 23 | SkDebugf(" [-h|--help]\n\n"); |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 24 | SkDebugf(" -i inFile : file to file.\n"); |
| 25 | SkDebugf(" -o outFile : result of filtering.\n"); |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 26 | SkDebugf(" --input-dir : process all files in dir with .skp extension.\n"); |
| 27 | SkDebugf(" --output-dir : results of filtering the input dir.\n"); |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 28 | SkDebugf(" -h|--help : Show this help message.\n"); |
| 29 | } |
| 30 | |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 31 | // Is the supplied paint simply a color? |
| 32 | static bool is_simple(const SkPaint& p) { |
| 33 | return NULL == p.getPathEffect() && |
| 34 | NULL == p.getShader() && |
| 35 | NULL == p.getXfermode() && |
| 36 | NULL == p.getMaskFilter() && |
| 37 | NULL == p.getColorFilter() && |
| 38 | NULL == p.getRasterizer() && |
| 39 | NULL == p.getLooper() && |
| 40 | NULL == p.getImageFilter(); |
| 41 | } |
robertphillips@google.com | d3d377f | 2012-12-07 20:56:13 +0000 | [diff] [blame] | 42 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 43 | |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 44 | // Check for: |
| 45 | // SAVE_LAYER |
| 46 | // DRAW_BITMAP_RECT_TO_RECT |
| 47 | // RESTORE |
| 48 | // where the saveLayer's color can be moved into the drawBitmapRect |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 49 | static bool check_0(SkDebugCanvas* canvas, int curCommand) { |
| 50 | if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() || |
| 51 | canvas->getSize() <= curCommand+2 || |
| 52 | DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || |
| 53 | RESTORE != canvas->getDrawCommandAt(curCommand+2)->getType()) { |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 54 | return false; |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 55 | } |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 56 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 57 | SaveLayer* saveLayer = (SaveLayer*) canvas->getDrawCommandAt(curCommand); |
| 58 | DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand+1); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 59 | |
| 60 | const SkPaint* saveLayerPaint = saveLayer->paint(); |
| 61 | SkPaint* dbmrPaint = dbmr->paint(); |
| 62 | |
skia.committer@gmail.com | 3d18d06 | 2013-02-14 07:01:34 +0000 | [diff] [blame] | 63 | // For this optimization we only fold the saveLayer and drawBitmapRect |
robertphillips@google.com | 1780a3c | 2013-02-13 13:27:44 +0000 | [diff] [blame] | 64 | // together if the saveLayer's draw is simple (i.e., no fancy effects) and |
| 65 | // and the only difference in the colors is that the saveLayer's can have |
| 66 | // an alpha while the drawBitmapRect's is opaque. |
| 67 | // TODO: it should be possible to fold them together even if they both |
| 68 | // have different non-255 alphas but this is low priority since we have |
| 69 | // never seen that case |
| 70 | // If either operation lacks a paint then the collapse is trivial |
| 71 | SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque |
| 72 | |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 73 | return NULL == saveLayerPaint || |
| 74 | NULL == dbmrPaint || |
robertphillips@google.com | 1780a3c | 2013-02-13 13:27:44 +0000 | [diff] [blame] | 75 | (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer |
| 79 | // and restore |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 80 | static void apply_0(SkDebugCanvas* canvas, int curCommand) { |
| 81 | SaveLayer* saveLayer = (SaveLayer*) canvas->getDrawCommandAt(curCommand); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 82 | const SkPaint* saveLayerPaint = saveLayer->paint(); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 83 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 84 | // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed |
| 85 | if (NULL != saveLayerPaint) { |
| 86 | DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand+1); |
| 87 | SkPaint* dbmrPaint = dbmr->paint(); |
| 88 | |
| 89 | if (NULL == dbmrPaint) { |
| 90 | // if the DBMR doesn't have a paint just use the saveLayer's |
| 91 | dbmr->setPaint(*saveLayerPaint); |
| 92 | } else if (NULL != saveLayerPaint) { |
| 93 | SkColor newColor = SkColorSetA(dbmrPaint->getColor(), |
| 94 | SkColorGetA(saveLayerPaint->getColor())); |
| 95 | dbmrPaint->setColor(newColor); |
| 96 | } |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 97 | } |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 98 | |
| 99 | canvas->deleteDrawCommandAt(curCommand+2); // restore |
| 100 | canvas->deleteDrawCommandAt(curCommand); // saveLayer |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // Check for: |
| 104 | // SAVE_LAYER |
| 105 | // SAVE |
| 106 | // CLIP_RECT |
| 107 | // DRAW_BITMAP_RECT_TO_RECT |
| 108 | // RESTORE |
| 109 | // RESTORE |
| 110 | // where the saveLayer's color can be moved into the drawBitmapRect |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 111 | static bool check_1(SkDebugCanvas* canvas, int curCommand) { |
| 112 | if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() || |
| 113 | canvas->getSize() <= curCommand+5 || |
| 114 | SAVE != canvas->getDrawCommandAt(curCommand+1)->getType() || |
| 115 | CLIP_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || |
| 116 | DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+3)->getType() || |
| 117 | RESTORE != canvas->getDrawCommandAt(curCommand+4)->getType() || |
| 118 | RESTORE != canvas->getDrawCommandAt(curCommand+5)->getType()) { |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 119 | return false; |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 120 | } |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 121 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 122 | SaveLayer* saveLayer = (SaveLayer*) canvas->getDrawCommandAt(curCommand); |
| 123 | DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand+3); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 124 | |
| 125 | const SkPaint* saveLayerPaint = saveLayer->paint(); |
| 126 | SkPaint* dbmrPaint = dbmr->paint(); |
| 127 | |
skia.committer@gmail.com | 3d18d06 | 2013-02-14 07:01:34 +0000 | [diff] [blame] | 128 | // For this optimization we only fold the saveLayer and drawBitmapRect |
robertphillips@google.com | 1780a3c | 2013-02-13 13:27:44 +0000 | [diff] [blame] | 129 | // together if the saveLayer's draw is simple (i.e., no fancy effects) and |
| 130 | // and the only difference in the colors is that the saveLayer's can have |
| 131 | // an alpha while the drawBitmapRect's is opaque. |
| 132 | // TODO: it should be possible to fold them together even if they both |
| 133 | // have different non-255 alphas but this is low priority since we have |
| 134 | // never seen that case |
| 135 | // If either operation lacks a paint then the collapse is trivial |
| 136 | SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque |
| 137 | |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 138 | return NULL == saveLayerPaint || |
| 139 | NULL == dbmrPaint || |
robertphillips@google.com | 1780a3c | 2013-02-13 13:27:44 +0000 | [diff] [blame] | 140 | (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | // Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer |
| 144 | // and restore |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 145 | static void apply_1(SkDebugCanvas* canvas, int curCommand) { |
| 146 | SaveLayer* saveLayer = (SaveLayer*) canvas->getDrawCommandAt(curCommand); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 147 | const SkPaint* saveLayerPaint = saveLayer->paint(); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 148 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 149 | // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed |
| 150 | if (NULL != saveLayerPaint) { |
| 151 | DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand+3); |
| 152 | SkPaint* dbmrPaint = dbmr->paint(); |
| 153 | |
| 154 | if (NULL == dbmrPaint) { |
| 155 | dbmr->setPaint(*saveLayerPaint); |
| 156 | } else { |
| 157 | SkColor newColor = SkColorSetA(dbmrPaint->getColor(), |
| 158 | SkColorGetA(saveLayerPaint->getColor())); |
| 159 | dbmrPaint->setColor(newColor); |
| 160 | } |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 161 | } |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 162 | |
| 163 | canvas->deleteDrawCommandAt(curCommand+5); // restore |
| 164 | canvas->deleteDrawCommandAt(curCommand); // saveLayer |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 165 | } |
| 166 | |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 167 | // Check for: |
| 168 | // SAVE |
| 169 | // CLIP_RECT |
| 170 | // DRAW_RECT |
| 171 | // RESTORE |
| 172 | // where the rect is entirely within the clip and the clip is an intersect |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 173 | static bool check_2(SkDebugCanvas* canvas, int curCommand) { |
| 174 | if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || |
| 175 | canvas->getSize() <= curCommand+4 || |
| 176 | CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || |
| 177 | DRAW_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || |
| 178 | RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 179 | return false; |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 180 | } |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 181 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 182 | ClipRect* cr = (ClipRect*) canvas->getDrawCommandAt(curCommand+1); |
| 183 | DrawRectC* dr = (DrawRectC*) canvas->getDrawCommandAt(curCommand+2); |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 184 | |
| 185 | if (SkRegion::kIntersect_Op != cr->op()) { |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | return cr->rect().contains(dr->rect()); |
| 190 | } |
| 191 | |
| 192 | // Remove everything but the drawRect |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 193 | static void apply_2(SkDebugCanvas* canvas, int curCommand) { |
| 194 | canvas->deleteDrawCommandAt(curCommand+3); // restore |
| 195 | // drawRect |
| 196 | canvas->deleteDrawCommandAt(curCommand+1); // clipRect |
| 197 | canvas->deleteDrawCommandAt(curCommand); // save |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | // Check for: |
| 201 | // SAVE |
| 202 | // CLIP_RRECT |
| 203 | // DRAW_RECT |
| 204 | // RESTORE |
| 205 | // where the rect entirely encloses the clip |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 206 | static bool check_3(SkDebugCanvas* canvas, int curCommand) { |
| 207 | if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || |
| 208 | canvas->getSize() <= curCommand+4 || |
| 209 | CLIP_RRECT != canvas->getDrawCommandAt(curCommand+1)->getType() || |
| 210 | DRAW_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || |
| 211 | RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 212 | return false; |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 213 | } |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 214 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 215 | ClipRRect* crr = (ClipRRect*) canvas->getDrawCommandAt(curCommand+1); |
| 216 | DrawRectC* dr = (DrawRectC*) canvas->getDrawCommandAt(curCommand+2); |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 217 | |
| 218 | if (SkRegion::kIntersect_Op != crr->op()) { |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | return dr->rect().contains(crr->rrect().rect()); |
| 223 | } |
| 224 | |
| 225 | // Replace everything with a drawRRect with the paint from the drawRect |
| 226 | // and the AA settings from the clipRRect |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 227 | static void apply_3(SkDebugCanvas* canvas, int curCommand) { |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 228 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 229 | canvas->deleteDrawCommandAt(curCommand+3); // restore |
| 230 | |
| 231 | ClipRRect* crr = (ClipRRect*) canvas->getDrawCommandAt(curCommand+1); |
| 232 | DrawRectC* dr = (DrawRectC*) canvas->getDrawCommandAt(curCommand+2); |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 233 | |
| 234 | // TODO: could skip paint re-creation if the AA settings already match |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 235 | SkPaint newPaint = dr->paint(); |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 236 | newPaint.setAntiAlias(crr->doAA()); |
| 237 | DrawRRect* drr = new DrawRRect(crr->rrect(), newPaint); |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 238 | canvas->setDrawCommandAt(curCommand+2, drr); |
| 239 | |
| 240 | canvas->deleteDrawCommandAt(curCommand+1); // clipRRect |
| 241 | canvas->deleteDrawCommandAt(curCommand); // save |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | // Check for: |
| 245 | // SAVE |
| 246 | // CLIP_RECT |
| 247 | // DRAW_BITMAP_RECT_TO_RECT |
| 248 | // RESTORE |
| 249 | // where the rect and drawBitmapRect dst exactly match |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 250 | static bool check_4(SkDebugCanvas* canvas, int curCommand) { |
| 251 | if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || |
| 252 | canvas->getSize() <= curCommand+4 || |
| 253 | CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || |
| 254 | DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() || |
| 255 | RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) { |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 256 | return false; |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 257 | } |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 258 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 259 | ClipRect* cr = (ClipRect*) canvas->getDrawCommandAt(curCommand+1); |
| 260 | DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand+2); |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 261 | |
| 262 | if (SkRegion::kIntersect_Op != cr->op()) { |
| 263 | return false; |
| 264 | } |
| 265 | |
| 266 | return dbmr->dstRect() == cr->rect(); |
| 267 | } |
| 268 | |
| 269 | // Remove everything but the drawBitmapRect |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 270 | static void apply_4(SkDebugCanvas* canvas, int curCommand) { |
| 271 | canvas->deleteDrawCommandAt(curCommand+3); // restore |
| 272 | // drawBitmapRectToRect |
| 273 | canvas->deleteDrawCommandAt(curCommand+1); // clipRect |
| 274 | canvas->deleteDrawCommandAt(curCommand); // save |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 275 | } |
| 276 | |
robertphillips@google.com | 9105ad0 | 2013-03-17 18:46:16 +0000 | [diff] [blame] | 277 | // Check for: |
| 278 | // TRANSLATE |
| 279 | // where the translate is zero |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 280 | static bool check_5(SkDebugCanvas* canvas, int curCommand) { |
| 281 | if (TRANSLATE != canvas->getDrawCommandAt(curCommand)->getType()) { |
robertphillips@google.com | 9105ad0 | 2013-03-17 18:46:16 +0000 | [diff] [blame] | 282 | return false; |
| 283 | } |
| 284 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 285 | Translate* t = (Translate*) canvas->getDrawCommandAt(curCommand); |
robertphillips@google.com | 9105ad0 | 2013-03-17 18:46:16 +0000 | [diff] [blame] | 286 | |
| 287 | return 0 == t->x() && 0 == t->y(); |
| 288 | } |
| 289 | |
| 290 | // Just remove the translate |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 291 | static void apply_5(SkDebugCanvas* canvas, int curCommand) { |
| 292 | canvas->deleteDrawCommandAt(curCommand); // translate |
robertphillips@google.com | 9105ad0 | 2013-03-17 18:46:16 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | // Check for: |
| 296 | // SCALE |
| 297 | // where the scale is 1,1 |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 298 | static bool check_6(SkDebugCanvas* canvas, int curCommand) { |
| 299 | if (SCALE != canvas->getDrawCommandAt(curCommand)->getType()) { |
robertphillips@google.com | 9105ad0 | 2013-03-17 18:46:16 +0000 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 303 | Scale* s = (Scale*) canvas->getDrawCommandAt(curCommand); |
robertphillips@google.com | 9105ad0 | 2013-03-17 18:46:16 +0000 | [diff] [blame] | 304 | |
| 305 | return SK_Scalar1 == s->x() && SK_Scalar1 == s->y(); |
| 306 | } |
| 307 | |
| 308 | // Just remove the scale |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 309 | static void apply_6(SkDebugCanvas* canvas, int curCommand) { |
| 310 | canvas->deleteDrawCommandAt(curCommand); // scale |
robertphillips@google.com | 9105ad0 | 2013-03-17 18:46:16 +0000 | [diff] [blame] | 311 | } |
| 312 | |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 313 | // Check for: |
| 314 | // SAVE |
| 315 | // CLIP_RECT |
| 316 | // SAVE_LAYER |
| 317 | // SAVE |
| 318 | // CLIP_RECT |
| 319 | // SAVE_LAYER |
| 320 | // SAVE |
| 321 | // CLIP_RECT |
| 322 | // DRAWBITMAPRECTTORECT |
| 323 | // RESTORE |
| 324 | // RESTORE |
| 325 | // RESTORE |
| 326 | // RESTORE |
| 327 | // RESTORE |
| 328 | // where: |
| 329 | // all the clipRect's are BW, nested, intersections |
| 330 | // the drawBitmapRectToRect is a 1-1 copy from src to dest |
| 331 | // the last (smallest) clip rect is a subset of the drawBitmapRectToRect's dest rect |
| 332 | // all the saveLayer's paints can be rolled into the drawBitmapRectToRect's paint |
| 333 | // This pattern is used by Google spreadsheet when drawing the toolbar buttons |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 334 | static bool check_7(SkDebugCanvas* canvas, int curCommand) { |
| 335 | if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() || |
| 336 | canvas->getSize() <= curCommand+13 || |
| 337 | CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() || |
| 338 | SAVE_LAYER != canvas->getDrawCommandAt(curCommand+2)->getType() || |
| 339 | SAVE != canvas->getDrawCommandAt(curCommand+3)->getType() || |
| 340 | CLIP_RECT != canvas->getDrawCommandAt(curCommand+4)->getType() || |
| 341 | SAVE_LAYER != canvas->getDrawCommandAt(curCommand+5)->getType() || |
| 342 | SAVE != canvas->getDrawCommandAt(curCommand+6)->getType() || |
| 343 | CLIP_RECT != canvas->getDrawCommandAt(curCommand+7)->getType() || |
| 344 | DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+8)->getType() || |
| 345 | RESTORE != canvas->getDrawCommandAt(curCommand+9)->getType() || |
| 346 | RESTORE != canvas->getDrawCommandAt(curCommand+10)->getType() || |
| 347 | RESTORE != canvas->getDrawCommandAt(curCommand+11)->getType() || |
| 348 | RESTORE != canvas->getDrawCommandAt(curCommand+12)->getType() || |
| 349 | RESTORE != canvas->getDrawCommandAt(curCommand+13)->getType()) { |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 350 | return false; |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 351 | } |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 352 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 353 | ClipRect* clip0 = (ClipRect*) canvas->getDrawCommandAt(curCommand+1); |
| 354 | SaveLayer* saveLayer0 = (SaveLayer*) canvas->getDrawCommandAt(curCommand+2); |
| 355 | ClipRect* clip1 = (ClipRect*) canvas->getDrawCommandAt(curCommand+4); |
| 356 | SaveLayer* saveLayer1 = (SaveLayer*) canvas->getDrawCommandAt(curCommand+5); |
| 357 | ClipRect* clip2 = (ClipRect*) canvas->getDrawCommandAt(curCommand+7); |
| 358 | DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand+8); |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 359 | |
| 360 | if (clip0->doAA() || clip1->doAA() || clip2->doAA()) { |
| 361 | return false; |
| 362 | } |
| 363 | |
| 364 | if (SkRegion::kIntersect_Op != clip0->op() || |
| 365 | SkRegion::kIntersect_Op != clip1->op() || |
| 366 | SkRegion::kIntersect_Op != clip2->op()) { |
| 367 | return false; |
| 368 | } |
| 369 | |
skia.committer@gmail.com | 6acd09e | 2013-03-29 07:01:22 +0000 | [diff] [blame] | 370 | if (!clip0->rect().contains(clip1->rect()) || |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 371 | !clip1->rect().contains(clip2->rect())) { |
| 372 | return false; |
| 373 | } |
| 374 | |
| 375 | // The src->dest mapping needs to be 1-to-1 |
| 376 | if (NULL == dbmr->srcRect()) { |
| 377 | if (dbmr->bitmap().width() != dbmr->dstRect().width() || |
| 378 | dbmr->bitmap().height() != dbmr->dstRect().height()) { |
| 379 | return false; |
| 380 | } |
| 381 | } else { |
| 382 | if (dbmr->srcRect()->width() != dbmr->dstRect().width() || |
| 383 | dbmr->srcRect()->height() != dbmr->dstRect().height()) { |
| 384 | return false; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | if (!dbmr->dstRect().contains(clip2->rect())) { |
| 389 | return false; |
| 390 | } |
| 391 | |
| 392 | const SkPaint* saveLayerPaint0 = saveLayer0->paint(); |
| 393 | const SkPaint* saveLayerPaint1 = saveLayer1->paint(); |
| 394 | |
| 395 | if ((NULL != saveLayerPaint0 && !is_simple(*saveLayerPaint0)) || |
| 396 | (NULL != saveLayerPaint1 && !is_simple(*saveLayerPaint1))) { |
| 397 | return false; |
| 398 | } |
| 399 | |
| 400 | SkPaint* dbmrPaint = dbmr->paint(); |
| 401 | |
| 402 | if (NULL == dbmrPaint) { |
skia.committer@gmail.com | 6acd09e | 2013-03-29 07:01:22 +0000 | [diff] [blame] | 403 | return true; |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 404 | } |
skia.committer@gmail.com | 6acd09e | 2013-03-29 07:01:22 +0000 | [diff] [blame] | 405 | |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 406 | if (NULL != saveLayerPaint0) { |
| 407 | SkColor layerColor0 = saveLayerPaint0->getColor() | 0xFF000000; // force opaque |
| 408 | if (dbmrPaint->getColor() != layerColor0) { |
| 409 | return false; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | if (NULL != saveLayerPaint1) { |
| 414 | SkColor layerColor1 = saveLayerPaint1->getColor() | 0xFF000000; // force opaque |
| 415 | if (dbmrPaint->getColor() != layerColor1) { |
| 416 | return false; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | return true; |
| 421 | } |
| 422 | |
| 423 | // Reduce to a single drawBitmapRectToRect call by folding the clipRect's into |
| 424 | // the src and dst Rects and the saveLayer paints into the drawBitmapRectToRect's |
| 425 | // paint. |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 426 | static void apply_7(SkDebugCanvas* canvas, int curCommand) { |
| 427 | SaveLayer* saveLayer0 = (SaveLayer*) canvas->getDrawCommandAt(curCommand+2); |
| 428 | SaveLayer* saveLayer1 = (SaveLayer*) canvas->getDrawCommandAt(curCommand+5); |
| 429 | ClipRect* clip2 = (ClipRect*) canvas->getDrawCommandAt(curCommand+7); |
| 430 | DrawBitmapRect* dbmr = (DrawBitmapRect*) canvas->getDrawCommandAt(curCommand+8); |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 431 | |
| 432 | SkScalar newSrcLeft = dbmr->srcRect()->fLeft + clip2->rect().fLeft - dbmr->dstRect().fLeft; |
| 433 | SkScalar newSrcTop = dbmr->srcRect()->fTop + clip2->rect().fTop - dbmr->dstRect().fTop; |
| 434 | |
skia.committer@gmail.com | 6acd09e | 2013-03-29 07:01:22 +0000 | [diff] [blame] | 435 | SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop, |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 436 | clip2->rect().width(), clip2->rect().height()); |
| 437 | |
| 438 | dbmr->setSrcRect(newSrc); |
| 439 | dbmr->setDstRect(clip2->rect()); |
| 440 | |
| 441 | SkColor color = 0xFF000000; |
| 442 | int a0, a1; |
| 443 | |
| 444 | const SkPaint* saveLayerPaint0 = saveLayer0->paint(); |
| 445 | if (NULL != saveLayerPaint0) { |
| 446 | color = saveLayerPaint0->getColor(); |
| 447 | a0 = SkColorGetA(color); |
| 448 | } else { |
| 449 | a0 = 0xFF; |
| 450 | } |
| 451 | |
| 452 | const SkPaint* saveLayerPaint1 = saveLayer1->paint(); |
| 453 | if (NULL != saveLayerPaint1) { |
| 454 | color = saveLayerPaint1->getColor(); |
| 455 | a1 = SkColorGetA(color); |
| 456 | } else { |
| 457 | a1 = 0xFF; |
| 458 | } |
| 459 | |
| 460 | int newA = (a0 * a1) / 255; |
| 461 | SkASSERT(newA <= 0xFF); |
| 462 | |
| 463 | SkPaint* dbmrPaint = dbmr->paint(); |
| 464 | |
| 465 | if (NULL != dbmrPaint) { |
| 466 | SkColor newColor = SkColorSetA(dbmrPaint->getColor(), newA); |
| 467 | dbmrPaint->setColor(newColor); |
| 468 | } else { |
| 469 | SkColor newColor = SkColorSetA(color, newA); |
| 470 | |
| 471 | SkPaint newPaint; |
| 472 | newPaint.setColor(newColor); |
| 473 | dbmr->setPaint(newPaint); |
| 474 | } |
| 475 | |
| 476 | // remove everything except the drawbitmaprect |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 477 | canvas->deleteDrawCommandAt(curCommand+13); // restore |
| 478 | canvas->deleteDrawCommandAt(curCommand+12); // restore |
| 479 | canvas->deleteDrawCommandAt(curCommand+11); // restore |
| 480 | canvas->deleteDrawCommandAt(curCommand+10); // restore |
| 481 | canvas->deleteDrawCommandAt(curCommand+9); // restore |
| 482 | canvas->deleteDrawCommandAt(curCommand+7); // clipRect |
| 483 | canvas->deleteDrawCommandAt(curCommand+6); // save |
| 484 | canvas->deleteDrawCommandAt(curCommand+5); // saveLayer |
| 485 | canvas->deleteDrawCommandAt(curCommand+4); // clipRect |
| 486 | canvas->deleteDrawCommandAt(curCommand+3); // save |
| 487 | canvas->deleteDrawCommandAt(curCommand+2); // saveLayer |
| 488 | canvas->deleteDrawCommandAt(curCommand+1); // clipRect |
| 489 | canvas->deleteDrawCommandAt(curCommand); // save |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 490 | } |
robertphillips@google.com | 9105ad0 | 2013-03-17 18:46:16 +0000 | [diff] [blame] | 491 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 492 | typedef bool (*PFCheck)(SkDebugCanvas* canvas, int curCommand); |
| 493 | typedef void (*PFApply)(SkDebugCanvas* canvas, int curCommand); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 494 | |
| 495 | struct OptTableEntry { |
| 496 | PFCheck fCheck; |
| 497 | PFApply fApply; |
| 498 | int fNumTimesApplied; |
| 499 | } gOptTable[] = { |
| 500 | { check_0, apply_0, 0 }, |
| 501 | { check_1, apply_1, 0 }, |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 502 | { check_2, apply_2, 0 }, |
| 503 | { check_3, apply_3, 0 }, |
| 504 | { check_4, apply_4, 0 }, |
robertphillips@google.com | 9105ad0 | 2013-03-17 18:46:16 +0000 | [diff] [blame] | 505 | { check_5, apply_5, 0 }, |
| 506 | { check_6, apply_6, 0 }, |
robertphillips@google.com | c3410b8 | 2013-03-28 12:25:25 +0000 | [diff] [blame] | 507 | { check_7, apply_7, 0 }, |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 508 | }; |
| 509 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 510 | |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 511 | static int filter_picture(const SkString& inFile, const SkString& outFile) { |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 512 | SkPicture* inPicture = NULL; |
| 513 | |
| 514 | SkFILEStream inStream(inFile.c_str()); |
| 515 | if (inStream.isValid()) { |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 516 | inPicture = SkNEW_ARGS(SkPicture, (&inStream, NULL, &SkImageDecoder::DecodeMemory)); |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | if (NULL == inPicture) { |
| 520 | SkDebugf("Could not read file %s\n", inFile.c_str()); |
| 521 | return -1; |
| 522 | } |
| 523 | |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 524 | int localCount[SK_ARRAY_COUNT(gOptTable)]; |
| 525 | |
| 526 | memset(localCount, 0, sizeof(localCount)); |
| 527 | |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 528 | SkDebugCanvas debugCanvas(inPicture->width(), inPicture->height()); |
| 529 | debugCanvas.setBounds(inPicture->width(), inPicture->height()); |
| 530 | inPicture->draw(&debugCanvas); |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 531 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 532 | // delete the initial save and restore since replaying the commands will |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 533 | // re-add them |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 534 | if (debugCanvas.getSize() > 1) { |
| 535 | debugCanvas.deleteDrawCommandAt(0); |
| 536 | debugCanvas.deleteDrawCommandAt(debugCanvas.getSize()-1); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 537 | } |
| 538 | |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 539 | for (int i = 0; i < debugCanvas.getSize(); ++i) { |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 540 | for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) { |
robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame^] | 541 | if ((*gOptTable[opt].fCheck)(&debugCanvas, i)) { |
| 542 | (*gOptTable[opt].fApply)(&debugCanvas, i); |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 543 | ++gOptTable[opt].fNumTimesApplied; |
| 544 | ++localCount[opt]; |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | } |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 548 | |
| 549 | if (!outFile.isEmpty()) { |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 550 | SkPicture outPicture; |
| 551 | |
| 552 | SkCanvas* canvas = outPicture.beginRecording(inPicture->width(), inPicture->height()); |
| 553 | debugCanvas.draw(canvas); |
| 554 | outPicture.endRecording(); |
| 555 | |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 556 | SkFILEWStream outStream(outFile.c_str()); |
| 557 | |
| 558 | outPicture.serialize(&outStream); |
| 559 | } |
| 560 | |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 561 | bool someOptFired = false; |
| 562 | for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) { |
| 563 | if (0 != localCount[opt]) { |
| 564 | SkDebugf("%d: %d ", opt, localCount[opt]); |
| 565 | someOptFired = true; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | if (!someOptFired) { |
| 570 | SkDebugf("No opts fired\n"); |
| 571 | } else { |
| 572 | SkDebugf("\n"); |
| 573 | } |
| 574 | |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 575 | return 0; |
| 576 | } |
| 577 | |
tfarina@chromium.org | a5b7cc0 | 2012-10-08 14:41:10 +0000 | [diff] [blame] | 578 | // This function is not marked as 'static' so it can be referenced externally |
| 579 | // in the iOS build. |
humper@google.com | 05af1af | 2013-01-07 16:47:43 +0000 | [diff] [blame] | 580 | int tool_main(int argc, char** argv); // suppress a warning on mac |
| 581 | |
caryclark@google.com | 9598f42 | 2012-10-09 12:32:37 +0000 | [diff] [blame] | 582 | int tool_main(int argc, char** argv) { |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 583 | SkGraphics::Init(); |
| 584 | |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 585 | if (argc < 3) { |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 586 | usage(); |
| 587 | return -1; |
| 588 | } |
| 589 | |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 590 | SkString inFile, outFile, inDir, outDir; |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 591 | |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 592 | char* const* stop = argv + argc; |
| 593 | for (++argv; argv < stop; ++argv) { |
| 594 | if (strcmp(*argv, "-i") == 0) { |
| 595 | argv++; |
| 596 | if (argv < stop && **argv) { |
| 597 | inFile.set(*argv); |
| 598 | } else { |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 599 | SkDebugf("missing arg for -i\n"); |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 600 | usage(); |
| 601 | return -1; |
| 602 | } |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 603 | } else if (strcmp(*argv, "--input-dir") == 0) { |
| 604 | argv++; |
| 605 | if (argv < stop && **argv) { |
| 606 | inDir.set(*argv); |
| 607 | } else { |
| 608 | SkDebugf("missing arg for --input-dir\n"); |
| 609 | usage(); |
| 610 | return -1; |
| 611 | } |
| 612 | } else if (strcmp(*argv, "--output-dir") == 0) { |
| 613 | argv++; |
| 614 | if (argv < stop && **argv) { |
| 615 | outDir.set(*argv); |
| 616 | } else { |
| 617 | SkDebugf("missing arg for --output-dir\n"); |
| 618 | usage(); |
| 619 | return -1; |
| 620 | } |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 621 | } else if (strcmp(*argv, "-o") == 0) { |
| 622 | argv++; |
| 623 | if (argv < stop && **argv) { |
| 624 | outFile.set(*argv); |
| 625 | } else { |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 626 | SkDebugf("missing arg for -o\n"); |
| 627 | usage(); |
| 628 | return -1; |
| 629 | } |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 630 | } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) { |
| 631 | usage(); |
| 632 | return 0; |
| 633 | } else { |
| 634 | SkDebugf("unknown arg %s\n", *argv); |
| 635 | usage(); |
| 636 | return -1; |
| 637 | } |
| 638 | } |
| 639 | |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 640 | SkOSFile::Iter iter(inDir.c_str(), "skp"); |
humper@google.com | 05af1af | 2013-01-07 16:47:43 +0000 | [diff] [blame] | 641 | |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 642 | SkString inputFilename, outputFilename; |
| 643 | if (iter.next(&inputFilename)) { |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 644 | |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 645 | do { |
| 646 | sk_tools::make_filepath(&inFile, inDir, inputFilename); |
| 647 | if (!outDir.isEmpty()) { |
| 648 | sk_tools::make_filepath(&outFile, outDir, inputFilename); |
| 649 | } |
| 650 | SkDebugf("Executing %s\n", inputFilename.c_str()); |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 651 | filter_picture(inFile, outFile); |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 652 | } while(iter.next(&inputFilename)); |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 653 | |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 654 | } else if (!inFile.isEmpty()) { |
robertphillips@google.com | 3b0a9fe | 2013-01-31 15:56:22 +0000 | [diff] [blame] | 655 | filter_picture(inFile, outFile); |
djsollen@google.com | a09e883 | 2012-11-13 18:50:33 +0000 | [diff] [blame] | 656 | } else { |
| 657 | usage(); |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 658 | return -1; |
| 659 | } |
| 660 | |
robertphillips@google.com | 7374355 | 2013-02-05 20:51:49 +0000 | [diff] [blame] | 661 | for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) { |
| 662 | SkDebugf("opt %d: %d\n", opt, gOptTable[opt].fNumTimesApplied); |
| 663 | } |
| 664 | |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 665 | SkGraphics::Term(); |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | #if !defined SK_BUILD_FOR_IOS |
| 670 | int main(int argc, char * const argv[]) { |
caryclark@google.com | 9598f42 | 2012-10-09 12:32:37 +0000 | [diff] [blame] | 671 | return tool_main(argc, (char**) argv); |
robertphillips@google.com | c7e4a5a | 2012-10-04 13:00:33 +0000 | [diff] [blame] | 672 | } |
| 673 | #endif |