1 /*
2 * Copyright 2023 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 #include "tests/Test.h"
9
10 #include "src/gpu/graphite/ContextPriv.h"
11 #include "src/gpu/graphite/DrawList.h"
12 #include "src/gpu/graphite/DrawPass.h"
13 #include "src/gpu/graphite/RecorderPriv.h"
14 #include "src/gpu/graphite/RendererProvider.h"
15
16 namespace skgpu::graphite {
17
18 // Tests that creating a draw pass that fails a dst copy doesn't result in a segfault.
DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(DrawPassTestFailedDstCopy,reporter,context,CtsEnforcement::kNextRelease)19 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(DrawPassTestFailedDstCopy,
20 reporter,
21 context,
22 CtsEnforcement::kNextRelease) {
23 const Caps* caps = context->priv().caps();
24 std::unique_ptr<Recorder> recorder = context->makeRecorder();
25
26 // Define a paint that requires a dst copy.
27 SkPaint paint;
28 PaintParams paintParams{paint, nullptr, nullptr, DstReadRequirement::kTextureCopy, false};
29
30 // Define a draw that uses the paint, but is larger than the max texture size. In this case the
31 // dst copy will fail.
32 const SkIRect drawSize = SkIRect::MakeWH(caps->maxTextureSize() + 1, 1);
33 std::unique_ptr<DrawList> drawList = std::make_unique<DrawList>();
34 drawList->recordDraw(recorder->priv().rendererProvider()->analyticRRect(),
35 Transform::Identity(),
36 Geometry(Shape(SkRect::Make(drawSize))),
37 Clip(Rect::Infinite(), Rect::Infinite(), drawSize, nullptr),
38 DrawOrder(DrawOrder::kClearDepth.next()),
39 &paintParams,
40 nullptr);
41
42 // Attempt to make a draw pass with the draw.
43 static constexpr SkISize targetSize = SkISize::Make(1, 1);
44 static constexpr SkColorType targetColorType = kN32_SkColorType;
45 static constexpr SkAlphaType targetAlphaType = kPremul_SkAlphaType;
46 const SkImageInfo targetInfo = SkImageInfo::Make(targetSize, targetColorType, targetAlphaType);
47 sk_sp<TextureProxy> target = TextureProxy::Make(
48 caps,
49 recorder->priv().resourceProvider(),
50 targetSize,
51 caps->getDefaultSampledTextureInfo(
52 targetColorType, Mipmapped::kNo,
53 recorder->priv().isProtected(), Renderable::kYes),
54 "DrawPassTestTargetProxy",
55 Budgeted::kYes);
56 std::unique_ptr<DrawPass> drawPass = DrawPass::Make(recorder.get(),
57 std::move(drawList),
58 target,
59 targetInfo,
60 {LoadOp::kClear, StoreOp::kStore},
61 {0.0f, 0.0f, 0.0f, 0.0f},
62 /*dstCopy=*/nullptr,
63 /*dstCopyOffset=*/{0,0});
64
65 // Make sure creating the draw pass failed.
66 REPORTER_ASSERT(reporter, !drawPass);
67 }
68
69 } // namespace skgpu::graphite
70