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 "src/gpu/GrFinishCallbacks.h" |
9 | #include "src/gpu/GrGpu.h" |
10 | |
11 | GrFinishCallbacks::GrFinishCallbacks(GrGpu* gpu) : fGpu(gpu) {} |
12 | |
13 | GrFinishCallbacks::~GrFinishCallbacks() { |
14 | this->callAll(true); |
15 | } |
16 | |
17 | void GrFinishCallbacks::add(GrGpuFinishedProc finishedProc, |
18 | GrGpuFinishedContext finishedContext) { |
19 | SkASSERT(finishedProc); |
20 | FinishCallback callback; |
21 | callback.fCallback = finishedProc; |
22 | callback.fContext = finishedContext; |
23 | callback.fFence = fGpu->insertFence(); |
24 | fCallbacks.push_back(callback); |
25 | } |
26 | |
27 | void GrFinishCallbacks::check() { |
28 | // Bail after the first unfinished sync since we expect they signal in the order inserted. |
29 | while (!fCallbacks.empty() && fGpu->waitFence(fCallbacks.front().fFence)) { |
30 | fCallbacks.front().fCallback(fCallbacks.front().fContext); |
31 | fGpu->deleteFence(fCallbacks.front().fFence); |
32 | fCallbacks.pop_front(); |
33 | } |
34 | } |
35 | |
36 | void GrFinishCallbacks::callAll(bool doDelete) { |
37 | while (!fCallbacks.empty()) { |
38 | fCallbacks.front().fCallback(fCallbacks.front().fContext); |
39 | if (doDelete) { |
40 | fGpu->deleteFence(fCallbacks.front().fFence); |
41 | } |
42 | fCallbacks.pop_front(); |
43 | } |
44 | } |
45 |