chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 8 | #include "SkDrawCommand.h" |
joshualitt | 6b3cf73 | 2016-02-17 11:20:26 -0800 | [diff] [blame] | 9 | |
halcanary | a73d76a | 2016-10-17 13:19:02 -0700 | [diff] [blame] | 10 | #include "png.h" |
| 11 | |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 12 | #include "SkAutoMalloc.h" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 13 | #include "SkBlurMaskFilter.h" |
| 14 | #include "SkColorFilter.h" |
| 15 | #include "SkDashPathEffect.h" |
| 16 | #include "SkImageFilter.h" |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 17 | #include "SkJsonWriteBuffer.h" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 18 | #include "SkMaskFilter.h" |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 19 | #include "SkObjectParser.h" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 20 | #include "SkPaintDefaults.h" |
| 21 | #include "SkPathEffect.h" |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 22 | #include "SkPicture.h" |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 23 | #include "SkTextBlob.h" |
fmalita | e77f2da | 2015-12-08 18:59:18 -0800 | [diff] [blame] | 24 | #include "SkTextBlobRunIterator.h" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 25 | #include "SkTHash.h" |
| 26 | #include "SkTypeface.h" |
| 27 | #include "SkValidatingReadBuffer.h" |
| 28 | #include "SkWriteBuffer.h" |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 29 | #include "picture_utils.h" |
Mike Reed | ebfce6d | 2016-12-12 10:02:12 -0500 | [diff] [blame] | 30 | #include "SkClipOpPriv.h" |
Stan Iliev | ac42aeb | 2017-01-12 16:20:50 -0500 | [diff] [blame] | 31 | #include <SkLatticeIter.h> |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 32 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 33 | #define SKDEBUGCANVAS_ATTRIBUTE_COMMAND "command" |
ethannicholas | 807dcab | 2016-02-23 06:53:37 -0800 | [diff] [blame] | 34 | #define SKDEBUGCANVAS_ATTRIBUTE_VISIBLE "visible" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 35 | #define SKDEBUGCANVAS_ATTRIBUTE_MATRIX "matrix" |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 36 | #define SKDEBUGCANVAS_ATTRIBUTE_DRAWDEPTHTRANS "drawDepthTranslation" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 37 | #define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords" |
halcanary | f412f09 | 2016-08-25 11:10:41 -0700 | [diff] [blame] | 38 | #define SKDEBUGCANVAS_ATTRIBUTE_HINTING "hinting" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 39 | #define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds" |
| 40 | #define SKDEBUGCANVAS_ATTRIBUTE_PAINT "paint" |
| 41 | #define SKDEBUGCANVAS_ATTRIBUTE_OUTER "outer" |
| 42 | #define SKDEBUGCANVAS_ATTRIBUTE_INNER "inner" |
| 43 | #define SKDEBUGCANVAS_ATTRIBUTE_MODE "mode" |
| 44 | #define SKDEBUGCANVAS_ATTRIBUTE_POINTS "points" |
| 45 | #define SKDEBUGCANVAS_ATTRIBUTE_PATH "path" |
| 46 | #define SKDEBUGCANVAS_ATTRIBUTE_TEXT "text" |
| 47 | #define SKDEBUGCANVAS_ATTRIBUTE_COLOR "color" |
| 48 | #define SKDEBUGCANVAS_ATTRIBUTE_ALPHA "alpha" |
Florin Malita | 82d8087 | 2017-06-06 16:58:40 -0400 | [diff] [blame] | 49 | #define SKDEBUGCANVAS_ATTRIBUTE_BLENDMODE "blendMode" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 50 | #define SKDEBUGCANVAS_ATTRIBUTE_STYLE "style" |
| 51 | #define SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH "strokeWidth" |
| 52 | #define SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER "strokeMiter" |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 53 | #define SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN "strokeJoin" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 54 | #define SKDEBUGCANVAS_ATTRIBUTE_CAP "cap" |
| 55 | #define SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS "antiAlias" |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 56 | #define SKDEBUGCANVAS_ATTRIBUTE_DITHER "dither" |
Ben Wagner | 78f1f5a | 2017-06-23 14:35:07 -0400 | [diff] [blame] | 57 | #define SKDEBUGCANVAS_ATTRIBUTE_FAKEBOLDTEXT "fakeBoldText" |
| 58 | #define SKDEBUGCANVAS_ATTRIBUTE_LINEARTEXT "linearText" |
| 59 | #define SKDEBUGCANVAS_ATTRIBUTE_SUBPIXELTEXT "subpixelText" |
| 60 | #define SKDEBUGCANVAS_ATTRIBUTE_DEVKERNTEXT "devKernText" |
| 61 | #define SKDEBUGCANVAS_ATTRIBUTE_LCDRENDERTEXT "lcdRenderText" |
| 62 | #define SKDEBUGCANVAS_ATTRIBUTE_EMBEDDEDBITMAPTEXT "embeddedBitmapText" |
| 63 | #define SKDEBUGCANVAS_ATTRIBUTE_AUTOHINTING "forceAutoHinting" |
| 64 | #define SKDEBUGCANVAS_ATTRIBUTE_VERTICALTEXT "verticalText" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 65 | #define SKDEBUGCANVAS_ATTRIBUTE_REGION "region" |
| 66 | #define SKDEBUGCANVAS_ATTRIBUTE_REGIONOP "op" |
| 67 | #define SKDEBUGCANVAS_ATTRIBUTE_EDGESTYLE "edgeStyle" |
| 68 | #define SKDEBUGCANVAS_ATTRIBUTE_DEVICEREGION "deviceRegion" |
| 69 | #define SKDEBUGCANVAS_ATTRIBUTE_BLUR "blur" |
| 70 | #define SKDEBUGCANVAS_ATTRIBUTE_SIGMA "sigma" |
| 71 | #define SKDEBUGCANVAS_ATTRIBUTE_QUALITY "quality" |
| 72 | #define SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN "textAlign" |
| 73 | #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE "textSize" |
| 74 | #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX "textScaleX" |
| 75 | #define SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX "textSkewX" |
| 76 | #define SKDEBUGCANVAS_ATTRIBUTE_DASHING "dashing" |
| 77 | #define SKDEBUGCANVAS_ATTRIBUTE_INTERVALS "intervals" |
| 78 | #define SKDEBUGCANVAS_ATTRIBUTE_PHASE "phase" |
| 79 | #define SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE "fillType" |
| 80 | #define SKDEBUGCANVAS_ATTRIBUTE_VERBS "verbs" |
| 81 | #define SKDEBUGCANVAS_ATTRIBUTE_NAME "name" |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 82 | #define SKDEBUGCANVAS_ATTRIBUTE_DATA "data" |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 83 | #define SKDEBUGCANVAS_ATTRIBUTE_VALUES "values" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 84 | #define SKDEBUGCANVAS_ATTRIBUTE_SHADER "shader" |
| 85 | #define SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT "pathEffect" |
| 86 | #define SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER "maskFilter" |
| 87 | #define SKDEBUGCANVAS_ATTRIBUTE_XFERMODE "xfermode" |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 88 | #define SKDEBUGCANVAS_ATTRIBUTE_LOOPER "looper" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 89 | #define SKDEBUGCANVAS_ATTRIBUTE_BACKDROP "backdrop" |
| 90 | #define SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER "colorfilter" |
| 91 | #define SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER "imagefilter" |
| 92 | #define SKDEBUGCANVAS_ATTRIBUTE_IMAGE "image" |
| 93 | #define SKDEBUGCANVAS_ATTRIBUTE_BITMAP "bitmap" |
| 94 | #define SKDEBUGCANVAS_ATTRIBUTE_SRC "src" |
| 95 | #define SKDEBUGCANVAS_ATTRIBUTE_DST "dst" |
| 96 | #define SKDEBUGCANVAS_ATTRIBUTE_CENTER "center" |
| 97 | #define SKDEBUGCANVAS_ATTRIBUTE_STRICT "strict" |
| 98 | #define SKDEBUGCANVAS_ATTRIBUTE_DESCRIPTION "description" |
| 99 | #define SKDEBUGCANVAS_ATTRIBUTE_X "x" |
| 100 | #define SKDEBUGCANVAS_ATTRIBUTE_Y "y" |
| 101 | #define SKDEBUGCANVAS_ATTRIBUTE_RUNS "runs" |
| 102 | #define SKDEBUGCANVAS_ATTRIBUTE_POSITIONS "positions" |
| 103 | #define SKDEBUGCANVAS_ATTRIBUTE_GLYPHS "glyphs" |
| 104 | #define SKDEBUGCANVAS_ATTRIBUTE_FONT "font" |
| 105 | #define SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE "typeface" |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 106 | #define SKDEBUGCANVAS_ATTRIBUTE_CUBICS "cubics" |
| 107 | #define SKDEBUGCANVAS_ATTRIBUTE_COLORS "colors" |
| 108 | #define SKDEBUGCANVAS_ATTRIBUTE_TEXTURECOORDS "textureCoords" |
| 109 | #define SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY "filterQuality" |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 110 | #define SKDEBUGCANVAS_ATTRIBUTE_STARTANGLE "startAngle" |
| 111 | #define SKDEBUGCANVAS_ATTRIBUTE_SWEEPANGLE "sweepAngle" |
| 112 | #define SKDEBUGCANVAS_ATTRIBUTE_USECENTER "useCenter" |
jcgregorio | ee0c555 | 2016-06-30 09:18:27 -0700 | [diff] [blame] | 113 | #define SKDEBUGCANVAS_ATTRIBUTE_SHORTDESC "shortDesc" |
msarett | 0ac1bec | 2016-08-29 09:15:33 -0700 | [diff] [blame] | 114 | #define SKDEBUGCANVAS_ATTRIBUTE_UNIQUE_ID "uniqueID" |
| 115 | #define SKDEBUGCANVAS_ATTRIBUTE_WIDTH "width" |
| 116 | #define SKDEBUGCANVAS_ATTRIBUTE_HEIGHT "height" |
| 117 | #define SKDEBUGCANVAS_ATTRIBUTE_ALPHA "alpha" |
Stan Iliev | ac42aeb | 2017-01-12 16:20:50 -0500 | [diff] [blame] | 118 | #define SKDEBUGCANVAS_ATTRIBUTE_LATTICE "lattice" |
| 119 | #define SKDEBUGCANVAS_ATTRIBUTE_LATTICEXCOUNT "xCount" |
| 120 | #define SKDEBUGCANVAS_ATTRIBUTE_LATTICEYCOUNT "yCount" |
| 121 | #define SKDEBUGCANVAS_ATTRIBUTE_LATTICEXDIVS "xDivs" |
| 122 | #define SKDEBUGCANVAS_ATTRIBUTE_LATTICEYDIVS "yDivs" |
| 123 | #define SKDEBUGCANVAS_ATTRIBUTE_LATTICEFLAGS "flags" |
reed | 67f62fa | 2016-06-29 11:36:34 -0700 | [diff] [blame] | 124 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 125 | #define SKDEBUGCANVAS_VERB_MOVE "move" |
| 126 | #define SKDEBUGCANVAS_VERB_LINE "line" |
| 127 | #define SKDEBUGCANVAS_VERB_QUAD "quad" |
| 128 | #define SKDEBUGCANVAS_VERB_CUBIC "cubic" |
| 129 | #define SKDEBUGCANVAS_VERB_CONIC "conic" |
| 130 | #define SKDEBUGCANVAS_VERB_CLOSE "close" |
| 131 | |
| 132 | #define SKDEBUGCANVAS_STYLE_FILL "fill" |
| 133 | #define SKDEBUGCANVAS_STYLE_STROKE "stroke" |
| 134 | #define SKDEBUGCANVAS_STYLE_STROKEANDFILL "strokeAndFill" |
| 135 | |
| 136 | #define SKDEBUGCANVAS_POINTMODE_POINTS "points" |
| 137 | #define SKDEBUGCANVAS_POINTMODE_LINES "lines" |
| 138 | #define SKDEBUGCANVAS_POINTMODE_POLYGON "polygon" |
| 139 | |
| 140 | #define SKDEBUGCANVAS_REGIONOP_DIFFERENCE "difference" |
| 141 | #define SKDEBUGCANVAS_REGIONOP_INTERSECT "intersect" |
| 142 | #define SKDEBUGCANVAS_REGIONOP_UNION "union" |
| 143 | #define SKDEBUGCANVAS_REGIONOP_XOR "xor" |
| 144 | #define SKDEBUGCANVAS_REGIONOP_REVERSE_DIFFERENCE "reverseDifference" |
| 145 | #define SKDEBUGCANVAS_REGIONOP_REPLACE "replace" |
| 146 | |
| 147 | #define SKDEBUGCANVAS_BLURSTYLE_NORMAL "normal" |
| 148 | #define SKDEBUGCANVAS_BLURSTYLE_SOLID "solid" |
| 149 | #define SKDEBUGCANVAS_BLURSTYLE_OUTER "outer" |
| 150 | #define SKDEBUGCANVAS_BLURSTYLE_INNER "inner" |
| 151 | |
| 152 | #define SKDEBUGCANVAS_BLURQUALITY_LOW "low" |
| 153 | #define SKDEBUGCANVAS_BLURQUALITY_HIGH "high" |
| 154 | |
| 155 | #define SKDEBUGCANVAS_ALIGN_LEFT "left" |
| 156 | #define SKDEBUGCANVAS_ALIGN_CENTER "center" |
| 157 | #define SKDEBUGCANVAS_ALIGN_RIGHT "right" |
| 158 | |
| 159 | #define SKDEBUGCANVAS_FILLTYPE_WINDING "winding" |
| 160 | #define SKDEBUGCANVAS_FILLTYPE_EVENODD "evenOdd" |
| 161 | #define SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING "inverseWinding" |
| 162 | #define SKDEBUGCANVAS_FILLTYPE_INVERSEEVENODD "inverseEvenOdd" |
| 163 | |
| 164 | #define SKDEBUGCANVAS_CAP_BUTT "butt" |
| 165 | #define SKDEBUGCANVAS_CAP_ROUND "round" |
| 166 | #define SKDEBUGCANVAS_CAP_SQUARE "square" |
| 167 | |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 168 | #define SKDEBUGCANVAS_MITER_JOIN "miter" |
| 169 | #define SKDEBUGCANVAS_ROUND_JOIN "round" |
| 170 | #define SKDEBUGCANVAS_BEVEL_JOIN "bevel" |
| 171 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 172 | #define SKDEBUGCANVAS_COLORTYPE_ARGB4444 "ARGB4444" |
| 173 | #define SKDEBUGCANVAS_COLORTYPE_RGBA8888 "RGBA8888" |
| 174 | #define SKDEBUGCANVAS_COLORTYPE_BGRA8888 "BGRA8888" |
| 175 | #define SKDEBUGCANVAS_COLORTYPE_565 "565" |
| 176 | #define SKDEBUGCANVAS_COLORTYPE_GRAY8 "Gray8" |
| 177 | #define SKDEBUGCANVAS_COLORTYPE_INDEX8 "Index8" |
| 178 | #define SKDEBUGCANVAS_COLORTYPE_ALPHA8 "Alpha8" |
| 179 | |
| 180 | #define SKDEBUGCANVAS_ALPHATYPE_OPAQUE "opaque" |
| 181 | #define SKDEBUGCANVAS_ALPHATYPE_PREMUL "premul" |
| 182 | #define SKDEBUGCANVAS_ALPHATYPE_UNPREMUL "unpremul" |
msarett | 0ac1bec | 2016-08-29 09:15:33 -0700 | [diff] [blame] | 183 | #define SKDEBUGCANVAS_ALPHATYPE_UNKNOWN "unknown" |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 184 | |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 185 | #define SKDEBUGCANVAS_FILTERQUALITY_NONE "none" |
| 186 | #define SKDEBUGCANVAS_FILTERQUALITY_LOW "low" |
| 187 | #define SKDEBUGCANVAS_FILTERQUALITY_MEDIUM "medium" |
| 188 | #define SKDEBUGCANVAS_FILTERQUALITY_HIGH "high" |
| 189 | |
halcanary | f412f09 | 2016-08-25 11:10:41 -0700 | [diff] [blame] | 190 | #define SKDEBUGCANVAS_HINTING_NONE "none" |
| 191 | #define SKDEBUGCANVAS_HINTING_SLIGHT "slight" |
| 192 | #define SKDEBUGCANVAS_HINTING_NORMAL "normal" |
| 193 | #define SKDEBUGCANVAS_HINTING_FULL "full" |
| 194 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 195 | typedef SkDrawCommand* (*FROM_JSON)(Json::Value&, UrlDataManager&); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 196 | |
reed | 67f62fa | 2016-06-29 11:36:34 -0700 | [diff] [blame] | 197 | static SkString* str_append(SkString* str, const SkRect& r) { |
| 198 | str->appendf(" [%g %g %g %g]", r.left(), r.top(), r.right(), r.bottom()); |
| 199 | return str; |
| 200 | } |
| 201 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 202 | // TODO(chudy): Refactor into non subclass model. |
| 203 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 204 | SkDrawCommand::SkDrawCommand(OpType type) |
| 205 | : fOpType(type) |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 206 | , fVisible(true) { |
| 207 | } |
| 208 | |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 209 | SkDrawCommand::~SkDrawCommand() { |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 210 | fInfo.deleteAll(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 211 | } |
| 212 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 213 | const char* SkDrawCommand::GetCommandString(OpType type) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 214 | switch (type) { |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 215 | case kBeginDrawPicture_OpType: return "BeginDrawPicture"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 216 | case kClipPath_OpType: return "ClipPath"; |
| 217 | case kClipRegion_OpType: return "ClipRegion"; |
| 218 | case kClipRect_OpType: return "ClipRect"; |
| 219 | case kClipRRect_OpType: return "ClipRRect"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 220 | case kConcat_OpType: return "Concat"; |
robertphillips | fb40923 | 2016-06-29 10:28:11 -0700 | [diff] [blame] | 221 | case kDrawAnnotation_OpType: return "DrawAnnotation"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 222 | case kDrawBitmap_OpType: return "DrawBitmap"; |
| 223 | case kDrawBitmapNine_OpType: return "DrawBitmapNine"; |
| 224 | case kDrawBitmapRect_OpType: return "DrawBitmapRect"; |
| 225 | case kDrawClear_OpType: return "DrawClear"; |
| 226 | case kDrawDRRect_OpType: return "DrawDRRect"; |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 227 | case kDrawImage_OpType: return "DrawImage"; |
Stan Iliev | ac42aeb | 2017-01-12 16:20:50 -0500 | [diff] [blame] | 228 | case kDrawImageLattice_OpType: return "DrawImageLattice"; |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 229 | case kDrawImageRect_OpType: return "DrawImageRect"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 230 | case kDrawOval_OpType: return "DrawOval"; |
| 231 | case kDrawPaint_OpType: return "DrawPaint"; |
| 232 | case kDrawPatch_OpType: return "DrawPatch"; |
| 233 | case kDrawPath_OpType: return "DrawPath"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 234 | case kDrawPoints_OpType: return "DrawPoints"; |
| 235 | case kDrawPosText_OpType: return "DrawPosText"; |
| 236 | case kDrawPosTextH_OpType: return "DrawPosTextH"; |
| 237 | case kDrawRect_OpType: return "DrawRect"; |
| 238 | case kDrawRRect_OpType: return "DrawRRect"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 239 | case kDrawText_OpType: return "DrawText"; |
| 240 | case kDrawTextBlob_OpType: return "DrawTextBlob"; |
| 241 | case kDrawTextOnPath_OpType: return "DrawTextOnPath"; |
reed | 63f30d9 | 2016-07-07 16:32:51 -0700 | [diff] [blame] | 242 | case kDrawTextRSXform_OpType: return "DrawTextRSXform"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 243 | case kDrawVertices_OpType: return "DrawVertices"; |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 244 | case kEndDrawPicture_OpType: return "EndDrawPicture"; |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 245 | case kRestore_OpType: return "Restore"; |
| 246 | case kSave_OpType: return "Save"; |
| 247 | case kSaveLayer_OpType: return "SaveLayer"; |
| 248 | case kSetMatrix_OpType: return "SetMatrix"; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 249 | default: |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 250 | SkDebugf("OpType error 0x%08x\n", type); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 251 | SkASSERT(0); |
| 252 | break; |
| 253 | } |
| 254 | SkDEBUGFAIL("DrawType UNUSED\n"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 255 | return nullptr; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 256 | } |
| 257 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 258 | SkString SkDrawCommand::toString() const { |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 259 | return SkString(GetCommandString(fOpType)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 260 | } |
| 261 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 262 | Json::Value SkDrawCommand::toJSON(UrlDataManager& urlDataManager) const { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 263 | Json::Value result; |
| 264 | result[SKDEBUGCANVAS_ATTRIBUTE_COMMAND] = this->GetCommandString(fOpType); |
ethannicholas | 807dcab | 2016-02-23 06:53:37 -0800 | [diff] [blame] | 265 | result[SKDEBUGCANVAS_ATTRIBUTE_VISIBLE] = Json::Value(this->isVisible()); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 266 | return result; |
| 267 | } |
| 268 | |
| 269 | #define INSTALL_FACTORY(name) factories.set(SkString(GetCommandString(k ## name ##_OpType)), \ |
| 270 | (FROM_JSON) Sk ## name ## Command::fromJSON) |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 271 | SkDrawCommand* SkDrawCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 272 | static SkTHashMap<SkString, FROM_JSON> factories; |
| 273 | static bool initialized = false; |
| 274 | if (!initialized) { |
| 275 | initialized = true; |
| 276 | INSTALL_FACTORY(Restore); |
| 277 | INSTALL_FACTORY(ClipPath); |
| 278 | INSTALL_FACTORY(ClipRegion); |
| 279 | INSTALL_FACTORY(ClipRect); |
| 280 | INSTALL_FACTORY(ClipRRect); |
| 281 | INSTALL_FACTORY(Concat); |
reed | 97660cc | 2016-06-28 18:54:19 -0700 | [diff] [blame] | 282 | INSTALL_FACTORY(DrawAnnotation); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 283 | INSTALL_FACTORY(DrawBitmap); |
| 284 | INSTALL_FACTORY(DrawBitmapRect); |
| 285 | INSTALL_FACTORY(DrawBitmapNine); |
| 286 | INSTALL_FACTORY(DrawImage); |
| 287 | INSTALL_FACTORY(DrawImageRect); |
| 288 | INSTALL_FACTORY(DrawOval); |
| 289 | INSTALL_FACTORY(DrawPaint); |
| 290 | INSTALL_FACTORY(DrawPath); |
| 291 | INSTALL_FACTORY(DrawPoints); |
| 292 | INSTALL_FACTORY(DrawText); |
| 293 | INSTALL_FACTORY(DrawPosText); |
bungeman | 51190df | 2016-03-09 07:42:54 -0800 | [diff] [blame] | 294 | INSTALL_FACTORY(DrawPosTextH); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 295 | INSTALL_FACTORY(DrawTextOnPath); |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 296 | INSTALL_FACTORY(DrawTextRSXform); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 297 | INSTALL_FACTORY(DrawTextBlob); |
| 298 | |
| 299 | INSTALL_FACTORY(DrawRect); |
| 300 | INSTALL_FACTORY(DrawRRect); |
| 301 | INSTALL_FACTORY(DrawDRRect); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 302 | INSTALL_FACTORY(DrawPatch); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 303 | INSTALL_FACTORY(Save); |
| 304 | INSTALL_FACTORY(SaveLayer); |
| 305 | INSTALL_FACTORY(SetMatrix); |
| 306 | } |
| 307 | SkString name = SkString(command[SKDEBUGCANVAS_ATTRIBUTE_COMMAND].asCString()); |
| 308 | FROM_JSON* factory = factories.find(name); |
| 309 | if (factory == nullptr) { |
| 310 | SkDebugf("no JSON factory for '%s'\n", name.c_str()); |
| 311 | return nullptr; |
| 312 | } |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 313 | return (*factory)(command, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 314 | } |
| 315 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 316 | namespace { |
| 317 | |
| 318 | void xlate_and_scale_to_bounds(SkCanvas* canvas, const SkRect& bounds) { |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 319 | const SkISize& size = canvas->getBaseLayerSize(); |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 320 | |
| 321 | static const SkScalar kInsetFrac = 0.9f; // Leave a border around object |
| 322 | |
| 323 | canvas->translate(size.fWidth/2.0f, size.fHeight/2.0f); |
| 324 | if (bounds.width() > bounds.height()) { |
| 325 | canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.width()), |
| 326 | SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.width())); |
| 327 | } else { |
| 328 | canvas->scale(SkDoubleToScalar((kInsetFrac*size.fWidth)/bounds.height()), |
| 329 | SkDoubleToScalar((kInsetFrac*size.fHeight)/bounds.height())); |
| 330 | } |
| 331 | canvas->translate(-bounds.centerX(), -bounds.centerY()); |
| 332 | } |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 333 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 334 | |
| 335 | void render_path(SkCanvas* canvas, const SkPath& path) { |
| 336 | canvas->clear(0xFFFFFFFF); |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 337 | |
| 338 | const SkRect& bounds = path.getBounds(); |
fmalita | b0cd8b7 | 2015-10-06 07:24:03 -0700 | [diff] [blame] | 339 | if (bounds.isEmpty()) { |
| 340 | return; |
| 341 | } |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 342 | |
fmalita | b0cd8b7 | 2015-10-06 07:24:03 -0700 | [diff] [blame] | 343 | SkAutoCanvasRestore acr(canvas, true); |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 344 | xlate_and_scale_to_bounds(canvas, bounds); |
| 345 | |
| 346 | SkPaint p; |
| 347 | p.setColor(SK_ColorBLACK); |
| 348 | p.setStyle(SkPaint::kStroke_Style); |
| 349 | |
| 350 | canvas->drawPath(path, p); |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 351 | } |
| 352 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 353 | void render_bitmap(SkCanvas* canvas, const SkBitmap& input, const SkRect* srcRect = nullptr) { |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 354 | const SkISize& size = canvas->getBaseLayerSize(); |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 355 | |
| 356 | SkScalar xScale = SkIntToScalar(size.fWidth-2) / input.width(); |
| 357 | SkScalar yScale = SkIntToScalar(size.fHeight-2) / input.height(); |
| 358 | |
| 359 | if (input.width() > input.height()) { |
| 360 | yScale *= input.height() / (float) input.width(); |
| 361 | } else { |
| 362 | xScale *= input.width() / (float) input.height(); |
| 363 | } |
| 364 | |
| 365 | SkRect dst = SkRect::MakeXYWH(SK_Scalar1, SK_Scalar1, |
| 366 | xScale * input.width(), |
| 367 | yScale * input.height()); |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 368 | |
robertphillips | 96a5cff | 2015-09-24 06:56:27 -0700 | [diff] [blame] | 369 | static const int kNumBlocks = 8; |
| 370 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 371 | canvas->clear(0xFFFFFFFF); |
robertphillips | 96a5cff | 2015-09-24 06:56:27 -0700 | [diff] [blame] | 372 | SkISize block = { |
| 373 | canvas->imageInfo().width()/kNumBlocks, |
| 374 | canvas->imageInfo().height()/kNumBlocks |
| 375 | }; |
| 376 | for (int y = 0; y < kNumBlocks; ++y) { |
| 377 | for (int x = 0; x < kNumBlocks; ++x) { |
| 378 | SkPaint paint; |
| 379 | paint.setColor((x+y)%2 ? SK_ColorLTGRAY : SK_ColorDKGRAY); |
| 380 | SkRect r = SkRect::MakeXYWH(SkIntToScalar(x*block.width()), |
| 381 | SkIntToScalar(y*block.height()), |
| 382 | SkIntToScalar(block.width()), |
| 383 | SkIntToScalar(block.height())); |
| 384 | canvas->drawRect(r, paint); |
| 385 | } |
| 386 | } |
| 387 | |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 388 | canvas->drawBitmapRect(input, dst, nullptr); |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 389 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 390 | if (srcRect) { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 391 | SkRect r = SkRect::MakeLTRB(srcRect->fLeft * xScale + SK_Scalar1, |
| 392 | srcRect->fTop * yScale + SK_Scalar1, |
| 393 | srcRect->fRight * xScale + SK_Scalar1, |
| 394 | srcRect->fBottom * yScale + SK_Scalar1); |
| 395 | SkPaint p; |
| 396 | p.setColor(SK_ColorRED); |
| 397 | p.setStyle(SkPaint::kStroke_Style); |
| 398 | |
| 399 | canvas->drawRect(r, p); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | void render_rrect(SkCanvas* canvas, const SkRRect& rrect) { |
| 404 | canvas->clear(0xFFFFFFFF); |
| 405 | canvas->save(); |
| 406 | |
| 407 | const SkRect& bounds = rrect.getBounds(); |
| 408 | |
| 409 | xlate_and_scale_to_bounds(canvas, bounds); |
| 410 | |
| 411 | SkPaint p; |
| 412 | p.setColor(SK_ColorBLACK); |
| 413 | p.setStyle(SkPaint::kStroke_Style); |
| 414 | |
| 415 | canvas->drawRRect(rrect, p); |
| 416 | canvas->restore(); |
| 417 | } |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 418 | |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 419 | void render_drrect(SkCanvas* canvas, const SkRRect& outer, const SkRRect& inner) { |
| 420 | canvas->clear(0xFFFFFFFF); |
| 421 | canvas->save(); |
| 422 | |
| 423 | const SkRect& bounds = outer.getBounds(); |
| 424 | |
| 425 | xlate_and_scale_to_bounds(canvas, bounds); |
| 426 | |
| 427 | SkPaint p; |
| 428 | p.setColor(SK_ColorBLACK); |
| 429 | p.setStyle(SkPaint::kStroke_Style); |
| 430 | |
| 431 | canvas->drawDRRect(outer, inner, p); |
| 432 | canvas->restore(); |
| 433 | } |
| 434 | |
Florin Malita | 82d8087 | 2017-06-06 16:58:40 -0400 | [diff] [blame] | 435 | static const char* const gBlendModeMap[] = { |
| 436 | "clear", |
| 437 | "src", |
| 438 | "dst", |
| 439 | "srcOver", |
| 440 | "dstOver", |
| 441 | "srcIn", |
| 442 | "dstIn", |
| 443 | "srcOut", |
| 444 | "dstOut", |
| 445 | "srcATop", |
| 446 | "dstATop", |
| 447 | "xor", |
| 448 | "plus", |
| 449 | "modulate", |
| 450 | |
| 451 | "screen", |
| 452 | |
| 453 | "overlay", |
| 454 | "darken", |
| 455 | "lighten", |
| 456 | "colorDodge", |
| 457 | "colorBurn", |
| 458 | "hardLight", |
| 459 | "softLight", |
| 460 | "difference", |
| 461 | "exclusion", |
| 462 | "multiply", |
| 463 | |
| 464 | "hue", |
| 465 | "saturation", |
| 466 | "color", |
| 467 | "luminosity", |
| 468 | }; |
| 469 | |
| 470 | static_assert(SK_ARRAY_COUNT(gBlendModeMap) == static_cast<size_t>(SkBlendMode::kLastMode) + 1, |
| 471 | "blendMode mismatch"); |
| 472 | static_assert(SK_ARRAY_COUNT(gBlendModeMap) == static_cast<size_t>(SkBlendMode::kLuminosity) + 1, |
| 473 | "blendMode mismatch"); |
| 474 | |
| 475 | void apply_paint_blend_mode(const SkPaint& paint, Json::Value* target) { |
| 476 | const auto mode = paint.getBlendMode(); |
| 477 | if (mode != SkBlendMode::kSrcOver) { |
| 478 | SkASSERT(static_cast<size_t>(mode) < SK_ARRAY_COUNT(gBlendModeMap)); |
| 479 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_BLENDMODE] = |
| 480 | Json::Value(gBlendModeMap[static_cast<size_t>(mode)]); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | void extract_json_paint_blend_mode(Json::Value& jsonPaint, SkPaint* target) { |
| 485 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_BLENDMODE)) { |
| 486 | const char* mode = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_BLENDMODE].asCString(); |
| 487 | |
| 488 | for (size_t i = 0; i < SK_ARRAY_COUNT(gBlendModeMap); ++i) { |
| 489 | if (!strcmp(mode, gBlendModeMap[i])) { |
| 490 | target->setBlendMode(static_cast<SkBlendMode>(i)); |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 497 | }; |
| 498 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 499 | Json::Value SkDrawCommand::MakeJsonColor(const SkColor color) { |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 500 | Json::Value result(Json::arrayValue); |
| 501 | result.append(Json::Value(SkColorGetA(color))); |
| 502 | result.append(Json::Value(SkColorGetR(color))); |
| 503 | result.append(Json::Value(SkColorGetG(color))); |
| 504 | result.append(Json::Value(SkColorGetB(color))); |
| 505 | return result; |
| 506 | } |
| 507 | |
brianosman | 97bbf82 | 2016-09-25 13:15:58 -0700 | [diff] [blame] | 508 | Json::Value SkDrawCommand::MakeJsonColor4f(const SkColor4f& color) { |
| 509 | Json::Value result(Json::arrayValue); |
| 510 | result.append(Json::Value(color.fA)); |
| 511 | result.append(Json::Value(color.fR)); |
| 512 | result.append(Json::Value(color.fG)); |
| 513 | result.append(Json::Value(color.fB)); |
| 514 | return result; |
| 515 | } |
| 516 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 517 | Json::Value SkDrawCommand::MakeJsonPoint(const SkPoint& point) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 518 | Json::Value result(Json::arrayValue); |
| 519 | result.append(Json::Value(point.x())); |
| 520 | result.append(Json::Value(point.y())); |
| 521 | return result; |
| 522 | } |
| 523 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 524 | Json::Value SkDrawCommand::MakeJsonPoint(SkScalar x, SkScalar y) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 525 | Json::Value result(Json::arrayValue); |
| 526 | result.append(Json::Value(x)); |
| 527 | result.append(Json::Value(y)); |
| 528 | return result; |
| 529 | } |
| 530 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 531 | Json::Value SkDrawCommand::MakeJsonRect(const SkRect& rect) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 532 | Json::Value result(Json::arrayValue); |
| 533 | result.append(Json::Value(rect.left())); |
| 534 | result.append(Json::Value(rect.top())); |
| 535 | result.append(Json::Value(rect.right())); |
| 536 | result.append(Json::Value(rect.bottom())); |
| 537 | return result; |
| 538 | } |
| 539 | |
joshualitt | bd72413 | 2016-03-03 11:39:38 -0800 | [diff] [blame] | 540 | Json::Value SkDrawCommand::MakeJsonIRect(const SkIRect& rect) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 541 | Json::Value result(Json::arrayValue); |
| 542 | result.append(Json::Value(rect.left())); |
| 543 | result.append(Json::Value(rect.top())); |
| 544 | result.append(Json::Value(rect.right())); |
| 545 | result.append(Json::Value(rect.bottom())); |
| 546 | return result; |
| 547 | } |
| 548 | |
| 549 | static Json::Value make_json_rrect(const SkRRect& rrect) { |
| 550 | Json::Value result(Json::arrayValue); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 551 | result.append(SkDrawCommand::MakeJsonRect(rrect.rect())); |
| 552 | result.append(SkDrawCommand::MakeJsonPoint(rrect.radii(SkRRect::kUpperLeft_Corner))); |
| 553 | result.append(SkDrawCommand::MakeJsonPoint(rrect.radii(SkRRect::kUpperRight_Corner))); |
| 554 | result.append(SkDrawCommand::MakeJsonPoint(rrect.radii(SkRRect::kLowerRight_Corner))); |
| 555 | result.append(SkDrawCommand::MakeJsonPoint(rrect.radii(SkRRect::kLowerLeft_Corner))); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 556 | return result; |
| 557 | } |
| 558 | |
joshualitt | bd72413 | 2016-03-03 11:39:38 -0800 | [diff] [blame] | 559 | Json::Value SkDrawCommand::MakeJsonMatrix(const SkMatrix& matrix) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 560 | Json::Value result(Json::arrayValue); |
| 561 | Json::Value row1(Json::arrayValue); |
| 562 | row1.append(Json::Value(matrix[0])); |
| 563 | row1.append(Json::Value(matrix[1])); |
| 564 | row1.append(Json::Value(matrix[2])); |
| 565 | result.append(row1); |
| 566 | Json::Value row2(Json::arrayValue); |
| 567 | row2.append(Json::Value(matrix[3])); |
| 568 | row2.append(Json::Value(matrix[4])); |
| 569 | row2.append(Json::Value(matrix[5])); |
| 570 | result.append(row2); |
| 571 | Json::Value row3(Json::arrayValue); |
| 572 | row3.append(Json::Value(matrix[6])); |
| 573 | row3.append(Json::Value(matrix[7])); |
| 574 | row3.append(Json::Value(matrix[8])); |
| 575 | result.append(row3); |
| 576 | return result; |
| 577 | } |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 578 | |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 579 | Json::Value SkDrawCommand::MakeJsonScalar(SkScalar z) { |
| 580 | Json::Value result(z); |
| 581 | return result; |
| 582 | } |
| 583 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 584 | Json::Value SkDrawCommand::MakeJsonPath(const SkPath& path) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 585 | Json::Value result(Json::objectValue); |
| 586 | switch (path.getFillType()) { |
| 587 | case SkPath::kWinding_FillType: |
| 588 | result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_WINDING; |
| 589 | break; |
| 590 | case SkPath::kEvenOdd_FillType: |
| 591 | result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_EVENODD; |
| 592 | break; |
| 593 | case SkPath::kInverseWinding_FillType: |
| 594 | result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING; |
| 595 | break; |
| 596 | case SkPath::kInverseEvenOdd_FillType: |
| 597 | result[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE] = SKDEBUGCANVAS_FILLTYPE_INVERSEEVENODD; |
| 598 | break; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 599 | } |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 600 | Json::Value verbs(Json::arrayValue); |
| 601 | SkPath::Iter iter(path, false); |
| 602 | SkPoint pts[4]; |
| 603 | SkPath::Verb verb; |
| 604 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 605 | switch (verb) { |
| 606 | case SkPath::kLine_Verb: { |
| 607 | Json::Value line(Json::objectValue); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 608 | line[SKDEBUGCANVAS_VERB_LINE] = MakeJsonPoint(pts[1]); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 609 | verbs.append(line); |
| 610 | break; |
| 611 | } |
| 612 | case SkPath::kQuad_Verb: { |
| 613 | Json::Value quad(Json::objectValue); |
| 614 | Json::Value coords(Json::arrayValue); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 615 | coords.append(MakeJsonPoint(pts[1])); |
| 616 | coords.append(MakeJsonPoint(pts[2])); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 617 | quad[SKDEBUGCANVAS_VERB_QUAD] = coords; |
| 618 | verbs.append(quad); |
| 619 | break; |
| 620 | } |
| 621 | case SkPath::kCubic_Verb: { |
| 622 | Json::Value cubic(Json::objectValue); |
| 623 | Json::Value coords(Json::arrayValue); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 624 | coords.append(MakeJsonPoint(pts[1])); |
| 625 | coords.append(MakeJsonPoint(pts[2])); |
| 626 | coords.append(MakeJsonPoint(pts[3])); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 627 | cubic[SKDEBUGCANVAS_VERB_CUBIC] = coords; |
| 628 | verbs.append(cubic); |
| 629 | break; |
| 630 | } |
| 631 | case SkPath::kConic_Verb: { |
| 632 | Json::Value conic(Json::objectValue); |
| 633 | Json::Value coords(Json::arrayValue); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 634 | coords.append(MakeJsonPoint(pts[1])); |
| 635 | coords.append(MakeJsonPoint(pts[2])); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 636 | coords.append(Json::Value(iter.conicWeight())); |
| 637 | conic[SKDEBUGCANVAS_VERB_CONIC] = coords; |
| 638 | verbs.append(conic); |
| 639 | break; |
| 640 | } |
| 641 | case SkPath::kMove_Verb: { |
| 642 | Json::Value move(Json::objectValue); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 643 | move[SKDEBUGCANVAS_VERB_MOVE] = MakeJsonPoint(pts[0]); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 644 | verbs.append(move); |
| 645 | break; |
| 646 | } |
| 647 | case SkPath::kClose_Verb: |
| 648 | verbs.append(Json::Value(SKDEBUGCANVAS_VERB_CLOSE)); |
| 649 | break; |
| 650 | case SkPath::kDone_Verb: |
| 651 | break; |
| 652 | } |
| 653 | } |
| 654 | result[SKDEBUGCANVAS_ATTRIBUTE_VERBS] = verbs; |
| 655 | return result; |
| 656 | } |
| 657 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 658 | Json::Value SkDrawCommand::MakeJsonRegion(const SkRegion& region) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 659 | return Json::Value("<unimplemented>"); |
| 660 | } |
| 661 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 662 | static Json::Value make_json_regionop(SkClipOp op) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 663 | switch (op) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 664 | case kDifference_SkClipOp: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 665 | return Json::Value(SKDEBUGCANVAS_REGIONOP_DIFFERENCE); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 666 | case kIntersect_SkClipOp: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 667 | return Json::Value(SKDEBUGCANVAS_REGIONOP_INTERSECT); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 668 | case kUnion_SkClipOp: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 669 | return Json::Value(SKDEBUGCANVAS_REGIONOP_UNION); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 670 | case kXOR_SkClipOp: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 671 | return Json::Value(SKDEBUGCANVAS_REGIONOP_XOR); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 672 | case kReverseDifference_SkClipOp: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 673 | return Json::Value(SKDEBUGCANVAS_REGIONOP_REVERSE_DIFFERENCE); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 674 | case kReplace_SkClipOp: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 675 | return Json::Value(SKDEBUGCANVAS_REGIONOP_REPLACE); |
| 676 | default: |
| 677 | SkASSERT(false); |
| 678 | return Json::Value("<invalid region op>"); |
| 679 | }; |
| 680 | } |
| 681 | |
| 682 | static Json::Value make_json_pointmode(SkCanvas::PointMode mode) { |
| 683 | switch (mode) { |
| 684 | case SkCanvas::kPoints_PointMode: |
| 685 | return Json::Value(SKDEBUGCANVAS_POINTMODE_POINTS); |
| 686 | case SkCanvas::kLines_PointMode: |
| 687 | return Json::Value(SKDEBUGCANVAS_POINTMODE_LINES); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 688 | case SkCanvas::kPolygon_PointMode: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 689 | return Json::Value(SKDEBUGCANVAS_POINTMODE_POLYGON); |
| 690 | default: |
| 691 | SkASSERT(false); |
| 692 | return Json::Value("<invalid point mode>"); |
| 693 | }; |
| 694 | } |
| 695 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 696 | static void store_scalar(Json::Value* target, const char* key, SkScalar value, |
ethannicholas | bd3dae8 | 2016-02-10 12:10:00 -0800 | [diff] [blame] | 697 | SkScalar defaultValue) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 698 | if (value != defaultValue) { |
| 699 | (*target)[key] = Json::Value(value); |
| 700 | } |
| 701 | } |
| 702 | |
ethannicholas | bd3dae8 | 2016-02-10 12:10:00 -0800 | [diff] [blame] | 703 | static void store_bool(Json::Value* target, const char* key, bool value, bool defaultValue) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 704 | if (value != defaultValue) { |
| 705 | (*target)[key] = Json::Value(value); |
| 706 | } |
| 707 | } |
| 708 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 709 | static void encode_data(const void* bytes, size_t count, const char* contentType, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 710 | UrlDataManager& urlDataManager, Json::Value* target) { |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 711 | sk_sp<SkData> data(SkData::MakeWithCopy(bytes, count)); |
| 712 | SkString url = urlDataManager.addData(data.get(), contentType); |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 713 | *target = Json::Value(url.c_str()); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 714 | } |
| 715 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 716 | void SkDrawCommand::flatten(const SkFlattenable* flattenable, Json::Value* target, |
| 717 | UrlDataManager& urlDataManager) { |
| 718 | SkBinaryWriteBuffer buffer; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 719 | flattenable->flatten(buffer); |
| 720 | void* data = sk_malloc_throw(buffer.bytesWritten()); |
| 721 | buffer.writeToMemory(data); |
| 722 | Json::Value jsonData; |
| 723 | encode_data(data, buffer.bytesWritten(), "application/octet-stream", urlDataManager, &jsonData); |
| 724 | Json::Value jsonFlattenable; |
| 725 | jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_NAME] = Json::Value(flattenable->getTypeName()); |
| 726 | jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_DATA] = jsonData; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 727 | |
| 728 | SkJsonWriteBuffer jsonBuffer(&urlDataManager); |
| 729 | flattenable->flatten(jsonBuffer); |
| 730 | jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_VALUES] = jsonBuffer.getValue(); |
| 731 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 732 | (*target) = jsonFlattenable; |
| 733 | sk_free(data); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 734 | } |
| 735 | |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 736 | static void write_png_callback(png_structp png_ptr, png_bytep data, png_size_t length) { |
| 737 | SkWStream* out = (SkWStream*) png_get_io_ptr(png_ptr); |
| 738 | out->write(data, length); |
| 739 | } |
| 740 | |
halcanary | a73d76a | 2016-10-17 13:19:02 -0700 | [diff] [blame] | 741 | void SkDrawCommand::WritePNG(const uint8_t* rgba, unsigned width, unsigned height, |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 742 | SkWStream& out, bool isOpaque) { |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 743 | png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); |
| 744 | SkASSERT(png != nullptr); |
| 745 | png_infop info_ptr = png_create_info_struct(png); |
| 746 | SkASSERT(info_ptr != nullptr); |
| 747 | if (setjmp(png_jmpbuf(png))) { |
| 748 | SkFAIL("png encode error"); |
| 749 | } |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 750 | png_set_write_fn(png, &out, write_png_callback, NULL); |
| 751 | int colorType = isOpaque ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGBA; |
| 752 | png_set_IHDR(png, info_ptr, width, height, 8, colorType, PNG_INTERLACE_NONE, |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 753 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 754 | png_set_compression_level(png, 1); |
| 755 | png_bytepp rows = (png_bytepp) sk_malloc_throw(height * sizeof(png_byte*)); |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 756 | png_bytep pixels = (png_bytep) sk_malloc_throw(width * height * 4); |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 757 | for (png_size_t y = 0; y < height; ++y) { |
halcanary | a73d76a | 2016-10-17 13:19:02 -0700 | [diff] [blame] | 758 | const uint8_t* src = rgba + y * width * 4; |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 759 | rows[y] = pixels + y * width * 4; |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 760 | for (png_size_t x = 0; x < width; ++x) { |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 761 | rows[y][x * 4] = src[x * 4]; |
| 762 | rows[y][x * 4 + 1] = src[x * 4 + 1]; |
| 763 | rows[y][x * 4 + 2] = src[x * 4 + 2]; |
| 764 | rows[y][x * 4 + 3] = src[x * 4 + 3]; |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 765 | } |
| 766 | } |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 767 | png_write_info(png, info_ptr); |
| 768 | if (isOpaque) { |
| 769 | png_set_filler(png, 0xFF, PNG_FILLER_AFTER); |
| 770 | } |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 771 | png_set_filter(png, 0, PNG_NO_FILTERS); |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 772 | png_write_image(png, &rows[0]); |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 773 | png_destroy_write_struct(&png, NULL); |
| 774 | sk_free(rows); |
| 775 | sk_free(pixels); |
| 776 | } |
| 777 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 778 | bool SkDrawCommand::flatten(const SkImage& image, Json::Value* target, |
| 779 | UrlDataManager& urlDataManager) { |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 780 | size_t rowBytes = 4 * image.width(); |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 781 | SkAutoMalloc buffer(rowBytes * image.height()); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 782 | SkImageInfo dstInfo = SkImageInfo::Make(image.width(), image.height(), |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 783 | kN32_SkColorType, kPremul_SkAlphaType); |
| 784 | if (!image.readPixels(dstInfo, buffer.get(), rowBytes, 0, 0)) { |
| 785 | SkDebugf("readPixels failed\n"); |
| 786 | return false; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 787 | } |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 788 | |
| 789 | SkBitmap bm; |
| 790 | bm.installPixels(dstInfo, buffer.get(), rowBytes); |
| 791 | sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(bm); |
| 792 | |
ethannicholas | f67531f | 2016-03-21 10:19:39 -0700 | [diff] [blame] | 793 | SkDynamicMemoryWStream out; |
halcanary | a73d76a | 2016-10-17 13:19:02 -0700 | [diff] [blame] | 794 | SkDrawCommand::WritePNG(encodedBitmap->bytes(), image.width(), image.height(), |
msarett | a5cf4f4 | 2016-06-30 10:06:51 -0700 | [diff] [blame] | 795 | out, false); |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 796 | sk_sp<SkData> encoded = out.detachAsData(); |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 797 | Json::Value jsonData; |
| 798 | encode_data(encoded->data(), encoded->size(), "image/png", urlDataManager, &jsonData); |
| 799 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_DATA] = jsonData; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 800 | return true; |
| 801 | } |
| 802 | |
| 803 | static const char* color_type_name(SkColorType colorType) { |
| 804 | switch (colorType) { |
| 805 | case kARGB_4444_SkColorType: |
| 806 | return SKDEBUGCANVAS_COLORTYPE_ARGB4444; |
| 807 | case kRGBA_8888_SkColorType: |
| 808 | return SKDEBUGCANVAS_COLORTYPE_RGBA8888; |
| 809 | case kBGRA_8888_SkColorType: |
| 810 | return SKDEBUGCANVAS_COLORTYPE_BGRA8888; |
| 811 | case kRGB_565_SkColorType: |
| 812 | return SKDEBUGCANVAS_COLORTYPE_565; |
| 813 | case kGray_8_SkColorType: |
| 814 | return SKDEBUGCANVAS_COLORTYPE_GRAY8; |
| 815 | case kIndex_8_SkColorType: |
| 816 | return SKDEBUGCANVAS_COLORTYPE_INDEX8; |
| 817 | case kAlpha_8_SkColorType: |
| 818 | return SKDEBUGCANVAS_COLORTYPE_ALPHA8; |
| 819 | default: |
| 820 | SkASSERT(false); |
| 821 | return SKDEBUGCANVAS_COLORTYPE_RGBA8888; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | static const char* alpha_type_name(SkAlphaType alphaType) { |
| 826 | switch (alphaType) { |
| 827 | case kOpaque_SkAlphaType: |
| 828 | return SKDEBUGCANVAS_ALPHATYPE_OPAQUE; |
| 829 | case kPremul_SkAlphaType: |
| 830 | return SKDEBUGCANVAS_ALPHATYPE_PREMUL; |
| 831 | case kUnpremul_SkAlphaType: |
| 832 | return SKDEBUGCANVAS_ALPHATYPE_UNPREMUL; |
| 833 | default: |
| 834 | SkASSERT(false); |
| 835 | return SKDEBUGCANVAS_ALPHATYPE_OPAQUE; |
| 836 | } |
| 837 | } |
| 838 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 839 | static Json::ArrayIndex decode_data(Json::Value data, UrlDataManager& urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 840 | const void** target) { |
| 841 | UrlDataManager::UrlData* urlData = urlDataManager.getDataFromUrl(SkString(data.asCString())); |
| 842 | if (urlData == nullptr) { |
| 843 | SkASSERT(false); |
| 844 | *target = nullptr; |
| 845 | return 0; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 846 | } |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 847 | *target = urlData->fData->data(); |
| 848 | // cast should be safe for any reasonably-sized object... |
| 849 | return (Json::ArrayIndex) urlData->fData->size(); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 850 | } |
| 851 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 852 | static SkFlattenable* load_flattenable(Json::Value jsonFlattenable, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 853 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 854 | if (!jsonFlattenable.isMember(SKDEBUGCANVAS_ATTRIBUTE_NAME)) { |
| 855 | return nullptr; |
| 856 | } |
| 857 | const char* name = jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_NAME].asCString(); |
| 858 | SkFlattenable::Factory factory = SkFlattenable::NameToFactory(name); |
| 859 | if (factory == nullptr) { |
| 860 | SkDebugf("no factory for loading '%s'\n", name); |
| 861 | return nullptr; |
| 862 | } |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 863 | const void* data; |
| 864 | int size = decode_data(jsonFlattenable[SKDEBUGCANVAS_ATTRIBUTE_DATA], urlDataManager, &data); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 865 | SkValidatingReadBuffer buffer(data, size); |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 866 | sk_sp<SkFlattenable> result = factory(buffer); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 867 | if (!buffer.isValid()) { |
| 868 | SkDebugf("invalid buffer loading flattenable\n"); |
| 869 | return nullptr; |
| 870 | } |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 871 | return result.release(); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | static SkColorType colortype_from_name(const char* name) { |
| 875 | if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_ARGB4444)) { |
| 876 | return kARGB_4444_SkColorType; |
| 877 | } |
| 878 | else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_RGBA8888)) { |
| 879 | return kRGBA_8888_SkColorType; |
| 880 | } |
| 881 | else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_BGRA8888)) { |
| 882 | return kBGRA_8888_SkColorType; |
| 883 | } |
| 884 | else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_565)) { |
| 885 | return kRGB_565_SkColorType; |
| 886 | } |
| 887 | else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_GRAY8)) { |
| 888 | return kGray_8_SkColorType; |
| 889 | } |
| 890 | else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_INDEX8)) { |
| 891 | return kIndex_8_SkColorType; |
| 892 | } |
| 893 | else if (!strcmp(name, SKDEBUGCANVAS_COLORTYPE_ALPHA8)) { |
| 894 | return kAlpha_8_SkColorType; |
| 895 | } |
| 896 | SkASSERT(false); |
| 897 | return kN32_SkColorType; |
| 898 | } |
| 899 | |
| 900 | static SkBitmap* convert_colortype(SkBitmap* bitmap, SkColorType colorType) { |
| 901 | if (bitmap->colorType() == colorType ) { |
| 902 | return bitmap; |
| 903 | } |
| 904 | SkBitmap* dst = new SkBitmap(); |
Matt Sarett | 68b8e3d | 2017-04-28 11:15:22 -0400 | [diff] [blame] | 905 | if (dst->tryAllocPixels(bitmap->info().makeColorType(colorType)) && |
| 906 | bitmap->readPixels(dst->info(), dst->getPixels(), dst->rowBytes(), 0, 0)) |
| 907 | { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 908 | delete bitmap; |
| 909 | return dst; |
| 910 | } |
| 911 | SkASSERT(false); |
| 912 | delete dst; |
| 913 | return bitmap; |
| 914 | } |
| 915 | |
| 916 | // caller is responsible for freeing return value |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 917 | static SkBitmap* load_bitmap(const Json::Value& jsonBitmap, UrlDataManager& urlDataManager) { |
| 918 | if (!jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_DATA)) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 919 | SkDebugf("invalid bitmap\n"); |
| 920 | return nullptr; |
| 921 | } |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 922 | const void* data; |
| 923 | int size = decode_data(jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_DATA], urlDataManager, &data); |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 924 | sk_sp<SkData> encoded(SkData::MakeWithoutCopy(data, size)); |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 925 | sk_sp<SkImage> image(SkImage::MakeFromEncoded(std::move(encoded), nullptr)); |
msarett | 790f99a | 2016-03-09 06:16:55 -0800 | [diff] [blame] | 926 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 927 | std::unique_ptr<SkBitmap> bitmap(new SkBitmap()); |
msarett | 790f99a | 2016-03-09 06:16:55 -0800 | [diff] [blame] | 928 | if (nullptr != image) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 929 | if (!image->asLegacyBitmap(bitmap.get(), SkImage::kRW_LegacyBitmapMode)) { |
msarett | 790f99a | 2016-03-09 06:16:55 -0800 | [diff] [blame] | 930 | SkDebugf("image decode failed\n"); |
| 931 | return nullptr; |
| 932 | } |
| 933 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 934 | if (jsonBitmap.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLOR)) { |
| 935 | const char* ctName = jsonBitmap[SKDEBUGCANVAS_ATTRIBUTE_COLOR].asCString(); |
| 936 | SkColorType ct = colortype_from_name(ctName); |
| 937 | if (ct != kIndex_8_SkColorType) { |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 938 | bitmap.reset(convert_colortype(bitmap.release(), ct)); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 939 | } |
| 940 | } |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 941 | return bitmap.release(); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 942 | } |
| 943 | SkDebugf("image decode failed\n"); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 944 | return nullptr; |
| 945 | } |
| 946 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 947 | static sk_sp<SkImage> load_image(const Json::Value& jsonImage, UrlDataManager& urlDataManager) { |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 948 | SkBitmap* bitmap = load_bitmap(jsonImage, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 949 | if (bitmap == nullptr) { |
| 950 | return nullptr; |
| 951 | } |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 952 | auto result = SkImage::MakeFromBitmap(*bitmap); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 953 | delete bitmap; |
| 954 | return result; |
| 955 | } |
| 956 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 957 | bool SkDrawCommand::flatten(const SkBitmap& bitmap, Json::Value* target, |
| 958 | UrlDataManager& urlDataManager) { |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 959 | sk_sp<SkImage> image(SkImage::MakeFromBitmap(bitmap)); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 960 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = Json::Value(color_type_name(bitmap.colorType())); |
| 961 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = Json::Value(alpha_type_name(bitmap.alphaType())); |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 962 | bool success = flatten(*image, target, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 963 | return success; |
| 964 | } |
| 965 | |
halcanary | f412f09 | 2016-08-25 11:10:41 -0700 | [diff] [blame] | 966 | static void apply_paint_hinting(const SkPaint& paint, Json::Value* target) { |
| 967 | SkPaint::Hinting hinting = paint.getHinting(); |
| 968 | if (hinting != SkPaintDefaults_Hinting) { |
| 969 | switch (hinting) { |
| 970 | case SkPaint::kNo_Hinting: |
| 971 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_HINTING] = SKDEBUGCANVAS_HINTING_NONE; |
| 972 | break; |
| 973 | case SkPaint::kSlight_Hinting: |
| 974 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_HINTING] = SKDEBUGCANVAS_HINTING_SLIGHT; |
| 975 | break; |
| 976 | case SkPaint::kNormal_Hinting: |
| 977 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_HINTING] = SKDEBUGCANVAS_HINTING_NORMAL; |
| 978 | break; |
| 979 | case SkPaint::kFull_Hinting: |
| 980 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_HINTING] = SKDEBUGCANVAS_HINTING_FULL; |
| 981 | break; |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 986 | static void apply_paint_color(const SkPaint& paint, Json::Value* target) { |
| 987 | SkColor color = paint.getColor(); |
| 988 | if (color != SK_ColorBLACK) { |
| 989 | Json::Value colorValue(Json::arrayValue); |
| 990 | colorValue.append(Json::Value(SkColorGetA(color))); |
| 991 | colorValue.append(Json::Value(SkColorGetR(color))); |
| 992 | colorValue.append(Json::Value(SkColorGetG(color))); |
| 993 | colorValue.append(Json::Value(SkColorGetB(color))); |
| 994 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = colorValue;; |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | static void apply_paint_style(const SkPaint& paint, Json::Value* target) { |
| 999 | SkPaint::Style style = paint.getStyle(); |
| 1000 | if (style != SkPaint::kFill_Style) { |
| 1001 | switch (style) { |
| 1002 | case SkPaint::kStroke_Style: { |
| 1003 | Json::Value stroke(SKDEBUGCANVAS_STYLE_STROKE); |
| 1004 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = stroke; |
| 1005 | break; |
| 1006 | } |
| 1007 | case SkPaint::kStrokeAndFill_Style: { |
| 1008 | Json::Value strokeAndFill(SKDEBUGCANVAS_STYLE_STROKEANDFILL); |
| 1009 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = strokeAndFill; |
| 1010 | break; |
| 1011 | } |
| 1012 | default: SkASSERT(false); |
| 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | static void apply_paint_cap(const SkPaint& paint, Json::Value* target) { |
| 1018 | SkPaint::Cap cap = paint.getStrokeCap(); |
| 1019 | if (cap != SkPaint::kDefault_Cap) { |
| 1020 | switch (cap) { |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1021 | case SkPaint::kButt_Cap: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1022 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_CAP] = Json::Value(SKDEBUGCANVAS_CAP_BUTT); |
| 1023 | break; |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1024 | case SkPaint::kRound_Cap: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1025 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_CAP] = Json::Value(SKDEBUGCANVAS_CAP_ROUND); |
| 1026 | break; |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1027 | case SkPaint::kSquare_Cap: |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1028 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_CAP] = Json::Value(SKDEBUGCANVAS_CAP_SQUARE); |
| 1029 | break; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1030 | default: SkASSERT(false); |
| 1031 | } |
| 1032 | } |
| 1033 | } |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1034 | |
| 1035 | static void apply_paint_join(const SkPaint& paint, Json::Value* target) { |
| 1036 | SkPaint::Join join = paint.getStrokeJoin(); |
| 1037 | if (join != SkPaint::kDefault_Join) { |
| 1038 | switch (join) { |
| 1039 | case SkPaint::kMiter_Join: |
| 1040 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN] = Json::Value( |
| 1041 | SKDEBUGCANVAS_MITER_JOIN); |
| 1042 | break; |
| 1043 | case SkPaint::kRound_Join: |
| 1044 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN] = Json::Value( |
| 1045 | SKDEBUGCANVAS_ROUND_JOIN); |
| 1046 | break; |
| 1047 | case SkPaint::kBevel_Join: |
| 1048 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN] = Json::Value( |
| 1049 | SKDEBUGCANVAS_BEVEL_JOIN); |
| 1050 | break; |
| 1051 | default: SkASSERT(false); |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | static void apply_paint_filterquality(const SkPaint& paint, Json::Value* target) { |
| 1057 | SkFilterQuality quality = paint.getFilterQuality(); |
| 1058 | switch (quality) { |
| 1059 | case kNone_SkFilterQuality: |
| 1060 | break; |
| 1061 | case kLow_SkFilterQuality: |
| 1062 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY] = Json::Value( |
| 1063 | SKDEBUGCANVAS_FILTERQUALITY_LOW); |
| 1064 | break; |
| 1065 | case kMedium_SkFilterQuality: |
| 1066 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY] = Json::Value( |
| 1067 | SKDEBUGCANVAS_FILTERQUALITY_MEDIUM); |
| 1068 | break; |
| 1069 | case kHigh_SkFilterQuality: |
| 1070 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY] = Json::Value( |
| 1071 | SKDEBUGCANVAS_FILTERQUALITY_HIGH); |
| 1072 | break; |
| 1073 | } |
| 1074 | } |
| 1075 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1076 | static void apply_paint_maskfilter(const SkPaint& paint, Json::Value* target, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1077 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1078 | SkMaskFilter* maskFilter = paint.getMaskFilter(); |
| 1079 | if (maskFilter != nullptr) { |
| 1080 | SkMaskFilter::BlurRec blurRec; |
| 1081 | if (maskFilter->asABlur(&blurRec)) { |
| 1082 | Json::Value blur(Json::objectValue); |
| 1083 | blur[SKDEBUGCANVAS_ATTRIBUTE_SIGMA] = Json::Value(blurRec.fSigma); |
| 1084 | switch (blurRec.fStyle) { |
| 1085 | case SkBlurStyle::kNormal_SkBlurStyle: |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1086 | blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value( |
| 1087 | SKDEBUGCANVAS_BLURSTYLE_NORMAL); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1088 | break; |
| 1089 | case SkBlurStyle::kSolid_SkBlurStyle: |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1090 | blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value( |
| 1091 | SKDEBUGCANVAS_BLURSTYLE_SOLID); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1092 | break; |
| 1093 | case SkBlurStyle::kOuter_SkBlurStyle: |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1094 | blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value( |
| 1095 | SKDEBUGCANVAS_BLURSTYLE_OUTER); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1096 | break; |
| 1097 | case SkBlurStyle::kInner_SkBlurStyle: |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1098 | blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE] = Json::Value( |
| 1099 | SKDEBUGCANVAS_BLURSTYLE_INNER); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1100 | break; |
| 1101 | default: |
| 1102 | SkASSERT(false); |
| 1103 | } |
| 1104 | switch (blurRec.fQuality) { |
| 1105 | case SkBlurQuality::kLow_SkBlurQuality: |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1106 | blur[SKDEBUGCANVAS_ATTRIBUTE_QUALITY] = Json::Value( |
| 1107 | SKDEBUGCANVAS_BLURQUALITY_LOW); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1108 | break; |
| 1109 | case SkBlurQuality::kHigh_SkBlurQuality: |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1110 | blur[SKDEBUGCANVAS_ATTRIBUTE_QUALITY] = Json::Value( |
| 1111 | SKDEBUGCANVAS_BLURQUALITY_HIGH); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1112 | break; |
| 1113 | default: |
| 1114 | SkASSERT(false); |
| 1115 | } |
| 1116 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_BLUR] = blur; |
| 1117 | } else { |
| 1118 | Json::Value jsonMaskFilter; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1119 | SkDrawCommand::flatten(maskFilter, &jsonMaskFilter, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1120 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER] = jsonMaskFilter; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1125 | static void apply_paint_patheffect(const SkPaint& paint, Json::Value* target, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1126 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1127 | SkPathEffect* pathEffect = paint.getPathEffect(); |
| 1128 | if (pathEffect != nullptr) { |
| 1129 | SkPathEffect::DashInfo dashInfo; |
| 1130 | SkPathEffect::DashType dashType = pathEffect->asADash(&dashInfo); |
| 1131 | if (dashType == SkPathEffect::kDash_DashType) { |
| 1132 | dashInfo.fIntervals = (SkScalar*) sk_malloc_throw(dashInfo.fCount * sizeof(SkScalar)); |
| 1133 | pathEffect->asADash(&dashInfo); |
| 1134 | Json::Value dashing(Json::objectValue); |
| 1135 | Json::Value intervals(Json::arrayValue); |
| 1136 | for (int32_t i = 0; i < dashInfo.fCount; i++) { |
| 1137 | intervals.append(Json::Value(dashInfo.fIntervals[i])); |
| 1138 | } |
| 1139 | sk_free(dashInfo.fIntervals); |
| 1140 | dashing[SKDEBUGCANVAS_ATTRIBUTE_INTERVALS] = intervals; |
| 1141 | dashing[SKDEBUGCANVAS_ATTRIBUTE_PHASE] = dashInfo.fPhase; |
| 1142 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_DASHING] = dashing; |
| 1143 | } else { |
| 1144 | Json::Value jsonPathEffect; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1145 | SkDrawCommand::flatten(pathEffect, &jsonPathEffect, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1146 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT] = jsonPathEffect; |
| 1147 | } |
| 1148 | } |
| 1149 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1150 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1151 | static void apply_paint_textalign(const SkPaint& paint, Json::Value* target) { |
| 1152 | SkPaint::Align textAlign = paint.getTextAlign(); |
| 1153 | if (textAlign != SkPaint::kLeft_Align) { |
| 1154 | switch (textAlign) { |
| 1155 | case SkPaint::kCenter_Align: { |
| 1156 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN] = SKDEBUGCANVAS_ALIGN_CENTER; |
| 1157 | break; |
| 1158 | } |
| 1159 | case SkPaint::kRight_Align: { |
| 1160 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN] = SKDEBUGCANVAS_ALIGN_RIGHT; |
| 1161 | break; |
| 1162 | } |
| 1163 | default: SkASSERT(false); |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1168 | static void apply_paint_typeface(const SkPaint& paint, Json::Value* target, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1169 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1170 | SkTypeface* typeface = paint.getTypeface(); |
| 1171 | if (typeface != nullptr) { |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1172 | Json::Value jsonTypeface; |
| 1173 | SkDynamicMemoryWStream buffer; |
| 1174 | typeface->serialize(&buffer); |
| 1175 | void* data = sk_malloc_throw(buffer.bytesWritten()); |
| 1176 | buffer.copyTo(data); |
| 1177 | Json::Value jsonData; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1178 | encode_data(data, buffer.bytesWritten(), "application/octet-stream", urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1179 | &jsonData); |
| 1180 | jsonTypeface[SKDEBUGCANVAS_ATTRIBUTE_DATA] = jsonData; |
| 1181 | sk_free(data); |
| 1182 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE] = jsonTypeface; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1186 | static void apply_paint_shader(const SkPaint& paint, Json::Value* target, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1187 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1188 | SkFlattenable* shader = paint.getShader(); |
| 1189 | if (shader != nullptr) { |
| 1190 | Json::Value jsonShader; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1191 | SkDrawCommand::flatten(shader, &jsonShader, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1192 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_SHADER] = jsonShader; |
| 1193 | } |
| 1194 | } |
| 1195 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1196 | static void apply_paint_imagefilter(const SkPaint& paint, Json::Value* target, |
| 1197 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1198 | SkFlattenable* imageFilter = paint.getImageFilter(); |
| 1199 | if (imageFilter != nullptr) { |
| 1200 | Json::Value jsonImageFilter; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1201 | SkDrawCommand::flatten(imageFilter, &jsonImageFilter, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1202 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER] = jsonImageFilter; |
| 1203 | } |
| 1204 | } |
| 1205 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1206 | static void apply_paint_colorfilter(const SkPaint& paint, Json::Value* target, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1207 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1208 | SkFlattenable* colorFilter = paint.getColorFilter(); |
| 1209 | if (colorFilter != nullptr) { |
| 1210 | Json::Value jsonColorFilter; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1211 | SkDrawCommand::flatten(colorFilter, &jsonColorFilter, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1212 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER] = jsonColorFilter; |
| 1213 | } |
| 1214 | } |
| 1215 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1216 | static void apply_paint_looper(const SkPaint& paint, Json::Value* target, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1217 | UrlDataManager& urlDataManager) { |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1218 | SkFlattenable* looper = paint.getLooper(); |
| 1219 | if (looper != nullptr) { |
| 1220 | Json::Value jsonLooper; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1221 | SkDrawCommand::flatten(looper, &jsonLooper, urlDataManager); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1222 | (*target)[SKDEBUGCANVAS_ATTRIBUTE_LOOPER] = jsonLooper; |
| 1223 | } |
| 1224 | } |
| 1225 | |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1226 | Json::Value SkDrawCommand::MakeJsonPaint(const SkPaint& paint, UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1227 | Json::Value result(Json::objectValue); |
| 1228 | store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH, paint.getStrokeWidth(), 0.0f); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1229 | store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER, paint.getStrokeMiter(), |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1230 | SkPaintDefaults_MiterLimit); |
| 1231 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS, paint.isAntiAlias(), false); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1232 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_DITHER, paint.isDither(), false); |
Ben Wagner | 78f1f5a | 2017-06-23 14:35:07 -0400 | [diff] [blame] | 1233 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_FAKEBOLDTEXT, paint.isFakeBoldText(), false); |
| 1234 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_LINEARTEXT, paint.isLinearText(), false); |
| 1235 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_SUBPIXELTEXT, paint.isSubpixelText(), false); |
| 1236 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_DEVKERNTEXT, paint.isDevKernText(), false); |
| 1237 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_LCDRENDERTEXT, paint.isLCDRenderText(), false); |
| 1238 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_EMBEDDEDBITMAPTEXT, paint.isEmbeddedBitmapText(), false); |
| 1239 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_AUTOHINTING, paint.isAutohinted(), false); |
| 1240 | store_bool(&result, SKDEBUGCANVAS_ATTRIBUTE_VERTICALTEXT, paint.isVerticalText(), false); |
| 1241 | //kGenA8FromLCD_Flag |
| 1242 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1243 | store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE, paint.getTextSize(), |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1244 | SkPaintDefaults_TextSize); |
| 1245 | store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextScaleX(), SK_Scalar1); |
| 1246 | store_scalar(&result, SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextSkewX(), 0.0f); |
halcanary | f412f09 | 2016-08-25 11:10:41 -0700 | [diff] [blame] | 1247 | apply_paint_hinting(paint, &result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1248 | apply_paint_color(paint, &result); |
| 1249 | apply_paint_style(paint, &result); |
Florin Malita | 82d8087 | 2017-06-06 16:58:40 -0400 | [diff] [blame] | 1250 | apply_paint_blend_mode(paint, &result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1251 | apply_paint_cap(paint, &result); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1252 | apply_paint_join(paint, &result); |
| 1253 | apply_paint_filterquality(paint, &result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1254 | apply_paint_textalign(paint, &result); |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1255 | apply_paint_patheffect(paint, &result, urlDataManager); |
| 1256 | apply_paint_maskfilter(paint, &result, urlDataManager); |
| 1257 | apply_paint_shader(paint, &result, urlDataManager); |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1258 | apply_paint_looper(paint, &result, urlDataManager); |
| 1259 | apply_paint_imagefilter(paint, &result, urlDataManager); |
| 1260 | apply_paint_colorfilter(paint, &result, urlDataManager); |
| 1261 | apply_paint_typeface(paint, &result, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1262 | return result; |
| 1263 | } |
| 1264 | |
Stan Iliev | ac42aeb | 2017-01-12 16:20:50 -0500 | [diff] [blame] | 1265 | Json::Value SkDrawCommand::MakeJsonLattice(const SkCanvas::Lattice& lattice) { |
| 1266 | Json::Value result(Json::objectValue); |
| 1267 | result[SKDEBUGCANVAS_ATTRIBUTE_LATTICEXCOUNT] = Json::Value(lattice.fXCount); |
| 1268 | result[SKDEBUGCANVAS_ATTRIBUTE_LATTICEYCOUNT] = Json::Value(lattice.fYCount); |
| 1269 | if (nullptr != lattice.fBounds) { |
| 1270 | result[SKDEBUGCANVAS_ATTRIBUTE_BOUNDS] = MakeJsonIRect(*lattice.fBounds); |
| 1271 | } |
| 1272 | Json::Value XDivs(Json::arrayValue); |
| 1273 | for (int i = 0; i < lattice.fXCount; i++) { |
| 1274 | XDivs.append(Json::Value(lattice.fXDivs[i])); |
| 1275 | } |
| 1276 | result[SKDEBUGCANVAS_ATTRIBUTE_LATTICEXDIVS] = XDivs; |
| 1277 | Json::Value YDivs(Json::arrayValue); |
| 1278 | for (int i = 0; i < lattice.fYCount; i++) { |
| 1279 | YDivs.append(Json::Value(lattice.fYDivs[i])); |
| 1280 | } |
| 1281 | result[SKDEBUGCANVAS_ATTRIBUTE_LATTICEYDIVS] = YDivs; |
| 1282 | if (nullptr != lattice.fFlags) { |
| 1283 | Json::Value flags(Json::arrayValue); |
| 1284 | int flagCount = 0; |
| 1285 | for (int row = 0; row < lattice.fYCount+1; row++) { |
| 1286 | Json::Value flagsRow(Json::arrayValue); |
| 1287 | for (int column = 0; column < lattice.fXCount+1; column++) { |
| 1288 | flagsRow.append(Json::Value(lattice.fFlags[flagCount++])); |
| 1289 | } |
| 1290 | flags.append(flagsRow); |
| 1291 | } |
| 1292 | result[SKDEBUGCANVAS_ATTRIBUTE_LATTICEFLAGS] = flags; |
| 1293 | } |
| 1294 | return result; |
| 1295 | } |
| 1296 | |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1297 | static SkPoint get_json_point(Json::Value point) { |
| 1298 | return SkPoint::Make(point[0].asFloat(), point[1].asFloat()); |
| 1299 | } |
| 1300 | |
| 1301 | static SkColor get_json_color(Json::Value color) { |
| 1302 | return SkColorSetARGB(color[0].asInt(), color[1].asInt(), color[2].asInt(), color[3].asInt()); |
| 1303 | } |
| 1304 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1305 | static void extract_json_paint_color(Json::Value& jsonPaint, SkPaint* target) { |
| 1306 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLOR)) { |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1307 | target->setColor(get_json_color(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_COLOR])); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1308 | } |
| 1309 | } |
| 1310 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1311 | static void extract_json_paint_shader(Json::Value& jsonPaint, UrlDataManager& urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1312 | SkPaint* target) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1313 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_SHADER)) { |
| 1314 | Json::Value jsonShader = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_SHADER]; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1315 | SkShader* shader = (SkShader*) load_flattenable(jsonShader, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1316 | if (shader != nullptr) { |
reed | fe63045 | 2016-03-25 09:08:00 -0700 | [diff] [blame] | 1317 | target->setShader(sk_ref_sp(shader)); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1322 | static void extract_json_paint_patheffect(Json::Value& jsonPaint, UrlDataManager& urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1323 | SkPaint* target) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1324 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT)) { |
| 1325 | Json::Value jsonPathEffect = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_PATHEFFECT]; |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 1326 | sk_sp<SkPathEffect> pathEffect((SkPathEffect*)load_flattenable(jsonPathEffect, |
| 1327 | urlDataManager)); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1328 | if (pathEffect != nullptr) { |
| 1329 | target->setPathEffect(pathEffect); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1334 | static void extract_json_paint_maskfilter(Json::Value& jsonPaint, UrlDataManager& urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1335 | SkPaint* target) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1336 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER)) { |
| 1337 | Json::Value jsonMaskFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_MASKFILTER]; |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 1338 | sk_sp<SkMaskFilter> maskFilter((SkMaskFilter*)load_flattenable(jsonMaskFilter, |
| 1339 | urlDataManager)); |
| 1340 | if (maskFilter) { |
| 1341 | target->setMaskFilter(std::move(maskFilter)); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | } |
| 1345 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1346 | static void extract_json_paint_colorfilter(Json::Value& jsonPaint, UrlDataManager& urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1347 | SkPaint* target) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1348 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER)) { |
| 1349 | Json::Value jsonColorFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER]; |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 1350 | sk_sp<SkColorFilter> colorFilter((SkColorFilter*)load_flattenable(jsonColorFilter, |
| 1351 | urlDataManager)); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1352 | if (colorFilter != nullptr) { |
| 1353 | target->setColorFilter(colorFilter); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | } |
| 1357 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1358 | static void extract_json_paint_looper(Json::Value& jsonPaint, UrlDataManager& urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1359 | SkPaint* target) { |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1360 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_LOOPER)) { |
| 1361 | Json::Value jsonLooper = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_LOOPER]; |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 1362 | sk_sp<SkDrawLooper> looper((SkDrawLooper*) load_flattenable(jsonLooper, urlDataManager)); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1363 | if (looper != nullptr) { |
reed | 7b380d0 | 2016-03-21 13:25:16 -0700 | [diff] [blame] | 1364 | target->setLooper(std::move(looper)); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | } |
| 1368 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1369 | static void extract_json_paint_imagefilter(Json::Value& jsonPaint, UrlDataManager& urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1370 | SkPaint* target) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1371 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER)) { |
| 1372 | Json::Value jsonImageFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_IMAGEFILTER]; |
Mike Reed | 5e25717 | 2016-11-01 11:22:05 -0400 | [diff] [blame] | 1373 | sk_sp<SkImageFilter> imageFilter((SkImageFilter*) load_flattenable(jsonImageFilter, |
| 1374 | urlDataManager)); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1375 | if (imageFilter != nullptr) { |
| 1376 | target->setImageFilter(imageFilter); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | } |
| 1380 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1381 | static void extract_json_paint_typeface(Json::Value& jsonPaint, UrlDataManager& urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1382 | SkPaint* target) { |
| 1383 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE)) { |
| 1384 | Json::Value jsonTypeface = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TYPEFACE]; |
| 1385 | Json::Value jsonData = jsonTypeface[SKDEBUGCANVAS_ATTRIBUTE_DATA]; |
| 1386 | const void* data; |
| 1387 | Json::ArrayIndex length = decode_data(jsonData, urlDataManager, &data); |
| 1388 | SkMemoryStream buffer(data, length); |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 1389 | target->setTypeface(SkTypeface::MakeDeserialize(&buffer)); |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1390 | } |
| 1391 | } |
| 1392 | |
halcanary | f412f09 | 2016-08-25 11:10:41 -0700 | [diff] [blame] | 1393 | static void extract_json_paint_hinting(Json::Value& jsonPaint, SkPaint* target) { |
| 1394 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_HINTING)) { |
| 1395 | const char* hinting = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_HINTING].asCString(); |
| 1396 | if (!strcmp(hinting, SKDEBUGCANVAS_HINTING_NONE)) { |
| 1397 | target->setHinting(SkPaint::kNo_Hinting); |
| 1398 | } else if (!strcmp(hinting, SKDEBUGCANVAS_HINTING_SLIGHT)) { |
| 1399 | target->setHinting(SkPaint::kSlight_Hinting); |
| 1400 | } else if (!strcmp(hinting, SKDEBUGCANVAS_HINTING_NORMAL)) { |
| 1401 | target->setHinting(SkPaint::kNormal_Hinting); |
| 1402 | } else if (!strcmp(hinting, SKDEBUGCANVAS_HINTING_FULL)) { |
| 1403 | target->setHinting(SkPaint::kFull_Hinting); |
| 1404 | } |
| 1405 | } |
| 1406 | } |
| 1407 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1408 | static void extract_json_paint_style(Json::Value& jsonPaint, SkPaint* target) { |
| 1409 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STYLE)) { |
| 1410 | const char* style = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STYLE].asCString(); |
| 1411 | if (!strcmp(style, SKDEBUGCANVAS_STYLE_FILL)) { |
| 1412 | target->setStyle(SkPaint::kFill_Style); |
| 1413 | } |
| 1414 | else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKE)) { |
| 1415 | target->setStyle(SkPaint::kStroke_Style); |
| 1416 | } |
| 1417 | else if (!strcmp(style, SKDEBUGCANVAS_STYLE_STROKEANDFILL)) { |
| 1418 | target->setStyle(SkPaint::kStrokeAndFill_Style); |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | static void extract_json_paint_strokewidth(Json::Value& jsonPaint, SkPaint* target) { |
| 1424 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH)) { |
| 1425 | float strokeWidth = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STROKEWIDTH].asFloat(); |
| 1426 | target->setStrokeWidth(strokeWidth); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1427 | } |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | static void extract_json_paint_strokemiter(Json::Value& jsonPaint, SkPaint* target) { |
| 1431 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER)) { |
| 1432 | float strokeMiter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STROKEMITER].asFloat(); |
| 1433 | target->setStrokeMiter(strokeMiter); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1434 | } |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1435 | } |
| 1436 | |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1437 | static void extract_json_paint_strokejoin(Json::Value& jsonPaint, SkPaint* target) { |
| 1438 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN)) { |
| 1439 | const char* join = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_STROKEJOIN].asCString(); |
| 1440 | if (!strcmp(join, SKDEBUGCANVAS_MITER_JOIN)) { |
| 1441 | target->setStrokeJoin(SkPaint::kMiter_Join); |
| 1442 | } |
| 1443 | else if (!strcmp(join, SKDEBUGCANVAS_ROUND_JOIN)) { |
| 1444 | target->setStrokeJoin(SkPaint::kRound_Join); |
| 1445 | } |
| 1446 | else if (!strcmp(join, SKDEBUGCANVAS_BEVEL_JOIN)) { |
| 1447 | target->setStrokeJoin(SkPaint::kBevel_Join); |
| 1448 | } |
| 1449 | else { |
| 1450 | SkASSERT(false); |
| 1451 | } |
| 1452 | } |
| 1453 | } |
| 1454 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1455 | static void extract_json_paint_cap(Json::Value& jsonPaint, SkPaint* target) { |
| 1456 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_CAP)) { |
| 1457 | const char* cap = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_CAP].asCString(); |
| 1458 | if (!strcmp(cap, SKDEBUGCANVAS_CAP_BUTT)) { |
| 1459 | target->setStrokeCap(SkPaint::kButt_Cap); |
| 1460 | } |
| 1461 | else if (!strcmp(cap, SKDEBUGCANVAS_CAP_ROUND)) { |
| 1462 | target->setStrokeCap(SkPaint::kRound_Cap); |
| 1463 | } |
| 1464 | else if (!strcmp(cap, SKDEBUGCANVAS_CAP_SQUARE)) { |
| 1465 | target->setStrokeCap(SkPaint::kSquare_Cap); |
| 1466 | } |
| 1467 | } |
| 1468 | } |
| 1469 | |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1470 | static void extract_json_paint_filterquality(Json::Value& jsonPaint, SkPaint* target) { |
| 1471 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY)) { |
| 1472 | const char* quality = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_FILTERQUALITY].asCString(); |
| 1473 | if (!strcmp(quality, SKDEBUGCANVAS_FILTERQUALITY_NONE)) { |
| 1474 | target->setFilterQuality(kNone_SkFilterQuality); |
| 1475 | } |
| 1476 | else if (!strcmp(quality, SKDEBUGCANVAS_FILTERQUALITY_LOW)) { |
| 1477 | target->setFilterQuality(kLow_SkFilterQuality); |
| 1478 | } |
| 1479 | else if (!strcmp(quality, SKDEBUGCANVAS_FILTERQUALITY_MEDIUM)) { |
| 1480 | target->setFilterQuality(kMedium_SkFilterQuality); |
| 1481 | } |
| 1482 | else if (!strcmp(quality, SKDEBUGCANVAS_FILTERQUALITY_HIGH)) { |
| 1483 | target->setFilterQuality(kHigh_SkFilterQuality); |
| 1484 | } |
| 1485 | } |
| 1486 | } |
| 1487 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1488 | static void extract_json_paint_antialias(Json::Value& jsonPaint, SkPaint* target) { |
| 1489 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS)) { |
| 1490 | target->setAntiAlias(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBool()); |
| 1491 | } |
| 1492 | } |
| 1493 | |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1494 | static void extract_json_paint_dither(Json::Value& jsonPaint, SkPaint* target) { |
| 1495 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_DITHER)) { |
| 1496 | target->setDither(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_DITHER].asBool()); |
| 1497 | } |
| 1498 | } |
| 1499 | |
Ben Wagner | 78f1f5a | 2017-06-23 14:35:07 -0400 | [diff] [blame] | 1500 | static void extract_json_paint_fakeboldtext(Json::Value& jsonPaint, SkPaint* target) { |
| 1501 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_FAKEBOLDTEXT)) { |
| 1502 | target->setFakeBoldText(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_FAKEBOLDTEXT].asBool()); |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | static void extract_json_paint_lineartext(Json::Value& jsonPaint, SkPaint* target) { |
| 1507 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_LINEARTEXT)) { |
| 1508 | target->setLinearText(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_LINEARTEXT].asBool()); |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | static void extract_json_paint_subpixeltext(Json::Value& jsonPaint, SkPaint* target) { |
| 1513 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_SUBPIXELTEXT)) { |
| 1514 | target->setSubpixelText(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_SUBPIXELTEXT].asBool()); |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | static void extract_json_paint_devkerntext(Json::Value& jsonPaint, SkPaint* target) { |
| 1519 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_DEVKERNTEXT)) { |
| 1520 | target->setDevKernText(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_DEVKERNTEXT].asBool()); |
| 1521 | } |
| 1522 | } |
| 1523 | |
| 1524 | static void extract_json_paint_lcdrendertext(Json::Value& jsonPaint, SkPaint* target) { |
| 1525 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_LCDRENDERTEXT)) { |
| 1526 | target->setLCDRenderText(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_LCDRENDERTEXT].asBool()); |
| 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | static void extract_json_paint_embeddedbitmaptext(Json::Value& jsonPaint, SkPaint* target) { |
| 1531 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_EMBEDDEDBITMAPTEXT)) { |
| 1532 | target->setEmbeddedBitmapText(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_EMBEDDEDBITMAPTEXT].asBool()); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | static void extract_json_paint_autohinting(Json::Value& jsonPaint, SkPaint* target) { |
| 1537 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_AUTOHINTING)) { |
| 1538 | target->setAutohinted(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_AUTOHINTING].asBool()); |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | static void extract_json_paint_verticaltext(Json::Value& jsonPaint, SkPaint* target) { |
| 1543 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_VERTICALTEXT)) { |
| 1544 | target->setVerticalText(jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_VERTICALTEXT].asBool()); |
| 1545 | } |
| 1546 | } |
| 1547 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1548 | static void extract_json_paint_blur(Json::Value& jsonPaint, SkPaint* target) { |
| 1549 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_BLUR)) { |
| 1550 | Json::Value blur = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_BLUR]; |
| 1551 | SkScalar sigma = blur[SKDEBUGCANVAS_ATTRIBUTE_SIGMA].asFloat(); |
| 1552 | SkBlurStyle style; |
| 1553 | const char* jsonStyle = blur[SKDEBUGCANVAS_ATTRIBUTE_STYLE].asCString(); |
| 1554 | if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_NORMAL)) { |
| 1555 | style = SkBlurStyle::kNormal_SkBlurStyle; |
| 1556 | } |
| 1557 | else if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_SOLID)) { |
| 1558 | style = SkBlurStyle::kSolid_SkBlurStyle; |
| 1559 | } |
| 1560 | else if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_OUTER)) { |
| 1561 | style = SkBlurStyle::kOuter_SkBlurStyle; |
| 1562 | } |
| 1563 | else if (!strcmp(jsonStyle, SKDEBUGCANVAS_BLURSTYLE_INNER)) { |
| 1564 | style = SkBlurStyle::kInner_SkBlurStyle; |
| 1565 | } |
| 1566 | else { |
| 1567 | SkASSERT(false); |
| 1568 | style = SkBlurStyle::kNormal_SkBlurStyle; |
| 1569 | } |
| 1570 | SkBlurMaskFilter::BlurFlags flags; |
| 1571 | const char* jsonQuality = blur[SKDEBUGCANVAS_ATTRIBUTE_QUALITY].asCString(); |
| 1572 | if (!strcmp(jsonQuality, SKDEBUGCANVAS_BLURQUALITY_LOW)) { |
| 1573 | flags = SkBlurMaskFilter::BlurFlags::kNone_BlurFlag; |
| 1574 | } |
| 1575 | else if (!strcmp(jsonQuality, SKDEBUGCANVAS_BLURQUALITY_HIGH)) { |
| 1576 | flags = SkBlurMaskFilter::BlurFlags::kHighQuality_BlurFlag; |
| 1577 | } |
| 1578 | else { |
| 1579 | SkASSERT(false); |
| 1580 | flags = SkBlurMaskFilter::BlurFlags::kNone_BlurFlag; |
| 1581 | } |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 1582 | target->setMaskFilter(SkBlurMaskFilter::Make(style, sigma, flags)); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1583 | } |
| 1584 | } |
| 1585 | |
| 1586 | static void extract_json_paint_dashing(Json::Value& jsonPaint, SkPaint* target) { |
| 1587 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_DASHING)) { |
| 1588 | Json::Value dash = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_DASHING]; |
| 1589 | Json::Value jsonIntervals = dash[SKDEBUGCANVAS_ATTRIBUTE_INTERVALS]; |
| 1590 | Json::ArrayIndex count = jsonIntervals.size(); |
| 1591 | SkScalar* intervals = (SkScalar*) sk_malloc_throw(count * sizeof(SkScalar)); |
| 1592 | for (Json::ArrayIndex i = 0; i < count; i++) { |
| 1593 | intervals[i] = jsonIntervals[i].asFloat(); |
| 1594 | } |
| 1595 | SkScalar phase = dash[SKDEBUGCANVAS_ATTRIBUTE_PHASE].asFloat(); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 1596 | target->setPathEffect(SkDashPathEffect::Make(intervals, count, phase)); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1597 | sk_free(intervals); |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | static void extract_json_paint_textalign(Json::Value& jsonPaint, SkPaint* target) { |
| 1602 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN)) { |
| 1603 | SkPaint::Align textAlign; |
| 1604 | const char* jsonAlign = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTALIGN].asCString(); |
| 1605 | if (!strcmp(jsonAlign, SKDEBUGCANVAS_ALIGN_LEFT)) { |
| 1606 | textAlign = SkPaint::kLeft_Align; |
| 1607 | } |
| 1608 | else if (!strcmp(jsonAlign, SKDEBUGCANVAS_ALIGN_CENTER)) { |
| 1609 | textAlign = SkPaint::kCenter_Align; |
| 1610 | } |
| 1611 | else if (!strcmp(jsonAlign, SKDEBUGCANVAS_ALIGN_RIGHT)) { |
| 1612 | textAlign = SkPaint::kRight_Align; |
| 1613 | } |
| 1614 | else { |
| 1615 | SkASSERT(false); |
| 1616 | textAlign = SkPaint::kLeft_Align; |
| 1617 | } |
| 1618 | target->setTextAlign(textAlign); |
| 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | static void extract_json_paint_textsize(Json::Value& jsonPaint, SkPaint* target) { |
| 1623 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE)) { |
| 1624 | float textSize = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSIZE].asFloat(); |
| 1625 | target->setTextSize(textSize); |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | static void extract_json_paint_textscalex(Json::Value& jsonPaint, SkPaint* target) { |
| 1630 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX)) { |
| 1631 | float textScaleX = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSCALEX].asFloat(); |
| 1632 | target->setTextScaleX(textScaleX); |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | static void extract_json_paint_textskewx(Json::Value& jsonPaint, SkPaint* target) { |
| 1637 | if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX)) { |
| 1638 | float textSkewX = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_TEXTSKEWX].asFloat(); |
| 1639 | target->setTextSkewX(textSkewX); |
| 1640 | } |
| 1641 | } |
| 1642 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1643 | static void extract_json_paint(Json::Value& paint, UrlDataManager& urlDataManager, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1644 | SkPaint* result) { |
halcanary | f412f09 | 2016-08-25 11:10:41 -0700 | [diff] [blame] | 1645 | extract_json_paint_hinting(paint, result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1646 | extract_json_paint_color(paint, result); |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1647 | extract_json_paint_shader(paint, urlDataManager, result); |
| 1648 | extract_json_paint_patheffect(paint, urlDataManager, result); |
| 1649 | extract_json_paint_maskfilter(paint, urlDataManager, result); |
| 1650 | extract_json_paint_colorfilter(paint, urlDataManager, result); |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1651 | extract_json_paint_looper(paint, urlDataManager, result); |
| 1652 | extract_json_paint_imagefilter(paint, urlDataManager, result); |
| 1653 | extract_json_paint_typeface(paint, urlDataManager, result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1654 | extract_json_paint_style(paint, result); |
Florin Malita | 82d8087 | 2017-06-06 16:58:40 -0400 | [diff] [blame] | 1655 | extract_json_paint_blend_mode(paint, result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1656 | extract_json_paint_strokewidth(paint, result); |
| 1657 | extract_json_paint_strokemiter(paint, result); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1658 | extract_json_paint_strokejoin(paint, result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1659 | extract_json_paint_cap(paint, result); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1660 | extract_json_paint_filterquality(paint, result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1661 | extract_json_paint_antialias(paint, result); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1662 | extract_json_paint_dither(paint, result); |
Ben Wagner | 78f1f5a | 2017-06-23 14:35:07 -0400 | [diff] [blame] | 1663 | extract_json_paint_fakeboldtext(paint, result); |
| 1664 | extract_json_paint_lineartext(paint, result); |
| 1665 | extract_json_paint_subpixeltext(paint, result); |
| 1666 | extract_json_paint_devkerntext(paint, result); |
| 1667 | extract_json_paint_lcdrendertext(paint, result); |
| 1668 | extract_json_paint_embeddedbitmaptext(paint, result); |
| 1669 | extract_json_paint_autohinting(paint, result); |
| 1670 | extract_json_paint_verticaltext(paint, result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1671 | extract_json_paint_blur(paint, result); |
| 1672 | extract_json_paint_dashing(paint, result); |
| 1673 | extract_json_paint_textalign(paint, result); |
| 1674 | extract_json_paint_textsize(paint, result); |
| 1675 | extract_json_paint_textscalex(paint, result); |
| 1676 | extract_json_paint_textskewx(paint, result); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | static void extract_json_rect(Json::Value& rect, SkRect* result) { |
| 1680 | result->set(rect[0].asFloat(), rect[1].asFloat(), rect[2].asFloat(), rect[3].asFloat()); |
| 1681 | } |
| 1682 | |
| 1683 | static void extract_json_irect(Json::Value& rect, SkIRect* result) { |
| 1684 | result->set(rect[0].asInt(), rect[1].asInt(), rect[2].asInt(), rect[3].asInt()); |
| 1685 | } |
| 1686 | |
| 1687 | static void extract_json_rrect(Json::Value& rrect, SkRRect* result) { |
| 1688 | SkVector radii[4] = { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1689 | { rrect[1][0].asFloat(), rrect[1][1].asFloat() }, |
| 1690 | { rrect[2][0].asFloat(), rrect[2][1].asFloat() }, |
| 1691 | { rrect[3][0].asFloat(), rrect[3][1].asFloat() }, |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1692 | { rrect[4][0].asFloat(), rrect[4][1].asFloat() } |
| 1693 | }; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1694 | result->setRectRadii(SkRect::MakeLTRB(rrect[0][0].asFloat(), rrect[0][1].asFloat(), |
| 1695 | rrect[0][2].asFloat(), rrect[0][3].asFloat()), |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1696 | radii); |
| 1697 | } |
| 1698 | |
| 1699 | static void extract_json_matrix(Json::Value& matrix, SkMatrix* result) { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1700 | SkScalar values[] = { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1701 | matrix[0][0].asFloat(), matrix[0][1].asFloat(), matrix[0][2].asFloat(), |
| 1702 | matrix[1][0].asFloat(), matrix[1][1].asFloat(), matrix[1][2].asFloat(), |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1703 | matrix[2][0].asFloat(), matrix[2][1].asFloat(), matrix[2][2].asFloat() |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1704 | }; |
| 1705 | result->set9(values); |
| 1706 | } |
| 1707 | |
| 1708 | static void extract_json_path(Json::Value& path, SkPath* result) { |
| 1709 | const char* fillType = path[SKDEBUGCANVAS_ATTRIBUTE_FILLTYPE].asCString(); |
| 1710 | if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_WINDING)) { |
| 1711 | result->setFillType(SkPath::kWinding_FillType); |
| 1712 | } |
| 1713 | else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_EVENODD)) { |
| 1714 | result->setFillType(SkPath::kEvenOdd_FillType); |
| 1715 | } |
| 1716 | else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEWINDING)) { |
| 1717 | result->setFillType(SkPath::kInverseWinding_FillType); |
| 1718 | } |
| 1719 | else if (!strcmp(fillType, SKDEBUGCANVAS_FILLTYPE_INVERSEEVENODD)) { |
| 1720 | result->setFillType(SkPath::kInverseEvenOdd_FillType); |
| 1721 | } |
| 1722 | Json::Value verbs = path[SKDEBUGCANVAS_ATTRIBUTE_VERBS]; |
| 1723 | for (Json::ArrayIndex i = 0; i < verbs.size(); i++) { |
| 1724 | Json::Value verb = verbs[i]; |
| 1725 | if (verb.isString()) { |
| 1726 | SkASSERT(!strcmp(verb.asCString(), SKDEBUGCANVAS_VERB_CLOSE)); |
| 1727 | result->close(); |
| 1728 | } |
| 1729 | else { |
| 1730 | if (verb.isMember(SKDEBUGCANVAS_VERB_MOVE)) { |
| 1731 | Json::Value move = verb[SKDEBUGCANVAS_VERB_MOVE]; |
| 1732 | result->moveTo(move[0].asFloat(), move[1].asFloat()); |
| 1733 | } |
| 1734 | else if (verb.isMember(SKDEBUGCANVAS_VERB_LINE)) { |
| 1735 | Json::Value line = verb[SKDEBUGCANVAS_VERB_LINE]; |
| 1736 | result->lineTo(line[0].asFloat(), line[1].asFloat()); |
| 1737 | } |
| 1738 | else if (verb.isMember(SKDEBUGCANVAS_VERB_QUAD)) { |
| 1739 | Json::Value quad = verb[SKDEBUGCANVAS_VERB_QUAD]; |
| 1740 | result->quadTo(quad[0][0].asFloat(), quad[0][1].asFloat(), |
| 1741 | quad[1][0].asFloat(), quad[1][1].asFloat()); |
| 1742 | } |
| 1743 | else if (verb.isMember(SKDEBUGCANVAS_VERB_CUBIC)) { |
| 1744 | Json::Value cubic = verb[SKDEBUGCANVAS_VERB_CUBIC]; |
| 1745 | result->cubicTo(cubic[0][0].asFloat(), cubic[0][1].asFloat(), |
| 1746 | cubic[1][0].asFloat(), cubic[1][1].asFloat(), |
| 1747 | cubic[2][0].asFloat(), cubic[2][1].asFloat()); |
| 1748 | } |
| 1749 | else if (verb.isMember(SKDEBUGCANVAS_VERB_CONIC)) { |
| 1750 | Json::Value conic = verb[SKDEBUGCANVAS_VERB_CONIC]; |
| 1751 | result->conicTo(conic[0][0].asFloat(), conic[0][1].asFloat(), |
| 1752 | conic[1][0].asFloat(), conic[1][1].asFloat(), |
| 1753 | conic[2].asFloat()); |
| 1754 | } |
| 1755 | else { |
| 1756 | SkASSERT(false); |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1762 | SkClipOp get_json_clipop(Json::Value& jsonOp) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1763 | const char* op = jsonOp.asCString(); |
| 1764 | if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_DIFFERENCE)) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1765 | return kDifference_SkClipOp; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1766 | } |
| 1767 | else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_INTERSECT)) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1768 | return kIntersect_SkClipOp; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1769 | } |
| 1770 | else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_UNION)) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1771 | return kUnion_SkClipOp; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1772 | } |
| 1773 | else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_XOR)) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1774 | return kXOR_SkClipOp; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1775 | } |
| 1776 | else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_REVERSE_DIFFERENCE)) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1777 | return kReverseDifference_SkClipOp; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1778 | } |
| 1779 | else if (!strcmp(op, SKDEBUGCANVAS_REGIONOP_REPLACE)) { |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1780 | return kReplace_SkClipOp; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1781 | } |
| 1782 | SkASSERT(false); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1783 | return kIntersect_SkClipOp; |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1786 | SkClearCommand::SkClearCommand(SkColor color) : INHERITED(kDrawClear_OpType) { |
| 1787 | fColor = color; |
| 1788 | fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
| 1789 | } |
| 1790 | |
| 1791 | void SkClearCommand::execute(SkCanvas* canvas) const { |
| 1792 | canvas->clear(fColor); |
| 1793 | } |
| 1794 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1795 | Json::Value SkClearCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 1796 | Json::Value result = INHERITED::toJSON(urlDataManager); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1797 | result[SKDEBUGCANVAS_ATTRIBUTE_COLOR] = MakeJsonColor(fColor); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1798 | return result; |
| 1799 | } |
| 1800 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1801 | SkClearCommand* SkClearCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) { |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 1802 | Json::Value color = command[SKDEBUGCANVAS_ATTRIBUTE_COLOR]; |
| 1803 | return new SkClearCommand(get_json_color(color)); |
| 1804 | } |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 1805 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1806 | SkClipPathCommand::SkClipPathCommand(const SkPath& path, SkClipOp op, bool doAA) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 1807 | : INHERITED(kClipPath_OpType) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 1808 | fPath = path; |
| 1809 | fOp = op; |
| 1810 | fDoAA = doAA; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1811 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 1812 | fInfo.push(SkObjectParser::PathToString(path)); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 1813 | fInfo.push(SkObjectParser::ClipOpToString(op)); |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 1814 | fInfo.push(SkObjectParser::BoolToString(doAA)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 1817 | void SkClipPathCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 1818 | canvas->clipPath(fPath, fOp, fDoAA); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 1821 | bool SkClipPathCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 1822 | render_path(canvas, fPath); |
| 1823 | return true; |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1826 | Json::Value SkClipPathCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 1827 | Json::Value result = INHERITED::toJSON(urlDataManager); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1828 | result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = MakeJsonPath(fPath); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1829 | result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp); |
| 1830 | result[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS] = fDoAA; |
| 1831 | return result; |
| 1832 | } |
| 1833 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1834 | SkClipPathCommand* SkClipPathCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1835 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1836 | SkPath path; |
| 1837 | extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 1838 | return new SkClipPathCommand(path, get_json_clipop(command[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP]), |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1839 | command[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBool()); |
| 1840 | } |
| 1841 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1842 | SkClipRegionCommand::SkClipRegionCommand(const SkRegion& region, SkClipOp op) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 1843 | : INHERITED(kClipRegion_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 1844 | fRegion = region; |
| 1845 | fOp = op; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1846 | |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 1847 | fInfo.push(SkObjectParser::RegionToString(region)); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 1848 | fInfo.push(SkObjectParser::ClipOpToString(op)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1849 | } |
| 1850 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 1851 | void SkClipRegionCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 1852 | canvas->clipRegion(fRegion, fOp); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1853 | } |
| 1854 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1855 | Json::Value SkClipRegionCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 1856 | Json::Value result = INHERITED::toJSON(urlDataManager); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1857 | result[SKDEBUGCANVAS_ATTRIBUTE_REGION] = MakeJsonRegion(fRegion); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1858 | result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp); |
| 1859 | return result; |
| 1860 | } |
| 1861 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1862 | SkClipRegionCommand* SkClipRegionCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1863 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1864 | SkASSERT(false); |
| 1865 | return nullptr; |
| 1866 | } |
| 1867 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1868 | SkClipRectCommand::SkClipRectCommand(const SkRect& rect, SkClipOp op, bool doAA) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 1869 | : INHERITED(kClipRect_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 1870 | fRect = rect; |
| 1871 | fOp = op; |
| 1872 | fDoAA = doAA; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1873 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 1874 | fInfo.push(SkObjectParser::RectToString(rect)); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 1875 | fInfo.push(SkObjectParser::ClipOpToString(op)); |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 1876 | fInfo.push(SkObjectParser::BoolToString(doAA)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 1879 | void SkClipRectCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 1880 | canvas->clipRect(fRect, fOp, fDoAA); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1881 | } |
| 1882 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1883 | Json::Value SkClipRectCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 1884 | Json::Value result = INHERITED::toJSON(urlDataManager); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 1885 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonRect(fRect); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1886 | result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp); |
| 1887 | result[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS] = Json::Value(fDoAA); |
reed | 67f62fa | 2016-06-29 11:36:34 -0700 | [diff] [blame] | 1888 | |
| 1889 | SkString desc; |
| 1890 | result[SKDEBUGCANVAS_ATTRIBUTE_SHORTDESC] = Json::Value(str_append(&desc, fRect)->c_str()); |
| 1891 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1892 | return result; |
| 1893 | } |
| 1894 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1895 | SkClipRectCommand* SkClipRectCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1896 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1897 | SkRect rect; |
| 1898 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &rect); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 1899 | return new SkClipRectCommand(rect, get_json_clipop(command[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP]), |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1900 | command[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBool()); |
| 1901 | } |
| 1902 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1903 | SkClipRRectCommand::SkClipRRectCommand(const SkRRect& rrect, SkClipOp op, bool doAA) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 1904 | : INHERITED(kClipRRect_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 1905 | fRRect = rrect; |
| 1906 | fOp = op; |
| 1907 | fDoAA = doAA; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 1908 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 1909 | fInfo.push(SkObjectParser::RRectToString(rrect)); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 1910 | fInfo.push(SkObjectParser::ClipOpToString(op)); |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 1911 | fInfo.push(SkObjectParser::BoolToString(doAA)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 1914 | void SkClipRRectCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 1915 | canvas->clipRRect(fRRect, fOp, fDoAA); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 1916 | } |
| 1917 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 1918 | bool SkClipRRectCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 1919 | render_rrect(canvas, fRRect); |
| 1920 | return true; |
| 1921 | } |
| 1922 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1923 | Json::Value SkClipRRectCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 1924 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1925 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rrect(fRRect); |
| 1926 | result[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP] = make_json_regionop(fOp); |
| 1927 | result[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS] = Json::Value(fDoAA); |
| 1928 | return result; |
| 1929 | } |
| 1930 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1931 | SkClipRRectCommand* SkClipRRectCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1932 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1933 | SkRRect rrect; |
| 1934 | extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &rrect); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 1935 | return new SkClipRRectCommand(rrect, |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 1936 | get_json_clipop(command[SKDEBUGCANVAS_ATTRIBUTE_REGIONOP]), |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1937 | command[SKDEBUGCANVAS_ATTRIBUTE_ANTIALIAS].asBool()); |
| 1938 | } |
| 1939 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 1940 | SkConcatCommand::SkConcatCommand(const SkMatrix& matrix) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 1941 | : INHERITED(kConcat_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 1942 | fMatrix = matrix; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1943 | |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 1944 | fInfo.push(SkObjectParser::MatrixToString(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1945 | } |
| 1946 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 1947 | void SkConcatCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 1948 | canvas->concat(fMatrix); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1951 | Json::Value SkConcatCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 1952 | Json::Value result = INHERITED::toJSON(urlDataManager); |
joshualitt | bd72413 | 2016-03-03 11:39:38 -0800 | [diff] [blame] | 1953 | result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1954 | return result; |
| 1955 | } |
| 1956 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 1957 | SkConcatCommand* SkConcatCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 1958 | SkMatrix matrix; |
| 1959 | extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); |
| 1960 | return new SkConcatCommand(matrix); |
| 1961 | } |
| 1962 | |
reed | 97660cc | 2016-06-28 18:54:19 -0700 | [diff] [blame] | 1963 | //// |
| 1964 | |
| 1965 | SkDrawAnnotationCommand::SkDrawAnnotationCommand(const SkRect& rect, const char key[], |
| 1966 | sk_sp<SkData> value) |
| 1967 | : INHERITED(kDrawAnnotation_OpType) |
| 1968 | , fRect(rect) |
| 1969 | , fKey(key) |
| 1970 | , fValue(std::move(value)) |
robertphillips | fb40923 | 2016-06-29 10:28:11 -0700 | [diff] [blame] | 1971 | { |
| 1972 | SkString str; |
| 1973 | str.appendf("Key: %s Value: ", key); |
| 1974 | if (fValue && fValue->size()) { |
| 1975 | str.append((const char*) fValue->bytes(), fValue->size()); |
| 1976 | } else { |
| 1977 | str.appendf("no value"); |
| 1978 | } |
| 1979 | str.appendf("\n"); |
| 1980 | fInfo.push(new SkString(str)); |
| 1981 | } |
reed | 97660cc | 2016-06-28 18:54:19 -0700 | [diff] [blame] | 1982 | |
| 1983 | void SkDrawAnnotationCommand::execute(SkCanvas* canvas) const { |
| 1984 | canvas->drawAnnotation(fRect, fKey.c_str(), fValue); |
| 1985 | } |
| 1986 | |
| 1987 | Json::Value SkDrawAnnotationCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 1988 | Json::Value result = INHERITED::toJSON(urlDataManager); |
| 1989 | |
| 1990 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonRect(fRect); |
| 1991 | result["key"] = Json::Value(fKey.c_str()); |
| 1992 | if (fValue.get()) { |
| 1993 | // TODO: dump out the "value" |
| 1994 | } |
reed | 67f62fa | 2016-06-29 11:36:34 -0700 | [diff] [blame] | 1995 | |
| 1996 | SkString desc; |
| 1997 | str_append(&desc, fRect)->appendf(" %s", fKey.c_str()); |
| 1998 | result[SKDEBUGCANVAS_ATTRIBUTE_SHORTDESC] = Json::Value(desc.c_str()); |
| 1999 | |
reed | 97660cc | 2016-06-28 18:54:19 -0700 | [diff] [blame] | 2000 | return result; |
| 2001 | } |
| 2002 | |
| 2003 | SkDrawAnnotationCommand* SkDrawAnnotationCommand::fromJSON(Json::Value& command, |
| 2004 | UrlDataManager& urlDataManager) { |
| 2005 | SkRect rect; |
| 2006 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &rect); |
| 2007 | sk_sp<SkData> data(nullptr); // TODO: extract "value" from the Json |
| 2008 | return new SkDrawAnnotationCommand(rect, command["key"].asCString(), data); |
| 2009 | } |
| 2010 | |
| 2011 | //// |
| 2012 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2013 | SkDrawBitmapCommand::SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 2014 | const SkPaint* paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2015 | : INHERITED(kDrawBitmap_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2016 | fBitmap = bitmap; |
| 2017 | fLeft = left; |
| 2018 | fTop = top; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2019 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2020 | fPaint = *paint; |
| 2021 | fPaintPtr = &fPaint; |
| 2022 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2023 | fPaintPtr = nullptr; |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2024 | } |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2025 | |
| 2026 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 2027 | fInfo.push(SkObjectParser::ScalarToString(left, "SkScalar left: ")); |
| 2028 | fInfo.push(SkObjectParser::ScalarToString(top, "SkScalar top: ")); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2029 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2030 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 2031 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2034 | void SkDrawBitmapCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2035 | canvas->drawBitmap(fBitmap, fLeft, fTop, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2038 | bool SkDrawBitmapCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 2039 | render_bitmap(canvas, fBitmap); |
| 2040 | return true; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2043 | Json::Value SkDrawBitmapCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2044 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2045 | Json::Value encoded; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2046 | if (flatten(fBitmap, &encoded, urlDataManager)) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2047 | Json::Value command(Json::objectValue); |
| 2048 | result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2049 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonPoint(fLeft, fTop); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2050 | if (fPaintPtr != nullptr) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2051 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(*fPaintPtr, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2052 | } |
| 2053 | } |
| 2054 | return result; |
| 2055 | } |
| 2056 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2057 | SkDrawBitmapCommand* SkDrawBitmapCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2058 | UrlDataManager& urlDataManager) { |
| 2059 | SkBitmap* bitmap = load_bitmap(command[SKDEBUGCANVAS_ATTRIBUTE_BITMAP], urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2060 | if (bitmap == nullptr) { |
| 2061 | return nullptr; |
| 2062 | } |
| 2063 | Json::Value point = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; |
| 2064 | SkPaint* paintPtr; |
| 2065 | SkPaint paint; |
| 2066 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2067 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2068 | paintPtr = &paint; |
| 2069 | } |
| 2070 | else { |
| 2071 | paintPtr = nullptr; |
| 2072 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2073 | SkDrawBitmapCommand* result = new SkDrawBitmapCommand(*bitmap, point[0].asFloat(), |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2074 | point[1].asFloat(), paintPtr); |
| 2075 | delete bitmap; |
| 2076 | return result; |
| 2077 | } |
| 2078 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2079 | SkDrawBitmapNineCommand::SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center, |
skia.committer@gmail.com | db35dab | 2014-03-27 03:02:48 +0000 | [diff] [blame] | 2080 | const SkRect& dst, const SkPaint* paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2081 | : INHERITED(kDrawBitmapNine_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2082 | fBitmap = bitmap; |
| 2083 | fCenter = center; |
| 2084 | fDst = dst; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2085 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2086 | fPaint = *paint; |
| 2087 | fPaintPtr = &fPaint; |
| 2088 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2089 | fPaintPtr = nullptr; |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2090 | } |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2091 | |
| 2092 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
| 2093 | fInfo.push(SkObjectParser::IRectToString(center)); |
| 2094 | fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2095 | if (paint) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2096 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 2097 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2100 | void SkDrawBitmapNineCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 2101 | canvas->drawBitmapNine(fBitmap, fCenter, fDst, fPaintPtr); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2102 | } |
| 2103 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2104 | bool SkDrawBitmapNineCommand::render(SkCanvas* canvas) const { |
robertphillips | 2b82982 | 2015-11-18 12:59:42 -0800 | [diff] [blame] | 2105 | SkRect tmp = SkRect::Make(fCenter); |
| 2106 | render_bitmap(canvas, fBitmap, &tmp); |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 2107 | return true; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2110 | Json::Value SkDrawBitmapNineCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2111 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2112 | Json::Value encoded; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2113 | if (flatten(fBitmap, &encoded, urlDataManager)) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2114 | result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded; |
joshualitt | bd72413 | 2016-03-03 11:39:38 -0800 | [diff] [blame] | 2115 | result[SKDEBUGCANVAS_ATTRIBUTE_CENTER] = MakeJsonIRect(fCenter); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2116 | result[SKDEBUGCANVAS_ATTRIBUTE_DST] = MakeJsonRect(fDst); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2117 | if (fPaintPtr != nullptr) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2118 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(*fPaintPtr, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | return result; |
| 2122 | } |
| 2123 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2124 | SkDrawBitmapNineCommand* SkDrawBitmapNineCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2125 | UrlDataManager& urlDataManager) { |
| 2126 | SkBitmap* bitmap = load_bitmap(command[SKDEBUGCANVAS_ATTRIBUTE_BITMAP], urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2127 | if (bitmap == nullptr) { |
| 2128 | return nullptr; |
| 2129 | } |
| 2130 | SkIRect center; |
| 2131 | extract_json_irect(command[SKDEBUGCANVAS_ATTRIBUTE_CENTER], ¢er); |
| 2132 | SkRect dst; |
| 2133 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_DST], &dst); |
| 2134 | SkPaint* paintPtr; |
| 2135 | SkPaint paint; |
| 2136 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2137 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2138 | paintPtr = &paint; |
| 2139 | } |
| 2140 | else { |
| 2141 | paintPtr = nullptr; |
| 2142 | } |
| 2143 | SkDrawBitmapNineCommand* result = new SkDrawBitmapNineCommand(*bitmap, center, dst, paintPtr); |
| 2144 | delete bitmap; |
| 2145 | return result; |
| 2146 | } |
| 2147 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2148 | SkDrawBitmapRectCommand::SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 2149 | const SkRect& dst, const SkPaint* paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 2150 | SkCanvas::SrcRectConstraint constraint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2151 | : INHERITED(kDrawBitmapRect_OpType) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2152 | fBitmap = bitmap; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2153 | if (src) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2154 | fSrc = *src; |
| 2155 | } else { |
| 2156 | fSrc.setEmpty(); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 2157 | } |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2158 | fDst = dst; |
| 2159 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2160 | if (paint) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2161 | fPaint = *paint; |
| 2162 | fPaintPtr = &fPaint; |
| 2163 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2164 | fPaintPtr = nullptr; |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2165 | } |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 2166 | fConstraint = constraint; |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 2167 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2168 | fInfo.push(SkObjectParser::BitmapToString(bitmap)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2169 | if (src) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2170 | fInfo.push(SkObjectParser::RectToString(*src, "Src: ")); |
| 2171 | } |
| 2172 | fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2173 | if (paint) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2174 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
robertphillips@google.com | b83b6b4 | 2013-01-22 14:32:09 +0000 | [diff] [blame] | 2175 | } |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 2176 | fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: ")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2179 | void SkDrawBitmapRectCommand::execute(SkCanvas* canvas) const { |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 2180 | canvas->legacy_drawBitmapRect(fBitmap, this->srcRect(), fDst, fPaintPtr, fConstraint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2183 | bool SkDrawBitmapRectCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 2184 | render_bitmap(canvas, fBitmap, this->srcRect()); |
| 2185 | return true; |
robertphillips@google.com | 53ec73d | 2012-11-26 13:09:17 +0000 | [diff] [blame] | 2186 | } |
| 2187 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2188 | Json::Value SkDrawBitmapRectCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2189 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2190 | Json::Value encoded; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2191 | if (flatten(fBitmap, &encoded, urlDataManager)) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2192 | result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded; |
| 2193 | if (!fSrc.isEmpty()) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2194 | result[SKDEBUGCANVAS_ATTRIBUTE_SRC] = MakeJsonRect(fSrc); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2195 | } |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2196 | result[SKDEBUGCANVAS_ATTRIBUTE_DST] = MakeJsonRect(fDst); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2197 | if (fPaintPtr != nullptr) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2198 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(*fPaintPtr, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2199 | } |
| 2200 | if (fConstraint == SkCanvas::kStrict_SrcRectConstraint) { |
| 2201 | result[SKDEBUGCANVAS_ATTRIBUTE_STRICT] = Json::Value(true); |
| 2202 | } |
| 2203 | } |
reed | 67f62fa | 2016-06-29 11:36:34 -0700 | [diff] [blame] | 2204 | |
| 2205 | SkString desc; |
| 2206 | result[SKDEBUGCANVAS_ATTRIBUTE_SHORTDESC] = Json::Value(str_append(&desc, fDst)->c_str()); |
| 2207 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2208 | return result; |
| 2209 | } |
| 2210 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2211 | SkDrawBitmapRectCommand* SkDrawBitmapRectCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2212 | UrlDataManager& urlDataManager) { |
| 2213 | SkBitmap* bitmap = load_bitmap(command[SKDEBUGCANVAS_ATTRIBUTE_BITMAP], urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2214 | if (bitmap == nullptr) { |
| 2215 | return nullptr; |
| 2216 | } |
| 2217 | SkRect dst; |
| 2218 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_DST], &dst); |
| 2219 | SkPaint* paintPtr; |
| 2220 | SkPaint paint; |
| 2221 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2222 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2223 | paintPtr = &paint; |
| 2224 | } |
| 2225 | else { |
| 2226 | paintPtr = nullptr; |
| 2227 | } |
| 2228 | SkCanvas::SrcRectConstraint constraint; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2229 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_STRICT) && |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2230 | command[SKDEBUGCANVAS_ATTRIBUTE_STRICT].asBool()) { |
| 2231 | constraint = SkCanvas::kStrict_SrcRectConstraint; |
| 2232 | } |
| 2233 | else { |
| 2234 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 2235 | } |
| 2236 | SkRect* srcPtr; |
| 2237 | SkRect src; |
| 2238 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_SRC)) { |
| 2239 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_SRC], &src); |
| 2240 | srcPtr = &src; |
| 2241 | } |
| 2242 | else { |
| 2243 | srcPtr = nullptr; |
| 2244 | } |
| 2245 | SkDrawBitmapRectCommand* result = new SkDrawBitmapRectCommand(*bitmap, srcPtr, dst, paintPtr, |
| 2246 | constraint); |
| 2247 | delete bitmap; |
| 2248 | return result; |
| 2249 | } |
| 2250 | |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 2251 | SkDrawImageCommand::SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top, |
| 2252 | const SkPaint* paint) |
| 2253 | : INHERITED(kDrawImage_OpType) |
| 2254 | , fImage(SkRef(image)) |
| 2255 | , fLeft(left) |
| 2256 | , fTop(top) { |
| 2257 | |
fmalita | 7361bf0 | 2015-10-29 12:13:48 -0700 | [diff] [blame] | 2258 | fInfo.push(SkObjectParser::ImageToString(image)); |
| 2259 | fInfo.push(SkObjectParser::ScalarToString(left, "Left: ")); |
| 2260 | fInfo.push(SkObjectParser::ScalarToString(top, "Top: ")); |
| 2261 | |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 2262 | if (paint) { |
| 2263 | fPaint.set(*paint); |
fmalita | 7361bf0 | 2015-10-29 12:13:48 -0700 | [diff] [blame] | 2264 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | |
| 2268 | void SkDrawImageCommand::execute(SkCanvas* canvas) const { |
Hal Canary | 1b612a8 | 2016-11-03 16:26:13 -0400 | [diff] [blame] | 2269 | canvas->drawImage(fImage.get(), fLeft, fTop, fPaint.getMaybeNull()); |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | bool SkDrawImageCommand::render(SkCanvas* canvas) const { |
| 2273 | SkAutoCanvasRestore acr(canvas, true); |
| 2274 | canvas->clear(0xFFFFFFFF); |
| 2275 | |
| 2276 | xlate_and_scale_to_bounds(canvas, SkRect::MakeXYWH(fLeft, fTop, |
| 2277 | SkIntToScalar(fImage->width()), |
| 2278 | SkIntToScalar(fImage->height()))); |
| 2279 | this->execute(canvas); |
| 2280 | return true; |
| 2281 | } |
| 2282 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2283 | Json::Value SkDrawImageCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2284 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2285 | Json::Value encoded; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2286 | if (flatten(*fImage, &encoded, urlDataManager)) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2287 | result[SKDEBUGCANVAS_ATTRIBUTE_IMAGE] = encoded; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2288 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonPoint(fLeft, fTop); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2289 | if (fPaint.isValid()) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2290 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(*fPaint.get(), urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2291 | } |
msarett | 0ac1bec | 2016-08-29 09:15:33 -0700 | [diff] [blame] | 2292 | |
| 2293 | result[SKDEBUGCANVAS_ATTRIBUTE_UNIQUE_ID] = fImage->uniqueID(); |
| 2294 | result[SKDEBUGCANVAS_ATTRIBUTE_WIDTH] = fImage->width(); |
| 2295 | result[SKDEBUGCANVAS_ATTRIBUTE_HEIGHT] = fImage->height(); |
| 2296 | switch (fImage->alphaType()) { |
| 2297 | case kOpaque_SkAlphaType: |
| 2298 | result[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = SKDEBUGCANVAS_ALPHATYPE_OPAQUE; |
| 2299 | break; |
| 2300 | case kPremul_SkAlphaType: |
| 2301 | result[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = SKDEBUGCANVAS_ALPHATYPE_PREMUL; |
| 2302 | break; |
| 2303 | case kUnpremul_SkAlphaType: |
| 2304 | result[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = SKDEBUGCANVAS_ALPHATYPE_UNPREMUL; |
| 2305 | break; |
| 2306 | default: |
| 2307 | result[SKDEBUGCANVAS_ATTRIBUTE_ALPHA] = SKDEBUGCANVAS_ALPHATYPE_UNKNOWN; |
| 2308 | break; |
| 2309 | } |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2310 | } |
| 2311 | return result; |
| 2312 | } |
| 2313 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2314 | SkDrawImageCommand* SkDrawImageCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2315 | UrlDataManager& urlDataManager) { |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 2316 | sk_sp<SkImage> image = load_image(command[SKDEBUGCANVAS_ATTRIBUTE_IMAGE], urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2317 | if (image == nullptr) { |
| 2318 | return nullptr; |
| 2319 | } |
| 2320 | Json::Value point = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; |
| 2321 | SkPaint* paintPtr; |
| 2322 | SkPaint paint; |
| 2323 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2324 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2325 | paintPtr = &paint; |
| 2326 | } |
| 2327 | else { |
| 2328 | paintPtr = nullptr; |
| 2329 | } |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 2330 | SkDrawImageCommand* result = new SkDrawImageCommand(image.get(), point[0].asFloat(), |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2331 | point[1].asFloat(), paintPtr); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2332 | return result; |
| 2333 | } |
| 2334 | |
Stan Iliev | ac42aeb | 2017-01-12 16:20:50 -0500 | [diff] [blame] | 2335 | SkDrawImageLatticeCommand::SkDrawImageLatticeCommand(const SkImage* image, |
| 2336 | const SkCanvas::Lattice& lattice, |
| 2337 | const SkRect& dst, const SkPaint* paint) |
| 2338 | : INHERITED(kDrawImageLattice_OpType) |
| 2339 | , fImage(SkRef(image)) |
| 2340 | , fLattice(lattice) |
| 2341 | , fDst(dst) { |
| 2342 | |
| 2343 | fInfo.push(SkObjectParser::ImageToString(image)); |
| 2344 | fInfo.push(SkObjectParser::LatticeToString(lattice)); |
| 2345 | fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
| 2346 | if (paint) { |
| 2347 | fPaint.set(*paint); |
| 2348 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 2349 | } |
| 2350 | } |
| 2351 | |
| 2352 | void SkDrawImageLatticeCommand::execute(SkCanvas* canvas) const { |
| 2353 | SkLatticeIter iter(fLattice, fDst); |
| 2354 | SkRect srcR, dstR; |
| 2355 | while (iter.next(&srcR, &dstR)) { |
| 2356 | canvas->legacy_drawImageRect(fImage.get(), &srcR, dstR, |
| 2357 | fPaint.getMaybeNull(), SkCanvas::kStrict_SrcRectConstraint); |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | bool SkDrawImageLatticeCommand::render(SkCanvas* canvas) const { |
| 2362 | SkAutoCanvasRestore acr(canvas, true); |
| 2363 | canvas->clear(0xFFFFFFFF); |
| 2364 | |
| 2365 | xlate_and_scale_to_bounds(canvas, fDst); |
| 2366 | |
| 2367 | this->execute(canvas); |
| 2368 | return true; |
| 2369 | } |
| 2370 | |
| 2371 | Json::Value SkDrawImageLatticeCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2372 | Json::Value result = INHERITED::toJSON(urlDataManager); |
| 2373 | Json::Value encoded; |
| 2374 | if (flatten(*fImage.get(), &encoded, urlDataManager)) { |
| 2375 | result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded; |
| 2376 | result[SKDEBUGCANVAS_ATTRIBUTE_LATTICE] = MakeJsonLattice(fLattice); |
| 2377 | result[SKDEBUGCANVAS_ATTRIBUTE_DST] = MakeJsonRect(fDst); |
| 2378 | if (fPaint.isValid()) { |
| 2379 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(*fPaint.get(), urlDataManager); |
| 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | SkString desc; |
| 2384 | result[SKDEBUGCANVAS_ATTRIBUTE_SHORTDESC] = Json::Value(str_append(&desc, fDst)->c_str()); |
| 2385 | |
| 2386 | return result; |
| 2387 | } |
| 2388 | |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 2389 | SkDrawImageRectCommand::SkDrawImageRectCommand(const SkImage* image, const SkRect* src, |
| 2390 | const SkRect& dst, const SkPaint* paint, |
| 2391 | SkCanvas::SrcRectConstraint constraint) |
| 2392 | : INHERITED(kDrawImageRect_OpType) |
| 2393 | , fImage(SkRef(image)) |
| 2394 | , fDst(dst) |
| 2395 | , fConstraint(constraint) { |
| 2396 | |
| 2397 | if (src) { |
| 2398 | fSrc.set(*src); |
| 2399 | } |
| 2400 | |
| 2401 | if (paint) { |
| 2402 | fPaint.set(*paint); |
| 2403 | } |
robertphillips | 80af645 | 2015-08-24 08:27:38 -0700 | [diff] [blame] | 2404 | |
| 2405 | fInfo.push(SkObjectParser::ImageToString(image)); |
| 2406 | if (src) { |
| 2407 | fInfo.push(SkObjectParser::RectToString(*src, "Src: ")); |
| 2408 | } |
| 2409 | fInfo.push(SkObjectParser::RectToString(dst, "Dst: ")); |
| 2410 | if (paint) { |
| 2411 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 2412 | } |
| 2413 | fInfo.push(SkObjectParser::IntToString(fConstraint, "Constraint: ")); |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | void SkDrawImageRectCommand::execute(SkCanvas* canvas) const { |
Hal Canary | 1b612a8 | 2016-11-03 16:26:13 -0400 | [diff] [blame] | 2417 | canvas->legacy_drawImageRect(fImage.get(), fSrc.getMaybeNull(), fDst, |
| 2418 | fPaint.getMaybeNull(), fConstraint); |
fmalita | 651c920 | 2015-07-22 10:23:01 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | bool SkDrawImageRectCommand::render(SkCanvas* canvas) const { |
| 2422 | SkAutoCanvasRestore acr(canvas, true); |
| 2423 | canvas->clear(0xFFFFFFFF); |
| 2424 | |
| 2425 | xlate_and_scale_to_bounds(canvas, fDst); |
| 2426 | |
| 2427 | this->execute(canvas); |
| 2428 | return true; |
| 2429 | } |
| 2430 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2431 | Json::Value SkDrawImageRectCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2432 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2433 | Json::Value encoded; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2434 | if (flatten(*fImage.get(), &encoded, urlDataManager)) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2435 | result[SKDEBUGCANVAS_ATTRIBUTE_BITMAP] = encoded; |
| 2436 | if (fSrc.isValid()) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2437 | result[SKDEBUGCANVAS_ATTRIBUTE_SRC] = MakeJsonRect(*fSrc.get()); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2438 | } |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2439 | result[SKDEBUGCANVAS_ATTRIBUTE_DST] = MakeJsonRect(fDst); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2440 | if (fPaint.isValid()) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2441 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(*fPaint.get(), urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2442 | } |
| 2443 | if (fConstraint == SkCanvas::kStrict_SrcRectConstraint) { |
| 2444 | result[SKDEBUGCANVAS_ATTRIBUTE_STRICT] = Json::Value(true); |
| 2445 | } |
| 2446 | } |
reed | 67f62fa | 2016-06-29 11:36:34 -0700 | [diff] [blame] | 2447 | |
| 2448 | SkString desc; |
| 2449 | result[SKDEBUGCANVAS_ATTRIBUTE_SHORTDESC] = Json::Value(str_append(&desc, fDst)->c_str()); |
| 2450 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2451 | return result; |
| 2452 | } |
| 2453 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2454 | SkDrawImageRectCommand* SkDrawImageRectCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2455 | UrlDataManager& urlDataManager) { |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 2456 | sk_sp<SkImage> image = load_image(command[SKDEBUGCANVAS_ATTRIBUTE_IMAGE], urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2457 | if (image == nullptr) { |
| 2458 | return nullptr; |
| 2459 | } |
| 2460 | SkRect dst; |
| 2461 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_DST], &dst); |
| 2462 | SkPaint* paintPtr; |
| 2463 | SkPaint paint; |
| 2464 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2465 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2466 | paintPtr = &paint; |
| 2467 | } |
| 2468 | else { |
| 2469 | paintPtr = nullptr; |
| 2470 | } |
| 2471 | SkCanvas::SrcRectConstraint constraint; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2472 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_STRICT) && |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2473 | command[SKDEBUGCANVAS_ATTRIBUTE_STRICT].asBool()) { |
| 2474 | constraint = SkCanvas::kStrict_SrcRectConstraint; |
| 2475 | } |
| 2476 | else { |
| 2477 | constraint = SkCanvas::kFast_SrcRectConstraint; |
| 2478 | } |
| 2479 | SkRect* srcPtr; |
| 2480 | SkRect src; |
| 2481 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_SRC)) { |
| 2482 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_SRC], &src); |
| 2483 | srcPtr = &src; |
| 2484 | } |
| 2485 | else { |
| 2486 | srcPtr = nullptr; |
| 2487 | } |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 2488 | SkDrawImageRectCommand* result = new SkDrawImageRectCommand(image.get(), srcPtr, dst, paintPtr, |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2489 | constraint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2490 | return result; |
| 2491 | } |
| 2492 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 2493 | SkDrawOvalCommand::SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2494 | : INHERITED(kDrawOval_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2495 | fOval = oval; |
| 2496 | fPaint = paint; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 2497 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2498 | fInfo.push(SkObjectParser::RectToString(oval)); |
| 2499 | fInfo.push(SkObjectParser::PaintToString(paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 2500 | } |
| 2501 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2502 | void SkDrawOvalCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2503 | canvas->drawOval(fOval, fPaint); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2506 | bool SkDrawOvalCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 2507 | canvas->clear(0xFFFFFFFF); |
| 2508 | canvas->save(); |
| 2509 | |
| 2510 | xlate_and_scale_to_bounds(canvas, fOval); |
| 2511 | |
| 2512 | SkPaint p; |
| 2513 | p.setColor(SK_ColorBLACK); |
| 2514 | p.setStyle(SkPaint::kStroke_Style); |
| 2515 | |
| 2516 | canvas->drawOval(fOval, p); |
| 2517 | canvas->restore(); |
| 2518 | |
| 2519 | return true; |
| 2520 | } |
| 2521 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2522 | Json::Value SkDrawOvalCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2523 | Json::Value result = INHERITED::toJSON(urlDataManager); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2524 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonRect(fOval); |
| 2525 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2526 | return result; |
| 2527 | } |
| 2528 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2529 | SkDrawOvalCommand* SkDrawOvalCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2530 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2531 | SkRect coords; |
| 2532 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords); |
| 2533 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2534 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2535 | return new SkDrawOvalCommand(coords, paint); |
| 2536 | } |
| 2537 | |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 2538 | SkDrawArcCommand::SkDrawArcCommand(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 2539 | bool useCenter, const SkPaint& paint) |
| 2540 | : INHERITED(kDrawOval_OpType) { |
| 2541 | fOval = oval; |
| 2542 | fStartAngle = startAngle; |
| 2543 | fSweepAngle = sweepAngle; |
| 2544 | fUseCenter = useCenter; |
| 2545 | fPaint = paint; |
| 2546 | |
| 2547 | fInfo.push(SkObjectParser::RectToString(oval)); |
| 2548 | fInfo.push(SkObjectParser::ScalarToString(startAngle, "StartAngle: ")); |
| 2549 | fInfo.push(SkObjectParser::ScalarToString(sweepAngle, "SweepAngle: ")); |
| 2550 | fInfo.push(SkObjectParser::BoolToString(useCenter)); |
| 2551 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 2552 | } |
| 2553 | |
| 2554 | void SkDrawArcCommand::execute(SkCanvas* canvas) const { |
| 2555 | canvas->drawArc(fOval, fStartAngle, fSweepAngle, fUseCenter, fPaint); |
| 2556 | } |
| 2557 | |
| 2558 | bool SkDrawArcCommand::render(SkCanvas* canvas) const { |
| 2559 | canvas->clear(0xFFFFFFFF); |
| 2560 | canvas->save(); |
| 2561 | |
| 2562 | xlate_and_scale_to_bounds(canvas, fOval); |
| 2563 | |
| 2564 | SkPaint p; |
| 2565 | p.setColor(SK_ColorBLACK); |
| 2566 | p.setStyle(SkPaint::kStroke_Style); |
| 2567 | |
| 2568 | canvas->drawArc(fOval, fStartAngle, fSweepAngle, fUseCenter, p); |
| 2569 | canvas->restore(); |
| 2570 | |
| 2571 | return true; |
| 2572 | } |
| 2573 | |
| 2574 | Json::Value SkDrawArcCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2575 | Json::Value result = INHERITED::toJSON(urlDataManager); |
| 2576 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonRect(fOval); |
| 2577 | result[SKDEBUGCANVAS_ATTRIBUTE_STARTANGLE] = MakeJsonScalar(fStartAngle); |
| 2578 | result[SKDEBUGCANVAS_ATTRIBUTE_SWEEPANGLE] = MakeJsonScalar(fSweepAngle); |
| 2579 | result[SKDEBUGCANVAS_ATTRIBUTE_USECENTER] = fUseCenter; |
| 2580 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
| 2581 | return result; |
| 2582 | } |
| 2583 | |
| 2584 | SkDrawArcCommand* SkDrawArcCommand::fromJSON(Json::Value& command, |
| 2585 | UrlDataManager& urlDataManager) { |
| 2586 | SkRect coords; |
| 2587 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords); |
| 2588 | SkScalar startAngle = command[SKDEBUGCANVAS_ATTRIBUTE_STARTANGLE].asFloat(); |
| 2589 | SkScalar sweepAngle = command[SKDEBUGCANVAS_ATTRIBUTE_SWEEPANGLE].asFloat(); |
| 2590 | bool useCenter = command[SKDEBUGCANVAS_ATTRIBUTE_USECENTER].asBool(); |
| 2591 | SkPaint paint; |
| 2592 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
| 2593 | return new SkDrawArcCommand(coords, startAngle, sweepAngle, useCenter, paint); |
| 2594 | } |
| 2595 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 2596 | SkDrawPaintCommand::SkDrawPaintCommand(const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2597 | : INHERITED(kDrawPaint_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2598 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2599 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2600 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2601 | } |
| 2602 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2603 | void SkDrawPaintCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2604 | canvas->drawPaint(fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2607 | bool SkDrawPaintCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 2608 | canvas->clear(0xFFFFFFFF); |
| 2609 | canvas->drawPaint(fPaint); |
| 2610 | return true; |
| 2611 | } |
| 2612 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2613 | Json::Value SkDrawPaintCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2614 | Json::Value result = INHERITED::toJSON(urlDataManager); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2615 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2616 | return result; |
| 2617 | } |
| 2618 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2619 | SkDrawPaintCommand* SkDrawPaintCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2620 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2621 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2622 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2623 | return new SkDrawPaintCommand(paint); |
| 2624 | } |
| 2625 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 2626 | SkDrawPathCommand::SkDrawPathCommand(const SkPath& path, const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2627 | : INHERITED(kDrawPath_OpType) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2628 | fPath = path; |
| 2629 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2630 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2631 | fInfo.push(SkObjectParser::PathToString(path)); |
| 2632 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2633 | } |
| 2634 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2635 | void SkDrawPathCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2636 | canvas->drawPath(fPath, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2637 | } |
| 2638 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2639 | bool SkDrawPathCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 2640 | render_path(canvas, fPath); |
| 2641 | return true; |
robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2644 | Json::Value SkDrawPathCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2645 | Json::Value result = INHERITED::toJSON(urlDataManager); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2646 | result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = MakeJsonPath(fPath); |
| 2647 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2648 | return result; |
| 2649 | } |
| 2650 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2651 | SkDrawPathCommand* SkDrawPathCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2652 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2653 | SkPath path; |
| 2654 | extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path); |
| 2655 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2656 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2657 | return new SkDrawPathCommand(path, paint); |
| 2658 | } |
| 2659 | |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 2660 | SkBeginDrawPictureCommand::SkBeginDrawPictureCommand(const SkPicture* picture, |
| 2661 | const SkMatrix* matrix, |
| 2662 | const SkPaint* paint) |
| 2663 | : INHERITED(kBeginDrawPicture_OpType) |
| 2664 | , fPicture(SkRef(picture)) { |
| 2665 | |
| 2666 | SkString* str = new SkString; |
| 2667 | str->appendf("SkPicture: L: %f T: %f R: %f B: %f", |
| 2668 | picture->cullRect().fLeft, picture->cullRect().fTop, |
| 2669 | picture->cullRect().fRight, picture->cullRect().fBottom); |
| 2670 | fInfo.push(str); |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 2671 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2672 | if (matrix) { |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 2673 | fMatrix.set(*matrix); |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 2674 | fInfo.push(SkObjectParser::MatrixToString(*matrix)); |
| 2675 | } |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 2676 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2677 | if (paint) { |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 2678 | fPaint.set(*paint); |
robertphillips | b3f319f | 2014-08-13 10:46:23 -0700 | [diff] [blame] | 2679 | fInfo.push(SkObjectParser::PaintToString(*paint)); |
| 2680 | } |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 2681 | |
| 2682 | } |
| 2683 | |
| 2684 | void SkBeginDrawPictureCommand::execute(SkCanvas* canvas) const { |
| 2685 | if (fPaint.isValid()) { |
| 2686 | SkRect bounds = fPicture->cullRect(); |
| 2687 | if (fMatrix.isValid()) { |
| 2688 | fMatrix.get()->mapRect(&bounds); |
| 2689 | } |
| 2690 | canvas->saveLayer(&bounds, fPaint.get()); |
| 2691 | } |
| 2692 | |
| 2693 | if (fMatrix.isValid()) { |
| 2694 | if (!fPaint.isValid()) { |
| 2695 | canvas->save(); |
| 2696 | } |
| 2697 | canvas->concat(*fMatrix.get()); |
| 2698 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2699 | } |
| 2700 | |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 2701 | bool SkBeginDrawPictureCommand::render(SkCanvas* canvas) const { |
commit-bot@chromium.org | e898e9c | 2013-11-21 17:08:12 +0000 | [diff] [blame] | 2702 | canvas->clear(0xFFFFFFFF); |
| 2703 | canvas->save(); |
| 2704 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 2705 | xlate_and_scale_to_bounds(canvas, fPicture->cullRect()); |
commit-bot@chromium.org | e898e9c | 2013-11-21 17:08:12 +0000 | [diff] [blame] | 2706 | |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 2707 | canvas->drawPicture(fPicture.get()); |
commit-bot@chromium.org | e898e9c | 2013-11-21 17:08:12 +0000 | [diff] [blame] | 2708 | |
| 2709 | canvas->restore(); |
| 2710 | |
| 2711 | return true; |
| 2712 | } |
| 2713 | |
fmalita | 160ebb2 | 2015-04-01 20:58:37 -0700 | [diff] [blame] | 2714 | SkEndDrawPictureCommand::SkEndDrawPictureCommand(bool restore) |
| 2715 | : INHERITED(kEndDrawPicture_OpType) , fRestore(restore) { } |
| 2716 | |
| 2717 | void SkEndDrawPictureCommand::execute(SkCanvas* canvas) const { |
| 2718 | if (fRestore) { |
| 2719 | canvas->restore(); |
| 2720 | } |
| 2721 | } |
| 2722 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2723 | SkDrawPointsCommand::SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 2724 | const SkPoint pts[], const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2725 | : INHERITED(kDrawPoints_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2726 | fMode = mode; |
| 2727 | fCount = count; |
| 2728 | fPts = new SkPoint[count]; |
| 2729 | memcpy(fPts, pts, count * sizeof(SkPoint)); |
| 2730 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2731 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2732 | fInfo.push(SkObjectParser::PointsToString(pts, count)); |
| 2733 | fInfo.push(SkObjectParser::ScalarToString(SkIntToScalar((unsigned int)count), |
| 2734 | "Points: ")); |
| 2735 | fInfo.push(SkObjectParser::PointModeToString(mode)); |
| 2736 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2737 | } |
| 2738 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2739 | void SkDrawPointsCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2740 | canvas->drawPoints(fMode, fCount, fPts, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2743 | bool SkDrawPointsCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 2744 | canvas->clear(0xFFFFFFFF); |
| 2745 | canvas->save(); |
| 2746 | |
| 2747 | SkRect bounds; |
| 2748 | |
| 2749 | bounds.setEmpty(); |
| 2750 | for (unsigned int i = 0; i < fCount; ++i) { |
| 2751 | bounds.growToInclude(fPts[i].fX, fPts[i].fY); |
| 2752 | } |
skia.committer@gmail.com | a009083 | 2013-06-07 07:01:06 +0000 | [diff] [blame] | 2753 | |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 2754 | xlate_and_scale_to_bounds(canvas, bounds); |
| 2755 | |
| 2756 | SkPaint p; |
| 2757 | p.setColor(SK_ColorBLACK); |
| 2758 | p.setStyle(SkPaint::kStroke_Style); |
| 2759 | |
| 2760 | canvas->drawPoints(fMode, fCount, fPts, p); |
| 2761 | canvas->restore(); |
| 2762 | |
| 2763 | return true; |
| 2764 | } |
| 2765 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2766 | Json::Value SkDrawPointsCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2767 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2768 | result[SKDEBUGCANVAS_ATTRIBUTE_MODE] = make_json_pointmode(fMode); |
| 2769 | Json::Value points(Json::arrayValue); |
| 2770 | for (size_t i = 0; i < fCount; i++) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2771 | points.append(MakeJsonPoint(fPts[i])); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2772 | } |
| 2773 | result[SKDEBUGCANVAS_ATTRIBUTE_POINTS] = points; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2774 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2775 | return result; |
| 2776 | } |
| 2777 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2778 | SkDrawPointsCommand* SkDrawPointsCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2779 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2780 | SkCanvas::PointMode mode; |
| 2781 | const char* jsonMode = command[SKDEBUGCANVAS_ATTRIBUTE_MODE].asCString(); |
| 2782 | if (!strcmp(jsonMode, SKDEBUGCANVAS_POINTMODE_POINTS)) { |
| 2783 | mode = SkCanvas::kPoints_PointMode; |
| 2784 | } |
| 2785 | else if (!strcmp(jsonMode, SKDEBUGCANVAS_POINTMODE_LINES)) { |
| 2786 | mode = SkCanvas::kLines_PointMode; |
| 2787 | } |
| 2788 | else if (!strcmp(jsonMode, SKDEBUGCANVAS_POINTMODE_POLYGON)) { |
| 2789 | mode = SkCanvas::kPolygon_PointMode; |
| 2790 | } |
| 2791 | else { |
| 2792 | SkASSERT(false); |
| 2793 | return nullptr; |
| 2794 | } |
| 2795 | Json::Value jsonPoints = command[SKDEBUGCANVAS_ATTRIBUTE_POINTS]; |
| 2796 | int count = (int) jsonPoints.size(); |
| 2797 | SkPoint* points = (SkPoint*) sk_malloc_throw(count * sizeof(SkPoint)); |
| 2798 | for (int i = 0; i < count; i++) { |
| 2799 | points[i] = SkPoint::Make(jsonPoints[i][0].asFloat(), jsonPoints[i][1].asFloat()); |
| 2800 | } |
| 2801 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2802 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2803 | SkDrawPointsCommand* result = new SkDrawPointsCommand(mode, count, points, paint); |
| 2804 | sk_free(points); |
| 2805 | return result; |
| 2806 | } |
| 2807 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2808 | SkDrawPosTextCommand::SkDrawPosTextCommand(const void* text, size_t byteLength, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 2809 | const SkPoint pos[], const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2810 | : INHERITED(kDrawPosText_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2811 | size_t numPts = paint.countText(text, byteLength); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2812 | |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2813 | fText = new char[byteLength]; |
| 2814 | memcpy(fText, text, byteLength); |
| 2815 | fByteLength = byteLength; |
| 2816 | |
| 2817 | fPos = new SkPoint[numPts]; |
| 2818 | memcpy(fPos, pos, numPts * sizeof(SkPoint)); |
| 2819 | |
| 2820 | fPaint = paint; |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2821 | |
| 2822 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2823 | // TODO(chudy): Test that this works. |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2824 | fInfo.push(SkObjectParser::PointsToString(pos, 1)); |
| 2825 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2826 | } |
| 2827 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2828 | void SkDrawPosTextCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2829 | canvas->drawPosText(fText, fByteLength, fPos, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2830 | } |
| 2831 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2832 | Json::Value SkDrawPosTextCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2833 | Json::Value result = INHERITED::toJSON(urlDataManager); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2834 | result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText, |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2835 | ((const char*) fText) + fByteLength); |
| 2836 | Json::Value coords(Json::arrayValue); |
bungeman | 51190df | 2016-03-09 07:42:54 -0800 | [diff] [blame] | 2837 | size_t numCoords = fPaint.textToGlyphs(fText, fByteLength, nullptr); |
| 2838 | for (size_t i = 0; i < numCoords; i++) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2839 | coords.append(MakeJsonPoint(fPos[i])); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2840 | } |
| 2841 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = coords; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2842 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2843 | return result; |
| 2844 | } |
| 2845 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 2846 | SkDrawPosTextCommand* SkDrawPosTextCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2847 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2848 | const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString(); |
| 2849 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2850 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2851 | Json::Value coords = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; |
| 2852 | int count = (int) coords.size(); |
| 2853 | SkPoint* points = (SkPoint*) sk_malloc_throw(count * sizeof(SkPoint)); |
| 2854 | for (int i = 0; i < count; i++) { |
| 2855 | points[i] = SkPoint::Make(coords[i][0].asFloat(), coords[i][1].asFloat()); |
| 2856 | } |
| 2857 | return new SkDrawPosTextCommand(text, strlen(text), points, paint); |
| 2858 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2859 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 2860 | SkDrawPosTextHCommand::SkDrawPosTextHCommand(const void* text, size_t byteLength, |
| 2861 | const SkScalar xpos[], SkScalar constY, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 2862 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2863 | : INHERITED(kDrawPosTextH_OpType) { |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2864 | size_t numPts = paint.countText(text, byteLength); |
| 2865 | |
| 2866 | fText = new char[byteLength]; |
| 2867 | memcpy(fText, text, byteLength); |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2868 | fByteLength = byteLength; |
robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 2869 | |
| 2870 | fXpos = new SkScalar[numPts]; |
| 2871 | memcpy(fXpos, xpos, numPts * sizeof(SkScalar)); |
| 2872 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2873 | fConstY = constY; |
| 2874 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2875 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2876 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 2877 | fInfo.push(SkObjectParser::ScalarToString(xpos[0], "XPOS: ")); |
| 2878 | fInfo.push(SkObjectParser::ScalarToString(constY, "SkScalar constY: ")); |
| 2879 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2880 | } |
| 2881 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2882 | void SkDrawPosTextHCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 2883 | canvas->drawPosTextH(fText, fByteLength, fXpos, fConstY, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
bungeman | 51190df | 2016-03-09 07:42:54 -0800 | [diff] [blame] | 2886 | Json::Value SkDrawPosTextHCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2887 | Json::Value result = INHERITED::toJSON(urlDataManager); |
| 2888 | result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText, |
| 2889 | ((const char*) fText) + fByteLength); |
| 2890 | result[SKDEBUGCANVAS_ATTRIBUTE_Y] = Json::Value(fConstY); |
| 2891 | Json::Value xpos(Json::arrayValue); |
| 2892 | size_t numXpos = fPaint.textToGlyphs(fText, fByteLength, nullptr); |
| 2893 | for (size_t i = 0; i < numXpos; i++) { |
| 2894 | xpos.append(Json::Value(fXpos[i])); |
| 2895 | } |
| 2896 | result[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS] = xpos; |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2897 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
bungeman | 51190df | 2016-03-09 07:42:54 -0800 | [diff] [blame] | 2898 | return result; |
| 2899 | } |
| 2900 | |
| 2901 | SkDrawPosTextHCommand* SkDrawPosTextHCommand::fromJSON(Json::Value& command, |
| 2902 | UrlDataManager& urlDataManager) { |
| 2903 | const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString(); |
| 2904 | SkPaint paint; |
| 2905 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
| 2906 | Json::Value jsonXpos = command[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS]; |
| 2907 | int count = (int) jsonXpos.size(); |
| 2908 | SkScalar* xpos = (SkScalar*) sk_malloc_throw(count * sizeof(SkScalar)); |
| 2909 | for (int i = 0; i < count; i++) { |
| 2910 | xpos[i] = jsonXpos[i].asFloat(); |
| 2911 | } |
| 2912 | SkScalar y = command[SKDEBUGCANVAS_ATTRIBUTE_Y].asFloat(); |
| 2913 | return new SkDrawPosTextHCommand(text, strlen(text), xpos, y, paint); |
| 2914 | } |
| 2915 | |
fmalita | 0d48e41 | 2016-01-04 08:08:04 -0800 | [diff] [blame] | 2916 | static const char* gPositioningLabels[] = { |
| 2917 | "kDefault_Positioning", |
| 2918 | "kHorizontal_Positioning", |
| 2919 | "kFull_Positioning", |
| 2920 | }; |
| 2921 | |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 2922 | SkDrawTextBlobCommand::SkDrawTextBlobCommand(sk_sp<SkTextBlob> blob, SkScalar x, SkScalar y, |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 2923 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 2924 | : INHERITED(kDrawTextBlob_OpType) |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 2925 | , fBlob(std::move(blob)) |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 2926 | , fXPos(x) |
| 2927 | , fYPos(y) |
| 2928 | , fPaint(paint) { |
| 2929 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 2930 | std::unique_ptr<SkString> runsStr(new SkString); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 2931 | fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: ")); |
fmalita | ff3106c | 2014-12-09 05:28:20 -0800 | [diff] [blame] | 2932 | fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: ")); |
| 2933 | fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: ")); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 2934 | fInfo.push(runsStr.get()); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 2935 | fInfo.push(SkObjectParser::PaintToString(paint)); |
fmalita | e77f2da | 2015-12-08 18:59:18 -0800 | [diff] [blame] | 2936 | |
| 2937 | unsigned runs = 0; |
| 2938 | SkPaint runPaint(paint); |
fmalita | 02526bd | 2016-09-14 14:55:59 -0700 | [diff] [blame] | 2939 | SkTextBlobRunIterator iter(fBlob.get()); |
fmalita | e77f2da | 2015-12-08 18:59:18 -0800 | [diff] [blame] | 2940 | while (!iter.done()) { |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 2941 | std::unique_ptr<SkString> tmpStr(new SkString); |
fmalita | 0d48e41 | 2016-01-04 08:08:04 -0800 | [diff] [blame] | 2942 | tmpStr->printf("==== Run [%d] ====", runs++); |
| 2943 | fInfo.push(tmpStr.release()); |
fmalita | e77f2da | 2015-12-08 18:59:18 -0800 | [diff] [blame] | 2944 | |
| 2945 | fInfo.push(SkObjectParser::IntToString(iter.glyphCount(), "GlyphCount: ")); |
fmalita | 0d48e41 | 2016-01-04 08:08:04 -0800 | [diff] [blame] | 2946 | tmpStr.reset(new SkString("GlyphPositioning: ")); |
| 2947 | tmpStr->append(gPositioningLabels[iter.positioning()]); |
| 2948 | fInfo.push(tmpStr.release()); |
| 2949 | |
fmalita | e77f2da | 2015-12-08 18:59:18 -0800 | [diff] [blame] | 2950 | iter.applyFontToPaint(&runPaint); |
| 2951 | fInfo.push(SkObjectParser::PaintToString(runPaint)); |
| 2952 | |
| 2953 | iter.next(); |
| 2954 | } |
| 2955 | |
| 2956 | runsStr->printf("Runs: %d", runs); |
| 2957 | // runStr is owned by fInfo at this point. |
| 2958 | runsStr.release(); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 2961 | void SkDrawTextBlobCommand::execute(SkCanvas* canvas) const { |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 2962 | canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint); |
| 2963 | } |
| 2964 | |
fmalita | 5577387 | 2014-08-29 15:08:20 -0700 | [diff] [blame] | 2965 | bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const { |
| 2966 | canvas->clear(SK_ColorWHITE); |
| 2967 | canvas->save(); |
| 2968 | |
| 2969 | SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos); |
| 2970 | xlate_and_scale_to_bounds(canvas, bounds); |
| 2971 | |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 2972 | canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint); |
fmalita | 5577387 | 2014-08-29 15:08:20 -0700 | [diff] [blame] | 2973 | |
| 2974 | canvas->restore(); |
| 2975 | |
| 2976 | return true; |
| 2977 | } |
| 2978 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 2979 | Json::Value SkDrawTextBlobCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 2980 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2981 | Json::Value runs(Json::arrayValue); |
| 2982 | SkTextBlobRunIterator iter(fBlob.get()); |
| 2983 | while (!iter.done()) { |
| 2984 | Json::Value run(Json::objectValue); |
| 2985 | Json::Value jsonPositions(Json::arrayValue); |
| 2986 | Json::Value jsonGlyphs(Json::arrayValue); |
| 2987 | const SkScalar* iterPositions = iter.pos(); |
| 2988 | const uint16_t* iterGlyphs = iter.glyphs(); |
| 2989 | for (uint32_t i = 0; i < iter.glyphCount(); i++) { |
| 2990 | switch (iter.positioning()) { |
| 2991 | case SkTextBlob::kFull_Positioning: |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 2992 | jsonPositions.append(MakeJsonPoint(iterPositions[i * 2], |
| 2993 | iterPositions[i * 2 + 1])); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 2994 | break; |
| 2995 | case SkTextBlob::kHorizontal_Positioning: |
| 2996 | jsonPositions.append(Json::Value(iterPositions[i])); |
| 2997 | break; |
| 2998 | case SkTextBlob::kDefault_Positioning: |
| 2999 | break; |
| 3000 | } |
| 3001 | jsonGlyphs.append(Json::Value(iterGlyphs[i])); |
| 3002 | } |
| 3003 | if (iter.positioning() != SkTextBlob::kDefault_Positioning) { |
| 3004 | run[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS] = jsonPositions; |
| 3005 | } |
| 3006 | run[SKDEBUGCANVAS_ATTRIBUTE_GLYPHS] = jsonGlyphs; |
| 3007 | SkPaint fontPaint; |
| 3008 | iter.applyFontToPaint(&fontPaint); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3009 | run[SKDEBUGCANVAS_ATTRIBUTE_FONT] = MakeJsonPaint(fontPaint, urlDataManager); |
| 3010 | run[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonPoint(iter.offset()); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3011 | runs.append(run); |
| 3012 | iter.next(); |
| 3013 | } |
reed | 6d2c3e7 | 2016-07-07 14:10:14 -0700 | [diff] [blame] | 3014 | SkRect bounds = fBlob->bounds(); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3015 | result[SKDEBUGCANVAS_ATTRIBUTE_RUNS] = runs; |
| 3016 | result[SKDEBUGCANVAS_ATTRIBUTE_X] = Json::Value(fXPos); |
| 3017 | result[SKDEBUGCANVAS_ATTRIBUTE_Y] = Json::Value(fYPos); |
reed | 6d2c3e7 | 2016-07-07 14:10:14 -0700 | [diff] [blame] | 3018 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonRect(bounds); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3019 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
reed | 6d2c3e7 | 2016-07-07 14:10:14 -0700 | [diff] [blame] | 3020 | |
| 3021 | SkString desc; |
| 3022 | // make the bounds local by applying the x,y |
| 3023 | bounds.offset(fXPos, fYPos); |
| 3024 | result[SKDEBUGCANVAS_ATTRIBUTE_SHORTDESC] = Json::Value(str_append(&desc, bounds)->c_str()); |
| 3025 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3026 | return result; |
| 3027 | } |
| 3028 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3029 | SkDrawTextBlobCommand* SkDrawTextBlobCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3030 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3031 | SkTextBlobBuilder builder; |
| 3032 | Json::Value runs = command[SKDEBUGCANVAS_ATTRIBUTE_RUNS]; |
| 3033 | for (Json::ArrayIndex i = 0 ; i < runs.size(); i++) { |
| 3034 | Json::Value run = runs[i]; |
| 3035 | SkPaint font; |
| 3036 | font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3037 | extract_json_paint(run[SKDEBUGCANVAS_ATTRIBUTE_FONT], urlDataManager, &font); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3038 | Json::Value glyphs = run[SKDEBUGCANVAS_ATTRIBUTE_GLYPHS]; |
| 3039 | int count = glyphs.size(); |
| 3040 | Json::Value coords = run[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; |
| 3041 | SkScalar x = coords[0].asFloat(); |
| 3042 | SkScalar y = coords[1].asFloat(); |
reed | 6d2c3e7 | 2016-07-07 14:10:14 -0700 | [diff] [blame] | 3043 | SkRect bounds; |
| 3044 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &bounds); |
| 3045 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3046 | if (run.isMember(SKDEBUGCANVAS_ATTRIBUTE_POSITIONS)) { |
| 3047 | Json::Value positions = run[SKDEBUGCANVAS_ATTRIBUTE_POSITIONS]; |
| 3048 | if (positions.size() > 0 && positions[0].isNumeric()) { |
reed | 6d2c3e7 | 2016-07-07 14:10:14 -0700 | [diff] [blame] | 3049 | SkTextBlobBuilder::RunBuffer buffer = builder.allocRunPosH(font, count, y, &bounds); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3050 | for (int j = 0; j < count; j++) { |
| 3051 | buffer.glyphs[j] = glyphs[j].asUInt(); |
| 3052 | buffer.pos[j] = positions[j].asFloat(); |
| 3053 | } |
| 3054 | } |
| 3055 | else { |
reed | 6d2c3e7 | 2016-07-07 14:10:14 -0700 | [diff] [blame] | 3056 | SkTextBlobBuilder::RunBuffer buffer = builder.allocRunPos(font, count, &bounds); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3057 | for (int j = 0; j < count; j++) { |
| 3058 | buffer.glyphs[j] = glyphs[j].asUInt(); |
| 3059 | buffer.pos[j * 2] = positions[j][0].asFloat(); |
| 3060 | buffer.pos[j * 2 + 1] = positions[j][1].asFloat(); |
| 3061 | } |
| 3062 | } |
| 3063 | } |
| 3064 | else { |
reed | 6d2c3e7 | 2016-07-07 14:10:14 -0700 | [diff] [blame] | 3065 | SkTextBlobBuilder::RunBuffer buffer = builder.allocRun(font, count, x, y, &bounds); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3066 | for (int j = 0; j < count; j++) { |
| 3067 | buffer.glyphs[j] = glyphs[j].asUInt(); |
| 3068 | } |
| 3069 | } |
| 3070 | } |
| 3071 | SkScalar x = command[SKDEBUGCANVAS_ATTRIBUTE_X].asFloat(); |
| 3072 | SkScalar y = command[SKDEBUGCANVAS_ATTRIBUTE_Y].asFloat(); |
| 3073 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3074 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
fmalita | 37283c2 | 2016-09-13 10:00:23 -0700 | [diff] [blame] | 3075 | return new SkDrawTextBlobCommand(builder.make(), x, y, paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3076 | } |
| 3077 | |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3078 | SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 3079 | const SkPoint texCoords[4], SkBlendMode bmode, |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3080 | const SkPaint& paint) |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 3081 | : INHERITED(kDrawPatch_OpType) |
| 3082 | , fBlendMode(bmode) |
| 3083 | { |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3084 | memcpy(fCubics, cubics, sizeof(fCubics)); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 3085 | if (colors != nullptr) { |
| 3086 | memcpy(fColors, colors, sizeof(fColors)); |
| 3087 | fColorsPtr = fColors; |
| 3088 | } else { |
| 3089 | fColorsPtr = nullptr; |
| 3090 | } |
| 3091 | if (texCoords != nullptr) { |
| 3092 | memcpy(fTexCoords, texCoords, sizeof(fTexCoords)); |
| 3093 | fTexCoordsPtr = fTexCoords; |
| 3094 | } else { |
| 3095 | fTexCoordsPtr = nullptr; |
| 3096 | } |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3097 | fPaint = paint; |
| 3098 | |
| 3099 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 3100 | } |
| 3101 | |
| 3102 | void SkDrawPatchCommand::execute(SkCanvas* canvas) const { |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 3103 | canvas->drawPatch(fCubics, fColorsPtr, fTexCoordsPtr, fBlendMode, fPaint); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 3104 | } |
| 3105 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3106 | Json::Value SkDrawPatchCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 3107 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 3108 | Json::Value cubics = Json::Value(Json::arrayValue); |
| 3109 | for (int i = 0; i < 12; i++) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3110 | cubics.append(MakeJsonPoint(fCubics[i])); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 3111 | } |
| 3112 | result[SKDEBUGCANVAS_ATTRIBUTE_CUBICS] = cubics; |
| 3113 | if (fColorsPtr != nullptr) { |
| 3114 | Json::Value colors = Json::Value(Json::arrayValue); |
| 3115 | for (int i = 0; i < 4; i++) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3116 | colors.append(MakeJsonColor(fColorsPtr[i])); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 3117 | } |
| 3118 | result[SKDEBUGCANVAS_ATTRIBUTE_COLORS] = colors; |
| 3119 | } |
| 3120 | if (fTexCoordsPtr != nullptr) { |
| 3121 | Json::Value texCoords = Json::Value(Json::arrayValue); |
| 3122 | for (int i = 0; i < 4; i++) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3123 | texCoords.append(MakeJsonPoint(fTexCoords[i])); |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 3124 | } |
| 3125 | result[SKDEBUGCANVAS_ATTRIBUTE_TEXTURECOORDS] = texCoords; |
| 3126 | } |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 3127 | // fBlendMode |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 3128 | return result; |
| 3129 | } |
| 3130 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3131 | SkDrawPatchCommand* SkDrawPatchCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3132 | UrlDataManager& urlDataManager) { |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 3133 | Json::Value jsonCubics = command[SKDEBUGCANVAS_ATTRIBUTE_CUBICS]; |
| 3134 | SkPoint cubics[12]; |
| 3135 | for (int i = 0; i < 12; i++) { |
| 3136 | cubics[i] = get_json_point(jsonCubics[i]); |
| 3137 | } |
| 3138 | SkColor* colorsPtr; |
| 3139 | SkColor colors[4]; |
| 3140 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLORS)) { |
| 3141 | Json::Value jsonColors = command[SKDEBUGCANVAS_ATTRIBUTE_COLORS]; |
| 3142 | for (int i = 0; i < 4; i++) { |
| 3143 | colors[i] = get_json_color(jsonColors[i]); |
| 3144 | } |
| 3145 | colorsPtr = colors; |
| 3146 | } |
| 3147 | else { |
| 3148 | colorsPtr = nullptr; |
| 3149 | } |
| 3150 | SkPoint* texCoordsPtr; |
| 3151 | SkPoint texCoords[4]; |
| 3152 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_TEXTURECOORDS)) { |
| 3153 | Json::Value jsonTexCoords = command[SKDEBUGCANVAS_ATTRIBUTE_TEXTURECOORDS]; |
| 3154 | for (int i = 0; i < 4; i++) { |
| 3155 | texCoords[i] = get_json_point(jsonTexCoords[i]); |
| 3156 | } |
| 3157 | texCoordsPtr = texCoords; |
| 3158 | } |
| 3159 | else { |
| 3160 | texCoordsPtr = nullptr; |
| 3161 | } |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 3162 | |
| 3163 | SkBlendMode bmode = SkBlendMode::kSrcOver; // TODO: extract from json |
| 3164 | |
ethannicholas | 1446a9a | 2016-02-10 14:05:02 -0800 | [diff] [blame] | 3165 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3166 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 3167 | return new SkDrawPatchCommand(cubics, colorsPtr, texCoordsPtr, bmode, paint); |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3168 | } |
| 3169 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 3170 | SkDrawRectCommand::SkDrawRectCommand(const SkRect& rect, const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3171 | : INHERITED(kDrawRect_OpType) { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 3172 | fRect = rect; |
| 3173 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3174 | |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 3175 | fInfo.push(SkObjectParser::RectToString(rect)); |
| 3176 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3177 | } |
| 3178 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3179 | void SkDrawRectCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 91217d0 | 2013-03-17 18:33:46 +0000 | [diff] [blame] | 3180 | canvas->drawRect(fRect, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3183 | Json::Value SkDrawRectCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 3184 | Json::Value result = INHERITED::toJSON(urlDataManager); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3185 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonRect(fRect); |
| 3186 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
reed | 67f62fa | 2016-06-29 11:36:34 -0700 | [diff] [blame] | 3187 | |
| 3188 | SkString desc; |
| 3189 | result[SKDEBUGCANVAS_ATTRIBUTE_SHORTDESC] = Json::Value(str_append(&desc, fRect)->c_str()); |
| 3190 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3191 | return result; |
| 3192 | } |
| 3193 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3194 | SkDrawRectCommand* SkDrawRectCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3195 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3196 | SkRect coords; |
| 3197 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords); |
| 3198 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3199 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3200 | return new SkDrawRectCommand(coords, paint); |
| 3201 | } |
| 3202 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 3203 | SkDrawRRectCommand::SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3204 | : INHERITED(kDrawRRect_OpType) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3205 | fRRect = rrect; |
| 3206 | fPaint = paint; |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 3207 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3208 | fInfo.push(SkObjectParser::RRectToString(rrect)); |
| 3209 | fInfo.push(SkObjectParser::PaintToString(paint)); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 3210 | } |
| 3211 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3212 | void SkDrawRRectCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 3213 | canvas->drawRRect(fRRect, fPaint); |
robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 3216 | bool SkDrawRRectCommand::render(SkCanvas* canvas) const { |
robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 3217 | render_rrect(canvas, fRRect); |
| 3218 | return true; |
| 3219 | } |
| 3220 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3221 | Json::Value SkDrawRRectCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 3222 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3223 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = make_json_rrect(fRRect); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3224 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3225 | return result; |
| 3226 | } |
| 3227 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3228 | SkDrawRRectCommand* SkDrawRRectCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3229 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3230 | SkRRect coords; |
| 3231 | extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_COORDS], &coords); |
| 3232 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3233 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3234 | return new SkDrawRRectCommand(coords, paint); |
| 3235 | } |
| 3236 | |
skia.committer@gmail.com | 90667ba | 2014-02-25 03:05:18 +0000 | [diff] [blame] | 3237 | SkDrawDRRectCommand::SkDrawDRRectCommand(const SkRRect& outer, |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 3238 | const SkRRect& inner, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 3239 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3240 | : INHERITED(kDrawDRRect_OpType) { |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 3241 | fOuter = outer; |
| 3242 | fInner = inner; |
| 3243 | fPaint = paint; |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 3244 | |
| 3245 | fInfo.push(SkObjectParser::RRectToString(outer)); |
| 3246 | fInfo.push(SkObjectParser::RRectToString(inner)); |
| 3247 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 3248 | } |
| 3249 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3250 | void SkDrawDRRectCommand::execute(SkCanvas* canvas) const { |
commit-bot@chromium.org | 3d30520 | 2014-02-24 17:28:55 +0000 | [diff] [blame] | 3251 | canvas->drawDRRect(fOuter, fInner, fPaint); |
| 3252 | } |
| 3253 | |
| 3254 | bool SkDrawDRRectCommand::render(SkCanvas* canvas) const { |
| 3255 | render_drrect(canvas, fOuter, fInner); |
| 3256 | return true; |
| 3257 | } |
| 3258 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3259 | Json::Value SkDrawDRRectCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 3260 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3261 | result[SKDEBUGCANVAS_ATTRIBUTE_OUTER] = make_json_rrect(fOuter); |
| 3262 | result[SKDEBUGCANVAS_ATTRIBUTE_INNER] = make_json_rrect(fInner); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3263 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3264 | return result; |
| 3265 | } |
| 3266 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3267 | SkDrawDRRectCommand* SkDrawDRRectCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3268 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3269 | SkRRect outer; |
| 3270 | extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_INNER], &outer); |
| 3271 | SkRRect inner; |
| 3272 | extract_json_rrect(command[SKDEBUGCANVAS_ATTRIBUTE_INNER], &inner); |
| 3273 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3274 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3275 | return new SkDrawDRRectCommand(outer, inner, paint); |
| 3276 | } |
| 3277 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 3278 | SkDrawTextCommand::SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 3279 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3280 | : INHERITED(kDrawText_OpType) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3281 | fText = new char[byteLength]; |
| 3282 | memcpy(fText, text, byteLength); |
| 3283 | fByteLength = byteLength; |
| 3284 | fX = x; |
| 3285 | fY = y; |
| 3286 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3287 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3288 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 3289 | fInfo.push(SkObjectParser::ScalarToString(x, "SkScalar x: ")); |
| 3290 | fInfo.push(SkObjectParser::ScalarToString(y, "SkScalar y: ")); |
| 3291 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3292 | } |
| 3293 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3294 | void SkDrawTextCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3295 | canvas->drawText(fText, fByteLength, fX, fY, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3296 | } |
| 3297 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3298 | Json::Value SkDrawTextCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 3299 | Json::Value result = INHERITED::toJSON(urlDataManager); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3300 | result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText, |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3301 | ((const char*) fText) + fByteLength); |
| 3302 | Json::Value coords(Json::arrayValue); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3303 | result[SKDEBUGCANVAS_ATTRIBUTE_COORDS] = MakeJsonPoint(fX, fY); |
| 3304 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3305 | return result; |
| 3306 | } |
| 3307 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3308 | SkDrawTextCommand* SkDrawTextCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3309 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3310 | const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString(); |
| 3311 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3312 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3313 | Json::Value coords = command[SKDEBUGCANVAS_ATTRIBUTE_COORDS]; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3314 | return new SkDrawTextCommand(text, strlen(text), coords[0].asFloat(), coords[1].asFloat(), |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3315 | paint); |
| 3316 | } |
| 3317 | |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 3318 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 3319 | |
commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 3320 | SkDrawTextOnPathCommand::SkDrawTextOnPathCommand(const void* text, size_t byteLength, |
| 3321 | const SkPath& path, const SkMatrix* matrix, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 3322 | const SkPaint& paint) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3323 | : INHERITED(kDrawTextOnPath_OpType) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3324 | fText = new char[byteLength]; |
| 3325 | memcpy(fText, text, byteLength); |
| 3326 | fByteLength = byteLength; |
| 3327 | fPath = path; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 3328 | if (matrix) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3329 | fMatrix = *matrix; |
| 3330 | } else { |
| 3331 | fMatrix.setIdentity(); |
| 3332 | } |
| 3333 | fPaint = paint; |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3334 | |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3335 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 3336 | fInfo.push(SkObjectParser::PathToString(path)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 3337 | if (matrix) { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3338 | fInfo.push(SkObjectParser::MatrixToString(*matrix)); |
| 3339 | } |
| 3340 | fInfo.push(SkObjectParser::PaintToString(paint)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3341 | } |
| 3342 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3343 | void SkDrawTextOnPathCommand::execute(SkCanvas* canvas) const { |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3344 | canvas->drawTextOnPath(fText, fByteLength, fPath, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3345 | fMatrix.isIdentity() ? nullptr : &fMatrix, |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3346 | fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3349 | Json::Value SkDrawTextOnPathCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 3350 | Json::Value result = INHERITED::toJSON(urlDataManager); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3351 | result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText, |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3352 | ((const char*) fText) + fByteLength); |
| 3353 | Json::Value coords(Json::arrayValue); |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3354 | result[SKDEBUGCANVAS_ATTRIBUTE_PATH] = MakeJsonPath(fPath); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3355 | if (!fMatrix.isIdentity()) { |
joshualitt | bd72413 | 2016-03-03 11:39:38 -0800 | [diff] [blame] | 3356 | result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3357 | } |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3358 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3359 | return result; |
| 3360 | } |
| 3361 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3362 | SkDrawTextOnPathCommand* SkDrawTextOnPathCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3363 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3364 | const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString(); |
| 3365 | SkPaint paint; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3366 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3367 | SkPath path; |
| 3368 | extract_json_path(command[SKDEBUGCANVAS_ATTRIBUTE_PATH], &path); |
| 3369 | SkMatrix* matrixPtr; |
| 3370 | SkMatrix matrix; |
| 3371 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_MATRIX)) { |
| 3372 | extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); |
| 3373 | matrixPtr = &matrix; |
| 3374 | } |
| 3375 | else { |
| 3376 | matrixPtr = nullptr; |
| 3377 | } |
| 3378 | return new SkDrawTextOnPathCommand(text, strlen(text), path, matrixPtr, paint); |
| 3379 | } |
| 3380 | |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 3381 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 3382 | |
| 3383 | SkDrawTextRSXformCommand::SkDrawTextRSXformCommand(const void* text, size_t byteLength, |
| 3384 | const SkRSXform xform[], const SkRect* cull, |
| 3385 | const SkPaint& paint) |
reed | 63f30d9 | 2016-07-07 16:32:51 -0700 | [diff] [blame] | 3386 | : INHERITED(kDrawTextRSXform_OpType) |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 3387 | { |
| 3388 | fText = new char[byteLength]; |
| 3389 | memcpy(fText, text, byteLength); |
| 3390 | fByteLength = byteLength; |
| 3391 | int count = paint.countText(text, byteLength); |
| 3392 | fXform = new SkRSXform[count]; |
| 3393 | memcpy(fXform, xform, count * sizeof(SkRSXform)); |
| 3394 | if (cull) { |
| 3395 | fCullStorage = *cull; |
| 3396 | fCull = &fCullStorage; |
| 3397 | } else { |
| 3398 | fCull = nullptr; |
| 3399 | } |
| 3400 | fPaint = paint; |
| 3401 | |
| 3402 | fInfo.push(SkObjectParser::TextToString(text, byteLength, paint.getTextEncoding())); |
| 3403 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 3404 | } |
| 3405 | |
| 3406 | void SkDrawTextRSXformCommand::execute(SkCanvas* canvas) const { |
| 3407 | canvas->drawTextRSXform(fText, fByteLength, fXform, fCull, fPaint); |
| 3408 | } |
| 3409 | |
| 3410 | Json::Value SkDrawTextRSXformCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 3411 | Json::Value result = INHERITED::toJSON(urlDataManager); |
| 3412 | result[SKDEBUGCANVAS_ATTRIBUTE_TEXT] = Json::Value((const char*) fText, |
| 3413 | ((const char*) fText) + fByteLength); |
| 3414 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(fPaint, urlDataManager); |
| 3415 | return result; |
| 3416 | } |
| 3417 | |
| 3418 | SkDrawTextRSXformCommand* SkDrawTextRSXformCommand::fromJSON(Json::Value& command, |
| 3419 | UrlDataManager& urlDataManager) { |
| 3420 | const char* text = command[SKDEBUGCANVAS_ATTRIBUTE_TEXT].asCString(); |
| 3421 | size_t byteLength = strlen(text); |
| 3422 | SkPaint paint; |
| 3423 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
| 3424 | |
| 3425 | // TODO: handle xform and cull |
| 3426 | int count = paint.countText(text, byteLength); |
| 3427 | SkAutoTArray<SkRSXform> xform(count); |
| 3428 | for (int i = 0; i < count; ++i) { |
| 3429 | xform[i].fSCos = 1; |
| 3430 | xform[i].fSSin = xform[i].fTx = xform[i].fTy = 0; |
| 3431 | } |
| 3432 | return new SkDrawTextRSXformCommand(text, byteLength, &xform[0], nullptr, paint); |
| 3433 | } |
| 3434 | |
| 3435 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 3436 | |
Mike Reed | fed9cfd | 2017-03-17 12:09:04 -0400 | [diff] [blame] | 3437 | SkDrawVerticesCommand::SkDrawVerticesCommand(sk_sp<SkVertices> vertices, SkBlendMode bmode, |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 3438 | const SkPaint& paint) |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 3439 | : INHERITED(kDrawVertices_OpType) |
Mike Reed | fed9cfd | 2017-03-17 12:09:04 -0400 | [diff] [blame] | 3440 | , fVertices(std::move(vertices)) |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 3441 | , fBlendMode(bmode) |
Mike Reed | fed9cfd | 2017-03-17 12:09:04 -0400 | [diff] [blame] | 3442 | , fPaint(paint) |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 3443 | { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3444 | // TODO(chudy) |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3445 | fInfo.push(SkObjectParser::CustomTextToString("To be implemented.")); |
| 3446 | fInfo.push(SkObjectParser::PaintToString(paint)); |
| 3447 | } |
| 3448 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3449 | void SkDrawVerticesCommand::execute(SkCanvas* canvas) const { |
Mike Reed | fed9cfd | 2017-03-17 12:09:04 -0400 | [diff] [blame] | 3450 | canvas->drawVertices(fVertices, fBlendMode, fPaint); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 3453 | SkRestoreCommand::SkRestoreCommand() |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3454 | : INHERITED(kRestore_OpType) { |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 3455 | fInfo.push(SkObjectParser::CustomTextToString("No Parameters")); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3456 | } |
| 3457 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3458 | void SkRestoreCommand::execute(SkCanvas* canvas) const { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3459 | canvas->restore(); |
| 3460 | } |
| 3461 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3462 | SkRestoreCommand* SkRestoreCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3463 | return new SkRestoreCommand(); |
| 3464 | } |
| 3465 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 3466 | SkSaveCommand::SkSaveCommand() |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3467 | : INHERITED(kSave_OpType) { |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3468 | } |
| 3469 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3470 | void SkSaveCommand::execute(SkCanvas* canvas) const { |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 3471 | canvas->save(); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3474 | SkSaveCommand* SkSaveCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3475 | return new SkSaveCommand(); |
| 3476 | } |
| 3477 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 3478 | SkSaveLayerCommand::SkSaveLayerCommand(const SkCanvas::SaveLayerRec& rec) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3479 | : INHERITED(kSaveLayer_OpType) { |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 3480 | if (rec.fBounds) { |
| 3481 | fBounds = *rec.fBounds; |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 3482 | } else { |
| 3483 | fBounds.setEmpty(); |
| 3484 | } |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3485 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 3486 | if (rec.fPaint) { |
| 3487 | fPaint = *rec.fPaint; |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 3488 | fPaintPtr = &fPaint; |
| 3489 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3490 | fPaintPtr = nullptr; |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 3491 | } |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 3492 | fSaveLayerFlags = rec.fSaveLayerFlags; |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 3493 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3494 | if (rec.fBackdrop) { |
| 3495 | fBackdrop = rec.fBackdrop; |
| 3496 | fBackdrop->ref(); |
| 3497 | } else { |
| 3498 | fBackdrop = nullptr; |
| 3499 | } |
| 3500 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 3501 | if (rec.fBounds) { |
| 3502 | fInfo.push(SkObjectParser::RectToString(*rec.fBounds, "Bounds: ")); |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 3503 | } |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 3504 | if (rec.fPaint) { |
| 3505 | fInfo.push(SkObjectParser::PaintToString(*rec.fPaint)); |
robertphillips@google.com | 24bfdac | 2013-03-22 16:33:31 +0000 | [diff] [blame] | 3506 | } |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 3507 | fInfo.push(SkObjectParser::SaveLayerFlagsToString(fSaveLayerFlags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3508 | } |
| 3509 | |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3510 | SkSaveLayerCommand::~SkSaveLayerCommand() { |
| 3511 | if (fBackdrop != nullptr) { |
| 3512 | fBackdrop->unref(); |
| 3513 | } |
| 3514 | } |
| 3515 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3516 | void SkSaveLayerCommand::execute(SkCanvas* canvas) const { |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 3517 | canvas->saveLayer(SkCanvas::SaveLayerRec(fBounds.isEmpty() ? nullptr : &fBounds, |
| 3518 | fPaintPtr, |
| 3519 | fSaveLayerFlags)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3520 | } |
| 3521 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3522 | void SkSaveLayerCommand::vizExecute(SkCanvas* canvas) const { |
commit-bot@chromium.org | 1643b2c | 2014-03-03 23:25:41 +0000 | [diff] [blame] | 3523 | canvas->save(); |
| 3524 | } |
| 3525 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3526 | Json::Value SkSaveLayerCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 3527 | Json::Value result = INHERITED::toJSON(urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3528 | if (!fBounds.isEmpty()) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3529 | result[SKDEBUGCANVAS_ATTRIBUTE_BOUNDS] = MakeJsonRect(fBounds); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3530 | } |
| 3531 | if (fPaintPtr != nullptr) { |
brianosman | fad9856 | 2016-05-04 11:06:28 -0700 | [diff] [blame] | 3532 | result[SKDEBUGCANVAS_ATTRIBUTE_PAINT] = MakeJsonPaint(*fPaintPtr, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3533 | urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3534 | } |
| 3535 | if (fBackdrop != nullptr) { |
| 3536 | Json::Value jsonBackdrop; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3537 | flatten(fBackdrop, &jsonBackdrop, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3538 | result[SKDEBUGCANVAS_ATTRIBUTE_BACKDROP] = jsonBackdrop; |
| 3539 | } |
| 3540 | if (fSaveLayerFlags != 0) { |
| 3541 | SkDebugf("unsupported: saveLayer flags\n"); |
| 3542 | SkASSERT(false); |
| 3543 | } |
| 3544 | return result; |
| 3545 | } |
| 3546 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3547 | SkSaveLayerCommand* SkSaveLayerCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3548 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3549 | SkCanvas::SaveLayerRec rec; |
| 3550 | SkRect bounds; |
| 3551 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_BOUNDS)) { |
| 3552 | extract_json_rect(command[SKDEBUGCANVAS_ATTRIBUTE_BOUNDS], &bounds); |
| 3553 | rec.fBounds = &bounds; |
| 3554 | } |
| 3555 | SkPaint paint; |
| 3556 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_PAINT)) { |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3557 | extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3558 | rec.fPaint = &paint; |
| 3559 | } |
| 3560 | if (command.isMember(SKDEBUGCANVAS_ATTRIBUTE_BACKDROP)) { |
| 3561 | Json::Value backdrop = command[SKDEBUGCANVAS_ATTRIBUTE_BACKDROP]; |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3562 | rec.fBackdrop = (SkImageFilter*) load_flattenable(backdrop, urlDataManager); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3563 | } |
| 3564 | SkSaveLayerCommand* result = new SkSaveLayerCommand(rec); |
| 3565 | if (rec.fBackdrop != nullptr) { |
| 3566 | rec.fBackdrop->unref(); |
| 3567 | } |
| 3568 | return result; |
| 3569 | } |
| 3570 | |
commit-bot@chromium.org | 57f74e0 | 2014-03-25 23:31:33 +0000 | [diff] [blame] | 3571 | SkSetMatrixCommand::SkSetMatrixCommand(const SkMatrix& matrix) |
robertphillips | 9bafc30 | 2015-02-13 11:13:00 -0800 | [diff] [blame] | 3572 | : INHERITED(kSetMatrix_OpType) { |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 3573 | fUserMatrix.reset(); |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3574 | fMatrix = matrix; |
robertphillips@google.com | 0df2a9a | 2013-03-25 11:50:42 +0000 | [diff] [blame] | 3575 | fInfo.push(SkObjectParser::MatrixToString(matrix)); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3576 | } |
| 3577 | |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 3578 | void SkSetMatrixCommand::setUserMatrix(const SkMatrix& userMatrix) { |
| 3579 | fUserMatrix = userMatrix; |
| 3580 | } |
| 3581 | |
fmalita | 8c89c52 | 2014-11-08 16:18:56 -0800 | [diff] [blame] | 3582 | void SkSetMatrixCommand::execute(SkCanvas* canvas) const { |
robertphillips | 7017168 | 2014-10-16 14:28:28 -0700 | [diff] [blame] | 3583 | SkMatrix temp = SkMatrix::Concat(fUserMatrix, fMatrix); |
| 3584 | canvas->setMatrix(temp); |
chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 3585 | } |
| 3586 | |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3587 | Json::Value SkSetMatrixCommand::toJSON(UrlDataManager& urlDataManager) const { |
| 3588 | Json::Value result = INHERITED::toJSON(urlDataManager); |
joshualitt | bd72413 | 2016-03-03 11:39:38 -0800 | [diff] [blame] | 3589 | result[SKDEBUGCANVAS_ATTRIBUTE_MATRIX] = MakeJsonMatrix(fMatrix); |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3590 | return result; |
| 3591 | } |
| 3592 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 3593 | SkSetMatrixCommand* SkSetMatrixCommand::fromJSON(Json::Value& command, |
ethannicholas | f62a8b7 | 2016-02-11 10:35:21 -0800 | [diff] [blame] | 3594 | UrlDataManager& urlDataManager) { |
ethannicholas | 50a8dd0 | 2016-02-10 05:40:46 -0800 | [diff] [blame] | 3595 | SkMatrix matrix; |
| 3596 | extract_json_matrix(command[SKDEBUGCANVAS_ATTRIBUTE_MATRIX], &matrix); |
| 3597 | return new SkSetMatrixCommand(matrix); |
| 3598 | } |