Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
DDLFuzzer Class Reference

Public Member Functions

 DDLFuzzer (Fuzz *, ContextType)
 
 DDLFuzzer ()=delete
 
 DDLFuzzer (DDLFuzzer &)=delete
 
DDLFuzzeroperator= (DDLFuzzer &)=delete
 
void run ()
 
sk_sp< GrPromiseImageTexturefulfillPromiseImage (PromiseImageInfo &)
 
void releasePromiseImage (PromiseImageInfo &)
 

Detailed Description

Definition at line 94 of file FuzzDDLThreading.cpp.

Constructor & Destructor Documentation

◆ DDLFuzzer() [1/3]

DDLFuzzer::DDLFuzzer ( Fuzz fuzz,
ContextType  contextType 
)

Definition at line 128 of file FuzzDDLThreading.cpp.

128 : fFuzz(fuzz) {
129 sk_gpu_test::ContextInfo ctxInfo = fContextFactory.getContextInfo(contextType);
130 sk_gpu_test::TestContext* testCtx = ctxInfo.testContext();
131 fContext = ctxInfo.directContext();
132 if (!fContext) {
133 return;
134 }
135 SkISize canvasSize = kPromiseImageSize;
136 canvasSize.fWidth *= kPromiseImagesPerDDL;
138 fSurface = SkSurfaces::RenderTarget(fContext, skgpu::Budgeted::kNo, ii);
139 if (!fSurface || !fSurface->characterize(&fSurfaceCharacterization)) {
140 return;
141 }
142
143 testCtx->makeNotCurrent();
144 fGpuTaskGroup.add([&]{
145 testCtx->makeCurrent();
146 fGpuThread = SkGetThreadID();
147 });
148 fGpuTaskGroup.wait();
149 for (int i = 0; i < kPromiseImageCount; ++i) {
150 this->initPromiseImage(i);
151 }
152}
static constexpr int kPromiseImageCount
static constexpr SkISize kPromiseImageSize
static constexpr int kPromiseImagesPerDDL
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
SkThreadID SkGetThreadID()
Definition: SkThreadID.cpp:15
bool characterize(GrSurfaceCharacterization *characterization) const
Definition: SkSurface.cpp:239
void add(std::function< void(void)> fn)
Definition: SkTaskGroup.cpp:16
GrDirectContext * directContext() const
TestContext * testContext() const
ContextInfo getContextInfo(ContextType type, ContextOverrides=ContextOverrides::kNone)
void makeNotCurrent() const
Definition: TestContext.cpp:28
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
Definition: SkSize.h:16
int32_t fWidth
Definition: SkSize.h:17
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DDLFuzzer() [2/3]

DDLFuzzer::DDLFuzzer ( )
delete

◆ DDLFuzzer() [3/3]

DDLFuzzer::DDLFuzzer ( DDLFuzzer )
delete

Member Function Documentation

◆ fulfillPromiseImage()

sk_sp< GrPromiseImageTexture > DDLFuzzer::fulfillPromiseImage ( PromiseImageInfo promiseImage)

Definition at line 154 of file FuzzDDLThreading.cpp.

154 {
156 if (!this->isOnGPUThread()) {
157 fFuzz->signalBug();
158 }
159 bool success = make_fuzz_t<bool>(fFuzz);
160 State prior = promiseImage.fState.exchange(State::kTriedToFulfill, std::memory_order_relaxed);
161 if (prior != State::kInitial || promiseImage.fTexture != nullptr) {
162 fFuzz->signalBug();
163 }
164 if (!success) {
165 return nullptr;
166 }
167
168 // Try reusing an existing texture if we can and if the fuzzer wills it.
169 if (!fReusableTextures.empty() && make_fuzz_t<bool>(fFuzz)) {
170 promiseImage.fTexture = std::move(fReusableTextures.front());
171 fReusableTextures.pop();
172 return promiseImage.fTexture;
173 }
174
175 bool finishedBECreate = false;
176 auto markFinished = [](void* context) {
177 *(bool*)context = true;
178 };
179
180 GrBackendTexture backendTex =
188 markFinished,
189 &finishedBECreate,
190 /*label=*/"DDLFuzzer_FulFillPromiseImage");
191 SkASSERT_RELEASE(backendTex.isValid());
192 while (!finishedBECreate) {
193 fContext->checkAsyncWorkCompletion();
194 }
195
196 promiseImage.fTexture = GrPromiseImageTexture::Make(backendTex);
197
198 return promiseImage.fTexture;
199}
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
void signalBug()
Definition: Fuzz.h:82
bool isValid() const
void checkAsyncWorkCompletion()
GrBackendTexture createBackendTexture(int width, int height, const GrBackendFormat &, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, std::string_view label={})
static sk_sp< GrPromiseImageTexture > Make(const GrBackendTexture &backendTexture)
std::atomic< State > fState
sk_sp< GrPromiseImageTexture > fTexture
constexpr SkColor4f kRed
Definition: SkColor.h:440
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37

◆ operator=()

DDLFuzzer & DDLFuzzer::operator= ( DDLFuzzer )
delete

◆ releasePromiseImage()

void DDLFuzzer::releasePromiseImage ( PromiseImageInfo promiseImage)

Definition at line 201 of file FuzzDDLThreading.cpp.

201 {
203 // TODO: This requirement will go away when we unref promise images off the GPU thread.
204 if (!this->isOnGPUThread()) {
205 fFuzz->signalBug();
206 }
207
208 State old = promiseImage.fState.exchange(State::kDone, std::memory_order_relaxed);
209 if (promiseImage.fDrawn && old != State::kTriedToFulfill) {
210 fFuzz->signalBug();
211 }
212
213 // If we failed to fulfill, then nothing to be done.
214 if (!promiseImage.fTexture) {
215 return;
216 }
217
218 bool reuse = make_fuzz_t<bool>(fFuzz);
219 if (reuse) {
220 fReusableTextures.push(std::move(promiseImage.fTexture));
221 } else {
222 fContext->deleteBackendTexture(promiseImage.fTexture->backendTexture());
223 }
224 promiseImage.fTexture = nullptr;
225}
void deleteBackendTexture(const GrBackendTexture &)
GrBackendTexture backendTexture() const
std::atomic< bool > fDrawn

◆ run()

void DDLFuzzer::run ( )

Definition at line 277 of file FuzzDDLThreading.cpp.

277 {
278 if (!fSurface) {
279 return;
280 }
281 fRecordingTaskGroup.batch(kIterationCount, [this](int i) { this->recordAndPlayDDL(); });
282 fRecordingTaskGroup.wait();
283
284 fGpuTaskGroup.add([this] { fContext->flushAndSubmit(fSurface.get(), GrSyncCpu::kYes); });
285
286 fGpuTaskGroup.wait();
287
288 fGpuTaskGroup.add([this] {
289 while (!fReusableTextures.empty()) {
290 sk_sp<GrPromiseImageTexture> gpuTexture = std::move(fReusableTextures.front());
291 fContext->deleteBackendTexture(gpuTexture->backendTexture());
292 fReusableTextures.pop();
293 }
294 fContextFactory.destroyContexts();
295 // TODO: Release promise images not on the GPU thread.
296 fPromiseImages.reset(0);
297 });
298 fGpuTaskGroup.wait();
299}
static constexpr int kIterationCount
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
void batch(int N, std::function< void(int)> fn)
Definition: SkTaskGroup.cpp:24
T * get() const
Definition: SkRefCnt.h:303
void reset(size_t count=0)
Definition: SkTemplates.h:123

The documentation for this class was generated from the following file: