aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/nanobench.cpp2
-rw-r--r--src/gpu/GrContextFactory.h13
-rw-r--r--tests/EGLImageTest.cpp223
-rwxr-xr-xtests/GLInterfaceValidationTest.cpp8
-rw-r--r--tests/GrContextFactoryTest.cpp19
5 files changed, 111 insertions, 154 deletions
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 0987cb7cfe..99483ebd99 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -172,7 +172,7 @@ struct GPUTarget : public Target {
this->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(this->config.ctxType),
SkSurface::kNo_Budgeted, info,
this->config.samples, &props));
- this->gl = gGrFactory->getGLContext(this->config.ctxType);
+ this->gl = gGrFactory->getContextInfo(this->config.ctxType)->fGLContext;
if (!this->surface.get()) {
return false;
}
diff --git a/src/gpu/GrContextFactory.h b/src/gpu/GrContextFactory.h
index 6d17432318..c837e74a25 100644
--- a/src/gpu/GrContextFactory.h
+++ b/src/gpu/GrContextFactory.h
@@ -137,19 +137,6 @@ public:
}
return nullptr;
}
-
- // Returns the GLContext of the given type. If it has not been created yet,
- // nullptr is returned instead.
- SkGLContext* getGLContext(GLContextType type) {
- for (int i = 0; i < fContexts.count(); ++i) {
- if (fContexts[i]->fType == type) {
- return fContexts[i]->fGLContext;
- }
- }
-
- return nullptr;
- }
-
const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
private:
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index 32e74f8e05..835f984013 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -37,133 +37,120 @@ static void cleanup(SkGLContext* glctx0, GrGLuint texID0, SkGLContext* glctx1, G
}
}
-DEF_GPUTEST(EGLImageTest, reporter, factory) {
- for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt; ++glCtxType) {
- GrContextFactory::GLContextType type = (GrContextFactory::GLContextType)glCtxType;
- if (!GrContextFactory::IsRenderingGLContext(type)) {
- continue;
- }
-
- // Try to create a second GL context and then check if the contexts have necessary
- // extensions to run this test.
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EGLImageTest, reporter, context0, glCtx0) {
+ // Try to create a second GL context and then check if the contexts have necessary
+ // extensions to run this test.
- GrContext* context0 = factory->get(type);
- if (!context0) {
- continue;
- }
- SkGLContext* glCtx0 = factory->getGLContext(type);
- SkASSERT(glCtx0);
- if (kGLES_GrGLStandard != glCtx0->gl()->fStandard) {
- continue;
- }
- GrGLGpu* gpu0 = static_cast<GrGLGpu*>(context0->getGpu());
- if (!gpu0->glCaps().externalTextureSupport()) {
- continue;
- }
+ if (kGLES_GrGLStandard != glCtx0->gl()->fStandard) {
+ return;
+ }
+ GrGLGpu* gpu0 = static_cast<GrGLGpu*>(context0->getGpu());
+ if (!gpu0->glCaps().externalTextureSupport()) {
+ return;
+ }
- SkGLContext* glCtx1 = glCtx0->createNew();
- if (!glCtx1) {
- continue;
- }
- GrContext* context1 = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)glCtx1->gl());
- const GrGLTextureInfo* backendTexture1 = nullptr;
- GrEGLImage image = GR_EGL_NO_IMAGE;
- GrGLTextureInfo externalTexture;
- externalTexture.fID = 0;
-
- if (!context1) {
- cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
- continue;
- }
+ SkGLContext* glCtx1 = glCtx0->createNew();
+ if (!glCtx1) {
+ return;
+ }
+ GrContext* context1 = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)glCtx1->gl());
+ const GrGLTextureInfo* backendTexture1 = nullptr;
+ GrEGLImage image = GR_EGL_NO_IMAGE;
+ GrGLTextureInfo externalTexture;
+ externalTexture.fID = 0;
- if (!glCtx1->gl()->hasExtension("EGL_KHR_image") ||
- !glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
- cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
- continue;
- }
+ if (!context1) {
+ cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
+ return;
+ }
-///////////////////////////////// CONTEXT 1 ///////////////////////////////////
-
- // Use GL Context 1 to create a texture unknown to GrContext.
- context1->flush();
- GrGpu* gpu1 = context1->getGpu();
- static const int kSize = 100;
- backendTexture1 = reinterpret_cast<const GrGLTextureInfo*>(
- gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig));
- if (!backendTexture1 || !backendTexture1->fID) {
- ERRORF(reporter, "Error creating texture for EGL Image");
- cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
- continue;
- }
- if (GR_GL_TEXTURE_2D != backendTexture1->fTarget) {
- ERRORF(reporter, "Expected backend texture to be 2D");
- cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
- continue;
- }
+ if (!glCtx1->gl()->hasExtension("EGL_KHR_image") ||
+ !glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
+ cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
+ return;
+ }
- // Wrap the texture in an EGLImage
- image = glCtx1->texture2DToEGLImage(backendTexture1->fID);
- if (GR_EGL_NO_IMAGE == image) {
- ERRORF(reporter, "Error creating EGL Image from texture");
- cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
- continue;
- }
+ ///////////////////////////////// CONTEXT 1 ///////////////////////////////////
- // 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(backendTexture1->fTarget, backendTexture1->fID));
- GR_GL_CALL(glCtx1->gl(), TexSubImage2D(backendTexture1->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);
-
- // Wrap this texture ID in a GrTexture
- GrBackendTextureDesc externalDesc;
- externalDesc.fConfig = kRGBA_8888_GrPixelConfig;
- externalDesc.fWidth = kSize;
- externalDesc.fHeight = kSize;
- externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externalTexture);
- SkAutoTUnref<GrTexture> externalTextureObj(
- context0->textureProvider()->wrapBackendTexture(externalDesc));
- if (!externalTextureObj) {
- ERRORF(reporter, "Error wrapping external texture in GrTexture.");
- cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
- continue;
- }
+ // Use GL Context 1 to create a texture unknown to GrContext.
+ context1->flush();
+ GrGpu* gpu1 = context1->getGpu();
+ static const int kSize = 100;
+ backendTexture1 = reinterpret_cast<const GrGLTextureInfo*>(
+ gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig));
+ if (!backendTexture1 || !backendTexture1->fID) {
+ ERRORF(reporter, "Error creating texture for EGL Image");
+ cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
+ return;
+ }
+ if (GR_GL_TEXTURE_2D != backendTexture1->fTarget) {
+ ERRORF(reporter, "Expected backend texture to be 2D");
+ cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
+ return;
+ }
- // Read the pixels and see if we get the values set in GL context 1
- memset(pixels.get(), 0, sizeof(uint32_t)*kSize*kSize);
- bool read = externalTextureObj->readPixels(0, 0, kSize, kSize, kRGBA_8888_GrPixelConfig,
- pixels.get());
- if (!read) {
- ERRORF(reporter, "Error reading external texture.");
- cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
- continue;
- }
- for (int i = 0; i < kSize*kSize; ++i) {
- if (pixels.get()[i] != 0xDDAABBCC) {
- ERRORF(reporter, "Error, external texture pixel value %d should be 0xDDAABBCC,"
- " got 0x%08x.", pixels.get()[i]);
- break;
- }
- }
+ // Wrap the texture in an EGLImage
+ image = glCtx1->texture2DToEGLImage(backendTexture1->fID);
+ if (GR_EGL_NO_IMAGE == image) {
+ ERRORF(reporter, "Error creating EGL Image from texture");
cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
+ return;
+ }
+
+ // 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(backendTexture1->fTarget, backendTexture1->fID));
+ GR_GL_CALL(glCtx1->gl(), TexSubImage2D(backendTexture1->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);
+
+ // Wrap this texture ID in a GrTexture
+ GrBackendTextureDesc externalDesc;
+ externalDesc.fConfig = kRGBA_8888_GrPixelConfig;
+ externalDesc.fWidth = kSize;
+ externalDesc.fHeight = kSize;
+ externalDesc.fTextureHandle = reinterpret_cast<GrBackendObject>(&externalTexture);
+ SkAutoTUnref<GrTexture> externalTextureObj(
+ context0->textureProvider()->wrapBackendTexture(externalDesc));
+ if (!externalTextureObj) {
+ ERRORF(reporter, "Error wrapping external texture in GrTexture.");
+ cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
+ return;
+ }
+
+ // Read the pixels and see if we get the values set in GL context 1
+ memset(pixels.get(), 0, sizeof(uint32_t)*kSize*kSize);
+ bool read = externalTextureObj->readPixels(0, 0, kSize, kSize, kRGBA_8888_GrPixelConfig,
+ pixels.get());
+ if (!read) {
+ ERRORF(reporter, "Error reading external texture.");
+ cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
+ return;
+ }
+ for (int i = 0; i < kSize*kSize; ++i) {
+ if (pixels.get()[i] != 0xDDAABBCC) {
+ ERRORF(reporter, "Error, external texture pixel value %d should be 0xDDAABBCC,"
+ " got 0x%08x.", pixels.get()[i]);
+ break;
+ }
}
+ cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image);
}
#endif
diff --git a/tests/GLInterfaceValidationTest.cpp b/tests/GLInterfaceValidationTest.cpp
index 7af34a7fe0..3632c255a6 100755
--- a/tests/GLInterfaceValidationTest.cpp
+++ b/tests/GLInterfaceValidationTest.cpp
@@ -16,14 +16,14 @@ DEF_GPUTEST(GLInterfaceValidation, reporter, factory) {
for (int i = 0; i <= GrContextFactory::kLastGLContextType; ++i) {
GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType)i;
// this forces the factory to make the context if it hasn't yet
- factory->get(glCtxType);
- SkGLContext* glCtx = factory->getGLContext(glCtxType);
+ GrContextFactory::ContextInfo* contextInfo = factory->getContextInfo(glCtxType);
+ SkGLContext* glCtx = contextInfo->fGLContext;
// We're supposed to fail the NVPR context type when we the native context that does not
// support the NVPR extension.
if (GrContextFactory::kNVPR_GLContextType == glCtxType &&
- factory->getGLContext(GrContextFactory::kNative_GLContextType) &&
- !factory->getGLContext(GrContextFactory::kNative_GLContextType)->gl()->hasExtension("GL_NV_path_rendering")) {
+ factory->getContextInfo(GrContextFactory::kNative_GLContextType) &&
+ !factory->getContextInfo(GrContextFactory::kNative_GLContextType)->fGLContext->gl()->hasExtension("GL_NV_path_rendering")) {
REPORTER_ASSERT(reporter, nullptr == glCtx);
continue;
}
diff --git a/tests/GrContextFactoryTest.cpp b/tests/GrContextFactoryTest.cpp
index 787f16c983..79209c719f 100644
--- a/tests/GrContextFactoryTest.cpp
+++ b/tests/GrContextFactoryTest.cpp
@@ -12,23 +12,6 @@
#include "GrContextFactory.h"
#include "Test.h"
-DEF_GPUTEST(GrContextFactory, reporter, factory) {
- // Reset in case some other test has been using it first.
- factory->destroyContexts();
-
- // Before we ask for a context, we expect the GL context to not be there.
- REPORTER_ASSERT(reporter,
- nullptr == factory->getGLContext(GrContextFactory::kNull_GLContextType));
-
- // After we ask for a context, we expect that the GL context to be there.
- factory->get(GrContextFactory::kNull_GLContextType);
- REPORTER_ASSERT(reporter,
- factory->getGLContext(GrContextFactory::kNull_GLContextType) != nullptr);
-
- // If we did not ask for a context with the particular GL context, we would
- // expect the particular GL context to not be there.
- REPORTER_ASSERT(reporter,
- nullptr == factory->getGLContext(GrContextFactory::kDebug_GLContextType));
-}
+// TODO: test GrContextFactory.
#endif