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