epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 3 | * Copyright 2013 Google Inc. |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 8 | #ifndef GLTestContext_DEFINED |
| 9 | #define GLTestContext_DEFINED |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "tools/gpu/TestContext.h" |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 12 | |
Robert Phillips | 89fb346 | 2019-05-22 13:13:58 -0400 | [diff] [blame^] | 13 | #ifdef SK_GL |
| 14 | |
| 15 | #include "include/gpu/gl/GrGLInterface.h" |
| 16 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 17 | namespace sk_gpu_test { |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 18 | /** |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 19 | * An offscreen OpenGL context. Provides a GrGLInterface struct of function pointers for the context |
| 20 | * This class is intended for Skia's internal testing needs and not for general use. |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 21 | */ |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 22 | class GLTestContext : public TestContext { |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 23 | public: |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 24 | ~GLTestContext() override; |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 25 | |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 26 | virtual GrBackendApi backend() override { return GrBackendApi::kOpenGL; } |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 27 | |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 28 | bool isValid() const { return SkToBool(this->gl()); } |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 29 | |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 30 | const GrGLInterface* gl() const { return fGL.get(); } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 31 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 32 | /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */ |
Ben Wagner | a93a14a | 2017-08-28 10:34:05 -0400 | [diff] [blame] | 33 | virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return nullptr; } |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 34 | |
| 35 | virtual void destroyEGLImage(GrEGLImage) const { } |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 36 | |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 37 | /** Used for testing GL_TEXTURE_RECTANGLE integration. */ |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 38 | GrGLuint createTextureRectangle(int width, int height, GrGLenum internalFormat, |
| 39 | GrGLenum externalFormat, GrGLenum externalType, GrGLvoid* data); |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 40 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 41 | /** |
| 42 | * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a |
| 43 | * GL_TEXTURE_EXTERNAL_OES. |
| 44 | */ |
| 45 | virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; } |
| 46 | |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 47 | void testAbandon() override; |
bsalomon | 944bcf0 | 2014-07-29 08:01:52 -0700 | [diff] [blame] | 48 | |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 49 | /** Ensures all work is submitted to the GPU for execution. */ |
| 50 | void submit() override; |
| 51 | |
| 52 | /** Wait until all GPU work is finished. */ |
| 53 | void finish() override; |
| 54 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 55 | /** |
| 56 | * Creates a new GL context of the same type and makes the returned context current |
| 57 | * (if not null). |
| 58 | */ |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 59 | virtual std::unique_ptr<GLTestContext> makeNew() const { return nullptr; } |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 60 | |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 61 | template<typename Ret, typename... Args> |
| 62 | void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE** out)(Args...), |
| 63 | const char* name, const char* ext = nullptr) const { |
| 64 | using Proc = Ret(GR_GL_FUNCTION_TYPE*)(Args...); |
| 65 | if (!SkStrStartsWith(name, "gl")) { |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 66 | SK_ABORT("getGLProcAddress: proc name must have 'gl' prefix"); |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 67 | *out = nullptr; |
| 68 | } else if (ext) { |
| 69 | SkString fullname(name); |
| 70 | fullname.append(ext); |
| 71 | *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(fullname.c_str())); |
| 72 | } else { |
| 73 | *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(name)); |
| 74 | } |
| 75 | } |
| 76 | |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 77 | sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override; |
| 78 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 79 | protected: |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 80 | GLTestContext(); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 81 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 82 | /* |
| 83 | * Methods that sublcasses must call from their constructors and destructors. |
| 84 | */ |
Brian Salomon | 3d6801e | 2017-12-11 10:06:31 -0500 | [diff] [blame] | 85 | void init(sk_sp<const GrGLInterface>, std::unique_ptr<FenceSync> = nullptr); |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 86 | |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 87 | void teardown() override; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 88 | |
| 89 | virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0; |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 90 | |
| 91 | private: |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 92 | /** Subclass provides the gl interface object if construction was |
| 93 | * successful. */ |
Hal Canary | 1b612a8 | 2016-11-03 16:26:13 -0400 | [diff] [blame] | 94 | sk_sp<const GrGLInterface> fGL; |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 95 | |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 96 | typedef TestContext INHERITED; |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Creates platform-dependent GL context object. The shareContext parameter is in an optional |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 101 | * context with which to share display lists. This should be a pointer to an GLTestContext created |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 102 | * with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to take place. Returns a |
| 103 | * valid gl context object or NULL if such can not be created. |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 104 | */ |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 105 | GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, |
| 106 | GLTestContext *shareContext = nullptr); |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 107 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 108 | } // namespace sk_gpu_test |
Robert Phillips | 89fb346 | 2019-05-22 13:13:58 -0400 | [diff] [blame^] | 109 | |
| 110 | #endif |
| 111 | |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 112 | #endif |