blob: 48e5a39b6f5db478cda0b2df33fd6702e739cf9c [file] [log] [blame]
Greg Danielc5296812020-02-28 13:06:02 -05001/*
2 * Copyright 2020 Google LLC
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
8// We want to make sure that if we collapse src-over down to src when blending, that batching still
9// works correctly with a draw that explicitly requests src.
10
11#include "include/core/SkCanvas.h"
12#include "include/core/SkShader.h"
13#include "include/core/SkSurface.h"
14#include "tests/Test.h"
15#include "tools/gpu/GrContextFactory.h"
16
17DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SrcSrcOverBatchTest, reporter, ctxInfo) {
18 GrContext* ctx = ctxInfo.grContext();
19
20 static const int kSize = 8;
21 const SkImageInfo ii = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
22 kPremul_SkAlphaType);
23
24 sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo,
25 ii, 0, kTopLeft_GrSurfaceOrigin,
26 nullptr));
27
28 auto canvas = surface->getCanvas();
29
30 SkPaint paint;
31 // Setting a shader so that we actually build a processor set and don't fallback to all
32 // defaults.
33 paint.setShader(SkShaders::Color(SK_ColorRED));
34
35 SkIRect rect = SkIRect::MakeWH(2, 2);
36
37 canvas->drawIRect(rect, paint);
38
39 // Now draw a rect with src blend mode. If we collapsed the previous draw to src blend mode (a
40 // setting on caps plus not having any coverage), then we expect this second draw to try to
41 // batch with it. This test is a success if we don't hit any asserts, specifically making sure
42 // that both things we decided can be batched together claim to have the same value for
43 // CompatibleWithCoverageAsAlpha.
44 canvas->translate(3, 0);
45 paint.setBlendMode(SkBlendMode::kSrc);
46 canvas->drawIRect(rect, paint);
47}