Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrSubmittedFlushTest.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
18#include "include/gpu/GrTypes.h"
21#include "tests/Test.h"
22#include "tools/gpu/FenceSync.h"
23
24struct GrContextOptions;
25
26using namespace sk_gpu_test;
27
28namespace {
29struct SubmittedInfo {
30 int* fCount;
31 bool* fSuccess;
32};
33} // namespace
34
35static void testing_submitted_proc(void* ctx, bool success) {
36 SubmittedInfo* info = (SubmittedInfo*)ctx;
37 *info->fCount += 1;
38 *info->fSuccess = success;
39}
40
43 ctxInfo,
45 auto ctx = ctxInfo.directContext();
46
49 SkCanvas* canvas = surface->getCanvas();
50
51 canvas->clear(SK_ColorGREEN);
52
53 int submittedCount = 0;
54 bool submittedSuccess = false;
55 SubmittedInfo submittedInfo = { &submittedCount, &submittedSuccess };
56
57 GrFlushInfo flushInfo;
59 flushInfo.fSubmittedContext = &submittedInfo;
60
61 ctx->flush(flushInfo);
62 REPORTER_ASSERT(reporter, submittedCount == 0);
63
64 ctx->submit();
65 REPORTER_ASSERT(reporter, submittedCount == 1);
66 REPORTER_ASSERT(reporter, submittedSuccess);
67
68 // There should be no work so if we flush again the submittedProc should be called immediately
69 ctx->flush(surface.get(), SkSurfaces::BackendSurfaceAccess::kNoAccess, flushInfo);
70 REPORTER_ASSERT(reporter, submittedCount == 2);
71 REPORTER_ASSERT(reporter, submittedSuccess);
72
73 // However, flushing the context we don't do any checks of work so we still require submit to be
74 // called in order for the callback to trigger.
75 ctx->flush(flushInfo);
76 REPORTER_ASSERT(reporter, submittedCount == 2);
77
78 ctx->submit();
79 REPORTER_ASSERT(reporter, submittedCount == 3);
80 REPORTER_ASSERT(reporter, submittedSuccess);
81
82 // Testing that doing multiple flushes before a submit triggers both submittedProcs to be called
83 canvas->clear(SK_ColorBLUE);
84 ctx->flush(surface.get(), SkSurfaces::BackendSurfaceAccess::kNoAccess, flushInfo);
85 REPORTER_ASSERT(reporter, submittedCount == 3);
86 canvas->clear(SK_ColorRED);
87 ctx->flush(surface.get(), SkSurfaces::BackendSurfaceAccess::kNoAccess, flushInfo);
88 REPORTER_ASSERT(reporter, submittedCount == 3);
89 ctx->submit();
90
91 REPORTER_ASSERT(reporter, submittedCount == 5);
92 REPORTER_ASSERT(reporter, submittedSuccess);
93
94 // Test an abandoned context to get a failed submit immediately when flush is called
95 canvas->clear(SK_ColorCYAN);
96 ctx->abandonContext();
97 ctx->flush(surface.get(), SkSurfaces::BackendSurfaceAccess::kNoAccess, flushInfo);
98 REPORTER_ASSERT(reporter, submittedCount == 6);
99 REPORTER_ASSERT(reporter, !submittedSuccess);
100 ctx->flush(flushInfo);
101 REPORTER_ASSERT(reporter, submittedCount == 7);
102 REPORTER_ASSERT(reporter, !submittedSuccess);
103}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
static void testing_submitted_proc(void *ctx, bool success)
@ 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
constexpr SkColor SK_ColorCYAN
Definition SkColor.h:143
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
Definition Test.h:434
void clear(SkColor color)
Definition SkCanvas.h:1199
VkSurfaceKHR surface
Definition main.cc:49
@ kNoAccess
back-end surface will not be used by client
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)
GrGpuSubmittedContext fSubmittedContext
Definition GrTypes.h:222
GrGpuSubmittedProc fSubmittedProc
Definition GrTypes.h:221
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)