blob: 787a190c20caa7cfaee3612b3bf5a13961aec07a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
robertphillips@google.com6177e692013-02-28 20:16:25 +00003 * Copyright 2013 Google Inc.
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
bsalomon273c0f52016-03-31 10:59:06 -07008#ifndef GLTestContext_DEFINED
9#define GLTestContext_DEFINED
reed@google.comc31ce102010-12-21 16:26:39 +000010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "tools/gpu/TestContext.h"
bsalomon3724e572016-03-30 18:56:19 -070012
Robert Phillips89fb3462019-05-22 13:13:58 -040013#ifdef SK_GL
14
15#include "include/gpu/gl/GrGLInterface.h"
16
bsalomon3724e572016-03-30 18:56:19 -070017namespace sk_gpu_test {
reed@google.com873cb1e2010-12-23 15:00:45 +000018/**
bsalomon18a2f9d2016-05-11 10:09:18 -070019 * 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.com873cb1e2010-12-23 15:00:45 +000021 */
bsalomon18a2f9d2016-05-11 10:09:18 -070022class GLTestContext : public TestContext {
reed@google.comc31ce102010-12-21 16:26:39 +000023public:
Brian Salomond3b65972017-03-22 12:05:03 -040024 ~GLTestContext() override;
reed@google.comc31ce102010-12-21 16:26:39 +000025
Greg Danielbdf12ad2018-10-12 09:31:11 -040026 virtual GrBackendApi backend() override { return GrBackendApi::kOpenGL; }
cdaltond416a5b2015-06-23 13:23:44 -070027
Greg Danielb76a72a2017-07-13 15:07:54 -040028 bool isValid() const { return SkToBool(this->gl()); }
bsalomon18a2f9d2016-05-11 10:09:18 -070029
Brian Salomon384fab42017-12-07 12:33:05 -050030 const GrGLInterface* gl() const { return fGL.get(); }
bsalomon@google.com373a6632011-10-19 20:43:20 +000031
bsalomon7ea33f52015-11-22 14:51:00 -080032 /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */
Ben Wagnera93a14a2017-08-28 10:34:05 -040033 virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return nullptr; }
bsalomon3724e572016-03-30 18:56:19 -070034
35 virtual void destroyEGLImage(GrEGLImage) const { }
bsalomon7ea33f52015-11-22 14:51:00 -080036
bsalomone5286e02016-01-14 09:24:09 -080037 /** Used for testing GL_TEXTURE_RECTANGLE integration. */
Brian Salomon1f05d452019-02-08 12:33:08 -050038 GrGLuint createTextureRectangle(int width, int height, GrGLenum internalFormat,
39 GrGLenum externalFormat, GrGLenum externalType, GrGLvoid* data);
bsalomone5286e02016-01-14 09:24:09 -080040
bsalomon7ea33f52015-11-22 14:51:00 -080041 /**
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
bsalomon18a2f9d2016-05-11 10:09:18 -070047 void testAbandon() override;
bsalomon944bcf02014-07-29 08:01:52 -070048
bsalomonc8699322016-05-11 11:55:36 -070049 /** 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
bsalomon7ea33f52015-11-22 14:51:00 -080055 /**
56 * Creates a new GL context of the same type and makes the returned context current
57 * (if not null).
58 */
Ben Wagner145dbcd2016-11-03 14:40:50 -040059 virtual std::unique_ptr<GLTestContext> makeNew() const { return nullptr; }
bsalomon7ea33f52015-11-22 14:51:00 -080060
csmartdalton421a3c12016-10-04 11:08:45 -070061 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 Wagnerb4aab9a2017-08-16 10:53:04 -040066 SK_ABORT("getGLProcAddress: proc name must have 'gl' prefix");
csmartdalton421a3c12016-10-04 11:08:45 -070067 *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 Daniel02611d92017-07-25 10:05:01 -040077 sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override;
78
bsalomon@google.com373a6632011-10-19 20:43:20 +000079protected:
bsalomon273c0f52016-03-31 10:59:06 -070080 GLTestContext();
bsalomon@google.com373a6632011-10-19 20:43:20 +000081
cdaltond416a5b2015-06-23 13:23:44 -070082 /*
83 * Methods that sublcasses must call from their constructors and destructors.
84 */
Brian Salomon3d6801e2017-12-11 10:06:31 -050085 void init(sk_sp<const GrGLInterface>, std::unique_ptr<FenceSync> = nullptr);
bsalomon3724e572016-03-30 18:56:19 -070086
bsalomon18a2f9d2016-05-11 10:09:18 -070087 void teardown() override;
bsalomon3724e572016-03-30 18:56:19 -070088
89 virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
cdaltond416a5b2015-06-23 13:23:44 -070090
91private:
kkinnunen30bc88c2014-10-15 23:03:54 -070092 /** Subclass provides the gl interface object if construction was
93 * successful. */
Hal Canary1b612a82016-11-03 16:26:13 -040094 sk_sp<const GrGLInterface> fGL;
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000095
bsalomon18a2f9d2016-05-11 10:09:18 -070096 typedef TestContext INHERITED;
reed@google.comc31ce102010-12-21 16:26:39 +000097};
98
bsalomon18a2f9d2016-05-11 10:09:18 -070099/**
100 * Creates platform-dependent GL context object. The shareContext parameter is in an optional
bsalomon273c0f52016-03-31 10:59:06 -0700101 * context with which to share display lists. This should be a pointer to an GLTestContext created
bsalomon18a2f9d2016-05-11 10:09:18 -0700102 * 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.
kkinnunen9e61bb72014-10-09 05:24:15 -0700104 */
bsalomon18a2f9d2016-05-11 10:09:18 -0700105GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI,
106 GLTestContext *shareContext = nullptr);
kkinnunen9e61bb72014-10-09 05:24:15 -0700107
bsalomon3724e572016-03-30 18:56:19 -0700108} // namespace sk_gpu_test
Robert Phillips89fb3462019-05-22 13:13:58 -0400109
110#endif
111
reed@google.com873cb1e2010-12-23 15:00:45 +0000112#endif