aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/private/GrSurfaceProxy.h5
-rw-r--r--src/gpu/GrContext.cpp15
-rw-r--r--src/gpu/GrContextPriv.h10
-rw-r--r--src/gpu/GrSurfaceProxy.cpp7
-rw-r--r--src/image/SkImage_Gpu.cpp14
-rw-r--r--tests/EGLImageTest.cpp37
-rw-r--r--tests/RectangleTextureTest.cpp23
7 files changed, 57 insertions, 54 deletions
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index 6f2a751239..a08cb2654a 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -178,6 +178,11 @@ public:
const GrSurfaceDesc&, SkBudgeted,
const void* srcData, size_t rowBytes);
+ static sk_sp<GrSurfaceProxy> MakeWrappedBackend(
+ GrContext*,
+ GrBackendTextureDesc&,
+ GrWrapOwnership ownership = kBorrow_GrWrapOwnership);
+
const GrSurfaceDesc& desc() const { return fDesc; }
GrSurfaceOrigin origin() const {
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index db8863fca0..88b14f305c 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -628,6 +628,21 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrSurfac
return this->makeWrappedSurfaceContext(std::move(proxy), nullptr);
}
+sk_sp<GrSurfaceContext> GrContextPriv::makeBackendSurfaceContext(const GrBackendTextureDesc& desc,
+ sk_sp<SkColorSpace> colorSpace,
+ GrWrapOwnership ownership) {
+ ASSERT_SINGLE_OWNER_PRIV
+
+ sk_sp<GrSurface> surface(fContext->textureProvider()->wrapBackendTexture(desc, ownership));
+ if (!surface) {
+ return nullptr;
+ }
+
+ sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(surface)));
+
+ return this->makeWrappedSurfaceContext(std::move(proxy), std::move(colorSpace));
+}
+
sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext(
const GrBackendTextureDesc& desc,
sk_sp<SkColorSpace> colorSpace,
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index ed9691c656..8ad3483e0d 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -35,11 +35,11 @@ public:
SkBackingFit dstFit,
SkBudgeted isDstBudgeted);
- // TODO: add:
- // sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTextureDesc& desc,
- // sk_sp<SkColorSpace> colorSpace,
- // GrWrapOwnership = kBorrow_GrWrapOwnership);
- // Maybe add a 'surfaceProps' param that is ignored for non-RTs?
+ // TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove
+ // makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext
+ sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTextureDesc& desc,
+ sk_sp<SkColorSpace> colorSpace,
+ GrWrapOwnership = kBorrow_GrWrapOwnership);
sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext(
const GrBackendTextureDesc& desc,
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 4cf4611f91..1e9ac9bdca 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -159,6 +159,13 @@ sk_sp<GrSurfaceProxy> GrSurfaceProxy::MakeDeferred(const GrCaps& caps,
return GrSurfaceProxy::MakeDeferred(caps, desc, SkBackingFit::kExact, budgeted);
}
+sk_sp<GrSurfaceProxy> GrSurfaceProxy::MakeWrappedBackend(GrContext* context,
+ GrBackendTextureDesc& desc,
+ GrWrapOwnership ownership) {
+ sk_sp<GrTexture> tex(context->textureProvider()->wrapBackendTexture(desc, ownership));
+ return GrSurfaceProxy::MakeWrapped(std::move(tex));
+}
+
#ifdef SK_DEBUG
void GrSurfaceProxy::validate(GrContext* context) const {
if (fTarget) {
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index ec1968f510..8a27836ee7 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -271,14 +271,8 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac
uDesc.fWidth = yuvSizes[1].fWidth;
uDesc.fHeight = yuvSizes[1].fHeight;
- sk_sp<GrTexture> yTex(
- ctx->textureProvider()->wrapBackendTexture(yDesc, kBorrow_GrWrapOwnership));
- sk_sp<GrSurfaceProxy> yProxy = GrSurfaceProxy::MakeWrapped(std::move(yTex));
-
- sk_sp<GrTexture> uTex(
- ctx->textureProvider()->wrapBackendTexture(uDesc, kBorrow_GrWrapOwnership));
- sk_sp<GrSurfaceProxy> uProxy = GrSurfaceProxy::MakeWrapped(std::move(uTex));
-
+ sk_sp<GrSurfaceProxy> yProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, yDesc);
+ sk_sp<GrSurfaceProxy> uProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, uDesc);
sk_sp<GrSurfaceProxy> vProxy;
if (nv12) {
@@ -292,9 +286,7 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac
vDesc.fWidth = yuvSizes[2].fWidth;
vDesc.fHeight = yuvSizes[2].fHeight;
- sk_sp<GrTexture> vTex = sk_sp<GrTexture>(
- ctx->textureProvider()->wrapBackendTexture(vDesc, kBorrow_GrWrapOwnership));
- vProxy = GrSurfaceProxy::MakeWrapped(std::move(vTex));
+ vProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, vDesc);
}
if (!yProxy || !uProxy || !vProxy) {
return nullptr;
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index 02ba4a82df..3011355115 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -135,27 +135,22 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
externalDesc.fHeight = kSize;
externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externalTexture);
- sk_sp<GrSurfaceContext> externalTextureContext;
+ sk_sp<GrSurfaceContext> surfaceContext = context0->contextPriv().makeBackendSurfaceContext(
+ externalDesc, nullptr);
- {
- sk_sp<GrTexture> externalTextureObj(
- context0->textureProvider()->wrapBackendTexture(externalDesc));
- if (!externalTextureObj) {
- ERRORF(reporter, "Error wrapping external texture in GrTexture.");
- cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image);
- return;
- }
-
- externalTextureContext = context0->contextPriv().makeWrappedSurfaceContext(
- std::move(externalTextureObj));
+ if (!surfaceContext) {
+ ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext.");
+ cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image);
+ return;
}
// Should not be able to wrap as a RT
{
externalDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
- sk_sp<GrTexture> externalTextureRTObj(
- context0->textureProvider()->wrapBackendTexture(externalDesc));
- if (externalTextureRTObj) {
+
+ sk_sp<GrSurfaceContext> temp = context0->contextPriv().makeBackendSurfaceContext(
+ externalDesc, nullptr);
+ if (temp) {
ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT.");
}
externalDesc.fFlags = kNone_GrBackendTextureFlag;
@@ -164,24 +159,24 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
// Should not be able to wrap with a sample count
{
externalDesc.fSampleCnt = 4;
- sk_sp<GrTexture> externalTextureMSAAObj(
- context0->textureProvider()->wrapBackendTexture(externalDesc));
- if (externalTextureMSAAObj) {
+ sk_sp<GrSurfaceContext> temp = context0->contextPriv().makeBackendSurfaceContext(
+ externalDesc, nullptr);
+ if (temp) {
ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture with MSAA.");
}
externalDesc.fSampleCnt = 0;
}
- test_read_pixels(reporter, context0, externalTextureContext.get(), pixels.get(),
+ test_read_pixels(reporter, context0, surfaceContext.get(), pixels.get(),
"EGLImageTest-read");
// We should not be able to write to a EXTERNAL texture
- test_write_pixels(reporter, context0, externalTextureContext.get(), false,
+ test_write_pixels(reporter, context0, surfaceContext.get(), false,
"EGLImageTest-write");
// Only test RT-config
// TODO: why do we always need to draw to copy from an external texture?
- test_copy_from_surface(reporter, context0, externalTextureContext->asDeferredSurface(),
+ test_copy_from_surface(reporter, context0, surfaceContext->asDeferredSurface(),
pixels.get(), true, "EGLImageTest-copy");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image);
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index d55b882f7e..ef5f2d31a6 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -133,23 +133,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) {
}
}
- sk_sp<GrSurfaceProxy> rectProxy;
-
- {
- sk_sp<GrTexture> rectangleTexture(
- context->textureProvider()->wrapBackendTexture(rectangleDesc));
- if (!rectangleTexture) {
- ERRORF(reporter, "Error wrapping rectangle texture in GrTexture.");
- GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID));
- continue;
- }
-
- rectProxy = GrSurfaceProxy::MakeWrapped(std::move(rectangleTexture));
- if (!rectProxy) {
- ERRORF(reporter, "Error creating proxy for rectangle texture.");
- GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID));
- continue;
- }
+ sk_sp<GrSurfaceProxy> rectProxy = GrSurfaceProxy::MakeWrappedBackend(context,
+ rectangleDesc);
+ if (!rectProxy) {
+ ERRORF(reporter, "Error creating proxy for rectangle texture.");
+ GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID));
+ continue;
}
test_basic_draw_as_src(reporter, context, rectProxy, refPixels);