xref: /aosp_15_r20/external/skia/tests/SrcSrcOverBatchTest.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
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/SkAlphaType.h"
12 #include "include/core/SkBlendMode.h"
13 #include "include/core/SkCanvas.h"
14 #include "include/core/SkColor.h"
15 #include "include/core/SkColorType.h"
16 #include "include/core/SkImageInfo.h"
17 #include "include/core/SkPaint.h"
18 #include "include/core/SkRect.h"
19 #include "include/core/SkRefCnt.h"
20 #include "include/core/SkShader.h"
21 #include "include/core/SkSurface.h"
22 #include "include/core/SkTypes.h"
23 #include "include/gpu/GpuTypes.h"
24 #include "include/gpu/ganesh/GrDirectContext.h"
25 #include "include/gpu/ganesh/GrTypes.h"
26 #include "include/gpu/ganesh/SkSurfaceGanesh.h"
27 #include "tests/CtsEnforcement.h"
28 #include "tests/Test.h"
29 
30 struct GrContextOptions;
31 
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(SrcSrcOverBatchTest,reporter,ctxInfo,CtsEnforcement::kNever)32 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(SrcSrcOverBatchTest,
33                                        reporter,
34                                        ctxInfo,
35                                        CtsEnforcement::kNever) {
36     auto ctx = ctxInfo.directContext();
37 
38     static const int kSize = 8;
39     const SkImageInfo ii = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
40                                              kPremul_SkAlphaType);
41 
42     sk_sp<SkSurface> surface(SkSurfaces::RenderTarget(
43             ctx, skgpu::Budgeted::kNo, ii, 0, kTopLeft_GrSurfaceOrigin, nullptr));
44 
45     auto canvas = surface->getCanvas();
46 
47     SkPaint paint;
48     // Setting a shader so that we actually build a processor set and don't fallback to all
49     // defaults.
50     paint.setShader(SkShaders::Color(SK_ColorRED));
51 
52     SkIRect rect = SkIRect::MakeWH(2, 2);
53 
54     canvas->drawIRect(rect, paint);
55 
56     // Now draw a rect with src blend mode. If we collapsed the previous draw to src blend mode (a
57     // setting on caps plus not having any coverage), then we expect this second draw to try to
58     // batch with it. This test is a success if we don't hit any asserts, specifically making sure
59     // that both things we decided can be batched together claim to have the same value for
60     // CompatibleWithCoverageAsAlpha.
61     canvas->translate(3, 0);
62     paint.setBlendMode(SkBlendMode::kSrc);
63     canvas->drawIRect(rect, paint);
64 }
65