2012-04-19 19:15:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrContextFactory_DEFINED
|
|
|
|
#define GrContextFactory_DEFINED
|
|
|
|
|
|
|
|
#include "GrContext.h"
|
2015-05-22 21:01:46 +00:00
|
|
|
#include "GrContextOptions.h"
|
2014-11-13 19:12:41 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
#include "gl/GLTestContext.h"
|
2012-08-01 20:08:47 +00:00
|
|
|
#include "SkTArray.h"
|
2012-04-19 19:15:35 +00:00
|
|
|
|
2016-04-11 21:21:33 +00:00
|
|
|
struct GrVkBackendContext;
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
namespace sk_gpu_test {
|
2017-06-08 20:03:17 +00:00
|
|
|
class ContextInfo;
|
2016-04-05 19:59:06 +00:00
|
|
|
|
2012-04-19 19:15:35 +00:00
|
|
|
/**
|
2012-08-23 18:09:54 +00:00
|
|
|
* This is a simple class that is useful in test apps that use different
|
2012-04-19 19:15:35 +00:00
|
|
|
* GrContexts backed by different types of GL contexts. It manages creating the
|
|
|
|
* GL context and a GrContext that uses it. The GL/Gr contexts persist until the
|
|
|
|
* factory is destroyed (though the caller can always grab a ref on the returned
|
2014-01-24 20:49:44 +00:00
|
|
|
* Gr and GL contexts to make them outlive the factory).
|
2012-04-19 19:15:35 +00:00
|
|
|
*/
|
2014-04-07 19:34:38 +00:00
|
|
|
class GrContextFactory : SkNoncopyable {
|
2012-04-19 19:15:35 +00:00
|
|
|
public:
|
2016-04-11 21:21:33 +00:00
|
|
|
// The availability of context types is subject to platform and build configuration
|
|
|
|
// restrictions.
|
2016-04-05 18:06:27 +00:00
|
|
|
enum ContextType {
|
2016-10-14 15:13:48 +00:00
|
|
|
kGL_ContextType, //! OpenGL context.
|
|
|
|
kGLES_ContextType, //! OpenGL ES context.
|
|
|
|
kANGLE_D3D9_ES2_ContextType, //! ANGLE on Direct3D9 OpenGL ES 2 context.
|
|
|
|
kANGLE_D3D11_ES2_ContextType,//! ANGLE on Direct3D11 OpenGL ES 2 context.
|
|
|
|
kANGLE_D3D11_ES3_ContextType,//! ANGLE on Direct3D11 OpenGL ES 3 context.
|
|
|
|
kANGLE_GL_ES2_ContextType, //! ANGLE on OpenGL OpenGL ES 2 context.
|
|
|
|
kANGLE_GL_ES3_ContextType, //! ANGLE on OpenGL OpenGL ES 3 context.
|
|
|
|
kCommandBuffer_ContextType, //! Chromium command buffer OpenGL ES context.
|
|
|
|
kVulkan_ContextType, //! Vulkan
|
2017-07-13 19:34:56 +00:00
|
|
|
kMetal_ContextType, //! Metal
|
2017-07-06 20:40:18 +00:00
|
|
|
kMock_ContextType, //! Mock context that does not draw.
|
|
|
|
kLastContextType = kMock_ContextType
|
2012-04-19 19:15:35 +00:00
|
|
|
};
|
|
|
|
|
2016-04-05 18:06:27 +00:00
|
|
|
static const int kContextTypeCnt = kLastContextType + 1;
|
2013-02-04 16:13:32 +00:00
|
|
|
|
2015-12-10 14:28:13 +00:00
|
|
|
/**
|
2017-02-21 19:36:05 +00:00
|
|
|
* Overrides for the initial GrContextOptions provided at construction time, and required
|
|
|
|
* features that will cause context creation to fail if not present.
|
2015-12-10 14:28:13 +00:00
|
|
|
*/
|
2017-02-21 19:36:05 +00:00
|
|
|
enum class ContextOverrides {
|
|
|
|
kNone = 0x0,
|
|
|
|
kDisableNVPR = 0x1,
|
Dest color space no longer impacts mipmaps or texture sampling
PS5: Removes SkDestinationSurfaceColorMode, tracking of mipmap
mode on GrTexture, sRGB decode state per-texture. Because we
were often choosing sRGB configs for RGB color types, legacy
rendering would then be incorrect (too dark). So...
PS7: Stops ever using sRGB pixel configs when translating
image info or color type. Also removes a bunch of GrCaps bits
and a GrContextOption that are no longer relevant.
PS9: Adjusts surface creation unit test expectations, and
changes the raster rules accordingly.
At this point, sRGB configs are (obviously) going to be broken.
Locally, I ran 8888, gl, and the gbr- versions of both. Across
all GMs x configs, there are 13 diffs. 12 are GMs that create
surfaces with a color-space attached (and thus, the offscreen
is no longer getting sRGB pixel config). The only remainder
constructs an SkPictureImageGenerator, (with an attached color
space) and renders it to the gbr-gl canvas, which triggers a
a tagged surface inside the generator.
Bug: skia:
Change-Id: Ie5edfa157dd799f3121e8173fc4f97f6c8ed6789
Reviewed-on: https://skia-review.googlesource.com/131282
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2018-06-01 16:25:08 +00:00
|
|
|
kAvoidStencilBuffers = 0x2,
|
2017-02-21 19:36:05 +00:00
|
|
|
|
Dest color space no longer impacts mipmaps or texture sampling
PS5: Removes SkDestinationSurfaceColorMode, tracking of mipmap
mode on GrTexture, sRGB decode state per-texture. Because we
were often choosing sRGB configs for RGB color types, legacy
rendering would then be incorrect (too dark). So...
PS7: Stops ever using sRGB pixel configs when translating
image info or color type. Also removes a bunch of GrCaps bits
and a GrContextOption that are no longer relevant.
PS9: Adjusts surface creation unit test expectations, and
changes the raster rules accordingly.
At this point, sRGB configs are (obviously) going to be broken.
Locally, I ran 8888, gl, and the gbr- versions of both. Across
all GMs x configs, there are 13 diffs. 12 are GMs that create
surfaces with a color-space attached (and thus, the offscreen
is no longer getting sRGB pixel config). The only remainder
constructs an SkPictureImageGenerator, (with an attached color
space) and renders it to the gbr-gl canvas, which triggers a
a tagged surface inside the generator.
Bug: skia:
Change-Id: Ie5edfa157dd799f3121e8173fc4f97f6c8ed6789
Reviewed-on: https://skia-review.googlesource.com/131282
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2018-06-01 16:25:08 +00:00
|
|
|
kRequireNVPRSupport = 0x4,
|
2015-12-10 14:28:13 +00:00
|
|
|
};
|
|
|
|
|
2016-04-05 18:06:27 +00:00
|
|
|
static bool IsRenderingContext(ContextType type) {
|
2013-02-04 16:13:32 +00:00
|
|
|
switch (type) {
|
2017-07-06 20:40:18 +00:00
|
|
|
case kMock_ContextType:
|
2013-02-04 16:13:32 +00:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-12 13:31:11 +00:00
|
|
|
static GrBackendApi ContextTypeBackend(ContextType type) {
|
2016-04-11 21:21:33 +00:00
|
|
|
switch (type) {
|
|
|
|
case kVulkan_ContextType:
|
2018-10-12 13:31:11 +00:00
|
|
|
return GrBackendApi::kVulkan;
|
2017-07-13 19:34:56 +00:00
|
|
|
case kMetal_ContextType:
|
2018-10-12 13:31:11 +00:00
|
|
|
return GrBackendApi::kMetal;
|
2017-07-06 20:40:18 +00:00
|
|
|
case kMock_ContextType:
|
2018-10-12 13:31:11 +00:00
|
|
|
return GrBackendApi::kMock;
|
2016-04-11 21:21:33 +00:00
|
|
|
default:
|
2018-10-12 13:31:11 +00:00
|
|
|
return GrBackendApi::kOpenGL;
|
2016-04-11 21:21:33 +00:00
|
|
|
}
|
2016-04-06 21:02:39 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 13:45:32 +00:00
|
|
|
static const char* ContextTypeName(ContextType contextType) {
|
|
|
|
switch (contextType) {
|
|
|
|
case kGL_ContextType:
|
|
|
|
return "OpenGL";
|
|
|
|
case kGLES_ContextType:
|
|
|
|
return "OpenGLES";
|
|
|
|
case kANGLE_D3D9_ES2_ContextType:
|
|
|
|
return "ANGLE D3D9 ES2";
|
|
|
|
case kANGLE_D3D11_ES2_ContextType:
|
|
|
|
return "ANGLE D3D11 ES2";
|
|
|
|
case kANGLE_D3D11_ES3_ContextType:
|
|
|
|
return "ANGLE D3D11 ES3";
|
|
|
|
case kANGLE_GL_ES2_ContextType:
|
|
|
|
return "ANGLE GL ES2";
|
|
|
|
case kANGLE_GL_ES3_ContextType:
|
|
|
|
return "ANGLE GL ES3";
|
|
|
|
case kCommandBuffer_ContextType:
|
|
|
|
return "Command Buffer";
|
|
|
|
case kVulkan_ContextType:
|
|
|
|
return "Vulkan";
|
2017-07-13 19:34:56 +00:00
|
|
|
case kMetal_ContextType:
|
|
|
|
return "Metal";
|
2017-07-06 20:40:18 +00:00
|
|
|
case kMock_ContextType:
|
|
|
|
return "Mock";
|
2017-06-16 13:45:32 +00:00
|
|
|
}
|
2017-08-16 14:53:04 +00:00
|
|
|
SK_ABORT("Unreachable");
|
2017-06-16 13:45:32 +00:00
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
2016-01-07 07:49:30 +00:00
|
|
|
explicit GrContextFactory(const GrContextOptions& opts);
|
|
|
|
GrContextFactory();
|
2012-04-19 19:15:35 +00:00
|
|
|
|
2016-01-07 07:49:30 +00:00
|
|
|
~GrContextFactory();
|
2013-02-04 16:13:32 +00:00
|
|
|
|
2016-01-07 07:49:30 +00:00
|
|
|
void destroyContexts();
|
|
|
|
void abandonContexts();
|
2016-04-01 18:54:31 +00:00
|
|
|
void releaseResourcesAndAbandonContexts();
|
2014-07-28 20:48:36 +00:00
|
|
|
|
2012-04-19 19:15:35 +00:00
|
|
|
/**
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
* Get a context initialized with a type of GL context. It also makes the GL context current.
|
2012-04-19 19:15:35 +00:00
|
|
|
*/
|
2016-04-05 18:06:27 +00:00
|
|
|
ContextInfo getContextInfo(ContextType type,
|
2017-02-24 19:51:44 +00:00
|
|
|
ContextOverrides overrides = ContextOverrides::kNone);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a context in the same share group as the passed in GrContext, with the same type and
|
|
|
|
* overrides. To get multiple contexts in a single share group, pass the same shareContext,
|
|
|
|
* with different values for shareIndex.
|
|
|
|
*/
|
|
|
|
ContextInfo getSharedContextInfo(GrContext* shareContext, uint32_t shareIndex = 0);
|
|
|
|
|
Generate list of GPU contexts outside SurfaceTest tests
Add support for feeding the tests with contexts directly to the unit
test framework.
This fixes the problem where tests are more complex than needed just in
order to run the test code with multiple backends.
Also makes it possible to change the logic how contexts are
created. Instead of direct numbering, the different testable contexts
may be generated from filtered cross-product of context options. For
example: currently NVPR is a type of context. However, it could be also
an on/off feature of any context. In order to test this kind of context,
the enumeration can not be just of context type. It's simpler
to move the enumeration out of the tests.
A test targeting both normal and GPU backends would look like:
static void test_obj_behavior(skiatest::Reporter* reporter,
SkObj* obj, [other params] ) {
... test with obj and param ..
}
DEF_TEST(ObjBehavior, reporter) {
for (auto& object : generate_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_ALL_CONTEXTS(ObjBehavior_Gpu, reporter, context) {
for (auto& object : generate_gpu_object) {
for (auto& other_param : generate_other_variant) {
test_obj_behavior(reporter, object, other_param);
}
}
}
#endif
Uses the feature in SurfaceTests as an example.
Moves SkSurface -related tests from ImageTest to SurfaceTest.
BUG=skia:2992
Review URL: https://codereview.chromium.org/1446453003
2015-11-20 21:32:24 +00:00
|
|
|
/**
|
|
|
|
* Get a GrContext initialized with a type of GL context. It also makes the GL context current.
|
|
|
|
*/
|
2017-06-08 20:03:17 +00:00
|
|
|
GrContext* get(ContextType type, ContextOverrides overrides = ContextOverrides::kNone);
|
2015-05-22 21:01:46 +00:00
|
|
|
const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
|
2014-08-18 14:52:17 +00:00
|
|
|
|
2012-04-19 19:15:35 +00:00
|
|
|
private:
|
2017-02-24 19:51:44 +00:00
|
|
|
ContextInfo getContextInfoInternal(ContextType type, ContextOverrides overrides,
|
|
|
|
GrContext* shareContext, uint32_t shareIndex);
|
|
|
|
|
2016-01-07 07:49:30 +00:00
|
|
|
struct Context {
|
2017-02-21 19:36:05 +00:00
|
|
|
ContextType fType;
|
|
|
|
ContextOverrides fOverrides;
|
2017-10-18 12:33:29 +00:00
|
|
|
GrContextOptions fOptions;
|
2018-10-12 13:31:11 +00:00
|
|
|
GrBackendApi fBackend;
|
2017-02-21 19:36:05 +00:00
|
|
|
TestContext* fTestContext;
|
|
|
|
GrContext* fGrContext;
|
2017-02-21 21:58:08 +00:00
|
|
|
GrContext* fShareContext;
|
|
|
|
uint32_t fShareIndex;
|
|
|
|
|
|
|
|
bool fAbandoned;
|
2016-01-07 07:49:30 +00:00
|
|
|
};
|
2016-04-11 21:21:33 +00:00
|
|
|
SkTArray<Context, true> fContexts;
|
2017-01-24 22:22:05 +00:00
|
|
|
std::unique_ptr<GLTestContext> fSentinelGLContext;
|
2016-04-11 21:21:33 +00:00
|
|
|
const GrContextOptions fGlobalOptions;
|
2012-04-19 19:15:35 +00:00
|
|
|
};
|
2017-06-08 20:03:17 +00:00
|
|
|
|
|
|
|
class ContextInfo {
|
|
|
|
public:
|
|
|
|
ContextInfo() = default;
|
|
|
|
ContextInfo& operator=(const ContextInfo&) = default;
|
|
|
|
|
|
|
|
GrContextFactory::ContextType type() const { return fType; }
|
2018-10-12 13:31:11 +00:00
|
|
|
GrBackendApi backend() const { return GrContextFactory::ContextTypeBackend(fType); }
|
2017-06-08 20:03:17 +00:00
|
|
|
|
|
|
|
GrContext* grContext() const { return fGrContext; }
|
|
|
|
|
|
|
|
TestContext* testContext() const { return fTestContext; }
|
|
|
|
|
|
|
|
GLTestContext* glContext() const {
|
2018-10-12 13:31:11 +00:00
|
|
|
SkASSERT(GrBackendApi::kOpenGL == this->backend());
|
2017-06-08 20:03:17 +00:00
|
|
|
return static_cast<GLTestContext*>(fTestContext);
|
|
|
|
}
|
|
|
|
|
2017-10-18 12:33:29 +00:00
|
|
|
const GrContextOptions& options() const { return fOptions; }
|
|
|
|
|
2017-06-08 20:03:17 +00:00
|
|
|
private:
|
2017-10-18 12:33:29 +00:00
|
|
|
ContextInfo(GrContextFactory::ContextType type, TestContext* testContext, GrContext* grContext,
|
|
|
|
const GrContextOptions& options)
|
|
|
|
: fType(type), fTestContext(testContext), fGrContext(grContext), fOptions(options) {}
|
2017-06-08 20:03:17 +00:00
|
|
|
|
|
|
|
GrContextFactory::ContextType fType = GrContextFactory::kGL_ContextType;
|
|
|
|
// Valid until the factory destroys it via abandonContexts() or destroyContexts().
|
2017-10-18 12:33:29 +00:00
|
|
|
TestContext* fTestContext = nullptr;
|
|
|
|
GrContext* fGrContext = nullptr;
|
|
|
|
GrContextOptions fOptions;
|
2017-06-08 20:03:17 +00:00
|
|
|
|
|
|
|
friend class GrContextFactory;
|
|
|
|
};
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
} // namespace sk_gpu_test
|
2016-09-13 17:41:49 +00:00
|
|
|
|
2017-02-21 19:36:05 +00:00
|
|
|
GR_MAKE_BITFIELD_CLASS_OPS(sk_gpu_test::GrContextFactory::ContextOverrides);
|
2016-09-13 17:41:49 +00:00
|
|
|
|
2012-04-19 19:15:35 +00:00
|
|
|
#endif
|