Add SkSurface::asyncReadPixels()
Initial version. Current limitations: No Metal support, no color space
conversions, for each src color type only one dst color type is legal (
which may or may not be the src color type), no alpha type conversions.
Bug: skia:8962
Change-Id: I6f046a32342b8f5ffb1799d67d7ba15c250ef9bf
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212981
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/ops/GrCopySurfaceOp.h b/src/gpu/ops/GrCopySurfaceOp.h
index 3581031..3c6194d 100644
--- a/src/gpu/ops/GrCopySurfaceOp.h
+++ b/src/gpu/ops/GrCopySurfaceOp.h
@@ -30,12 +30,12 @@
#ifdef SK_DEBUG
SkString dumpInfo() const override {
SkString string;
- string.append(INHERITED::dumpInfo());
- string.printf("srcProxyID: %d,\n"
- "srcRect: [ L: %d, T: %d, R: %d, B: %d ], dstPt: [ X: %d, Y: %d ]\n",
- fSrc.get()->uniqueID().asUInt(),
- fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBottom,
- fDstPoint.fX, fDstPoint.fY);
+ string = INHERITED::dumpInfo();
+ string.appendf(
+ "srcProxyID: %d,\n"
+ "srcRect: [ L: %d, T: %d, R: %d, B: %d ], dstPt: [ X: %d, Y: %d ]\n",
+ fSrc.get()->uniqueID().asUInt(), fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight,
+ fSrcRect.fBottom, fDstPoint.fX, fDstPoint.fY);
return string;
}
#endif
diff --git a/src/gpu/ops/GrTransferFromOp.cpp b/src/gpu/ops/GrTransferFromOp.cpp
new file mode 100644
index 0000000..e1ddfc5
--- /dev/null
+++ b/src/gpu/ops/GrTransferFromOp.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2019 Google LLC
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "src/gpu/ops/GrTransferFromOp.h"
+#include "include/private/GrRecordingContext.h"
+#include "src/gpu/GrCaps.h"
+#include "src/gpu/GrGpuCommandBuffer.h"
+#include "src/gpu/GrMemoryPool.h"
+#include "src/gpu/GrRecordingContextPriv.h"
+
+std::unique_ptr<GrOp> GrTransferFromOp::Make(GrRecordingContext* context,
+ const SkIRect& srcRect,
+ GrColorType dstColorType,
+ sk_sp<GrGpuBuffer> dstBuffer,
+ size_t dstOffset) {
+ SkASSERT(context->priv().caps()->transferFromOffsetAlignment(dstColorType));
+ SkASSERT(dstOffset % context->priv().caps()->transferFromOffsetAlignment(dstColorType) == 0);
+ GrOpMemoryPool* pool = context->priv().opMemoryPool();
+ return pool->allocate<GrTransferFromOp>(srcRect, dstColorType, std::move(dstBuffer), dstOffset);
+}
+
+void GrTransferFromOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
+ state->commandBuffer()->transferFrom(fSrcRect, fDstColorType, fDstBuffer.get(), fDstOffset);
+}
diff --git a/src/gpu/ops/GrTransferFromOp.h b/src/gpu/ops/GrTransferFromOp.h
new file mode 100644
index 0000000..34d8f54
--- /dev/null
+++ b/src/gpu/ops/GrTransferFromOp.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2019 Google LLC
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrTransferFromOp_DEFINED
+#define GrTransferFromOp_DEFINED
+
+#include "src/gpu/GrOpFlushState.h"
+#include "src/gpu/ops/GrOp.h"
+
+/**
+ * Does a transfer from the surface context's surface to a transfer buffer. It is assumed
+ * that the caller has checked the GrCaps to ensure this transfer is legal.
+ */
+class GrTransferFromOp final : public GrOp {
+public:
+ DEFINE_OP_CLASS_ID
+
+ static std::unique_ptr<GrOp> Make(GrRecordingContext*,
+ const SkIRect& srcRect,
+ GrColorType dstColorType,
+ sk_sp<GrGpuBuffer> dstBuffer,
+ size_t dstOffset);
+
+ const char* name() const override { return "TransferFromOp"; }
+
+#ifdef SK_DEBUG
+ SkString dumpInfo() const override {
+ SkString string;
+ string = INHERITED::dumpInfo();
+ string.appendf(
+ "bufferID:: %d offset: %zu, color type: %d\n"
+ "srcRect: [ L: %d, T: %d, R: %d, B: %d ]\n",
+ fDstBuffer->uniqueID().asUInt(), fDstOffset, fDstColorType, fSrcRect.fLeft,
+ fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBottom);
+ return string;
+ }
+#endif
+
+private:
+ friend class GrOpMemoryPool; // for ctor
+
+ GrTransferFromOp(const SkIRect& srcRect,
+ GrColorType dstColorType,
+ sk_sp<GrGpuBuffer> dstBuffer,
+ size_t dstOffset)
+ : INHERITED(ClassID())
+ , fDstBuffer(std::move(dstBuffer))
+ , fDstOffset(dstOffset)
+ , fSrcRect(srcRect)
+ , fDstColorType(dstColorType) {
+ this->setBounds(SkRect::Make(srcRect), HasAABloat::kNo, IsZeroArea::kNo);
+ }
+
+ void onPrepare(GrOpFlushState*) override {}
+
+ void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
+
+ sk_sp<GrGpuBuffer> fDstBuffer;
+ size_t fDstOffset;
+ SkIRect fSrcRect;
+ GrColorType fDstColorType;
+
+ typedef GrOp INHERITED;
+};
+
+#endif