blob: 00854d4e3efce54a5bb6037b2331cd1985f9b56f [file] [log] [blame]
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +00001/*
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.com3b0a9fe2013-01-31 15:56:22 +00008#include "SkDebugCanvas.h"
robertphillips@google.com801cee12012-10-19 19:06:11 +00009#include "SkDevice.h"
scroggo@google.com7def5e12013-05-31 14:00:10 +000010#include "SkForceLinking.h"
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +000011#include "SkGraphics.h"
robertphillips@google.com4e4d75b2012-11-12 18:03:19 +000012#include "SkImageDecoder.h"
robertphillips@google.com801cee12012-10-19 19:06:11 +000013#include "SkImageEncoder.h"
djsollen@google.coma09e8832012-11-13 18:50:33 +000014#include "SkOSFile.h"
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +000015#include "SkPicture.h"
robertphillips@google.com801cee12012-10-19 19:06:11 +000016#include "SkPictureRecord.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000017#include "SkPictureRecorder.h"
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +000018#include "SkStream.h"
djsollen@google.coma09e8832012-11-13 18:50:33 +000019#include "picture_utils.h"
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +000020
scroggo@google.com7def5e12013-05-31 14:00:10 +000021__SK_FORCE_IMAGE_DECODER_LINKING;
22
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +000023static void usage() {
robertphillips@google.comd3d377f2012-12-07 20:56:13 +000024 SkDebugf("Usage: filter -i inFile [-o outFile] [--input-dir path] [--output-dir path]\n");
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +000025 SkDebugf(" [-h|--help]\n\n");
robertphillips@google.com2e87ba02013-04-08 15:45:30 +000026 SkDebugf(" -i inFile : file to filter.\n");
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +000027 SkDebugf(" -o outFile : result of filtering.\n");
djsollen@google.coma09e8832012-11-13 18:50:33 +000028 SkDebugf(" --input-dir : process all files in dir with .skp extension.\n");
29 SkDebugf(" --output-dir : results of filtering the input dir.\n");
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +000030 SkDebugf(" -h|--help : Show this help message.\n");
31}
32
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +000033// Is the supplied paint simply a color?
34static bool is_simple(const SkPaint& p) {
35 return NULL == p.getPathEffect() &&
36 NULL == p.getShader() &&
37 NULL == p.getXfermode() &&
38 NULL == p.getMaskFilter() &&
39 NULL == p.getColorFilter() &&
40 NULL == p.getRasterizer() &&
41 NULL == p.getLooper() &&
42 NULL == p.getImageFilter();
43}
robertphillips@google.comd3d377f2012-12-07 20:56:13 +000044
robertphillips@google.com50c84da2013-04-01 18:18:49 +000045
robertphillips@google.com73743552013-02-05 20:51:49 +000046// Check for:
47// SAVE_LAYER
48// DRAW_BITMAP_RECT_TO_RECT
49// RESTORE
50// where the saveLayer's color can be moved into the drawBitmapRect
robertphillips@google.com50c84da2013-04-01 18:18:49 +000051static bool check_0(SkDebugCanvas* canvas, int curCommand) {
52 if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() ||
53 canvas->getSize() <= curCommand+2 ||
54 DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
55 RESTORE != canvas->getDrawCommandAt(curCommand+2)->getType()) {
robertphillips@google.com73743552013-02-05 20:51:49 +000056 return false;
robertphillips@google.com50c84da2013-04-01 18:18:49 +000057 }
robertphillips@google.com73743552013-02-05 20:51:49 +000058
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000059 SkSaveLayerCommand* saveLayer =
60 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand);
61 SkDrawBitmapRectCommand* dbmr =
62 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+1);
robertphillips@google.com73743552013-02-05 20:51:49 +000063
64 const SkPaint* saveLayerPaint = saveLayer->paint();
65 SkPaint* dbmrPaint = dbmr->paint();
66
skia.committer@gmail.com3d18d062013-02-14 07:01:34 +000067 // For this optimization we only fold the saveLayer and drawBitmapRect
robertphillips@google.comc5257042013-04-02 15:30:03 +000068 // together if the saveLayer's draw is simple (i.e., no fancy effects)
69 // and the only difference in the colors is their alpha value
robertphillips@google.com1780a3c2013-02-13 13:27:44 +000070 SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque
robertphillips@google.comc5257042013-04-02 15:30:03 +000071 SkColor dbmrColor = dbmrPaint->getColor() | 0xFF000000; // force opaque
robertphillips@google.com1780a3c2013-02-13 13:27:44 +000072
robertphillips@google.comc5257042013-04-02 15:30:03 +000073 // If either operation lacks a paint then the collapse is trivial
robertphillips@google.com73743552013-02-05 20:51:49 +000074 return NULL == saveLayerPaint ||
75 NULL == dbmrPaint ||
robertphillips@google.comc5257042013-04-02 15:30:03 +000076 (is_simple(*saveLayerPaint) && dbmrColor == layerColor);
robertphillips@google.com73743552013-02-05 20:51:49 +000077}
78
79// Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer
80// and restore
robertphillips@google.com50c84da2013-04-01 18:18:49 +000081static void apply_0(SkDebugCanvas* canvas, int curCommand) {
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000082 SkSaveLayerCommand* saveLayer =
83 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand);
robertphillips@google.com73743552013-02-05 20:51:49 +000084 const SkPaint* saveLayerPaint = saveLayer->paint();
robertphillips@google.com73743552013-02-05 20:51:49 +000085
robertphillips@google.com50c84da2013-04-01 18:18:49 +000086 // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +000087 if (NULL != saveLayerPaint) {
commit-bot@chromium.org7a115912013-06-18 20:20:55 +000088 SkDrawBitmapRectCommand* dbmr =
89 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+1);
robertphillips@google.com50c84da2013-04-01 18:18:49 +000090 SkPaint* dbmrPaint = dbmr->paint();
91
92 if (NULL == dbmrPaint) {
93 // if the DBMR doesn't have a paint just use the saveLayer's
94 dbmr->setPaint(*saveLayerPaint);
95 } else if (NULL != saveLayerPaint) {
robertphillips@google.comc5257042013-04-02 15:30:03 +000096 // Both paints are present so their alphas need to be combined
97 SkColor color = saveLayerPaint->getColor();
98 int a0 = SkColorGetA(color);
99
100 color = dbmrPaint->getColor();
101 int a1 = SkColorGetA(color);
102
103 int newA = SkMulDiv255Round(a0, a1);
104 SkASSERT(newA <= 0xFF);
105
106 SkColor newColor = SkColorSetA(color, newA);
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000107 dbmrPaint->setColor(newColor);
108 }
robertphillips@google.com73743552013-02-05 20:51:49 +0000109 }
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000110
111 canvas->deleteDrawCommandAt(curCommand+2); // restore
112 canvas->deleteDrawCommandAt(curCommand); // saveLayer
robertphillips@google.com73743552013-02-05 20:51:49 +0000113}
114
115// Check for:
116// SAVE_LAYER
117// SAVE
118// CLIP_RECT
119// DRAW_BITMAP_RECT_TO_RECT
120// RESTORE
121// RESTORE
122// where the saveLayer's color can be moved into the drawBitmapRect
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000123static bool check_1(SkDebugCanvas* canvas, int curCommand) {
124 if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() ||
125 canvas->getSize() <= curCommand+5 ||
126 SAVE != canvas->getDrawCommandAt(curCommand+1)->getType() ||
127 CLIP_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
128 DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+3)->getType() ||
129 RESTORE != canvas->getDrawCommandAt(curCommand+4)->getType() ||
130 RESTORE != canvas->getDrawCommandAt(curCommand+5)->getType()) {
robertphillips@google.com73743552013-02-05 20:51:49 +0000131 return false;
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000132 }
robertphillips@google.com73743552013-02-05 20:51:49 +0000133
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000134 SkSaveLayerCommand* saveLayer =
135 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand);
136 SkDrawBitmapRectCommand* dbmr =
137 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+3);
robertphillips@google.com73743552013-02-05 20:51:49 +0000138
139 const SkPaint* saveLayerPaint = saveLayer->paint();
140 SkPaint* dbmrPaint = dbmr->paint();
141
skia.committer@gmail.com3d18d062013-02-14 07:01:34 +0000142 // For this optimization we only fold the saveLayer and drawBitmapRect
robertphillips@google.com1780a3c2013-02-13 13:27:44 +0000143 // together if the saveLayer's draw is simple (i.e., no fancy effects) and
144 // and the only difference in the colors is that the saveLayer's can have
145 // an alpha while the drawBitmapRect's is opaque.
146 // TODO: it should be possible to fold them together even if they both
147 // have different non-255 alphas but this is low priority since we have
148 // never seen that case
149 // If either operation lacks a paint then the collapse is trivial
150 SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque
151
robertphillips@google.com73743552013-02-05 20:51:49 +0000152 return NULL == saveLayerPaint ||
153 NULL == dbmrPaint ||
robertphillips@google.com1780a3c2013-02-13 13:27:44 +0000154 (is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor);
robertphillips@google.com73743552013-02-05 20:51:49 +0000155}
156
157// Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer
158// and restore
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000159static void apply_1(SkDebugCanvas* canvas, int curCommand) {
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000160 SkSaveLayerCommand* saveLayer =
161 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand);
robertphillips@google.com73743552013-02-05 20:51:49 +0000162 const SkPaint* saveLayerPaint = saveLayer->paint();
robertphillips@google.com73743552013-02-05 20:51:49 +0000163
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000164 // if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed
165 if (NULL != saveLayerPaint) {
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000166 SkDrawBitmapRectCommand* dbmr =
167 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+3);
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000168 SkPaint* dbmrPaint = dbmr->paint();
169
170 if (NULL == dbmrPaint) {
171 dbmr->setPaint(*saveLayerPaint);
172 } else {
173 SkColor newColor = SkColorSetA(dbmrPaint->getColor(),
174 SkColorGetA(saveLayerPaint->getColor()));
175 dbmrPaint->setColor(newColor);
176 }
robertphillips@google.com73743552013-02-05 20:51:49 +0000177 }
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000178
179 canvas->deleteDrawCommandAt(curCommand+5); // restore
180 canvas->deleteDrawCommandAt(curCommand); // saveLayer
robertphillips@google.com73743552013-02-05 20:51:49 +0000181}
182
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000183// Check for:
184// SAVE
185// CLIP_RECT
186// DRAW_RECT
187// RESTORE
188// where the rect is entirely within the clip and the clip is an intersect
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000189static bool check_2(SkDebugCanvas* canvas, int curCommand) {
190 if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
191 canvas->getSize() <= curCommand+4 ||
192 CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
193 DRAW_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
194 RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000195 return false;
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000196 }
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000197
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000198 SkClipRectCommand* cr =
199 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
200 SkDrawRectCommand* dr =
201 (SkDrawRectCommand*) canvas->getDrawCommandAt(curCommand+2);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000202
203 if (SkRegion::kIntersect_Op != cr->op()) {
204 return false;
205 }
206
207 return cr->rect().contains(dr->rect());
208}
209
210// Remove everything but the drawRect
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000211static void apply_2(SkDebugCanvas* canvas, int curCommand) {
212 canvas->deleteDrawCommandAt(curCommand+3); // restore
213 // drawRect
214 canvas->deleteDrawCommandAt(curCommand+1); // clipRect
215 canvas->deleteDrawCommandAt(curCommand); // save
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000216}
217
218// Check for:
219// SAVE
220// CLIP_RRECT
221// DRAW_RECT
222// RESTORE
223// where the rect entirely encloses the clip
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000224static bool check_3(SkDebugCanvas* canvas, int curCommand) {
225 if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
226 canvas->getSize() <= curCommand+4 ||
227 CLIP_RRECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
228 DRAW_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
229 RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000230 return false;
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000231 }
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000232
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000233 SkClipRRectCommand* crr =
234 (SkClipRRectCommand*) canvas->getDrawCommandAt(curCommand+1);
235 SkDrawRectCommand* dr =
236 (SkDrawRectCommand*) canvas->getDrawCommandAt(curCommand+2);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000237
238 if (SkRegion::kIntersect_Op != crr->op()) {
239 return false;
240 }
241
242 return dr->rect().contains(crr->rrect().rect());
243}
244
245// Replace everything with a drawRRect with the paint from the drawRect
246// and the AA settings from the clipRRect
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000247static void apply_3(SkDebugCanvas* canvas, int curCommand) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000248
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000249 canvas->deleteDrawCommandAt(curCommand+3); // restore
250
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000251 SkClipRRectCommand* crr =
252 (SkClipRRectCommand*) canvas->getDrawCommandAt(curCommand+1);
253 SkDrawRectCommand* dr =
254 (SkDrawRectCommand*) canvas->getDrawCommandAt(curCommand+2);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000255
256 // TODO: could skip paint re-creation if the AA settings already match
robertphillips@google.com91217d02013-03-17 18:33:46 +0000257 SkPaint newPaint = dr->paint();
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000258 newPaint.setAntiAlias(crr->doAA());
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000259 SkDrawRRectCommand* drr = new SkDrawRRectCommand(crr->rrect(), newPaint);
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000260 canvas->setDrawCommandAt(curCommand+2, drr);
261
262 canvas->deleteDrawCommandAt(curCommand+1); // clipRRect
263 canvas->deleteDrawCommandAt(curCommand); // save
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000264}
265
266// Check for:
267// SAVE
268// CLIP_RECT
269// DRAW_BITMAP_RECT_TO_RECT
270// RESTORE
271// where the rect and drawBitmapRect dst exactly match
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000272static bool check_4(SkDebugCanvas* canvas, int curCommand) {
273 if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
274 canvas->getSize() <= curCommand+4 ||
275 CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
276 DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
277 RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000278 return false;
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000279 }
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000280
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000281 SkClipRectCommand* cr =
282 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
283 SkDrawBitmapRectCommand* dbmr =
284 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2);
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000285
286 if (SkRegion::kIntersect_Op != cr->op()) {
287 return false;
288 }
289
290 return dbmr->dstRect() == cr->rect();
291}
292
293// Remove everything but the drawBitmapRect
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000294static void apply_4(SkDebugCanvas* canvas, int curCommand) {
295 canvas->deleteDrawCommandAt(curCommand+3); // restore
296 // drawBitmapRectToRect
297 canvas->deleteDrawCommandAt(curCommand+1); // clipRect
298 canvas->deleteDrawCommandAt(curCommand); // save
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000299}
300
robertphillips@google.com9105ad02013-03-17 18:46:16 +0000301// Check for:
302// TRANSLATE
303// where the translate is zero
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000304static bool check_5(SkDebugCanvas* canvas, int curCommand) {
305 if (TRANSLATE != canvas->getDrawCommandAt(curCommand)->getType()) {
robertphillips@google.com9105ad02013-03-17 18:46:16 +0000306 return false;
307 }
308
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000309 SkTranslateCommand* t =
310 (SkTranslateCommand*) canvas->getDrawCommandAt(curCommand);
robertphillips@google.com9105ad02013-03-17 18:46:16 +0000311
312 return 0 == t->x() && 0 == t->y();
313}
314
315// Just remove the translate
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000316static void apply_5(SkDebugCanvas* canvas, int curCommand) {
317 canvas->deleteDrawCommandAt(curCommand); // translate
robertphillips@google.com9105ad02013-03-17 18:46:16 +0000318}
319
320// Check for:
321// SCALE
322// where the scale is 1,1
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000323static bool check_6(SkDebugCanvas* canvas, int curCommand) {
324 if (SCALE != canvas->getDrawCommandAt(curCommand)->getType()) {
robertphillips@google.com9105ad02013-03-17 18:46:16 +0000325 return false;
326 }
327
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000328 SkScaleCommand* s = (SkScaleCommand*) canvas->getDrawCommandAt(curCommand);
robertphillips@google.com9105ad02013-03-17 18:46:16 +0000329
330 return SK_Scalar1 == s->x() && SK_Scalar1 == s->y();
331}
332
333// Just remove the scale
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000334static void apply_6(SkDebugCanvas* canvas, int curCommand) {
335 canvas->deleteDrawCommandAt(curCommand); // scale
robertphillips@google.com9105ad02013-03-17 18:46:16 +0000336}
337
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000338// Check for:
339// SAVE
340// CLIP_RECT
341// SAVE_LAYER
342// SAVE
343// CLIP_RECT
344// SAVE_LAYER
345// SAVE
346// CLIP_RECT
347// DRAWBITMAPRECTTORECT
348// RESTORE
349// RESTORE
350// RESTORE
351// RESTORE
352// RESTORE
353// where:
354// all the clipRect's are BW, nested, intersections
355// the drawBitmapRectToRect is a 1-1 copy from src to dest
356// the last (smallest) clip rect is a subset of the drawBitmapRectToRect's dest rect
357// all the saveLayer's paints can be rolled into the drawBitmapRectToRect's paint
358// This pattern is used by Google spreadsheet when drawing the toolbar buttons
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000359static bool check_7(SkDebugCanvas* canvas, int curCommand) {
360 if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
361 canvas->getSize() <= curCommand+13 ||
362 CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
363 SAVE_LAYER != canvas->getDrawCommandAt(curCommand+2)->getType() ||
364 SAVE != canvas->getDrawCommandAt(curCommand+3)->getType() ||
365 CLIP_RECT != canvas->getDrawCommandAt(curCommand+4)->getType() ||
366 SAVE_LAYER != canvas->getDrawCommandAt(curCommand+5)->getType() ||
367 SAVE != canvas->getDrawCommandAt(curCommand+6)->getType() ||
368 CLIP_RECT != canvas->getDrawCommandAt(curCommand+7)->getType() ||
369 DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+8)->getType() ||
370 RESTORE != canvas->getDrawCommandAt(curCommand+9)->getType() ||
371 RESTORE != canvas->getDrawCommandAt(curCommand+10)->getType() ||
372 RESTORE != canvas->getDrawCommandAt(curCommand+11)->getType() ||
373 RESTORE != canvas->getDrawCommandAt(curCommand+12)->getType() ||
374 RESTORE != canvas->getDrawCommandAt(curCommand+13)->getType()) {
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000375 return false;
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000376 }
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000377
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000378 SkClipRectCommand* clip0 =
379 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
380 SkSaveLayerCommand* saveLayer0 =
381 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand+2);
382 SkClipRectCommand* clip1 =
383 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+4);
384 SkSaveLayerCommand* saveLayer1 =
385 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand+5);
386 SkClipRectCommand* clip2 =
387 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+7);
388 SkDrawBitmapRectCommand* dbmr =
389 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+8);
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000390
391 if (clip0->doAA() || clip1->doAA() || clip2->doAA()) {
392 return false;
393 }
394
395 if (SkRegion::kIntersect_Op != clip0->op() ||
396 SkRegion::kIntersect_Op != clip1->op() ||
397 SkRegion::kIntersect_Op != clip2->op()) {
398 return false;
399 }
400
skia.committer@gmail.com6acd09e2013-03-29 07:01:22 +0000401 if (!clip0->rect().contains(clip1->rect()) ||
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000402 !clip1->rect().contains(clip2->rect())) {
403 return false;
404 }
405
406 // The src->dest mapping needs to be 1-to-1
407 if (NULL == dbmr->srcRect()) {
408 if (dbmr->bitmap().width() != dbmr->dstRect().width() ||
409 dbmr->bitmap().height() != dbmr->dstRect().height()) {
410 return false;
411 }
412 } else {
413 if (dbmr->srcRect()->width() != dbmr->dstRect().width() ||
414 dbmr->srcRect()->height() != dbmr->dstRect().height()) {
415 return false;
416 }
417 }
418
419 if (!dbmr->dstRect().contains(clip2->rect())) {
420 return false;
421 }
422
423 const SkPaint* saveLayerPaint0 = saveLayer0->paint();
424 const SkPaint* saveLayerPaint1 = saveLayer1->paint();
425
426 if ((NULL != saveLayerPaint0 && !is_simple(*saveLayerPaint0)) ||
427 (NULL != saveLayerPaint1 && !is_simple(*saveLayerPaint1))) {
428 return false;
429 }
430
431 SkPaint* dbmrPaint = dbmr->paint();
432
433 if (NULL == dbmrPaint) {
skia.committer@gmail.com6acd09e2013-03-29 07:01:22 +0000434 return true;
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000435 }
skia.committer@gmail.com6acd09e2013-03-29 07:01:22 +0000436
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000437 if (NULL != saveLayerPaint0) {
438 SkColor layerColor0 = saveLayerPaint0->getColor() | 0xFF000000; // force opaque
439 if (dbmrPaint->getColor() != layerColor0) {
440 return false;
441 }
442 }
443
444 if (NULL != saveLayerPaint1) {
445 SkColor layerColor1 = saveLayerPaint1->getColor() | 0xFF000000; // force opaque
446 if (dbmrPaint->getColor() != layerColor1) {
447 return false;
448 }
449 }
450
451 return true;
452}
453
454// Reduce to a single drawBitmapRectToRect call by folding the clipRect's into
455// the src and dst Rects and the saveLayer paints into the drawBitmapRectToRect's
456// paint.
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000457static void apply_7(SkDebugCanvas* canvas, int curCommand) {
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000458 SkSaveLayerCommand* saveLayer0 =
459 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand+2);
460 SkSaveLayerCommand* saveLayer1 =
461 (SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand+5);
462 SkClipRectCommand* clip2 =
463 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+7);
464 SkDrawBitmapRectCommand* dbmr =
465 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+8);
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000466
467 SkScalar newSrcLeft = dbmr->srcRect()->fLeft + clip2->rect().fLeft - dbmr->dstRect().fLeft;
468 SkScalar newSrcTop = dbmr->srcRect()->fTop + clip2->rect().fTop - dbmr->dstRect().fTop;
469
skia.committer@gmail.com6acd09e2013-03-29 07:01:22 +0000470 SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop,
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000471 clip2->rect().width(), clip2->rect().height());
472
473 dbmr->setSrcRect(newSrc);
474 dbmr->setDstRect(clip2->rect());
475
476 SkColor color = 0xFF000000;
477 int a0, a1;
478
479 const SkPaint* saveLayerPaint0 = saveLayer0->paint();
480 if (NULL != saveLayerPaint0) {
481 color = saveLayerPaint0->getColor();
482 a0 = SkColorGetA(color);
483 } else {
484 a0 = 0xFF;
485 }
486
487 const SkPaint* saveLayerPaint1 = saveLayer1->paint();
488 if (NULL != saveLayerPaint1) {
489 color = saveLayerPaint1->getColor();
490 a1 = SkColorGetA(color);
491 } else {
492 a1 = 0xFF;
493 }
494
robertphillips@google.comc5257042013-04-02 15:30:03 +0000495 int newA = SkMulDiv255Round(a0, a1);
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000496 SkASSERT(newA <= 0xFF);
497
498 SkPaint* dbmrPaint = dbmr->paint();
499
500 if (NULL != dbmrPaint) {
501 SkColor newColor = SkColorSetA(dbmrPaint->getColor(), newA);
502 dbmrPaint->setColor(newColor);
503 } else {
504 SkColor newColor = SkColorSetA(color, newA);
505
506 SkPaint newPaint;
507 newPaint.setColor(newColor);
508 dbmr->setPaint(newPaint);
509 }
510
511 // remove everything except the drawbitmaprect
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000512 canvas->deleteDrawCommandAt(curCommand+13); // restore
513 canvas->deleteDrawCommandAt(curCommand+12); // restore
514 canvas->deleteDrawCommandAt(curCommand+11); // restore
515 canvas->deleteDrawCommandAt(curCommand+10); // restore
516 canvas->deleteDrawCommandAt(curCommand+9); // restore
517 canvas->deleteDrawCommandAt(curCommand+7); // clipRect
518 canvas->deleteDrawCommandAt(curCommand+6); // save
519 canvas->deleteDrawCommandAt(curCommand+5); // saveLayer
520 canvas->deleteDrawCommandAt(curCommand+4); // clipRect
521 canvas->deleteDrawCommandAt(curCommand+3); // save
522 canvas->deleteDrawCommandAt(curCommand+2); // saveLayer
523 canvas->deleteDrawCommandAt(curCommand+1); // clipRect
524 canvas->deleteDrawCommandAt(curCommand); // save
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000525}
robertphillips@google.com9105ad02013-03-17 18:46:16 +0000526
commit-bot@chromium.org3bdf1642013-04-01 21:00:27 +0000527// Check for:
528// SAVE
529// CLIP_RECT
530// DRAWBITMAPRECTTORECT
531// RESTORE
532// where:
533// the drawBitmapRectToRect is a 1-1 copy from src to dest
534// the clip rect is BW and a subset of the drawBitmapRectToRect's dest rect
535static bool check_8(SkDebugCanvas* canvas, int curCommand) {
536 if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
537 canvas->getSize() <= curCommand+4 ||
538 CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
539 DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
540 RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
541 return false;
542 }
543
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000544 SkClipRectCommand* clip =
545 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
546 SkDrawBitmapRectCommand* dbmr =
547 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2);
commit-bot@chromium.org3bdf1642013-04-01 21:00:27 +0000548
549 if (clip->doAA() || SkRegion::kIntersect_Op != clip->op()) {
550 return false;
551 }
552
553 // The src->dest mapping needs to be 1-to-1
554 if (NULL == dbmr->srcRect()) {
555 if (dbmr->bitmap().width() != dbmr->dstRect().width() ||
556 dbmr->bitmap().height() != dbmr->dstRect().height()) {
557 return false;
558 }
559 } else {
560 if (dbmr->srcRect()->width() != dbmr->dstRect().width() ||
561 dbmr->srcRect()->height() != dbmr->dstRect().height()) {
562 return false;
563 }
564 }
565
566 if (!dbmr->dstRect().contains(clip->rect())) {
567 return false;
568 }
569
570 return true;
571}
572
573// Fold the clipRect into the drawBitmapRectToRect's src and dest rects
574static void apply_8(SkDebugCanvas* canvas, int curCommand) {
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000575 SkClipRectCommand* clip =
576 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
577 SkDrawBitmapRectCommand* dbmr =
578 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2);
commit-bot@chromium.org3bdf1642013-04-01 21:00:27 +0000579
580 SkScalar newSrcLeft, newSrcTop;
581
582 if (NULL != dbmr->srcRect()) {
583 newSrcLeft = dbmr->srcRect()->fLeft + clip->rect().fLeft - dbmr->dstRect().fLeft;
584 newSrcTop = dbmr->srcRect()->fTop + clip->rect().fTop - dbmr->dstRect().fTop;
585 } else {
586 newSrcLeft = clip->rect().fLeft - dbmr->dstRect().fLeft;
587 newSrcTop = clip->rect().fTop - dbmr->dstRect().fTop;
588 }
589
590 SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop,
591 clip->rect().width(), clip->rect().height());
592
593 dbmr->setSrcRect(newSrc);
594 dbmr->setDstRect(clip->rect());
595
596 // remove everything except the drawbitmaprect
597 canvas->deleteDrawCommandAt(curCommand+3);
598 canvas->deleteDrawCommandAt(curCommand+1);
599 canvas->deleteDrawCommandAt(curCommand);
600}
601
602// Check for:
603// SAVE
604// CLIP_RECT
605// DRAWBITMAPRECTTORECT
606// RESTORE
607// where:
608// clipRect is BW and encloses the DBMR2R's dest rect
609static bool check_9(SkDebugCanvas* canvas, int curCommand) {
610 if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
611 canvas->getSize() <= curCommand+4 ||
612 CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
613 DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
614 RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
615 return false;
616 }
617
commit-bot@chromium.org7a115912013-06-18 20:20:55 +0000618 SkClipRectCommand* clip =
619 (SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
620 SkDrawBitmapRectCommand* dbmr =
621 (SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2);
commit-bot@chromium.org3bdf1642013-04-01 21:00:27 +0000622
623 if (clip->doAA() || SkRegion::kIntersect_Op != clip->op()) {
624 return false;
625 }
626
627 if (!clip->rect().contains(dbmr->dstRect())) {
628 return false;
629 }
630
631 return true;
632}
633
634// remove everything except the drawbitmaprect
635static void apply_9(SkDebugCanvas* canvas, int curCommand) {
636 canvas->deleteDrawCommandAt(curCommand+3); // restore
637 // drawBitmapRectToRect
638 canvas->deleteDrawCommandAt(curCommand+1); // clipRect
639 canvas->deleteDrawCommandAt(curCommand); // save
640}
641
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000642typedef bool (*PFCheck)(SkDebugCanvas* canvas, int curCommand);
643typedef void (*PFApply)(SkDebugCanvas* canvas, int curCommand);
robertphillips@google.com73743552013-02-05 20:51:49 +0000644
645struct OptTableEntry {
646 PFCheck fCheck;
647 PFApply fApply;
648 int fNumTimesApplied;
649} gOptTable[] = {
650 { check_0, apply_0, 0 },
651 { check_1, apply_1, 0 },
robertphillips@google.comfebc0ec2013-03-11 22:53:11 +0000652 { check_2, apply_2, 0 },
653 { check_3, apply_3, 0 },
654 { check_4, apply_4, 0 },
robertphillips@google.com9105ad02013-03-17 18:46:16 +0000655 { check_5, apply_5, 0 },
656 { check_6, apply_6, 0 },
robertphillips@google.comc3410b82013-03-28 12:25:25 +0000657 { check_7, apply_7, 0 },
commit-bot@chromium.org3bdf1642013-04-01 21:00:27 +0000658 { check_8, apply_8, 0 },
659 { check_9, apply_9, 0 },
robertphillips@google.com73743552013-02-05 20:51:49 +0000660};
661
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000662
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000663static int filter_picture(const SkString& inFile, const SkString& outFile) {
robertphillips@google.com4d98b742013-05-10 14:51:54 +0000664 SkAutoTDelete<SkPicture> inPicture;
djsollen@google.coma09e8832012-11-13 18:50:33 +0000665
666 SkFILEStream inStream(inFile.c_str());
667 if (inStream.isValid()) {
scroggo@google.comf1754ec2013-06-28 21:32:00 +0000668 inPicture.reset(SkPicture::CreateFromStream(&inStream));
djsollen@google.coma09e8832012-11-13 18:50:33 +0000669 }
670
robertphillips@google.com4d98b742013-05-10 14:51:54 +0000671 if (NULL == inPicture.get()) {
djsollen@google.coma09e8832012-11-13 18:50:33 +0000672 SkDebugf("Could not read file %s\n", inFile.c_str());
673 return -1;
674 }
675
robertphillips@google.com73743552013-02-05 20:51:49 +0000676 int localCount[SK_ARRAY_COUNT(gOptTable)];
677
678 memset(localCount, 0, sizeof(localCount));
679
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700680 SkDebugCanvas debugCanvas(SkScalarCeilToInt(inPicture->cullRect().width()),
681 SkScalarCeilToInt(inPicture->cullRect().height()));
robertphillipsc5ba71d2014-09-04 08:42:50 -0700682 inPicture->playback(&debugCanvas);
djsollen@google.coma09e8832012-11-13 18:50:33 +0000683
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000684 // delete the initial save and restore since replaying the commands will
robertphillips@google.com73743552013-02-05 20:51:49 +0000685 // re-add them
robertphillips@google.com50c84da2013-04-01 18:18:49 +0000686 if (debugCanvas.getSize() > 1) {
687 debugCanvas.deleteDrawCommandAt(0);
688 debugCanvas.deleteDrawCommandAt(debugCanvas.getSize()-1);
robertphillips@google.com73743552013-02-05 20:51:49 +0000689 }
690
robertphillips@google.comd9c18532013-04-01 19:10:21 +0000691 bool changed = true;
robertphillips@google.com2e87ba02013-04-08 15:45:30 +0000692 int numBefore = debugCanvas.getSize();
robertphillips@google.comd9c18532013-04-01 19:10:21 +0000693
694 while (changed) {
695 changed = false;
696 for (int i = 0; i < debugCanvas.getSize(); ++i) {
697 for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
698 if ((*gOptTable[opt].fCheck)(&debugCanvas, i)) {
699 (*gOptTable[opt].fApply)(&debugCanvas, i);
700
701 ++gOptTable[opt].fNumTimesApplied;
702 ++localCount[opt];
703
704 if (debugCanvas.getSize() == i) {
705 // the optimization removed all the remaining operations
706 break;
707 }
708
709 opt = 0; // try all the opts all over again
710 changed = true;
711 }
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000712 }
713 }
714 }
djsollen@google.coma09e8832012-11-13 18:50:33 +0000715
robertphillips@google.com2e87ba02013-04-08 15:45:30 +0000716 int numAfter = debugCanvas.getSize();
717
djsollen@google.coma09e8832012-11-13 18:50:33 +0000718 if (!outFile.isEmpty()) {
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000719 SkPictureRecorder recorder;
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700720 SkCanvas* canvas = recorder.beginRecording(inPicture->cullRect().width(),
721 inPicture->cullRect().height(),
722 NULL, 0);
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000723 debugCanvas.draw(canvas);
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000724 SkAutoTUnref<SkPicture> outPicture(recorder.endRecording());
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000725
djsollen@google.coma09e8832012-11-13 18:50:33 +0000726 SkFILEWStream outStream(outFile.c_str());
727
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000728 outPicture->serialize(&outStream);
djsollen@google.coma09e8832012-11-13 18:50:33 +0000729 }
730
robertphillips@google.com73743552013-02-05 20:51:49 +0000731 bool someOptFired = false;
732 for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
733 if (0 != localCount[opt]) {
734 SkDebugf("%d: %d ", opt, localCount[opt]);
735 someOptFired = true;
736 }
737 }
738
739 if (!someOptFired) {
740 SkDebugf("No opts fired\n");
741 } else {
skia.committer@gmail.com32840172013-04-09 07:01:27 +0000742 SkDebugf("\t before: %d after: %d delta: %d\n",
robertphillips@google.com2e87ba02013-04-08 15:45:30 +0000743 numBefore, numAfter, numBefore-numAfter);
robertphillips@google.com73743552013-02-05 20:51:49 +0000744 }
745
djsollen@google.coma09e8832012-11-13 18:50:33 +0000746 return 0;
747}
748
tfarina@chromium.orga5b7cc02012-10-08 14:41:10 +0000749// This function is not marked as 'static' so it can be referenced externally
750// in the iOS build.
humper@google.com05af1af2013-01-07 16:47:43 +0000751int tool_main(int argc, char** argv); // suppress a warning on mac
752
caryclark@google.com9598f422012-10-09 12:32:37 +0000753int tool_main(int argc, char** argv) {
robertphillips@google.com4d98b742013-05-10 14:51:54 +0000754#if SK_ENABLE_INST_COUNT
755 gPrintInstCount = true;
756#endif
757
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000758 SkGraphics::Init();
759
robertphillips@google.com801cee12012-10-19 19:06:11 +0000760 if (argc < 3) {
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000761 usage();
762 return -1;
763 }
764
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000765 SkString inFile, outFile, inDir, outDir;
robertphillips@google.com801cee12012-10-19 19:06:11 +0000766
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000767 char* const* stop = argv + argc;
768 for (++argv; argv < stop; ++argv) {
769 if (strcmp(*argv, "-i") == 0) {
770 argv++;
771 if (argv < stop && **argv) {
772 inFile.set(*argv);
773 } else {
robertphillips@google.com801cee12012-10-19 19:06:11 +0000774 SkDebugf("missing arg for -i\n");
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000775 usage();
776 return -1;
777 }
djsollen@google.coma09e8832012-11-13 18:50:33 +0000778 } else if (strcmp(*argv, "--input-dir") == 0) {
779 argv++;
780 if (argv < stop && **argv) {
781 inDir.set(*argv);
782 } else {
783 SkDebugf("missing arg for --input-dir\n");
784 usage();
785 return -1;
786 }
787 } else if (strcmp(*argv, "--output-dir") == 0) {
788 argv++;
789 if (argv < stop && **argv) {
790 outDir.set(*argv);
791 } else {
792 SkDebugf("missing arg for --output-dir\n");
793 usage();
794 return -1;
795 }
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000796 } else if (strcmp(*argv, "-o") == 0) {
797 argv++;
798 if (argv < stop && **argv) {
799 outFile.set(*argv);
800 } else {
robertphillips@google.com801cee12012-10-19 19:06:11 +0000801 SkDebugf("missing arg for -o\n");
802 usage();
803 return -1;
804 }
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000805 } else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) {
806 usage();
807 return 0;
808 } else {
809 SkDebugf("unknown arg %s\n", *argv);
810 usage();
811 return -1;
812 }
813 }
814
djsollen@google.coma09e8832012-11-13 18:50:33 +0000815 SkOSFile::Iter iter(inDir.c_str(), "skp");
humper@google.com05af1af2013-01-07 16:47:43 +0000816
djsollen@google.coma09e8832012-11-13 18:50:33 +0000817 SkString inputFilename, outputFilename;
818 if (iter.next(&inputFilename)) {
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000819
djsollen@google.coma09e8832012-11-13 18:50:33 +0000820 do {
tfarinaa8e2e152014-07-28 19:26:58 -0700821 inFile = SkOSPath::Join(inDir.c_str(), inputFilename.c_str());
djsollen@google.coma09e8832012-11-13 18:50:33 +0000822 if (!outDir.isEmpty()) {
tfarinaa8e2e152014-07-28 19:26:58 -0700823 outFile = SkOSPath::Join(outDir.c_str(), inputFilename.c_str());
djsollen@google.coma09e8832012-11-13 18:50:33 +0000824 }
825 SkDebugf("Executing %s\n", inputFilename.c_str());
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000826 filter_picture(inFile, outFile);
djsollen@google.coma09e8832012-11-13 18:50:33 +0000827 } while(iter.next(&inputFilename));
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000828
djsollen@google.coma09e8832012-11-13 18:50:33 +0000829 } else if (!inFile.isEmpty()) {
robertphillips@google.com3b0a9fe2013-01-31 15:56:22 +0000830 filter_picture(inFile, outFile);
djsollen@google.coma09e8832012-11-13 18:50:33 +0000831 } else {
832 usage();
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000833 return -1;
834 }
835
robertphillips@google.com73743552013-02-05 20:51:49 +0000836 for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
837 SkDebugf("opt %d: %d\n", opt, gOptTable[opt].fNumTimesApplied);
838 }
839
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000840 SkGraphics::Term();
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000841 return 0;
842}
843
844#if !defined SK_BUILD_FOR_IOS
845int main(int argc, char * const argv[]) {
caryclark@google.com9598f422012-10-09 12:32:37 +0000846 return tool_main(argc, (char**) argv);
robertphillips@google.comc7e4a5a2012-10-04 13:00:33 +0000847}
848#endif