2012-06-29 14:21:22 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "SkDrawCommand.h"
|
2016-02-17 19:20:26 +00:00
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkDashPathEffect.h"
|
|
|
|
#include "SkImageFilter.h"
|
|
|
|
#include "SkMaskFilter.h"
|
2012-06-29 14:21:22 +00:00
|
|
|
#include "SkObjectParser.h"
|
2016-02-10 13:40:46 +00:00
|
|
|
#include "SkPaintDefaults.h"
|
|
|
|
#include "SkPathEffect.h"
|
2015-02-13 19:13:00 +00:00
|
|
|
#include "SkPicture.h"
|
2014-08-26 14:56:44 +00:00
|
|
|
#include "SkTextBlob.h"
|
2015-12-09 02:59:18 +00:00
|
|
|
#include "SkTextBlobRunIterator.h"
|
2016-02-10 13:40:46 +00:00
|
|
|
#include "SkTHash.h"
|
|
|
|
#include "SkTypeface.h"
|
|
|
|
#include "SkValidatingReadBuffer.h"
|
|
|
|
#include "SkWriteBuffer.h"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_COMMAND "command"
|
2016-02-23 14:53:37 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_VISIBLE "visible"
|
2016-02-10 13:40:46 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_MATRIX "matrix"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_PAINT "paint"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_OUTER "outer"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_INNER "inner"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_MODE "mode"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_POINTS "points"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_PATH "path"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_TEXT "text"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_COLOR "color"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_ALPHA "alpha"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_STYLE "style"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH "strokeWidth"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER "strokeMiter"
|
2016-02-10 22:05:02 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN "strokeJoin"
|
2016-02-10 13:40:46 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_CAP "cap"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS "antiAlias"
|
2016-02-10 22:05:02 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_DITHER "dither"
|
2016-02-10 13:40:46 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_REGION "region"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_REGIONOP "op"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_EDGESTYLE "edgeStyle"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_DEVICEREGION "deviceRegion"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_BLUR "blur"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_SIGMA "sigma"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_QUALITY "quality"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN "textAlign"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE "textSize"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX "textScaleX"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX "textSkewX"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_DASHING "dashing"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_INTERVALS "intervals"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_PHASE "phase"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE "fillType"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_VERBS "verbs"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_NAME "name"
|
2016-02-11 18:35:21 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_DATA "data"
|
2016-02-10 13:40:46 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_SHADER "shader"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT "pathEffect"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER "maskFilter"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_XFERMODE "xfermode"
|
2016-02-10 22:05:02 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_LOOPER "looper"
|
2016-02-10 13:40:46 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_BACKDROP "backdrop"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER "colorfilter"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER "imagefilter"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_IMAGE "image"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_BITMAP "bitmap"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_SRC "src"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_DST "dst"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_CENTER "center"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_STRICT "strict"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_DESCRIPTION "description"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_X "x"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_Y "y"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_RUNS "runs"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_POSITIONS "positions"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_GLYPHS "glyphs"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_FONT "font"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE "typeface"
|
2016-02-10 22:05:02 +00:00
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_CUBICS "cubics"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_COLORS "colors"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_TEXTURECOORDS "textureCoords"
|
|
|
|
#define SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY "filterQuality"
|
2016-02-10 13:40:46 +00:00
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_VERB_MOVE "move"
|
|
|
|
#define SKDEBUGCANVAS_VERB_LINE "line"
|
|
|
|
#define SKDEBUGCANVAS_VERB_QUAD "quad"
|
|
|
|
#define SKDEBUGCANVAS_VERB_CUBIC "cubic"
|
|
|
|
#define SKDEBUGCANVAS_VERB_CONIC "conic"
|
|
|
|
#define SKDEBUGCANVAS_VERB_CLOSE "close"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_STYLE_FILL "fill"
|
|
|
|
#define SKDEBUGCANVAS_STYLE_STROKE "stroke"
|
|
|
|
#define SKDEBUGCANVAS_STYLE_STROKEANDFILL "strokeAndFill"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_POINTMODE_POINTS "points"
|
|
|
|
#define SKDEBUGCANVAS_POINTMODE_LINES "lines"
|
|
|
|
#define SKDEBUGCANVAS_POINTMODE_POLYGON "polygon"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_REGIONOP_DIFFERENCE "difference"
|
|
|
|
#define SKDEBUGCANVAS_REGIONOP_INTERSECT "intersect"
|
|
|
|
#define SKDEBUGCANVAS_REGIONOP_UNION "union"
|
|
|
|
#define SKDEBUGCANVAS_REGIONOP_XOR "xor"
|
|
|
|
#define SKDEBUGCANVAS_REGIONOP_REVERSE_DIFFERENCE "reverseDifference"
|
|
|
|
#define SKDEBUGCANVAS_REGIONOP_REPLACE "replace"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_BLURSTYLE_NORMAL "normal"
|
|
|
|
#define SKDEBUGCANVAS_BLURSTYLE_SOLID "solid"
|
|
|
|
#define SKDEBUGCANVAS_BLURSTYLE_OUTER "outer"
|
|
|
|
#define SKDEBUGCANVAS_BLURSTYLE_INNER "inner"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_BLURQUALITY_LOW "low"
|
|
|
|
#define SKDEBUGCANVAS_BLURQUALITY_HIGH "high"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_ALIGN_LEFT "left"
|
|
|
|
#define SKDEBUGCANVAS_ALIGN_CENTER "center"
|
|
|
|
#define SKDEBUGCANVAS_ALIGN_RIGHT "right"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_FILLTYPE_WINDING "winding"
|
|
|
|
#define SKDEBUGCANVAS_FILLTYPE_EVENODD "evenOdd"
|
|
|
|
#define SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING "inverseWinding"
|
|
|
|
#define SKDEBUGCANVAS_FILLTYPE_INVERSEEVENODD "inverseEvenOdd"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_CAP_BUTT "butt"
|
|
|
|
#define SKDEBUGCANVAS_CAP_ROUND "round"
|
|
|
|
#define SKDEBUGCANVAS_CAP_SQUARE "square"
|
|
|
|
|
2016-02-10 22:05:02 +00:00
|
|
|
#define SKDEBUGCANVAS_MITER_JOIN "miter"
|
|
|
|
#define SKDEBUGCANVAS_ROUND_JOIN "round"
|
|
|
|
#define SKDEBUGCANVAS_BEVEL_JOIN "bevel"
|
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
#define SKDEBUGCANVAS_COLORTYPE_ARGB4444 "ARGB4444"
|
|
|
|
#define SKDEBUGCANVAS_COLORTYPE_RGBA8888 "RGBA8888"
|
|
|
|
#define SKDEBUGCANVAS_COLORTYPE_BGRA8888 "BGRA8888"
|
|
|
|
#define SKDEBUGCANVAS_COLORTYPE_565 "565"
|
|
|
|
#define SKDEBUGCANVAS_COLORTYPE_GRAY8 "Gray8"
|
|
|
|
#define SKDEBUGCANVAS_COLORTYPE_INDEX8 "Index8"
|
|
|
|
#define SKDEBUGCANVAS_COLORTYPE_ALPHA8 "Alpha8"
|
|
|
|
|
|
|
|
#define SKDEBUGCANVAS_ALPHATYPE_OPAQUE "opaque"
|
|
|
|
#define SKDEBUGCANVAS_ALPHATYPE_PREMUL "premul"
|
|
|
|
#define SKDEBUGCANVAS_ALPHATYPE_UNPREMUL "unpremul"
|
|
|
|
|
2016-02-10 22:05:02 +00:00
|
|
|
#define SKDEBUGCANVAS_FILTERQUALITY_NONE "none"
|
|
|
|
#define SKDEBUGCANVAS_FILTERQUALITY_LOW "low"
|
|
|
|
#define SKDEBUGCANVAS_FILTERQUALITY_MEDIUM "medium"
|
|
|
|
#define SKDEBUGCANVAS_FILTERQUALITY_HIGH "high"
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
typedef SkDrawCommand* (*FROM_JSON)(Json::Value&, UrlDataManager&);
|
2014-08-26 14:56:44 +00:00
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
// TODO(chudy): Refactor into non subclass model.
|
|
|
|
|
2015-02-13 19:13:00 +00:00
|
|
|
SkDrawCommand::SkDrawCommand(OpType type)
|
|
|
|
: fOpType(type)
|
2013-05-29 13:24:23 +00:00
|
|
|
, fVisible(true) {
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
SkDrawCommand::~SkDrawCommand() {
|
2012-08-07 20:41:37 +00:00
|
|
|
fInfo.deleteAll();
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 19:13:00 +00:00
|
|
|
const char* SkDrawCommand::GetCommandString(OpType type) {
|
2012-06-29 14:21:22 +00:00
|
|
|
switch (type) {
|
2015-04-02 03:58:37 +00:00
|
|
|
case kBeginDrawPicture_OpType: return "BeginDrawPicture";
|
2015-02-13 19:13:00 +00:00
|
|
|
case kClipPath_OpType: return "ClipPath";
|
|
|
|
case kClipRegion_OpType: return "ClipRegion";
|
|
|
|
case kClipRect_OpType: return "ClipRect";
|
|
|
|
case kClipRRect_OpType: return "ClipRRect";
|
|
|
|
case kConcat_OpType: return "Concat";
|
|
|
|
case kDrawBitmap_OpType: return "DrawBitmap";
|
|
|
|
case kDrawBitmapNine_OpType: return "DrawBitmapNine";
|
|
|
|
case kDrawBitmapRect_OpType: return "DrawBitmapRect";
|
|
|
|
case kDrawClear_OpType: return "DrawClear";
|
|
|
|
case kDrawDRRect_OpType: return "DrawDRRect";
|
2015-07-22 17:23:01 +00:00
|
|
|
case kDrawImage_OpType: return "DrawImage";
|
|
|
|
case kDrawImageRect_OpType: return "DrawImageRect";
|
2015-02-13 19:13:00 +00:00
|
|
|
case kDrawOval_OpType: return "DrawOval";
|
|
|
|
case kDrawPaint_OpType: return "DrawPaint";
|
|
|
|
case kDrawPatch_OpType: return "DrawPatch";
|
|
|
|
case kDrawPath_OpType: return "DrawPath";
|
|
|
|
case kDrawPoints_OpType: return "DrawPoints";
|
|
|
|
case kDrawPosText_OpType: return "DrawPosText";
|
|
|
|
case kDrawPosTextH_OpType: return "DrawPosTextH";
|
|
|
|
case kDrawRect_OpType: return "DrawRect";
|
|
|
|
case kDrawRRect_OpType: return "DrawRRect";
|
|
|
|
case kDrawText_OpType: return "DrawText";
|
|
|
|
case kDrawTextBlob_OpType: return "DrawTextBlob";
|
|
|
|
case kDrawTextOnPath_OpType: return "DrawTextOnPath";
|
|
|
|
case kDrawVertices_OpType: return "DrawVertices";
|
2015-04-02 03:58:37 +00:00
|
|
|
case kEndDrawPicture_OpType: return "EndDrawPicture";
|
2015-02-13 19:13:00 +00:00
|
|
|
case kRestore_OpType: return "Restore";
|
|
|
|
case kSave_OpType: return "Save";
|
|
|
|
case kSaveLayer_OpType: return "SaveLayer";
|
|
|
|
case kSetMatrix_OpType: return "SetMatrix";
|
2012-06-29 14:21:22 +00:00
|
|
|
default:
|
2015-02-13 19:13:00 +00:00
|
|
|
SkDebugf("OpType error 0x%08x\n", type);
|
2012-06-29 14:21:22 +00:00
|
|
|
SkASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SkDEBUGFAIL("DrawType UNUSED\n");
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
SkString SkDrawCommand::toString() const {
|
2015-02-13 19:13:00 +00:00
|
|
|
return SkString(GetCommandString(fOpType));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawCommand::toJSON(UrlDataManager& urlDataManager) const {
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value result;
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COMMAND] = this->GetCommandString(fOpType);
|
2016-02-23 14:53:37 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_VISIBLE] = Json::Value(this->isVisible());
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define INSTALL_FACTORY(name) factories.set(SkString(GetCommandString(k ## name ##_OpType)), \
|
|
|
|
(FROM_JSON) Sk ## name ## Command::fromJSON)
|
2016-02-11 18:35:21 +00:00
|
|
|
SkDrawCommand* SkDrawCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
static SkTHashMap<SkString, FROM_JSON> factories;
|
|
|
|
static bool initialized = false;
|
|
|
|
if (!initialized) {
|
|
|
|
initialized = true;
|
|
|
|
INSTALL_FACTORY(Restore);
|
|
|
|
INSTALL_FACTORY(ClipPath);
|
|
|
|
INSTALL_FACTORY(ClipRegion);
|
|
|
|
INSTALL_FACTORY(ClipRect);
|
|
|
|
INSTALL_FACTORY(ClipRRect);
|
|
|
|
INSTALL_FACTORY(Concat);
|
|
|
|
INSTALL_FACTORY(DrawBitmap);
|
|
|
|
INSTALL_FACTORY(DrawBitmapRect);
|
|
|
|
INSTALL_FACTORY(DrawBitmapNine);
|
|
|
|
INSTALL_FACTORY(DrawImage);
|
|
|
|
INSTALL_FACTORY(DrawImageRect);
|
|
|
|
INSTALL_FACTORY(DrawOval);
|
|
|
|
INSTALL_FACTORY(DrawPaint);
|
|
|
|
INSTALL_FACTORY(DrawPath);
|
|
|
|
INSTALL_FACTORY(DrawPoints);
|
|
|
|
INSTALL_FACTORY(DrawText);
|
|
|
|
INSTALL_FACTORY(DrawPosText);
|
2016-03-09 15:42:54 +00:00
|
|
|
INSTALL_FACTORY(DrawPosTextH);
|
2016-02-10 13:40:46 +00:00
|
|
|
INSTALL_FACTORY(DrawTextOnPath);
|
|
|
|
INSTALL_FACTORY(DrawTextBlob);
|
|
|
|
|
|
|
|
INSTALL_FACTORY(DrawRect);
|
|
|
|
INSTALL_FACTORY(DrawRRect);
|
|
|
|
INSTALL_FACTORY(DrawDRRect);
|
2016-02-10 22:05:02 +00:00
|
|
|
INSTALL_FACTORY(DrawPatch);
|
2016-02-10 13:40:46 +00:00
|
|
|
INSTALL_FACTORY(Save);
|
|
|
|
INSTALL_FACTORY(SaveLayer);
|
|
|
|
INSTALL_FACTORY(SetMatrix);
|
|
|
|
}
|
|
|
|
SkString name = SkString(command[SKDEBUGCANVAS_ATTRIBUTE_COMMAND].asCString());
|
|
|
|
FROM_JSON* factory = factories.find(name);
|
|
|
|
if (factory == nullptr) {
|
|
|
|
SkDebugf("no JSON factory for '%s'\n", name.c_str());
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-02-11 18:35:21 +00:00
|
|
|
return (*factory)(command, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-06 23:59:28 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) {
|
|
|
|
const SkISize& size = canvas->getDeviceSize();
|
|
|
|
|
|
|
|
static const SkScalar kInsetFrac = 0.9f; // Leave a border around object
|
|
|
|
|
|
|
|
canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f);
|
|
|
|
if (bounds.width() > bounds.height()) {
|
|
|
|
canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()),
|
|
|
|
SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width()));
|
|
|
|
} else {
|
|
|
|
canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()),
|
|
|
|
SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height()));
|
|
|
|
}
|
|
|
|
canvas->translate(-bounds.centerX(), -bounds.centerY());
|
|
|
|
}
|
2013-06-07 07:01:06 +00:00
|
|
|
|
2013-06-06 23:59:28 +00:00
|
|
|
|
|
|
|
void render_path(SkCanvas* canvas, const SkPath& path) {
|
|
|
|
canvas->clear(0xFFFFFFFF);
|
|
|
|
|
|
|
|
const SkRect& bounds = path.getBounds();
|
2015-10-06 14:24:03 +00:00
|
|
|
if (bounds.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-06-06 23:59:28 +00:00
|
|
|
|
2015-10-06 14:24:03 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
2013-06-06 23:59:28 +00:00
|
|
|
xlate_and_scale_to_bounds(canvas, bounds);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->drawPath(path, p);
|
|
|
|
}
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = nullptr) {
|
2013-06-06 23:59:28 +00:00
|
|
|
const SkISize& size = canvas->getDeviceSize();
|
|
|
|
|
|
|
|
SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width();
|
|
|
|
SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height();
|
|
|
|
|
|
|
|
if (input.width() > input.height()) {
|
|
|
|
yScale *= input.height() / (float) input.width();
|
|
|
|
} else {
|
|
|
|
xScale *= input.width() / (float) input.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1,
|
|
|
|
xScale * input.width(),
|
|
|
|
yScale * input.height());
|
2013-06-07 07:01:06 +00:00
|
|
|
|
2015-09-24 13:56:27 +00:00
|
|
|
static const int kNumBlocks = 8;
|
|
|
|
|
2013-06-06 23:59:28 +00:00
|
|
|
canvas->clear(0xFFFFFFFF);
|
2015-09-24 13:56:27 +00:00
|
|
|
SkISize block = {
|
|
|
|
canvas->imageInfo().width()/kNumBlocks,
|
|
|
|
canvas->imageInfo().height()/kNumBlocks
|
|
|
|
};
|
|
|
|
for (int y = 0; y < kNumBlocks; ++y) {
|
|
|
|
for (int x = 0; x < kNumBlocks; ++x) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor((x+y)%2 ? SK_ColorLTGRAY : SK_ColorDKGRAY);
|
|
|
|
SkRect r = SkRect::MakeXYWH(SkIntToScalar(x*block.width()),
|
|
|
|
SkIntToScalar(y*block.height()),
|
|
|
|
SkIntToScalar(block.width()),
|
|
|
|
SkIntToScalar(block.height()));
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:02:53 +00:00
|
|
|
canvas->drawBitmapRect(input, dst, nullptr);
|
2013-06-06 23:59:28 +00:00
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
if (srcRect) {
|
2013-06-06 23:59:28 +00:00
|
|
|
SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1,
|
|
|
|
srcRect->fTop * yScale + SK_Scalar1,
|
|
|
|
srcRect->fRight * xScale + SK_Scalar1,
|
|
|
|
srcRect->fBottom * yScale + SK_Scalar1);
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void render_rrect(SkCanvas* canvas, const SkRRect& rrect) {
|
|
|
|
canvas->clear(0xFFFFFFFF);
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
const SkRect& bounds = rrect.getBounds();
|
|
|
|
|
|
|
|
xlate_and_scale_to_bounds(canvas, bounds);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->drawRRect(rrect, p);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2013-06-07 07:01:06 +00:00
|
|
|
|
2014-02-24 17:28:55 +00:00
|
|
|
void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) {
|
|
|
|
canvas->clear(0xFFFFFFFF);
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
const SkRect& bounds = outer.getBounds();
|
|
|
|
|
|
|
|
xlate_and_scale_to_bounds(canvas, bounds);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->drawDRRect(outer, inner, p);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2013-06-06 23:59:28 +00:00
|
|
|
};
|
|
|
|
|
2016-02-10 22:05:02 +00:00
|
|
|
static Json::Value make_json_color(const SkColor color) {
|
|
|
|
Json::Value result(Json::arrayValue);
|
|
|
|
result.append(Json::Value(SkColorGetA(color)));
|
|
|
|
result.append(Json::Value(SkColorGetR(color)));
|
|
|
|
result.append(Json::Value(SkColorGetG(color)));
|
|
|
|
result.append(Json::Value(SkColorGetB(color)));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
static Json::Value make_json_point(const SkPoint& point) {
|
|
|
|
Json::Value result(Json::arrayValue);
|
|
|
|
result.append(Json::Value(point.x()));
|
|
|
|
result.append(Json::Value(point.y()));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Json::Value make_json_point(SkScalar x, SkScalar y) {
|
|
|
|
Json::Value result(Json::arrayValue);
|
|
|
|
result.append(Json::Value(x));
|
|
|
|
result.append(Json::Value(y));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Json::Value make_json_rect(const SkRect& rect) {
|
|
|
|
Json::Value result(Json::arrayValue);
|
|
|
|
result.append(Json::Value(rect.left()));
|
|
|
|
result.append(Json::Value(rect.top()));
|
|
|
|
result.append(Json::Value(rect.right()));
|
|
|
|
result.append(Json::Value(rect.bottom()));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-03 19:39:38 +00:00
|
|
|
Json::Value SkDrawCommand::MakeJsonIRect(const SkIRect& rect) {
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value result(Json::arrayValue);
|
|
|
|
result.append(Json::Value(rect.left()));
|
|
|
|
result.append(Json::Value(rect.top()));
|
|
|
|
result.append(Json::Value(rect.right()));
|
|
|
|
result.append(Json::Value(rect.bottom()));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Json::Value make_json_rrect(const SkRRect& rrect) {
|
|
|
|
Json::Value result(Json::arrayValue);
|
|
|
|
result.append(make_json_rect(rrect.rect()));
|
|
|
|
result.append(make_json_point(rrect.radii(SkRRect::kUpperLeft_Corner)));
|
|
|
|
result.append(make_json_point(rrect.radii(SkRRect::kUpperRight_Corner)));
|
|
|
|
result.append(make_json_point(rrect.radii(SkRRect::kLowerRight_Corner)));
|
|
|
|
result.append(make_json_point(rrect.radii(SkRRect::kLowerLeft_Corner)));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-03 19:39:38 +00:00
|
|
|
Json::Value SkDrawCommand::MakeJsonMatrix(const SkMatrix& matrix) {
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value result(Json::arrayValue);
|
|
|
|
Json::Value row1(Json::arrayValue);
|
|
|
|
row1.append(Json::Value(matrix[0]));
|
|
|
|
row1.append(Json::Value(matrix[1]));
|
|
|
|
row1.append(Json::Value(matrix[2]));
|
|
|
|
result.append(row1);
|
|
|
|
Json::Value row2(Json::arrayValue);
|
|
|
|
row2.append(Json::Value(matrix[3]));
|
|
|
|
row2.append(Json::Value(matrix[4]));
|
|
|
|
row2.append(Json::Value(matrix[5]));
|
|
|
|
result.append(row2);
|
|
|
|
Json::Value row3(Json::arrayValue);
|
|
|
|
row3.append(Json::Value(matrix[6]));
|
|
|
|
row3.append(Json::Value(matrix[7]));
|
|
|
|
row3.append(Json::Value(matrix[8]));
|
|
|
|
result.append(row3);
|
|
|
|
return result;
|
|
|
|
}
|
2016-02-10 22:05:02 +00:00
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
static Json::Value make_json_path(const SkPath& path) {
|
|
|
|
Json::Value result(Json::objectValue);
|
|
|
|
switch (path.getFillType()) {
|
|
|
|
case SkPath::kWinding_FillType:
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_WINDING;
|
|
|
|
break;
|
|
|
|
case SkPath::kEvenOdd_FillType:
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_EVENODD;
|
|
|
|
break;
|
|
|
|
case SkPath::kInverseWinding_FillType:
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING;
|
|
|
|
break;
|
|
|
|
case SkPath::kInverseEvenOdd_FillType:
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_INVERSEEVENODD;
|
|
|
|
break;
|
2016-03-29 16:03:52 +00:00
|
|
|
}
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value verbs(Json::arrayValue);
|
|
|
|
SkPath::Iter iter(path, false);
|
|
|
|
SkPoint pts[4];
|
|
|
|
SkPath::Verb verb;
|
|
|
|
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
|
|
|
|
switch (verb) {
|
|
|
|
case SkPath::kLine_Verb: {
|
|
|
|
Json::Value line(Json::objectValue);
|
|
|
|
line[SKDEBUGCANVAS_VERB_LINE] = make_json_point(pts[1]);
|
|
|
|
verbs.append(line);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kQuad_Verb: {
|
|
|
|
Json::Value quad(Json::objectValue);
|
|
|
|
Json::Value coords(Json::arrayValue);
|
|
|
|
coords.append(make_json_point(pts[1]));
|
|
|
|
coords.append(make_json_point(pts[2]));
|
|
|
|
quad[SKDEBUGCANVAS_VERB_QUAD] = coords;
|
|
|
|
verbs.append(quad);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kCubic_Verb: {
|
|
|
|
Json::Value cubic(Json::objectValue);
|
|
|
|
Json::Value coords(Json::arrayValue);
|
|
|
|
coords.append(make_json_point(pts[1]));
|
|
|
|
coords.append(make_json_point(pts[2]));
|
|
|
|
coords.append(make_json_point(pts[3]));
|
|
|
|
cubic[SKDEBUGCANVAS_VERB_CUBIC] = coords;
|
|
|
|
verbs.append(cubic);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kConic_Verb: {
|
|
|
|
Json::Value conic(Json::objectValue);
|
|
|
|
Json::Value coords(Json::arrayValue);
|
|
|
|
coords.append(make_json_point(pts[1]));
|
|
|
|
coords.append(make_json_point(pts[2]));
|
|
|
|
coords.append(Json::Value(iter.conicWeight()));
|
|
|
|
conic[SKDEBUGCANVAS_VERB_CONIC] = coords;
|
|
|
|
verbs.append(conic);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kMove_Verb: {
|
|
|
|
Json::Value move(Json::objectValue);
|
|
|
|
move[SKDEBUGCANVAS_VERB_MOVE] = make_json_point(pts[0]);
|
|
|
|
verbs.append(move);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPath::kClose_Verb:
|
|
|
|
verbs.append(Json::Value(SKDEBUGCANVAS_VERB_CLOSE));
|
|
|
|
break;
|
|
|
|
case SkPath::kDone_Verb:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_VERBS] = verbs;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Json::Value make_json_region(const SkRegion& region) {
|
|
|
|
return Json::Value("<unimplemented>");
|
|
|
|
}
|
|
|
|
|
|
|
|
static Json::Value make_json_regionop(SkRegion::Op op) {
|
|
|
|
switch (op) {
|
|
|
|
case SkRegion::kDifference_Op:
|
|
|
|
return Json::Value(SKDEBUGCANVAS_REGIONOP_DIFFERENCE);
|
|
|
|
case SkRegion::kIntersect_Op:
|
|
|
|
return Json::Value(SKDEBUGCANVAS_REGIONOP_INTERSECT);
|
|
|
|
case SkRegion::kUnion_Op:
|
|
|
|
return Json::Value(SKDEBUGCANVAS_REGIONOP_UNION);
|
|
|
|
case SkRegion::kXOR_Op:
|
|
|
|
return Json::Value(SKDEBUGCANVAS_REGIONOP_XOR);
|
|
|
|
case SkRegion::kReverseDifference_Op:
|
|
|
|
return Json::Value(SKDEBUGCANVAS_REGIONOP_REVERSE_DIFFERENCE);
|
|
|
|
case SkRegion::kReplace_Op:
|
|
|
|
return Json::Value(SKDEBUGCANVAS_REGIONOP_REPLACE);
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return Json::Value("<invalid region op>");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static Json::Value make_json_pointmode(SkCanvas::PointMode mode) {
|
|
|
|
switch (mode) {
|
|
|
|
case SkCanvas::kPoints_PointMode:
|
|
|
|
return Json::Value(SKDEBUGCANVAS_POINTMODE_POINTS);
|
|
|
|
case SkCanvas::kLines_PointMode:
|
|
|
|
return Json::Value(SKDEBUGCANVAS_POINTMODE_LINES);
|
2016-03-29 16:03:52 +00:00
|
|
|
case SkCanvas::kPolygon_PointMode:
|
2016-02-10 13:40:46 +00:00
|
|
|
return Json::Value(SKDEBUGCANVAS_POINTMODE_POLYGON);
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return Json::Value("<invalid point mode>");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void store_scalar(Json::Value* target, const char* key, SkScalar value,
|
2016-02-10 20:10:00 +00:00
|
|
|
SkScalar defaultValue) {
|
2016-02-10 13:40:46 +00:00
|
|
|
if (value != defaultValue) {
|
|
|
|
(*target)[key] = Json::Value(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 20:10:00 +00:00
|
|
|
static void store_bool(Json::Value* target, const char* key, bool value, bool defaultValue) {
|
2016-02-10 13:40:46 +00:00
|
|
|
if (value != defaultValue) {
|
|
|
|
(*target)[key] = Json::Value(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void encode_data(const void* bytes, size_t count, const char* contentType,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager, Json::Value* target) {
|
|
|
|
SkAutoTUnref<SkData> data(SkData::NewWithCopy(bytes, count));
|
|
|
|
SkString url = urlDataManager.addData(data, contentType);
|
|
|
|
*target = Json::Value(url.c_str());
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void flatten(const SkFlattenable* flattenable, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
|
|
|
SkWriteBuffer buffer;
|
|
|
|
flattenable->flatten(buffer);
|
|
|
|
void* data = sk_malloc_throw(buffer.bytesWritten());
|
|
|
|
buffer.writeToMemory(data);
|
|
|
|
Json::Value jsonData;
|
|
|
|
encode_data(data, buffer.bytesWritten(), "application/octet-stream", urlDataManager, &jsonData);
|
|
|
|
Json::Value jsonFlattenable;
|
|
|
|
jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_NAME] = Json::Value(flattenable->getTypeName());
|
|
|
|
jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_DATA] = jsonData;
|
|
|
|
(*target) = jsonFlattenable;
|
|
|
|
sk_free(data);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 17:19:39 +00:00
|
|
|
static void write_png_callback(png_structp png_ptr, png_bytep data, png_size_t length) {
|
|
|
|
SkWStream* out = (SkWStream*) png_get_io_ptr(png_ptr);
|
|
|
|
out->write(data, length);
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
void SkDrawCommand::WritePNG(const png_bytep rgba, png_uint_32 width, png_uint_32 height,
|
2016-03-21 17:19:39 +00:00
|
|
|
SkWStream& out) {
|
|
|
|
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
|
|
SkASSERT(png != nullptr);
|
|
|
|
png_infop info_ptr = png_create_info_struct(png);
|
|
|
|
SkASSERT(info_ptr != nullptr);
|
|
|
|
if (setjmp(png_jmpbuf(png))) {
|
|
|
|
SkFAIL("png encode error");
|
|
|
|
}
|
|
|
|
png_set_IHDR(png, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
|
|
|
|
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
|
|
|
png_set_compression_level(png, 1);
|
|
|
|
png_bytepp rows = (png_bytepp) sk_malloc_throw(height * sizeof(png_byte*));
|
|
|
|
png_bytep pixels = (png_bytep) sk_malloc_throw(width * height * 3);
|
|
|
|
for (png_size_t y = 0; y < height; ++y) {
|
|
|
|
const png_bytep src = rgba + y * width * 4;
|
|
|
|
rows[y] = pixels + y * width * 3;
|
|
|
|
// convert from RGBA to RGB
|
|
|
|
for (png_size_t x = 0; x < width; ++x) {
|
|
|
|
rows[y][x * 3] = src[x * 4];
|
|
|
|
rows[y][x * 3 + 1] = src[x * 4 + 1];
|
|
|
|
rows[y][x * 3 + 2] = src[x * 4 + 2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
png_set_filter(png, 0, PNG_NO_FILTERS);
|
|
|
|
png_set_rows(png, info_ptr, &rows[0]);
|
|
|
|
png_set_write_fn(png, &out, write_png_callback, NULL);
|
|
|
|
png_write_png(png, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
|
|
|
|
png_destroy_write_struct(&png, NULL);
|
|
|
|
sk_free(rows);
|
|
|
|
sk_free(pixels);
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static bool SK_WARN_UNUSED_RESULT flatten(const SkImage& image, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-03-21 17:19:39 +00:00
|
|
|
size_t rowBytes = 4 * image.width();
|
|
|
|
SkAutoFree buffer(sk_malloc_throw(rowBytes * image.height()));
|
2016-03-29 16:03:52 +00:00
|
|
|
SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(),
|
2016-03-21 17:19:39 +00:00
|
|
|
kN32_SkColorType, kPremul_SkAlphaType);
|
|
|
|
if (!image.readPixels(dstInfo, buffer.get(), rowBytes, 0, 0)) {
|
|
|
|
SkDebugf("readPixels failed\n");
|
|
|
|
return false;
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
2016-03-21 17:19:39 +00:00
|
|
|
SkDynamicMemoryWStream out;
|
|
|
|
SkDrawCommand::WritePNG((png_bytep) buffer.get(), image.width(), image.height(), out);
|
|
|
|
SkData* encoded = out.copyToData();
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value jsonData;
|
|
|
|
encode_data(encoded->data(), encoded->size(), "image/png", urlDataManager, &jsonData);
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_DATA] = jsonData;
|
|
|
|
encoded->unref();
|
2016-02-10 13:40:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* color_type_name(SkColorType colorType) {
|
|
|
|
switch (colorType) {
|
|
|
|
case kARGB_4444_SkColorType:
|
|
|
|
return SKDEBUGCANVAS_COLORTYPE_ARGB4444;
|
|
|
|
case kRGBA_8888_SkColorType:
|
|
|
|
return SKDEBUGCANVAS_COLORTYPE_RGBA8888;
|
|
|
|
case kBGRA_8888_SkColorType:
|
|
|
|
return SKDEBUGCANVAS_COLORTYPE_BGRA8888;
|
|
|
|
case kRGB_565_SkColorType:
|
|
|
|
return SKDEBUGCANVAS_COLORTYPE_565;
|
|
|
|
case kGray_8_SkColorType:
|
|
|
|
return SKDEBUGCANVAS_COLORTYPE_GRAY8;
|
|
|
|
case kIndex_8_SkColorType:
|
|
|
|
return SKDEBUGCANVAS_COLORTYPE_INDEX8;
|
|
|
|
case kAlpha_8_SkColorType:
|
|
|
|
return SKDEBUGCANVAS_COLORTYPE_ALPHA8;
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return SKDEBUGCANVAS_COLORTYPE_RGBA8888;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* alpha_type_name(SkAlphaType alphaType) {
|
|
|
|
switch (alphaType) {
|
|
|
|
case kOpaque_SkAlphaType:
|
|
|
|
return SKDEBUGCANVAS_ALPHATYPE_OPAQUE;
|
|
|
|
case kPremul_SkAlphaType:
|
|
|
|
return SKDEBUGCANVAS_ALPHATYPE_PREMUL;
|
|
|
|
case kUnpremul_SkAlphaType:
|
|
|
|
return SKDEBUGCANVAS_ALPHATYPE_UNPREMUL;
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return SKDEBUGCANVAS_ALPHATYPE_OPAQUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static Json::ArrayIndex decode_data(Json::Value data, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
const void** target) {
|
|
|
|
UrlDataManager::UrlData* urlData = urlDataManager.getDataFromUrl(SkString(data.asCString()));
|
|
|
|
if (urlData == nullptr) {
|
|
|
|
SkASSERT(false);
|
|
|
|
*target = nullptr;
|
|
|
|
return 0;
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
2016-02-11 18:35:21 +00:00
|
|
|
*target = urlData->fData->data();
|
|
|
|
// cast should be safe for any reasonably-sized object...
|
|
|
|
return (Json::ArrayIndex) urlData->fData->size();
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static SkFlattenable* load_flattenable(Json::Value jsonFlattenable,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
if (!jsonFlattenable.isMember(SKDEBUGCANVAS_ATTRIBUTE_NAME)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const char* name = jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_NAME].asCString();
|
|
|
|
SkFlattenable::Factory factory = SkFlattenable::NameToFactory(name);
|
|
|
|
if (factory == nullptr) {
|
|
|
|
SkDebugf("no factory for loading '%s'\n", name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-02-11 18:35:21 +00:00
|
|
|
const void* data;
|
|
|
|
int size = decode_data(jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_DATA], urlDataManager, &data);
|
2016-02-10 13:40:46 +00:00
|
|
|
SkValidatingReadBuffer buffer(data, size);
|
2016-04-03 16:11:13 +00:00
|
|
|
sk_sp<SkFlattenable> result = factory(buffer);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (!buffer.isValid()) {
|
|
|
|
SkDebugf("invalid buffer loading flattenable\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-04-03 16:11:13 +00:00
|
|
|
return result.release();
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static SkColorType colortype_from_name(const char* name) {
|
|
|
|
if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_ARGB4444)) {
|
|
|
|
return kARGB_4444_SkColorType;
|
|
|
|
}
|
|
|
|
else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_RGBA8888)) {
|
|
|
|
return kRGBA_8888_SkColorType;
|
|
|
|
}
|
|
|
|
else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_BGRA8888)) {
|
|
|
|
return kBGRA_8888_SkColorType;
|
|
|
|
}
|
|
|
|
else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_565)) {
|
|
|
|
return kRGB_565_SkColorType;
|
|
|
|
}
|
|
|
|
else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_GRAY8)) {
|
|
|
|
return kGray_8_SkColorType;
|
|
|
|
}
|
|
|
|
else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_INDEX8)) {
|
|
|
|
return kIndex_8_SkColorType;
|
|
|
|
}
|
|
|
|
else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_ALPHA8)) {
|
|
|
|
return kAlpha_8_SkColorType;
|
|
|
|
}
|
|
|
|
SkASSERT(false);
|
|
|
|
return kN32_SkColorType;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkBitmap* convert_colortype(SkBitmap* bitmap, SkColorType colorType) {
|
|
|
|
if (bitmap->colorType() == colorType ) {
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
SkBitmap* dst = new SkBitmap();
|
|
|
|
if (bitmap->copyTo(dst, colorType)) {
|
|
|
|
delete bitmap;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
SkASSERT(false);
|
|
|
|
delete dst;
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
// caller is responsible for freeing return value
|
2016-02-11 18:35:21 +00:00
|
|
|
static SkBitmap* load_bitmap(const Json::Value& jsonBitmap, UrlDataManager& urlDataManager) {
|
|
|
|
if (!jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_DATA)) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkDebugf("invalid bitmap\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-02-11 18:35:21 +00:00
|
|
|
const void* data;
|
|
|
|
int size = decode_data(jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_DATA], urlDataManager, &data);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::NewWithoutCopy(data, size));
|
|
|
|
sk_sp<SkImage> image(SkImage::MakeFromEncoded(std::move(encoded), nullptr));
|
2016-03-09 14:16:55 +00:00
|
|
|
|
|
|
|
SkAutoTDelete<SkBitmap> bitmap(new SkBitmap());
|
|
|
|
if (nullptr != image) {
|
|
|
|
if (!image->asLegacyBitmap(bitmap, SkImage::kRW_LegacyBitmapMode)) {
|
|
|
|
SkDebugf("image decode failed\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
if (jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLOR)) {
|
|
|
|
const char* ctName = jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_COLOR].asCString();
|
|
|
|
SkColorType ct = colortype_from_name(ctName);
|
|
|
|
if (ct != kIndex_8_SkColorType) {
|
2016-03-16 20:53:35 +00:00
|
|
|
bitmap.reset(convert_colortype(bitmap.release(), ct));
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-16 20:53:35 +00:00
|
|
|
return bitmap.release();
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
SkDebugf("image decode failed\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
static sk_sp<SkImage> load_image(const Json::Value& jsonImage, UrlDataManager& urlDataManager) {
|
2016-02-11 18:35:21 +00:00
|
|
|
SkBitmap* bitmap = load_bitmap(jsonImage, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (bitmap == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-03-17 17:51:11 +00:00
|
|
|
auto result = SkImage::MakeFromBitmap(*bitmap);
|
2016-02-10 13:40:46 +00:00
|
|
|
delete bitmap;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static bool SK_WARN_UNUSED_RESULT flatten(const SkBitmap& bitmap, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
bitmap.lockPixels();
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bitmap));
|
2016-02-10 13:40:46 +00:00
|
|
|
bitmap.unlockPixels();
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = Json::Value(color_type_name(bitmap.colorType()));
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = Json::Value(alpha_type_name(bitmap.alphaType()));
|
2016-02-11 18:35:21 +00:00
|
|
|
bool success = flatten(*image, target, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void apply_paint_color(const SkPaint& paint, Json::Value* target) {
|
|
|
|
SkColor color = paint.getColor();
|
|
|
|
if (color != SK_ColorBLACK) {
|
|
|
|
Json::Value colorValue(Json::arrayValue);
|
|
|
|
colorValue.append(Json::Value(SkColorGetA(color)));
|
|
|
|
colorValue.append(Json::Value(SkColorGetR(color)));
|
|
|
|
colorValue.append(Json::Value(SkColorGetG(color)));
|
|
|
|
colorValue.append(Json::Value(SkColorGetB(color)));
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = colorValue;;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void apply_paint_style(const SkPaint& paint, Json::Value* target) {
|
|
|
|
SkPaint::Style style = paint.getStyle();
|
|
|
|
if (style != SkPaint::kFill_Style) {
|
|
|
|
switch (style) {
|
|
|
|
case SkPaint::kStroke_Style: {
|
|
|
|
Json::Value stroke(SKDEBUGCANVAS_STYLE_STROKE);
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = stroke;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPaint::kStrokeAndFill_Style: {
|
|
|
|
Json::Value strokeAndFill(SKDEBUGCANVAS_STYLE_STROKEANDFILL);
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = strokeAndFill;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: SkASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void apply_paint_cap(const SkPaint& paint, Json::Value* target) {
|
|
|
|
SkPaint::Cap cap = paint.getStrokeCap();
|
|
|
|
if (cap != SkPaint::kDefault_Cap) {
|
|
|
|
switch (cap) {
|
2016-02-10 22:05:02 +00:00
|
|
|
case SkPaint::kButt_Cap:
|
2016-02-10 13:40:46 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_CAP] = Json::Value(SKDEBUGCANVAS_CAP_BUTT);
|
|
|
|
break;
|
2016-02-10 22:05:02 +00:00
|
|
|
case SkPaint::kRound_Cap:
|
2016-02-10 13:40:46 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_CAP] = Json::Value(SKDEBUGCANVAS_CAP_ROUND);
|
|
|
|
break;
|
2016-02-10 22:05:02 +00:00
|
|
|
case SkPaint::kSquare_Cap:
|
2016-02-10 13:40:46 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_CAP] = Json::Value(SKDEBUGCANVAS_CAP_SQUARE);
|
|
|
|
break;
|
|
|
|
default: SkASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-10 22:05:02 +00:00
|
|
|
|
|
|
|
static void apply_paint_join(const SkPaint& paint, Json::Value* target) {
|
|
|
|
SkPaint::Join join = paint.getStrokeJoin();
|
|
|
|
if (join != SkPaint::kDefault_Join) {
|
|
|
|
switch (join) {
|
|
|
|
case SkPaint::kMiter_Join:
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_MITER_JOIN);
|
|
|
|
break;
|
|
|
|
case SkPaint::kRound_Join:
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_ROUND_JOIN);
|
|
|
|
break;
|
|
|
|
case SkPaint::kBevel_Join:
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_BEVEL_JOIN);
|
|
|
|
break;
|
|
|
|
default: SkASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void apply_paint_filterquality(const SkPaint& paint, Json::Value* target) {
|
|
|
|
SkFilterQuality quality = paint.getFilterQuality();
|
|
|
|
switch (quality) {
|
|
|
|
case kNone_SkFilterQuality:
|
|
|
|
break;
|
|
|
|
case kLow_SkFilterQuality:
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_FILTERQUALITY_LOW);
|
|
|
|
break;
|
|
|
|
case kMedium_SkFilterQuality:
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_FILTERQUALITY_MEDIUM);
|
|
|
|
break;
|
|
|
|
case kHigh_SkFilterQuality:
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_FILTERQUALITY_HIGH);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void apply_paint_maskfilter(const SkPaint& paint, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkMaskFilter* maskFilter = paint.getMaskFilter();
|
|
|
|
if (maskFilter != nullptr) {
|
|
|
|
SkMaskFilter::BlurRec blurRec;
|
|
|
|
if (maskFilter->asABlur(&blurRec)) {
|
|
|
|
Json::Value blur(Json::objectValue);
|
|
|
|
blur[SKDEBUGCANVAS_ATTRIBUTE_SIGMA] = Json::Value(blurRec.fSigma);
|
|
|
|
switch (blurRec.fStyle) {
|
|
|
|
case SkBlurStyle::kNormal_SkBlurStyle:
|
2016-02-10 22:05:02 +00:00
|
|
|
blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_BLURSTYLE_NORMAL);
|
2016-02-10 13:40:46 +00:00
|
|
|
break;
|
|
|
|
case SkBlurStyle::kSolid_SkBlurStyle:
|
2016-02-10 22:05:02 +00:00
|
|
|
blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_BLURSTYLE_SOLID);
|
2016-02-10 13:40:46 +00:00
|
|
|
break;
|
|
|
|
case SkBlurStyle::kOuter_SkBlurStyle:
|
2016-02-10 22:05:02 +00:00
|
|
|
blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_BLURSTYLE_OUTER);
|
2016-02-10 13:40:46 +00:00
|
|
|
break;
|
|
|
|
case SkBlurStyle::kInner_SkBlurStyle:
|
2016-02-10 22:05:02 +00:00
|
|
|
blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_BLURSTYLE_INNER);
|
2016-02-10 13:40:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
}
|
|
|
|
switch (blurRec.fQuality) {
|
|
|
|
case SkBlurQuality::kLow_SkBlurQuality:
|
2016-02-10 22:05:02 +00:00
|
|
|
blur[SKDEBUGCANVAS_ATTRIBUTE_QUALITY] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_BLURQUALITY_LOW);
|
2016-02-10 13:40:46 +00:00
|
|
|
break;
|
|
|
|
case SkBlurQuality::kHigh_SkBlurQuality:
|
2016-02-10 22:05:02 +00:00
|
|
|
blur[SKDEBUGCANVAS_ATTRIBUTE_QUALITY] = Json::Value(
|
|
|
|
SKDEBUGCANVAS_BLURQUALITY_HIGH);
|
2016-02-10 13:40:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
}
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_BLUR] = blur;
|
|
|
|
} else {
|
|
|
|
Json::Value jsonMaskFilter;
|
2016-02-11 18:35:21 +00:00
|
|
|
flatten(maskFilter, &jsonMaskFilter, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER] = jsonMaskFilter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void apply_paint_patheffect(const SkPaint& paint, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkPathEffect* pathEffect = paint.getPathEffect();
|
|
|
|
if (pathEffect != nullptr) {
|
|
|
|
SkPathEffect::DashInfo dashInfo;
|
|
|
|
SkPathEffect::DashType dashType = pathEffect->asADash(&dashInfo);
|
|
|
|
if (dashType == SkPathEffect::kDash_DashType) {
|
|
|
|
dashInfo.fIntervals = (SkScalar*) sk_malloc_throw(dashInfo.fCount * sizeof(SkScalar));
|
|
|
|
pathEffect->asADash(&dashInfo);
|
|
|
|
Json::Value dashing(Json::objectValue);
|
|
|
|
Json::Value intervals(Json::arrayValue);
|
|
|
|
for (int32_t i = 0; i < dashInfo.fCount; i++) {
|
|
|
|
intervals.append(Json::Value(dashInfo.fIntervals[i]));
|
|
|
|
}
|
|
|
|
sk_free(dashInfo.fIntervals);
|
|
|
|
dashing[SKDEBUGCANVAS_ATTRIBUTE_INTERVALS] = intervals;
|
|
|
|
dashing[SKDEBUGCANVAS_ATTRIBUTE_PHASE] = dashInfo.fPhase;
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_DASHING] = dashing;
|
|
|
|
} else {
|
|
|
|
Json::Value jsonPathEffect;
|
2016-02-11 18:35:21 +00:00
|
|
|
flatten(pathEffect, &jsonPathEffect, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT] = jsonPathEffect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
static void apply_paint_textalign(const SkPaint& paint, Json::Value* target) {
|
|
|
|
SkPaint::Align textAlign = paint.getTextAlign();
|
|
|
|
if (textAlign != SkPaint::kLeft_Align) {
|
|
|
|
switch (textAlign) {
|
|
|
|
case SkPaint::kCenter_Align: {
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN] = SKDEBUGCANVAS_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkPaint::kRight_Align: {
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN] = SKDEBUGCANVAS_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: SkASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void apply_paint_typeface(const SkPaint& paint, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkTypeface* typeface = paint.getTypeface();
|
|
|
|
if (typeface != nullptr) {
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value jsonTypeface;
|
|
|
|
SkDynamicMemoryWStream buffer;
|
|
|
|
typeface->serialize(&buffer);
|
|
|
|
void* data = sk_malloc_throw(buffer.bytesWritten());
|
|
|
|
buffer.copyTo(data);
|
|
|
|
Json::Value jsonData;
|
2016-03-29 16:03:52 +00:00
|
|
|
encode_data(data, buffer.bytesWritten(), "application/octet-stream", urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
&jsonData);
|
|
|
|
jsonTypeface[SKDEBUGCANVAS_ATTRIBUTE_DATA] = jsonData;
|
|
|
|
sk_free(data);
|
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE] = jsonTypeface;
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void apply_paint_shader(const SkPaint& paint, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkFlattenable* shader = paint.getShader();
|
|
|
|
if (shader != nullptr) {
|
|
|
|
Json::Value jsonShader;
|
2016-02-11 18:35:21 +00:00
|
|
|
flatten(shader, &jsonShader, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_SHADER] = jsonShader;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void apply_paint_xfermode(const SkPaint& paint, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkFlattenable* xfermode = paint.getXfermode();
|
|
|
|
if (xfermode != nullptr) {
|
|
|
|
Json::Value jsonXfermode;
|
2016-02-11 18:35:21 +00:00
|
|
|
flatten(xfermode, &jsonXfermode, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_XFERMODE] = jsonXfermode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
static void apply_paint_imagefilter(const SkPaint& paint, Json::Value* target,
|
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkFlattenable* imageFilter = paint.getImageFilter();
|
|
|
|
if (imageFilter != nullptr) {
|
|
|
|
Json::Value jsonImageFilter;
|
2016-02-11 18:35:21 +00:00
|
|
|
flatten(imageFilter, &jsonImageFilter, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER] = jsonImageFilter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void apply_paint_colorfilter(const SkPaint& paint, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkFlattenable* colorFilter = paint.getColorFilter();
|
|
|
|
if (colorFilter != nullptr) {
|
|
|
|
Json::Value jsonColorFilter;
|
2016-02-11 18:35:21 +00:00
|
|
|
flatten(colorFilter, &jsonColorFilter, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER] = jsonColorFilter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void apply_paint_looper(const SkPaint& paint, Json::Value* target,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 22:05:02 +00:00
|
|
|
SkFlattenable* looper = paint.getLooper();
|
|
|
|
if (looper != nullptr) {
|
|
|
|
Json::Value jsonLooper;
|
2016-02-11 18:35:21 +00:00
|
|
|
flatten(looper, &jsonLooper, urlDataManager);
|
2016-02-10 22:05:02 +00:00
|
|
|
(*target)[SKDEBUGCANVAS_ATTRIBUTE_LOOPER] = jsonLooper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value make_json_paint(const SkPaint& paint, UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value result(Json::objectValue);
|
|
|
|
store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH, paint.getStrokeWidth(), 0.0f);
|
2016-03-29 16:03:52 +00:00
|
|
|
store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER, paint.getStrokeMiter(),
|
2016-02-10 13:40:46 +00:00
|
|
|
SkPaintDefaults_MiterLimit);
|
|
|
|
store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS, paint.isAntiAlias(), false);
|
2016-02-10 22:05:02 +00:00
|
|
|
store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_DITHER, paint.isDither(), false);
|
2016-03-29 16:03:52 +00:00
|
|
|
store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE, paint.getTextSize(),
|
2016-02-10 13:40:46 +00:00
|
|
|
SkPaintDefaults_TextSize);
|
|
|
|
store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextScaleX(), SK_Scalar1);
|
|
|
|
store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextSkewX(), 0.0f);
|
|
|
|
apply_paint_color(paint, &result);
|
|
|
|
apply_paint_style(paint, &result);
|
|
|
|
apply_paint_cap(paint, &result);
|
2016-02-10 22:05:02 +00:00
|
|
|
apply_paint_join(paint, &result);
|
|
|
|
apply_paint_filterquality(paint, &result);
|
2016-02-10 13:40:46 +00:00
|
|
|
apply_paint_textalign(paint, &result);
|
2016-02-11 18:35:21 +00:00
|
|
|
apply_paint_patheffect(paint, &result, urlDataManager);
|
|
|
|
apply_paint_maskfilter(paint, &result, urlDataManager);
|
|
|
|
apply_paint_shader(paint, &result, urlDataManager);
|
|
|
|
apply_paint_xfermode(paint, &result, urlDataManager);
|
|
|
|
apply_paint_looper(paint, &result, urlDataManager);
|
|
|
|
apply_paint_imagefilter(paint, &result, urlDataManager);
|
|
|
|
apply_paint_colorfilter(paint, &result, urlDataManager);
|
|
|
|
apply_paint_typeface(paint, &result, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-10 22:05:02 +00:00
|
|
|
static SkPoint get_json_point(Json::Value point) {
|
|
|
|
return SkPoint::Make(point[0].asFloat(), point[1].asFloat());
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkColor get_json_color(Json::Value color) {
|
|
|
|
return SkColorSetARGB(color[0].asInt(), color[1].asInt(), color[2].asInt(), color[3].asInt());
|
|
|
|
}
|
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
static void extract_json_paint_color(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLOR)) {
|
2016-02-10 22:05:02 +00:00
|
|
|
target->setColor(get_json_color(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_COLOR]));
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void extract_json_paint_shader(Json::Value& jsonPaint, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
SkPaint* target) {
|
2016-02-10 13:40:46 +00:00
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_SHADER)) {
|
|
|
|
Json::Value jsonShader = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_SHADER];
|
2016-02-11 18:35:21 +00:00
|
|
|
SkShader* shader = (SkShader*) load_flattenable(jsonShader, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (shader != nullptr) {
|
2016-03-25 16:08:00 +00:00
|
|
|
target->setShader(sk_ref_sp(shader));
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void extract_json_paint_patheffect(Json::Value& jsonPaint, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
SkPaint* target) {
|
2016-02-10 13:40:46 +00:00
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT)) {
|
|
|
|
Json::Value jsonPathEffect = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT];
|
2016-03-18 18:22:57 +00:00
|
|
|
sk_sp<SkPathEffect> pathEffect((SkPathEffect*)load_flattenable(jsonPathEffect,
|
|
|
|
urlDataManager));
|
2016-02-10 13:40:46 +00:00
|
|
|
if (pathEffect != nullptr) {
|
|
|
|
target->setPathEffect(pathEffect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void extract_json_paint_maskfilter(Json::Value& jsonPaint, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
SkPaint* target) {
|
2016-02-10 13:40:46 +00:00
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER)) {
|
|
|
|
Json::Value jsonMaskFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER];
|
2016-02-11 18:35:21 +00:00
|
|
|
SkMaskFilter* maskFilter = (SkMaskFilter*) load_flattenable(jsonMaskFilter, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (maskFilter != nullptr) {
|
|
|
|
target->setMaskFilter(maskFilter);
|
|
|
|
maskFilter->unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void extract_json_paint_colorfilter(Json::Value& jsonPaint, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
SkPaint* target) {
|
2016-02-10 13:40:46 +00:00
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER)) {
|
|
|
|
Json::Value jsonColorFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER];
|
2016-03-22 17:17:23 +00:00
|
|
|
sk_sp<SkColorFilter> colorFilter((SkColorFilter*)load_flattenable(jsonColorFilter,
|
|
|
|
urlDataManager));
|
2016-02-10 13:40:46 +00:00
|
|
|
if (colorFilter != nullptr) {
|
|
|
|
target->setColorFilter(colorFilter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void extract_json_paint_xfermode(Json::Value& jsonPaint, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
SkPaint* target) {
|
2016-02-10 13:40:46 +00:00
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_XFERMODE)) {
|
|
|
|
Json::Value jsonXfermode = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_XFERMODE];
|
2016-03-29 18:32:50 +00:00
|
|
|
sk_sp<SkXfermode> xfermode((SkXfermode*) load_flattenable(jsonXfermode, urlDataManager));
|
2016-02-10 13:40:46 +00:00
|
|
|
if (xfermode != nullptr) {
|
|
|
|
target->setXfermode(xfermode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void extract_json_paint_looper(Json::Value& jsonPaint, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
SkPaint* target) {
|
2016-02-10 22:05:02 +00:00
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_LOOPER)) {
|
|
|
|
Json::Value jsonLooper = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_LOOPER];
|
2016-03-21 20:25:16 +00:00
|
|
|
sk_sp<SkDrawLooper> looper((SkDrawLooper*) load_flattenable(jsonLooper, urlDataManager));
|
2016-02-10 22:05:02 +00:00
|
|
|
if (looper != nullptr) {
|
2016-03-21 20:25:16 +00:00
|
|
|
target->setLooper(std::move(looper));
|
2016-02-10 22:05:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void extract_json_paint_imagefilter(Json::Value& jsonPaint, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
SkPaint* target) {
|
2016-02-10 13:40:46 +00:00
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER)) {
|
|
|
|
Json::Value jsonImageFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER];
|
2016-03-29 16:03:52 +00:00
|
|
|
SkImageFilter* imageFilter = (SkImageFilter*) load_flattenable(jsonImageFilter,
|
2016-02-11 18:35:21 +00:00
|
|
|
urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (imageFilter != nullptr) {
|
|
|
|
target->setImageFilter(imageFilter);
|
|
|
|
imageFilter->unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void extract_json_paint_typeface(Json::Value& jsonPaint, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE)) {
|
|
|
|
Json::Value jsonTypeface = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE];
|
|
|
|
Json::Value jsonData = jsonTypeface[SKDEBUGCANVAS_ATTRIBUTE_DATA];
|
|
|
|
const void* data;
|
|
|
|
Json::ArrayIndex length = decode_data(jsonData, urlDataManager, &data);
|
|
|
|
SkMemoryStream buffer(data, length);
|
|
|
|
SkTypeface* typeface = SkTypeface::Deserialize(&buffer);
|
|
|
|
target->setTypeface(typeface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
static void extract_json_paint_style(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STYLE)) {
|
|
|
|
const char* style = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STYLE].asCString();
|
|
|
|
if (!strcmp(style, SKDEBUGCANVAS_STYLE_FILL)) {
|
|
|
|
target->setStyle(SkPaint::kFill_Style);
|
|
|
|
}
|
|
|
|
else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKE)) {
|
|
|
|
target->setStyle(SkPaint::kStroke_Style);
|
|
|
|
}
|
|
|
|
else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKEANDFILL)) {
|
|
|
|
target->setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_paint_strokewidth(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH)) {
|
|
|
|
float strokeWidth = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH].asFloat();
|
|
|
|
target->setStrokeWidth(strokeWidth);
|
2016-03-29 16:03:52 +00:00
|
|
|
}
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_paint_strokemiter(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER)) {
|
|
|
|
float strokeMiter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER].asFloat();
|
|
|
|
target->setStrokeMiter(strokeMiter);
|
2016-03-29 16:03:52 +00:00
|
|
|
}
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 22:05:02 +00:00
|
|
|
static void extract_json_paint_strokejoin(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN)) {
|
|
|
|
const char* join = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN].asCString();
|
|
|
|
if (!strcmp(join, SKDEBUGCANVAS_MITER_JOIN)) {
|
|
|
|
target->setStrokeJoin(SkPaint::kMiter_Join);
|
|
|
|
}
|
|
|
|
else if (!strcmp(join, SKDEBUGCANVAS_ROUND_JOIN)) {
|
|
|
|
target->setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
}
|
|
|
|
else if (!strcmp(join, SKDEBUGCANVAS_BEVEL_JOIN)) {
|
|
|
|
target->setStrokeJoin(SkPaint::kBevel_Join);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SkASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
static void extract_json_paint_cap(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_CAP)) {
|
|
|
|
const char* cap = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_CAP].asCString();
|
|
|
|
if (!strcmp(cap, SKDEBUGCANVAS_CAP_BUTT)) {
|
|
|
|
target->setStrokeCap(SkPaint::kButt_Cap);
|
|
|
|
}
|
|
|
|
else if (!strcmp(cap, SKDEBUGCANVAS_CAP_ROUND)) {
|
|
|
|
target->setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
}
|
|
|
|
else if (!strcmp(cap, SKDEBUGCANVAS_CAP_SQUARE)) {
|
|
|
|
target->setStrokeCap(SkPaint::kSquare_Cap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 22:05:02 +00:00
|
|
|
static void extract_json_paint_filterquality(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY)) {
|
|
|
|
const char* quality = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY].asCString();
|
|
|
|
if (!strcmp(quality, SKDEBUGCANVAS_FILTERQUALITY_NONE)) {
|
|
|
|
target->setFilterQuality(kNone_SkFilterQuality);
|
|
|
|
}
|
|
|
|
else if (!strcmp(quality, SKDEBUGCANVAS_FILTERQUALITY_LOW)) {
|
|
|
|
target->setFilterQuality(kLow_SkFilterQuality);
|
|
|
|
}
|
|
|
|
else if (!strcmp(quality, SKDEBUGCANVAS_FILTERQUALITY_MEDIUM)) {
|
|
|
|
target->setFilterQuality(kMedium_SkFilterQuality);
|
|
|
|
}
|
|
|
|
else if (!strcmp(quality, SKDEBUGCANVAS_FILTERQUALITY_HIGH)) {
|
|
|
|
target->setFilterQuality(kHigh_SkFilterQuality);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
static void extract_json_paint_antialias(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS)) {
|
|
|
|
target->setAntiAlias(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 22:05:02 +00:00
|
|
|
static void extract_json_paint_dither(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_DITHER)) {
|
|
|
|
target->setDither(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_DITHER].asBool());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
static void extract_json_paint_blur(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_BLUR)) {
|
|
|
|
Json::Value blur = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_BLUR];
|
|
|
|
SkScalar sigma = blur[SKDEBUGCANVAS_ATTRIBUTE_SIGMA].asFloat();
|
|
|
|
SkBlurStyle style;
|
|
|
|
const char* jsonStyle = blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE].asCString();
|
|
|
|
if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_NORMAL)) {
|
|
|
|
style = SkBlurStyle::kNormal_SkBlurStyle;
|
|
|
|
}
|
|
|
|
else if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_SOLID)) {
|
|
|
|
style = SkBlurStyle::kSolid_SkBlurStyle;
|
|
|
|
}
|
|
|
|
else if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_OUTER)) {
|
|
|
|
style = SkBlurStyle::kOuter_SkBlurStyle;
|
|
|
|
}
|
|
|
|
else if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_INNER)) {
|
|
|
|
style = SkBlurStyle::kInner_SkBlurStyle;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SkASSERT(false);
|
|
|
|
style = SkBlurStyle::kNormal_SkBlurStyle;
|
|
|
|
}
|
|
|
|
SkBlurMaskFilter::BlurFlags flags;
|
|
|
|
const char* jsonQuality = blur[SKDEBUGCANVAS_ATTRIBUTE_QUALITY].asCString();
|
|
|
|
if (!strcmp(jsonQuality, SKDEBUGCANVAS_BLURQUALITY_LOW)) {
|
|
|
|
flags = SkBlurMaskFilter::BlurFlags::kNone_BlurFlag;
|
|
|
|
}
|
|
|
|
else if (!strcmp(jsonQuality, SKDEBUGCANVAS_BLURQUALITY_HIGH)) {
|
|
|
|
flags = SkBlurMaskFilter::BlurFlags::kHighQuality_BlurFlag;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SkASSERT(false);
|
|
|
|
flags = SkBlurMaskFilter::BlurFlags::kNone_BlurFlag;
|
|
|
|
}
|
|
|
|
target->setMaskFilter(SkBlurMaskFilter::Create(style, sigma, flags));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_paint_dashing(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_DASHING)) {
|
|
|
|
Json::Value dash = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_DASHING];
|
|
|
|
Json::Value jsonIntervals = dash[SKDEBUGCANVAS_ATTRIBUTE_INTERVALS];
|
|
|
|
Json::ArrayIndex count = jsonIntervals.size();
|
|
|
|
SkScalar* intervals = (SkScalar*) sk_malloc_throw(count * sizeof(SkScalar));
|
|
|
|
for (Json::ArrayIndex i = 0; i < count; i++) {
|
|
|
|
intervals[i] = jsonIntervals[i].asFloat();
|
|
|
|
}
|
|
|
|
SkScalar phase = dash[SKDEBUGCANVAS_ATTRIBUTE_PHASE].asFloat();
|
2016-03-18 18:22:57 +00:00
|
|
|
target->setPathEffect(SkDashPathEffect::Make(intervals, count, phase));
|
2016-02-10 13:40:46 +00:00
|
|
|
sk_free(intervals);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_paint_textalign(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN)) {
|
|
|
|
SkPaint::Align textAlign;
|
|
|
|
const char* jsonAlign = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN].asCString();
|
|
|
|
if (!strcmp(jsonAlign, SKDEBUGCANVAS_ALIGN_LEFT)) {
|
|
|
|
textAlign = SkPaint::kLeft_Align;
|
|
|
|
}
|
|
|
|
else if (!strcmp(jsonAlign, SKDEBUGCANVAS_ALIGN_CENTER)) {
|
|
|
|
textAlign = SkPaint::kCenter_Align;
|
|
|
|
}
|
|
|
|
else if (!strcmp(jsonAlign, SKDEBUGCANVAS_ALIGN_RIGHT)) {
|
|
|
|
textAlign = SkPaint::kRight_Align;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SkASSERT(false);
|
|
|
|
textAlign = SkPaint::kLeft_Align;
|
|
|
|
}
|
|
|
|
target->setTextAlign(textAlign);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_paint_textsize(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE)) {
|
|
|
|
float textSize = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE].asFloat();
|
|
|
|
target->setTextSize(textSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_paint_textscalex(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX)) {
|
|
|
|
float textScaleX = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX].asFloat();
|
|
|
|
target->setTextScaleX(textScaleX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_paint_textskewx(Json::Value& jsonPaint, SkPaint* target) {
|
|
|
|
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX)) {
|
|
|
|
float textSkewX = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX].asFloat();
|
|
|
|
target->setTextSkewX(textSkewX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
static void extract_json_paint(Json::Value& paint, UrlDataManager& urlDataManager,
|
2016-02-11 18:35:21 +00:00
|
|
|
SkPaint* result) {
|
2016-02-10 13:40:46 +00:00
|
|
|
extract_json_paint_color(paint, result);
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint_shader(paint, urlDataManager, result);
|
|
|
|
extract_json_paint_patheffect(paint, urlDataManager, result);
|
|
|
|
extract_json_paint_maskfilter(paint, urlDataManager, result);
|
|
|
|
extract_json_paint_colorfilter(paint, urlDataManager, result);
|
|
|
|
extract_json_paint_xfermode(paint, urlDataManager, result);
|
|
|
|
extract_json_paint_looper(paint, urlDataManager, result);
|
|
|
|
extract_json_paint_imagefilter(paint, urlDataManager, result);
|
|
|
|
extract_json_paint_typeface(paint, urlDataManager, result);
|
2016-02-10 13:40:46 +00:00
|
|
|
extract_json_paint_style(paint, result);
|
|
|
|
extract_json_paint_strokewidth(paint, result);
|
|
|
|
extract_json_paint_strokemiter(paint, result);
|
2016-02-10 22:05:02 +00:00
|
|
|
extract_json_paint_strokejoin(paint, result);
|
2016-02-10 13:40:46 +00:00
|
|
|
extract_json_paint_cap(paint, result);
|
2016-02-10 22:05:02 +00:00
|
|
|
extract_json_paint_filterquality(paint, result);
|
2016-02-10 13:40:46 +00:00
|
|
|
extract_json_paint_antialias(paint, result);
|
2016-02-10 22:05:02 +00:00
|
|
|
extract_json_paint_dither(paint, result);
|
2016-02-10 13:40:46 +00:00
|
|
|
extract_json_paint_blur(paint, result);
|
|
|
|
extract_json_paint_dashing(paint, result);
|
|
|
|
extract_json_paint_textalign(paint, result);
|
|
|
|
extract_json_paint_textsize(paint, result);
|
|
|
|
extract_json_paint_textscalex(paint, result);
|
|
|
|
extract_json_paint_textskewx(paint, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_rect(Json::Value& rect, SkRect* result) {
|
|
|
|
result->set(rect[0].asFloat(), rect[1].asFloat(), rect[2].asFloat(), rect[3].asFloat());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_irect(Json::Value& rect, SkIRect* result) {
|
|
|
|
result->set(rect[0].asInt(), rect[1].asInt(), rect[2].asInt(), rect[3].asInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_rrect(Json::Value& rrect, SkRRect* result) {
|
|
|
|
SkVector radii[4] = {
|
2016-03-29 16:03:52 +00:00
|
|
|
{ rrect[1][0].asFloat(), rrect[1][1].asFloat() },
|
|
|
|
{ rrect[2][0].asFloat(), rrect[2][1].asFloat() },
|
|
|
|
{ rrect[3][0].asFloat(), rrect[3][1].asFloat() },
|
2016-02-10 13:40:46 +00:00
|
|
|
{ rrect[4][0].asFloat(), rrect[4][1].asFloat() }
|
|
|
|
};
|
2016-03-29 16:03:52 +00:00
|
|
|
result->setRectRadii(SkRect::MakeLTRB(rrect[0][0].asFloat(), rrect[0][1].asFloat(),
|
|
|
|
rrect[0][2].asFloat(), rrect[0][3].asFloat()),
|
2016-02-10 13:40:46 +00:00
|
|
|
radii);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_matrix(Json::Value& matrix, SkMatrix* result) {
|
2016-03-29 16:03:52 +00:00
|
|
|
SkScalar values[] = {
|
2016-02-10 13:40:46 +00:00
|
|
|
matrix[0][0].asFloat(), matrix[0][1].asFloat(), matrix[0][2].asFloat(),
|
|
|
|
matrix[1][0].asFloat(), matrix[1][1].asFloat(), matrix[1][2].asFloat(),
|
2016-03-29 16:03:52 +00:00
|
|
|
matrix[2][0].asFloat(), matrix[2][1].asFloat(), matrix[2][2].asFloat()
|
2016-02-10 13:40:46 +00:00
|
|
|
};
|
|
|
|
result->set9(values);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void extract_json_path(Json::Value& path, SkPath* result) {
|
|
|
|
const char* fillType = path[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE].asCString();
|
|
|
|
if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_WINDING)) {
|
|
|
|
result->setFillType(SkPath::kWinding_FillType);
|
|
|
|
}
|
|
|
|
else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_EVENODD)) {
|
|
|
|
result->setFillType(SkPath::kEvenOdd_FillType);
|
|
|
|
}
|
|
|
|
else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING)) {
|
|
|
|
result->setFillType(SkPath::kInverseWinding_FillType);
|
|
|
|
}
|
|
|
|
else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEEVENODD)) {
|
|
|
|
result->setFillType(SkPath::kInverseEvenOdd_FillType);
|
|
|
|
}
|
|
|
|
Json::Value verbs = path[SKDEBUGCANVAS_ATTRIBUTE_VERBS];
|
|
|
|
for (Json::ArrayIndex i = 0; i < verbs.size(); i++) {
|
|
|
|
Json::Value verb = verbs[i];
|
|
|
|
if (verb.isString()) {
|
|
|
|
SkASSERT(!strcmp(verb.asCString(), SKDEBUGCANVAS_VERB_CLOSE));
|
|
|
|
result->close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (verb.isMember(SKDEBUGCANVAS_VERB_MOVE)) {
|
|
|
|
Json::Value move = verb[SKDEBUGCANVAS_VERB_MOVE];
|
|
|
|
result->moveTo(move[0].asFloat(), move[1].asFloat());
|
|
|
|
}
|
|
|
|
else if (verb.isMember(SKDEBUGCANVAS_VERB_LINE)) {
|
|
|
|
Json::Value line = verb[SKDEBUGCANVAS_VERB_LINE];
|
|
|
|
result->lineTo(line[0].asFloat(), line[1].asFloat());
|
|
|
|
}
|
|
|
|
else if (verb.isMember(SKDEBUGCANVAS_VERB_QUAD)) {
|
|
|
|
Json::Value quad = verb[SKDEBUGCANVAS_VERB_QUAD];
|
|
|
|
result->quadTo(quad[0][0].asFloat(), quad[0][1].asFloat(),
|
|
|
|
quad[1][0].asFloat(), quad[1][1].asFloat());
|
|
|
|
}
|
|
|
|
else if (verb.isMember(SKDEBUGCANVAS_VERB_CUBIC)) {
|
|
|
|
Json::Value cubic = verb[SKDEBUGCANVAS_VERB_CUBIC];
|
|
|
|
result->cubicTo(cubic[0][0].asFloat(), cubic[0][1].asFloat(),
|
|
|
|
cubic[1][0].asFloat(), cubic[1][1].asFloat(),
|
|
|
|
cubic[2][0].asFloat(), cubic[2][1].asFloat());
|
|
|
|
}
|
|
|
|
else if (verb.isMember(SKDEBUGCANVAS_VERB_CONIC)) {
|
|
|
|
Json::Value conic = verb[SKDEBUGCANVAS_VERB_CONIC];
|
|
|
|
result->conicTo(conic[0][0].asFloat(), conic[0][1].asFloat(),
|
|
|
|
conic[1][0].asFloat(), conic[1][1].asFloat(),
|
|
|
|
conic[2].asFloat());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SkASSERT(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRegion::Op get_json_regionop(Json::Value& jsonOp) {
|
|
|
|
const char* op = jsonOp.asCString();
|
|
|
|
if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_DIFFERENCE)) {
|
|
|
|
return SkRegion::kDifference_Op;
|
|
|
|
}
|
|
|
|
else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_INTERSECT)) {
|
|
|
|
return SkRegion::kIntersect_Op;
|
|
|
|
}
|
|
|
|
else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_UNION)) {
|
|
|
|
return SkRegion::kUnion_Op;
|
|
|
|
}
|
|
|
|
else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_XOR)) {
|
|
|
|
return SkRegion::kXOR_Op;
|
|
|
|
}
|
|
|
|
else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_REVERSE_DIFFERENCE)) {
|
|
|
|
return SkRegion::kReverseDifference_Op;
|
|
|
|
}
|
|
|
|
else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_REPLACE)) {
|
|
|
|
return SkRegion::kReplace_Op;
|
|
|
|
}
|
|
|
|
SkASSERT(false);
|
|
|
|
return SkRegion::kIntersect_Op;
|
|
|
|
}
|
|
|
|
|
2016-02-10 22:05:02 +00:00
|
|
|
SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) {
|
|
|
|
fColor = color;
|
|
|
|
fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkClearCommand::execute(SkCanvas* canvas) const {
|
|
|
|
canvas->clear(fColor);
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkClearCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 22:05:02 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = make_json_color(fColor);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
SkClearCommand* SkClearCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) {
|
2016-02-10 22:05:02 +00:00
|
|
|
Json::Value color = command[SKDEBUGCANVAS_ATTRIBUTE_COLOR];
|
|
|
|
return new SkClearCommand(get_json_color(color));
|
|
|
|
}
|
2013-06-06 23:59:28 +00:00
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkRegion::Op op, bool doAA)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kClipPath_OpType) {
|
2013-03-17 18:33:46 +00:00
|
|
|
fPath = path;
|
|
|
|
fOp = op;
|
|
|
|
fDoAA = doAA;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-17 18:33:46 +00:00
|
|
|
fInfo.push(SkObjectParser::PathToString(path));
|
|
|
|
fInfo.push(SkObjectParser::RegionOpToString(op));
|
|
|
|
fInfo.push(SkObjectParser::BoolToString(doAA));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkClipPathCommand::execute(SkCanvas* canvas) const {
|
2013-03-17 18:33:46 +00:00
|
|
|
canvas->clipPath(fPath, fOp, fDoAA);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkClipPathCommand::render(SkCanvas* canvas) const {
|
2013-06-06 23:59:28 +00:00
|
|
|
render_path(canvas, fPath);
|
|
|
|
return true;
|
2012-11-21 17:11:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkClipPathCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = make_json_path(fPath);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS] = fDoAA;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkClipPathCommand* SkClipPathCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkPath path;
|
|
|
|
extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path);
|
2016-03-29 16:03:52 +00:00
|
|
|
return new SkClipPathCommand(path, get_json_regionop(command[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP]),
|
2016-02-10 13:40:46 +00:00
|
|
|
command[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
|
|
|
|
}
|
|
|
|
|
2014-03-27 03:02:48 +00:00
|
|
|
SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkRegion::Op op)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kClipRegion_OpType) {
|
2013-03-22 16:33:31 +00:00
|
|
|
fRegion = region;
|
|
|
|
fOp = op;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-22 16:33:31 +00:00
|
|
|
fInfo.push(SkObjectParser::RegionToString(region));
|
|
|
|
fInfo.push(SkObjectParser::RegionOpToString(op));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkClipRegionCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 16:33:31 +00:00
|
|
|
canvas->clipRegion(fRegion, fOp);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkClipRegionCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_REGION] = make_json_region(fRegion);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkClipRegionCommand* SkClipRegionCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkRegion::Op op, bool doAA)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kClipRect_OpType) {
|
2013-03-22 12:25:30 +00:00
|
|
|
fRect = rect;
|
|
|
|
fOp = op;
|
|
|
|
fDoAA = doAA;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-22 12:25:30 +00:00
|
|
|
fInfo.push(SkObjectParser::RectToString(rect));
|
|
|
|
fInfo.push(SkObjectParser::RegionOpToString(op));
|
|
|
|
fInfo.push(SkObjectParser::BoolToString(doAA));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkClipRectCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 12:25:30 +00:00
|
|
|
canvas->clipRect(fRect, fOp, fDoAA);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkClipRectCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rect(fRect);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS] = Json::Value(fDoAA);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkClipRectCommand* SkClipRectCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkRect rect;
|
|
|
|
extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &rect);
|
2016-03-29 16:03:52 +00:00
|
|
|
return new SkClipRectCommand(rect, get_json_regionop(command[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP]),
|
2016-02-10 13:40:46 +00:00
|
|
|
command[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
|
|
|
|
}
|
|
|
|
|
2014-03-27 03:02:48 +00:00
|
|
|
SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkRegion::Op op, bool doAA)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kClipRRect_OpType) {
|
2013-03-22 12:25:30 +00:00
|
|
|
fRRect = rrect;
|
|
|
|
fOp = op;
|
|
|
|
fDoAA = doAA;
|
2013-01-02 20:20:31 +00:00
|
|
|
|
2013-03-22 12:25:30 +00:00
|
|
|
fInfo.push(SkObjectParser::RRectToString(rrect));
|
|
|
|
fInfo.push(SkObjectParser::RegionOpToString(op));
|
|
|
|
fInfo.push(SkObjectParser::BoolToString(doAA));
|
2013-01-02 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkClipRRectCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 12:25:30 +00:00
|
|
|
canvas->clipRRect(fRRect, fOp, fDoAA);
|
2013-01-02 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkClipRRectCommand::render(SkCanvas* canvas) const {
|
2013-06-06 23:59:28 +00:00
|
|
|
render_rrect(canvas, fRRect);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkClipRRectCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rrect(fRRect);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS] = Json::Value(fDoAA);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkClipRRectCommand* SkClipRRectCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkRRect rrect;
|
|
|
|
extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &rrect);
|
2016-03-29 16:03:52 +00:00
|
|
|
return new SkClipRRectCommand(rrect,
|
|
|
|
get_json_regionop(command[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP]),
|
2016-02-10 13:40:46 +00:00
|
|
|
command[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBool());
|
|
|
|
}
|
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkConcatCommand::SkConcatCommand(const SkMatrix& matrix)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kConcat_OpType) {
|
2013-03-22 16:33:31 +00:00
|
|
|
fMatrix = matrix;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-22 16:33:31 +00:00
|
|
|
fInfo.push(SkObjectParser::MatrixToString(matrix));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkConcatCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 16:33:31 +00:00
|
|
|
canvas->concat(fMatrix);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkConcatCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-03-03 19:39:38 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
SkConcatCommand* SkConcatCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkMatrix matrix;
|
|
|
|
extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix);
|
|
|
|
return new SkConcatCommand(matrix);
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
2014-08-13 17:46:23 +00:00
|
|
|
const SkPaint* paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawBitmap_OpType) {
|
2013-03-22 16:33:31 +00:00
|
|
|
fBitmap = bitmap;
|
|
|
|
fLeft = left;
|
|
|
|
fTop = top;
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2013-03-22 16:33:31 +00:00
|
|
|
fPaint = *paint;
|
|
|
|
fPaintPtr = &fPaint;
|
|
|
|
} else {
|
2015-08-27 14:41:13 +00:00
|
|
|
fPaintPtr = nullptr;
|
2013-03-22 16:33:31 +00:00
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-22 16:33:31 +00:00
|
|
|
fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
|
|
|
fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: "));
|
|
|
|
fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: "));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2013-03-22 16:33:31 +00:00
|
|
|
fInfo.push(SkObjectParser::PaintToString(*paint));
|
2013-01-22 14:32:09 +00:00
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawBitmapCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 16:33:31 +00:00
|
|
|
canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkDrawBitmapCommand::render(SkCanvas* canvas) const {
|
2013-06-06 23:59:28 +00:00
|
|
|
render_bitmap(canvas, fBitmap);
|
|
|
|
return true;
|
2012-11-26 13:09:17 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawBitmapCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value encoded;
|
2016-02-11 18:35:21 +00:00
|
|
|
if (flatten(fBitmap, &encoded, urlDataManager)) {
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value command(Json::objectValue);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded;
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_point(fLeft, fTop);
|
|
|
|
if (fPaintPtr != nullptr) {
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaintPtr, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawBitmapCommand* SkDrawBitmapCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
|
|
|
SkBitmap* bitmap = load_bitmap(command[SKDEBUGCANVAS_ATTRIBUTE_BITMAP], urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (bitmap == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Json::Value point = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS];
|
|
|
|
SkPaint* paintPtr;
|
|
|
|
SkPaint paint;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) {
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
paintPtr = &paint;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paintPtr = nullptr;
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawBitmapCommand* result = new SkDrawBitmapCommand(*bitmap, point[0].asFloat(),
|
2016-02-10 13:40:46 +00:00
|
|
|
point[1].asFloat(), paintPtr);
|
|
|
|
delete bitmap;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center,
|
2014-03-27 03:02:48 +00:00
|
|
|
const SkRect& dst, const SkPaint* paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawBitmapNine_OpType) {
|
2013-03-22 16:33:31 +00:00
|
|
|
fBitmap = bitmap;
|
|
|
|
fCenter = center;
|
|
|
|
fDst = dst;
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2013-03-22 16:33:31 +00:00
|
|
|
fPaint = *paint;
|
|
|
|
fPaintPtr = &fPaint;
|
|
|
|
} else {
|
2015-08-27 14:41:13 +00:00
|
|
|
fPaintPtr = nullptr;
|
2013-03-22 16:33:31 +00:00
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-22 16:33:31 +00:00
|
|
|
fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
|
|
|
fInfo.push(SkObjectParser::IRectToString(center));
|
|
|
|
fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2013-03-22 16:33:31 +00:00
|
|
|
fInfo.push(SkObjectParser::PaintToString(*paint));
|
2013-01-22 14:32:09 +00:00
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 16:33:31 +00:00
|
|
|
canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const {
|
2015-11-18 20:59:42 +00:00
|
|
|
SkRect tmp = SkRect::Make(fCenter);
|
|
|
|
render_bitmap(canvas, fBitmap, &tmp);
|
2013-06-06 23:59:28 +00:00
|
|
|
return true;
|
2012-11-26 13:09:17 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawBitmapNineCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value encoded;
|
2016-02-11 18:35:21 +00:00
|
|
|
if (flatten(fBitmap, &encoded, urlDataManager)) {
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded;
|
2016-03-03 19:39:38 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_CENTER] = MakeJsonIRect(fCenter);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_DST] = make_json_rect(fDst);
|
|
|
|
if (fPaintPtr != nullptr) {
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaintPtr, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawBitmapNineCommand* SkDrawBitmapNineCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
|
|
|
SkBitmap* bitmap = load_bitmap(command[SKDEBUGCANVAS_ATTRIBUTE_BITMAP], urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (bitmap == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SkIRect center;
|
|
|
|
extract_json_irect(command[SKDEBUGCANVAS_ATTRIBUTE_CENTER], ¢er);
|
|
|
|
SkRect dst;
|
|
|
|
extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_DST], &dst);
|
|
|
|
SkPaint* paintPtr;
|
|
|
|
SkPaint paint;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) {
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
paintPtr = &paint;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paintPtr = nullptr;
|
|
|
|
}
|
|
|
|
SkDrawBitmapNineCommand* result = new SkDrawBitmapNineCommand(*bitmap, center, dst, paintPtr);
|
|
|
|
delete bitmap;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src,
|
2013-08-16 10:24:37 +00:00
|
|
|
const SkRect& dst, const SkPaint* paint,
|
2015-07-14 17:54:12 +00:00
|
|
|
SkCanvas::SrcRectConstraint constraint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawBitmapRect_OpType) {
|
2013-03-17 18:33:46 +00:00
|
|
|
fBitmap = bitmap;
|
2014-09-05 20:34:00 +00:00
|
|
|
if (src) {
|
2013-03-17 18:33:46 +00:00
|
|
|
fSrc = *src;
|
|
|
|
} else {
|
|
|
|
fSrc.setEmpty();
|
|
|
|
}
|
|
|
|
fDst = dst;
|
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2013-03-17 18:33:46 +00:00
|
|
|
fPaint = *paint;
|
|
|
|
fPaintPtr = &fPaint;
|
2013-01-31 15:56:22 +00:00
|
|
|
} else {
|
2015-08-27 14:41:13 +00:00
|
|
|
fPaintPtr = nullptr;
|
2013-01-31 15:56:22 +00:00
|
|
|
}
|
2015-07-14 17:54:12 +00:00
|
|
|
fConstraint = constraint;
|
2013-08-16 10:24:37 +00:00
|
|
|
|
2013-03-17 18:33:46 +00:00
|
|
|
fInfo.push(SkObjectParser::BitmapToString(bitmap));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (src) {
|
2013-03-17 18:33:46 +00:00
|
|
|
fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
|
2013-01-22 14:32:09 +00:00
|
|
|
}
|
2013-03-17 18:33:46 +00:00
|
|
|
fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2013-03-17 18:33:46 +00:00
|
|
|
fInfo.push(SkObjectParser::PaintToString(*paint));
|
2013-01-22 14:32:09 +00:00
|
|
|
}
|
2015-07-14 17:54:12 +00:00
|
|
|
fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const {
|
2015-08-06 17:02:53 +00:00
|
|
|
canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const {
|
2013-06-06 23:59:28 +00:00
|
|
|
render_bitmap(canvas, fBitmap, this->srcRect());
|
|
|
|
return true;
|
2012-11-26 13:09:17 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawBitmapRectCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value encoded;
|
2016-02-11 18:35:21 +00:00
|
|
|
if (flatten(fBitmap, &encoded, urlDataManager)) {
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded;
|
|
|
|
if (!fSrc.isEmpty()) {
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_SRC] = make_json_rect(fSrc);
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_DST] = make_json_rect(fDst);
|
|
|
|
if (fPaintPtr != nullptr) {
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaintPtr, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
if (fConstraint == SkCanvas::kStrict_SrcRectConstraint) {
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_STRICT] = Json::Value(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawBitmapRectCommand* SkDrawBitmapRectCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
|
|
|
SkBitmap* bitmap = load_bitmap(command[SKDEBUGCANVAS_ATTRIBUTE_BITMAP], urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (bitmap == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SkRect dst;
|
|
|
|
extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_DST], &dst);
|
|
|
|
SkPaint* paintPtr;
|
|
|
|
SkPaint paint;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) {
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
paintPtr = &paint;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paintPtr = nullptr;
|
|
|
|
}
|
|
|
|
SkCanvas::SrcRectConstraint constraint;
|
2016-03-29 16:03:52 +00:00
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_STRICT) &&
|
2016-02-10 13:40:46 +00:00
|
|
|
command[SKDEBUGCANVAS_ATTRIBUTE_STRICT].asBool()) {
|
|
|
|
constraint = SkCanvas::kStrict_SrcRectConstraint;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
constraint = SkCanvas::kFast_SrcRectConstraint;
|
|
|
|
}
|
|
|
|
SkRect* srcPtr;
|
|
|
|
SkRect src;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_SRC)) {
|
|
|
|
extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_SRC], &src);
|
|
|
|
srcPtr = &src;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
srcPtr = nullptr;
|
|
|
|
}
|
|
|
|
SkDrawBitmapRectCommand* result = new SkDrawBitmapRectCommand(*bitmap, srcPtr, dst, paintPtr,
|
|
|
|
constraint);
|
|
|
|
delete bitmap;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-07-22 17:23:01 +00:00
|
|
|
SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top,
|
|
|
|
const SkPaint* paint)
|
|
|
|
: INHERITED(kDrawImage_OpType)
|
|
|
|
, fImage(SkRef(image))
|
|
|
|
, fLeft(left)
|
|
|
|
, fTop(top) {
|
|
|
|
|
2015-10-29 19:13:48 +00:00
|
|
|
fInfo.push(SkObjectParser::ImageToString(image));
|
|
|
|
fInfo.push(SkObjectParser::ScalarToString(left, "Left: "));
|
|
|
|
fInfo.push(SkObjectParser::ScalarToString(top, "Top: "));
|
|
|
|
|
2015-07-22 17:23:01 +00:00
|
|
|
if (paint) {
|
|
|
|
fPaint.set(*paint);
|
2015-10-29 19:13:48 +00:00
|
|
|
fInfo.push(SkObjectParser::PaintToString(*paint));
|
2015-07-22 17:23:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDrawImageCommand::execute(SkCanvas* canvas) const {
|
|
|
|
canvas->drawImage(fImage, fLeft, fTop, fPaint.getMaybeNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDrawImageCommand::render(SkCanvas* canvas) const {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->clear(0xFFFFFFFF);
|
|
|
|
|
|
|
|
xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop,
|
|
|
|
SkIntToScalar(fImage->width()),
|
|
|
|
SkIntToScalar(fImage->height())));
|
|
|
|
this->execute(canvas);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawImageCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value encoded;
|
2016-02-11 18:35:21 +00:00
|
|
|
if (flatten(*fImage, &encoded, urlDataManager)) {
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_IMAGE] = encoded;
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_point(fLeft, fTop);
|
|
|
|
if (fPaint.isValid()) {
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaint.get(), urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawImageCommand* SkDrawImageCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image = load_image(command[SKDEBUGCANVAS_ATTRIBUTE_IMAGE], urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (image == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Json::Value point = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS];
|
|
|
|
SkPaint* paintPtr;
|
|
|
|
SkPaint paint;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) {
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
paintPtr = &paint;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paintPtr = nullptr;
|
|
|
|
}
|
2016-03-17 17:51:11 +00:00
|
|
|
SkDrawImageCommand* result = new SkDrawImageCommand(image.get(), point[0].asFloat(),
|
2016-02-10 13:40:46 +00:00
|
|
|
point[1].asFloat(), paintPtr);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-07-22 17:23:01 +00:00
|
|
|
SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRect* src,
|
|
|
|
const SkRect& dst, const SkPaint* paint,
|
|
|
|
SkCanvas::SrcRectConstraint constraint)
|
|
|
|
: INHERITED(kDrawImageRect_OpType)
|
|
|
|
, fImage(SkRef(image))
|
|
|
|
, fDst(dst)
|
|
|
|
, fConstraint(constraint) {
|
|
|
|
|
|
|
|
if (src) {
|
|
|
|
fSrc.set(*src);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (paint) {
|
|
|
|
fPaint.set(*paint);
|
|
|
|
}
|
2015-08-24 15:27:38 +00:00
|
|
|
|
|
|
|
fInfo.push(SkObjectParser::ImageToString(image));
|
|
|
|
if (src) {
|
|
|
|
fInfo.push(SkObjectParser::RectToString(*src, "Src: "));
|
|
|
|
}
|
|
|
|
fInfo.push(SkObjectParser::RectToString(dst, "Dst: "));
|
|
|
|
if (paint) {
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(*paint));
|
|
|
|
}
|
|
|
|
fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: "));
|
2015-07-22 17:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkDrawImageRectCommand::execute(SkCanvas* canvas) const {
|
2016-03-29 16:03:52 +00:00
|
|
|
canvas->legacy_drawImageRect(fImage, fSrc.getMaybeNull(), fDst, fPaint.getMaybeNull(),
|
2016-02-10 22:05:02 +00:00
|
|
|
fConstraint);
|
2015-07-22 17:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDrawImageRectCommand::render(SkCanvas* canvas) const {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->clear(0xFFFFFFFF);
|
|
|
|
|
|
|
|
xlate_and_scale_to_bounds(canvas, fDst);
|
|
|
|
|
|
|
|
this->execute(canvas);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawImageRectCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value encoded;
|
2016-02-11 18:35:21 +00:00
|
|
|
if (flatten(*fImage.get(), &encoded, urlDataManager)) {
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded;
|
|
|
|
if (fSrc.isValid()) {
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_SRC] = make_json_rect(*fSrc.get());
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_DST] = make_json_rect(fDst);
|
|
|
|
if (fPaint.isValid()) {
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaint.get(), urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
if (fConstraint == SkCanvas::kStrict_SrcRectConstraint) {
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_STRICT] = Json::Value(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawImageRectCommand* SkDrawImageRectCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image = load_image(command[SKDEBUGCANVAS_ATTRIBUTE_IMAGE], urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (image == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SkRect dst;
|
|
|
|
extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_DST], &dst);
|
|
|
|
SkPaint* paintPtr;
|
|
|
|
SkPaint paint;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) {
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
paintPtr = &paint;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
paintPtr = nullptr;
|
|
|
|
}
|
|
|
|
SkCanvas::SrcRectConstraint constraint;
|
2016-03-29 16:03:52 +00:00
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_STRICT) &&
|
2016-02-10 13:40:46 +00:00
|
|
|
command[SKDEBUGCANVAS_ATTRIBUTE_STRICT].asBool()) {
|
|
|
|
constraint = SkCanvas::kStrict_SrcRectConstraint;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
constraint = SkCanvas::kFast_SrcRectConstraint;
|
|
|
|
}
|
|
|
|
SkRect* srcPtr;
|
|
|
|
SkRect src;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_SRC)) {
|
|
|
|
extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_SRC], &src);
|
|
|
|
srcPtr = &src;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
srcPtr = nullptr;
|
|
|
|
}
|
2016-03-17 17:51:11 +00:00
|
|
|
SkDrawImageRectCommand* result = new SkDrawImageRectCommand(image.get(), srcPtr, dst, paintPtr,
|
2016-02-10 13:40:46 +00:00
|
|
|
constraint);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawOval_OpType) {
|
2013-03-22 12:25:30 +00:00
|
|
|
fOval = oval;
|
|
|
|
fPaint = paint;
|
2013-01-02 20:20:31 +00:00
|
|
|
|
2013-03-22 12:25:30 +00:00
|
|
|
fInfo.push(SkObjectParser::RectToString(oval));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2013-01-02 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawOvalCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 12:25:30 +00:00
|
|
|
canvas->drawOval(fOval, fPaint);
|
2013-01-02 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkDrawOvalCommand::render(SkCanvas* canvas) const {
|
2013-06-06 23:59:28 +00:00
|
|
|
canvas->clear(0xFFFFFFFF);
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
xlate_and_scale_to_bounds(canvas, fOval);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->drawOval(fOval, p);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawOvalCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rect(fOval);
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawOvalCommand* SkDrawOvalCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkRect coords;
|
|
|
|
extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords);
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
return new SkDrawOvalCommand(coords, paint);
|
|
|
|
}
|
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawPaint_OpType) {
|
2013-03-22 12:25:30 +00:00
|
|
|
fPaint = paint;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-22 12:25:30 +00:00
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawPaintCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 12:25:30 +00:00
|
|
|
canvas->drawPaint(fPaint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkDrawPaintCommand::render(SkCanvas* canvas) const {
|
2013-06-06 23:59:28 +00:00
|
|
|
canvas->clear(0xFFFFFFFF);
|
|
|
|
canvas->drawPaint(fPaint);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawPaintCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawPaintCommand* SkDrawPaintCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
return new SkDrawPaintCommand(paint);
|
|
|
|
}
|
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawPath_OpType) {
|
2013-03-17 18:33:46 +00:00
|
|
|
fPath = path;
|
|
|
|
fPaint = paint;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-17 18:33:46 +00:00
|
|
|
fInfo.push(SkObjectParser::PathToString(path));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawPathCommand::execute(SkCanvas* canvas) const {
|
2013-03-17 18:33:46 +00:00
|
|
|
canvas->drawPath(fPath, fPaint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkDrawPathCommand::render(SkCanvas* canvas) const {
|
2013-06-06 23:59:28 +00:00
|
|
|
render_path(canvas, fPath);
|
|
|
|
return true;
|
2012-11-21 17:11:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawPathCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = make_json_path(fPath);
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawPathCommand* SkDrawPathCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkPath path;
|
|
|
|
extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path);
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
return new SkDrawPathCommand(path, paint);
|
|
|
|
}
|
|
|
|
|
2015-04-02 03:58:37 +00:00
|
|
|
SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture,
|
|
|
|
const SkMatrix* matrix,
|
|
|
|
const SkPaint* paint)
|
|
|
|
: INHERITED(kBeginDrawPicture_OpType)
|
|
|
|
, fPicture(SkRef(picture)) {
|
2014-08-13 17:46:23 +00:00
|
|
|
|
2015-04-02 03:58:37 +00:00
|
|
|
SkString* str = new SkString;
|
|
|
|
str->appendf("SkPicture: L: %f T: %f R: %f B: %f",
|
|
|
|
picture->cullRect().fLeft, picture->cullRect().fTop,
|
|
|
|
picture->cullRect().fRight, picture->cullRect().fBottom);
|
|
|
|
fInfo.push(str);
|
2014-08-13 17:46:23 +00:00
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
if (matrix) {
|
2015-04-02 03:58:37 +00:00
|
|
|
fMatrix.set(*matrix);
|
2014-08-13 17:46:23 +00:00
|
|
|
fInfo.push(SkObjectParser::MatrixToString(*matrix));
|
|
|
|
}
|
2015-04-02 03:58:37 +00:00
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2015-04-02 03:58:37 +00:00
|
|
|
fPaint.set(*paint);
|
2014-08-13 17:46:23 +00:00
|
|
|
fInfo.push(SkObjectParser::PaintToString(*paint));
|
|
|
|
}
|
2015-04-02 03:58:37 +00:00
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 03:58:37 +00:00
|
|
|
void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const {
|
|
|
|
if (fPaint.isValid()) {
|
|
|
|
SkRect bounds = fPicture->cullRect();
|
|
|
|
if (fMatrix.isValid()) {
|
|
|
|
fMatrix.get()->mapRect(&bounds);
|
|
|
|
}
|
|
|
|
canvas->saveLayer(&bounds, fPaint.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fMatrix.isValid()) {
|
|
|
|
if (!fPaint.isValid()) {
|
|
|
|
canvas->save();
|
|
|
|
}
|
|
|
|
canvas->concat(*fMatrix.get());
|
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 03:58:37 +00:00
|
|
|
bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const {
|
2013-11-21 17:08:12 +00:00
|
|
|
canvas->clear(0xFFFFFFFF);
|
|
|
|
canvas->save();
|
|
|
|
|
2014-08-29 15:03:56 +00:00
|
|
|
xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
|
2013-11-21 17:08:12 +00:00
|
|
|
|
2014-06-04 12:40:44 +00:00
|
|
|
canvas->drawPicture(fPicture.get());
|
2013-11-21 17:08:12 +00:00
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-02 03:58:37 +00:00
|
|
|
SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore)
|
|
|
|
: INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { }
|
|
|
|
|
|
|
|
void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const {
|
|
|
|
if (fRestore) {
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count,
|
2014-03-25 23:31:33 +00:00
|
|
|
const SkPoint pts[], const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawPoints_OpType) {
|
2013-03-22 12:25:30 +00:00
|
|
|
fMode = mode;
|
|
|
|
fCount = count;
|
|
|
|
fPts = new SkPoint[count];
|
|
|
|
memcpy(fPts, pts, count * sizeof(SkPoint));
|
|
|
|
fPaint = paint;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-22 12:25:30 +00:00
|
|
|
fInfo.push(SkObjectParser::PointsToString(pts, count));
|
|
|
|
fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count),
|
|
|
|
"Points: "));
|
|
|
|
fInfo.push(SkObjectParser::PointModeToString(mode));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawPointsCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 12:25:30 +00:00
|
|
|
canvas->drawPoints(fMode, fCount, fPts, fPaint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkDrawPointsCommand::render(SkCanvas* canvas) const {
|
2013-06-06 23:59:28 +00:00
|
|
|
canvas->clear(0xFFFFFFFF);
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
SkRect bounds;
|
|
|
|
|
|
|
|
bounds.setEmpty();
|
|
|
|
for (unsigned int i = 0; i < fCount; ++i) {
|
|
|
|
bounds.growToInclude(fPts[i].fX, fPts[i].fY);
|
|
|
|
}
|
2013-06-07 07:01:06 +00:00
|
|
|
|
2013-06-06 23:59:28 +00:00
|
|
|
xlate_and_scale_to_bounds(canvas, bounds);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->drawPoints(fMode, fCount, fPts, p);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawPointsCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_MODE] = make_json_pointmode(fMode);
|
|
|
|
Json::Value points(Json::arrayValue);
|
|
|
|
for (size_t i = 0; i < fCount; i++) {
|
|
|
|
points.append(make_json_point(fPts[i]));
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_POINTS] = points;
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawPointsCommand* SkDrawPointsCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkCanvas::PointMode mode;
|
|
|
|
const char* jsonMode = command[SKDEBUGCANVAS_ATTRIBUTE_MODE].asCString();
|
|
|
|
if (!strcmp(jsonMode, SKDEBUGCANVAS_POINTMODE_POINTS)) {
|
|
|
|
mode = SkCanvas::kPoints_PointMode;
|
|
|
|
}
|
|
|
|
else if (!strcmp(jsonMode, SKDEBUGCANVAS_POINTMODE_LINES)) {
|
|
|
|
mode = SkCanvas::kLines_PointMode;
|
|
|
|
}
|
|
|
|
else if (!strcmp(jsonMode, SKDEBUGCANVAS_POINTMODE_POLYGON)) {
|
|
|
|
mode = SkCanvas::kPolygon_PointMode;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SkASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Json::Value jsonPoints = command[SKDEBUGCANVAS_ATTRIBUTE_POINTS];
|
|
|
|
int count = (int) jsonPoints.size();
|
|
|
|
SkPoint* points = (SkPoint*) sk_malloc_throw(count * sizeof(SkPoint));
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
points[i] = SkPoint::Make(jsonPoints[i][0].asFloat(), jsonPoints[i][1].asFloat());
|
|
|
|
}
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
SkDrawPointsCommand* result = new SkDrawPointsCommand(mode, count, points, paint);
|
|
|
|
sk_free(points);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength,
|
2014-03-25 23:31:33 +00:00
|
|
|
const SkPoint pos[], const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawPosText_OpType) {
|
2013-03-22 12:25:30 +00:00
|
|
|
size_t numPts = paint.countText(text, byteLength);
|
|
|
|
|
|
|
|
fText = new char[byteLength];
|
|
|
|
memcpy(fText, text, byteLength);
|
|
|
|
fByteLength = byteLength;
|
|
|
|
|
|
|
|
fPos = new SkPoint[numPts];
|
|
|
|
memcpy(fPos, pos, numPts * sizeof(SkPoint));
|
|
|
|
|
|
|
|
fPaint = paint;
|
|
|
|
|
|
|
|
fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
|
2012-06-29 14:21:22 +00:00
|
|
|
// TODO(chudy): Test that this works.
|
2013-03-22 12:25:30 +00:00
|
|
|
fInfo.push(SkObjectParser::PointsToString(pos, 1));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawPosTextCommand::execute(SkCanvas* canvas) const {
|
2013-03-22 12:25:30 +00:00
|
|
|
canvas->drawPosText(fText, fByteLength, fPos, fPaint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawPosTextCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-03-29 16:03:52 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText,
|
2016-02-10 13:40:46 +00:00
|
|
|
((const char*) fText) + fByteLength);
|
|
|
|
Json::Value coords(Json::arrayValue);
|
2016-03-09 15:42:54 +00:00
|
|
|
size_t numCoords = fPaint.textToGlyphs(fText, fByteLength, nullptr);
|
|
|
|
for (size_t i = 0; i < numCoords; i++) {
|
2016-02-10 13:40:46 +00:00
|
|
|
coords.append(make_json_point(fPos[i]));
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = coords;
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawPosTextCommand* SkDrawPosTextCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString();
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value coords = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS];
|
|
|
|
int count = (int) coords.size();
|
|
|
|
SkPoint* points = (SkPoint*) sk_malloc_throw(count * sizeof(SkPoint));
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
points[i] = SkPoint::Make(coords[i][0].asFloat(), coords[i][1].asFloat());
|
|
|
|
}
|
|
|
|
return new SkDrawPosTextCommand(text, strlen(text), points, paint);
|
|
|
|
}
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength,
|
|
|
|
const SkScalar xpos[], SkScalar constY,
|
2014-03-25 23:31:33 +00:00
|
|
|
const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawPosTextH_OpType) {
|
2013-03-22 12:25:30 +00:00
|
|
|
size_t numPts = paint.countText(text, byteLength);
|
|
|
|
|
|
|
|
fText = new char[byteLength];
|
|
|
|
memcpy(fText, text, byteLength);
|
2013-03-17 18:33:46 +00:00
|
|
|
fByteLength = byteLength;
|
2013-03-22 12:25:30 +00:00
|
|
|
|
|
|
|
fXpos = new SkScalar[numPts];
|
|
|
|
memcpy(fXpos, xpos, numPts * sizeof(SkScalar));
|
|
|
|
|
2013-03-17 18:33:46 +00:00
|
|
|
fConstY = constY;
|
|
|
|
fPaint = paint;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-17 18:33:46 +00:00
|
|
|
fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
|
|
|
|
fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: "));
|
|
|
|
fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: "));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const {
|
2013-03-17 18:33:46 +00:00
|
|
|
canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 15:42:54 +00:00
|
|
|
Json::Value SkDrawPosTextHCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText,
|
|
|
|
((const char*) fText) + fByteLength);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_Y] = Json::Value(fConstY);
|
|
|
|
Json::Value xpos(Json::arrayValue);
|
|
|
|
size_t numXpos = fPaint.textToGlyphs(fText, fByteLength, nullptr);
|
|
|
|
for (size_t i = 0; i < numXpos; i++) {
|
|
|
|
xpos.append(Json::Value(fXpos[i]));
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS] = xpos;
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkDrawPosTextHCommand* SkDrawPosTextHCommand::fromJSON(Json::Value& command,
|
|
|
|
UrlDataManager& urlDataManager) {
|
|
|
|
const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString();
|
|
|
|
SkPaint paint;
|
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
|
|
|
Json::Value jsonXpos = command[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS];
|
|
|
|
int count = (int) jsonXpos.size();
|
|
|
|
SkScalar* xpos = (SkScalar*) sk_malloc_throw(count * sizeof(SkScalar));
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
xpos[i] = jsonXpos[i].asFloat();
|
|
|
|
}
|
|
|
|
SkScalar y = command[SKDEBUGCANVAS_ATTRIBUTE_Y].asFloat();
|
|
|
|
return new SkDrawPosTextHCommand(text, strlen(text), xpos, y, paint);
|
|
|
|
}
|
|
|
|
|
2016-01-04 16:08:04 +00:00
|
|
|
static const char* gPositioningLabels[] = {
|
|
|
|
"kDefault_Positioning",
|
|
|
|
"kHorizontal_Positioning",
|
|
|
|
"kFull_Positioning",
|
|
|
|
};
|
|
|
|
|
2014-08-26 14:56:44 +00:00
|
|
|
SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y,
|
|
|
|
const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawTextBlob_OpType)
|
2015-12-09 02:59:18 +00:00
|
|
|
, fBlob(SkRef(blob))
|
2014-08-26 14:56:44 +00:00
|
|
|
, fXPos(x)
|
|
|
|
, fYPos(y)
|
|
|
|
, fPaint(paint) {
|
|
|
|
|
2015-12-09 02:59:18 +00:00
|
|
|
SkAutoTDelete<SkString> runsStr(new SkString);
|
2014-08-26 14:56:44 +00:00
|
|
|
fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: "));
|
2014-12-09 13:28:20 +00:00
|
|
|
fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: "));
|
|
|
|
fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: "));
|
2015-12-09 02:59:18 +00:00
|
|
|
fInfo.push(runsStr);
|
2014-08-26 14:56:44 +00:00
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2015-12-09 02:59:18 +00:00
|
|
|
|
|
|
|
unsigned runs = 0;
|
|
|
|
SkPaint runPaint(paint);
|
|
|
|
SkTextBlobRunIterator iter(blob);
|
|
|
|
while (!iter.done()) {
|
2016-01-04 16:08:04 +00:00
|
|
|
SkAutoTDelete<SkString> tmpStr(new SkString);
|
|
|
|
tmpStr->printf("==== Run [%d] ====", runs++);
|
|
|
|
fInfo.push(tmpStr.release());
|
2015-12-09 02:59:18 +00:00
|
|
|
|
|
|
|
fInfo.push(SkObjectParser::IntToString(iter.glyphCount(), "GlyphCount: "));
|
2016-01-04 16:08:04 +00:00
|
|
|
tmpStr.reset(new SkString("GlyphPositioning: "));
|
|
|
|
tmpStr->append(gPositioningLabels[iter.positioning()]);
|
|
|
|
fInfo.push(tmpStr.release());
|
|
|
|
|
2015-12-09 02:59:18 +00:00
|
|
|
iter.applyFontToPaint(&runPaint);
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(runPaint));
|
|
|
|
|
|
|
|
iter.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
runsStr->printf("Runs: %d", runs);
|
|
|
|
// runStr is owned by fInfo at this point.
|
|
|
|
runsStr.release();
|
2014-08-26 14:56:44 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const {
|
2014-08-26 14:56:44 +00:00
|
|
|
canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint);
|
|
|
|
}
|
|
|
|
|
2014-08-29 22:08:20 +00:00
|
|
|
bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const {
|
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos);
|
|
|
|
xlate_and_scale_to_bounds(canvas, bounds);
|
|
|
|
|
|
|
|
canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawTextBlobCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value runs(Json::arrayValue);
|
|
|
|
SkTextBlobRunIterator iter(fBlob.get());
|
|
|
|
while (!iter.done()) {
|
|
|
|
Json::Value run(Json::objectValue);
|
|
|
|
Json::Value jsonPositions(Json::arrayValue);
|
|
|
|
Json::Value jsonGlyphs(Json::arrayValue);
|
|
|
|
const SkScalar* iterPositions = iter.pos();
|
|
|
|
const uint16_t* iterGlyphs = iter.glyphs();
|
|
|
|
for (uint32_t i = 0; i < iter.glyphCount(); i++) {
|
|
|
|
switch (iter.positioning()) {
|
|
|
|
case SkTextBlob::kFull_Positioning:
|
|
|
|
jsonPositions.append(make_json_point(iterPositions[i * 2],
|
|
|
|
iterPositions[i * 2 + 1]));
|
|
|
|
break;
|
|
|
|
case SkTextBlob::kHorizontal_Positioning:
|
|
|
|
jsonPositions.append(Json::Value(iterPositions[i]));
|
|
|
|
break;
|
|
|
|
case SkTextBlob::kDefault_Positioning:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
jsonGlyphs.append(Json::Value(iterGlyphs[i]));
|
|
|
|
}
|
|
|
|
if (iter.positioning() != SkTextBlob::kDefault_Positioning) {
|
|
|
|
run[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS] = jsonPositions;
|
|
|
|
}
|
|
|
|
run[SKDEBUGCANVAS_ATTRIBUTE_GLYPHS] = jsonGlyphs;
|
|
|
|
SkPaint fontPaint;
|
|
|
|
iter.applyFontToPaint(&fontPaint);
|
2016-02-11 18:35:21 +00:00
|
|
|
run[SKDEBUGCANVAS_ATTRIBUTE_FONT] = make_json_paint(fontPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
run[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_point(iter.offset());
|
|
|
|
runs.append(run);
|
|
|
|
iter.next();
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_RUNS] = runs;
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_X] = Json::Value(fXPos);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_Y] = Json::Value(fYPos);
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawTextBlobCommand* SkDrawTextBlobCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
Json::Value runs = command[SKDEBUGCANVAS_ATTRIBUTE_RUNS];
|
|
|
|
for (Json::ArrayIndex i = 0 ; i < runs.size(); i++) {
|
|
|
|
Json::Value run = runs[i];
|
|
|
|
SkPaint font;
|
|
|
|
font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(run[SKDEBUGCANVAS_ATTRIBUTE_FONT], urlDataManager, &font);
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value glyphs = run[SKDEBUGCANVAS_ATTRIBUTE_GLYPHS];
|
|
|
|
int count = glyphs.size();
|
|
|
|
Json::Value coords = run[SKDEBUGCANVAS_ATTRIBUTE_COORDS];
|
|
|
|
SkScalar x = coords[0].asFloat();
|
|
|
|
SkScalar y = coords[1].asFloat();
|
|
|
|
if (run.isMember(SKDEBUGCANVAS_ATTRIBUTE_POSITIONS)) {
|
|
|
|
Json::Value positions = run[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS];
|
|
|
|
if (positions.size() > 0 && positions[0].isNumeric()) {
|
|
|
|
SkTextBlobBuilder::RunBuffer buffer = builder.allocRunPosH(font, count, y);
|
|
|
|
for (int j = 0; j < count; j++) {
|
|
|
|
buffer.glyphs[j] = glyphs[j].asUInt();
|
|
|
|
buffer.pos[j] = positions[j].asFloat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SkTextBlobBuilder::RunBuffer buffer = builder.allocRunPos(font, count);
|
|
|
|
for (int j = 0; j < count; j++) {
|
|
|
|
buffer.glyphs[j] = glyphs[j].asUInt();
|
|
|
|
buffer.pos[j * 2] = positions[j][0].asFloat();
|
|
|
|
buffer.pos[j * 2 + 1] = positions[j][1].asFloat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SkTextBlobBuilder::RunBuffer buffer = builder.allocRun(font, count, x, y);
|
|
|
|
for (int j = 0; j < count; j++) {
|
|
|
|
buffer.glyphs[j] = glyphs[j].asUInt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkScalar x = command[SKDEBUGCANVAS_ATTRIBUTE_X].asFloat();
|
|
|
|
SkScalar y = command[SKDEBUGCANVAS_ATTRIBUTE_Y].asFloat();
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
return new SkDrawTextBlobCommand(builder.build(), x, y, paint);
|
|
|
|
}
|
|
|
|
|
2015-02-13 19:13:00 +00:00
|
|
|
SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4],
|
|
|
|
const SkPoint texCoords[4], SkXfermode* xfermode,
|
|
|
|
const SkPaint& paint)
|
|
|
|
: INHERITED(kDrawPatch_OpType) {
|
|
|
|
memcpy(fCubics, cubics, sizeof(fCubics));
|
2016-02-10 22:05:02 +00:00
|
|
|
if (colors != nullptr) {
|
|
|
|
memcpy(fColors, colors, sizeof(fColors));
|
|
|
|
fColorsPtr = fColors;
|
|
|
|
} else {
|
|
|
|
fColorsPtr = nullptr;
|
|
|
|
}
|
|
|
|
if (texCoords != nullptr) {
|
|
|
|
memcpy(fTexCoords, texCoords, sizeof(fTexCoords));
|
|
|
|
fTexCoordsPtr = fTexCoords;
|
|
|
|
} else {
|
|
|
|
fTexCoordsPtr = nullptr;
|
|
|
|
}
|
|
|
|
if (xfermode != nullptr) {
|
|
|
|
fXfermode.reset(SkRef(xfermode));
|
|
|
|
}
|
2015-02-13 19:13:00 +00:00
|
|
|
fPaint = paint;
|
|
|
|
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkDrawPatchCommand::execute(SkCanvas* canvas) const {
|
2016-02-10 22:05:02 +00:00
|
|
|
canvas->drawPatch(fCubics, fColorsPtr, fTexCoordsPtr, fXfermode, fPaint);
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawPatchCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 22:05:02 +00:00
|
|
|
Json::Value cubics = Json::Value(Json::arrayValue);
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
cubics.append(make_json_point(fCubics[i]));
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_CUBICS] = cubics;
|
|
|
|
if (fColorsPtr != nullptr) {
|
|
|
|
Json::Value colors = Json::Value(Json::arrayValue);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
colors.append(make_json_color(fColorsPtr[i]));
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COLORS] = colors;
|
|
|
|
}
|
|
|
|
if (fTexCoordsPtr != nullptr) {
|
|
|
|
Json::Value texCoords = Json::Value(Json::arrayValue);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
texCoords.append(make_json_point(fTexCoords[i]));
|
|
|
|
}
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_TEXTURECOORDS] = texCoords;
|
|
|
|
}
|
|
|
|
if (fXfermode.get() != nullptr) {
|
|
|
|
Json::Value jsonXfermode;
|
2016-02-11 18:35:21 +00:00
|
|
|
flatten(fXfermode, &jsonXfermode, urlDataManager);
|
2016-02-10 22:05:02 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_XFERMODE] = jsonXfermode;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawPatchCommand* SkDrawPatchCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 22:05:02 +00:00
|
|
|
Json::Value jsonCubics = command[SKDEBUGCANVAS_ATTRIBUTE_CUBICS];
|
|
|
|
SkPoint cubics[12];
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
cubics[i] = get_json_point(jsonCubics[i]);
|
|
|
|
}
|
|
|
|
SkColor* colorsPtr;
|
|
|
|
SkColor colors[4];
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLORS)) {
|
|
|
|
Json::Value jsonColors = command[SKDEBUGCANVAS_ATTRIBUTE_COLORS];
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
colors[i] = get_json_color(jsonColors[i]);
|
|
|
|
}
|
|
|
|
colorsPtr = colors;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
colorsPtr = nullptr;
|
|
|
|
}
|
|
|
|
SkPoint* texCoordsPtr;
|
|
|
|
SkPoint texCoords[4];
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTURECOORDS)) {
|
|
|
|
Json::Value jsonTexCoords = command[SKDEBUGCANVAS_ATTRIBUTE_TEXTURECOORDS];
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
texCoords[i] = get_json_point(jsonTexCoords[i]);
|
|
|
|
}
|
|
|
|
texCoordsPtr = texCoords;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
texCoordsPtr = nullptr;
|
|
|
|
}
|
|
|
|
SkAutoTUnref<SkXfermode> xfermode;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_XFERMODE)) {
|
|
|
|
Json::Value jsonXfermode = command[SKDEBUGCANVAS_ATTRIBUTE_XFERMODE];
|
2016-02-11 18:35:21 +00:00
|
|
|
xfermode.reset((SkXfermode*) load_flattenable(jsonXfermode, urlDataManager));
|
2016-02-10 22:05:02 +00:00
|
|
|
}
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 22:05:02 +00:00
|
|
|
return new SkDrawPatchCommand(cubics, colorsPtr, texCoordsPtr, xfermode, paint);
|
2015-02-13 19:13:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawRect_OpType) {
|
2013-03-17 18:33:46 +00:00
|
|
|
fRect = rect;
|
|
|
|
fPaint = paint;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-17 18:33:46 +00:00
|
|
|
fInfo.push(SkObjectParser::RectToString(rect));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawRectCommand::execute(SkCanvas* canvas) const {
|
2013-03-17 18:33:46 +00:00
|
|
|
canvas->drawRect(fRect, fPaint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawRectCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rect(fRect);
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawRectCommand* SkDrawRectCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkRect coords;
|
|
|
|
extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords);
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
return new SkDrawRectCommand(coords, paint);
|
|
|
|
}
|
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawRRect_OpType) {
|
2013-03-25 11:50:42 +00:00
|
|
|
fRRect = rrect;
|
|
|
|
fPaint = paint;
|
2013-01-02 20:20:31 +00:00
|
|
|
|
2013-03-25 11:50:42 +00:00
|
|
|
fInfo.push(SkObjectParser::RRectToString(rrect));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2013-01-02 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawRRectCommand::execute(SkCanvas* canvas) const {
|
2013-03-11 22:53:11 +00:00
|
|
|
canvas->drawRRect(fRRect, fPaint);
|
2013-01-02 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
bool SkDrawRRectCommand::render(SkCanvas* canvas) const {
|
2013-06-06 23:59:28 +00:00
|
|
|
render_rrect(canvas, fRRect);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawRRectCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rrect(fRRect);
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawRRectCommand* SkDrawRRectCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkRRect coords;
|
|
|
|
extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords);
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
return new SkDrawRRectCommand(coords, paint);
|
|
|
|
}
|
|
|
|
|
2014-02-25 03:05:18 +00:00
|
|
|
SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer,
|
2014-02-24 17:28:55 +00:00
|
|
|
const SkRRect& inner,
|
2014-03-25 23:31:33 +00:00
|
|
|
const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawDRRect_OpType) {
|
2014-02-24 17:28:55 +00:00
|
|
|
fOuter = outer;
|
|
|
|
fInner = inner;
|
|
|
|
fPaint = paint;
|
|
|
|
|
|
|
|
fInfo.push(SkObjectParser::RRectToString(outer));
|
|
|
|
fInfo.push(SkObjectParser::RRectToString(inner));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawDRRectCommand::execute(SkCanvas* canvas) const {
|
2014-02-24 17:28:55 +00:00
|
|
|
canvas->drawDRRect(fOuter, fInner, fPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkDrawDRRectCommand::render(SkCanvas* canvas) const {
|
|
|
|
render_drrect(canvas, fOuter, fInner);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawDRRectCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_OUTER] = make_json_rrect(fOuter);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_INNER] = make_json_rrect(fInner);
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawDRRectCommand* SkDrawDRRectCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkRRect outer;
|
|
|
|
extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_INNER], &outer);
|
|
|
|
SkRRect inner;
|
|
|
|
extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_INNER], &inner);
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
return new SkDrawDRRectCommand(outer, inner, paint);
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y,
|
2014-03-25 23:31:33 +00:00
|
|
|
const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawText_OpType) {
|
2013-03-25 11:50:42 +00:00
|
|
|
fText = new char[byteLength];
|
|
|
|
memcpy(fText, text, byteLength);
|
|
|
|
fByteLength = byteLength;
|
|
|
|
fX = x;
|
|
|
|
fY = y;
|
|
|
|
fPaint = paint;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-25 11:50:42 +00:00
|
|
|
fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
|
|
|
|
fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: "));
|
|
|
|
fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: "));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawTextCommand::execute(SkCanvas* canvas) const {
|
2013-03-25 11:50:42 +00:00
|
|
|
canvas->drawText(fText, fByteLength, fX, fY, fPaint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawTextCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-03-29 16:03:52 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText,
|
2016-02-10 13:40:46 +00:00
|
|
|
((const char*) fText) + fByteLength);
|
|
|
|
Json::Value coords(Json::arrayValue);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_point(fX, fY);
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawTextCommand* SkDrawTextCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString();
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
Json::Value coords = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS];
|
2016-03-29 16:03:52 +00:00
|
|
|
return new SkDrawTextCommand(text, strlen(text), coords[0].asFloat(), coords[1].asFloat(),
|
2016-02-10 13:40:46 +00:00
|
|
|
paint);
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength,
|
|
|
|
const SkPath& path, const SkMatrix* matrix,
|
2014-03-25 23:31:33 +00:00
|
|
|
const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawTextOnPath_OpType) {
|
2013-03-25 11:50:42 +00:00
|
|
|
fText = new char[byteLength];
|
|
|
|
memcpy(fText, text, byteLength);
|
|
|
|
fByteLength = byteLength;
|
|
|
|
fPath = path;
|
2014-09-05 20:34:00 +00:00
|
|
|
if (matrix) {
|
2013-03-25 11:50:42 +00:00
|
|
|
fMatrix = *matrix;
|
|
|
|
} else {
|
|
|
|
fMatrix.setIdentity();
|
|
|
|
}
|
|
|
|
fPaint = paint;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2013-03-25 11:50:42 +00:00
|
|
|
fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding()));
|
|
|
|
fInfo.push(SkObjectParser::PathToString(path));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (matrix) {
|
2013-03-25 11:50:42 +00:00
|
|
|
fInfo.push(SkObjectParser::MatrixToString(*matrix));
|
|
|
|
}
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const {
|
2013-03-25 11:50:42 +00:00
|
|
|
canvas->drawTextOnPath(fText, fByteLength, fPath,
|
2015-08-27 14:41:13 +00:00
|
|
|
fMatrix.isIdentity() ? nullptr : &fMatrix,
|
2013-03-25 11:50:42 +00:00
|
|
|
fPaint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkDrawTextOnPathCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-03-29 16:03:52 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText,
|
2016-02-10 13:40:46 +00:00
|
|
|
((const char*) fText) + fByteLength);
|
|
|
|
Json::Value coords(Json::arrayValue);
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = make_json_path(fPath);
|
|
|
|
if (!fMatrix.isIdentity()) {
|
2016-03-03 19:39:38 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
2016-02-11 18:35:21 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(fPaint, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkDrawTextOnPathCommand* SkDrawTextOnPathCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString();
|
|
|
|
SkPaint paint;
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
SkPath path;
|
|
|
|
extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path);
|
|
|
|
SkMatrix* matrixPtr;
|
|
|
|
SkMatrix matrix;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_MATRIX)) {
|
|
|
|
extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix);
|
|
|
|
matrixPtr = &matrix;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
matrixPtr = nullptr;
|
|
|
|
}
|
|
|
|
return new SkDrawTextOnPathCommand(text, strlen(text), path, matrixPtr, paint);
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawVerticesCommand::SkDrawVerticesCommand(SkCanvas::VertexMode vmode, int vertexCount,
|
|
|
|
const SkPoint vertices[], const SkPoint texs[],
|
|
|
|
const SkColor colors[], SkXfermode* xfermode,
|
|
|
|
const uint16_t indices[], int indexCount,
|
2014-03-25 23:31:33 +00:00
|
|
|
const SkPaint& paint)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kDrawVertices_OpType) {
|
2013-03-25 11:50:42 +00:00
|
|
|
fVmode = vmode;
|
|
|
|
|
|
|
|
fVertexCount = vertexCount;
|
|
|
|
|
|
|
|
fVertices = new SkPoint[vertexCount];
|
|
|
|
memcpy(fVertices, vertices, vertexCount * sizeof(SkPoint));
|
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
if (texs) {
|
2013-03-25 11:50:42 +00:00
|
|
|
fTexs = new SkPoint[vertexCount];
|
|
|
|
memcpy(fTexs, texs, vertexCount * sizeof(SkPoint));
|
|
|
|
} else {
|
2015-08-27 14:41:13 +00:00
|
|
|
fTexs = nullptr;
|
2013-03-25 11:50:42 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
if (colors) {
|
2013-03-25 11:50:42 +00:00
|
|
|
fColors = new SkColor[vertexCount];
|
|
|
|
memcpy(fColors, colors, vertexCount * sizeof(SkColor));
|
|
|
|
} else {
|
2015-08-27 14:41:13 +00:00
|
|
|
fColors = nullptr;
|
2013-03-25 11:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fXfermode = xfermode;
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fXfermode) {
|
2013-03-25 11:50:42 +00:00
|
|
|
fXfermode->ref();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indexCount > 0) {
|
|
|
|
fIndices = new uint16_t[indexCount];
|
|
|
|
memcpy(fIndices, indices, indexCount * sizeof(uint16_t));
|
|
|
|
} else {
|
2015-08-27 14:41:13 +00:00
|
|
|
fIndices = nullptr;
|
2013-03-25 11:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fIndexCount = indexCount;
|
|
|
|
fPaint = paint;
|
|
|
|
|
2012-06-29 14:21:22 +00:00
|
|
|
// TODO(chudy)
|
2013-03-25 11:50:42 +00:00
|
|
|
fInfo.push(SkObjectParser::CustomTextToString("To be implemented."));
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(paint));
|
|
|
|
}
|
|
|
|
|
2013-06-18 20:20:55 +00:00
|
|
|
SkDrawVerticesCommand::~SkDrawVerticesCommand() {
|
2013-03-25 11:50:42 +00:00
|
|
|
delete [] fVertices;
|
|
|
|
delete [] fTexs;
|
|
|
|
delete [] fColors;
|
|
|
|
SkSafeUnref(fXfermode);
|
|
|
|
delete [] fIndices;
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkDrawVerticesCommand::execute(SkCanvas* canvas) const {
|
2013-03-25 11:50:42 +00:00
|
|
|
canvas->drawVertices(fVmode, fVertexCount, fVertices,
|
|
|
|
fTexs, fColors, fXfermode, fIndices,
|
|
|
|
fIndexCount, fPaint);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkRestoreCommand::SkRestoreCommand()
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kRestore_OpType) {
|
2013-03-22 16:33:31 +00:00
|
|
|
fInfo.push(SkObjectParser::CustomTextToString("No Parameters"));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkRestoreCommand::execute(SkCanvas* canvas) const {
|
2012-06-29 14:21:22 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
SkRestoreCommand* SkRestoreCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
return new SkRestoreCommand();
|
|
|
|
}
|
|
|
|
|
2014-06-30 14:13:28 +00:00
|
|
|
SkSaveCommand::SkSaveCommand()
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kSave_OpType) {
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkSaveCommand::execute(SkCanvas* canvas) const {
|
2014-06-30 14:13:28 +00:00
|
|
|
canvas->save();
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
SkSaveCommand* SkSaveCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
return new SkSaveCommand();
|
|
|
|
}
|
|
|
|
|
2015-12-18 15:09:18 +00:00
|
|
|
SkSaveLayerCommand::SkSaveLayerCommand(const SkCanvas::SaveLayerRec& rec)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kSaveLayer_OpType) {
|
2015-12-18 15:09:18 +00:00
|
|
|
if (rec.fBounds) {
|
|
|
|
fBounds = *rec.fBounds;
|
2013-03-22 16:33:31 +00:00
|
|
|
} else {
|
|
|
|
fBounds.setEmpty();
|
|
|
|
}
|
|
|
|
|
2015-12-18 15:09:18 +00:00
|
|
|
if (rec.fPaint) {
|
|
|
|
fPaint = *rec.fPaint;
|
2013-03-22 16:33:31 +00:00
|
|
|
fPaintPtr = &fPaint;
|
|
|
|
} else {
|
2015-08-27 14:41:13 +00:00
|
|
|
fPaintPtr = nullptr;
|
2013-03-22 16:33:31 +00:00
|
|
|
}
|
2015-12-18 15:09:18 +00:00
|
|
|
fSaveLayerFlags = rec.fSaveLayerFlags;
|
2012-06-29 14:21:22 +00:00
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
if (rec.fBackdrop) {
|
|
|
|
fBackdrop = rec.fBackdrop;
|
|
|
|
fBackdrop->ref();
|
|
|
|
} else {
|
|
|
|
fBackdrop = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-12-18 15:09:18 +00:00
|
|
|
if (rec.fBounds) {
|
|
|
|
fInfo.push(SkObjectParser::RectToString(*rec.fBounds, "Bounds: "));
|
2013-03-22 16:33:31 +00:00
|
|
|
}
|
2015-12-18 15:09:18 +00:00
|
|
|
if (rec.fPaint) {
|
|
|
|
fInfo.push(SkObjectParser::PaintToString(*rec.fPaint));
|
2013-03-22 16:33:31 +00:00
|
|
|
}
|
2015-12-18 15:09:18 +00:00
|
|
|
fInfo.push(SkObjectParser::SaveLayerFlagsToString(fSaveLayerFlags));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 13:40:46 +00:00
|
|
|
SkSaveLayerCommand::~SkSaveLayerCommand() {
|
|
|
|
if (fBackdrop != nullptr) {
|
|
|
|
fBackdrop->unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkSaveLayerCommand::execute(SkCanvas* canvas) const {
|
2015-12-18 15:09:18 +00:00
|
|
|
canvas->saveLayer(SkCanvas::SaveLayerRec(fBounds.isEmpty() ? nullptr : &fBounds,
|
|
|
|
fPaintPtr,
|
|
|
|
fSaveLayerFlags));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const {
|
2014-03-03 23:25:41 +00:00
|
|
|
canvas->save();
|
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkSaveLayerCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
if (!fBounds.isEmpty()) {
|
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_BOUNDS] = make_json_rect(fBounds);
|
|
|
|
}
|
|
|
|
if (fPaintPtr != nullptr) {
|
2016-03-29 16:03:52 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = make_json_paint(*fPaintPtr,
|
2016-02-11 18:35:21 +00:00
|
|
|
urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
if (fBackdrop != nullptr) {
|
|
|
|
Json::Value jsonBackdrop;
|
2016-02-11 18:35:21 +00:00
|
|
|
flatten(fBackdrop, &jsonBackdrop, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_BACKDROP] = jsonBackdrop;
|
|
|
|
}
|
|
|
|
if (fSaveLayerFlags != 0) {
|
|
|
|
SkDebugf("unsupported: saveLayer flags\n");
|
|
|
|
SkASSERT(false);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkSaveLayerCommand* SkSaveLayerCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkCanvas::SaveLayerRec rec;
|
|
|
|
SkRect bounds;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_BOUNDS)) {
|
|
|
|
extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_BOUNDS], &bounds);
|
|
|
|
rec.fBounds = &bounds;
|
|
|
|
}
|
|
|
|
SkPaint paint;
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) {
|
2016-02-11 18:35:21 +00:00
|
|
|
extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint);
|
2016-02-10 13:40:46 +00:00
|
|
|
rec.fPaint = &paint;
|
|
|
|
}
|
|
|
|
if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_BACKDROP)) {
|
|
|
|
Json::Value backdrop = command[SKDEBUGCANVAS_ATTRIBUTE_BACKDROP];
|
2016-02-11 18:35:21 +00:00
|
|
|
rec.fBackdrop = (SkImageFilter*) load_flattenable(backdrop, urlDataManager);
|
2016-02-10 13:40:46 +00:00
|
|
|
}
|
|
|
|
SkSaveLayerCommand* result = new SkSaveLayerCommand(rec);
|
|
|
|
if (rec.fBackdrop != nullptr) {
|
|
|
|
rec.fBackdrop->unref();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-03-25 23:31:33 +00:00
|
|
|
SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix)
|
2015-02-13 19:13:00 +00:00
|
|
|
: INHERITED(kSetMatrix_OpType) {
|
2014-10-16 21:28:28 +00:00
|
|
|
fUserMatrix.reset();
|
2013-03-25 11:50:42 +00:00
|
|
|
fMatrix = matrix;
|
|
|
|
fInfo.push(SkObjectParser::MatrixToString(matrix));
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2014-10-16 21:28:28 +00:00
|
|
|
void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) {
|
|
|
|
fUserMatrix = userMatrix;
|
|
|
|
}
|
|
|
|
|
2014-11-09 00:18:56 +00:00
|
|
|
void SkSetMatrixCommand::execute(SkCanvas* canvas) const {
|
2014-10-16 21:28:28 +00:00
|
|
|
SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix);
|
|
|
|
canvas->setMatrix(temp);
|
2012-06-29 14:21:22 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:35:21 +00:00
|
|
|
Json::Value SkSetMatrixCommand::toJSON(UrlDataManager& urlDataManager) const {
|
|
|
|
Json::Value result = INHERITED::toJSON(urlDataManager);
|
2016-03-03 19:39:38 +00:00
|
|
|
result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix);
|
2016-02-10 13:40:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command,
|
2016-02-11 18:35:21 +00:00
|
|
|
UrlDataManager& urlDataManager) {
|
2016-02-10 13:40:46 +00:00
|
|
|
SkMatrix matrix;
|
|
|
|
extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix);
|
|
|
|
return new SkSetMatrixCommand(matrix);
|
|
|
|
}
|