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 surfaceColorType, 25 GrColorType dstColorType, 26 sk_sp<GrGpuBuffer> dstBuffer, 27 size_t dstOffset); 28 name()29 const char* name() const override { return "TransferFromOp"; } 30 31 #ifdef SK_DEBUG dumpInfo()32 SkString dumpInfo() const override { 33 SkString string; 34 string = INHERITED::dumpInfo(); 35 string.appendf( 36 "bufferID:: %d offset: %zu, surf color type: %d, dst color type: %d\n" 37 "srcRect: [ L: %d, T: %d, R: %d, B: %d ]\n", 38 fDstBuffer->uniqueID().asUInt(), fDstOffset, (int)fSurfaceColorType, 39 (int)fDstColorType, fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, 40 fSrcRect.fBottom); 41 return string; 42 } 43 #endif 44 45 private: 46 friend class GrOpMemoryPool; // for ctor 47 GrTransferFromOp(const SkIRect & srcRect,GrColorType surfaceColorType,GrColorType dstColorType,sk_sp<GrGpuBuffer> dstBuffer,size_t dstOffset)48 GrTransferFromOp(const SkIRect& srcRect, 49 GrColorType surfaceColorType, 50 GrColorType dstColorType, 51 sk_sp<GrGpuBuffer> dstBuffer, 52 size_t dstOffset) 53 : INHERITED(ClassID()) 54 , fDstBuffer(std::move(dstBuffer)) 55 , fDstOffset(dstOffset) 56 , fSrcRect(srcRect) 57 , fSurfaceColorType(surfaceColorType) 58 , fDstColorType(dstColorType) { 59 this->setBounds(SkRect::Make(srcRect), HasAABloat::kNo, IsZeroArea::kNo); 60 } 61 onPrepare(GrOpFlushState *)62 void onPrepare(GrOpFlushState*) override {} 63 64 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; 65 66 sk_sp<GrGpuBuffer> fDstBuffer; 67 size_t fDstOffset; 68 SkIRect fSrcRect; 69 GrColorType fSurfaceColorType; 70 GrColorType fDstColorType; 71 72 typedef GrOp INHERITED; 73 }; 74 75 #endif 76