| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <initializer_list> | 8 #include <initializer_list> |
| 9 #include <functional> | 9 #include <functional> |
| 10 #include "Test.h" | 10 #include "Test.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 return true; | 30 return true; |
| 31 } | 31 } |
| 32 | 32 |
| 33 static bool paths_fill_same(const SkPath& a, const SkPath& b) { | 33 static bool paths_fill_same(const SkPath& a, const SkPath& b) { |
| 34 SkPath pathXor; | 34 SkPath pathXor; |
| 35 Op(a, b, SkPathOp::kXOR_SkPathOp, &pathXor); | 35 Op(a, b, SkPathOp::kXOR_SkPathOp, &pathXor); |
| 36 return pathXor.isEmpty(); | 36 return pathXor.isEmpty(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 static bool test_bounds_by_rasterizing(const SkPath& path, const SkRect& bounds)
{ | 39 static bool test_bounds_by_rasterizing(const SkPath& path, const SkRect& bounds)
{ |
| 40 // We test the bounds by rasterizing the path into a kRes by kRes grid. The
bounds is |
| 41 // mapped to the range kRes/4 to 3*kRes/4 in x and y. A difference clip is u
sed to avoid |
| 42 // rendering within the bounds (with a tolerance). Then we render the path a
nd check that |
| 43 // everything got clipped out. |
| 40 static constexpr int kRes = 2000; | 44 static constexpr int kRes = 2000; |
| 41 // This tolerance is in units of 1/kRes fractions of the bounds width/height
. | 45 // This tolerance is in units of 1/kRes fractions of the bounds width/height
. |
| 42 static constexpr int kTol = 0; | 46 static constexpr int kTol = 0; |
| 43 GR_STATIC_ASSERT(kRes % 4 == 0); | 47 GR_STATIC_ASSERT(kRes % 4 == 0); |
| 44 SkImageInfo info = SkImageInfo::MakeA8(kRes, kRes); | 48 SkImageInfo info = SkImageInfo::MakeA8(kRes, kRes); |
| 45 sk_sp<SkSurface> surface = SkSurface::MakeRaster(info); | 49 sk_sp<SkSurface> surface = SkSurface::MakeRaster(info); |
| 46 surface->getCanvas()->clear(0x0); | 50 surface->getCanvas()->clear(0x0); |
| 47 SkRect clip = SkRect::MakeXYWH(kRes/4, kRes/4, kRes/2, kRes/2); | 51 SkRect clip = SkRect::MakeXYWH(kRes/4, kRes/4, kRes/2, kRes/2); |
| 48 SkMatrix matrix; | 52 SkMatrix matrix; |
| 49 matrix.setRectToRect(bounds, clip, SkMatrix::kFill_ScaleToFit); | 53 matrix.setRectToRect(bounds, clip, SkMatrix::kFill_ScaleToFit); |
| 50 clip.outset(SkIntToScalar(kTol), SkIntToScalar(kTol)); | 54 clip.outset(SkIntToScalar(kTol), SkIntToScalar(kTol)); |
| 51 surface->getCanvas()->clipRect(clip, SkRegion::kDifference_Op); | 55 surface->getCanvas()->clipRect(clip, SkRegion::kDifference_Op); |
| 52 surface->getCanvas()->concat(matrix); | 56 surface->getCanvas()->concat(matrix); |
| 53 SkPaint whitePaint; | 57 SkPaint whitePaint; |
| 54 whitePaint.setColor(SK_ColorWHITE); | 58 whitePaint.setColor(SK_ColorWHITE); |
| 55 surface->getCanvas()->drawPath(path, whitePaint); | 59 surface->getCanvas()->drawPath(path, whitePaint); |
| 56 SkPixmap pixmap; | 60 SkPixmap pixmap; |
| 57 surface->getCanvas()->peekPixels(&pixmap); | 61 surface->getCanvas()->peekPixels(&pixmap); |
| 58 #if defined(SK_BUILD_FOR_WIN) | 62 #if defined(SK_BUILD_FOR_WIN) |
| 59 // The static constexpr version in #else causes cl.exe to crash. | 63 // The static constexpr version in #else causes cl.exe to crash. |
| 60 const uint8_t* kZeros = reinterpret_cast<uint8_t*>(calloc(kRes, 1)); | 64 const uint8_t* kZeros = reinterpret_cast<uint8_t*>(calloc(kRes, 1)); |
| 61 #else | 65 #else |
| 62 static constexpr uint8_t kZeros[kRes] = {0}; | 66 static constexpr uint8_t kZeros[kRes] = {0}; |
| 63 #endif | 67 #endif |
| 64 for (int y = 0; y < kRes/4; ++y) { | 68 for (int y = 0; y < kRes; ++y) { |
| 65 const uint8_t* row = pixmap.addr8(0, y); | 69 const uint8_t* row = pixmap.addr8(0, y); |
| 66 if (0 != memcmp(kZeros, row, kRes)) { | 70 if (0 != memcmp(kZeros, row, kRes)) { |
| 67 return false; | 71 return false; |
| 68 } | 72 } |
| 69 } | 73 } |
| 70 #ifdef SK_BUILD_FOR_WIN | 74 #ifdef SK_BUILD_FOR_WIN |
| 71 free(const_cast<uint8_t*>(kZeros)); | 75 free(const_cast<uint8_t*>(kZeros)); |
| 72 #endif | 76 #endif |
| 73 return true; | 77 return true; |
| 74 } | 78 } |
| (...skipping 1811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1886 test_volatile_path(reporter, PathGeo(SkPath(), PathGeo::Invert::kNo)); | 1890 test_volatile_path(reporter, PathGeo(SkPath(), PathGeo::Invert::kNo)); |
| 1887 | 1891 |
| 1888 test_empty_shape(reporter); | 1892 test_empty_shape(reporter); |
| 1889 | 1893 |
| 1890 test_lines(reporter); | 1894 test_lines(reporter); |
| 1891 | 1895 |
| 1892 test_stroked_lines(reporter); | 1896 test_stroked_lines(reporter); |
| 1893 } | 1897 } |
| 1894 | 1898 |
| 1895 #endif | 1899 #endif |
| OLD | NEW |