skia2/tests/EGLImageTest.cpp
Greg Daniel 09c9400695 Reland "Reland "Require mips to be allocated at texture creation time and disable late allocations.""
This reverts commit 01422bc8ef.

Reason for revert: follow on change may be ready

Original change's description:
> Revert "Reland "Require mips to be allocated at texture creation time and disable late allocations.""
> 
> This reverts commit 9eb36b9eb8.
> 
> Reason for revert: Alpha8 isn't renderable on es2 so we end up dropping draws on certain A8 mip requests
> 
> Original change's description:
> > Reland "Require mips to be allocated at texture creation time and disable late allocations."
> > 
> > This reverts commit 0c78238e29.
> > 
> > Reason for revert: <INSERT REASONING HERE>
> > 
> > Original change's description:
> > > Revert "Require mips to be allocated at texture creation time and disable late allocations."
> > > 
> > > This reverts commit cd2c3f9055.
> > > 
> > > Reason for revert: Looks to be causing angle failures on initial clear test
> > > 
> > > Original change's description:
> > > > Require mips to be allocated at texture creation time and disable late allocations.
> > > > 
> > > > If we get a non-mipped texture for a draw that wants to be use mip map filter, we
> > > > will copy the texture into a new mipped texture.
> > > > 
> > > > Clean up of unused code in the GPU backends for reallocating for mips will be done
> > > > in a follow up CL.
> > > > 
> > > > Bug: skia:
> > > > Change-Id: Idab588c1abf4bbbf7eeceb3727d500e5df274188
> > > > Reviewed-on: https://skia-review.googlesource.com/132830
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > > 
> > >
> > > 
> > > Change-Id: I49f0ace52f2586d61b451630b2e6aae84b420b81
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Bug: skia:
> > > Reviewed-on: https://skia-review.googlesource.com/133041
> > > Reviewed-by: Greg Daniel <egdaniel@google.com>
> > > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > 
> > Bug: skia:
> > Change-Id: I004447a5f1ec72c3be2318ddea803f57efb12ea4
> > Reviewed-on: https://skia-review.googlesource.com/133340
> > 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: I9e9718d380c4d9927ec39e46008750ab7396391f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/133680
> 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: Ic3df69f65a89962b21cdb50ee436a29fd121ab1f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/133740
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-06-08 23:01:44 +00:00

202 lines
7.9 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Test.h"
#include "TestUtils.h"
#include "GrContext.h"
#include "GrContextFactory.h"
#include "GrContextPriv.h"
#include "GrRenderTargetContext.h"
#include "GrShaderCaps.h"
#include "GrSurfacePriv.h"
#include "GrTest.h"
#include "GrTexture.h"
#include "GrTextureContext.h"
#include "GrTexturePriv.h"
#include "GrTextureProxyPriv.h"
#include "gl/GLTestContext.h"
#include "gl/GrGLGpu.h"
#include "gl/GrGLUtil.h"
using sk_gpu_test::GLTestContext;
static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx1,
sk_sp<GrContext> grctx1, GrBackendTexture* backendTex1,
GrEGLImage image1) {
if (glctx1) {
glctx1->makeCurrent();
if (grctx1) {
if (backendTex1 && backendTex1->isValid()) {
GrGLGpu* gpu1 = static_cast<GrGLGpu*>(grctx1->contextPriv().getGpu());
gpu1->deleteTestingOnlyBackendTexture(*backendTex1);
}
}
if (GR_EGL_NO_IMAGE != image1) {
glctx1->destroyEGLImage(image1);
}
}
glctx0->makeCurrent();
if (texID0) {
GR_GL_CALL(glctx0->gl(), DeleteTextures(1, &texID0));
}
}
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
GrContext* context0 = ctxInfo.grContext();
sk_gpu_test::GLTestContext* glCtx0 = ctxInfo.glContext();
// Try to create a second GL context and then check if the contexts have necessary
// extensions to run this test.
if (kGLES_GrGLStandard != glCtx0->gl()->fStandard) {
return;
}
GrGLGpu* gpu0 = static_cast<GrGLGpu*>(context0->contextPriv().getGpu());
if (!gpu0->glCaps().shaderCaps()->externalTextureSupport()) {
return;
}
std::unique_ptr<GLTestContext> glCtx1 = glCtx0->makeNew();
if (!glCtx1) {
return;
}
sk_sp<GrContext> context1 = GrContext::MakeGL(sk_ref_sp(glCtx1->gl()));
GrBackendTexture backendTexture1;
GrEGLImage image = GR_EGL_NO_IMAGE;
GrGLTextureInfo externalTexture;
externalTexture.fID = 0;
if (!context1) {
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return;
}
if (!glCtx1->gl()->hasExtension("EGL_KHR_image") ||
!glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return;
}
///////////////////////////////// CONTEXT 1 ///////////////////////////////////
// Use GL Context 1 to create a texture unknown to GrContext.
context1->flush();
GrGpu* gpu1 = context1->contextPriv().getGpu();
static const int kSize = 100;
backendTexture1 =
gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig,
false, GrMipMapped::kNo);
if (!backendTexture1.isValid() || !gpu1->isTestingOnlyBackendTexture(backendTexture1)) {
ERRORF(reporter, "Error creating texture for EGL Image");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return;
}
GrGLTextureInfo texInfo;
if (!backendTexture1.getGLTextureInfo(&texInfo)) {
ERRORF(reporter, "Failed to get GrGLTextureInfo");
return;
}
if (GR_GL_TEXTURE_2D != texInfo.fTarget) {
ERRORF(reporter, "Expected backend texture to be 2D");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return;
}
// Wrap the texture in an EGLImage
image = glCtx1->texture2DToEGLImage(texInfo.fID);
if (GR_EGL_NO_IMAGE == image) {
ERRORF(reporter, "Error creating EGL Image from texture");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return;
}
// 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());
// 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));
GR_GL_CALL(glCtx1->gl(), BindTexture(texInfo.fTarget, texInfo.fID));
GR_GL_CALL(glCtx1->gl(), TexSubImage2D(texInfo.fTarget, 0, 0, 0, kSize, kSize,
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);
if (0 == externalTexture.fID) {
ERRORF(reporter, "Error converting EGL Image back to texture");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return;
}
// Wrap this texture ID in a GrTexture
GrBackendTexture backendTex(kSize, kSize, kRGBA_8888_GrPixelConfig, externalTexture);
// TODO: If I make this TopLeft origin to match resolve_origin calls for kDefault, this test
// fails on the Nexus5. Why?
sk_sp<GrTextureContext> surfaceContext = context0->contextPriv().makeBackendTextureContext(
backendTex, kBottomLeft_GrSurfaceOrigin, nullptr);
if (!surfaceContext) {
ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext.");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
return;
}
GrTextureProxy* proxy = surfaceContext->asTextureProxy();
REPORTER_ASSERT(reporter, proxy->mipMapped() == GrMipMapped::kNo);
REPORTER_ASSERT(reporter,
proxy->priv().peekTexture()->texturePriv().mipMapped() == GrMipMapped::kNo);
REPORTER_ASSERT(reporter, proxy->texPriv().isGLTextureRectangleOrExternal());
REPORTER_ASSERT(reporter,
proxy->priv().peekTexture()->surfacePriv().isGLTextureRectangleOrExternal());
REPORTER_ASSERT(reporter, proxy->texPriv().isClampOnly());
REPORTER_ASSERT(reporter, proxy->priv().peekTexture()->surfacePriv().isClampOnly());
// Should not be able to wrap as a RT
{
sk_sp<GrRenderTargetContext> temp =
context0->contextPriv().makeBackendTextureRenderTargetContext(
backendTex, kBottomLeft_GrSurfaceOrigin, 1, nullptr);
if (temp) {
ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT.");
}
}
test_read_pixels(reporter, surfaceContext.get(), pixels.get(), "EGLImageTest-read");
// We should not be able to write to a EXTERNAL texture
test_write_pixels(reporter, 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, surfaceContext->asSurfaceProxy(),
pixels.get(), true, "EGLImageTest-copy");
cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image);
}