aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/gpu/GrContext.cpp68
-rw-r--r--src/gpu/GrContextPriv.h18
-rw-r--r--src/gpu/GrSurfaceContext.cpp6
-rw-r--r--tests/FloatingPointTextureTest.cpp7
-rw-r--r--tests/IntTextureTest.cpp36
5 files changed, 69 insertions, 66 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index f37eff65c5..234303fbc9 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -289,7 +289,7 @@ static bool pm_upm_must_round_trip(GrPixelConfig config, SkColorSpace* colorSpac
(kRGBA_8888_GrPixelConfig == config || kBGRA_8888_GrPixelConfig == config);
}
-bool GrContextPriv::writeSurfacePixels(GrSurfaceProxy* dstProxy, SkColorSpace* dstColorSpace,
+bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst,
int left, int top, int width, int height,
GrPixelConfig srcConfig, SkColorSpace* srcColorSpace,
const void* buffer, size_t rowBytes,
@@ -298,26 +298,27 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceProxy* dstProxy, SkColorSpace* d
ASSERT_SINGLE_OWNER_PRIV
RETURN_FALSE_IF_ABANDONED_PRIV
- ASSERT_OWNED_PROXY_PRIV(dstProxy);
- SkASSERT(dstProxy);
+ SkASSERT(dst);
+ ASSERT_OWNED_PROXY_PRIV(dst->asSurfaceProxy());
GR_AUDIT_TRAIL_AUTO_FRAME(&fContext->fAuditTrail, "GrContextPriv::writeSurfacePixels");
- GrSurface* surface = dstProxy->instantiate(fContext->resourceProvider());
- if (!surface) {
+ GrSurface* dstSurface = dst->asSurfaceProxy()->instantiate(fContext->resourceProvider());
+ if (!dstSurface) {
return false;
}
// The src is unpremul but the dst is premul -> premul the src before or as part of the write
const bool premul = SkToBool(kUnpremul_PixelOpsFlag & pixelOpsFlags);
- if (!valid_pixel_conversion(srcConfig, surface->config(), premul)) {
+ if (!valid_pixel_conversion(srcConfig, dstSurface->config(), premul)) {
return false;
}
// We need to guarantee round-trip conversion if we are reading and writing 8888 non-sRGB data,
// without any color spaces attached, and the caller wants us to premul.
- bool useConfigConversionEffect = premul &&
- pm_upm_must_round_trip(srcConfig, srcColorSpace) &&
- pm_upm_must_round_trip(surface->config(), dstColorSpace);
+ bool useConfigConversionEffect =
+ premul &&
+ pm_upm_must_round_trip(srcConfig, srcColorSpace) &&
+ pm_upm_must_round_trip(dstSurface->config(), dst->getColorSpace());
// Are we going to try to premul as part of a draw? For the non-legacy case, we always allow
// this. GrConfigConversionEffect fails on some GPUs, so only allow this if it works perfectly.
@@ -326,7 +327,7 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceProxy* dstProxy, SkColorSpace* d
// Trim the params here so that if we wind up making a temporary surface it can be as small as
// necessary and because GrGpu::getWritePixelsInfo requires it.
- if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height(),
+ if (!GrSurfacePriv::AdjustWritePixelParams(dstSurface->width(), dstSurface->height(),
GrBytesPerPixel(srcConfig), &left, &top, &width,
&height, &buffer, &rowBytes)) {
return false;
@@ -335,12 +336,12 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceProxy* dstProxy, SkColorSpace* d
GrGpu::DrawPreference drawPreference = premulOnGpu ? GrGpu::kCallerPrefersDraw_DrawPreference
: GrGpu::kNoDraw_DrawPreference;
GrGpu::WritePixelTempDrawInfo tempDrawInfo;
- if (!fContext->fGpu->getWritePixelsInfo(surface, width, height, srcConfig,
+ if (!fContext->fGpu->getWritePixelsInfo(dstSurface, width, height, srcConfig,
&drawPreference, &tempDrawInfo)) {
return false;
}
- if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().hasPendingIO()) {
+ if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && dstSurface->surfacePriv().hasPendingIO()) {
this->flush(nullptr); // MDB TODO: tighten this
}
@@ -392,13 +393,7 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceProxy* dstProxy, SkColorSpace* d
}
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
- // TODO: Need to decide the semantics of this function for color spaces. Do we support
- // conversion from a passed-in color space? For now, specifying nullptr means that this
- // path will do no conversion, so it will match the behavior of the non-draw path.
- GrRenderTarget* renderTarget = surface->asRenderTarget();
- SkASSERT(renderTarget);
- sk_sp<GrRenderTargetContext> renderTargetContext(
- this->makeWrappedRenderTargetContext(sk_ref_sp(renderTarget), nullptr));
+ GrRenderTargetContext* renderTargetContext = dst->asRenderTargetContext();
if (!renderTargetContext) {
return false;
}
@@ -414,13 +409,13 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceProxy* dstProxy, SkColorSpace* d
this->flushSurfaceWrites(renderTargetContext->asRenderTargetProxy());
}
} else {
- return fContext->fGpu->writePixels(surface, left, top, width, height, srcConfig,
+ return fContext->fGpu->writePixels(dstSurface, left, top, width, height, srcConfig,
buffer, rowBytes);
}
return true;
}
-bool GrContextPriv::readSurfacePixels(GrSurfaceProxy* srcProxy, SkColorSpace* srcColorSpace,
+bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src,
int left, int top, int width, int height,
GrPixelConfig dstConfig, SkColorSpace* dstColorSpace,
void* buffer, size_t rowBytes, uint32_t flags) {
@@ -428,27 +423,28 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceProxy* srcProxy, SkColorSpace* sr
ASSERT_SINGLE_OWNER_PRIV
RETURN_FALSE_IF_ABANDONED_PRIV
- ASSERT_OWNED_PROXY_PRIV(srcProxy);
- SkASSERT(srcProxy);
+ SkASSERT(src);
+ ASSERT_OWNED_PROXY_PRIV(src->asSurfaceProxy());
GR_AUDIT_TRAIL_AUTO_FRAME(&fContext->fAuditTrail, "GrContextPriv::readSurfacePixels");
// MDB TODO: delay this instantiation until later in the method
- GrSurface* src = srcProxy->instantiate(fContext->resourceProvider());
- if (!src) {
+ GrSurface* srcSurface = src->asSurfaceProxy()->instantiate(fContext->resourceProvider());
+ if (!srcSurface) {
return false;
}
// The src is premul but the dst is unpremul -> unpremul the src after or as part of the read
bool unpremul = SkToBool(kUnpremul_PixelOpsFlag & flags);
- if (!valid_pixel_conversion(src->config(), dstConfig, unpremul)) {
+ if (!valid_pixel_conversion(srcSurface->config(), dstConfig, unpremul)) {
return false;
}
// We need to guarantee round-trip conversion if we are reading and writing 8888 non-sRGB data,
// without any color spaces attached, and the caller wants us to unpremul.
- bool useConfigConversionEffect = unpremul &&
- pm_upm_must_round_trip(src->config(), srcColorSpace) &&
- pm_upm_must_round_trip(dstConfig, dstColorSpace);
+ bool useConfigConversionEffect =
+ unpremul &&
+ pm_upm_must_round_trip(srcSurface->config(), src->getColorSpace()) &&
+ pm_upm_must_round_trip(dstConfig, dstColorSpace);
// Are we going to try to unpremul as part of a draw? For the non-legacy case, we always allow
// this. GrConfigConversionEffect fails on some GPUs, so only allow this if it works perfectly.
@@ -457,7 +453,7 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceProxy* srcProxy, SkColorSpace* sr
// Adjust the params so that if we wind up using an intermediate surface we've already done
// all the trimming and the temporary can be the min size required.
- if (!GrSurfacePriv::AdjustReadPixelParams(src->width(), src->height(),
+ if (!GrSurfacePriv::AdjustReadPixelParams(srcSurface->width(), srcSurface->height(),
GrBytesPerPixel(dstConfig), &left,
&top, &width, &height, &buffer, &rowBytes)) {
return false;
@@ -466,22 +462,22 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceProxy* srcProxy, SkColorSpace* sr
GrGpu::DrawPreference drawPreference = unpremulOnGpu ? GrGpu::kCallerPrefersDraw_DrawPreference
: GrGpu::kNoDraw_DrawPreference;
GrGpu::ReadPixelTempDrawInfo tempDrawInfo;
- if (!fContext->fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig,
+ if (!fContext->fGpu->getReadPixelsInfo(srcSurface, width, height, rowBytes, dstConfig,
&drawPreference, &tempDrawInfo)) {
return false;
}
- if (!(kDontFlush_PixelOpsFlag & flags) && src->surfacePriv().hasPendingWrite()) {
+ if (!(kDontFlush_PixelOpsFlag & flags) && srcSurface->surfacePriv().hasPendingWrite()) {
this->flush(nullptr); // MDB TODO: tighten this
}
- sk_sp<GrSurfaceProxy> proxyToRead = sk_ref_sp(srcProxy);
+ sk_sp<GrSurfaceProxy> proxyToRead = src->asSurfaceProxyRef();
bool didTempDraw = false;
if (GrGpu::kNoDraw_DrawPreference != drawPreference) {
if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) {
// We only respect this when the entire src is being read. Otherwise we can trigger too
// many odd ball texture sizes and trash the cache.
- if (width != src->width() || height != src->height()) {
+ if (width != srcSurface->width() || height != srcSurface->height()) {
tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox;
}
}
@@ -498,9 +494,9 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceProxy* srcProxy, SkColorSpace* sr
tempDrawInfo.fTempSurfaceDesc.fOrigin);
if (tempRTC) {
SkMatrix textureMatrix = SkMatrix::MakeTrans(SkIntToScalar(left), SkIntToScalar(top));
- sk_sp<GrTextureProxy> proxy = sk_ref_sp(srcProxy->asTextureProxy());
+ sk_sp<GrTextureProxy> proxy = src->asTextureProxyRef();
sk_sp<GrFragmentProcessor> fp = GrSimpleTextureEffect::Make(
- fContext->resourceProvider(), proxy, nullptr, textureMatrix);
+ fContext->resourceProvider(), std::move(proxy), nullptr, textureMatrix);
if (unpremulOnGpu) {
fp = fContext->createPMToUPMEffect(std::move(fp), useConfigConversionEffect);
// We no longer need to do this on CPU after the read back.
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 0f4f7da4d8..9fa1077009 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -112,13 +112,12 @@ public:
/**
* Reads a rectangle of pixels from a surface.
- * @param surface the surface to read from.
- * @param srcColorSpace color space of the surface
+ * @param src the surface context to read from.
* @param left left edge of the rectangle to read (inclusive)
* @param top top edge of the rectangle to read (inclusive)
* @param width width of rectangle to read in pixels.
* @param height height of rectangle to read in pixels.
- * @param config the pixel config of the destination buffer
+ * @param dstConfig the pixel config of the destination buffer
* @param dstColorSpace color space of the destination buffer
* @param buffer memory to read the rectangle into.
* @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
@@ -128,21 +127,20 @@ public:
* @return true if the read succeeded, false if not. The read can fail because of an unsupported
* pixel configs
*/
- bool readSurfacePixels(GrSurfaceProxy* src, SkColorSpace* srcColorSpace,
+ bool readSurfacePixels(GrSurfaceContext* src,
int left, int top, int width, int height,
- GrPixelConfig config, SkColorSpace* dstColorSpace, void* buffer,
+ GrPixelConfig dstConfig, SkColorSpace* dstColorSpace, void* buffer,
size_t rowBytes = 0,
uint32_t pixelOpsFlags = 0);
/**
* Writes a rectangle of pixels to a surface.
- * @param dst the surface to write to.
- * @param dstColorSpace color space of the surface
+ * @param dst the surface context to write to.
* @param left left edge of the rectangle to write (inclusive)
* @param top top edge of the rectangle to write (inclusive)
* @param width width of rectangle to write in pixels.
* @param height height of rectangle to write in pixels.
- * @param config the pixel config of the source buffer
+ * @param srcConfig the pixel config of the source buffer
* @param srcColorSpace color space of the source buffer
* @param buffer memory to read pixels from
* @param rowBytes number of bytes between consecutive rows. Zero
@@ -151,9 +149,9 @@ public:
* @return true if the write succeeded, false if not. The write can fail because of an
* unsupported combination of surface and src configs.
*/
- bool writeSurfacePixels(GrSurfaceProxy* dst, SkColorSpace* dstColorSpace,
+ bool writeSurfacePixels(GrSurfaceContext* dst,
int left, int top, int width, int height,
- GrPixelConfig config, SkColorSpace* srcColorSpace, const void* buffer,
+ GrPixelConfig srcConfig, SkColorSpace* srcColorSpace, const void* buffer,
size_t rowBytes,
uint32_t pixelOpsFlags = 0);
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 6b6a942720..2bde24baf5 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -46,8 +46,7 @@ bool GrSurfaceContext::readPixels(const SkImageInfo& dstInfo, void* dstBuffer,
flags |= GrContextPriv::kUnpremul_PixelOpsFlag;
}
- return fContext->contextPriv().readSurfacePixels(this->asSurfaceProxy(),
- this->getColorSpace(), x, y,
+ return fContext->contextPriv().readSurfacePixels(this, x, y,
dstInfo.width(), dstInfo.height(), config,
dstInfo.colorSpace(),
dstBuffer, dstRowBytes, flags);
@@ -64,8 +63,7 @@ bool GrSurfaceContext::writePixels(const SkImageInfo& srcInfo, const void* srcBu
flags |= GrContextPriv::kUnpremul_PixelOpsFlag;
}
- return fContext->contextPriv().writeSurfacePixels(this->asSurfaceProxy(),
- this->getColorSpace(), x, y,
+ return fContext->contextPriv().writeSurfacePixels(this, x, y,
srcInfo.width(), srcInfo.height(),
config, srcInfo.colorSpace(),
srcBuffer, srcRowBytes, flags);
diff --git a/tests/FloatingPointTextureTest.cpp b/tests/FloatingPointTextureTest.cpp
index 5adc2e7892..e092921cbb 100644
--- a/tests/FloatingPointTextureTest.cpp
+++ b/tests/FloatingPointTextureTest.cpp
@@ -59,7 +59,12 @@ void runFPTest(skiatest::Reporter* reporter, GrContext* context,
if (!fpProxy) {
continue;
}
- bool result = context->contextPriv().readSurfacePixels(fpProxy.get(), nullptr,
+
+ sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
+ std::move(fpProxy), nullptr);
+ REPORTER_ASSERT(reporter, sContext);
+
+ bool result = context->contextPriv().readSurfacePixels(sContext.get(),
0, 0, DEV_W, DEV_H,
desc.fConfig, nullptr,
readBuffer.begin(), 0);
diff --git a/tests/IntTextureTest.cpp b/tests/IntTextureTest.cpp
index eacd0617a2..daeb13e53d 100644
--- a/tests/IntTextureTest.cpp
+++ b/tests/IntTextureTest.cpp
@@ -82,10 +82,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
return;
}
+ sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext(
+ std::move(proxy), nullptr);
+ if (!sContext) {
+ return;
+ }
+
std::unique_ptr<int32_t[]> readData(new int32_t[kS * kS]);
// Test that reading to a non-integer config fails.
{
- bool success = context->contextPriv().readSurfacePixels(proxy.get(), nullptr,
+ bool success = context->contextPriv().readSurfacePixels(sContext.get(),
0, 0, kS, kS,
kRGBA_8888_GrPixelConfig,
nullptr, readData.get());
@@ -93,7 +99,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
}
{
std::unique_ptr<uint16_t[]> halfData(new uint16_t[4 * kS * kS]);
- bool success = context->contextPriv().readSurfacePixels(proxy.get(), nullptr,
+ bool success = context->contextPriv().readSurfacePixels(sContext.get(),
0, 0, kS, kS,
kRGBA_half_GrPixelConfig,
nullptr, halfData.get());
@@ -104,7 +110,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
// we don't support. Right now this test is counting on GR_RGBA_INTEGER/GL_BYTE being the
// implementation-dependent second format).
sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
- bool success = context->contextPriv().readSurfacePixels(proxy.get(), nullptr,
+ bool success = context->contextPriv().readSurfacePixels(sContext.get(),
0, 0, kS, kS,
kRGBA_8888_sint_GrPixelConfig,
nullptr, readData.get());
@@ -116,7 +122,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
{
// readPixels should fail if we attempt to use the unpremul flag with an integer texture.
bool success = context->contextPriv().readSurfacePixels(
- proxy.get(), nullptr,
+ sContext.get(),
0, 0, kS, kS,
kRGBA_8888_sint_GrPixelConfig,
nullptr, readData.get(), 0,
@@ -127,15 +133,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
// Test that copying from one integer texture to another succeeds.
{
sk_sp<GrSurfaceContext> dstContext(GrSurfaceProxy::TestCopy(context, desc,
- proxy.get()));
+ sContext->asSurfaceProxy()));
REPORTER_ASSERT(reporter, dstContext);
if (!dstContext || !dstContext->asTextureProxy()) {
return;
}
sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
- bool success = context->contextPriv().readSurfacePixels(dstContext->asSurfaceProxy(),
- nullptr, 0, 0, kS, kS,
+ bool success = context->contextPriv().readSurfacePixels(dstContext.get(), 0, 0, kS, kS,
kRGBA_8888_sint_GrPixelConfig,
nullptr, readData.get());
REPORTER_ASSERT(reporter, success);
@@ -151,7 +156,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
nonIntDesc.fConfig = kRGBA_8888_GrPixelConfig;
sk_sp<GrSurfaceContext> dstContext(GrSurfaceProxy::TestCopy(context, nonIntDesc,
- proxy.get()));
+ sContext->asSurfaceProxy()));
REPORTER_ASSERT(reporter, !dstContext);
}
@@ -161,7 +166,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
nonIntDesc.fConfig = kRGBA_half_GrPixelConfig;
sk_sp<GrSurfaceContext> dstContext(GrSurfaceProxy::TestCopy(context, nonIntDesc,
- proxy.get()));
+ sContext->asSurfaceProxy()));
REPORTER_ASSERT(reporter, !dstContext);
}
@@ -171,7 +176,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
{
// Can't write pixels from a non-int config.
- bool success = context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
+ bool success = context->contextPriv().writeSurfacePixels(sContext.get(),
0, 0, kS/2, kS/2,
kRGBA_8888_GrPixelConfig, nullptr,
bottomRightQuarter, kRowBytes);
@@ -180,7 +185,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
{
// Can't use unpremul flag.
bool success = context->contextPriv().writeSurfacePixels(
- proxy.get(), nullptr,
+ sContext.get(),
0, 0, kS/2, kS/2,
kRGBA_8888_sint_GrPixelConfig,
nullptr,
@@ -189,7 +194,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, !success);
}
{
- bool success = context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
+ bool success = context->contextPriv().writeSurfacePixels(sContext.get(),
0, 0, kS/2, kS/2,
kRGBA_8888_sint_GrPixelConfig,
nullptr,
@@ -200,7 +205,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
}
sk_bzero(readData.get(), sizeof(int32_t) * kS * kS);
- success = context->contextPriv().readSurfacePixels(proxy.get(), nullptr,
+ success = context->contextPriv().readSurfacePixels(sContext.get(),
0, 0, kS, kS,
kRGBA_8888_sint_GrPixelConfig,
nullptr, readData.get(), 0);
@@ -234,7 +239,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
expectedData.get()[i] = ((0xFF * a) << 24) | ((0xFF * b) << 16) |
((0xFF * g) << 8) | (0xFF * r);
}
- context->contextPriv().writeSurfacePixels(proxy.get(), nullptr,
+ context->contextPriv().writeSurfacePixels(sContext.get(),
0, 0, kS, kS,
kRGBA_8888_sint_GrPixelConfig, nullptr,
testData.get(), 0);
@@ -253,7 +258,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) {
for (auto filter : kNamedFilters) {
sk_sp<GrFragmentProcessor> fp(GrSimpleTextureEffect::Make(context->resourceProvider(),
- proxy, nullptr,
+ sContext->asTextureProxyRef(),
+ nullptr,
SkMatrix::I(),
filter.fMode));
REPORTER_ASSERT(reporter, fp);