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 { 20 class MutableTextureState; 21 } 22 23 namespace skgpu::graphite { 24 25 class BackendSemaphore; 26 class Recording; 27 class Task; 28 29 using GpuFinishedContext = void*; 30 using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackResult); 31 32 /** 33 * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or 34 * when there is a failure that caused it not to be submitted. The callback will always be called 35 * and the caller can use the callback to know it is safe to free any resources associated with 36 * the Recording that they may be holding onto. If the Recording is successfully submitted to the 37 * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All 38 * other cases where some failure occured it will be called with CallbackResult::kFailed. 39 * 40 * The fTargetSurface, if provided, is used as a target for any draws recorded onto a deferred 41 * canvas returned from Recorder::makeDeferredCanvas. This target surface must be provided iff 42 * the Recording contains any such draws. It must be Graphite-backed and its backing texture's 43 * TextureInfo must match the info provided to the Recorder when making the deferred canvas. 44 * 45 * fTargetTranslation is an additional translation applied to draws targeting fTargetSurface. 46 * 47 * The client may pass in two arrays of initialized BackendSemaphores to be included in the 48 * command stream. At some time before issuing commands in the Recording, the fWaitSemaphores will 49 * be waited on by the gpu. We only guarantee these wait semaphores block transfer and fragment 50 * shader work. Similarly, at some time after issuing the Recording's commands, the 51 * fSignalSemaphores will be signaled by the gpu. Depending on the platform, the timing of the wait 52 * and signal operations will either be immediately before or after the given Recording's command 53 * stream, respectively, or before and after the entire CommandBuffer's command stream. The 54 * semaphores are not sent to the GPU until the next Context::submit call is made. 55 * 56 * The client will own and be responsible for deleting the underlying semaphore objects after the 57 * submission completes, however the BackendSemaphore objects themselves can be deleted as soon 58 * as this function returns. 59 */ 60 struct InsertRecordingInfo { 61 Recording* fRecording = nullptr; 62 63 SkSurface* fTargetSurface = nullptr; 64 SkIVector fTargetTranslation = {0, 0}; 65 MutableTextureState* fTargetTextureState = nullptr; 66 67 size_t fNumWaitSemaphores = 0; 68 BackendSemaphore* fWaitSemaphores = nullptr; 69 size_t fNumSignalSemaphores = 0; 70 BackendSemaphore* fSignalSemaphores = nullptr; 71 72 GpuFinishedContext fFinishedContext = nullptr; 73 GpuFinishedProc fFinishedProc = nullptr; 74 }; 75 76 /** 77 * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or 78 * when there is a failure that caused it not to be submitted. The callback will always be called 79 * and the caller can use the callback to know it is safe to free any resources associated with 80 * the Recording that they may be holding onto. If the Recording is successfully submitted to the 81 * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All 82 * other cases where some failure occured it will be called with CallbackResult::kFailed. 83 */ 84 struct InsertFinishInfo { 85 GpuFinishedContext fFinishedContext = nullptr; 86 GpuFinishedProc fFinishedProc = nullptr; 87 }; 88 89 /** 90 * Actually submit work to the GPU and track its completion 91 */ 92 enum class SyncToCpu : bool { 93 kYes = true, 94 kNo = false 95 }; 96 97 /* 98 * For Promise Images - should the Promise Image be fulfilled every time a Recording that references 99 * it is inserted into the Context. 100 */ 101 enum class Volatile : bool { 102 kNo = false, // only fulfilled once 103 kYes = true // fulfilled on every insertion call 104 }; 105 106 /* 107 * Graphite's different rendering methods each only apply to certain types of draws. This 108 * enum supports decision-making regarding the different renderers and what is being drawn. 109 */ 110 enum DrawTypeFlags : uint8_t { 111 112 kNone = 0b0000, 113 114 // SkCanvas:: drawSimpleText, drawString, drawGlyphs, drawTextBlob, drawSlug 115 kText = 0b0001, 116 117 // SkCanvas::drawVertices 118 kDrawVertices = 0b0010, 119 120 // SkCanvas::experimental_DrawEdgeAAQuad, experimental_DrawEdgeAAImageSet 121 // SkCanvas:: drawRect, drawRRect, drawLine for: 122 // regular filled and hairline [r]rects, 123 // stroked rects, 124 // stroked and hairline lines, 125 // stroked circular rrects 126 // Note: clipping can bump a draw out of the simple shape path 127 kSimpleShape = 0b0100, 128 // All other shapes (e.g., any strokeAndFill shape, non-circular-stroked RRects, SkPaths, ...) 129 kNonSimpleShape = 0b1000, 130 131 kShape = kSimpleShape | kNonSimpleShape, 132 133 kMostCommon = kText | kShape, 134 kAll = kText | kDrawVertices | kShape 135 }; 136 137 } // namespace skgpu::graphite 138 139 #endif // skgpu_graphite_GraphiteTypes_DEFINED 140