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 GrVkSemaphore_DEFINED
9#define GrVkSemaphore_DEFINED
10
11#include "GrSemaphore.h"
12#include "GrVkResource.h"
13
14#include "vk/GrVkTypes.h"
15
16class GrBackendSemaphore;
17class GrVkGpu;
18
19class GrVkSemaphore : public GrSemaphore {
20public:
21    static sk_sp<GrVkSemaphore> Make(const GrVkGpu* gpu, bool isOwned);
22
23    static sk_sp<GrVkSemaphore> MakeWrapped(const GrVkGpu* gpu,
24                                            VkSemaphore semaphore,
25                                            GrWrapOwnership);
26
27    ~GrVkSemaphore() override;
28
29    class Resource : public GrVkResource {
30    public:
31        Resource(VkSemaphore semaphore, bool isOwned)
32                : INHERITED(), fSemaphore(semaphore), fIsOwned(isOwned) {}
33
34        ~Resource() override {}
35
36        VkSemaphore semaphore() const { return fSemaphore; }
37
38#ifdef SK_TRACE_VK_RESOURCES
39        void dumpInfo() const override {
40            SkDebugf("GrVkSemaphore: %d (%d refs)\n", fSemaphore, this->getRefCnt());
41        }
42#endif
43    private:
44        void freeGPUData(const GrVkGpu* gpu) const override;
45
46        VkSemaphore fSemaphore;
47        bool        fIsOwned;
48
49        typedef GrVkResource INHERITED;
50    };
51
52    const Resource* getResource() const { return fResource; }
53
54private:
55    GrVkSemaphore(const GrVkGpu* gpu, VkSemaphore semaphore, bool isOwned);
56
57    void setBackendSemaphore(GrBackendSemaphore*) const override;
58
59    const Resource* fResource;
60
61    typedef GrSemaphore INHERITED;
62};
63
64#endif
65