aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/GLBench.h
blob: 9033b12e55a24aec669ef5412616b38322fce66c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GLBench_DEFINED
#define GLBench_DEFINED

#include "Benchmark.h"
#include "SkCanvas.h"
#include "SkImageEncoder.h"

#if SK_SUPPORT_GPU
#include "gl/GrGLFunctions.h"

class GrGLContext;
struct GrGLInterface;

/*
 * A virtual base class for microbenches which want to specifically test the performance of GL
 */

class GLBench : public Benchmark {
public:
    GLBench() {}

protected:
    const GrGLContext* getGLContext(SkCanvas*);
    virtual const GrGLContext* onGetGLContext(const GrGLContext* ctx) { return ctx; }
    void onPreDraw(SkCanvas*) override;
    virtual void setup(const GrGLContext*)=0;
    void onPostDraw(SkCanvas* canvas) override;
    virtual void teardown(const GrGLInterface*)=0;
    void onDraw(int loops, SkCanvas*) override;
    virtual void glDraw(int loops, const GrGLContext*)=0;
    static GrGLuint CompileShader(const GrGLInterface*, const char* shaderSrc, GrGLenum type);
    static GrGLuint CreateProgram(const GrGLInterface*, const char* vshader, const char* fshader);
    static GrGLuint SetupFramebuffer(const GrGLInterface*, int screenWidth, int screenHeight);
    static void DumpImage(const GrGLInterface* gl, uint32_t screenWidth, uint32_t screenHeight,
                          const char* filename);


private:
    typedef Benchmark INHERITED;
};


#endif
#endif