| 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 GrTransferFromRenderTask_DEFINED |
| 9 | #define GrTransferFromRenderTask_DEFINED |
| 10 | |
| 11 | #include "src/gpu/GrRenderTask.h" |
| 12 | |
| 13 | class GrTransferFromRenderTask final : public GrRenderTask { |
| 14 | public: |
| 15 | GrTransferFromRenderTask(sk_sp<GrSurfaceProxy> srcProxy, |
| 16 | const SkIRect& srcRect, |
| 17 | GrColorType surfaceColorType, |
| 18 | GrColorType dstColorType, |
| 19 | sk_sp<GrGpuBuffer> dstBuffer, |
| 20 | size_t dstOffset) |
| 21 | : GrRenderTask() |
| 22 | , fSrcProxy(std::move(srcProxy)) |
| 23 | , fSrcRect(srcRect) |
| 24 | , fSurfaceColorType(surfaceColorType) |
| 25 | , fDstColorType(dstColorType) |
| 26 | , fDstBuffer(std::move(dstBuffer)) |
| 27 | , fDstOffset(dstOffset) {} |
| 28 | |
| 29 | private: |
| 30 | bool onIsUsed(GrSurfaceProxy* proxy) const override { |
| 31 | SkASSERT(0 == this->numTargets()); |
| 32 | return proxy == fSrcProxy.get(); |
| 33 | } |
| 34 | // If fSrcProxy is uninstantiated at flush time we simply will skip doing the transfer. |
| 35 | void handleInternalAllocationFailure() override {} |
| 36 | void gatherProxyIntervals(GrResourceAllocator*) const override; |
| 37 | |
| 38 | ExpectedOutcome onMakeClosed(const GrCaps&, SkIRect*) override { |
| 39 | return ExpectedOutcome::kTargetUnchanged; |
| 40 | } |
| 41 | |
| 42 | bool onExecute(GrOpFlushState*) override; |
| 43 | |
| 44 | #if GR_TEST_UTILS |
| 45 | const char* name() const final { return "TransferFrom" ; } |
| 46 | #endif |
| 47 | #ifdef SK_DEBUG |
| 48 | void visitProxies_debugOnly(const GrOp::VisitProxyFunc& fn) const override { |
| 49 | fn(fSrcProxy.get(), GrMipmapped::kNo); |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | sk_sp<GrSurfaceProxy> fSrcProxy; |
| 54 | SkIRect fSrcRect; |
| 55 | GrColorType fSurfaceColorType; |
| 56 | GrColorType fDstColorType; |
| 57 | sk_sp<GrGpuBuffer> fDstBuffer; |
| 58 | size_t fDstOffset; |
| 59 | |
| 60 | }; |
| 61 | |
| 62 | #endif |
| 63 | |
| 64 | |