• 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 #include "include/core/SkAlphaType.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkColorType.h"
12 #include "include/core/SkImageInfo.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkSurface.h"
15 #include "include/core/SkTypes.h"
16 #include "include/gpu/GpuTypes.h"
17 #include "include/gpu/GrDirectContext.h"
18 #include "include/gpu/GrTypes.h"
19 #include "tests/CtsEnforcement.h"
20 #include "tests/Test.h"
21 #include "tools/gpu/FenceSync.h"
22 
23 struct GrContextOptions;
24 
25 using namespace sk_gpu_test;
26 
27 namespace {
28 struct SubmittedInfo {
29     int* fCount;
30     bool* fSuccess;
31 };
32 }  // namespace
33 
testing_submitted_proc(void * ctx,bool success)34 static void testing_submitted_proc(void* ctx, bool success) {
35     SubmittedInfo* info = (SubmittedInfo*)ctx;
36     *info->fCount += 1;
37     *info->fSuccess = success;
38 }
39 
DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(FlushSubmittedProcTest,reporter,ctxInfo,CtsEnforcement::kApiLevel_T)40 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(FlushSubmittedProcTest,
41                                        reporter,
42                                        ctxInfo,
43                                        CtsEnforcement::kApiLevel_T) {
44     auto ctx = ctxInfo.directContext();
45 
46     SkImageInfo info = SkImageInfo::Make(8, 8, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
47     sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctx, skgpu::Budgeted::kNo, info);
48     SkCanvas* canvas = surface->getCanvas();
49 
50     canvas->clear(SK_ColorGREEN);
51 
52     int submittedCount = 0;
53     bool submittedSuccess = false;
54     SubmittedInfo submittedInfo = { &submittedCount, &submittedSuccess };
55 
56     GrFlushInfo flushInfo;
57     flushInfo.fSubmittedProc = testing_submitted_proc;
58     flushInfo.fSubmittedContext = &submittedInfo;
59 
60     ctx->flush(flushInfo);
61     REPORTER_ASSERT(reporter, submittedCount == 0);
62 
63     ctx->submit();
64     REPORTER_ASSERT(reporter, submittedCount == 1);
65     REPORTER_ASSERT(reporter, submittedSuccess);
66 
67     // There should be no work so if we flush again the submittedProc should be called immediately
68     surface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
69     REPORTER_ASSERT(reporter, submittedCount == 2);
70     REPORTER_ASSERT(reporter, submittedSuccess);
71 
72     // However, flushing the context we don't do any checks of work so we still require submit to be
73     // called in order for the callback to trigger.
74     ctx->flush(flushInfo);
75     REPORTER_ASSERT(reporter, submittedCount == 2);
76 
77     ctx->submit();
78     REPORTER_ASSERT(reporter, submittedCount == 3);
79     REPORTER_ASSERT(reporter, submittedSuccess);
80 
81     // Testing that doing multiple flushes before a submit triggers both submittedProcs to be called
82     canvas->clear(SK_ColorBLUE);
83     surface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
84     REPORTER_ASSERT(reporter, submittedCount == 3);
85     canvas->clear(SK_ColorRED);
86     surface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
87     REPORTER_ASSERT(reporter, submittedCount == 3);
88     ctx->submit();
89 
90     REPORTER_ASSERT(reporter, submittedCount == 5);
91     REPORTER_ASSERT(reporter, submittedSuccess);
92 
93     // Test an abandoned context to get a failed submit immediately when flush is called
94     canvas->clear(SK_ColorCYAN);
95     ctx->abandonContext();
96     surface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
97     REPORTER_ASSERT(reporter, submittedCount == 6);
98     REPORTER_ASSERT(reporter, !submittedSuccess);
99     ctx->flush(flushInfo);
100     REPORTER_ASSERT(reporter, submittedCount == 7);
101     REPORTER_ASSERT(reporter, !submittedSuccess);
102 }
103