bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 1 | /* |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 2 | * Copyright 2013 Google Inc. |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 7 | |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 8 | #include "GLTestContext.h" |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 9 | |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 10 | #include "GrContext.h" |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 11 | #include "GpuTimer.h" |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 12 | #include "gl/GrGLUtil.h" |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 13 | |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 14 | namespace { |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 15 | |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 16 | class GLFenceSync : public sk_gpu_test::FenceSync { |
| 17 | public: |
Brian Osman | 5fbd183 | 2017-10-10 16:39:50 -0400 | [diff] [blame] | 18 | static std::unique_ptr<FenceSync> MakeIfSupported(const sk_gpu_test::GLTestContext*); |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 19 | |
| 20 | sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override; |
| 21 | bool waitFence(sk_gpu_test::PlatformFence fence) const override; |
| 22 | void deleteFence(sk_gpu_test::PlatformFence fence) const override; |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 23 | |
| 24 | private: |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 25 | GLFenceSync(const sk_gpu_test::GLTestContext*, const char* ext = ""); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 26 | |
Brian Osman | 5fbd183 | 2017-10-10 16:39:50 -0400 | [diff] [blame] | 27 | bool validate() const override { return fGLFenceSync && fGLClientWaitSync && fGLDeleteSync; } |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 28 | |
| 29 | static constexpr GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117; |
| 30 | static constexpr GrGLenum GL_WAIT_FAILED = 0x911d; |
| 31 | static constexpr GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001; |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 32 | |
| 33 | typedef struct __GLsync *GLsync; |
csmartdalton | 024229a | 2016-10-04 14:24:23 -0700 | [diff] [blame] | 34 | GR_STATIC_ASSERT(sizeof(GLsync) <= sizeof(sk_gpu_test::PlatformFence)); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 35 | |
| 36 | typedef GLsync (GR_GL_FUNCTION_TYPE* GLFenceSyncProc) (GrGLenum, GrGLbitfield); |
| 37 | typedef GrGLenum (GR_GL_FUNCTION_TYPE* GLClientWaitSyncProc) (GLsync, GrGLbitfield, GrGLuint64); |
| 38 | typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GLDeleteSyncProc) (GLsync); |
| 39 | |
| 40 | GLFenceSyncProc fGLFenceSync; |
| 41 | GLClientWaitSyncProc fGLClientWaitSync; |
| 42 | GLDeleteSyncProc fGLDeleteSync; |
| 43 | |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 44 | typedef FenceSync INHERITED; |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
Brian Osman | 5fbd183 | 2017-10-10 16:39:50 -0400 | [diff] [blame] | 47 | class GLNVFenceSync : public sk_gpu_test::FenceSync { |
| 48 | public: |
| 49 | GLNVFenceSync(const sk_gpu_test::GLTestContext*); |
| 50 | |
| 51 | sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override; |
| 52 | bool waitFence(sk_gpu_test::PlatformFence fence) const override; |
| 53 | void deleteFence(sk_gpu_test::PlatformFence fence) const override; |
| 54 | |
| 55 | private: |
| 56 | bool validate() const override { |
| 57 | return fGLGenFencesNV && fGLDeleteFencesNV && fGLSetFenceNV && fGLFinishFenceNV; |
| 58 | } |
| 59 | |
| 60 | static constexpr GrGLenum GL_ALL_COMPLETED_NV = 0x84F2; |
| 61 | |
| 62 | typedef GrGLvoid(GR_GL_FUNCTION_TYPE* GLGenFencesNVProc) (GrGLsizei, GrGLuint*); |
| 63 | typedef GrGLvoid(GR_GL_FUNCTION_TYPE* GLDeleteFencesNVProc) (GrGLsizei, const GrGLuint*); |
| 64 | typedef GrGLvoid(GR_GL_FUNCTION_TYPE* GLSetFenceNVProc) (GrGLuint, GrGLenum); |
| 65 | typedef GrGLvoid(GR_GL_FUNCTION_TYPE* GLFinishFenceNVProc) (GrGLuint); |
| 66 | |
| 67 | GLGenFencesNVProc fGLGenFencesNV; |
| 68 | GLDeleteFencesNVProc fGLDeleteFencesNV; |
| 69 | GLSetFenceNVProc fGLSetFenceNV; |
| 70 | GLFinishFenceNVProc fGLFinishFenceNV; |
| 71 | |
| 72 | typedef FenceSync INHERITED; |
| 73 | }; |
| 74 | |
| 75 | std::unique_ptr<sk_gpu_test::FenceSync> GLFenceSync::MakeIfSupported( |
| 76 | const sk_gpu_test::GLTestContext* ctx) { |
| 77 | std::unique_ptr<FenceSync> ret; |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 78 | if (kGL_GrGLStandard == ctx->gl()->fStandard) { |
| 79 | if (GrGLGetVersion(ctx->gl()) < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) { |
| 80 | return nullptr; |
| 81 | } |
| 82 | ret.reset(new GLFenceSync(ctx)); |
| 83 | } else { |
Brian Osman | 80be240 | 2017-04-21 15:12:30 -0400 | [diff] [blame] | 84 | if (ctx->gl()->hasExtension("GL_APPLE_sync")) { |
| 85 | ret.reset(new GLFenceSync(ctx, "APPLE")); |
Brian Osman | 5fbd183 | 2017-10-10 16:39:50 -0400 | [diff] [blame] | 86 | } else if (ctx->gl()->hasExtension("GL_NV_fence")) { |
| 87 | ret.reset(new GLNVFenceSync(ctx)); |
Brian Osman | 80be240 | 2017-04-21 15:12:30 -0400 | [diff] [blame] | 88 | } else if (GrGLGetVersion(ctx->gl()) >= GR_GL_VER(3, 0)) { |
| 89 | ret.reset(new GLFenceSync(ctx)); |
| 90 | } else { |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 91 | return nullptr; |
| 92 | } |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 93 | } |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 94 | if (!ret->validate()) { |
| 95 | ret = nullptr; |
| 96 | } |
| 97 | return ret; |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | GLFenceSync::GLFenceSync(const sk_gpu_test::GLTestContext* ctx, const char* ext) { |
Brian Osman | e6984a0 | 2017-10-10 14:45:29 -0400 | [diff] [blame] | 101 | ctx->getGLProcAddress(&fGLFenceSync, "glFenceSync", ext); |
| 102 | ctx->getGLProcAddress(&fGLClientWaitSync, "glClientWaitSync", ext); |
| 103 | ctx->getGLProcAddress(&fGLDeleteSync, "glDeleteSync", ext); |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | sk_gpu_test::PlatformFence GLFenceSync::insertFence() const { |
| 107 | __GLsync* glsync = fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); |
| 108 | return reinterpret_cast<sk_gpu_test::PlatformFence>(glsync); |
| 109 | } |
| 110 | |
| 111 | bool GLFenceSync::waitFence(sk_gpu_test::PlatformFence fence) const { |
| 112 | GLsync glsync = reinterpret_cast<GLsync>(fence); |
| 113 | return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BIT, -1); |
| 114 | } |
| 115 | |
| 116 | void GLFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const { |
| 117 | GLsync glsync = reinterpret_cast<GLsync>(fence); |
| 118 | fGLDeleteSync(glsync); |
| 119 | } |
| 120 | |
Brian Osman | 5fbd183 | 2017-10-10 16:39:50 -0400 | [diff] [blame] | 121 | GLNVFenceSync::GLNVFenceSync(const sk_gpu_test::GLTestContext* ctx) { |
| 122 | ctx->getGLProcAddress(&fGLGenFencesNV, "glGenFencesNV"); |
| 123 | ctx->getGLProcAddress(&fGLDeleteFencesNV, "glDeleteFencesNV"); |
| 124 | ctx->getGLProcAddress(&fGLSetFenceNV, "glSetFenceNV"); |
| 125 | ctx->getGLProcAddress(&fGLFinishFenceNV, "glFinishFenceNV"); |
| 126 | } |
| 127 | |
| 128 | sk_gpu_test::PlatformFence GLNVFenceSync::insertFence() const { |
| 129 | GrGLuint fence; |
| 130 | fGLGenFencesNV(1, &fence); |
| 131 | fGLSetFenceNV(fence, GL_ALL_COMPLETED_NV); |
| 132 | return fence; |
| 133 | } |
| 134 | |
| 135 | bool GLNVFenceSync::waitFence(sk_gpu_test::PlatformFence fence) const { |
| 136 | fGLFinishFenceNV(fence); |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | void GLNVFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const { |
| 141 | GrGLuint glFence = static_cast<GrGLuint>(fence); |
| 142 | fGLDeleteFencesNV(1, &glFence); |
| 143 | } |
| 144 | |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 145 | class GLGpuTimer : public sk_gpu_test::GpuTimer { |
| 146 | public: |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 147 | static std::unique_ptr<GLGpuTimer> MakeIfSupported(const sk_gpu_test::GLTestContext*); |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 148 | |
| 149 | QueryStatus checkQueryStatus(sk_gpu_test::PlatformTimerQuery) override; |
| 150 | std::chrono::nanoseconds getTimeElapsed(sk_gpu_test::PlatformTimerQuery) override; |
| 151 | void deleteQuery(sk_gpu_test::PlatformTimerQuery) override; |
| 152 | |
| 153 | private: |
| 154 | GLGpuTimer(bool disjointSupport, const sk_gpu_test::GLTestContext*, const char* ext = ""); |
| 155 | |
| 156 | bool validate() const; |
| 157 | |
| 158 | sk_gpu_test::PlatformTimerQuery onQueueTimerStart() const override; |
| 159 | void onQueueTimerStop(sk_gpu_test::PlatformTimerQuery) const override; |
| 160 | |
| 161 | static constexpr GrGLenum GL_QUERY_RESULT = 0x8866; |
| 162 | static constexpr GrGLenum GL_QUERY_RESULT_AVAILABLE = 0x8867; |
| 163 | static constexpr GrGLenum GL_TIME_ELAPSED = 0x88bf; |
| 164 | static constexpr GrGLenum GL_GPU_DISJOINT = 0x8fbb; |
| 165 | |
| 166 | typedef void (GR_GL_FUNCTION_TYPE* GLGetIntegervProc) (GrGLenum, GrGLint*); |
| 167 | typedef void (GR_GL_FUNCTION_TYPE* GLGenQueriesProc) (GrGLsizei, GrGLuint*); |
| 168 | typedef void (GR_GL_FUNCTION_TYPE* GLDeleteQueriesProc) (GrGLsizei, const GrGLuint*); |
| 169 | typedef void (GR_GL_FUNCTION_TYPE* GLBeginQueryProc) (GrGLenum, GrGLuint); |
| 170 | typedef void (GR_GL_FUNCTION_TYPE* GLEndQueryProc) (GrGLenum); |
| 171 | typedef void (GR_GL_FUNCTION_TYPE* GLGetQueryObjectuivProc) (GrGLuint, GrGLenum, GrGLuint*); |
| 172 | typedef void (GR_GL_FUNCTION_TYPE* GLGetQueryObjectui64vProc) (GrGLuint, GrGLenum, GrGLuint64*); |
| 173 | |
| 174 | GLGetIntegervProc fGLGetIntegerv; |
| 175 | GLGenQueriesProc fGLGenQueries; |
| 176 | GLDeleteQueriesProc fGLDeleteQueries; |
| 177 | GLBeginQueryProc fGLBeginQuery; |
| 178 | GLEndQueryProc fGLEndQuery; |
| 179 | GLGetQueryObjectuivProc fGLGetQueryObjectuiv; |
| 180 | GLGetQueryObjectui64vProc fGLGetQueryObjectui64v; |
| 181 | |
| 182 | |
| 183 | typedef sk_gpu_test::GpuTimer INHERITED; |
| 184 | }; |
| 185 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 186 | std::unique_ptr<GLGpuTimer> GLGpuTimer::MakeIfSupported(const sk_gpu_test::GLTestContext* ctx) { |
| 187 | std::unique_ptr<GLGpuTimer> ret; |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 188 | const GrGLInterface* gl = ctx->gl(); |
| 189 | if (gl->fExtensions.has("GL_EXT_disjoint_timer_query")) { |
| 190 | ret.reset(new GLGpuTimer(true, ctx, "EXT")); |
| 191 | } else if (kGL_GrGLStandard == gl->fStandard && |
| 192 | (GrGLGetVersion(gl) > GR_GL_VER(3,3) || gl->fExtensions.has("GL_ARB_timer_query"))) { |
| 193 | ret.reset(new GLGpuTimer(false, ctx)); |
| 194 | } else if (gl->fExtensions.has("GL_EXT_timer_query")) { |
| 195 | ret.reset(new GLGpuTimer(false, ctx, "EXT")); |
| 196 | } |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 197 | if (ret && !ret->validate()) { |
| 198 | ret = nullptr; |
| 199 | } |
| 200 | return ret; |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | GLGpuTimer::GLGpuTimer(bool disjointSupport, const sk_gpu_test::GLTestContext* ctx, const char* ext) |
| 204 | : INHERITED(disjointSupport) { |
| 205 | ctx->getGLProcAddress(&fGLGetIntegerv, "glGetIntegerv"); |
| 206 | ctx->getGLProcAddress(&fGLGenQueries, "glGenQueries", ext); |
| 207 | ctx->getGLProcAddress(&fGLDeleteQueries, "glDeleteQueries", ext); |
| 208 | ctx->getGLProcAddress(&fGLBeginQuery, "glBeginQuery", ext); |
| 209 | ctx->getGLProcAddress(&fGLEndQuery, "glEndQuery", ext); |
| 210 | ctx->getGLProcAddress(&fGLGetQueryObjectuiv, "glGetQueryObjectuiv", ext); |
| 211 | ctx->getGLProcAddress(&fGLGetQueryObjectui64v, "glGetQueryObjectui64v", ext); |
| 212 | } |
| 213 | |
| 214 | bool GLGpuTimer::validate() const { |
| 215 | return fGLGetIntegerv && fGLGenQueries && fGLDeleteQueries && fGLBeginQuery && fGLEndQuery && |
| 216 | fGLGetQueryObjectuiv && fGLGetQueryObjectui64v; |
| 217 | } |
| 218 | |
| 219 | sk_gpu_test::PlatformTimerQuery GLGpuTimer::onQueueTimerStart() const { |
| 220 | GrGLuint queryID; |
| 221 | fGLGenQueries(1, &queryID); |
| 222 | if (!queryID) { |
| 223 | return sk_gpu_test::kInvalidTimerQuery; |
| 224 | } |
| 225 | if (this->disjointSupport()) { |
| 226 | // Clear the disjoint flag. |
| 227 | GrGLint disjoint; |
| 228 | fGLGetIntegerv(GL_GPU_DISJOINT, &disjoint); |
| 229 | } |
| 230 | fGLBeginQuery(GL_TIME_ELAPSED, queryID); |
| 231 | return static_cast<sk_gpu_test::PlatformTimerQuery>(queryID); |
| 232 | } |
| 233 | |
| 234 | void GLGpuTimer::onQueueTimerStop(sk_gpu_test::PlatformTimerQuery platformTimer) const { |
| 235 | if (sk_gpu_test::kInvalidTimerQuery == platformTimer) { |
| 236 | return; |
| 237 | } |
| 238 | fGLEndQuery(GL_TIME_ELAPSED); |
| 239 | } |
| 240 | |
| 241 | sk_gpu_test::GpuTimer::QueryStatus |
| 242 | GLGpuTimer::checkQueryStatus(sk_gpu_test::PlatformTimerQuery platformTimer) { |
| 243 | const GrGLuint queryID = static_cast<GrGLuint>(platformTimer); |
| 244 | if (!queryID) { |
| 245 | return QueryStatus::kInvalid; |
| 246 | } |
| 247 | GrGLuint available = 0; |
| 248 | fGLGetQueryObjectuiv(queryID, GL_QUERY_RESULT_AVAILABLE, &available); |
| 249 | if (!available) { |
| 250 | return QueryStatus::kPending; |
| 251 | } |
| 252 | if (this->disjointSupport()) { |
| 253 | GrGLint disjoint = 1; |
| 254 | fGLGetIntegerv(GL_GPU_DISJOINT, &disjoint); |
| 255 | if (disjoint) { |
| 256 | return QueryStatus::kDisjoint; |
| 257 | } |
| 258 | } |
| 259 | return QueryStatus::kAccurate; |
| 260 | } |
| 261 | |
| 262 | std::chrono::nanoseconds GLGpuTimer::getTimeElapsed(sk_gpu_test::PlatformTimerQuery platformTimer) { |
| 263 | SkASSERT(this->checkQueryStatus(platformTimer) >= QueryStatus::kDisjoint); |
| 264 | const GrGLuint queryID = static_cast<GrGLuint>(platformTimer); |
| 265 | GrGLuint64 nanoseconds; |
| 266 | fGLGetQueryObjectui64v(queryID, GL_QUERY_RESULT, &nanoseconds); |
| 267 | return std::chrono::nanoseconds(nanoseconds); |
| 268 | } |
| 269 | |
| 270 | void GLGpuTimer::deleteQuery(sk_gpu_test::PlatformTimerQuery platformTimer) { |
| 271 | const GrGLuint queryID = static_cast<GrGLuint>(platformTimer); |
| 272 | fGLDeleteQueries(1, &queryID); |
| 273 | } |
| 274 | |
| 275 | GR_STATIC_ASSERT(sizeof(GrGLuint) <= sizeof(sk_gpu_test::PlatformTimerQuery)); |
| 276 | |
csmartdalton | 421a3c1 | 2016-10-04 11:08:45 -0700 | [diff] [blame] | 277 | } // anonymous namespace |
| 278 | |
| 279 | namespace sk_gpu_test { |
| 280 | |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 281 | GLTestContext::GLTestContext() : TestContext() {} |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 282 | |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 283 | GLTestContext::~GLTestContext() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 284 | SkASSERT(nullptr == fGL.get()); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 287 | void GLTestContext::init(const GrGLInterface* gl, std::unique_ptr<FenceSync> fenceSync) { |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 288 | SkASSERT(!fGL.get()); |
| 289 | fGL.reset(gl); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 290 | fFenceSync = fenceSync ? std::move(fenceSync) : GLFenceSync::MakeIfSupported(this); |
| 291 | fGpuTimer = GLGpuTimer::MakeIfSupported(this); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 292 | } |
| 293 | |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 294 | void GLTestContext::teardown() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 295 | fGL.reset(nullptr); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 296 | INHERITED::teardown(); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 297 | } |
bsalomon | 944bcf0 | 2014-07-29 08:01:52 -0700 | [diff] [blame] | 298 | |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 299 | void GLTestContext::testAbandon() { |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 300 | INHERITED::testAbandon(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 301 | if (fGL) { |
bsalomon | 944bcf0 | 2014-07-29 08:01:52 -0700 | [diff] [blame] | 302 | fGL->abandon(); |
| 303 | } |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 304 | } |
| 305 | |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 306 | void GLTestContext::submit() { |
| 307 | if (fGL) { |
| 308 | GR_GL_CALL(fGL.get(), Flush()); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | void GLTestContext::finish() { |
| 313 | if (fGL) { |
| 314 | GR_GL_CALL(fGL.get(), Finish()); |
| 315 | } |
| 316 | } |
| 317 | |
bsalomon | 273c0f5 | 2016-03-31 10:59:06 -0700 | [diff] [blame] | 318 | GrGLint GLTestContext::createTextureRectangle(int width, int height, GrGLenum internalFormat, |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 319 | GrGLenum externalFormat, GrGLenum externalType, |
| 320 | GrGLvoid* data) { |
Hal Canary | 1b612a8 | 2016-11-03 16:26:13 -0400 | [diff] [blame] | 321 | if (!(kGL_GrGLStandard == fGL->fStandard && GrGLGetVersion(fGL.get()) >= GR_GL_VER(3, 1)) && |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 322 | !fGL->fExtensions.has("GL_ARB_texture_rectangle")) { |
| 323 | return 0; |
| 324 | } |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame] | 325 | |
Hal Canary | 1b612a8 | 2016-11-03 16:26:13 -0400 | [diff] [blame] | 326 | if (GrGLGetGLSLVersion(fGL.get()) < GR_GLSL_VER(1, 40)) { |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame] | 327 | return 0; |
| 328 | } |
| 329 | |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 330 | GrGLuint id; |
Hal Canary | 1b612a8 | 2016-11-03 16:26:13 -0400 | [diff] [blame] | 331 | GR_GL_CALL(fGL.get(), GenTextures(1, &id)); |
| 332 | GR_GL_CALL(fGL.get(), BindTexture(GR_GL_TEXTURE_RECTANGLE, id)); |
| 333 | GR_GL_CALL(fGL.get(), TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MAG_FILTER, |
| 334 | GR_GL_NEAREST)); |
| 335 | GR_GL_CALL(fGL.get(), TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FILTER, |
| 336 | GR_GL_NEAREST)); |
| 337 | GR_GL_CALL(fGL.get(), TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, |
| 338 | GR_GL_CLAMP_TO_EDGE)); |
| 339 | GR_GL_CALL(fGL.get(), TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, |
| 340 | GR_GL_CLAMP_TO_EDGE)); |
| 341 | GR_GL_CALL(fGL.get(), TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width, height, 0, |
| 342 | externalFormat, externalType, data)); |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 343 | return id; |
| 344 | } |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 345 | |
| 346 | sk_sp<GrContext> GLTestContext::makeGrContext(const GrContextOptions& options) { |
| 347 | return GrContext::MakeGL(fGL.get(), options); |
| 348 | } |
| 349 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 350 | } // namespace sk_gpu_test |