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