SkAutoBlitterChoose.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 SkAutoBlitterChoose_DEFINED
  8. #define SkAutoBlitterChoose_DEFINED
  9. #include "include/private/SkMacros.h"
  10. #include "src/core/SkArenaAlloc.h"
  11. #include "src/core/SkBlitter.h"
  12. #include "src/core/SkDraw.h"
  13. class SkMatrix;
  14. class SkPaint;
  15. class SkPixmap;
  16. class SkAutoBlitterChoose : SkNoncopyable {
  17. public:
  18. SkAutoBlitterChoose() {}
  19. SkAutoBlitterChoose(const SkDraw& draw, const SkMatrix* matrix, const SkPaint& paint,
  20. bool drawCoverage = false) {
  21. this->choose(draw, matrix, paint, drawCoverage);
  22. }
  23. SkBlitter* operator->() { return fBlitter; }
  24. SkBlitter* get() const { return fBlitter; }
  25. SkBlitter* choose(const SkDraw& draw, const SkMatrix* matrix, const SkPaint& paint,
  26. bool drawCoverage = false) {
  27. SkASSERT(!fBlitter);
  28. if (!matrix) {
  29. matrix = draw.fMatrix;
  30. }
  31. fBlitter = SkBlitter::Choose(draw.fDst, *matrix, paint, &fAlloc, drawCoverage);
  32. if (draw.fCoverage) {
  33. // hmm, why can't choose ignore the paint if drawCoverage is true?
  34. SkBlitter* coverageBlitter = SkBlitter::Choose(*draw.fCoverage, *matrix, SkPaint(),
  35. &fAlloc, true);
  36. fBlitter = fAlloc.make<SkPairBlitter>(fBlitter, coverageBlitter);
  37. }
  38. return fBlitter;
  39. }
  40. private:
  41. // Owned by fAlloc, which will handle the delete.
  42. SkBlitter* fBlitter = nullptr;
  43. SkSTArenaAlloc<kSkBlitterContextSize> fAlloc;
  44. };
  45. #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose)
  46. #endif