OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrXferProcessor_DEFINED | 8 #ifndef GrXferProcessor_DEFINED |
9 #define GrXferProcessor_DEFINED | 9 #define GrXferProcessor_DEFINED |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 * seconday fragment shader output color. When allowed by the backend API, the G
rXferProcessor may | 97 * seconday fragment shader output color. When allowed by the backend API, the G
rXferProcessor may |
98 * read the destination color. The GrXferProcessor is responsible for setting th
e blend coefficients | 98 * read the destination color. The GrXferProcessor is responsible for setting th
e blend coefficients |
99 * and blend constant color. | 99 * and blend constant color. |
100 * | 100 * |
101 * A GrXferProcessor is never installed directly into our draw state, but instea
d is created from a | 101 * A GrXferProcessor is never installed directly into our draw state, but instea
d is created from a |
102 * GrXPFactory once we have finalized the state of our draw. | 102 * GrXPFactory once we have finalized the state of our draw. |
103 */ | 103 */ |
104 class GrXferProcessor : public GrProcessor { | 104 class GrXferProcessor : public GrProcessor { |
105 public: | 105 public: |
106 /** | 106 /** |
107 * A texture that contains the dst pixel values and an integer coord offset
from device space | |
108 * to the space of the texture. Depending on GPU capabilities a DstTexture m
ay be used by a | |
109 * GrXferProcessor for blending in the fragment shader. | |
110 */ | |
111 class DstTexture { | |
112 public: | |
113 DstTexture() { fOffset.set(0, 0); } | |
114 | |
115 DstTexture(const DstTexture& other) { | |
116 *this = other; | |
117 } | |
118 | |
119 DstTexture(GrTexture* texture, const SkIPoint& offset) | |
120 : fTexture(SkSafeRef(texture)) | |
121 , fOffset(offset) { | |
122 } | |
123 | |
124 DstTexture& operator=(const DstTexture& other) { | |
125 fTexture.reset(SkSafeRef(other.fTexture.get())); | |
126 fOffset = other.fOffset; | |
127 return *this; | |
128 } | |
129 | |
130 const SkIPoint& offset() const { return fOffset; } | |
131 | |
132 void setOffset(const SkIPoint& offset) { fOffset = offset; } | |
133 void setOffset(int ox, int oy) { fOffset.set(ox, oy); } | |
134 | |
135 GrTexture* texture() const { return fTexture.get(); } | |
136 | |
137 GrTexture* setTexture(GrTexture* texture) { | |
138 fTexture.reset(SkSafeRef(texture)); | |
139 return texture; | |
140 } | |
141 | |
142 private: | |
143 SkAutoTUnref<GrTexture> fTexture; | |
144 SkIPoint fOffset; | |
145 }; | |
146 | |
147 /** | |
148 * Sets a unique key on the GrProcessorKeyBuilder calls onGetGLProcessorKey(
...) to get the | 107 * Sets a unique key on the GrProcessorKeyBuilder calls onGetGLProcessorKey(
...) to get the |
149 * specific subclass's key. | 108 * specific subclass's key. |
150 */ | 109 */ |
151 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) con
st; | 110 void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) con
st; |
152 | 111 |
153 /** Returns a new instance of the appropriate *GL* implementation class | 112 /** Returns a new instance of the appropriate *GL* implementation class |
154 for the given GrXferProcessor; caller is responsible for deleting | 113 for the given GrXferProcessor; caller is responsible for deleting |
155 the object. */ | 114 the object. */ |
156 virtual GrGLXferProcessor* createGLInstance() const = 0; | 115 virtual GrGLXferProcessor* createGLInstance() const = 0; |
157 | 116 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 this->onGetBlendInfo(blendInfo); | 192 this->onGetBlendInfo(blendInfo); |
234 } | 193 } |
235 | 194 |
236 bool willReadDstColor() const { return fWillReadDstColor; } | 195 bool willReadDstColor() const { return fWillReadDstColor; } |
237 | 196 |
238 /** | 197 /** |
239 * Returns the texture to be used as the destination when reading the dst in
the fragment | 198 * Returns the texture to be used as the destination when reading the dst in
the fragment |
240 * shader. If the returned texture is NULL then the XP is either not reading
the dst or we have | 199 * shader. If the returned texture is NULL then the XP is either not reading
the dst or we have |
241 * extentions that support framebuffer fetching and thus don't need a copy o
f the dst texture. | 200 * extentions that support framebuffer fetching and thus don't need a copy o
f the dst texture. |
242 */ | 201 */ |
243 const GrTexture* getDstTexture() const { return fDstTexture.getTexture(); } | 202 const GrTexture* getDstCopyTexture() const { return fDstCopy.getTexture(); } |
244 | 203 |
245 /** | 204 /** |
246 * Returns the offset in device coords to use when accessing the dst texture
to get the dst | 205 * Returns the offset into the DstCopyTexture to use when reading it in the
shader. This value |
247 * pixel color in the shader. This value is only valid if getDstTexture() !=
NULL. | 206 * is only valid if getDstCopyTexture() != NULL. |
248 */ | 207 */ |
249 const SkIPoint& dstTextureOffset() const { | 208 const SkIPoint& dstCopyTextureOffset() const { |
250 SkASSERT(this->getDstTexture()); | 209 SkASSERT(this->getDstCopyTexture()); |
251 return fDstTextureOffset; | 210 return fDstCopyTextureOffset; |
252 } | 211 } |
253 | 212 |
254 /** | 213 /** |
255 * Returns whether or not the XP will look at coverage when doing its blendi
ng. | 214 * Returns whether or not the XP will look at coverage when doing its blendi
ng. |
256 */ | 215 */ |
257 bool readsCoverage() const { return fReadsCoverage; } | 216 bool readsCoverage() const { return fReadsCoverage; } |
258 | 217 |
259 /** | 218 /** |
260 * Returns whether or not this xferProcossor will set a secondary output to
be used with dual | 219 * Returns whether or not this xferProcossor will set a secondary output to
be used with dual |
261 * source blending. | 220 * source blending. |
(...skipping 10 matching lines...) Expand all Loading... |
272 bool isEqual(const GrXferProcessor& that) const { | 231 bool isEqual(const GrXferProcessor& that) const { |
273 if (this->classID() != that.classID()) { | 232 if (this->classID() != that.classID()) { |
274 return false; | 233 return false; |
275 } | 234 } |
276 if (this->fWillReadDstColor != that.fWillReadDstColor) { | 235 if (this->fWillReadDstColor != that.fWillReadDstColor) { |
277 return false; | 236 return false; |
278 } | 237 } |
279 if (this->fReadsCoverage != that.fReadsCoverage) { | 238 if (this->fReadsCoverage != that.fReadsCoverage) { |
280 return false; | 239 return false; |
281 } | 240 } |
282 if (this->fDstTexture.getTexture() != that.fDstTexture.getTexture()) { | 241 if (this->fDstCopy.getTexture() != that.fDstCopy.getTexture()) { |
283 return false; | 242 return false; |
284 } | 243 } |
285 if (this->fDstTextureOffset != that.fDstTextureOffset) { | 244 if (this->fDstCopyTextureOffset != that.fDstCopyTextureOffset) { |
286 return false; | 245 return false; |
287 } | 246 } |
288 return this->onIsEqual(that); | 247 return this->onIsEqual(that); |
289 } | 248 } |
290 | 249 |
291 protected: | 250 protected: |
292 GrXferProcessor(); | 251 GrXferProcessor(); |
293 GrXferProcessor(const DstTexture*, bool willReadDstColor); | 252 GrXferProcessor(const GrDeviceCoordTexture* dstCopy, bool willReadDstColor); |
294 | 253 |
295 private: | 254 private: |
296 virtual OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 255 virtual OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
297 const GrProcOptInfo& coveragePOI, | 256 const GrProcOptInfo& coveragePOI, |
298 bool doesStencilWrite, | 257 bool doesStencilWrite, |
299 GrColor* overrideColor, | 258 GrColor* overrideColor, |
300 const GrCaps& caps) = 0; | 259 const GrCaps& caps) = 0; |
301 | 260 |
302 /** | 261 /** |
303 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this xfer | 262 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this xfer |
(...skipping 16 matching lines...) Expand all Loading... |
320 * Retrieves the hardware blend state required by this Xfer processor. The B
lendInfo struct | 279 * Retrieves the hardware blend state required by this Xfer processor. The B
lendInfo struct |
321 * comes initialized to default values, so the Xfer processor only needs to
set the state it | 280 * comes initialized to default values, so the Xfer processor only needs to
set the state it |
322 * needs. It may not even need to override this method at all. | 281 * needs. It may not even need to override this method at all. |
323 */ | 282 */ |
324 virtual void onGetBlendInfo(BlendInfo*) const {} | 283 virtual void onGetBlendInfo(BlendInfo*) const {} |
325 | 284 |
326 virtual bool onIsEqual(const GrXferProcessor&) const = 0; | 285 virtual bool onIsEqual(const GrXferProcessor&) const = 0; |
327 | 286 |
328 bool fWillReadDstColor; | 287 bool fWillReadDstColor; |
329 bool fReadsCoverage; | 288 bool fReadsCoverage; |
330 SkIPoint fDstTextureOffset; | 289 SkIPoint fDstCopyTextureOffset; |
331 GrTextureAccess fDstTexture; | 290 GrTextureAccess fDstCopy; |
332 | 291 |
333 typedef GrFragmentProcessor INHERITED; | 292 typedef GrFragmentProcessor INHERITED; |
334 }; | 293 }; |
335 | 294 |
336 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); | 295 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); |
337 | 296 |
338 /////////////////////////////////////////////////////////////////////////////// | 297 /////////////////////////////////////////////////////////////////////////////// |
339 | 298 |
340 /** | 299 /** |
341 * We install a GrXPFactory (XPF) early on in the pipeline before all the final
draw information is | 300 * We install a GrXPFactory (XPF) early on in the pipeline before all the final
draw information is |
342 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or
4 channel, is the | 301 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or
4 channel, is the |
343 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a
long with all the | 302 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a
long with all the |
344 * draw information to create a GrXferProcessor (XP) which can implement the des
ired blending for | 303 * draw information to create a GrXferProcessor (XP) which can implement the des
ired blending for |
345 * the draw. | 304 * the draw. |
346 * | 305 * |
347 * Before the XP is created, the XPF is able to answer queries about what functi
onality the XPs it | 306 * Before the XP is created, the XPF is able to answer queries about what functi
onality the XPs it |
348 * creates will have. For example, can it create an XP that supports RGB coverag
e or will the XP | 307 * creates will have. For example, can it create an XP that supports RGB coverag
e or will the XP |
349 * blend with the destination color. | 308 * blend with the destination color. |
350 */ | 309 */ |
351 class GrXPFactory : public SkRefCnt { | 310 class GrXPFactory : public SkRefCnt { |
352 public: | 311 public: |
353 typedef GrXferProcessor::DstTexture DstTexture; | |
354 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, | 312 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, |
355 const GrProcOptInfo& coveragePOI, | 313 const GrProcOptInfo& coveragePOI, |
356 const DstTexture*, | 314 const GrDeviceCoordTexture* dstCopy, |
357 const GrCaps& caps) const; | 315 const GrCaps& caps) const; |
358 | 316 |
359 /** | 317 /** |
360 * This function returns true if the GrXferProcessor generated from this fac
tory will be able to | 318 * This function returns true if the GrXferProcessor generated from this fac
tory will be able to |
361 * correctly blend when using RGB coverage. The knownColor and knownColorFla
gs represent the | 319 * correctly blend when using RGB coverage. The knownColor and knownColorFla
gs represent the |
362 * final computed color from the color stages. | 320 * final computed color from the color stages. |
363 */ | 321 */ |
364 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag
s) const = 0; | 322 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag
s) const = 0; |
365 | 323 |
366 struct InvariantOutput { | 324 struct InvariantOutput { |
367 bool fWillBlendWithDst; | 325 bool fWillBlendWithDst; |
368 GrColor fBlendedColor; | 326 GrColor fBlendedColor; |
369 uint32_t fBlendedColorFlags; | 327 uint32_t fBlendedColorFlags; |
370 }; | 328 }; |
371 | 329 |
372 /** | 330 /** |
373 * This function returns known information about the output of the xfer proc
essor produced by | 331 * This function returns known information about the output of the xfer proc
essor produced by |
374 * this xp factory. The invariant color information returned by this functio
n refers to the | 332 * this xp factory. The invariant color information returned by this functio
n refers to the |
375 * final color produced after all blending. | 333 * final color produced after all blending. |
376 */ | 334 */ |
377 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO
ptInfo& coveragePOI, | 335 virtual void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcO
ptInfo& coveragePOI, |
378 InvariantOutput*) const = 0; | 336 InvariantOutput*) const = 0; |
379 | 337 |
380 bool willNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI, | 338 bool willNeedDstCopy(const GrCaps& caps, const GrProcOptInfo& colorPOI, |
381 const GrProcOptInfo& coveragePOI) const; | 339 const GrProcOptInfo& coveragePOI) const; |
382 | 340 |
383 bool isEqual(const GrXPFactory& that) const { | 341 bool isEqual(const GrXPFactory& that) const { |
384 if (this->classID() != that.classID()) { | 342 if (this->classID() != that.classID()) { |
385 return false; | 343 return false; |
386 } | 344 } |
387 return this->onIsEqual(that); | 345 return this->onIsEqual(that); |
388 } | 346 } |
389 | 347 |
390 /** | 348 /** |
391 * Helper for down-casting to a GrXPFactory subclass | 349 * Helper for down-casting to a GrXPFactory subclass |
392 */ | 350 */ |
393 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } | 351 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } |
394 | 352 |
395 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return
fClassID; } | 353 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return
fClassID; } |
396 | 354 |
397 protected: | 355 protected: |
398 GrXPFactory() : fClassID(kIllegalXPFClassID) {} | 356 GrXPFactory() : fClassID(kIllegalXPFClassID) {} |
399 | 357 |
400 template <typename XPF_SUBCLASS> void initClassID() { | 358 template <typename XPF_SUBCLASS> void initClassID() { |
401 static uint32_t kClassID = GenClassID(); | 359 static uint32_t kClassID = GenClassID(); |
402 fClassID = kClassID; | 360 fClassID = kClassID; |
403 } | 361 } |
404 | 362 |
405 uint32_t fClassID; | 363 uint32_t fClassID; |
406 | 364 |
407 private: | 365 private: |
408 virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, | 366 virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, |
409 const GrProcOptInfo& colorPOI
, | 367 const GrProcOptInfo& colorPOI
, |
410 const GrProcOptInfo& coverage
POI, | 368 const GrProcOptInfo& coverage
POI, |
411 const DstTexture*) const = 0; | 369 const GrDeviceCoordTexture* d
stCopy) const = 0; |
412 /** | 370 /** |
413 * Returns true if the XP generated by this factory will explicitly read ds
t in the fragment | 371 * Returns true if the XP generated by this factory will explicitly read ds
t in the fragment |
414 * shader. | 372 * shader. |
415 */ | 373 */ |
416 virtual bool willReadDstColor(const GrCaps& caps, | 374 virtual bool willReadDstColor(const GrCaps& caps, |
417 const GrProcOptInfo& colorPOI, | 375 const GrProcOptInfo& colorPOI, |
418 const GrProcOptInfo& coveragePOI) const = 0; | 376 const GrProcOptInfo& coveragePOI) const = 0; |
419 | 377 |
420 virtual bool onIsEqual(const GrXPFactory&) const = 0; | 378 virtual bool onIsEqual(const GrXPFactory&) const = 0; |
421 | 379 |
(...skipping 12 matching lines...) Expand all Loading... |
434 enum { | 392 enum { |
435 kIllegalXPFClassID = 0, | 393 kIllegalXPFClassID = 0, |
436 }; | 394 }; |
437 static int32_t gCurrXPFClassID; | 395 static int32_t gCurrXPFClassID; |
438 | 396 |
439 typedef GrProgramElement INHERITED; | 397 typedef GrProgramElement INHERITED; |
440 }; | 398 }; |
441 | 399 |
442 #endif | 400 #endif |
443 | 401 |
OLD | NEW |