1 /* 2 * Copyright 2024 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_precompile_Precompile_DEFINED 9 #define skgpu_graphite_precompile_Precompile_DEFINED 10 11 #include "include/core/SkColorSpace.h" 12 #include "include/core/SkColorType.h" 13 #include "include/core/SkSpan.h" 14 #include "include/gpu/graphite/GraphiteTypes.h" 15 16 namespace skgpu::graphite { 17 18 class PaintOptions; 19 class PrecompileContext; 20 21 /** 22 * Describes the required properties of a RenderPass that will be combined with the 23 * other portions of the Precompilation API (i.e., paintOptions and drawTypes) to yield 24 * a pipeline. 25 */ 26 struct SK_API RenderPassProperties { 27 bool operator==(const RenderPassProperties& other) const { 28 return fDSFlags == other.fDSFlags && 29 fDstCT == other.fDstCT && 30 fRequiresMSAA == other.fRequiresMSAA && 31 SkColorSpace::Equals(fDstCS.get(), other.fDstCS.get()); 32 } 33 bool operator!= (const RenderPassProperties& other) const { return !(*this == other); } 34 35 DepthStencilFlags fDSFlags = DepthStencilFlags::kNone; 36 SkColorType fDstCT = kRGBA_8888_SkColorType; 37 sk_sp<SkColorSpace> fDstCS = nullptr; 38 bool fRequiresMSAA = false; 39 }; 40 41 /** 42 * Precompilation allows clients to create pipelines ahead of time based on what they expect 43 * to draw. This can reduce performance hitches, due to inline compilation, during the actual 44 * drawing. Graphite will always be able to perform an inline compilation if some SkPaint 45 * combination was omitted from precompilation. 46 * 47 * @param precompileContext thread-safe helper holding required portions of the Context 48 * @param paintOptions captures a set of SkPaints that will be drawn 49 * @param drawTypes communicates which primitives those paints will be drawn with 50 * @param renderPassProperties describes the RenderPasses needed for the desired Pipelines 51 */ 52 void SK_API Precompile(PrecompileContext* precompileContext, 53 const PaintOptions& paintOptions, 54 DrawTypeFlags drawTypes, 55 SkSpan<const RenderPassProperties> renderPassProperties); 56 57 } // namespace skgpu::graphite 58 59 #endif // skgpu_graphite_precompile_Precompile_DEFINED 60