skia2/tests/SrcSrcOverBatchTest.cpp
Robert Phillips 6d344c3069 Update unit tests to accept GrDirectContext
This CL makes it explicit that the unit tests always get a direct context.

It is mainly a mechanical CL.

Change-Id: I49e0628851d9c81eb47386ef978edf905c6469d8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299866
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2020-07-06 15:45:12 +00:00

49 lines
1.8 KiB
C++

/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// We want to make sure that if we collapse src-over down to src when blending, that batching still
// works correctly with a draw that explicitly requests src.
#include "include/core/SkCanvas.h"
#include "include/core/SkShader.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "tests/Test.h"
#include "tools/gpu/GrContextFactory.h"
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SrcSrcOverBatchTest, reporter, ctxInfo) {
auto ctx = ctxInfo.directContext();
static const int kSize = 8;
const SkImageInfo ii = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo,
ii, 0, kTopLeft_GrSurfaceOrigin,
nullptr));
auto canvas = surface->getCanvas();
SkPaint paint;
// Setting a shader so that we actually build a processor set and don't fallback to all
// defaults.
paint.setShader(SkShaders::Color(SK_ColorRED));
SkIRect rect = SkIRect::MakeWH(2, 2);
canvas->drawIRect(rect, paint);
// Now draw a rect with src blend mode. If we collapsed the previous draw to src blend mode (a
// setting on caps plus not having any coverage), then we expect this second draw to try to
// batch with it. This test is a success if we don't hit any asserts, specifically making sure
// that both things we decided can be batched together claim to have the same value for
// CompatibleWithCoverageAsAlpha.
canvas->translate(3, 0);
paint.setBlendMode(SkBlendMode::kSrc);
canvas->drawIRect(rect, paint);
}