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
17class GrColorSpaceXform;
18class GrDrawOp;
19class GrTextureProxy;
20struct SkRect;
21class SkMatrix;
22
23class GrTextureOp {
24public:
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, 'subset' 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 GrSamplerState::MipmapMode,
49 const SkPMColor4f&,
50 Saturate,
51 SkBlendMode,
52 GrAAType,
53 DrawQuad*,
54 const SkRect* subset = nullptr);
55
56 // Automatically falls back to using one GrFillRectOp per entry if dynamic states are not
57 // supported, or if the blend mode is not src-over. 'cnt' is the size of the entry array.
58 // 'proxyCnt' <= 'cnt' and represents the number of proxy switches within the array.
59 static void AddTextureSetOps(GrRenderTargetContext*,
60 const GrClip* clip,
61 GrRecordingContext*,
62 GrRenderTargetContext::TextureSetEntry[],
63 int cnt,
64 int proxyRunCnt,
65 GrSamplerState::Filter,
66 GrSamplerState::MipmapMode,
67 Saturate,
68 SkBlendMode,
69 GrAAType,
70 SkCanvas::SrcRectConstraint,
71 const SkMatrix& viewMatrix,
72 sk_sp<GrColorSpaceXform> textureXform);
73
74#if GR_TEST_UTILS
75 static uint32_t ClassID();
76#endif
77
78private:
79 class BatchSizeLimiter;
80};
81
82#endif // GrTextureOp_DEFINED
83