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