bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkBitmap.h" |
| 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkColorSpace.h" |
| 12 | #include "include/core/SkImageInfo.h" |
| 13 | #include "include/core/SkPaint.h" |
| 14 | #include "include/core/SkRect.h" |
| 15 | #include "include/core/SkRefCnt.h" |
| 16 | #include "include/core/SkSurface.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 17 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "include/gpu/GrContextOptions.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 19 | #include "include/gpu/GrDirectContext.h" |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 20 | #include "include/private/GrTypesPriv.h" |
| 21 | #include "include/private/SkColorData.h" |
Robert Phillips | d344284 | 2019-08-02 12:26:22 -0400 | [diff] [blame] | 22 | #include "src/core/SkAutoPixmapStorage.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 23 | #include "src/gpu/GrColor.h" |
Robert Phillips | 4b10d58 | 2020-12-02 18:27:18 -0500 | [diff] [blame] | 24 | #include "src/gpu/GrDirectContextPriv.h" |
Brian Salomon | f2ebdd9 | 2019-09-30 12:15:30 -0400 | [diff] [blame] | 25 | #include "src/gpu/GrImageInfo.h" |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 26 | #include "src/gpu/GrSurfaceDrawContext.h" |
Robert Phillips | 4b10d58 | 2020-12-02 18:27:18 -0500 | [diff] [blame] | 27 | #include "src/gpu/ops/GrClearOp.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 28 | #include "tests/Test.h" |
| 29 | #include "tools/gpu/GrContextFactory.h" |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 30 | |
Ben Wagner | 9707a7e | 2019-05-06 17:17:19 -0400 | [diff] [blame] | 31 | #include <cstdint> |
Ben Wagner | b607a8f | 2018-03-12 13:46:21 -0400 | [diff] [blame] | 32 | #include <memory> |
Robert Phillips | dbfecd0 | 2017-10-18 15:44:08 -0400 | [diff] [blame] | 33 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 34 | static bool check_rect(GrDirectContext* dContext, GrSurfaceDrawContext* rtc, const SkIRect& rect, |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 35 | uint32_t expectedValue, uint32_t* actualValue, int* failX, int* failY) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 36 | int w = rect.width(); |
| 37 | int h = rect.height(); |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 38 | |
| 39 | SkImageInfo dstInfo = SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 40 | |
Robert Phillips | d344284 | 2019-08-02 12:26:22 -0400 | [diff] [blame] | 41 | SkAutoPixmapStorage readback; |
| 42 | readback.alloc(dstInfo); |
| 43 | |
| 44 | readback.erase(~expectedValue); |
Brian Salomon | dd4087d | 2020-12-23 20:36:44 -0500 | [diff] [blame] | 45 | if (!rtc->readPixels(dContext, readback, {rect.fLeft, rect.fTop})) { |
Robert Phillips | 301431d | 2017-03-29 12:08:49 -0400 | [diff] [blame] | 46 | return false; |
| 47 | } |
| 48 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 49 | for (int y = 0; y < h; ++y) { |
| 50 | for (int x = 0; x < w; ++x) { |
Robert Phillips | d344284 | 2019-08-02 12:26:22 -0400 | [diff] [blame] | 51 | uint32_t pixel = readback.addr32()[y * w + x]; |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 52 | if (pixel != expectedValue) { |
| 53 | *actualValue = pixel; |
| 54 | *failX = x + rect.fLeft; |
| 55 | *failY = y + rect.fTop; |
| 56 | return false; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | return true; |
| 61 | } |
| 62 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 63 | std::unique_ptr<GrSurfaceDrawContext> newRTC(GrRecordingContext* rContext, int w, int h) { |
| 64 | return GrSurfaceDrawContext::Make( |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 65 | rContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {w, h}); |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 68 | static void clear_op_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 69 | static const int kW = 10; |
| 70 | static const int kH = 10; |
| 71 | |
| 72 | SkIRect fullRect = SkIRect::MakeWH(kW, kH); |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 73 | std::unique_ptr<GrSurfaceDrawContext> rtContext; |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 74 | |
| 75 | // A rectangle that is inset by one on all sides and the 1-pixel wide rectangles that surround |
| 76 | // it. |
| 77 | SkIRect mid1Rect = SkIRect::MakeXYWH(1, 1, kW-2, kH-2); |
| 78 | SkIRect outerLeftEdge = SkIRect::MakeXYWH(0, 0, 1, kH); |
| 79 | SkIRect outerTopEdge = SkIRect::MakeXYWH(0, 0, kW, 1); |
| 80 | SkIRect outerRightEdge = SkIRect::MakeXYWH(kW-1, 0, 1, kH); |
| 81 | SkIRect outerBottomEdge = SkIRect::MakeXYWH(0, kH-1, kW, 1); |
| 82 | |
| 83 | // A rectangle that is inset by two on all sides and the 1-pixel wide rectangles that surround |
| 84 | // it. |
| 85 | SkIRect mid2Rect = SkIRect::MakeXYWH(2, 2, kW-4, kH-4); |
| 86 | SkIRect innerLeftEdge = SkIRect::MakeXYWH(1, 1, 1, kH-2); |
| 87 | SkIRect innerTopEdge = SkIRect::MakeXYWH(1, 1, kW-2, 1); |
| 88 | SkIRect innerRightEdge = SkIRect::MakeXYWH(kW-2, 1, 1, kH-2); |
| 89 | SkIRect innerBottomEdge = SkIRect::MakeXYWH(1, kH-2, kW-2, 1); |
| 90 | |
| 91 | uint32_t actualValue; |
| 92 | int failX, failY; |
| 93 | |
| 94 | static const GrColor kColor1 = 0xABCDEF01; |
| 95 | static const GrColor kColor2 = ~kColor1; |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 96 | static const SkPMColor4f kColor1f = SkPMColor4f::FromBytes_RGBA(kColor1); |
| 97 | static const SkPMColor4f kColor2f = SkPMColor4f::FromBytes_RGBA(kColor2); |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 98 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 99 | rtContext = newRTC(dContext, kW, kH); |
Robert Phillips | e4d45bf | 2017-06-02 14:53:40 -0400 | [diff] [blame] | 100 | SkASSERT(rtContext); |
| 101 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 102 | // Check a full clear |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 103 | rtContext->clear(fullRect, kColor1f); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 104 | if (!check_rect(dContext, rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 105 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, |
| 106 | failX, failY); |
| 107 | } |
| 108 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 109 | rtContext = newRTC(dContext, kW, kH); |
Robert Phillips | e4d45bf | 2017-06-02 14:53:40 -0400 | [diff] [blame] | 110 | SkASSERT(rtContext); |
| 111 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 112 | // Check two full clears, same color |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 113 | rtContext->clear(fullRect, kColor1f); |
| 114 | rtContext->clear(fullRect, kColor1f); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 115 | if (!check_rect(dContext, rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 116 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, |
| 117 | failX, failY); |
| 118 | } |
| 119 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 120 | rtContext = newRTC(dContext, kW, kH); |
Robert Phillips | e4d45bf | 2017-06-02 14:53:40 -0400 | [diff] [blame] | 121 | SkASSERT(rtContext); |
| 122 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 123 | // Check two full clears, different colors |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 124 | rtContext->clear(fullRect, kColor1f); |
| 125 | rtContext->clear(fullRect, kColor2f); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 126 | if (!check_rect(dContext, rtContext.get(), fullRect, kColor2, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 127 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, |
| 128 | failX, failY); |
| 129 | } |
| 130 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 131 | rtContext = newRTC(dContext, kW, kH); |
Robert Phillips | e4d45bf | 2017-06-02 14:53:40 -0400 | [diff] [blame] | 132 | SkASSERT(rtContext); |
| 133 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 134 | // Test a full clear followed by a same color inset clear |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 135 | rtContext->clear(fullRect, kColor1f); |
| 136 | rtContext->clear(mid1Rect, kColor1f); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 137 | if (!check_rect(dContext, rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 138 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, |
| 139 | failX, failY); |
| 140 | } |
| 141 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 142 | rtContext = newRTC(dContext, kW, kH); |
Robert Phillips | e4d45bf | 2017-06-02 14:53:40 -0400 | [diff] [blame] | 143 | SkASSERT(rtContext); |
| 144 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 145 | // Test a inset clear followed by same color full clear |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 146 | rtContext->clear(mid1Rect, kColor1f); |
| 147 | rtContext->clear(fullRect, kColor1f); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 148 | if (!check_rect(dContext, rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 149 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, |
| 150 | failX, failY); |
| 151 | } |
| 152 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 153 | rtContext = newRTC(dContext, kW, kH); |
Robert Phillips | e4d45bf | 2017-06-02 14:53:40 -0400 | [diff] [blame] | 154 | SkASSERT(rtContext); |
| 155 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 156 | // Test a full clear followed by a different color inset clear |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 157 | rtContext->clear(fullRect, kColor1f); |
| 158 | rtContext->clear(mid1Rect, kColor2f); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 159 | if (!check_rect(dContext, rtContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 160 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, |
| 161 | failX, failY); |
| 162 | } |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 163 | if (!check_rect( |
| 164 | dContext, rtContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) || |
| 165 | !check_rect( |
| 166 | dContext, rtContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) || |
| 167 | !check_rect( |
| 168 | dContext, rtContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) || |
| 169 | !check_rect( |
| 170 | dContext, rtContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 171 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, |
| 172 | failX, failY); |
| 173 | } |
| 174 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 175 | rtContext = newRTC(dContext, kW, kH); |
Robert Phillips | e4d45bf | 2017-06-02 14:53:40 -0400 | [diff] [blame] | 176 | SkASSERT(rtContext); |
| 177 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 178 | // Test a inset clear followed by a different full clear |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 179 | rtContext->clear(mid1Rect, kColor2f); |
| 180 | rtContext->clear(fullRect, kColor1f); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 181 | if (!check_rect(dContext, rtContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 182 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, |
| 183 | failX, failY); |
| 184 | } |
| 185 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 186 | rtContext = newRTC(dContext, kW, kH); |
Robert Phillips | e4d45bf | 2017-06-02 14:53:40 -0400 | [diff] [blame] | 187 | SkASSERT(rtContext); |
| 188 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 189 | // Check three nested clears from largest to smallest where outermost and innermost are same |
| 190 | // color. |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 191 | rtContext->clear(fullRect, kColor1f); |
| 192 | rtContext->clear(mid1Rect, kColor2f); |
| 193 | rtContext->clear(mid2Rect, kColor1f); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 194 | if (!check_rect(dContext, rtContext.get(), mid2Rect, kColor1, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 195 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, |
| 196 | failX, failY); |
| 197 | } |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 198 | if (!check_rect( |
| 199 | dContext, rtContext.get(), innerLeftEdge, kColor2, &actualValue, &failX, &failY) || |
| 200 | !check_rect( |
| 201 | dContext, rtContext.get(), innerTopEdge, kColor2, &actualValue, &failX, &failY) || |
| 202 | !check_rect( |
| 203 | dContext, rtContext.get(), innerRightEdge, kColor2, &actualValue, &failX, &failY) || |
| 204 | !check_rect( |
| 205 | dContext, rtContext.get(), innerBottomEdge, kColor2, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 206 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, |
| 207 | failX, failY); |
| 208 | } |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 209 | if (!check_rect( |
| 210 | dContext, rtContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) || |
| 211 | !check_rect( |
| 212 | dContext, rtContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) || |
| 213 | !check_rect( |
| 214 | dContext, rtContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) || |
| 215 | !check_rect( |
| 216 | dContext, rtContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 217 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, |
| 218 | failX, failY); |
| 219 | } |
| 220 | |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 221 | rtContext = newRTC(dContext, kW, kH); |
Robert Phillips | e4d45bf | 2017-06-02 14:53:40 -0400 | [diff] [blame] | 222 | SkASSERT(rtContext); |
| 223 | |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 224 | // Swap the order of the second two clears in the above test. |
Michael Ludwig | 81d4172 | 2020-05-26 16:57:38 -0400 | [diff] [blame] | 225 | rtContext->clear(fullRect, kColor1f); |
| 226 | rtContext->clear(mid2Rect, kColor1f); |
| 227 | rtContext->clear(mid1Rect, kColor2f); |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 228 | if (!check_rect(dContext, rtContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 229 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue, |
| 230 | failX, failY); |
| 231 | } |
Adlai Holler | c95b589 | 2020-08-11 12:02:22 -0400 | [diff] [blame] | 232 | if (!check_rect( |
| 233 | dContext, rtContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) || |
| 234 | !check_rect( |
| 235 | dContext, rtContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) || |
| 236 | !check_rect( |
| 237 | dContext, rtContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) || |
| 238 | !check_rect( |
| 239 | dContext, rtContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 240 | ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue, |
| 241 | failX, failY); |
| 242 | } |
Robert Phillips | 4b10d58 | 2020-12-02 18:27:18 -0500 | [diff] [blame] | 243 | |
| 244 | // Clear calls need to remain ClearOps for the following combining-tests to work as expected |
| 245 | if (!dContext->priv().caps()->performColorClearsAsDraws() && |
| 246 | !dContext->priv().caps()->performStencilClearsAsDraws() && |
| 247 | !dContext->priv().caps()->performPartialClearsAsDraws()) { |
| 248 | static constexpr SkIRect kScissorRect = SkIRect::MakeXYWH(1, 1, kW-1, kH-1); |
| 249 | |
| 250 | // Try combining a pure-color clear w/ a combined stencil & color clear |
| 251 | // (re skbug.com/10963) |
| 252 | { |
| 253 | rtContext = newRTC(dContext, kW, kH); |
| 254 | SkASSERT(rtContext); |
| 255 | |
| 256 | rtContext->clearStencilClip(kScissorRect, true); |
| 257 | // This color clear can combine w/ the preceding stencil clear |
| 258 | rtContext->clear(kScissorRect, SK_PMColor4fWHITE); |
| 259 | |
| 260 | // This should combine w/ the prior combined clear and overwrite the color |
| 261 | rtContext->clear(kScissorRect, SK_PMColor4fBLACK); |
| 262 | |
| 263 | GrOpsTask* ops = rtContext->getOpsTask(); |
| 264 | REPORTER_ASSERT(reporter, ops->numOpChains() == 1); |
| 265 | |
| 266 | const GrClearOp& clearOp = ops->getChain(0)->cast<GrClearOp>(); |
| 267 | |
| 268 | constexpr std::array<float, 4> kExpected { 0, 0, 0, 1 }; |
| 269 | REPORTER_ASSERT(reporter, clearOp.color() == kExpected); |
| 270 | REPORTER_ASSERT(reporter, clearOp.stencilInsideMask()); |
| 271 | |
| 272 | dContext->flushAndSubmit(); |
| 273 | } |
| 274 | |
| 275 | // Try combining a pure-stencil clear w/ a combined stencil & color clear |
| 276 | // (re skbug.com/10963) |
| 277 | { |
| 278 | rtContext = newRTC(dContext, kW, kH); |
| 279 | SkASSERT(rtContext); |
| 280 | |
| 281 | rtContext->clearStencilClip(kScissorRect, true); |
| 282 | // This color clear can combine w/ the preceding stencil clear |
| 283 | rtContext->clear(kScissorRect, SK_PMColor4fWHITE); |
| 284 | |
| 285 | // This should combine w/ the prior combined clear and overwrite the 'insideStencilMask' |
| 286 | // field |
| 287 | rtContext->clearStencilClip(kScissorRect, false); |
| 288 | |
| 289 | GrOpsTask* ops = rtContext->getOpsTask(); |
| 290 | REPORTER_ASSERT(reporter, ops->numOpChains() == 1); |
| 291 | |
| 292 | const GrClearOp& clearOp = ops->getChain(0)->cast<GrClearOp>(); |
| 293 | |
| 294 | constexpr std::array<float, 4> kExpected { 1, 1, 1, 1 }; |
| 295 | REPORTER_ASSERT(reporter, clearOp.color() == kExpected); |
| 296 | REPORTER_ASSERT(reporter, !clearOp.stencilInsideMask()); |
| 297 | |
| 298 | dContext->flushAndSubmit(); |
| 299 | } |
| 300 | } |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 301 | } |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 302 | |
| 303 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearOp, reporter, ctxInfo) { |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 304 | // Regular clear |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 305 | clear_op_test(reporter, ctxInfo.directContext()); |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 306 | |
| 307 | // Force drawing for clears |
| 308 | GrContextOptions options(ctxInfo.options()); |
| 309 | options.fUseDrawInsteadOfClear = GrContextOptions::Enable::kYes; |
| 310 | sk_gpu_test::GrContextFactory workaroundFactory(options); |
| 311 | clear_op_test(reporter, workaroundFactory.get(ctxInfo.type())); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 312 | } |
| 313 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 314 | void fullscreen_clear_with_layer_test(skiatest::Reporter* reporter, GrRecordingContext* rContext) { |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 315 | const SkImageInfo ii = SkImageInfo::Make(400, 77, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
| 316 | |
Robert Phillips | fe4b481 | 2020-07-17 14:15:51 -0400 | [diff] [blame] | 317 | sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(rContext, SkBudgeted::kYes, ii); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 318 | SkCanvas* canvas = surf->getCanvas(); |
| 319 | |
| 320 | SkPaint paints[2]; |
| 321 | paints[0].setColor(SK_ColorGREEN); |
| 322 | paints[1].setColor(SK_ColorGRAY); |
| 323 | |
| 324 | static const int kLeftX = 158; |
| 325 | static const int kMidX = 258; |
| 326 | static const int kRightX = 383; |
| 327 | static const int kTopY = 26; |
| 328 | static const int kBotY = 51; |
| 329 | |
| 330 | const SkRect rects[2] = { |
| 331 | { kLeftX, kTopY, kMidX, kBotY }, |
| 332 | { kMidX, kTopY, kRightX, kBotY }, |
| 333 | }; |
| 334 | |
| 335 | for (int i = 0; i < 2; ++i) { |
| 336 | // the bounds parameter is required to cause a full screen clear |
| 337 | canvas->saveLayer(&rects[i], nullptr); |
| 338 | canvas->drawRect(rects[i], paints[i]); |
| 339 | canvas->restore(); |
| 340 | } |
| 341 | |
| 342 | SkBitmap bm; |
| 343 | bm.allocPixels(ii, 0); |
| 344 | |
| 345 | SkAssertResult(surf->readPixels(bm, 0, 0)); |
| 346 | |
| 347 | bool isCorrect = true; |
| 348 | for (int y = kTopY; isCorrect && y < kBotY; ++y) { |
| 349 | const uint32_t* sl = bm.getAddr32(0, y); |
| 350 | |
| 351 | for (int x = kLeftX; x < kMidX; ++x) { |
| 352 | if (SK_ColorGREEN != sl[x]) { |
| 353 | isCorrect = false; |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | for (int x = kMidX; x < kRightX; ++x) { |
| 359 | if (SK_ColorGRAY != sl[x]) { |
| 360 | isCorrect = false; |
| 361 | break; |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | REPORTER_ASSERT(reporter, isCorrect); |
| 367 | } |
| 368 | // From crbug.com/768134 |
| 369 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FullScreenClearWithLayers, reporter, ctxInfo) { |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 370 | // Regular clear |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 371 | fullscreen_clear_with_layer_test(reporter, ctxInfo.directContext()); |
Michael Ludwig | a21d196 | 2019-01-11 15:26:22 -0500 | [diff] [blame] | 372 | |
| 373 | // Use draws for clears |
| 374 | GrContextOptions options(ctxInfo.options()); |
| 375 | options.fUseDrawInsteadOfClear = GrContextOptions::Enable::kYes; |
| 376 | sk_gpu_test::GrContextFactory workaroundFactory(options); |
| 377 | fullscreen_clear_with_layer_test(reporter, workaroundFactory.get(ctxInfo.type())); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 378 | } |