fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
Anas AlJabri | 84dd183 | 2018-07-31 15:53:05 -0700 | [diff] [blame] | 8 | #define ABORT_TEST(r, cond, ...) \ |
| 9 | do { \ |
| 10 | if (cond) { \ |
| 11 | REPORT_FAILURE(r, #cond, SkStringPrintf(__VA_ARGS__)); \ |
| 12 | return; \ |
| 13 | } \ |
| 14 | } while (0) |
| 15 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/core/SkBitmap.h" |
| 17 | #include "include/core/SkCanvas.h" |
| 18 | #include "include/core/SkColorFilter.h" |
| 19 | #include "include/core/SkData.h" |
| 20 | #include "include/core/SkImage.h" |
| 21 | #include "include/core/SkShader.h" |
| 22 | #include "include/core/SkStream.h" |
| 23 | #include "include/private/SkTo.h" |
| 24 | #include "include/utils/SkParse.h" |
| 25 | #include "src/core/SkMakeUnique.h" |
| 26 | #include "src/shaders/SkImageShader.h" |
| 27 | #include "tests/Test.h" |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 28 | |
| 29 | #include <string.h> |
| 30 | |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 31 | #ifdef SK_XML |
| 32 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 33 | #include "src/svg/SkSVGDevice.h" |
| 34 | #include "src/xml/SkDOM.h" |
| 35 | #include "src/xml/SkXMLWriter.h" |
Ben Wagner | 6ce482a | 2018-03-27 10:57:43 -0400 | [diff] [blame] | 36 | |
Florin Malita | 562017b | 2019-02-14 13:42:15 -0500 | [diff] [blame] | 37 | static std::unique_ptr<SkCanvas> MakeDOMCanvas(SkDOM* dom) { |
| 38 | auto svgDevice = SkSVGDevice::Make(SkISize::Make(100, 100), |
| 39 | skstd::make_unique<SkXMLParserWriter>(dom->beginParsing())); |
| 40 | return svgDevice ? skstd::make_unique<SkCanvas>(svgDevice) |
| 41 | : nullptr; |
| 42 | } |
| 43 | |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 44 | #if 0 |
| 45 | Using the new system where devices only gets glyphs causes this to fail because the font has no |
| 46 | glyph to unichar data. |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 47 | namespace { |
| 48 | |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 49 | |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 50 | void check_text_node(skiatest::Reporter* reporter, |
| 51 | const SkDOM& dom, |
| 52 | const SkDOM::Node* root, |
| 53 | const SkPoint& offset, |
| 54 | unsigned scalarsPerPos, |
| 55 | const char* expected) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 56 | if (root == nullptr) { |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 57 | ERRORF(reporter, "root element not found."); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | const SkDOM::Node* textElem = dom.getFirstChild(root, "text"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 62 | if (textElem == nullptr) { |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 63 | ERRORF(reporter, "<text> element not found."); |
| 64 | return; |
| 65 | } |
| 66 | REPORTER_ASSERT(reporter, dom.getType(textElem) == SkDOM::kElement_Type); |
| 67 | |
| 68 | const SkDOM::Node* textNode= dom.getFirstChild(textElem); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 69 | REPORTER_ASSERT(reporter, textNode != nullptr); |
| 70 | if (textNode != nullptr) { |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 71 | REPORTER_ASSERT(reporter, dom.getType(textNode) == SkDOM::kText_Type); |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 72 | if (strcmp(expected, dom.getName(textNode)) != 0) { |
| 73 | SkDebugf("string fail %s == %s\n", expected, dom.getName(textNode)); |
| 74 | } |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 75 | REPORTER_ASSERT(reporter, strcmp(expected, dom.getName(textNode)) == 0); |
| 76 | } |
| 77 | |
| 78 | int textLen = SkToInt(strlen(expected)); |
| 79 | |
| 80 | const char* x = dom.findAttr(textElem, "x"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 81 | REPORTER_ASSERT(reporter, x != nullptr); |
| 82 | if (x != nullptr) { |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 83 | int xposCount = (scalarsPerPos < 1) ? 1 : textLen; |
| 84 | REPORTER_ASSERT(reporter, SkParse::Count(x) == xposCount); |
| 85 | |
| 86 | SkAutoTMalloc<SkScalar> xpos(xposCount); |
| 87 | SkParse::FindScalars(x, xpos.get(), xposCount); |
| 88 | if (scalarsPerPos < 1) { |
| 89 | REPORTER_ASSERT(reporter, xpos[0] == offset.x()); |
| 90 | } else { |
| 91 | for (int i = 0; i < xposCount; ++i) { |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 92 | if (xpos[i] != SkIntToScalar(expected[i])) { |
| 93 | SkDebugf("Bad xs %g == %g\n", xpos[i], SkIntToScalar(expected[i])); |
| 94 | } |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 95 | REPORTER_ASSERT(reporter, xpos[i] == SkIntToScalar(expected[i])); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | const char* y = dom.findAttr(textElem, "y"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 101 | REPORTER_ASSERT(reporter, y != nullptr); |
| 102 | if (y != nullptr) { |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 103 | int yposCount = (scalarsPerPos < 2) ? 1 : textLen; |
| 104 | REPORTER_ASSERT(reporter, SkParse::Count(y) == yposCount); |
| 105 | |
| 106 | SkAutoTMalloc<SkScalar> ypos(yposCount); |
| 107 | SkParse::FindScalars(y, ypos.get(), yposCount); |
| 108 | if (scalarsPerPos < 2) { |
| 109 | REPORTER_ASSERT(reporter, ypos[0] == offset.y()); |
| 110 | } else { |
| 111 | for (int i = 0; i < yposCount; ++i) { |
| 112 | REPORTER_ASSERT(reporter, ypos[i] == -SkIntToScalar(expected[i])); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | void test_whitespace_pos(skiatest::Reporter* reporter, |
| 119 | const char* txt, |
| 120 | const char* expected) { |
| 121 | size_t len = strlen(txt); |
| 122 | |
| 123 | SkDOM dom; |
| 124 | SkPaint paint; |
Mike Reed | 212e906 | 2018-12-25 17:35:49 -0500 | [diff] [blame] | 125 | SkFont font; |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 126 | SkPoint offset = SkPoint::Make(10, 20); |
| 127 | |
| 128 | { |
Florin Malita | 562017b | 2019-02-14 13:42:15 -0500 | [diff] [blame] | 129 | auto svgCanvas = MakeDOMCanvas(&dom); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 130 | svgCanvas->drawSimpleText(txt, len, SkTextEncoding::kUTF8, offset.x(), offset.y(), |
Mike Reed | 212e906 | 2018-12-25 17:35:49 -0500 | [diff] [blame] | 131 | font, paint); |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 132 | } |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 133 | check_text_node(reporter, dom, dom.finishParsing(), offset, 2, expected); |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 134 | |
| 135 | { |
| 136 | SkAutoTMalloc<SkScalar> xpos(len); |
| 137 | for (int i = 0; i < SkToInt(len); ++i) { |
| 138 | xpos[i] = SkIntToScalar(txt[i]); |
| 139 | } |
| 140 | |
Florin Malita | 562017b | 2019-02-14 13:42:15 -0500 | [diff] [blame] | 141 | auto svgCanvas = MakeDOMCanvas(&dom); |
Mike Reed | 212e906 | 2018-12-25 17:35:49 -0500 | [diff] [blame] | 142 | auto blob = SkTextBlob::MakeFromPosTextH(txt, len, &xpos[0], offset.y(), font); |
| 143 | svgCanvas->drawTextBlob(blob, 0, 0, paint); |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 144 | } |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 145 | check_text_node(reporter, dom, dom.finishParsing(), offset, 2, expected); |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 146 | |
| 147 | { |
| 148 | SkAutoTMalloc<SkPoint> pos(len); |
| 149 | for (int i = 0; i < SkToInt(len); ++i) { |
| 150 | pos[i] = SkPoint::Make(SkIntToScalar(txt[i]), -SkIntToScalar(txt[i])); |
| 151 | } |
| 152 | |
| 153 | SkXMLParserWriter writer(dom.beginParsing()); |
Mike Reed | 212e906 | 2018-12-25 17:35:49 -0500 | [diff] [blame] | 154 | auto blob = SkTextBlob::MakeFromPosTextH(txt, len, &pos[0], font); |
| 155 | svgCanvas->drawTextBlob(blob, 0, 0, paint); |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 156 | } |
| 157 | check_text_node(reporter, dom, dom.finishParsing(), offset, 2, expected); |
| 158 | } |
| 159 | |
| 160 | } |
| 161 | |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 162 | |
fmalita | 7a04869 | 2015-02-20 13:54:40 -0800 | [diff] [blame] | 163 | DEF_TEST(SVGDevice_whitespace_pos, reporter) { |
| 164 | static const struct { |
| 165 | const char* tst_in; |
| 166 | const char* tst_out; |
| 167 | } tests[] = { |
| 168 | { "abcd" , "abcd" }, |
| 169 | { "ab cd" , "ab cd" }, |
| 170 | { "ab \t\t cd", "ab cd" }, |
| 171 | { " abcd" , "abcd" }, |
| 172 | { " abcd" , "abcd" }, |
| 173 | { " \t\t abcd", "abcd" }, |
| 174 | { "abcd " , "abcd " }, // we allow one trailing whitespace char |
| 175 | { "abcd " , "abcd " }, // because it makes no difference and |
| 176 | { "abcd\t " , "abcd\t" }, // simplifies the implementation |
| 177 | { "\t\t \t ab \t\t \t cd \t\t \t ", "ab cd " }, |
| 178 | }; |
| 179 | |
| 180 | for (unsigned i = 0; i < SK_ARRAY_COUNT(tests); ++i) { |
| 181 | test_whitespace_pos(reporter, tests[i].tst_in, tests[i].tst_out); |
| 182 | } |
| 183 | } |
Herb Derby | 41f4f31 | 2018-06-06 17:45:53 +0000 | [diff] [blame] | 184 | #endif |
Hal Canary | ff2742e | 2018-01-30 11:35:47 -0500 | [diff] [blame] | 185 | |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 186 | |
Mike Reed | e25b447 | 2019-04-02 17:49:12 -0400 | [diff] [blame] | 187 | void SetImageShader(SkPaint* paint, int imageWidth, int imageHeight, SkTileMode xTile, |
| 188 | SkTileMode yTile) { |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 189 | auto surface = SkSurface::MakeRasterN32Premul(imageWidth, imageHeight); |
Mike Reed | e25b447 | 2019-04-02 17:49:12 -0400 | [diff] [blame] | 190 | paint->setShader(surface->makeImageSnapshot()->makeShader(xTile, yTile, nullptr)); |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | // Attempt to find the three nodes on which we have expectations: |
| 194 | // the pattern node, the image within that pattern, and the rect which |
| 195 | // uses the pattern as a fill. |
| 196 | // returns false if not all nodes are found. |
| 197 | bool FindImageShaderNodes(skiatest::Reporter* reporter, const SkDOM* dom, const SkDOM::Node* root, |
| 198 | const SkDOM::Node** patternOut, const SkDOM::Node** imageOut, |
| 199 | const SkDOM::Node** rectOut) { |
| 200 | if (root == nullptr || dom == nullptr) { |
| 201 | ERRORF(reporter, "root element not found"); |
| 202 | return false; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | const SkDOM::Node* rect = dom->getFirstChild(root, "rect"); |
| 207 | if (rect == nullptr) { |
| 208 | ERRORF(reporter, "rect not found"); |
| 209 | return false; |
| 210 | } |
| 211 | *rectOut = rect; |
| 212 | |
| 213 | const SkDOM::Node* defs = dom->getFirstChild(root, "defs"); |
| 214 | if (defs == nullptr) { |
| 215 | ERRORF(reporter, "defs not found"); |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | const SkDOM::Node* pattern = dom->getFirstChild(defs, "pattern"); |
| 220 | if (pattern == nullptr) { |
| 221 | ERRORF(reporter, "pattern not found"); |
| 222 | return false; |
| 223 | } |
| 224 | *patternOut = pattern; |
| 225 | |
| 226 | const SkDOM::Node* image = dom->getFirstChild(pattern, "image"); |
| 227 | if (image == nullptr) { |
| 228 | ERRORF(reporter, "image not found"); |
| 229 | return false; |
| 230 | } |
| 231 | *imageOut = image; |
| 232 | |
| 233 | return true; |
| 234 | } |
| 235 | |
| 236 | void ImageShaderTestSetup(SkDOM* dom, SkPaint* paint, int imageWidth, int imageHeight, |
Mike Reed | e25b447 | 2019-04-02 17:49:12 -0400 | [diff] [blame] | 237 | int rectWidth, int rectHeight, SkTileMode xTile, SkTileMode yTile) { |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 238 | SetImageShader(paint, imageWidth, imageHeight, xTile, yTile); |
Florin Malita | 562017b | 2019-02-14 13:42:15 -0500 | [diff] [blame] | 239 | auto svgCanvas = MakeDOMCanvas(dom); |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 240 | |
| 241 | SkRect bounds{0, 0, SkIntToScalar(rectWidth), SkIntToScalar(rectHeight)}; |
| 242 | svgCanvas->drawRect(bounds, *paint); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | DEF_TEST(SVGDevice_image_shader_norepeat, reporter) { |
| 247 | SkDOM dom; |
| 248 | SkPaint paint; |
| 249 | int imageWidth = 3, imageHeight = 3; |
| 250 | int rectWidth = 10, rectHeight = 10; |
| 251 | ImageShaderTestSetup(&dom, &paint, imageWidth, imageHeight, rectWidth, rectHeight, |
Mike Reed | e25b447 | 2019-04-02 17:49:12 -0400 | [diff] [blame] | 252 | SkTileMode::kClamp, SkTileMode::kClamp); |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 253 | |
| 254 | const SkDOM::Node* root = dom.finishParsing(); |
| 255 | |
| 256 | const SkDOM::Node *patternNode, *imageNode, *rectNode; |
| 257 | bool structureAppropriate = |
| 258 | FindImageShaderNodes(reporter, &dom, root, &patternNode, &imageNode, &rectNode); |
| 259 | REPORTER_ASSERT(reporter, structureAppropriate); |
| 260 | |
| 261 | // the image should always maintain its size. |
| 262 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageWidth); |
| 263 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageHeight); |
| 264 | |
| 265 | // making the pattern as large as the container prevents |
| 266 | // it from repeating. |
| 267 | REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "width"), "100%") == 0); |
| 268 | REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "height"), "100%") == 0); |
| 269 | } |
| 270 | |
| 271 | DEF_TEST(SVGDevice_image_shader_tilex, reporter) { |
| 272 | SkDOM dom; |
| 273 | SkPaint paint; |
| 274 | int imageWidth = 3, imageHeight = 3; |
| 275 | int rectWidth = 10, rectHeight = 10; |
| 276 | ImageShaderTestSetup(&dom, &paint, imageWidth, imageHeight, rectWidth, rectHeight, |
Mike Reed | e25b447 | 2019-04-02 17:49:12 -0400 | [diff] [blame] | 277 | SkTileMode::kRepeat, SkTileMode::kClamp); |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 278 | |
| 279 | const SkDOM::Node* root = dom.finishParsing(); |
| 280 | const SkDOM::Node* innerSvg = dom.getFirstChild(root, "svg"); |
| 281 | if (innerSvg == nullptr) { |
| 282 | ERRORF(reporter, "inner svg element not found"); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | const SkDOM::Node *patternNode, *imageNode, *rectNode; |
| 287 | bool structureAppropriate = |
| 288 | FindImageShaderNodes(reporter, &dom, innerSvg, &patternNode, &imageNode, &rectNode); |
| 289 | REPORTER_ASSERT(reporter, structureAppropriate); |
| 290 | |
| 291 | // the imageNode should always maintain its size. |
| 292 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageWidth); |
| 293 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageHeight); |
| 294 | |
| 295 | // if the patternNode width matches the imageNode width, |
| 296 | // it will repeat in along the x axis. |
| 297 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "width")) == imageWidth); |
| 298 | REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "height"), "100%") == 0); |
| 299 | } |
| 300 | |
| 301 | DEF_TEST(SVGDevice_image_shader_tiley, reporter) { |
| 302 | SkDOM dom; |
| 303 | SkPaint paint; |
| 304 | int imageNodeWidth = 3, imageNodeHeight = 3; |
| 305 | int rectNodeWidth = 10, rectNodeHeight = 10; |
| 306 | ImageShaderTestSetup(&dom, &paint, imageNodeWidth, imageNodeHeight, rectNodeWidth, |
Mike Reed | e25b447 | 2019-04-02 17:49:12 -0400 | [diff] [blame] | 307 | rectNodeHeight, SkTileMode::kClamp, SkTileMode::kRepeat); |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 308 | |
| 309 | const SkDOM::Node* root = dom.finishParsing(); |
| 310 | const SkDOM::Node* innerSvg = dom.getFirstChild(root, "svg"); |
| 311 | if (innerSvg == nullptr) { |
| 312 | ERRORF(reporter, "inner svg element not found"); |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | const SkDOM::Node *patternNode, *imageNode, *rectNode; |
| 317 | bool structureAppropriate = |
| 318 | FindImageShaderNodes(reporter, &dom, innerSvg, &patternNode, &imageNode, &rectNode); |
| 319 | REPORTER_ASSERT(reporter, structureAppropriate); |
| 320 | |
| 321 | // the imageNode should always maintain its size. |
| 322 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageNodeWidth); |
| 323 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageNodeHeight); |
| 324 | |
| 325 | // making the patternNode as large as the container prevents |
| 326 | // it from repeating. |
| 327 | REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "width"), "100%") == 0); |
| 328 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "height")) == imageNodeHeight); |
| 329 | } |
| 330 | |
| 331 | DEF_TEST(SVGDevice_image_shader_tileboth, reporter) { |
| 332 | SkDOM dom; |
| 333 | SkPaint paint; |
| 334 | int imageWidth = 3, imageHeight = 3; |
| 335 | int rectWidth = 10, rectHeight = 10; |
| 336 | ImageShaderTestSetup(&dom, &paint, imageWidth, imageHeight, rectWidth, rectHeight, |
Mike Reed | e25b447 | 2019-04-02 17:49:12 -0400 | [diff] [blame] | 337 | SkTileMode::kRepeat, SkTileMode::kRepeat); |
Alexander Midlash | 77e3afc | 2018-03-06 17:21:28 -0800 | [diff] [blame] | 338 | |
| 339 | const SkDOM::Node* root = dom.finishParsing(); |
| 340 | |
| 341 | const SkDOM::Node *patternNode, *imageNode, *rectNode; |
| 342 | const SkDOM::Node* innerSvg = dom.getFirstChild(root, "svg"); |
| 343 | if (innerSvg == nullptr) { |
| 344 | ERRORF(reporter, "inner svg element not found"); |
| 345 | return; |
| 346 | } |
| 347 | bool structureAppropriate = |
| 348 | FindImageShaderNodes(reporter, &dom, innerSvg, &patternNode, &imageNode, &rectNode); |
| 349 | REPORTER_ASSERT(reporter, structureAppropriate); |
| 350 | |
| 351 | // the imageNode should always maintain its size. |
| 352 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageWidth); |
| 353 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageHeight); |
| 354 | |
| 355 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "width")) == imageWidth); |
| 356 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "height")) == imageHeight); |
| 357 | } |
| 358 | |
Anas AlJabri | 84dd183 | 2018-07-31 15:53:05 -0700 | [diff] [blame] | 359 | DEF_TEST(SVGDevice_ColorFilters, reporter) { |
| 360 | SkDOM dom; |
| 361 | SkPaint paint; |
Mike Reed | b286bc2 | 2019-04-08 16:23:20 -0400 | [diff] [blame] | 362 | paint.setColorFilter(SkColorFilters::Blend(SK_ColorRED, SkBlendMode::kSrcIn)); |
Anas AlJabri | 84dd183 | 2018-07-31 15:53:05 -0700 | [diff] [blame] | 363 | { |
Florin Malita | 562017b | 2019-02-14 13:42:15 -0500 | [diff] [blame] | 364 | auto svgCanvas = MakeDOMCanvas(&dom); |
Anas AlJabri | 84dd183 | 2018-07-31 15:53:05 -0700 | [diff] [blame] | 365 | SkRect bounds{0, 0, SkIntToScalar(100), SkIntToScalar(100)}; |
| 366 | svgCanvas->drawRect(bounds, paint); |
| 367 | } |
| 368 | const SkDOM::Node* rootElement = dom.finishParsing(); |
| 369 | ABORT_TEST(reporter, !rootElement, "root element not found"); |
| 370 | |
| 371 | const SkDOM::Node* filterElement = dom.getFirstChild(rootElement, "filter"); |
| 372 | ABORT_TEST(reporter, !filterElement, "filter element not found"); |
| 373 | |
| 374 | const SkDOM::Node* floodElement = dom.getFirstChild(filterElement, "feFlood"); |
| 375 | ABORT_TEST(reporter, !floodElement, "feFlood element not found"); |
| 376 | |
| 377 | const SkDOM::Node* compositeElement = dom.getFirstChild(filterElement, "feComposite"); |
| 378 | ABORT_TEST(reporter, !compositeElement, "feComposite element not found"); |
| 379 | |
| 380 | REPORTER_ASSERT(reporter, strcmp(dom.findAttr(filterElement, "width"), "100%") == 0); |
| 381 | REPORTER_ASSERT(reporter, strcmp(dom.findAttr(filterElement, "height"), "100%") == 0); |
| 382 | |
| 383 | REPORTER_ASSERT(reporter, |
| 384 | strcmp(dom.findAttr(floodElement, "flood-color"), "rgb(255,0,0)") == 0); |
| 385 | REPORTER_ASSERT(reporter, atoi(dom.findAttr(floodElement, "flood-opacity")) == 1); |
| 386 | |
| 387 | REPORTER_ASSERT(reporter, strcmp(dom.findAttr(compositeElement, "in"), "flood") == 0); |
| 388 | REPORTER_ASSERT(reporter, strcmp(dom.findAttr(compositeElement, "operator"), "in") == 0); |
| 389 | } |
| 390 | |
Hal Canary | ff2742e | 2018-01-30 11:35:47 -0500 | [diff] [blame] | 391 | #endif |