aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLSemaphore.h
blob: cfc3de99511118e5ba6deec6704afb0eb805d8a7 (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
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrGLSemaphore_DEFINED
#define GrGLSemaphore_DEFINED

#include "GrSemaphore.h"

#include "GrBackendSemaphore.h"
#include "GrGLGpu.h"

class GrGLSemaphore : public GrSemaphore {
public:
    static sk_sp<GrGLSemaphore> Make(const GrGLGpu* gpu, bool isOwned) {
        return sk_sp<GrGLSemaphore>(new GrGLSemaphore(gpu, isOwned));
    }

    static sk_sp<GrGLSemaphore> MakeWrapped(const GrGLGpu* gpu,
                                            GrGLsync sync,
                                            GrWrapOwnership ownership) {
        auto sema = sk_sp<GrGLSemaphore>(new GrGLSemaphore(gpu,
                                                           kBorrow_GrWrapOwnership != ownership));
        sema->setSync(sync);
        return sema;
    }

    ~GrGLSemaphore() override {
        if (fIsOwned && fGpu) {
            static_cast<const GrGLGpu*>(fGpu)->deleteSync(fSync);
        }
    }

    GrGLsync sync() const { return fSync; }
    void setSync(const GrGLsync& sync) { fSync = sync; }

private:
    GrGLSemaphore(const GrGLGpu* gpu, bool isOwned) : INHERITED(gpu), fSync(0), fIsOwned(isOwned) {}

    void setBackendSemaphore(GrBackendSemaphore* backendSemaphore) const override {
        backendSemaphore->initGL(fSync);
    }

    GrGLsync fSync;
    bool     fIsOwned;

    typedef GrSemaphore INHERITED;
};

#endif