2015-11-22 22:51:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
#include "include/gpu/GrTexture.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrRenderTargetContext.h"
|
|
|
|
#include "src/gpu/GrShaderCaps.h"
|
|
|
|
#include "src/gpu/GrSurfacePriv.h"
|
|
|
|
#include "src/gpu/GrTextureContext.h"
|
|
|
|
#include "src/gpu/GrTexturePriv.h"
|
|
|
|
#include "src/gpu/GrTextureProxyPriv.h"
|
|
|
|
#include "src/gpu/gl/GrGLGpu.h"
|
|
|
|
#include "src/gpu/gl/GrGLUtil.h"
|
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tests/TestUtils.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
|
|
|
#include "tools/gpu/gl/GLTestContext.h"
|
2015-11-22 22:51:00 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
using sk_gpu_test::GLTestContext;
|
2016-03-31 01:56:19 +00:00
|
|
|
|
2017-07-25 14:05:01 +00:00
|
|
|
static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx1,
|
2017-12-12 18:01:25 +00:00
|
|
|
sk_sp<GrContext> grctx1, GrBackendTexture* backendTex1,
|
2017-07-25 14:05:01 +00:00
|
|
|
GrEGLImage image1) {
|
2015-11-22 22:51:00 +00:00
|
|
|
if (glctx1) {
|
|
|
|
glctx1->makeCurrent();
|
|
|
|
if (grctx1) {
|
2017-12-12 18:01:25 +00:00
|
|
|
if (backendTex1 && backendTex1->isValid()) {
|
2019-05-20 12:38:07 +00:00
|
|
|
grctx1->deleteBackendTexture(*backendTex1);
|
2015-11-22 22:51:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (GR_EGL_NO_IMAGE != image1) {
|
|
|
|
glctx1->destroyEGLImage(image1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glctx0->makeCurrent();
|
|
|
|
if (texID0) {
|
|
|
|
GR_GL_CALL(glctx0->gl(), DeleteTextures(1, &texID0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 21:02:39 +00:00
|
|
|
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
GrContext* context0 = ctxInfo.grContext();
|
|
|
|
sk_gpu_test::GLTestContext* glCtx0 = ctxInfo.glContext();
|
2016-04-05 19:59:06 +00:00
|
|
|
|
2015-11-23 07:23:53 +00:00
|
|
|
// Try to create a second GL context and then check if the contexts have necessary
|
|
|
|
// extensions to run this test.
|
2015-11-22 22:51:00 +00:00
|
|
|
|
2015-11-23 07:23:53 +00:00
|
|
|
if (kGLES_GrGLStandard != glCtx0->gl()->fStandard) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGLGpu* gpu0 = static_cast<GrGLGpu*>(context0->priv().getGpu());
|
2016-11-29 18:43:46 +00:00
|
|
|
if (!gpu0->glCaps().shaderCaps()->externalTextureSupport()) {
|
2015-11-23 07:23:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-22 22:51:00 +00:00
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<GLTestContext> glCtx1 = glCtx0->makeNew();
|
2015-11-23 07:23:53 +00:00
|
|
|
if (!glCtx1) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-07 17:33:05 +00:00
|
|
|
sk_sp<GrContext> context1 = GrContext::MakeGL(sk_ref_sp(glCtx1->gl()));
|
2017-12-12 18:01:25 +00:00
|
|
|
GrBackendTexture backendTexture1;
|
2015-11-23 07:23:53 +00:00
|
|
|
GrEGLImage image = GR_EGL_NO_IMAGE;
|
|
|
|
GrGLTextureInfo externalTexture;
|
|
|
|
externalTexture.fID = 0;
|
2015-11-22 22:51:00 +00:00
|
|
|
|
2015-11-23 07:23:53 +00:00
|
|
|
if (!context1) {
|
2017-12-12 18:01:25 +00:00
|
|
|
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
|
2015-11-23 07:23:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-22 22:51:00 +00:00
|
|
|
|
2015-11-23 07:23:53 +00:00
|
|
|
if (!glCtx1->gl()->hasExtension("EGL_KHR_image") ||
|
|
|
|
!glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
|
2017-12-12 18:01:25 +00:00
|
|
|
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
|
2015-11-23 07:23:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-22 22:51:00 +00:00
|
|
|
|
2015-11-23 07:23:53 +00:00
|
|
|
///////////////////////////////// CONTEXT 1 ///////////////////////////////////
|
2015-11-22 22:51:00 +00:00
|
|
|
|
2015-11-23 07:23:53 +00:00
|
|
|
// Use GL Context 1 to create a texture unknown to GrContext.
|
|
|
|
context1->flush();
|
2019-02-04 18:26:26 +00:00
|
|
|
GrGpu* gpu1 = context1->priv().getGpu();
|
2015-11-23 07:23:53 +00:00
|
|
|
static const int kSize = 100;
|
2017-12-12 18:01:25 +00:00
|
|
|
backendTexture1 =
|
2019-06-04 15:03:06 +00:00
|
|
|
context1->createBackendTexture(kSize, kSize, kRGBA_8888_SkColorType,
|
|
|
|
SkColors::kTransparent,
|
|
|
|
GrMipMapped::kNo, GrRenderable::kNo);
|
2018-01-10 14:57:53 +00:00
|
|
|
|
|
|
|
if (!backendTexture1.isValid() || !gpu1->isTestingOnlyBackendTexture(backendTexture1)) {
|
2015-11-23 07:23:53 +00:00
|
|
|
ERRORF(reporter, "Error creating texture for EGL Image");
|
2017-12-12 18:01:25 +00:00
|
|
|
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
|
2015-11-23 07:23:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-12 18:01:25 +00:00
|
|
|
|
2018-04-10 13:34:07 +00:00
|
|
|
GrGLTextureInfo texInfo;
|
|
|
|
if (!backendTexture1.getGLTextureInfo(&texInfo)) {
|
|
|
|
ERRORF(reporter, "Failed to get GrGLTextureInfo");
|
|
|
|
return;
|
|
|
|
}
|
2017-12-12 18:01:25 +00:00
|
|
|
|
2018-04-10 13:34:07 +00:00
|
|
|
if (GR_GL_TEXTURE_2D != texInfo.fTarget) {
|
2015-11-23 07:23:53 +00:00
|
|
|
ERRORF(reporter, "Expected backend texture to be 2D");
|
2017-12-12 18:01:25 +00:00
|
|
|
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
|
2015-11-23 07:23:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-22 22:51:00 +00:00
|
|
|
|
2015-11-23 07:23:53 +00:00
|
|
|
// Wrap the texture in an EGLImage
|
2018-04-10 13:34:07 +00:00
|
|
|
image = glCtx1->texture2DToEGLImage(texInfo.fID);
|
2015-11-23 07:23:53 +00:00
|
|
|
if (GR_EGL_NO_IMAGE == image) {
|
|
|
|
ERRORF(reporter, "Error creating EGL Image from texture");
|
2017-12-12 18:01:25 +00:00
|
|
|
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
|
2015-11-23 07:23:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-23 13:37:36 +00:00
|
|
|
// Since we are dealing with two different GL contexts here, we need to call finish so that the
|
|
|
|
// clearing of the texture that happens in createTextingOnlyBackendTexture occurs before we call
|
|
|
|
// TexSubImage below on the other context. Otherwise, it is possible the calls get reordered and
|
|
|
|
// the clearing overwrites the TexSubImage writes.
|
|
|
|
GR_GL_CALL(glCtx1->gl(), Finish());
|
|
|
|
|
2015-11-23 07:23:53 +00:00
|
|
|
// Populate the texture using GL context 1. Important to use TexSubImage as TexImage orphans
|
|
|
|
// the EGL image. Also, this must be done after creating the EGLImage as the texture
|
|
|
|
// contents may not be preserved when the image is created.
|
|
|
|
SkAutoTMalloc<uint32_t> pixels(kSize * kSize);
|
|
|
|
for (int i = 0; i < kSize*kSize; ++i) {
|
|
|
|
pixels.get()[i] = 0xDDAABBCC;
|
|
|
|
}
|
|
|
|
GR_GL_CALL(glCtx1->gl(), ActiveTexture(GR_GL_TEXTURE0));
|
2018-04-10 13:34:07 +00:00
|
|
|
GR_GL_CALL(glCtx1->gl(), BindTexture(texInfo.fTarget, texInfo.fID));
|
|
|
|
GR_GL_CALL(glCtx1->gl(), TexSubImage2D(texInfo.fTarget, 0, 0, 0, kSize, kSize,
|
2015-11-23 07:23:53 +00:00
|
|
|
GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, pixels.get()));
|
|
|
|
GR_GL_CALL(glCtx1->gl(), Finish());
|
|
|
|
// We've been making direct GL calls in GL context 1, let GrContext 1 know its internal
|
|
|
|
// state is invalid.
|
|
|
|
context1->resetContext();
|
|
|
|
|
|
|
|
///////////////////////////////// CONTEXT 0 ///////////////////////////////////
|
|
|
|
|
|
|
|
// Make a new texture ID in GL Context 0 from the EGL Image
|
|
|
|
glCtx0->makeCurrent();
|
|
|
|
externalTexture.fTarget = GR_GL_TEXTURE_EXTERNAL;
|
|
|
|
externalTexture.fID = glCtx0->eglImageToExternalTexture(image);
|
2019-06-13 20:50:49 +00:00
|
|
|
externalTexture.fFormat = GR_GL_RGBA8;
|
2017-06-08 22:22:53 +00:00
|
|
|
if (0 == externalTexture.fID) {
|
|
|
|
ERRORF(reporter, "Error converting EGL Image back to texture");
|
2017-12-12 18:01:25 +00:00
|
|
|
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
|
2017-06-08 22:22:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-23 07:23:53 +00:00
|
|
|
|
|
|
|
// Wrap this texture ID in a GrTexture
|
2018-07-03 20:18:29 +00:00
|
|
|
GrBackendTexture backendTex(kSize, kSize, GrMipMapped::kNo, externalTexture);
|
|
|
|
backendTex.setPixelConfig(kRGBA_8888_GrPixelConfig);
|
2017-01-25 17:10:37 +00:00
|
|
|
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
// TODO: If I make this TopLeft origin to match resolve_origin calls for kDefault, this test
|
|
|
|
// fails on the Nexus5. Why?
|
2019-02-04 18:26:26 +00:00
|
|
|
sk_sp<GrTextureContext> surfaceContext = context0->priv().makeBackendTextureContext(
|
2017-07-19 22:28:58 +00:00
|
|
|
backendTex, kBottomLeft_GrSurfaceOrigin, nullptr);
|
2017-01-25 17:10:37 +00:00
|
|
|
|
2017-01-27 15:58:31 +00:00
|
|
|
if (!surfaceContext) {
|
|
|
|
ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext.");
|
2017-12-12 18:01:25 +00:00
|
|
|
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
|
2017-01-27 15:58:31 +00:00
|
|
|
return;
|
2015-11-23 07:23:53 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 16:13:37 +00:00
|
|
|
GrTextureProxy* proxy = surfaceContext->asTextureProxy();
|
2018-06-08 22:11:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy->mipMapped() == GrMipMapped::kNo);
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy->peekTexture()->texturePriv().mipMapped() == GrMipMapped::kNo);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, proxy->textureType() == GrTextureType::kExternal);
|
2018-06-08 22:11:51 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
2018-07-31 21:25:29 +00:00
|
|
|
proxy->peekTexture()->texturePriv().textureType() == GrTextureType::kExternal);
|
|
|
|
REPORTER_ASSERT(reporter, proxy->hasRestrictedSampling());
|
|
|
|
REPORTER_ASSERT(reporter, proxy->peekTexture()->texturePriv().hasRestrictedSampling());
|
2018-03-21 16:13:37 +00:00
|
|
|
|
2015-11-23 15:09:50 +00:00
|
|
|
// Should not be able to wrap as a RT
|
2017-01-25 17:10:37 +00:00
|
|
|
{
|
2017-07-19 22:28:58 +00:00
|
|
|
sk_sp<GrRenderTargetContext> temp =
|
2019-02-04 18:26:26 +00:00
|
|
|
context0->priv().makeBackendTextureRenderTargetContext(
|
2018-02-03 01:32:49 +00:00
|
|
|
backendTex, kBottomLeft_GrSurfaceOrigin, 1, nullptr);
|
2017-01-27 15:58:31 +00:00
|
|
|
if (temp) {
|
2017-01-25 17:10:37 +00:00
|
|
|
ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT.");
|
|
|
|
}
|
2015-11-23 07:23:53 +00:00
|
|
|
}
|
2015-11-23 15:09:50 +00:00
|
|
|
|
2017-03-14 18:39:29 +00:00
|
|
|
test_read_pixels(reporter, surfaceContext.get(), pixels.get(), "EGLImageTest-read");
|
2015-11-23 15:09:50 +00:00
|
|
|
|
2017-01-27 15:11:42 +00:00
|
|
|
// We should not be able to write to a EXTERNAL texture
|
2017-03-14 18:39:29 +00:00
|
|
|
test_write_pixels(reporter, surfaceContext.get(), false, "EGLImageTest-write");
|
2015-11-23 15:09:50 +00:00
|
|
|
|
2017-01-27 15:11:42 +00:00
|
|
|
// Only test RT-config
|
|
|
|
// TODO: why do we always need to draw to copy from an external texture?
|
2017-01-30 18:27:37 +00:00
|
|
|
test_copy_from_surface(reporter, context0, surfaceContext->asSurfaceProxy(),
|
Reland "Reland "Remove support for copyAsDraw in gpu copySurface.""
This reverts commit 4c6f9b767034c6812d868108516c2580dce3cb56.
Reason for revert: Landing with neuxs 7 and androind one fixes
Original change's description:
> Revert "Reland "Remove support for copyAsDraw in gpu copySurface.""
>
> This reverts commit 84ea04949cabc87a88d06c5c6f6aeb944a745911.
>
> Reason for revert: nexus 7 and android one broken
>
> Original change's description:
> > Reland "Remove support for copyAsDraw in gpu copySurface."
> >
> > This reverts commit c5167c053bd58e6afbad83fe493c0231df3f9704.
> >
> > Reason for revert: fixed
> >
> > Original change's description:
> > > Revert "Remove support for copyAsDraw in gpu copySurface."
> > >
> > > This reverts commit 6565506463db042d3d543a1707f473cdf1ef4e9e.
> > >
> > > Reason for revert: seems to break things?
> > >
> > > Original change's description:
> > > > Remove support for copyAsDraw in gpu copySurface.
> > > >
> > > > The major changes on a higher lever are:
> > > > 1) The majority of all copies now go through GrSurfaceProxy::Copy which
> > > > takes in a proxy and returns a new one with the data copied to it. This
> > > > is the most common use case within Ganesh.
> > > >
> > > > 2) The backend copy calls no longer do draws, require origins to be the
> > > > same, and won't do any swizzling or adjustment of subrects. They are
> > > > all implemented to be dumb copy this data to this other spot.
> > > >
> > > > 3) The GrSurfaceContext copy call has now been moved to priv and renamed
> > > > copyNoDraw, and a new priv copyAsDraw was added to GrRenderTargetContext.
> > > >
> > > > 4) WritePixels and ReplaceRenderTarget both need to specifiy the destination
> > > > of copies. They are the only users (besides the GrSurfaceProxy::Copy) which
> > > > call the priv methods on GrSurfaceContext.
> > > >
> > > > Change-Id: Iaf1eb3a73ccaf39a75af77e281dae594f809186f
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/217459
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > >
> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> > >
> > > Change-Id: Id43aa8aa1451e794342e930441d9975b90e6b59f
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218549
> > > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> >
> > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> >
> > Change-Id: I1a96f85ae2ff7622a6b57406755d478e7fbcf56e
> > No-Presubmit: true
> > No-Tree-Checks: true
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218797
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
>
> Change-Id: I310930a9df30535f45a065263a40239141e15562
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219384
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
Change-Id: I88df4f19aa26ed77b5af4e25d138387cbabd1934
No-Presubmit: true
No-Tree-Checks: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219386
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
2019-06-07 15:43:30 +00:00
|
|
|
pixels.get(), "EGLImageTest-copy");
|
2015-11-23 15:09:50 +00:00
|
|
|
|
2017-12-12 18:01:25 +00:00
|
|
|
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
|
2015-11-22 22:51:00 +00:00
|
|
|
}
|