blob: 156de0096e7563971ac39174ce81da3fc6cdc0b0 [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"
Robert Phillips6d344c32020-07-06 10:56:46 -040014#include "include/gpu/GrDirectContext.h"
Greg Danielc5296812020-02-28 13:06:02 -050015#include "tests/Test.h"
16#include "tools/gpu/GrContextFactory.h"
17
18DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SrcSrcOverBatchTest, reporter, ctxInfo) {
Robert Phillips6d344c32020-07-06 10:56:46 -040019 auto ctx = ctxInfo.directContext();
Greg Danielc5296812020-02-28 13:06:02 -050020
21 static const int kSize = 8;
22 const SkImageInfo ii = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
23 kPremul_SkAlphaType);
24
25 sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo,
26 ii, 0, kTopLeft_GrSurfaceOrigin,
27 nullptr));
28
29 auto canvas = surface->getCanvas();
30
31 SkPaint paint;
32 // Setting a shader so that we actually build a processor set and don't fallback to all
33 // defaults.
34 paint.setShader(SkShaders::Color(SK_ColorRED));
35
36 SkIRect rect = SkIRect::MakeWH(2, 2);
37
38 canvas->drawIRect(rect, paint);
39
40 // Now draw a rect with src blend mode. If we collapsed the previous draw to src blend mode (a
41 // setting on caps plus not having any coverage), then we expect this second draw to try to
42 // batch with it. This test is a success if we don't hit any asserts, specifically making sure
43 // that both things we decided can be batched together claim to have the same value for
44 // CompatibleWithCoverageAsAlpha.
45 canvas->translate(3, 0);
46 paint.setBlendMode(SkBlendMode::kSrc);
47 canvas->drawIRect(rect, paint);
48}