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