GrTransferFromOp.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2019 Google LLC
  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 GrTransferFromOp_DEFINED
  8. #define GrTransferFromOp_DEFINED
  9. #include "src/gpu/GrOpFlushState.h"
  10. #include "src/gpu/ops/GrOp.h"
  11. /**
  12. * Does a transfer from the surface context's surface to a transfer buffer. It is assumed
  13. * that the caller has checked the GrCaps to ensure this transfer is legal.
  14. */
  15. class GrTransferFromOp final : public GrOp {
  16. public:
  17. DEFINE_OP_CLASS_ID
  18. static std::unique_ptr<GrOp> Make(GrRecordingContext*,
  19. const SkIRect& srcRect,
  20. GrColorType dstColorType,
  21. sk_sp<GrGpuBuffer> dstBuffer,
  22. size_t dstOffset);
  23. const char* name() const override { return "TransferFromOp"; }
  24. #ifdef SK_DEBUG
  25. SkString dumpInfo() const override {
  26. SkString string;
  27. string = INHERITED::dumpInfo();
  28. string.appendf(
  29. "bufferID:: %d offset: %zu, color type: %d\n"
  30. "srcRect: [ L: %d, T: %d, R: %d, B: %d ]\n",
  31. fDstBuffer->uniqueID().asUInt(), fDstOffset, (int)fDstColorType, fSrcRect.fLeft,
  32. fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBottom);
  33. return string;
  34. }
  35. #endif
  36. private:
  37. friend class GrOpMemoryPool; // for ctor
  38. GrTransferFromOp(const SkIRect& srcRect,
  39. GrColorType dstColorType,
  40. sk_sp<GrGpuBuffer> dstBuffer,
  41. size_t dstOffset)
  42. : INHERITED(ClassID())
  43. , fDstBuffer(std::move(dstBuffer))
  44. , fDstOffset(dstOffset)
  45. , fSrcRect(srcRect)
  46. , fDstColorType(dstColorType) {
  47. this->setBounds(SkRect::Make(srcRect), HasAABloat::kNo, IsZeroArea::kNo);
  48. }
  49. void onPrepare(GrOpFlushState*) override {}
  50. void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
  51. sk_sp<GrGpuBuffer> fDstBuffer;
  52. size_t fDstOffset;
  53. SkIRect fSrcRect;
  54. GrColorType fDstColorType;
  55. typedef GrOp INHERITED;
  56. };
  57. #endif