* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkAlphaType.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathTypes.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/ganesh/GrDirectContext.h"
#include "include/gpu/ganesh/GrTypes.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <initializer_list>
struct GrContextOptions;
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(crbug_1271431,
reporter,
context_info,
CtsEnforcement::kApiLevel_T) {
GrDirectContext* dc = context_info.directContext();
dc->freeGpuResources();
SkImageInfo ii = SkImageInfo::Make({100, 100},
kRGBA_8888_SkColorType,
kPremul_SkAlphaType,
nullptr);
sk_sp<SkSurface> surfs[2]{SkSurfaces::RenderTarget(dc, skgpu::Budgeted::kYes, ii, 1, nullptr),
SkSurfaces::RenderTarget(dc, skgpu::Budgeted::kYes, ii, 1, nullptr)};
for (int i = 0; i < 2; ++i) {
surfs[i]->getCanvas()->clear(SK_ColorWHITE);
dc->flushAndSubmit(surfs[i].get(), GrSyncCpu::kNo);
}
auto drawWithStencilClip = [&](SkSurface& surf, SkColor color) {
SkPath clip;
clip.addCircle(50, 50, 50);
clip.addCircle(50, 50, 10, SkPathDirection::kCCW);
SkPaint paint;
paint.setColor(color);
surf.getCanvas()->clipPath(clip, false);
surf.getCanvas()->drawRect(SkRect::MakeLTRB(0,0, 100, 100), paint);
};
drawWithStencilClip(*surfs[0], SK_ColorRED);
dc->flushAndSubmit(surfs[0].get(), GrSyncCpu::kNo);
surfs[1]->getCanvas()->clear(SK_ColorGREEN);
dc->flushAndSubmit(surfs[1].get(), GrSyncCpu::kNo);
drawWithStencilClip(*surfs[1], SK_ColorBLUE);
SkAutoPixmapStorage rb;
rb.alloc(surfs[1]->imageInfo().makeWH(1, 1));
for (int x : {5, 95}) {
for (int y : {5, 95}) {
if (!surfs[1]->readPixels(rb, x, y)) {
ERRORF(reporter, "readback failed");
return;
}
if (*rb.addr32() != SK_ColorGREEN) {
ERRORF(reporter,
"Expected green at (%d, %d), instead got 0x%08x.",
x,
y,
*rb.addr32());
return;
}
}
}
}