Flutter Engine
The Flutter Engine
TextureOpTest.cpp
Go to the documentation of this file.
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
11#include "include/core/SkRect.h"
14#include "include/core/SkSize.h"
20#include "include/gpu/GrTypes.h"
24#include "src/gpu/Swizzle.h"
40#include "tests/Test.h"
41
42#include <utility>
43
44struct GrContextOptions;
45
46using namespace skgpu::ganesh;
47
49public:
50 typedef skgpu::ganesh::OpsTask::OpChain OpChain;
51};
52
53static void check_chain(OpsTaskTestingAccess::OpChain* chain, SkRect firstRect, SkRect lastRect,
54 int expectedNumOps) {
55 int actualNumOps = 0;
56 for (const auto& op : GrOp::ChainRange<>(chain->head())) {
57 ++actualNumOps;
58
59 if (actualNumOps == 1) {
60 SkAssertResult(op.bounds() == firstRect.makeOutset(0.5f, 0.5f));
61 } else if (actualNumOps == expectedNumOps) {
62 SkAssertResult(op.bounds() == lastRect.makeOutset(0.5f, 0.5f));
63 }
64 }
65
66 SkAssertResult(actualNumOps == expectedNumOps);
67}
68
70 const GrCaps* caps = rContext->priv().caps();
71
72 static constexpr SkISize kDimensions = {16, 16};
73
76 return rContext->priv().proxyProvider()->createProxy(format,
77 kDimensions,
79 1,
84 /*label=*/"TextureOpTest",
86}
87
89 const GrSurfaceProxyView& proxyView, bool isAA) {
90 DrawQuad quad;
91
92 quad.fDevice = GrQuad::MakeFromRect(rect.makeOutset(0.5f, 0.5f), SkMatrix::I());
93 quad.fLocal = GrQuad(rect);
95
96 return TextureOp::Make(dContext,
97 proxyView,
99 nullptr,
102 {1.f, 1.f, 1.f, 1.f},
103 TextureOp::Saturate::kYes,
107 &quad,
108 nullptr);
109}
110
111// This unit test exercises the crbug.com/1112259 case.
113 GrDirectContext* dContext = ctxInfo.directContext();
114 const GrCaps* caps = dContext->priv().caps();
115 SkArenaAlloc arena{nullptr, 0, 1024};
116 auto auditTrail = dContext->priv().auditTrail();
117
119 // This test requires chaining
120 return;
121 }
122
123 GrSurfaceProxyView proxyViewA(create_proxy(dContext),
126 GrSurfaceProxyView proxyViewB(create_proxy(dContext),
129 GrSurfaceProxyView proxyViewC(create_proxy(dContext),
132
133 static const SkRect kOpARect{ 0, 0, 16, 16 };
134 static const SkRect kOpBRect{ 32, 0, 48, 16 };
135 static const SkRect kOpCRect{ 0, 32, 16, 48 };
136 static const SkRect kOpDRect{ 32, 32, 48, 48 };
137
138 // opA & opB can chain together but can't merge bc they have different proxies
139 GrOp::Owner opA = create_op(dContext, kOpARect, proxyViewA, false);
140 GrOp::Owner opB = create_op(dContext, kOpBRect, proxyViewB, false);
141
144 &noClip, nullptr);
145 chain1.appendOp(std::move(opB), GrProcessorSet::EmptySetAnalysis(), nullptr, &noClip, *caps,
146 &arena, dContext->priv().auditTrail());
147 check_chain(&chain1, kOpARect, kOpBRect, 2);
148
149 // opC & opD can also chain together but can't merge (bc, again, they have different
150 // proxies). Note, however, that opA and opD do share a proxy so can be merged if opA's
151 // anti-aliasing is upgraded to coverage.
152 GrOp::Owner opC = create_op(dContext, kOpCRect, proxyViewC, true);
153 GrOp::Owner opD = create_op(dContext, kOpDRect, proxyViewA, true);
154
156 &noClip, nullptr);
157 chain2.appendOp(std::move(opD), GrProcessorSet::EmptySetAnalysis(), nullptr, &noClip, *caps,
158 &arena, auditTrail);
159 check_chain(&chain2, kOpCRect, kOpDRect, 2);
160
161 // opA and opD, now in separate chains, can merge when the two chains are combined while
162 // opB and opC can still only chain.
163 chain1.prependChain(&chain2, *caps, &arena, auditTrail);
164
165 // We should end up with the chain
166 // opC - opD/opA - opB
167 check_chain(&chain1, kOpCRect, kOpBRect, 3);
168
169 chain1.deleteOps();
170}
reporter
Definition: FontMgrTest.cpp:39
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kSrcOver
r = s + (1-sa)*d
static GrOp::Owner create_op(GrDirectContext *dContext, SkRect rect, const GrSurfaceProxyView &proxyView, bool isAA)
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(TextureOpTest, reporter, ctxInfo, CtsEnforcement::kNever)
static sk_sp< GrSurfaceProxy > create_proxy(GrRecordingContext *rContext)
static void check_chain(OpsTaskTestingAccess::OpChain *chain, SkRect firstRect, SkRect lastRect, int expectedNumOps)
static GrAppliedClip Disabled()
Definition: GrAppliedClip.h:96
const GrCaps * caps() const
Definition: GrCaps.h:57
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
bool dynamicStateArrayGeometryProcessorTextureSupport() const
Definition: GrCaps.h:418
GrDirectContextPriv priv()
std::unique_ptr< GrOp > Owner
Definition: GrOp.h:72
static constexpr Analysis EmptySetAnalysis()
sk_sp< GrTextureProxy > createProxy(const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
Definition: GrQuad.h:30
static GrQuad MakeFromRect(const SkRect &, const SkMatrix &)
Definition: GrQuad.cpp:107
GrProxyProvider * proxyProvider()
GrRecordingContextPriv priv()
skgpu::ganesh::OpsTask::OpChain OpChain
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
static constexpr Swizzle RGBA()
Definition: Swizzle.h:66
uint32_t uint32_t * format
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
GrQuad fLocal
Definition: GrQuad.h:186
GrQuad fDevice
Definition: GrQuad.h:185
GrQuadAAFlags fEdgeFlags
Definition: GrQuad.h:187
Definition: SkSize.h:16
SkRect makeOutset(float dx, float dy) const
Definition: SkRect.h:1002