GrOp.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2015 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. #include "src/gpu/ops/GrOp.h"
  8. std::atomic<uint32_t> GrOp::gCurrOpClassID {GrOp::kIllegalOpID + 1};
  9. std::atomic<uint32_t> GrOp::gCurrOpUniqueID{GrOp::kIllegalOpID + 1};
  10. #ifdef SK_DEBUG
  11. void* GrOp::operator new(size_t size) {
  12. // All GrOp-derived class should be allocated in a GrMemoryPool
  13. SkASSERT(0);
  14. return ::operator new(size);
  15. }
  16. void GrOp::operator delete(void* target) {
  17. // All GrOp-derived class should be released from their owning GrMemoryPool
  18. SkASSERT(0);
  19. ::operator delete(target);
  20. }
  21. #endif
  22. GrOp::GrOp(uint32_t classID) : fClassID(classID) {
  23. SkASSERT(classID == SkToU32(fClassID));
  24. SkASSERT(classID);
  25. SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag);
  26. }
  27. GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, const GrCaps& caps) {
  28. SkASSERT(this != that);
  29. if (this->classID() != that->classID()) {
  30. return CombineResult::kCannotCombine;
  31. }
  32. auto result = this->onCombineIfPossible(that, caps);
  33. if (result == CombineResult::kMerged) {
  34. this->joinBounds(*that);
  35. }
  36. return result;
  37. }
  38. void GrOp::chainConcat(std::unique_ptr<GrOp> next) {
  39. SkASSERT(next);
  40. SkASSERT(this->classID() == next->classID());
  41. SkASSERT(this->isChainTail());
  42. SkASSERT(next->isChainHead());
  43. fNextInChain = std::move(next);
  44. fNextInChain->fPrevInChain = this;
  45. }
  46. std::unique_ptr<GrOp> GrOp::cutChain() {
  47. if (fNextInChain) {
  48. fNextInChain->fPrevInChain = nullptr;
  49. return std::move(fNextInChain);
  50. }
  51. return nullptr;
  52. }
  53. #ifdef SK_DEBUG
  54. void GrOp::validateChain(GrOp* expectedTail) const {
  55. SkASSERT(this->isChainHead());
  56. uint32_t classID = this->classID();
  57. const GrOp* op = this;
  58. while (op) {
  59. SkASSERT(op == this || (op->prevInChain() && op->prevInChain()->nextInChain() == op));
  60. SkASSERT(classID == op->classID());
  61. if (op->nextInChain()) {
  62. SkASSERT(op->nextInChain()->prevInChain() == op);
  63. SkASSERT(op != expectedTail);
  64. } else {
  65. SkASSERT(!expectedTail || op == expectedTail);
  66. }
  67. op = op->nextInChain();
  68. }
  69. }
  70. #endif