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