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