Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d0d66fb

Browse files
egdanielSkia Commit-Bot
authored andcommitted
Remove call to copy in GrcontextPriv read/write pixel calls.
Instead we just directly do all those copies as draws. Change-Id: I0cd9dfc6f96e35fbbc9c153a28a08eebf1d7b77f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/216356 Commit-Queue: Greg Daniel <[email protected]> Reviewed-by: Brian Salomon <[email protected]> Reviewed-by: Robert Phillips <[email protected]>
1 parent 29e013d commit d0d66fb

File tree

4 files changed

+44
-48
lines changed

4 files changed

+44
-48
lines changed

src/gpu/GrContextPriv.cpp

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -327,63 +327,50 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, int left, int top,
327327

328328
if (!fContext->priv().caps()->surfaceSupportsReadPixels(srcSurface) ||
329329
canvas2DFastPath) {
330-
GrSurfaceDesc desc;
331-
desc.fWidth = width;
332-
desc.fHeight = height;
333-
desc.fSampleCnt = 1;
334-
335330
GrBackendFormat format;
331+
GrPixelConfig config;
336332
if (canvas2DFastPath) {
337-
desc.fFlags = kRenderTarget_GrSurfaceFlag;
338-
desc.fConfig = kRGBA_8888_GrPixelConfig;
333+
config = kRGBA_8888_GrPixelConfig;
339334
format = this->caps()->getBackendFormatFromColorType(kRGBA_8888_SkColorType);
340335
} else {
341-
desc.fFlags = kNone_GrSurfaceFlags;
342-
desc.fConfig = srcProxy->config();
336+
config = srcProxy->config();
343337
format = srcProxy->backendFormat().makeTexture2D();
344338
if (!format.isValid()) {
345339
return false;
346340
}
347341
}
342+
sk_sp<SkColorSpace> cs = canvas2DFastPath ? nullptr : src->colorSpaceInfo().refColorSpace();
348343

349-
auto tempProxy = this->proxyProvider()->createProxy(
350-
format, desc, kTopLeft_GrSurfaceOrigin, SkBackingFit::kApprox, SkBudgeted::kYes);
351-
if (!tempProxy) {
352-
return false;
353-
}
354-
sk_sp<GrSurfaceContext> tempCtx;
355-
if (canvas2DFastPath) {
356-
tempCtx = this->drawingManager()->makeRenderTargetContext(std::move(tempProxy), nullptr,
357-
nullptr);
358-
SkASSERT(tempCtx->asRenderTargetContext());
359-
tempCtx->asRenderTargetContext()->discard();
360-
} else {
361-
tempCtx = this->drawingManager()->makeTextureContext(
362-
std::move(tempProxy), src->colorSpaceInfo().refColorSpace());
363-
}
344+
sk_sp<GrRenderTargetContext> tempCtx = this->makeDeferredRenderTargetContext(
345+
format, SkBackingFit::kApprox, width, height, config, std::move(cs), 1,
346+
GrMipMapped::kNo, kTopLeft_GrSurfaceOrigin, nullptr, SkBudgeted::kYes);
364347
if (!tempCtx) {
365348
return false;
366349
}
350+
351+
std::unique_ptr<GrFragmentProcessor> fp;
367352
if (canvas2DFastPath) {
368-
GrPaint paint;
369-
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
370-
auto fp = fContext->createPMToUPMEffect(
353+
fp = fContext->createPMToUPMEffect(
371354
GrSimpleTextureEffect::Make(sk_ref_sp(srcProxy->asTextureProxy()),
372355
SkMatrix::I()));
373356
if (dstColorType == GrColorType::kBGRA_8888) {
374357
fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA());
375358
dstColorType = GrColorType::kRGBA_8888;
376359
}
377-
if (!fp) {
378-
return false;
379-
}
380-
paint.addColorFragmentProcessor(std::move(fp));
381-
tempCtx->asRenderTargetContext()->fillRectToRect(
382-
GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
383-
SkRect::MakeWH(width, height), SkRect::MakeXYWH(left, top, width, height));
384-
} else if (!tempCtx->copy(srcProxy, SkIRect::MakeXYWH(left, top, width, height), {0, 0})) {
360+
} else {
361+
fp = GrSimpleTextureEffect::Make(sk_ref_sp(srcProxy->asTextureProxy()), SkMatrix::I());
362+
}
363+
if (!fp) {
385364
return false;
386365
}
366+
GrPaint paint;
367+
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
368+
paint.addColorFragmentProcessor(std::move(fp));
369+
370+
tempCtx->asRenderTargetContext()->fillRectToRect(
371+
GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
372+
SkRect::MakeWH(width, height), SkRect::MakeXYWH(left, top, width, height));
373+
387374
uint32_t flags = canvas2DFastPath ? 0 : pixelOpsFlags;
388375
return this->readSurfacePixels(tempCtx.get(), 0, 0, width, height, dstColorType,
389376
dstColorSpace, buffer, rowBytes, flags);
@@ -545,26 +532,26 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top,
545532
srcColorSpace, buffer, rowBytes, flags)) {
546533
return false;
547534
}
535+
536+
std::unique_ptr<GrFragmentProcessor> fp;
548537
if (canvas2DFastPath) {
549-
GrPaint paint;
550-
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
551-
auto fp = fContext->createUPMToPMEffect(
538+
fp = fContext->createUPMToPMEffect(
552539
GrSimpleTextureEffect::Make(std::move(tempProxy), SkMatrix::I()));
553540
if (srcColorType == GrColorType::kBGRA_8888) {
554541
fp = GrFragmentProcessor::SwizzleOutput(std::move(fp), GrSwizzle::BGRA());
555542
}
556-
if (!fp) {
557-
return false;
558-
}
559-
paint.addColorFragmentProcessor(std::move(fp));
560-
dst->asRenderTargetContext()->fillRectToRect(
561-
GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
562-
SkRect::MakeXYWH(left, top, width, height), SkRect::MakeWH(width, height));
563543
} else {
564-
if (!dst->copy(tempProxy.get(), SkIRect::MakeWH(width, height), {left, top})) {
565-
return false;
566-
}
544+
fp = GrSimpleTextureEffect::Make(std::move(tempProxy), SkMatrix::I());
545+
}
546+
if (!fp) {
547+
return false;
567548
}
549+
GrPaint paint;
550+
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
551+
paint.addColorFragmentProcessor(std::move(fp));
552+
dst->asRenderTargetContext()->fillRectToRect(
553+
GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
554+
SkRect::MakeXYWH(left, top, width, height), SkRect::MakeWH(width, height));
568555

569556
return true;
570557
}

src/gpu/GrSurfaceContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ bool GrSurfaceContext::writePixels(const SkImageInfo& srcInfo, const void* srcBu
9494
return false;
9595
}
9696

97+
if (this->asSurfaceProxy()->readOnly()) {
98+
return false;
99+
}
100+
97101
return direct->priv().writeSurfacePixels(this, x, y, srcInfo.width(), srcInfo.height(),
98102
colorType, srcInfo.colorSpace(), srcBuffer,
99103
srcRowBytes, flags);

tests/GrSurfaceTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) {
329329

330330
// Mip regen should not work with a read only texture.
331331
if (context->priv().caps()->mipMapSupport()) {
332+
delete_backend_texture(context, backendTex);
332333
backendTex = context->createBackendTexture(
333334
kSize, kSize, kRGBA_8888_SkColorType, GrMipMapped::kYes, GrRenderable::kYes);
334335
proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin,
@@ -340,6 +341,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) {
340341
context->priv().getGpu()->regenerateMipMapLevels(proxy->peekTexture());
341342
REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType));
342343
}
344+
delete_backend_texture(context, backendTex);
343345
}
344346
}
345347

tests/TestUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ bool create_backend_texture(GrContext* context, GrBackendTexture* backendTex,
156156
}
157157

158158
void delete_backend_texture(GrContext* context, const GrBackendTexture& backendTex) {
159+
GrFlushInfo flushInfo;
160+
flushInfo.fFlags = kSyncCpu_GrFlushFlag;
161+
context->flush(flushInfo);
159162
context->deleteBackendTexture(backendTex);
160163
}
161164

0 commit comments

Comments
 (0)