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