2019-04-12 18:24:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2019-04-12 18:24:55 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
2019-04-12 18:24:55 +00:00
|
|
|
|
|
|
|
using namespace sk_gpu_test;
|
|
|
|
|
|
|
|
static void testing_finished_proc(void* ctx) {
|
|
|
|
int* count = (int*)ctx;
|
|
|
|
*count += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) {
|
|
|
|
GrContext* ctx = ctxInfo.grContext();
|
|
|
|
|
|
|
|
SkImageInfo info =
|
|
|
|
SkImageInfo::Make(8, 8, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info);
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
|
|
|
// We flush the surface first just to get rid of any discards/clears that got recorded from
|
|
|
|
// making the surface.
|
|
|
|
surface->flush();
|
2019-04-17 19:26:11 +00:00
|
|
|
GrFlushInfo flushInfoSyncCpu;
|
|
|
|
flushInfoSyncCpu.fFlags = kSyncCpu_GrFlushFlag;
|
|
|
|
ctx->flush(flushInfoSyncCpu);
|
2019-04-12 18:24:55 +00:00
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
2019-04-17 19:26:11 +00:00
|
|
|
GrFlushInfo flushInfoFinishedProc;
|
|
|
|
flushInfoFinishedProc.fFinishedProc = testing_finished_proc;
|
|
|
|
flushInfoFinishedProc.fFinishedContext = (void*)&count;
|
2019-04-12 18:24:55 +00:00
|
|
|
// There is no work on the surface so flushing should immediately call the finished proc.
|
2019-04-17 19:26:11 +00:00
|
|
|
surface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfoFinishedProc);
|
2019-04-12 18:24:55 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, count == 1);
|
|
|
|
|
|
|
|
canvas->clear(SK_ColorRED);
|
|
|
|
|
2019-04-17 19:26:11 +00:00
|
|
|
surface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfoFinishedProc);
|
2019-04-12 18:24:55 +00:00
|
|
|
|
|
|
|
bool isVulkan = ctx->backend() == GrBackendApi::kVulkan;
|
|
|
|
if (isVulkan) {
|
|
|
|
// On Vulkan the command buffer we just submitted may or may not have finished immediately
|
|
|
|
// so the finish proc may not have been called.
|
|
|
|
REPORTER_ASSERT(reporter, count == 1 || count == 2);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, count == 2);
|
|
|
|
}
|
2019-04-17 19:26:11 +00:00
|
|
|
ctx->flush(flushInfoSyncCpu);
|
2019-04-12 18:24:55 +00:00
|
|
|
REPORTER_ASSERT(reporter, count == 2);
|
|
|
|
|
|
|
|
// Test flushing via the GrContext
|
|
|
|
canvas->clear(SK_ColorBLUE);
|
2019-04-17 19:26:11 +00:00
|
|
|
ctx->flush(flushInfoFinishedProc);
|
2019-04-12 18:24:55 +00:00
|
|
|
if (isVulkan) {
|
|
|
|
// On Vulkan the command buffer we just submitted may or may not have finished immediately
|
|
|
|
// so the finish proc may not have been called.
|
|
|
|
REPORTER_ASSERT(reporter, count == 2 || count == 3);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, count == 3);
|
|
|
|
}
|
2019-04-17 19:26:11 +00:00
|
|
|
ctx->flush(flushInfoSyncCpu);
|
2019-04-12 18:24:55 +00:00
|
|
|
REPORTER_ASSERT(reporter, count == 3);
|
|
|
|
|
|
|
|
// There is no work on the surface so flushing should immediately call the finished proc.
|
2019-04-17 19:26:11 +00:00
|
|
|
ctx->flush(flushInfoFinishedProc);
|
2019-04-12 18:24:55 +00:00
|
|
|
REPORTER_ASSERT(reporter, count == 4);
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
int count2 = 0;
|
|
|
|
canvas->clear(SK_ColorGREEN);
|
2019-04-17 19:26:11 +00:00
|
|
|
surface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfoFinishedProc);
|
2019-04-12 18:24:55 +00:00
|
|
|
// There is no work to be flushed here so this will return immediately, but make sure the
|
|
|
|
// finished call from this proc isn't called till the previous surface flush also is finished.
|
2019-04-17 19:26:11 +00:00
|
|
|
flushInfoFinishedProc.fFinishedContext = (void*)&count2;
|
|
|
|
ctx->flush(flushInfoFinishedProc);
|
2019-04-12 18:24:55 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, count == count2);
|
|
|
|
|
2019-04-17 19:26:11 +00:00
|
|
|
ctx->flush(flushInfoSyncCpu);
|
2019-04-12 18:24:55 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, count == 1);
|
|
|
|
REPORTER_ASSERT(reporter, count == count2);
|
|
|
|
}
|
|
|
|
|