2012-10-04 13:00:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2013-01-31 15:56:22 +00:00
|
|
|
#include "SkDebugCanvas.h"
|
2012-10-19 19:06:11 +00:00
|
|
|
#include "SkDevice.h"
|
2013-05-31 14:00:10 +00:00
|
|
|
#include "SkForceLinking.h"
|
2012-10-04 13:00:33 +00:00
|
|
|
#include "SkGraphics.h"
|
2012-11-12 18:03:19 +00:00
|
|
|
#include "SkImageDecoder.h"
|
2012-10-19 19:06:11 +00:00
|
|
|
#include "SkImageEncoder.h"
|
2012-11-13 18:50:33 +00:00
|
|
|
#include "SkOSFile.h"
|
2012-10-04 13:00:33 +00:00
|
|
|
#include "SkPicture.h"
|
2012-10-19 19:06:11 +00:00
|
|
|
#include "SkPicturePlayback.h"
|
|
|
|
#include "SkPictureRecord.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2012-10-04 13:00:33 +00:00
|
|
|
#include "SkStream.h"
|
2012-11-13 18:50:33 +00:00
|
|
|
#include "picture_utils.h"
|
2012-12-07 20:56:13 +00:00
|
|
|
#include "path_utils.h"
|
2012-10-04 13:00:33 +00:00
|
|
|
|
2013-05-31 14:00:10 +00:00
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
2012-10-04 13:00:33 +00:00
|
|
|
static void usage() {
|
2012-12-07 20:56:13 +00:00
|
|
|
SkDebugf("Usage: filter -i inFile [-o outFile] [--input-dir path] [--output-dir path]\n");
|
2013-01-31 15:56:22 +00:00
|
|
|
SkDebugf(" [-h|--help]\n\n");
|
2013-04-08 15:45:30 +00:00
|
|
|
SkDebugf(" -i inFile : file to filter.\n");
|
2012-10-04 13:00:33 +00:00
|
|
|
SkDebugf(" -o outFile : result of filtering.\n");
|
2012-11-13 18:50:33 +00:00
|
|
|
SkDebugf(" --input-dir : process all files in dir with .skp extension.\n");
|
|
|
|
SkDebugf(" --output-dir : results of filtering the input dir.\n");
|
2012-10-04 13:00:33 +00:00
|
|
|
SkDebugf(" -h|--help : Show this help message.\n");
|
|
|
|
}
|
|
|
|
|
2013-01-31 15:56:22 +00:00
|
|
|
// Is the supplied paint simply a color?
|
|
|
|
static bool is_simple(const SkPaint& p) {
|
|
|
|
return NULL == p.getPathEffect() &&
|
|
|
|
NULL == p.getShader() &&
|
|
|
|
NULL == p.getXfermode() &&
|
|
|
|
NULL == p.getMaskFilter() &&
|
|
|
|
NULL == p.getColorFilter() &&
|
|
|
|
NULL == p.getRasterizer() &&
|
|
|
|
NULL == p.getLooper() &&
|
|
|
|
NULL == p.getImageFilter();
|
|
|
|
}
|
2012-10-24 19:30:41 +00:00
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
|
2013-02-05 20:51:49 +00:00
|
|
|
// Check for:
|
|
|
|
// SAVE_LAYER
|
|
|
|
// DRAW_BITMAP_RECT_TO_RECT
|
|
|
|
// RESTORE
|
|
|
|
// where the saveLayer's color can be moved into the drawBitmapRect
|
2013-04-01 18:18:49 +00:00
|
|
|
static bool check_0(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() ||
|
|
|
|
canvas->getSize() <= curCommand+2 ||
|
|
|
|
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+2)->getType()) {
|
2013-02-05 20:51:49 +00:00
|
|
|
return false;
|
2013-04-01 18:18:49 +00:00
|
|
|
}
|
2013-02-05 20:51:49 +00:00
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkSaveLayerCommand* saveLayer =
|
|
|
|
(SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand);
|
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
2013-02-05 20:51:49 +00:00
|
|
|
|
|
|
|
const SkPaint* saveLayerPaint = saveLayer->paint();
|
|
|
|
SkPaint* dbmrPaint = dbmr->paint();
|
|
|
|
|
2013-02-14 07:01:34 +00:00
|
|
|
// For this optimization we only fold the saveLayer and drawBitmapRect
|
2013-04-02 15:30:03 +00:00
|
|
|
// together if the saveLayer's draw is simple (i.e., no fancy effects)
|
|
|
|
// and the only difference in the colors is their alpha value
|
2013-02-13 13:27:44 +00:00
|
|
|
SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque
|
2013-04-02 15:30:03 +00:00
|
|
|
SkColor dbmrColor = dbmrPaint->getColor() | 0xFF000000; // force opaque
|
2013-02-13 13:27:44 +00:00
|
|
|
|
2013-04-02 15:30:03 +00:00
|
|
|
// If either operation lacks a paint then the collapse is trivial
|
2013-02-05 20:51:49 +00:00
|
|
|
return NULL == saveLayerPaint ||
|
|
|
|
NULL == dbmrPaint ||
|
2013-04-02 15:30:03 +00:00
|
|
|
(is_simple(*saveLayerPaint) && dbmrColor == layerColor);
|
2013-02-05 20:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer
|
|
|
|
// and restore
|
2013-04-01 18:18:49 +00:00
|
|
|
static void apply_0(SkDebugCanvas* canvas, int curCommand) {
|
2013-06-18 20:20:55 +00:00
|
|
|
SkSaveLayerCommand* saveLayer =
|
|
|
|
(SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand);
|
2013-02-05 20:51:49 +00:00
|
|
|
const SkPaint* saveLayerPaint = saveLayer->paint();
|
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
// if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed
|
2013-04-02 07:01:34 +00:00
|
|
|
if (NULL != saveLayerPaint) {
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
2013-04-01 18:18:49 +00:00
|
|
|
SkPaint* dbmrPaint = dbmr->paint();
|
|
|
|
|
|
|
|
if (NULL == dbmrPaint) {
|
|
|
|
// if the DBMR doesn't have a paint just use the saveLayer's
|
|
|
|
dbmr->setPaint(*saveLayerPaint);
|
|
|
|
} else if (NULL != saveLayerPaint) {
|
2013-04-02 15:30:03 +00:00
|
|
|
// Both paints are present so their alphas need to be combined
|
|
|
|
SkColor color = saveLayerPaint->getColor();
|
|
|
|
int a0 = SkColorGetA(color);
|
|
|
|
|
|
|
|
color = dbmrPaint->getColor();
|
|
|
|
int a1 = SkColorGetA(color);
|
|
|
|
|
|
|
|
int newA = SkMulDiv255Round(a0, a1);
|
|
|
|
SkASSERT(newA <= 0xFF);
|
|
|
|
|
|
|
|
SkColor newColor = SkColorSetA(color, newA);
|
2013-04-01 18:18:49 +00:00
|
|
|
dbmrPaint->setColor(newColor);
|
|
|
|
}
|
2013-02-05 20:51:49 +00:00
|
|
|
}
|
2013-04-01 18:18:49 +00:00
|
|
|
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+2); // restore
|
|
|
|
canvas->deleteDrawCommandAt(curCommand); // saveLayer
|
2013-02-05 20:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for:
|
|
|
|
// SAVE_LAYER
|
|
|
|
// SAVE
|
|
|
|
// CLIP_RECT
|
|
|
|
// DRAW_BITMAP_RECT_TO_RECT
|
|
|
|
// RESTORE
|
|
|
|
// RESTORE
|
|
|
|
// where the saveLayer's color can be moved into the drawBitmapRect
|
2013-04-01 18:18:49 +00:00
|
|
|
static bool check_1(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (SAVE_LAYER != canvas->getDrawCommandAt(curCommand)->getType() ||
|
|
|
|
canvas->getSize() <= curCommand+5 ||
|
|
|
|
SAVE != canvas->getDrawCommandAt(curCommand+1)->getType() ||
|
|
|
|
CLIP_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
|
|
|
|
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+3)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+4)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+5)->getType()) {
|
2013-02-05 20:51:49 +00:00
|
|
|
return false;
|
2013-04-01 18:18:49 +00:00
|
|
|
}
|
2013-02-05 20:51:49 +00:00
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkSaveLayerCommand* saveLayer =
|
|
|
|
(SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand);
|
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+3);
|
2013-02-05 20:51:49 +00:00
|
|
|
|
|
|
|
const SkPaint* saveLayerPaint = saveLayer->paint();
|
|
|
|
SkPaint* dbmrPaint = dbmr->paint();
|
|
|
|
|
2013-02-14 07:01:34 +00:00
|
|
|
// For this optimization we only fold the saveLayer and drawBitmapRect
|
2013-02-13 13:27:44 +00:00
|
|
|
// together if the saveLayer's draw is simple (i.e., no fancy effects) and
|
|
|
|
// and the only difference in the colors is that the saveLayer's can have
|
|
|
|
// an alpha while the drawBitmapRect's is opaque.
|
|
|
|
// TODO: it should be possible to fold them together even if they both
|
|
|
|
// have different non-255 alphas but this is low priority since we have
|
|
|
|
// never seen that case
|
|
|
|
// If either operation lacks a paint then the collapse is trivial
|
|
|
|
SkColor layerColor = saveLayerPaint->getColor() | 0xFF000000; // force opaque
|
|
|
|
|
2013-02-05 20:51:49 +00:00
|
|
|
return NULL == saveLayerPaint ||
|
|
|
|
NULL == dbmrPaint ||
|
2013-02-13 13:27:44 +00:00
|
|
|
(is_simple(*saveLayerPaint) && dbmrPaint->getColor() == layerColor);
|
2013-02-05 20:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fold the saveLayer's alpha into the drawBitmapRect and remove the saveLayer
|
|
|
|
// and restore
|
2013-04-01 18:18:49 +00:00
|
|
|
static void apply_1(SkDebugCanvas* canvas, int curCommand) {
|
2013-06-18 20:20:55 +00:00
|
|
|
SkSaveLayerCommand* saveLayer =
|
|
|
|
(SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand);
|
2013-02-05 20:51:49 +00:00
|
|
|
const SkPaint* saveLayerPaint = saveLayer->paint();
|
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
// if (NULL == saveLayerPaint) the dbmr's paint doesn't need to be changed
|
|
|
|
if (NULL != saveLayerPaint) {
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+3);
|
2013-04-01 18:18:49 +00:00
|
|
|
SkPaint* dbmrPaint = dbmr->paint();
|
|
|
|
|
|
|
|
if (NULL == dbmrPaint) {
|
|
|
|
dbmr->setPaint(*saveLayerPaint);
|
|
|
|
} else {
|
|
|
|
SkColor newColor = SkColorSetA(dbmrPaint->getColor(),
|
|
|
|
SkColorGetA(saveLayerPaint->getColor()));
|
|
|
|
dbmrPaint->setColor(newColor);
|
|
|
|
}
|
2013-02-05 20:51:49 +00:00
|
|
|
}
|
2013-04-01 18:18:49 +00:00
|
|
|
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+5); // restore
|
|
|
|
canvas->deleteDrawCommandAt(curCommand); // saveLayer
|
2013-02-05 20:51:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-11 22:53:11 +00:00
|
|
|
// Check for:
|
|
|
|
// SAVE
|
|
|
|
// CLIP_RECT
|
|
|
|
// DRAW_RECT
|
|
|
|
// RESTORE
|
|
|
|
// where the rect is entirely within the clip and the clip is an intersect
|
2013-04-01 18:18:49 +00:00
|
|
|
static bool check_2(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
|
|
|
|
canvas->getSize() <= curCommand+4 ||
|
|
|
|
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
|
|
|
|
DRAW_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
|
2013-03-11 22:53:11 +00:00
|
|
|
return false;
|
2013-04-01 18:18:49 +00:00
|
|
|
}
|
2013-03-11 22:53:11 +00:00
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkClipRectCommand* cr =
|
|
|
|
(SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
|
|
|
SkDrawRectCommand* dr =
|
|
|
|
(SkDrawRectCommand*) canvas->getDrawCommandAt(curCommand+2);
|
2013-03-11 22:53:11 +00:00
|
|
|
|
|
|
|
if (SkRegion::kIntersect_Op != cr->op()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cr->rect().contains(dr->rect());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove everything but the drawRect
|
2013-04-01 18:18:49 +00:00
|
|
|
static void apply_2(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+3); // restore
|
|
|
|
// drawRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+1); // clipRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand); // save
|
2013-03-11 22:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for:
|
|
|
|
// SAVE
|
|
|
|
// CLIP_RRECT
|
|
|
|
// DRAW_RECT
|
|
|
|
// RESTORE
|
|
|
|
// where the rect entirely encloses the clip
|
2013-04-01 18:18:49 +00:00
|
|
|
static bool check_3(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
|
|
|
|
canvas->getSize() <= curCommand+4 ||
|
|
|
|
CLIP_RRECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
|
|
|
|
DRAW_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
|
2013-03-11 22:53:11 +00:00
|
|
|
return false;
|
2013-04-01 18:18:49 +00:00
|
|
|
}
|
2013-03-11 22:53:11 +00:00
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkClipRRectCommand* crr =
|
|
|
|
(SkClipRRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
|
|
|
SkDrawRectCommand* dr =
|
|
|
|
(SkDrawRectCommand*) canvas->getDrawCommandAt(curCommand+2);
|
2013-03-11 22:53:11 +00:00
|
|
|
|
|
|
|
if (SkRegion::kIntersect_Op != crr->op()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dr->rect().contains(crr->rrect().rect());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace everything with a drawRRect with the paint from the drawRect
|
|
|
|
// and the AA settings from the clipRRect
|
2013-04-01 18:18:49 +00:00
|
|
|
static void apply_3(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+3); // restore
|
2013-03-11 22:53:11 +00:00
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkClipRRectCommand* crr =
|
|
|
|
(SkClipRRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
|
|
|
SkDrawRectCommand* dr =
|
|
|
|
(SkDrawRectCommand*) canvas->getDrawCommandAt(curCommand+2);
|
2013-03-11 22:53:11 +00:00
|
|
|
|
|
|
|
// TODO: could skip paint re-creation if the AA settings already match
|
2013-03-17 18:33:46 +00:00
|
|
|
SkPaint newPaint = dr->paint();
|
2013-03-11 22:53:11 +00:00
|
|
|
newPaint.setAntiAlias(crr->doAA());
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawRRectCommand* drr = new SkDrawRRectCommand(crr->rrect(), newPaint);
|
2013-04-01 18:18:49 +00:00
|
|
|
canvas->setDrawCommandAt(curCommand+2, drr);
|
|
|
|
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+1); // clipRRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand); // save
|
2013-03-11 22:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for:
|
|
|
|
// SAVE
|
|
|
|
// CLIP_RECT
|
|
|
|
// DRAW_BITMAP_RECT_TO_RECT
|
|
|
|
// RESTORE
|
|
|
|
// where the rect and drawBitmapRect dst exactly match
|
2013-04-01 18:18:49 +00:00
|
|
|
static bool check_4(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
|
|
|
|
canvas->getSize() <= curCommand+4 ||
|
|
|
|
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
|
|
|
|
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
|
2013-03-11 22:53:11 +00:00
|
|
|
return false;
|
2013-04-01 18:18:49 +00:00
|
|
|
}
|
2013-03-11 22:53:11 +00:00
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkClipRectCommand* cr =
|
|
|
|
(SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2);
|
2013-03-11 22:53:11 +00:00
|
|
|
|
|
|
|
if (SkRegion::kIntersect_Op != cr->op()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dbmr->dstRect() == cr->rect();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove everything but the drawBitmapRect
|
2013-04-01 18:18:49 +00:00
|
|
|
static void apply_4(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+3); // restore
|
|
|
|
// drawBitmapRectToRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+1); // clipRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand); // save
|
2013-03-11 22:53:11 +00:00
|
|
|
}
|
|
|
|
|
2013-03-17 18:46:16 +00:00
|
|
|
// Check for:
|
|
|
|
// TRANSLATE
|
|
|
|
// where the translate is zero
|
2013-04-01 18:18:49 +00:00
|
|
|
static bool check_5(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (TRANSLATE != canvas->getDrawCommandAt(curCommand)->getType()) {
|
2013-03-17 18:46:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkTranslateCommand* t =
|
|
|
|
(SkTranslateCommand*) canvas->getDrawCommandAt(curCommand);
|
2013-03-17 18:46:16 +00:00
|
|
|
|
|
|
|
return 0 == t->x() && 0 == t->y();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just remove the translate
|
2013-04-01 18:18:49 +00:00
|
|
|
static void apply_5(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
canvas->deleteDrawCommandAt(curCommand); // translate
|
2013-03-17 18:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for:
|
|
|
|
// SCALE
|
|
|
|
// where the scale is 1,1
|
2013-04-01 18:18:49 +00:00
|
|
|
static bool check_6(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (SCALE != canvas->getDrawCommandAt(curCommand)->getType()) {
|
2013-03-17 18:46:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkScaleCommand* s = (SkScaleCommand*) canvas->getDrawCommandAt(curCommand);
|
2013-03-17 18:46:16 +00:00
|
|
|
|
|
|
|
return SK_Scalar1 == s->x() && SK_Scalar1 == s->y();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just remove the scale
|
2013-04-01 18:18:49 +00:00
|
|
|
static void apply_6(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
canvas->deleteDrawCommandAt(curCommand); // scale
|
2013-03-17 18:46:16 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 12:25:25 +00:00
|
|
|
// Check for:
|
|
|
|
// SAVE
|
|
|
|
// CLIP_RECT
|
|
|
|
// SAVE_LAYER
|
|
|
|
// SAVE
|
|
|
|
// CLIP_RECT
|
|
|
|
// SAVE_LAYER
|
|
|
|
// SAVE
|
|
|
|
// CLIP_RECT
|
|
|
|
// DRAWBITMAPRECTTORECT
|
|
|
|
// RESTORE
|
|
|
|
// RESTORE
|
|
|
|
// RESTORE
|
|
|
|
// RESTORE
|
|
|
|
// RESTORE
|
|
|
|
// where:
|
|
|
|
// all the clipRect's are BW, nested, intersections
|
|
|
|
// the drawBitmapRectToRect is a 1-1 copy from src to dest
|
|
|
|
// the last (smallest) clip rect is a subset of the drawBitmapRectToRect's dest rect
|
|
|
|
// all the saveLayer's paints can be rolled into the drawBitmapRectToRect's paint
|
|
|
|
// This pattern is used by Google spreadsheet when drawing the toolbar buttons
|
2013-04-01 18:18:49 +00:00
|
|
|
static bool check_7(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
|
|
|
|
canvas->getSize() <= curCommand+13 ||
|
|
|
|
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
|
|
|
|
SAVE_LAYER != canvas->getDrawCommandAt(curCommand+2)->getType() ||
|
|
|
|
SAVE != canvas->getDrawCommandAt(curCommand+3)->getType() ||
|
|
|
|
CLIP_RECT != canvas->getDrawCommandAt(curCommand+4)->getType() ||
|
|
|
|
SAVE_LAYER != canvas->getDrawCommandAt(curCommand+5)->getType() ||
|
|
|
|
SAVE != canvas->getDrawCommandAt(curCommand+6)->getType() ||
|
|
|
|
CLIP_RECT != canvas->getDrawCommandAt(curCommand+7)->getType() ||
|
|
|
|
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+8)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+9)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+10)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+11)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+12)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+13)->getType()) {
|
2013-03-28 12:25:25 +00:00
|
|
|
return false;
|
2013-04-01 18:18:49 +00:00
|
|
|
}
|
2013-03-28 12:25:25 +00:00
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkClipRectCommand* clip0 =
|
|
|
|
(SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
|
|
|
SkSaveLayerCommand* saveLayer0 =
|
|
|
|
(SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand+2);
|
|
|
|
SkClipRectCommand* clip1 =
|
|
|
|
(SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+4);
|
|
|
|
SkSaveLayerCommand* saveLayer1 =
|
|
|
|
(SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand+5);
|
|
|
|
SkClipRectCommand* clip2 =
|
|
|
|
(SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+7);
|
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+8);
|
2013-03-28 12:25:25 +00:00
|
|
|
|
|
|
|
if (clip0->doAA() || clip1->doAA() || clip2->doAA()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SkRegion::kIntersect_Op != clip0->op() ||
|
|
|
|
SkRegion::kIntersect_Op != clip1->op() ||
|
|
|
|
SkRegion::kIntersect_Op != clip2->op()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-29 07:01:22 +00:00
|
|
|
if (!clip0->rect().contains(clip1->rect()) ||
|
2013-03-28 12:25:25 +00:00
|
|
|
!clip1->rect().contains(clip2->rect())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The src->dest mapping needs to be 1-to-1
|
|
|
|
if (NULL == dbmr->srcRect()) {
|
|
|
|
if (dbmr->bitmap().width() != dbmr->dstRect().width() ||
|
|
|
|
dbmr->bitmap().height() != dbmr->dstRect().height()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (dbmr->srcRect()->width() != dbmr->dstRect().width() ||
|
|
|
|
dbmr->srcRect()->height() != dbmr->dstRect().height()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dbmr->dstRect().contains(clip2->rect())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkPaint* saveLayerPaint0 = saveLayer0->paint();
|
|
|
|
const SkPaint* saveLayerPaint1 = saveLayer1->paint();
|
|
|
|
|
|
|
|
if ((NULL != saveLayerPaint0 && !is_simple(*saveLayerPaint0)) ||
|
|
|
|
(NULL != saveLayerPaint1 && !is_simple(*saveLayerPaint1))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint* dbmrPaint = dbmr->paint();
|
|
|
|
|
|
|
|
if (NULL == dbmrPaint) {
|
2013-03-29 07:01:22 +00:00
|
|
|
return true;
|
2013-03-28 12:25:25 +00:00
|
|
|
}
|
2013-03-29 07:01:22 +00:00
|
|
|
|
2013-03-28 12:25:25 +00:00
|
|
|
if (NULL != saveLayerPaint0) {
|
|
|
|
SkColor layerColor0 = saveLayerPaint0->getColor() | 0xFF000000; // force opaque
|
|
|
|
if (dbmrPaint->getColor() != layerColor0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL != saveLayerPaint1) {
|
|
|
|
SkColor layerColor1 = saveLayerPaint1->getColor() | 0xFF000000; // force opaque
|
|
|
|
if (dbmrPaint->getColor() != layerColor1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reduce to a single drawBitmapRectToRect call by folding the clipRect's into
|
|
|
|
// the src and dst Rects and the saveLayer paints into the drawBitmapRectToRect's
|
|
|
|
// paint.
|
2013-04-01 18:18:49 +00:00
|
|
|
static void apply_7(SkDebugCanvas* canvas, int curCommand) {
|
2013-06-18 20:20:55 +00:00
|
|
|
SkSaveLayerCommand* saveLayer0 =
|
|
|
|
(SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand+2);
|
|
|
|
SkSaveLayerCommand* saveLayer1 =
|
|
|
|
(SkSaveLayerCommand*) canvas->getDrawCommandAt(curCommand+5);
|
|
|
|
SkClipRectCommand* clip2 =
|
|
|
|
(SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+7);
|
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+8);
|
2013-03-28 12:25:25 +00:00
|
|
|
|
|
|
|
SkScalar newSrcLeft = dbmr->srcRect()->fLeft + clip2->rect().fLeft - dbmr->dstRect().fLeft;
|
|
|
|
SkScalar newSrcTop = dbmr->srcRect()->fTop + clip2->rect().fTop - dbmr->dstRect().fTop;
|
|
|
|
|
2013-03-29 07:01:22 +00:00
|
|
|
SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop,
|
2013-03-28 12:25:25 +00:00
|
|
|
clip2->rect().width(), clip2->rect().height());
|
|
|
|
|
|
|
|
dbmr->setSrcRect(newSrc);
|
|
|
|
dbmr->setDstRect(clip2->rect());
|
|
|
|
|
|
|
|
SkColor color = 0xFF000000;
|
|
|
|
int a0, a1;
|
|
|
|
|
|
|
|
const SkPaint* saveLayerPaint0 = saveLayer0->paint();
|
|
|
|
if (NULL != saveLayerPaint0) {
|
|
|
|
color = saveLayerPaint0->getColor();
|
|
|
|
a0 = SkColorGetA(color);
|
|
|
|
} else {
|
|
|
|
a0 = 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkPaint* saveLayerPaint1 = saveLayer1->paint();
|
|
|
|
if (NULL != saveLayerPaint1) {
|
|
|
|
color = saveLayerPaint1->getColor();
|
|
|
|
a1 = SkColorGetA(color);
|
|
|
|
} else {
|
|
|
|
a1 = 0xFF;
|
|
|
|
}
|
|
|
|
|
2013-04-02 15:30:03 +00:00
|
|
|
int newA = SkMulDiv255Round(a0, a1);
|
2013-03-28 12:25:25 +00:00
|
|
|
SkASSERT(newA <= 0xFF);
|
|
|
|
|
|
|
|
SkPaint* dbmrPaint = dbmr->paint();
|
|
|
|
|
|
|
|
if (NULL != dbmrPaint) {
|
|
|
|
SkColor newColor = SkColorSetA(dbmrPaint->getColor(), newA);
|
|
|
|
dbmrPaint->setColor(newColor);
|
|
|
|
} else {
|
|
|
|
SkColor newColor = SkColorSetA(color, newA);
|
|
|
|
|
|
|
|
SkPaint newPaint;
|
|
|
|
newPaint.setColor(newColor);
|
|
|
|
dbmr->setPaint(newPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove everything except the drawbitmaprect
|
2013-04-01 18:18:49 +00:00
|
|
|
canvas->deleteDrawCommandAt(curCommand+13); // restore
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+12); // restore
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+11); // restore
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+10); // restore
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+9); // restore
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+7); // clipRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+6); // save
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+5); // saveLayer
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+4); // clipRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+3); // save
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+2); // saveLayer
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+1); // clipRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand); // save
|
2013-03-28 12:25:25 +00:00
|
|
|
}
|
2013-03-17 18:46:16 +00:00
|
|
|
|
2013-04-01 21:00:27 +00:00
|
|
|
// Check for:
|
|
|
|
// SAVE
|
|
|
|
// CLIP_RECT
|
|
|
|
// DRAWBITMAPRECTTORECT
|
|
|
|
// RESTORE
|
|
|
|
// where:
|
|
|
|
// the drawBitmapRectToRect is a 1-1 copy from src to dest
|
|
|
|
// the clip rect is BW and a subset of the drawBitmapRectToRect's dest rect
|
|
|
|
static bool check_8(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
|
|
|
|
canvas->getSize() <= curCommand+4 ||
|
|
|
|
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
|
|
|
|
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkClipRectCommand* clip =
|
|
|
|
(SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2);
|
2013-04-01 21:00:27 +00:00
|
|
|
|
|
|
|
if (clip->doAA() || SkRegion::kIntersect_Op != clip->op()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The src->dest mapping needs to be 1-to-1
|
|
|
|
if (NULL == dbmr->srcRect()) {
|
|
|
|
if (dbmr->bitmap().width() != dbmr->dstRect().width() ||
|
|
|
|
dbmr->bitmap().height() != dbmr->dstRect().height()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (dbmr->srcRect()->width() != dbmr->dstRect().width() ||
|
|
|
|
dbmr->srcRect()->height() != dbmr->dstRect().height()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dbmr->dstRect().contains(clip->rect())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fold the clipRect into the drawBitmapRectToRect's src and dest rects
|
|
|
|
static void apply_8(SkDebugCanvas* canvas, int curCommand) {
|
2013-06-18 20:20:55 +00:00
|
|
|
SkClipRectCommand* clip =
|
|
|
|
(SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2);
|
2013-04-01 21:00:27 +00:00
|
|
|
|
|
|
|
SkScalar newSrcLeft, newSrcTop;
|
|
|
|
|
|
|
|
if (NULL != dbmr->srcRect()) {
|
|
|
|
newSrcLeft = dbmr->srcRect()->fLeft + clip->rect().fLeft - dbmr->dstRect().fLeft;
|
|
|
|
newSrcTop = dbmr->srcRect()->fTop + clip->rect().fTop - dbmr->dstRect().fTop;
|
|
|
|
} else {
|
|
|
|
newSrcLeft = clip->rect().fLeft - dbmr->dstRect().fLeft;
|
|
|
|
newSrcTop = clip->rect().fTop - dbmr->dstRect().fTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRect newSrc = SkRect::MakeXYWH(newSrcLeft, newSrcTop,
|
|
|
|
clip->rect().width(), clip->rect().height());
|
|
|
|
|
|
|
|
dbmr->setSrcRect(newSrc);
|
|
|
|
dbmr->setDstRect(clip->rect());
|
|
|
|
|
|
|
|
// remove everything except the drawbitmaprect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+3);
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+1);
|
|
|
|
canvas->deleteDrawCommandAt(curCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for:
|
|
|
|
// SAVE
|
|
|
|
// CLIP_RECT
|
|
|
|
// DRAWBITMAPRECTTORECT
|
|
|
|
// RESTORE
|
|
|
|
// where:
|
|
|
|
// clipRect is BW and encloses the DBMR2R's dest rect
|
|
|
|
static bool check_9(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
if (SAVE != canvas->getDrawCommandAt(curCommand)->getType() ||
|
|
|
|
canvas->getSize() <= curCommand+4 ||
|
|
|
|
CLIP_RECT != canvas->getDrawCommandAt(curCommand+1)->getType() ||
|
|
|
|
DRAW_BITMAP_RECT_TO_RECT != canvas->getDrawCommandAt(curCommand+2)->getType() ||
|
|
|
|
RESTORE != canvas->getDrawCommandAt(curCommand+3)->getType()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkClipRectCommand* clip =
|
|
|
|
(SkClipRectCommand*) canvas->getDrawCommandAt(curCommand+1);
|
|
|
|
SkDrawBitmapRectCommand* dbmr =
|
|
|
|
(SkDrawBitmapRectCommand*) canvas->getDrawCommandAt(curCommand+2);
|
2013-04-01 21:00:27 +00:00
|
|
|
|
|
|
|
if (clip->doAA() || SkRegion::kIntersect_Op != clip->op()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!clip->rect().contains(dbmr->dstRect())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove everything except the drawbitmaprect
|
|
|
|
static void apply_9(SkDebugCanvas* canvas, int curCommand) {
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+3); // restore
|
|
|
|
// drawBitmapRectToRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand+1); // clipRect
|
|
|
|
canvas->deleteDrawCommandAt(curCommand); // save
|
|
|
|
}
|
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
typedef bool (*PFCheck)(SkDebugCanvas* canvas, int curCommand);
|
|
|
|
typedef void (*PFApply)(SkDebugCanvas* canvas, int curCommand);
|
2013-02-05 20:51:49 +00:00
|
|
|
|
|
|
|
struct OptTableEntry {
|
|
|
|
PFCheck fCheck;
|
|
|
|
PFApply fApply;
|
|
|
|
int fNumTimesApplied;
|
|
|
|
} gOptTable[] = {
|
|
|
|
{ check_0, apply_0, 0 },
|
|
|
|
{ check_1, apply_1, 0 },
|
2013-03-11 22:53:11 +00:00
|
|
|
{ check_2, apply_2, 0 },
|
|
|
|
{ check_3, apply_3, 0 },
|
|
|
|
{ check_4, apply_4, 0 },
|
2013-03-17 18:46:16 +00:00
|
|
|
{ check_5, apply_5, 0 },
|
|
|
|
{ check_6, apply_6, 0 },
|
2013-03-28 12:25:25 +00:00
|
|
|
{ check_7, apply_7, 0 },
|
2013-04-01 21:00:27 +00:00
|
|
|
{ check_8, apply_8, 0 },
|
|
|
|
{ check_9, apply_9, 0 },
|
2013-02-05 20:51:49 +00:00
|
|
|
};
|
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
|
2013-01-31 15:56:22 +00:00
|
|
|
static int filter_picture(const SkString& inFile, const SkString& outFile) {
|
2013-05-10 14:51:54 +00:00
|
|
|
SkAutoTDelete<SkPicture> inPicture;
|
2012-11-13 18:50:33 +00:00
|
|
|
|
|
|
|
SkFILEStream inStream(inFile.c_str());
|
|
|
|
if (inStream.isValid()) {
|
2013-06-28 21:32:00 +00:00
|
|
|
inPicture.reset(SkPicture::CreateFromStream(&inStream));
|
2012-11-13 18:50:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 14:51:54 +00:00
|
|
|
if (NULL == inPicture.get()) {
|
2012-11-13 18:50:33 +00:00
|
|
|
SkDebugf("Could not read file %s\n", inFile.c_str());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-02-05 20:51:49 +00:00
|
|
|
int localCount[SK_ARRAY_COUNT(gOptTable)];
|
|
|
|
|
|
|
|
memset(localCount, 0, sizeof(localCount));
|
|
|
|
|
2013-01-31 15:56:22 +00:00
|
|
|
SkDebugCanvas debugCanvas(inPicture->width(), inPicture->height());
|
|
|
|
debugCanvas.setBounds(inPicture->width(), inPicture->height());
|
|
|
|
inPicture->draw(&debugCanvas);
|
|
|
|
|
2013-04-01 18:18:49 +00:00
|
|
|
// delete the initial save and restore since replaying the commands will
|
2013-02-05 20:51:49 +00:00
|
|
|
// re-add them
|
2013-04-01 18:18:49 +00:00
|
|
|
if (debugCanvas.getSize() > 1) {
|
|
|
|
debugCanvas.deleteDrawCommandAt(0);
|
|
|
|
debugCanvas.deleteDrawCommandAt(debugCanvas.getSize()-1);
|
2013-02-05 20:51:49 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 19:10:21 +00:00
|
|
|
bool changed = true;
|
2013-04-08 15:45:30 +00:00
|
|
|
int numBefore = debugCanvas.getSize();
|
2013-04-01 19:10:21 +00:00
|
|
|
|
|
|
|
while (changed) {
|
|
|
|
changed = false;
|
|
|
|
for (int i = 0; i < debugCanvas.getSize(); ++i) {
|
|
|
|
for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
|
|
|
|
if ((*gOptTable[opt].fCheck)(&debugCanvas, i)) {
|
|
|
|
(*gOptTable[opt].fApply)(&debugCanvas, i);
|
|
|
|
|
|
|
|
++gOptTable[opt].fNumTimesApplied;
|
|
|
|
++localCount[opt];
|
|
|
|
|
|
|
|
if (debugCanvas.getSize() == i) {
|
|
|
|
// the optimization removed all the remaining operations
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
opt = 0; // try all the opts all over again
|
|
|
|
changed = true;
|
|
|
|
}
|
2013-01-31 15:56:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-13 18:50:33 +00:00
|
|
|
|
2013-04-08 15:45:30 +00:00
|
|
|
int numAfter = debugCanvas.getSize();
|
|
|
|
|
2013-01-31 15:56:22 +00:00
|
|
|
if (!outFile.isEmpty()) {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-04-17 23:35:06 +00:00
|
|
|
SkCanvas* canvas = recorder.beginRecording(inPicture->width(), inPicture->height(), NULL, 0);
|
2013-01-31 15:56:22 +00:00
|
|
|
debugCanvas.draw(canvas);
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> outPicture(recorder.endRecording());
|
2012-11-13 18:50:33 +00:00
|
|
|
|
|
|
|
SkFILEWStream outStream(outFile.c_str());
|
|
|
|
|
2014-04-13 19:09:42 +00:00
|
|
|
outPicture->serialize(&outStream);
|
2012-11-13 18:50:33 +00:00
|
|
|
}
|
|
|
|
|
2013-02-05 20:51:49 +00:00
|
|
|
bool someOptFired = false;
|
|
|
|
for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
|
|
|
|
if (0 != localCount[opt]) {
|
|
|
|
SkDebugf("%d: %d ", opt, localCount[opt]);
|
|
|
|
someOptFired = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!someOptFired) {
|
|
|
|
SkDebugf("No opts fired\n");
|
|
|
|
} else {
|
2013-04-09 07:01:27 +00:00
|
|
|
SkDebugf("\t before: %d after: %d delta: %d\n",
|
2013-04-08 15:45:30 +00:00
|
|
|
numBefore, numAfter, numBefore-numAfter);
|
2013-02-05 20:51:49 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 18:50:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-08 14:41:10 +00:00
|
|
|
// This function is not marked as 'static' so it can be referenced externally
|
|
|
|
// in the iOS build.
|
2013-01-07 16:47:43 +00:00
|
|
|
int tool_main(int argc, char** argv); // suppress a warning on mac
|
|
|
|
|
2012-10-09 12:32:37 +00:00
|
|
|
int tool_main(int argc, char** argv) {
|
2013-05-10 14:51:54 +00:00
|
|
|
#if SK_ENABLE_INST_COUNT
|
|
|
|
gPrintInstCount = true;
|
|
|
|
#endif
|
|
|
|
|
2012-10-04 13:00:33 +00:00
|
|
|
SkGraphics::Init();
|
|
|
|
|
2012-10-19 19:06:11 +00:00
|
|
|
if (argc < 3) {
|
2012-10-04 13:00:33 +00:00
|
|
|
usage();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-01-31 15:56:22 +00:00
|
|
|
SkString inFile, outFile, inDir, outDir;
|
2012-10-19 19:06:11 +00:00
|
|
|
|
2012-10-04 13:00:33 +00:00
|
|
|
char* const* stop = argv + argc;
|
|
|
|
for (++argv; argv < stop; ++argv) {
|
|
|
|
if (strcmp(*argv, "-i") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
inFile.set(*argv);
|
|
|
|
} else {
|
2012-10-19 19:06:11 +00:00
|
|
|
SkDebugf("missing arg for -i\n");
|
2012-10-04 13:00:33 +00:00
|
|
|
usage();
|
|
|
|
return -1;
|
|
|
|
}
|
2012-11-13 18:50:33 +00:00
|
|
|
} else if (strcmp(*argv, "--input-dir") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
inDir.set(*argv);
|
|
|
|
} else {
|
|
|
|
SkDebugf("missing arg for --input-dir\n");
|
|
|
|
usage();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else if (strcmp(*argv, "--output-dir") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
outDir.set(*argv);
|
|
|
|
} else {
|
|
|
|
SkDebugf("missing arg for --output-dir\n");
|
|
|
|
usage();
|
|
|
|
return -1;
|
|
|
|
}
|
2012-10-04 13:00:33 +00:00
|
|
|
} else if (strcmp(*argv, "-o") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
outFile.set(*argv);
|
|
|
|
} else {
|
2012-10-19 19:06:11 +00:00
|
|
|
SkDebugf("missing arg for -o\n");
|
|
|
|
usage();
|
|
|
|
return -1;
|
|
|
|
}
|
2012-10-04 13:00:33 +00:00
|
|
|
} else if (strcmp(*argv, "--help") == 0 || strcmp(*argv, "-h") == 0) {
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
SkDebugf("unknown arg %s\n", *argv);
|
|
|
|
usage();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-13 18:50:33 +00:00
|
|
|
SkOSFile::Iter iter(inDir.c_str(), "skp");
|
2013-01-07 16:47:43 +00:00
|
|
|
|
2012-11-13 18:50:33 +00:00
|
|
|
SkString inputFilename, outputFilename;
|
|
|
|
if (iter.next(&inputFilename)) {
|
2012-10-04 13:00:33 +00:00
|
|
|
|
2012-11-13 18:50:33 +00:00
|
|
|
do {
|
|
|
|
sk_tools::make_filepath(&inFile, inDir, inputFilename);
|
|
|
|
if (!outDir.isEmpty()) {
|
|
|
|
sk_tools::make_filepath(&outFile, outDir, inputFilename);
|
|
|
|
}
|
|
|
|
SkDebugf("Executing %s\n", inputFilename.c_str());
|
2013-01-31 15:56:22 +00:00
|
|
|
filter_picture(inFile, outFile);
|
2012-11-13 18:50:33 +00:00
|
|
|
} while(iter.next(&inputFilename));
|
2012-10-04 13:00:33 +00:00
|
|
|
|
2012-11-13 18:50:33 +00:00
|
|
|
} else if (!inFile.isEmpty()) {
|
2013-01-31 15:56:22 +00:00
|
|
|
filter_picture(inFile, outFile);
|
2012-11-13 18:50:33 +00:00
|
|
|
} else {
|
|
|
|
usage();
|
2012-10-04 13:00:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-02-05 20:51:49 +00:00
|
|
|
for (size_t opt = 0; opt < SK_ARRAY_COUNT(gOptTable); ++opt) {
|
|
|
|
SkDebugf("opt %d: %d\n", opt, gOptTable[opt].fNumTimesApplied);
|
|
|
|
}
|
|
|
|
|
2012-10-04 13:00:33 +00:00
|
|
|
SkGraphics::Term();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
|
|
int main(int argc, char * const argv[]) {
|
2012-10-09 12:32:37 +00:00
|
|
|
return tool_main(argc, (char**) argv);
|
2012-10-04 13:00:33 +00:00
|
|
|
}
|
|
|
|
#endif
|