2016-02-05 15:17:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkColorSpace.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContextOptions.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-05-06 21:17:19 +00:00
|
|
|
#include "include/private/GrTypesPriv.h"
|
|
|
|
#include "include/private/SkColorData.h"
|
2019-08-02 16:26:22 +00:00
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrColor.h"
|
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/ganesh/GrImageInfo.h"
|
|
|
|
#include "src/gpu/ganesh/ops/ClearOp.h"
|
|
|
|
#include "src/gpu/ganesh/v1/SurfaceDrawContext_v1.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2018-03-12 17:46:21 +00:00
|
|
|
|
2019-05-06 21:17:19 +00:00
|
|
|
#include <cstdint>
|
2018-03-12 17:46:21 +00:00
|
|
|
#include <memory>
|
2017-10-18 19:44:08 +00:00
|
|
|
|
2021-09-01 17:02:28 +00:00
|
|
|
using SurfaceDrawContext = skgpu::v1::SurfaceDrawContext;
|
|
|
|
using ClearOp = skgpu::v1::ClearOp;
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
static bool check_rect(GrDirectContext* dContext,
|
2021-09-01 17:02:28 +00:00
|
|
|
SurfaceDrawContext* sdc,
|
2021-07-28 19:13:20 +00:00
|
|
|
const SkIRect& rect,
|
|
|
|
uint32_t expectedValue,
|
|
|
|
uint32_t* actualValue,
|
|
|
|
int* failX,
|
|
|
|
int* failY) {
|
2016-02-05 15:17:34 +00:00
|
|
|
int w = rect.width();
|
|
|
|
int h = rect.height();
|
2017-03-29 16:08:49 +00:00
|
|
|
|
|
|
|
SkImageInfo dstInfo = SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
2019-08-02 16:26:22 +00:00
|
|
|
SkAutoPixmapStorage readback;
|
|
|
|
readback.alloc(dstInfo);
|
|
|
|
|
|
|
|
readback.erase(~expectedValue);
|
2021-07-28 19:13:20 +00:00
|
|
|
if (!sdc->readPixels(dContext, readback, {rect.fLeft, rect.fTop})) {
|
2017-03-29 16:08:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
for (int x = 0; x < w; ++x) {
|
2019-08-02 16:26:22 +00:00
|
|
|
uint32_t pixel = readback.addr32()[y * w + x];
|
2016-02-05 15:17:34 +00:00
|
|
|
if (pixel != expectedValue) {
|
|
|
|
*actualValue = pixel;
|
|
|
|
*failX = x + rect.fLeft;
|
|
|
|
*failY = y + rect.fTop;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-01 17:02:28 +00:00
|
|
|
std::unique_ptr<SurfaceDrawContext> newSDC(GrRecordingContext* rContext, int w, int h) {
|
|
|
|
return SurfaceDrawContext::Make(rContext, GrColorType::kRGBA_8888, nullptr,
|
|
|
|
SkBackingFit::kExact, {w, h}, SkSurfaceProps());
|
2016-02-05 15:17:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 16:02:22 +00:00
|
|
|
static void clear_op_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
|
2016-02-05 15:17:34 +00:00
|
|
|
static const int kW = 10;
|
|
|
|
static const int kH = 10;
|
|
|
|
|
|
|
|
SkIRect fullRect = SkIRect::MakeWH(kW, kH);
|
2021-09-01 17:02:28 +00:00
|
|
|
std::unique_ptr<SurfaceDrawContext> sdc;
|
2016-02-05 15:17:34 +00:00
|
|
|
|
|
|
|
// A rectangle that is inset by one on all sides and the 1-pixel wide rectangles that surround
|
|
|
|
// it.
|
|
|
|
SkIRect mid1Rect = SkIRect::MakeXYWH(1, 1, kW-2, kH-2);
|
|
|
|
SkIRect outerLeftEdge = SkIRect::MakeXYWH(0, 0, 1, kH);
|
|
|
|
SkIRect outerTopEdge = SkIRect::MakeXYWH(0, 0, kW, 1);
|
|
|
|
SkIRect outerRightEdge = SkIRect::MakeXYWH(kW-1, 0, 1, kH);
|
|
|
|
SkIRect outerBottomEdge = SkIRect::MakeXYWH(0, kH-1, kW, 1);
|
|
|
|
|
|
|
|
// A rectangle that is inset by two on all sides and the 1-pixel wide rectangles that surround
|
|
|
|
// it.
|
|
|
|
SkIRect mid2Rect = SkIRect::MakeXYWH(2, 2, kW-4, kH-4);
|
|
|
|
SkIRect innerLeftEdge = SkIRect::MakeXYWH(1, 1, 1, kH-2);
|
|
|
|
SkIRect innerTopEdge = SkIRect::MakeXYWH(1, 1, kW-2, 1);
|
|
|
|
SkIRect innerRightEdge = SkIRect::MakeXYWH(kW-2, 1, 1, kH-2);
|
|
|
|
SkIRect innerBottomEdge = SkIRect::MakeXYWH(1, kH-2, kW-2, 1);
|
|
|
|
|
|
|
|
uint32_t actualValue;
|
|
|
|
int failX, failY;
|
|
|
|
|
|
|
|
static const GrColor kColor1 = 0xABCDEF01;
|
|
|
|
static const GrColor kColor2 = ~kColor1;
|
2018-11-05 20:06:26 +00:00
|
|
|
static const SkPMColor4f kColor1f = SkPMColor4f::FromBytes_RGBA(kColor1);
|
|
|
|
static const SkPMColor4f kColor2f = SkPMColor4f::FromBytes_RGBA(kColor2);
|
2016-02-05 15:17:34 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2017-06-02 18:53:40 +00:00
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
// Check a full clear
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
if (!check_rect(dContext, sdc.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2017-06-02 18:53:40 +00:00
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
// Check two full clears, same color
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
if (!check_rect(dContext, sdc.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2017-06-02 18:53:40 +00:00
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
// Check two full clears, different colors
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
sdc->clear(fullRect, kColor2f);
|
|
|
|
if (!check_rect(dContext, sdc.get(), fullRect, kColor2, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2017-06-02 18:53:40 +00:00
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
// Test a full clear followed by a same color inset clear
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
sdc->clear(mid1Rect, kColor1f);
|
|
|
|
if (!check_rect(dContext, sdc.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2017-06-02 18:53:40 +00:00
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
// Test a inset clear followed by same color full clear
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(mid1Rect, kColor1f);
|
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
if (!check_rect(dContext, sdc.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2017-06-02 18:53:40 +00:00
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
// Test a full clear followed by a different color inset clear
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
sdc->clear(mid1Rect, kColor2f);
|
|
|
|
if (!check_rect(dContext, sdc.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
2021-07-28 19:13:20 +00:00
|
|
|
if (!check_rect(dContext, sdc.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2017-06-02 18:53:40 +00:00
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
// Test a inset clear followed by a different full clear
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(mid1Rect, kColor2f);
|
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
if (!check_rect(dContext, sdc.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2017-06-02 18:53:40 +00:00
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
// Check three nested clears from largest to smallest where outermost and innermost are same
|
|
|
|
// color.
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
sdc->clear(mid1Rect, kColor2f);
|
|
|
|
sdc->clear(mid2Rect, kColor1f);
|
|
|
|
if (!check_rect(dContext, sdc.get(), mid2Rect, kColor1, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
2021-07-28 19:13:20 +00:00
|
|
|
if (!check_rect(dContext, sdc.get(), innerLeftEdge, kColor2, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), innerTopEdge, kColor2, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), innerRightEdge, kColor2, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), innerBottomEdge, kColor2, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
2021-07-28 19:13:20 +00:00
|
|
|
if (!check_rect(dContext, sdc.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2017-06-02 18:53:40 +00:00
|
|
|
|
2016-02-05 15:17:34 +00:00
|
|
|
// Swap the order of the second two clears in the above test.
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(fullRect, kColor1f);
|
|
|
|
sdc->clear(mid2Rect, kColor1f);
|
|
|
|
sdc->clear(mid1Rect, kColor2f);
|
|
|
|
if (!check_rect(dContext, sdc.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
2021-07-28 19:13:20 +00:00
|
|
|
if (!check_rect(dContext, sdc.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
|
|
|
|
!check_rect(dContext, sdc.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
|
2016-02-05 15:17:34 +00:00
|
|
|
ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
|
|
|
|
failX, failY);
|
|
|
|
}
|
2020-12-02 23:27:18 +00:00
|
|
|
|
|
|
|
// Clear calls need to remain ClearOps for the following combining-tests to work as expected
|
|
|
|
if (!dContext->priv().caps()->performColorClearsAsDraws() &&
|
|
|
|
!dContext->priv().caps()->performStencilClearsAsDraws() &&
|
|
|
|
!dContext->priv().caps()->performPartialClearsAsDraws()) {
|
|
|
|
static constexpr SkIRect kScissorRect = SkIRect::MakeXYWH(1, 1, kW-1, kH-1);
|
|
|
|
|
|
|
|
// Try combining a pure-color clear w/ a combined stencil & color clear
|
|
|
|
// (re skbug.com/10963)
|
|
|
|
{
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2020-12-02 23:27:18 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clearStencilClip(kScissorRect, true);
|
2020-12-02 23:27:18 +00:00
|
|
|
// This color clear can combine w/ the preceding stencil clear
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(kScissorRect, SK_PMColor4fWHITE);
|
2020-12-02 23:27:18 +00:00
|
|
|
|
|
|
|
// This should combine w/ the prior combined clear and overwrite the color
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(kScissorRect, SK_PMColor4fBLACK);
|
2020-12-02 23:27:18 +00:00
|
|
|
|
2021-08-25 17:22:24 +00:00
|
|
|
auto opsTask = sdc->getOpsTask();
|
|
|
|
REPORTER_ASSERT(reporter, opsTask->numOpChains() == 1);
|
2020-12-02 23:27:18 +00:00
|
|
|
|
2021-09-01 17:02:28 +00:00
|
|
|
const ClearOp& clearOp = opsTask->getChain(0)->cast<ClearOp>();
|
2020-12-02 23:27:18 +00:00
|
|
|
|
|
|
|
constexpr std::array<float, 4> kExpected { 0, 0, 0, 1 };
|
|
|
|
REPORTER_ASSERT(reporter, clearOp.color() == kExpected);
|
|
|
|
REPORTER_ASSERT(reporter, clearOp.stencilInsideMask());
|
|
|
|
|
|
|
|
dContext->flushAndSubmit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try combining a pure-stencil clear w/ a combined stencil & color clear
|
|
|
|
// (re skbug.com/10963)
|
|
|
|
{
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc = newSDC(dContext, kW, kH);
|
|
|
|
SkASSERT(sdc);
|
2020-12-02 23:27:18 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clearStencilClip(kScissorRect, true);
|
2020-12-02 23:27:18 +00:00
|
|
|
// This color clear can combine w/ the preceding stencil clear
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(kScissorRect, SK_PMColor4fWHITE);
|
2020-12-02 23:27:18 +00:00
|
|
|
|
|
|
|
// This should combine w/ the prior combined clear and overwrite the 'insideStencilMask'
|
|
|
|
// field
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clearStencilClip(kScissorRect, false);
|
2020-12-02 23:27:18 +00:00
|
|
|
|
2021-08-25 17:22:24 +00:00
|
|
|
auto opsTask = sdc->getOpsTask();
|
|
|
|
REPORTER_ASSERT(reporter, opsTask->numOpChains() == 1);
|
2020-12-02 23:27:18 +00:00
|
|
|
|
2021-09-01 17:02:28 +00:00
|
|
|
const ClearOp& clearOp = opsTask->getChain(0)->cast<ClearOp>();
|
2020-12-02 23:27:18 +00:00
|
|
|
|
|
|
|
constexpr std::array<float, 4> kExpected { 1, 1, 1, 1 };
|
|
|
|
REPORTER_ASSERT(reporter, clearOp.color() == kExpected);
|
|
|
|
REPORTER_ASSERT(reporter, !clearOp.stencilInsideMask());
|
|
|
|
|
|
|
|
dContext->flushAndSubmit();
|
|
|
|
}
|
|
|
|
}
|
2016-02-05 15:17:34 +00:00
|
|
|
}
|
2017-10-18 12:33:29 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearOp, reporter, ctxInfo) {
|
2019-01-11 20:26:22 +00:00
|
|
|
// Regular clear
|
2020-07-06 14:56:46 +00:00
|
|
|
clear_op_test(reporter, ctxInfo.directContext());
|
2019-01-11 20:26:22 +00:00
|
|
|
|
|
|
|
// Force drawing for clears
|
|
|
|
GrContextOptions options(ctxInfo.options());
|
|
|
|
options.fUseDrawInsteadOfClear = GrContextOptions::Enable::kYes;
|
|
|
|
sk_gpu_test::GrContextFactory workaroundFactory(options);
|
|
|
|
clear_op_test(reporter, workaroundFactory.get(ctxInfo.type()));
|
2017-10-18 12:33:29 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 18:15:51 +00:00
|
|
|
void fullscreen_clear_with_layer_test(skiatest::Reporter* reporter, GrRecordingContext* rContext) {
|
2017-10-18 12:33:29 +00:00
|
|
|
const SkImageInfo ii = SkImageInfo::Make(400, 77, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
2020-07-17 18:15:51 +00:00
|
|
|
sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(rContext, SkBudgeted::kYes, ii);
|
2017-10-18 12:33:29 +00:00
|
|
|
SkCanvas* canvas = surf->getCanvas();
|
|
|
|
|
|
|
|
SkPaint paints[2];
|
|
|
|
paints[0].setColor(SK_ColorGREEN);
|
|
|
|
paints[1].setColor(SK_ColorGRAY);
|
|
|
|
|
|
|
|
static const int kLeftX = 158;
|
|
|
|
static const int kMidX = 258;
|
|
|
|
static const int kRightX = 383;
|
|
|
|
static const int kTopY = 26;
|
|
|
|
static const int kBotY = 51;
|
|
|
|
|
|
|
|
const SkRect rects[2] = {
|
|
|
|
{ kLeftX, kTopY, kMidX, kBotY },
|
|
|
|
{ kMidX, kTopY, kRightX, kBotY },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
// the bounds parameter is required to cause a full screen clear
|
|
|
|
canvas->saveLayer(&rects[i], nullptr);
|
|
|
|
canvas->drawRect(rects[i], paints[i]);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(ii, 0);
|
|
|
|
|
|
|
|
SkAssertResult(surf->readPixels(bm, 0, 0));
|
|
|
|
|
|
|
|
bool isCorrect = true;
|
|
|
|
for (int y = kTopY; isCorrect && y < kBotY; ++y) {
|
|
|
|
const uint32_t* sl = bm.getAddr32(0, y);
|
|
|
|
|
|
|
|
for (int x = kLeftX; x < kMidX; ++x) {
|
|
|
|
if (SK_ColorGREEN != sl[x]) {
|
|
|
|
isCorrect = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int x = kMidX; x < kRightX; ++x) {
|
|
|
|
if (SK_ColorGRAY != sl[x]) {
|
|
|
|
isCorrect = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, isCorrect);
|
|
|
|
}
|
|
|
|
// From crbug.com/768134
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FullScreenClearWithLayers, reporter, ctxInfo) {
|
2019-01-11 20:26:22 +00:00
|
|
|
// Regular clear
|
2020-07-06 14:56:46 +00:00
|
|
|
fullscreen_clear_with_layer_test(reporter, ctxInfo.directContext());
|
2019-01-11 20:26:22 +00:00
|
|
|
|
|
|
|
// Use draws for clears
|
|
|
|
GrContextOptions options(ctxInfo.options());
|
|
|
|
options.fUseDrawInsteadOfClear = GrContextOptions::Enable::kYes;
|
|
|
|
sk_gpu_test::GrContextFactory workaroundFactory(options);
|
|
|
|
fullscreen_clear_with_layer_test(reporter, workaroundFactory.get(ctxInfo.type()));
|
2017-10-18 12:33:29 +00:00
|
|
|
}
|