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