xref: /third_party/skia/src/gpu/ops/TextureOp.h (revision cb93a386)
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 TextureOp_DEFINED
8#define TextureOp_DEFINED
9
10#include "include/core/SkCanvas.h"
11#include "include/core/SkRefCnt.h"
12#include "include/private/GrTypesPriv.h"
13#include "src/gpu/GrColor.h"
14#include "src/gpu/GrSamplerState.h"
15#include "src/gpu/ops/GrOp.h"
16
17struct DrawQuad;
18class GrClip;
19class GrColorSpaceXform;
20class GrDrawOp;
21class GrTextureProxy;
22struct GrTextureSetEntry;
23struct SkRect;
24class SkMatrix;
25
26namespace skgpu::v1 {
27
28class SurfaceDrawContext;
29
30class TextureOp {
31public:
32
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 };
38
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
42     * 'localQuad' to map into the proxy's texture space. If non-null, 'subset' represents the
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     *
46     * This is functionally very similar to FillRectOp::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 FillRectOp with a paint that samples the proxy.
49     */
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);
62
63#if SK_GPU_V1
64    // Automatically falls back to using one FillRectOp per entry if dynamic states are not
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.
67    static void AddTextureSetOps(skgpu::v1::SurfaceDrawContext*,
68                                 const GrClip*,
69                                 GrRecordingContext*,
70                                 GrTextureSetEntry[],
71                                 int cnt,
72                                 int proxyRunCnt,
73                                 GrSamplerState::Filter,
74                                 GrSamplerState::MipmapMode,
75                                 Saturate,
76                                 SkBlendMode,
77                                 GrAAType,
78                                 SkCanvas::SrcRectConstraint,
79                                 const SkMatrix& viewMatrix,
80                                 sk_sp<GrColorSpaceXform> textureXform);
81#endif
82
83#if GR_TEST_UTILS
84    static uint32_t ClassID();
85#endif
86
87private:
88    class BatchSizeLimiter;
89};
90
91} // namespace skgpu::v1
92
93#endif  // TextureOp_DEFINED
94