blob: a358894cb41f62abd62769f438f8cda68d5572e9 [file] [log] [blame]
joshualitt74a07db2015-07-01 12:39:07 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GLBench_DEFINED
9#define GLBench_DEFINED
10
11#include "Benchmark.h"
12#include "SkCanvas.h"
13#include "SkImageEncoder.h"
14
15#if SK_SUPPORT_GPU
16#include "gl/GrGLFunctions.h"
17
18class GrGLContext;
19struct GrGLInterface;
20
21/*
22 * A virtual base class for microbenches which want to specifically test the performance of GL
23 */
24
25class GLBench : public Benchmark {
26public:
27 GLBench() {}
28
29protected:
30 const GrGLContext* getGLContext(SkCanvas*);
31 virtual const GrGLContext* onGetGLContext(const GrGLContext* ctx) { return ctx; }
joshualitt8a6697a2015-09-30 12:11:07 -070032 void onPreDraw(SkCanvas*) override;
joshualitt74a07db2015-07-01 12:39:07 -070033 virtual void setup(const GrGLContext*)=0;
joshualitt8a6697a2015-09-30 12:11:07 -070034 void onPostDraw(SkCanvas* canvas) override;
joshualitt74a07db2015-07-01 12:39:07 -070035 virtual void teardown(const GrGLInterface*)=0;
mtkleina1ebeb22015-10-01 09:43:39 -070036 void onDraw(int loops, SkCanvas*) override;
37 virtual void glDraw(int loops, const GrGLContext*)=0;
ethannicholas5961bc92016-10-12 06:39:56 -070038 static GrGLuint CompileShader(const GrGLContext*, const char* shaderSrc, GrGLenum type);
39 static GrGLuint CreateProgram(const GrGLContext*, const char* vshader, const char* fshader);
joshualitt74a07db2015-07-01 12:39:07 -070040 static GrGLuint SetupFramebuffer(const GrGLInterface*, int screenWidth, int screenHeight);
41 static void DumpImage(const GrGLInterface* gl, uint32_t screenWidth, uint32_t screenHeight,
42 const char* filename);
43
44
45private:
46 typedef Benchmark INHERITED;
47};
48
49
50#endif
51#endif