1 /*
2  * Copyright 2017 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 GrGLSemaphore_DEFINED
9 #define GrGLSemaphore_DEFINED
10 
11 #include "include/gpu/GrBackendSemaphore.h"
12 #include "include/private/GrTypesPriv.h"
13 #include "src/gpu/GrSemaphore.h"
14 
15 class GrGLGpu;
16 
17 class GrGLSemaphore : public GrSemaphore {
18 public:
Make(GrGLGpu * gpu,bool isOwned)19     static sk_sp<GrGLSemaphore> Make(GrGLGpu* gpu, bool isOwned) {
20         return sk_sp<GrGLSemaphore>(new GrGLSemaphore(gpu, isOwned));
21     }
22 
MakeWrapped(GrGLGpu * gpu,GrGLsync sync,GrWrapOwnership ownership)23     static sk_sp<GrGLSemaphore> MakeWrapped(GrGLGpu* gpu,
24                                             GrGLsync sync,
25                                             GrWrapOwnership ownership) {
26         auto sema = sk_sp<GrGLSemaphore>(new GrGLSemaphore(gpu,
27                                                            kBorrow_GrWrapOwnership != ownership));
28         sema->setSync(sync);
29         return sema;
30     }
31 
sync()32     GrGLsync sync() const { return fSync; }
setSync(const GrGLsync & sync)33     void setSync(const GrGLsync& sync) { fSync = sync; }
34 
backendSemaphore()35     GrBackendSemaphore backendSemaphore() const override {
36         GrBackendSemaphore backendSemaphore;
37         backendSemaphore.initGL(fSync);
38         return backendSemaphore;
39     }
40 
41 private:
42     GrGLSemaphore(GrGLGpu* gpu, bool isOwned);
43 
44     void onRelease() override;
45     void onAbandon() override;
46 
47     GrGLsync fSync;
48     bool     fIsOwned;
49 
50     typedef GrSemaphore INHERITED;
51 };
52 
53 #endif
54