blob: 09dce05685df26ed0ad694ae25aa863eb1418915 [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:
bsalomon273c0f52016-03-31 10:59:06 -070021 virtual ~GLTestContext();
reed@google.comc31ce102010-12-21 16:26:39 +000022
bsalomon18a2f9d2016-05-11 10:09:18 -070023 virtual GrBackend backend() override { return kOpenGL_GrBackend; }
24 virtual GrBackendContext backendContext() override {
25 return reinterpret_cast<GrBackendContext>(fGL.get());
cdaltond416a5b2015-06-23 13:23:44 -070026 }
27
bsalomon18a2f9d2016-05-11 10:09:18 -070028 bool isValid() const override { return SkToBool(this->gl()); }
29
30 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 */
33 virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return 0; }
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. */
38 GrGLint createTextureRectangle(int width, int height, GrGLenum internalFormat,
39 GrGLenum externalFormat, GrGLenum externalType,
bsalomon3724e572016-03-30 18:56:19 -070040 GrGLvoid *data);
bsalomone5286e02016-01-14 09:24:09 -080041
bsalomon7ea33f52015-11-22 14:51:00 -080042 /**
43 * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a
44 * GL_TEXTURE_EXTERNAL_OES.
45 */
46 virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; }
47
bsalomon18a2f9d2016-05-11 10:09:18 -070048 void testAbandon() override;
bsalomon944bcf02014-07-29 08:01:52 -070049
bsalomonc8699322016-05-11 11:55:36 -070050 /** Ensures all work is submitted to the GPU for execution. */
51 void submit() override;
52
53 /** Wait until all GPU work is finished. */
54 void finish() override;
55
bsalomon7ea33f52015-11-22 14:51:00 -080056 /**
57 * Creates a new GL context of the same type and makes the returned context current
58 * (if not null).
59 */
Ben Wagner145dbcd2016-11-03 14:40:50 -040060 virtual std::unique_ptr<GLTestContext> makeNew() const { return nullptr; }
bsalomon7ea33f52015-11-22 14:51:00 -080061
csmartdalton421a3c12016-10-04 11:08:45 -070062 template<typename Ret, typename... Args>
63 void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE** out)(Args...),
64 const char* name, const char* ext = nullptr) const {
65 using Proc = Ret(GR_GL_FUNCTION_TYPE*)(Args...);
66 if (!SkStrStartsWith(name, "gl")) {
67 SkFAIL("getGLProcAddress: proc name must have 'gl' prefix");
68 *out = nullptr;
69 } else if (ext) {
70 SkString fullname(name);
71 fullname.append(ext);
72 *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(fullname.c_str()));
73 } else {
74 *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(name));
75 }
76 }
77
bsalomon@google.com373a6632011-10-19 20:43:20 +000078protected:
bsalomon273c0f52016-03-31 10:59:06 -070079 GLTestContext();
bsalomon@google.com373a6632011-10-19 20:43:20 +000080
cdaltond416a5b2015-06-23 13:23:44 -070081 /*
82 * Methods that sublcasses must call from their constructors and destructors.
83 */
Ben Wagner145dbcd2016-11-03 14:40:50 -040084 void init(const GrGLInterface *, std::unique_ptr<FenceSync> = nullptr);
bsalomon3724e572016-03-30 18:56:19 -070085
bsalomon18a2f9d2016-05-11 10:09:18 -070086 void teardown() override;
bsalomon3724e572016-03-30 18:56:19 -070087
88 virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
cdaltond416a5b2015-06-23 13:23:44 -070089
90private:
kkinnunen30bc88c2014-10-15 23:03:54 -070091 /** Subclass provides the gl interface object if construction was
92 * successful. */
Hal Canary1b612a82016-11-03 16:26:13 -040093 sk_sp<const GrGLInterface> fGL;
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000094
bsalomon18a2f9d2016-05-11 10:09:18 -070095 typedef TestContext INHERITED;
reed@google.comc31ce102010-12-21 16:26:39 +000096};
97
bsalomon18a2f9d2016-05-11 10:09:18 -070098/**
99 * Creates platform-dependent GL context object. The shareContext parameter is in an optional
bsalomon273c0f52016-03-31 10:59:06 -0700100 * context with which to share display lists. This should be a pointer to an GLTestContext created
bsalomon18a2f9d2016-05-11 10:09:18 -0700101 * with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to take place. Returns a
102 * valid gl context object or NULL if such can not be created.
kkinnunen9e61bb72014-10-09 05:24:15 -0700103 */
bsalomon18a2f9d2016-05-11 10:09:18 -0700104GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI,
105 GLTestContext *shareContext = nullptr);
kkinnunen9e61bb72014-10-09 05:24:15 -0700106
bsalomon3724e572016-03-30 18:56:19 -0700107} // namespace sk_gpu_test
reed@google.com873cb1e2010-12-23 15:00:45 +0000108#endif