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