aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrStagedProcessor.h
blob: a9f23b485b10c8766482bbba2ed146d1ebe067a8 (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
/*
 * 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 GrStagedProcessorStage_DEFINED
#define GrStagedProcessorStage_DEFINED

#include "GrFragmentProcessor.h"
#include "SkRefCnt.h"

/**
 * Wraps a GrFragmentProcessor, basically a copyable SkAutoTUnref
 * Templatized based on the ref type so backends can use the same wrapper
 */
template<template<typename> class T>
class GrStagedProcessor {
public:
    explicit GrStagedProcessor(const GrFragmentProcessor* proc) : fProc(SkRef(proc)) {}

    GrStagedProcessor(const GrStagedProcessor& other) { fProc.reset(SkRef(other.fProc.get())); }

    const GrFragmentProcessor* processor() const { return fProc.get(); }

    bool operator==(const GrStagedProcessor& that) const {
        return this->processor()->isEqual(*that.processor());
    }

    bool operator!=(const GrStagedProcessor& that) const { return !(*this == that); }

    const char* name() const { return fProc->name(); }

protected:
    GrStagedProcessor() {}

    T<const GrFragmentProcessor> fProc;
};

typedef GrStagedProcessor<SkAutoTUnref> GrFragmentStage;

#endif