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