blob: d376ed66904cccb50f960ad55f8884de4f1fe988 [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
bsalomon18a2f9d2016-05-11 10:09:18 -070011#include "TestContext.h"
bsalomon3724e572016-03-30 18:56:19 -070012#include "gl/GrGLInterface.h"
bsalomon3724e572016-03-30 18:56:19 -070013
14namespace sk_gpu_test {
reed@google.com873cb1e2010-12-23 15:00:45 +000015/**
bsalomon18a2f9d2016-05-11 10:09:18 -070016 * An offscreen OpenGL context. Provides a GrGLInterface struct of function pointers for the context
17 * This class is intended for Skia's internal testing needs and not for general use.
reed@google.com873cb1e2010-12-23 15:00:45 +000018 */
bsalomon18a2f9d2016-05-11 10:09:18 -070019class GLTestContext : public TestContext {
reed@google.comc31ce102010-12-21 16:26:39 +000020public:
Brian Salomond3b65972017-03-22 12:05:03 -040021 ~GLTestContext() override;
reed@google.comc31ce102010-12-21 16:26:39 +000022
Greg Danielbdf12ad2018-10-12 09:31:11 -040023 virtual GrBackendApi backend() override { return GrBackendApi::kOpenGL; }
cdaltond416a5b2015-06-23 13:23:44 -070024
Greg Danielb76a72a2017-07-13 15:07:54 -040025 bool isValid() const { return SkToBool(this->gl()); }
bsalomon18a2f9d2016-05-11 10:09:18 -070026
Brian Salomon384fab42017-12-07 12:33:05 -050027 const GrGLInterface* gl() const { return fGL.get(); }
bsalomon@google.com373a6632011-10-19 20:43:20 +000028
bsalomon7ea33f52015-11-22 14:51:00 -080029 /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */
Ben Wagnera93a14a2017-08-28 10:34:05 -040030 virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return nullptr; }
bsalomon3724e572016-03-30 18:56:19 -070031
32 virtual void destroyEGLImage(GrEGLImage) const { }
bsalomon7ea33f52015-11-22 14:51:00 -080033
bsalomone5286e02016-01-14 09:24:09 -080034 /** Used for testing GL_TEXTURE_RECTANGLE integration. */
35 GrGLint createTextureRectangle(int width, int height, GrGLenum internalFormat,
36 GrGLenum externalFormat, GrGLenum externalType,
bsalomon3724e572016-03-30 18:56:19 -070037 GrGLvoid *data);
bsalomone5286e02016-01-14 09:24:09 -080038
bsalomon7ea33f52015-11-22 14:51:00 -080039 /**
40 * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a
41 * GL_TEXTURE_EXTERNAL_OES.
42 */
43 virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; }
44
bsalomon18a2f9d2016-05-11 10:09:18 -070045 void testAbandon() override;
bsalomon944bcf02014-07-29 08:01:52 -070046
bsalomonc8699322016-05-11 11:55:36 -070047 /** Ensures all work is submitted to the GPU for execution. */
48 void submit() override;
49
50 /** Wait until all GPU work is finished. */
51 void finish() override;
52
bsalomon7ea33f52015-11-22 14:51:00 -080053 /**
54 * Creates a new GL context of the same type and makes the returned context current
55 * (if not null).
56 */
Ben Wagner145dbcd2016-11-03 14:40:50 -040057 virtual std::unique_ptr<GLTestContext> makeNew() const { return nullptr; }
bsalomon7ea33f52015-11-22 14:51:00 -080058
csmartdalton421a3c12016-10-04 11:08:45 -070059 template<typename Ret, typename... Args>
60 void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE** out)(Args...),
61 const char* name, const char* ext = nullptr) const {
62 using Proc = Ret(GR_GL_FUNCTION_TYPE*)(Args...);
63 if (!SkStrStartsWith(name, "gl")) {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040064 SK_ABORT("getGLProcAddress: proc name must have 'gl' prefix");
csmartdalton421a3c12016-10-04 11:08:45 -070065 *out = nullptr;
66 } else if (ext) {
67 SkString fullname(name);
68 fullname.append(ext);
69 *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(fullname.c_str()));
70 } else {
71 *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(name));
72 }
73 }
74
Greg Daniel02611d92017-07-25 10:05:01 -040075 sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override;
76
bsalomon@google.com373a6632011-10-19 20:43:20 +000077protected:
bsalomon273c0f52016-03-31 10:59:06 -070078 GLTestContext();
bsalomon@google.com373a6632011-10-19 20:43:20 +000079
cdaltond416a5b2015-06-23 13:23:44 -070080 /*
81 * Methods that sublcasses must call from their constructors and destructors.
82 */
Brian Salomon3d6801e2017-12-11 10:06:31 -050083 void init(sk_sp<const GrGLInterface>, std::unique_ptr<FenceSync> = nullptr);
bsalomon3724e572016-03-30 18:56:19 -070084
bsalomon18a2f9d2016-05-11 10:09:18 -070085 void teardown() override;
bsalomon3724e572016-03-30 18:56:19 -070086
87 virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
cdaltond416a5b2015-06-23 13:23:44 -070088
89private:
kkinnunen30bc88c2014-10-15 23:03:54 -070090 /** Subclass provides the gl interface object if construction was
91 * successful. */
Hal Canary1b612a82016-11-03 16:26:13 -040092 sk_sp<const GrGLInterface> fGL;
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000093
bsalomon18a2f9d2016-05-11 10:09:18 -070094 typedef TestContext INHERITED;
reed@google.comc31ce102010-12-21 16:26:39 +000095};
96
bsalomon18a2f9d2016-05-11 10:09:18 -070097/**
98 * Creates platform-dependent GL context object. The shareContext parameter is in an optional
bsalomon273c0f52016-03-31 10:59:06 -070099 * context with which to share display lists. This should be a pointer to an GLTestContext created
bsalomon18a2f9d2016-05-11 10:09:18 -0700100 * with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to take place. Returns a
101 * valid gl context object or NULL if such can not be created.
kkinnunen9e61bb72014-10-09 05:24:15 -0700102 */
bsalomon18a2f9d2016-05-11 10:09:18 -0700103GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI,
104 GLTestContext *shareContext = nullptr);
kkinnunen9e61bb72014-10-09 05:24:15 -0700105
bsalomon3724e572016-03-30 18:56:19 -0700106} // namespace sk_gpu_test
reed@google.com873cb1e2010-12-23 15:00:45 +0000107#endif