135 auto* caps = dContext->
priv().
caps();
138 if (!backendFormat.isValid()) {
145 static constexpr SkISize kTexDims = {16, 16};
146 int srcBufferWidth = caps->transferPixelsToRowBytesSupport() ? 20 : 16;
154 skgpu::Mipmapped::kNo,
167 caps->surfaceSupportsReadPixels(tex.
get())) {
173 if (!caps->isFormatAsColorTypeRenderable(
colorType, tex->backendFormat())) {
185 caps->transferBufferRowBytesAlignment());
187 std::unique_ptr<char[]> srcData(
new char[kTexDims.
fHeight * srcRowBytes]);
201 void* data =
buffer->map();
206 memcpy(data, srcData.get(), size);
223 std::unique_ptr<char[]> dstBuffer(
new char[dstRowBytes * kTexDims.
fHeight]());
225 float compareTolerances[4] = {};
228 ERRORF(
reporter,
"Could not read pixels from texture, color type: %d",
233 auto error = std::function<ComparePixmapsErrorReporter>(
236 "Error at (%d %d) in transfer, color type: %s, diffs: (%f, %f, %f, %f)",
238 diffs[0], diffs[1], diffs[2], diffs[3]);
243 GrCPixmap(dstInfo, dstBuffer.get(), dstRowBytes),
251 if (!caps->transferPixelsToRowBytesSupport()) {
260 const int width = 10;
272 offset = top * srcRowBytes;
282 memcpy(data, srcData.get(), size);
293 ERRORF(
reporter,
"Could not transfer pixels to texture, color type: %d",
300 ERRORF(
reporter,
"Could not read pixels from texture, color type: %d",
305 GrCPixmap(dstInfo, dstBuffer.get(), dstRowBytes),
318 auto resourceProvider = context->priv().resourceProvider();
319 GrGpu* gpu = context->priv().getGpu();
321 static constexpr SkISize kTexDims = {16, 16};
325 const int kPartialLeft = 2;
326 const int kPartialTop = 10;
327 const int kPartialWidth = 10;
328 const int kPartialHeight = 2;
331 auto format = context->priv().caps()->getDefaultBackendFormat(
colorType, renderable);
337 size_t textureDataRowBytes = kTexDims.
fWidth * textureDataBpp;
338 std::unique_ptr<char[]> textureData(
new char[kTexDims.
fHeight * textureDataRowBytes]);
342 data.fPixels = textureData.get();
343 data.fRowBytes = textureDataRowBytes;
351 skgpu::Mipmapped::kNo,
360 caps->surfaceSupportsReadPixels(tex.
get())) {
366 if (!caps->isFormatAsColorTypeRenderable(
colorType, tex->backendFormat())) {
373 if (!allowedRead.fOffsetAlignmentForTransferBuffer) {
380 caps->transferBufferRowBytesAlignment());
381 size_t partialBufferRowBytes =
SkAlignTo(kPartialWidth * bpp,
382 caps->transferBufferRowBytesAlignment());
383 size_t offsetAlignment = allowedRead.fOffsetAlignmentForTransferBuffer;
386 size_t bufferSize = fullBufferRowBytes * kTexDims.
fHeight;
388 static constexpr size_t kStartingOffset = 11;
389 size_t partialReadOffset = kStartingOffset +
390 (offsetAlignment - kStartingOffset%offsetAlignment)%offsetAlignment;
391 bufferSize = std::max(bufferSize,
392 partialReadOffset + partialBufferRowBytes * kPartialHeight);
403 int expectedTransferCnt = 0;
404 gpu->
stats()->reset();
411 allowedRead.fColorType,
418 ++expectedTransferCnt;
425 const auto* map =
reinterpret_cast<const char*
>(
buffer->map());
431 std::unique_ptr<char[]> transferData(
new char[kTexDims.
fHeight * fullBufferRowBytes]);
432 memcpy(transferData.get(), map, fullBufferRowBytes * kTexDims.
fHeight);
439 auto error = std::function<ComparePixmapsErrorReporter>(
442 "Error at (%d %d) in transfer, color type: %s, diffs: (%f, %f, %f, %f)",
444 diffs[0], diffs[1], diffs[2], diffs[3]);
448 GrCPixmap( transferInfo, transferData.get(), fullBufferRowBytes),
458 allowedRead.fColorType,
465 ++expectedTransferCnt;
471 map =
reinterpret_cast<const char*
>(
buffer->map());
477 const char* bufferStart =
reinterpret_cast<const char*
>(map) + partialReadOffset;
478 memcpy(transferData.get(), bufferStart, partialBufferRowBytes * kTexDims.
fHeight);
481 transferInfo = transferInfo.
makeWH(kPartialWidth, kPartialHeight);
482 const char* textureDataStart =
483 textureData.get() + textureDataRowBytes * kPartialTop + textureDataBpp * kPartialLeft;
484 textureDataInfo = textureDataInfo.
makeWH(kPartialWidth, kPartialHeight);
486 GrCPixmap(transferInfo , transferData.get(), partialBufferRowBytes),
492 (void)expectedTransferCnt;
const GrCaps * caps() const
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
bool transferPixelsTo(GrTexture *texture, SkIRect rect, GrColorType textureColorType, GrColorType bufferColorType, sk_sp< GrGpuBuffer > transferBuffer, size_t offset, size_t rowBytes)
GrDirectContext * directContext() const
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
static constexpr uint32_t kBufferHeight
uint32_t uint32_t * format