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