1 /* 2 * Copyright 2017 Google Inc. 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 #ifndef skgpu_ganesh_TextureOp_DEFINED 8 #define skgpu_ganesh_TextureOp_DEFINED 9 10 #include "include/core/SkCanvas.h" 11 #include "include/core/SkRefCnt.h" 12 #include "include/private/gpu/ganesh/GrTypesPriv.h" 13 #include "src/gpu/ganesh/GrColor.h" 14 #include "src/gpu/ganesh/GrSamplerState.h" 15 #include "src/gpu/ganesh/ops/GrOp.h" 16 17 struct DrawQuad; 18 class GrClip; 19 class GrColorSpaceXform; 20 class GrDrawOp; 21 class GrTextureProxy; 22 struct GrTextureSetEntry; 23 struct SkRect; 24 class SkMatrix; 25 26 namespace skgpu::v1 { 27 class SurfaceDrawContext; 28 } 29 30 namespace skgpu::ganesh { 31 32 class SurfaceDrawContext; 33 34 class TextureOp { 35 public: 36 37 /** 38 * Controls whether saturate() is called after the texture is color-converted to ensure all 39 * color values are in 0..1 range. 40 */ 41 enum class Saturate : bool { kNo = false, kYes = true }; 42 43 /** 44 * Creates an op that draws a sub-quadrilateral of a texture. The passed color is modulated by 45 * the texture's color. 'deviceQuad' specifies the device-space coordinates to draw, using 46 * 'localQuad' to map into the proxy's texture space. If non-null, 'subset' represents the 47 * boundary for the strict src rect constraint. If GrAAType is kCoverage then AA is applied to 48 * the edges indicated by GrQuadAAFlags. Otherwise, GrQuadAAFlags is ignored. 49 * 50 * This is functionally very similar to FillRectOp::Make, except that the GrPaint has been 51 * deconstructed into the texture, filter, modulating color, and blend mode. When blend mode is 52 * src over, this will return a FillRectOp with a paint that samples the proxy. 53 */ 54 static GrOp::Owner Make(GrRecordingContext*, 55 GrSurfaceProxyView, 56 SkAlphaType srcAlphaType, 57 sk_sp<GrColorSpaceXform>, 58 GrSamplerState::Filter, 59 GrSamplerState::MipmapMode, 60 const SkPMColor4f&, 61 Saturate, 62 SkBlendMode, 63 GrAAType, 64 DrawQuad*, 65 const SkRect* subset = nullptr); 66 67 // Automatically falls back to using one FillRectOp per entry if dynamic states are not 68 // supported, or if the blend mode is not src-over. 'cnt' is the size of the entry array. 69 // 'proxyCnt' <= 'cnt' and represents the number of proxy switches within the array. 70 static void AddTextureSetOps(skgpu::v1::SurfaceDrawContext*, 71 const GrClip*, 72 GrRecordingContext*, 73 GrTextureSetEntry[], 74 int cnt, 75 int proxyRunCnt, 76 GrSamplerState::Filter, 77 GrSamplerState::MipmapMode, 78 Saturate, 79 SkBlendMode, 80 GrAAType, 81 SkCanvas::SrcRectConstraint, 82 const SkMatrix& viewMatrix, 83 sk_sp<GrColorSpaceXform> textureXform); 84 85 #if GR_TEST_UTILS 86 static uint32_t ClassID(); 87 #endif 88 89 private: 90 class BatchSizeLimiter; 91 }; 92 93 } // namespace skgpu::ganesh 94 95 #endif // skgpu_ganesh_TextureOp_DEFINED 96