• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 #ifndef skgpu_graphite_GraphiteTypes_DEFINED
9 #define skgpu_graphite_GraphiteTypes_DEFINED
10 
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkTypes.h"
13 #include "include/gpu/GpuTypes.h"
14 
15 #include <memory>
16 
17 class SkSurface;
18 
19 namespace skgpu::graphite {
20 
21 class Recording;
22 class Task;
23 
24 using GpuFinishedContext = void*;
25 using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackResult);
26 
27 /**
28  * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or
29  * when there is a failure that caused it not to be submitted. The callback will always be called
30  * and the caller can use the callback to know it is safe to free any resources associated with
31  * the Recording that they may be holding onto. If the Recording is successfully submitted to the
32  * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All
33  * other cases where some failure occured it will be called with CallbackResult::kFailed.
34  *
35  * The fTargetSurface, if provided, is used as a target for any draws recorded onto a deferred
36  * canvas returned from Recorder::makeDeferredCanvas. This target surface must be provided iff
37  * the Recording contains any such draws. It must be Graphite-backed and its backing texture's
38  * TextureInfo must match the info provided to the Recorder when making the deferred canvas.
39  *
40  * fTargetTranslation is an additional translation applied to draws targeting fTargetSurface.
41  */
42 struct InsertRecordingInfo {
43     Recording* fRecording = nullptr;
44 
45     SkSurface* fTargetSurface = nullptr;
46     SkIVector fTargetTranslation = {0, 0};
47 
48     GpuFinishedContext fFinishedContext = nullptr;
49     GpuFinishedProc fFinishedProc = nullptr;
50 };
51 
52 /**
53  * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or
54  * when there is a failure that caused it not to be submitted. The callback will always be called
55  * and the caller can use the callback to know it is safe to free any resources associated with
56  * the Recording that they may be holding onto. If the Recording is successfully submitted to the
57  * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All
58  * other cases where some failure occured it will be called with CallbackResult::kFailed.
59  */
60 struct InsertFinishInfo {
61     GpuFinishedContext fFinishedContext = nullptr;
62     GpuFinishedProc fFinishedProc = nullptr;
63 };
64 
65 /**
66  * Actually submit work to the GPU and track its completion
67  */
68 enum class SyncToCpu : bool {
69     kYes = true,
70     kNo = false
71 };
72 
73 /*
74  * For Promise Images - should the Promise Image be fulfilled every time a Recording that references
75  * it is inserted into the Context.
76  */
77 enum class Volatile : bool {
78     kNo = false,              // only fulfilled once
79     kYes = true               // fulfilled on every insertion call
80 };
81 
82 /*
83  * Graphite's different rendering methods each only apply to certain types of draws. This
84  * enum supports decision-making regarding the different renderers and what is being drawn.
85  */
86 enum DrawTypeFlags : uint8_t {
87 
88     kNone         = 0b000,
89 
90     // SkCanvas:: drawSimpleText, drawString, drawGlyphs, drawTextBlob, drawSlug
91     kText         = 0b001,
92 
93     // SkCanvas::drawVertices
94     kDrawVertices = 0b010,
95 
96     // All other canvas draw calls
97     kShape        = 0b100,
98 
99     kMostCommon = kText | kShape,
100     kAll = kText | kDrawVertices | kShape
101 };
102 
103 } // namespace skgpu::graphite
104 
105 #endif // skgpu_graphite_GraphiteTypes_DEFINED
106