| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 /** | 245 /** |
| 246 * Returns the offset in device coords to use when accessing the dst texture
to get the dst | 246 * Returns the offset in device coords to use when accessing the dst texture
to get the dst |
| 247 * pixel color in the shader. This value is only valid if getDstTexture() !=
NULL. | 247 * pixel color in the shader. This value is only valid if getDstTexture() !=
NULL. |
| 248 */ | 248 */ |
| 249 const SkIPoint& dstTextureOffset() const { | 249 const SkIPoint& dstTextureOffset() const { |
| 250 SkASSERT(this->getDstTexture()); | 250 SkASSERT(this->getDstTexture()); |
| 251 return fDstTextureOffset; | 251 return fDstTextureOffset; |
| 252 } | 252 } |
| 253 | 253 |
| 254 /** | 254 /** |
| 255 * If we are performing a dst read, returns whether the base class will use
mixed samples to |
| 256 * antialias the shader's final output. If not doing a dst read, the subclas
s is responsible |
| 257 * for antialiasing and this returns false. |
| 258 */ |
| 259 bool dstReadUsesMixedSamples() const { return fDstReadUsesMixedSamples; } |
| 260 |
| 261 /** |
| 255 * Returns whether or not the XP will look at coverage when doing its blendi
ng. | 262 * Returns whether or not the XP will look at coverage when doing its blendi
ng. |
| 256 */ | 263 */ |
| 257 bool readsCoverage() const { return fReadsCoverage; } | 264 bool readsCoverage() const { return fReadsCoverage; } |
| 258 | 265 |
| 259 /** | 266 /** |
| 260 * Returns whether or not this xferProcossor will set a secondary output to
be used with dual | 267 * Returns whether or not this xferProcossor will set a secondary output to
be used with dual |
| 261 * source blending. | 268 * source blending. |
| 262 */ | 269 */ |
| 263 bool hasSecondaryOutput() const; | 270 bool hasSecondaryOutput() const; |
| 264 | 271 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 278 } | 285 } |
| 279 if (this->fReadsCoverage != that.fReadsCoverage) { | 286 if (this->fReadsCoverage != that.fReadsCoverage) { |
| 280 return false; | 287 return false; |
| 281 } | 288 } |
| 282 if (this->fDstTexture.getTexture() != that.fDstTexture.getTexture()) { | 289 if (this->fDstTexture.getTexture() != that.fDstTexture.getTexture()) { |
| 283 return false; | 290 return false; |
| 284 } | 291 } |
| 285 if (this->fDstTextureOffset != that.fDstTextureOffset) { | 292 if (this->fDstTextureOffset != that.fDstTextureOffset) { |
| 286 return false; | 293 return false; |
| 287 } | 294 } |
| 295 if (this->fDstReadUsesMixedSamples != that.fDstReadUsesMixedSamples) { |
| 296 return false; |
| 297 } |
| 288 return this->onIsEqual(that); | 298 return this->onIsEqual(that); |
| 289 } | 299 } |
| 290 | 300 |
| 291 protected: | 301 protected: |
| 292 GrXferProcessor(); | 302 GrXferProcessor(); |
| 293 GrXferProcessor(const DstTexture*, bool willReadDstColor); | 303 GrXferProcessor(const DstTexture*, bool willReadDstColor, bool hasMixedSampl
es); |
| 294 | 304 |
| 295 private: | 305 private: |
| 296 virtual OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 306 virtual OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
| 297 const GrProcOptInfo& coveragePOI, | 307 const GrProcOptInfo& coveragePOI, |
| 298 bool doesStencilWrite, | 308 bool doesStencilWrite, |
| 299 GrColor* overrideColor, | 309 GrColor* overrideColor, |
| 300 const GrCaps& caps) = 0; | 310 const GrCaps& caps) = 0; |
| 301 | 311 |
| 302 /** | 312 /** |
| 303 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this xfer | 313 * Sets a unique key on the GrProcessorKeyBuilder that is directly associate
d with this xfer |
| 304 * processor's GL backend implementation. | 314 * processor's GL backend implementation. |
| 305 */ | 315 */ |
| 306 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 316 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 307 GrProcessorKeyBuilder* b) const = 0; | 317 GrProcessorKeyBuilder* b) const = 0; |
| 308 | 318 |
| 309 /** | 319 /** |
| 310 * If not using a texture barrier, retrieves whether the subclass will requi
re a different type | 320 * If not using a texture barrier, retrieves whether the subclass will requi
re a different type |
| 311 * of barrier. | 321 * of barrier. |
| 312 */ | 322 */ |
| 313 virtual bool onWillNeedXferBarrier(const GrRenderTarget*, | 323 virtual bool onWillNeedXferBarrier(const GrRenderTarget*, |
| 314 const GrCaps&, | 324 const GrCaps&, |
| 315 GrXferBarrierType* outBarrierType SK_UNUS
ED) const { | 325 GrXferBarrierType* outBarrierType SK_UNUS
ED) const { |
| 316 return false; | 326 return false; |
| 317 } | 327 } |
| 318 | 328 |
| 319 /** | 329 /** |
| 320 * If we are not performing a dst read, returns whether the subclass will se
t a secondary | 330 * If we are not performing a dst read, returns whether the subclass will se
t a secondary |
| 321 * output. When using dst reads, the base class disables the secondary outpu
t and this method | 331 * output. When using dst reads, the base class controls the secondary outpu
t and this method |
| 322 * will not be called. | 332 * will not be called. |
| 323 */ | 333 */ |
| 324 virtual bool onHasSecondaryOutput() const { return false; } | 334 virtual bool onHasSecondaryOutput() const { return false; } |
| 325 | 335 |
| 326 /** | 336 /** |
| 327 * If we are not performing a dst read, retrieves the fixed-function blend s
tate required by the | 337 * If we are not performing a dst read, retrieves the fixed-function blend s
tate required by the |
| 328 * subclass. When using dst reads, the base class disables fixed-function bl
ending and this | 338 * subclass. When using dst reads, the base class controls the fixed-functio
n blend state and |
| 329 * method will not be called. The BlendInfo struct comes initialized to "no
blending". | 339 * this method will not be called. The BlendInfo struct comes initialized to
"no blending". |
| 330 */ | 340 */ |
| 331 virtual void onGetBlendInfo(BlendInfo*) const {} | 341 virtual void onGetBlendInfo(BlendInfo*) const {} |
| 332 | 342 |
| 333 virtual bool onIsEqual(const GrXferProcessor&) const = 0; | 343 virtual bool onIsEqual(const GrXferProcessor&) const = 0; |
| 334 | 344 |
| 335 bool fWillReadDstColor; | 345 bool fWillReadDstColor; |
| 346 bool fDstReadUsesMixedSamples; |
| 336 bool fReadsCoverage; | 347 bool fReadsCoverage; |
| 337 SkIPoint fDstTextureOffset; | 348 SkIPoint fDstTextureOffset; |
| 338 GrTextureAccess fDstTexture; | 349 GrTextureAccess fDstTexture; |
| 339 | 350 |
| 340 typedef GrFragmentProcessor INHERITED; | 351 typedef GrFragmentProcessor INHERITED; |
| 341 }; | 352 }; |
| 342 | 353 |
| 343 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); | 354 GR_MAKE_BITFIELD_OPS(GrXferProcessor::OptFlags); |
| 344 | 355 |
| 345 /////////////////////////////////////////////////////////////////////////////// | 356 /////////////////////////////////////////////////////////////////////////////// |
| 346 | 357 |
| 347 /** | 358 /** |
| 348 * We install a GrXPFactory (XPF) early on in the pipeline before all the final
draw information is | 359 * We install a GrXPFactory (XPF) early on in the pipeline before all the final
draw information is |
| 349 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or
4 channel, is the | 360 * known (e.g. whether there is fractional pixel coverage, will coverage be 1 or
4 channel, is the |
| 350 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a
long with all the | 361 * draw opaque, etc.). Once the state of the draw is finalized, we use the XPF a
long with all the |
| 351 * draw information to create a GrXferProcessor (XP) which can implement the des
ired blending for | 362 * draw information to create a GrXferProcessor (XP) which can implement the des
ired blending for |
| 352 * the draw. | 363 * the draw. |
| 353 * | 364 * |
| 354 * Before the XP is created, the XPF is able to answer queries about what functi
onality the XPs it | 365 * Before the XP is created, the XPF is able to answer queries about what functi
onality the XPs it |
| 355 * creates will have. For example, can it create an XP that supports RGB coverag
e or will the XP | 366 * creates will have. For example, can it create an XP that supports RGB coverag
e or will the XP |
| 356 * blend with the destination color. | 367 * blend with the destination color. |
| 357 */ | 368 */ |
| 358 class GrXPFactory : public SkRefCnt { | 369 class GrXPFactory : public SkRefCnt { |
| 359 public: | 370 public: |
| 360 typedef GrXferProcessor::DstTexture DstTexture; | 371 typedef GrXferProcessor::DstTexture DstTexture; |
| 361 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, | 372 GrXferProcessor* createXferProcessor(const GrProcOptInfo& colorPOI, |
| 362 const GrProcOptInfo& coveragePOI, | 373 const GrProcOptInfo& coveragePOI, |
| 374 bool hasMixedSamples, |
| 363 const DstTexture*, | 375 const DstTexture*, |
| 364 const GrCaps& caps) const; | 376 const GrCaps& caps) const; |
| 365 | 377 |
| 366 /** | 378 /** |
| 367 * This function returns true if the GrXferProcessor generated from this fac
tory will be able to | 379 * This function returns true if the GrXferProcessor generated from this fac
tory will be able to |
| 368 * correctly blend when using RGB coverage. The knownColor and knownColorFla
gs represent the | 380 * correctly blend when using RGB coverage. The knownColor and knownColorFla
gs represent the |
| 369 * final computed color from the color stages. | 381 * final computed color from the color stages. |
| 370 */ | 382 */ |
| 371 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag
s) const = 0; | 383 virtual bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlag
s) const = 0; |
| 372 | 384 |
| 373 /** | 385 /** |
| 374 * Known color information after blending, but before accounting for any cov
erage. | 386 * Known color information after blending, but before accounting for any cov
erage. |
| 375 */ | 387 */ |
| 376 struct InvariantBlendedColor { | 388 struct InvariantBlendedColor { |
| 377 bool fWillBlendWithDst; | 389 bool fWillBlendWithDst; |
| 378 GrColor fKnownColor; | 390 GrColor fKnownColor; |
| 379 GrColorComponentFlags fKnownColorFlags; | 391 GrColorComponentFlags fKnownColorFlags; |
| 380 }; | 392 }; |
| 381 | 393 |
| 382 /** | 394 /** |
| 383 * Returns information about the output color, produced by XPs from this fac
tory, that will be | 395 * Returns information about the output color, produced by XPs from this fac
tory, that will be |
| 384 * known after blending. Note that we can conflate coverage and color, so th
e actual values | 396 * known after blending. Note that we can conflate coverage and color, so th
e actual values |
| 385 * written to pixels with partial coverage may not always seem consistent wi
th the invariant | 397 * written to pixels with partial coverage may not always seem consistent wi
th the invariant |
| 386 * information returned by this function. | 398 * information returned by this function. |
| 387 */ | 399 */ |
| 388 virtual void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, | 400 virtual void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, |
| 389 InvariantBlendedColor*) const = 0; | 401 InvariantBlendedColor*) const = 0; |
| 390 | 402 |
| 391 bool willNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI, | 403 bool willNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI, |
| 392 const GrProcOptInfo& coveragePOI) const; | 404 const GrProcOptInfo& coveragePOI, bool hasMixedSampl
es) const; |
| 393 | 405 |
| 394 bool isEqual(const GrXPFactory& that) const { | 406 bool isEqual(const GrXPFactory& that) const { |
| 395 if (this->classID() != that.classID()) { | 407 if (this->classID() != that.classID()) { |
| 396 return false; | 408 return false; |
| 397 } | 409 } |
| 398 return this->onIsEqual(that); | 410 return this->onIsEqual(that); |
| 399 } | 411 } |
| 400 | 412 |
| 401 /** | 413 /** |
| 402 * Helper for down-casting to a GrXPFactory subclass | 414 * Helper for down-casting to a GrXPFactory subclass |
| 403 */ | 415 */ |
| 404 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } | 416 template <typename T> const T& cast() const { return *static_cast<const T*>(
this); } |
| 405 | 417 |
| 406 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return
fClassID; } | 418 uint32_t classID() const { SkASSERT(kIllegalXPFClassID != fClassID); return
fClassID; } |
| 407 | 419 |
| 408 protected: | 420 protected: |
| 409 GrXPFactory() : fClassID(kIllegalXPFClassID) {} | 421 GrXPFactory() : fClassID(kIllegalXPFClassID) {} |
| 410 | 422 |
| 411 template <typename XPF_SUBCLASS> void initClassID() { | 423 template <typename XPF_SUBCLASS> void initClassID() { |
| 412 static uint32_t kClassID = GenClassID(); | 424 static uint32_t kClassID = GenClassID(); |
| 413 fClassID = kClassID; | 425 fClassID = kClassID; |
| 414 } | 426 } |
| 415 | 427 |
| 416 uint32_t fClassID; | 428 uint32_t fClassID; |
| 417 | 429 |
| 418 private: | 430 private: |
| 419 virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, | 431 virtual GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, |
| 420 const GrProcOptInfo& colorPOI
, | 432 const GrProcOptInfo& colorPOI
, |
| 421 const GrProcOptInfo& coverage
POI, | 433 const GrProcOptInfo& coverage
POI, |
| 434 bool hasMixedSamples, |
| 422 const DstTexture*) const = 0; | 435 const DstTexture*) const = 0; |
| 423 /** | 436 /** |
| 424 * Returns true if the XP generated by this factory will explicitly read ds
t in the fragment | 437 * Returns true if the XP generated by this factory will explicitly read ds
t in the fragment |
| 425 * shader. | 438 * shader. |
| 426 */ | 439 */ |
| 427 virtual bool willReadDstColor(const GrCaps& caps, | 440 virtual bool willReadDstColor(const GrCaps& caps, |
| 428 const GrProcOptInfo& colorPOI, | 441 const GrProcOptInfo& colorPOI, |
| 429 const GrProcOptInfo& coveragePOI) const = 0; | 442 const GrProcOptInfo& coveragePOI, |
| 443 bool hasMixedSamples) const = 0; |
| 430 | 444 |
| 431 virtual bool onIsEqual(const GrXPFactory&) const = 0; | 445 virtual bool onIsEqual(const GrXPFactory&) const = 0; |
| 432 | 446 |
| 433 static uint32_t GenClassID() { | 447 static uint32_t GenClassID() { |
| 434 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The | 448 // fCurrXPFactoryID has been initialized to kIllegalXPFactoryID. The |
| 435 // atomic inc returns the old value not the incremented value. So we add | 449 // atomic inc returns the old value not the incremented value. So we add |
| 436 // 1 to the returned value. | 450 // 1 to the returned value. |
| 437 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1
; | 451 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrXPFClassID)) + 1
; |
| 438 if (!id) { | 452 if (!id) { |
| 439 SkFAIL("This should never wrap as it should only be called once for
each GrXPFactory " | 453 SkFAIL("This should never wrap as it should only be called once for
each GrXPFactory " |
| 440 "subclass."); | 454 "subclass."); |
| 441 } | 455 } |
| 442 return id; | 456 return id; |
| 443 } | 457 } |
| 444 | 458 |
| 445 enum { | 459 enum { |
| 446 kIllegalXPFClassID = 0, | 460 kIllegalXPFClassID = 0, |
| 447 }; | 461 }; |
| 448 static int32_t gCurrXPFClassID; | 462 static int32_t gCurrXPFClassID; |
| 449 | 463 |
| 450 typedef GrProgramElement INHERITED; | 464 typedef GrProgramElement INHERITED; |
| 451 }; | 465 }; |
| 452 | 466 |
| 453 #endif | 467 #endif |
| 454 | 468 |
| OLD | NEW |