blob: d976c902e0f31f512c01f466ef70a2b5027721cd [file] [log] [blame]
Brian Salomon34169692017-08-28 15:32:01 -04001/*
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 Phillips21453902021-08-27 16:05:04 -04007#ifndef TextureOp_DEFINED
8#define TextureOp_DEFINED
Brian Salomon34169692017-08-28 15:32:01 -04009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkCanvas.h"
11#include "include/core/SkRefCnt.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/private/GrTypesPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040013#include "src/gpu/GrColor.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040014#include "src/gpu/GrSamplerState.h"
Robert Phillipse40495d2021-07-20 09:40:13 -040015#include "src/gpu/ops/GrOp.h"
Brian Salomon34169692017-08-28 15:32:01 -040016
Robert Phillipse40495d2021-07-20 09:40:13 -040017struct DrawQuad;
18class GrClip;
Brian Osmand49e9462017-10-16 13:17:48 -040019class GrColorSpaceXform;
Brian Salomon34169692017-08-28 15:32:01 -040020class GrDrawOp;
21class GrTextureProxy;
Robert Phillipse40495d2021-07-20 09:40:13 -040022struct GrTextureSetEntry;
Brian Salomon34169692017-08-28 15:32:01 -040023struct SkRect;
24class SkMatrix;
25
Robert Phillips21453902021-08-27 16:05:04 -040026namespace skgpu::v1 {
27
28class SurfaceDrawContext;
29
30class TextureOp {
Robert Phillipse837e612019-11-15 11:02:50 -050031public:
Brian Salomonb80ffee2018-05-23 16:39:39 -040032
Robert Phillipse837e612019-11-15 11:02:50 -050033 /**
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 Salomonf19f9ca2019-09-18 15:54:26 -040038
Robert Phillipse837e612019-11-15 11:02:50 -050039 /**
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 Salomon2432d062020-04-16 20:48:09 -040042 * 'localQuad' to map into the proxy's texture space. If non-null, 'subset' represents the
Robert Phillipse837e612019-11-15 11:02:50 -050043 * 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 *
46 * This is functionally very similar to GrFillRectOp::Make, except that the GrPaint has been
47 * deconstructed into the texture, filter, modulating color, and blend mode. When blend mode is
48 * src over, this will return a GrFillRectOp with a paint that samples the proxy.
49 */
Herb Derbyc76d4092020-10-07 16:46:15 -040050 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 Ludwig009b92e2019-02-15 16:03:53 -050062
Robert Phillips46eb3ab2021-08-02 17:09:01 -040063#if SK_GPU_V1
Michael Ludwigfe13ca32019-11-21 10:26:41 -050064 // Automatically falls back to using one GrFillRectOp per entry if dynamic states are not
Michael Ludwig379e4962019-12-06 13:21:26 -050065 // 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 Phillips4dca8312021-07-28 15:13:20 -040067 static void AddTextureSetOps(skgpu::v1::SurfaceDrawContext*,
68 const GrClip*,
Michael Ludwigfe13ca32019-11-21 10:26:41 -050069 GrRecordingContext*,
Robert Phillipse40495d2021-07-20 09:40:13 -040070 GrTextureSetEntry[],
Michael Ludwigfe13ca32019-11-21 10:26:41 -050071 int cnt,
Michael Ludwig379e4962019-12-06 13:21:26 -050072 int proxyRunCnt,
Michael Ludwigfe13ca32019-11-21 10:26:41 -050073 GrSamplerState::Filter,
Brian Salomone69b9ef2020-07-22 11:18:06 -040074 GrSamplerState::MipmapMode,
Michael Ludwigfe13ca32019-11-21 10:26:41 -050075 Saturate,
76 SkBlendMode,
77 GrAAType,
78 SkCanvas::SrcRectConstraint,
79 const SkMatrix& viewMatrix,
80 sk_sp<GrColorSpaceXform> textureXform);
Robert Phillips46eb3ab2021-08-02 17:09:01 -040081#endif
Michael Ludwiga3c45c72019-01-17 17:26:48 -050082
Robert Phillipse837e612019-11-15 11:02:50 -050083#if GR_TEST_UTILS
84 static uint32_t ClassID();
85#endif
86
87private:
88 class BatchSizeLimiter;
89};
90
Robert Phillips21453902021-08-27 16:05:04 -040091} // namespace skgpu::v1
92
93#endif // TextureOp_DEFINED