OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2014 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 | |
8 #ifndef GrOptDrawState_DEFINED | |
9 #define GrOptDrawState_DEFINED | |
10 | |
11 #include "GrColor.h" | |
12 #include "GrGpu.h" | |
13 #include "GrPendingFragmentStage.h" | |
14 #include "GrProgramDesc.h" | |
15 #include "GrStencil.h" | |
16 #include "GrTypesPriv.h" | |
17 #include "SkMatrix.h" | |
18 #include "SkRefCnt.h" | |
19 | |
20 class GrDeviceCoordTexture; | |
21 class GrDrawState; | |
22 class GrPathProcessor; | |
23 | |
24 /** | |
25 * Class that holds an optimized version of a GrDrawState. It is meant to be an
immutable class, | |
26 * and contains all data needed to set the state for a gpu draw. | |
27 */ | |
28 class GrOptDrawState { | |
29 public: | |
30 SK_DECLARE_INST_COUNT(GrOptDrawState) | |
31 | |
32 GrOptDrawState(const GrDrawState& drawState, const GrPrimitiveProcessor*, | |
33 const GrDrawTargetCaps&, const GrScissorState&, | |
34 const GrDeviceCoordTexture* dstCopy); | |
35 | |
36 /* | |
37 * Returns true if it is possible to combine the two GrOptDrawStates and it
will update 'this' | |
38 * to subsume 'that''s draw. | |
39 */ | |
40 bool isEqual(const GrOptDrawState& that) const; | |
41 | |
42 /// @} | |
43 | |
44 /////////////////////////////////////////////////////////////////////////// | |
45 /// @name Effect Stages | |
46 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the | |
47 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables | |
48 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, | |
49 /// the fragment position, local coordinates). | |
50 /// | |
51 /// The stages are divided into two sets, color-computing and coverage-compu
ting. The final | |
52 /// color stage produces the final pixel color. The coverage-computing stage
s function exactly | |
53 /// as the color-computing but the output of the final coverage stage is tre
ated as a fractional | |
54 /// pixel coverage rather than as input to the src/dst color blend step. | |
55 /// | |
56 /// The input color to the first color-stage is either the constant color or
interpolated | |
57 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage | |
58 /// (usually full-coverage) or interpolated per-vertex coverage. | |
59 //// | |
60 | |
61 int numColorStages() const { return fNumColorStages; } | |
62 int numCoverageStages() const { return fFragmentStages.count() - fNumColorSt
ages; } | |
63 int numFragmentStages() const { return fFragmentStages.count(); } | |
64 | |
65 const GrXferProcessor* getXferProcessor() const { return fXferProcessor.get(
); } | |
66 | |
67 const GrPendingFragmentStage& getColorStage(int idx) const { | |
68 SkASSERT(idx < this->numColorStages()); | |
69 return fFragmentStages[idx]; | |
70 } | |
71 const GrPendingFragmentStage& getCoverageStage(int idx) const { | |
72 SkASSERT(idx < this->numCoverageStages()); | |
73 return fFragmentStages[fNumColorStages + idx]; | |
74 } | |
75 const GrPendingFragmentStage& getFragmentStage(int idx) const { | |
76 return fFragmentStages[idx]; | |
77 } | |
78 | |
79 /// @} | |
80 | |
81 /////////////////////////////////////////////////////////////////////////// | |
82 /// @name Render Target | |
83 //// | |
84 | |
85 /** | |
86 * Retrieves the currently set render-target. | |
87 * | |
88 * @return The currently set render target. | |
89 */ | |
90 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } | |
91 | |
92 /// @} | |
93 | |
94 /////////////////////////////////////////////////////////////////////////// | |
95 /// @name Stencil | |
96 //// | |
97 | |
98 const GrStencilSettings& getStencil() const { return fStencilSettings; } | |
99 | |
100 /// @} | |
101 | |
102 /////////////////////////////////////////////////////////////////////////// | |
103 /// @name ScissorState | |
104 //// | |
105 | |
106 const GrScissorState& getScissorState() const { return fScissorState; } | |
107 | |
108 /// @} | |
109 | |
110 /////////////////////////////////////////////////////////////////////////// | |
111 /// @name Boolean Queries | |
112 //// | |
113 | |
114 bool isDitherState() const { return SkToBool(fFlags & kDither_Flag); } | |
115 bool isHWAntialiasState() const { return SkToBool(fFlags & kHWAA_Flag); } | |
116 bool mustSkip() const { return NULL == this->getRenderTarget(); } | |
117 | |
118 /// @} | |
119 | |
120 /** | |
121 * Gets whether the target is drawing clockwise, counterclockwise, | |
122 * or both faces. | |
123 * @return the current draw face(s). | |
124 */ | |
125 GrDrawState::DrawFace getDrawFace() const { return fDrawFace; } | |
126 | |
127 /// @} | |
128 | |
129 /////////////////////////////////////////////////////////////////////////// | |
130 | |
131 const GrDeviceCoordTexture* getDstCopy() const { return fDstCopy.texture() ?
&fDstCopy : NULL; } | |
132 | |
133 const GrProgramDesc::DescInfo& descInfo() const { return fDescInfo; } | |
134 | |
135 const GrGeometryProcessor::InitBT& getInitBatchTracker() const { return fIni
tBT; } | |
136 | |
137 private: | |
138 /** | |
139 * Alter the program desc and inputs (attribs and processors) based on the b
lend optimization. | |
140 */ | |
141 void adjustProgramFromOptimizations(const GrDrawState& ds, | |
142 GrXferProcessor::OptFlags, | |
143 const GrProcOptInfo& colorPOI, | |
144 const GrProcOptInfo& coveragePOI, | |
145 int* firstColorStageIdx, | |
146 int* firstCoverageStageIdx); | |
147 | |
148 /** | |
149 * Calculates the primary and secondary output types of the shader. For cert
ain output types | |
150 * the function may adjust the blend coefficients. After this function is ca
lled the src and dst | |
151 * blend coeffs will represent those used by backend API. | |
152 */ | |
153 void setOutputStateInfo(const GrDrawState& ds, GrXferProcessor::OptFlags, | |
154 const GrDrawTargetCaps&); | |
155 | |
156 enum Flags { | |
157 kDither_Flag = 0x1, | |
158 kHWAA_Flag = 0x2, | |
159 }; | |
160 | |
161 typedef GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> RenderTarget; | |
162 typedef SkSTArray<8, GrPendingFragmentStage> FragmentStageArray; | |
163 typedef GrPendingProgramElement<const GrXferProcessor> ProgramXferProcessor; | |
164 RenderTarget fRenderTarget; | |
165 GrScissorState fScissorState; | |
166 GrStencilSettings fStencilSettings; | |
167 GrDrawState::DrawFace fDrawFace; | |
168 GrDeviceCoordTexture fDstCopy; | |
169 uint32_t fFlags; | |
170 ProgramXferProcessor fXferProcessor; | |
171 FragmentStageArray fFragmentStages; | |
172 GrProgramDesc::DescInfo fDescInfo; | |
173 GrGeometryProcessor::InitBT fInitBT; | |
174 | |
175 // This function is equivalent to the offset into fFragmentStages where cove
rage stages begin. | |
176 int fNumColorStages; | |
177 | |
178 GrProgramDesc fDesc; | |
179 | |
180 typedef SkRefCnt INHERITED; | |
181 }; | |
182 | |
183 #endif | |
OLD | NEW |