aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLPathProgramDataManager.h
blob: 9eeac7ea2083948dae85a69b5a5164cfb9e50c92 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * 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 GrGLPathProgramDataManager_DEFINED
#define GrGLPathProgramDataManager_DEFINED

#include "gl/GrGLProgramDataManager.h"

class GrGLPathProgram;
class GrGLPathProgramBuilder;

/** Manages the resources used by a shader program for NVPR rendering.
 */
class GrGLPathProgramDataManager : SkNoncopyable {
public:
    class SeparableVaryingHandle : public GrGLProgramDataManager::ShaderResourceHandle {
    public:
        /*
         * Creates a reference to a separable varying of a GrGLShaderBuilder.  The ref can be used
         * to set the varying with the corresponding GrGLPathProgramDataManager.
         */
        static SeparableVaryingHandle CreateFromSeparableVaryingIndex(int i) {
            return GrGLPathProgramDataManager::SeparableVaryingHandle(i);
        }
        SeparableVaryingHandle() { }
        bool operator==(const SeparableVaryingHandle& other) {
            return other.fValue == fValue;
        }
    private:
        SeparableVaryingHandle(int value) : ShaderResourceHandle(value) { }
        int toProgramDataIndex() const { SkASSERT(isValid()); return fValue; }
        int toShaderBuilderIndex() const { return toProgramDataIndex(); }

        friend class GrGLPathProgramDataManager; // For accessing toProgramDataIndex().
        friend class GrGLPathProcessor; // For accessing toShaderBuilderIndex().
    };

    struct SeparableVaryingInfo {
        GrGLShaderVar fVariable;
        GrGLint       fLocation;
    };

    // This uses an allocator rather than array so that the GrGLShaderVars don't move in memory
    // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their
    // name strings. Otherwise, we'd have to hand out copies.
    typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray;

    GrGLPathProgramDataManager(GrGLGpu*, GrGLuint programID, const SeparableVaryingInfoArray&);

    /** Functions for uploading the varying values.
     */
    void setPathFragmentInputTransform(SeparableVaryingHandle u,
                                       int components,
                                       const SkMatrix& matrix) const;
private:
    enum {
        kUnusedSeparableVarying = -1,
    };
    struct SeparableVarying {
        GrGLint     fLocation;
        SkDEBUGCODE(
            GrSLType    fType;
            int         fArrayCount;
        );
    };
    SkTArray<SeparableVarying, true> fSeparableVaryings;
    GrGLGpu* fGpu;
    GrGLuint fProgramID;
    typedef SkNoncopyable INHERITED;
};
#endif