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